gbuild-to-ide cleanup GbuildParser

Removed .files replaced by
.modules[*]['targets']

Affected generators updated.

Change-Id: I4bf4cb5a23ba0b48b11adb1795c0a4f9dfbb0d3a
This commit is contained in:
jan Iversen
2017-01-14 10:02:28 +01:00
parent b6e6d2d31d
commit 9cb3b064e5

View File

@@ -49,8 +49,7 @@ class GbuildParser:
self.binpath = os.path.dirname(os.environ['GPERF']) # woha, this is quite a hack self.binpath = os.path.dirname(os.environ['GPERF']) # woha, this is quite a hack
(self.srcdir, self.builddir, self.instdir, self.workdir) = (os.environ['SRCDIR'], os.environ['BUILDDIR'], (self.srcdir, self.builddir, self.instdir, self.workdir) = (os.environ['SRCDIR'], os.environ['BUILDDIR'],
os.environ['INSTDIR'], os.environ['WORKDIR']) os.environ['INSTDIR'], os.environ['WORKDIR'])
(self.modules, self.files) = (collections.OrderedDict(), []) (self.modules, self.target_by_path) = (collections.OrderedDict(), collections.OrderedDict())
self.target_by_path = collections.OrderedDict()
_includepattern = re.compile('-I(\S+)') _includepattern = re.compile('-I(\S+)')
_isystempattern = re.compile('-isystem\s*(\S+)') _isystempattern = re.compile('-isystem\s*(\S+)')
@@ -87,6 +86,7 @@ class GbuildParser:
return [cxxflag.strip() for cxxflag in GbuildParser._warningpattern.sub('', '%s %s' % (flagsline, flagslineappend)).split(' ') if len(cxxflag) > 1] return [cxxflag.strip() for cxxflag in GbuildParser._warningpattern.sub('', '%s %s' % (flagsline, flagslineappend)).split(' ') if len(cxxflag) > 1]
def parse(self): def parse(self):
moduleDict = {}
for jsontype in ['Library', 'Executable', 'CppunitTest']: for jsontype in ['Library', 'Executable', 'CppunitTest']:
for jsonfilename in os.listdir(os.path.join(self.workdir, 'GbuildToJson', jsontype)): for jsonfilename in os.listdir(os.path.join(self.workdir, 'GbuildToJson', jsontype)):
with open(os.path.join(self.workdir, 'GbuildToJson', jsontype, jsonfilename), 'r') as f: with open(os.path.join(self.workdir, 'GbuildToJson', jsontype, jsonfilename), 'r') as f:
@@ -94,48 +94,47 @@ class GbuildParser:
(foundincludes, foundisystem) = GbuildParser.__split_includes(jsondata['INCLUDE']) (foundincludes, foundisystem) = GbuildParser.__split_includes(jsondata['INCLUDE'])
match = GbuildParser._buildpattern[jsontype].match(os.path.basename(jsondata['MAKEFILE'])).group(1) match = GbuildParser._buildpattern[jsontype].match(os.path.basename(jsondata['MAKEFILE'])).group(1)
location = os.path.dirname(jsondata['MAKEFILE'])
newObj = GbuildLinkTarget(match, newObj = GbuildLinkTarget(match,
os.path.dirname(jsondata['MAKEFILE']), location,
foundincludes, foundincludes,
foundisystem, foundisystem,
GbuildParser.__split_defs(jsondata['DEFS']), GbuildParser.__split_defs(jsondata['DEFS']),
GbuildParser.__split_objs(jsondata['CXXOBJECTS']), sorted(GbuildParser.__split_objs(jsondata['CXXOBJECTS'])),
GbuildParser.__split_flags(jsondata['CXXFLAGS'], jsondata['CXXFLAGSAPPEND']), GbuildParser.__split_flags(jsondata['CXXFLAGS'], jsondata['CXXFLAGSAPPEND']),
jsondata['LINKED_LIBS'].strip().split(' '), jsondata['LINKED_LIBS'].strip().split(' '),
jsondata['ASMOBJECTS'], sorted(jsondata['ASMOBJECTS']),
GbuildParser.__split_flags(jsondata['CFLAGS'], jsondata['CFLAGSAPPEND']), GbuildParser.__split_flags(jsondata['CFLAGS'], jsondata['CFLAGSAPPEND']),
jsondata['GENCOBJECTS'], sorted(jsondata['GENCOBJECTS']),
jsondata['GENCXXOBJECTS'], sorted(jsondata['GENCXXOBJECTS']),
jsondata['ILIBTARGET'], jsondata['ILIBTARGET'],
jsondata['LINKED_STATIC_LIBS'], jsondata['LINKED_STATIC_LIBS'],
jsondata['LINKTARGET'], jsondata['LINKTARGET'],
GbuildParser.__split_flags(jsondata['OBJCFLAGS'], jsondata['OBJCFLAGSAPPEND']), GbuildParser.__split_flags(jsondata['OBJCFLAGS'], jsondata['OBJCFLAGSAPPEND']),
jsondata['OBJCOBJECTS'], sorted(jsondata['OBJCOBJECTS']),
GbuildParser.__split_flags(jsondata['OBJCXXFLAGS'], jsondata['OBJCXXFLAGSAPPEND']), GbuildParser.__split_flags(jsondata['OBJCXXFLAGS'], jsondata['OBJCXXFLAGSAPPEND']),
jsondata['OBJCXXOBJECTS'], sorted(jsondata['OBJCXXOBJECTS']),
jsondata['YACCOBJECTS'], sorted(jsondata['YACCOBJECTS']),
jsontype) jsontype)
self.files.append(newObj) module = location.split('/')[-1]
if not module in moduleDict:
moduleDict[module] = {'targets': set()}
moduleDict[module]['targets'] |= set([newObj])
moduleDict = {} for module in sorted(moduleDict):
for target in self.files: self.modules[module] = moduleDict[module]
module = target.location.split('/')[-1] for m in self.modules:
if not module in moduleDict: for target in self.modules[m]['targets']:
moduleDict[module] = {'targets': set()} for cxx in target.cxxobjects:
moduleDict[module]['targets'] |= set([target]) path = '/'.join(cxx.split('/')[:-1])
if path not in self.target_by_path:
for cxx in target.cxxobjects: self.target_by_path[path] = set()
path = '/'.join(cxx.split('/')[:-1]) self.target_by_path[path] |= set([target])
if path not in self.target_by_path:
self.target_by_path[path] = set()
self.target_by_path[path] |= set([target])
for path in self.target_by_path: for path in self.target_by_path:
x = self.target_by_path[path] x = self.target_by_path[path]
if path != '' and len(set(self.target_by_path[path])) > 1: if path != '' and len(set(self.target_by_path[path])) > 1:
print('fdo#70422: multiple target use dir %s: %s' % ( print('fdo#70422: multiple target use dir %s: %s' % (
path, ', '.join([target.target_name for target in set(self.target_by_path[path])]))) path, ', '.join([target.target_name for target in set(self.target_by_path[path])])))
for module in sorted(moduleDict):
self.modules[module] = moduleDict[module]
return self return self
@@ -273,15 +272,15 @@ class DebugIntegrationGenerator(IdeIntegrationGenerator):
def emit(self): def emit(self):
print(self.gbuildparser.srcdir) print(self.gbuildparser.srcdir)
print(self.gbuildparser.builddir) print(self.gbuildparser.builddir)
for f in self.gbuildparser.files: for f in self.gbuildparser.modules:
print(f) for j in self.gbuildparser.modules[f]['targets']:
print(j)
VisualStudioIntegrationGenerator(self.gbuildparser, self.ide).emit() VisualStudioIntegrationGenerator(self.gbuildparser, self.ide).emit()
XcodeIntegrationGenerator(self.gbuildparser, self.ide).emit() XcodeIntegrationGenerator(self.gbuildparser, self.ide).emit()
EclipseCDTIntegrationGenerator(self.gbuildparser, self.ide).emit() EclipseCDTIntegrationGenerator(self.gbuildparser, self.ide).emit()
KdevelopIntegrationGenerator(self.gbuildparser, self.ide).emit() KdevelopIntegrationGenerator(self.gbuildparser, self.ide).emit()
VisualStudioIntegrationGenerator(self.gbuildparser, self.ide).emit()
VimIntegrationGenerator(self.gbuildparser, self.ide).emit() VimIntegrationGenerator(self.gbuildparser, self.ide).emit()
QtCreatorIntegrationGenerator(self.gbuildparser, self.ide).emit() QtCreatorIntegrationGenerator(self.gbuildparser, self.ide).emit()
@@ -293,13 +292,14 @@ class VimIntegrationGenerator(IdeIntegrationGenerator):
def emit(self): def emit(self):
global_list = [] global_list = []
for lib in self.gbuildparser.files: for m in self.gbuildparser.modules:
entries = [] for lib in self.gbuildparser.modules[m]['targets']:
for file in lib.cxxobjects: entries = []
filePath = os.path.join(self.gbuildparser.srcdir, file) + ".cxx" for file in lib.cxxobjects:
entry = {'directory': lib.location, 'file': filePath, 'command': self.generateCommand(lib, filePath)} filePath = os.path.join(self.gbuildparser.srcdir, file) + ".cxx"
entries.append(entry) entry = {'directory': lib.location, 'file': filePath, 'command': self.generateCommand(lib, filePath)}
global_list.extend(entries) entries.append(entry)
global_list.extend(entries)
export_file = open('compile_commands.json', 'w') export_file = open('compile_commands.json', 'w')
json.dump(global_list, export_file) json.dump(global_list, export_file)
@@ -1018,10 +1018,11 @@ class QtCreatorIntegrationGenerator(IdeIntegrationGenerator):
def __init__(self, gbuildparser, ide): def __init__(self, gbuildparser, ide):
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) IdeIntegrationGenerator.__init__(self, gbuildparser, ide)
self.target_by_location = {} self.target_by_location = {}
for target in self.gbuildparser.files: for m in self.gbuildparser.modules:
if target.location not in self.target_by_location: for target in self.gbuildparser.modules[m]['targets']:
self.target_by_location[target.location] = set() if target.location not in self.target_by_location:
self.target_by_location[target.location] |= set([target]) self.target_by_location[target.location] = set()
self.target_by_location[target.location] |= set([target])
self._do_log = False # set to 'True' to activate log of QtCreatorIntegrationGenerator self._do_log = False # set to 'True' to activate log of QtCreatorIntegrationGenerator
if self._do_log: if self._do_log:
@@ -1474,7 +1475,10 @@ class QtCreatorIntegrationGenerator(IdeIntegrationGenerator):
self.data_libs = {} self.data_libs = {}
all_libs = self.gbuildparser.files all_libs = []
for m in self.gbuildparser.modules:
for f in self.gbuildparser.modules[m]['targets']:
all_libs.append(f)
for lib in all_libs: for lib in all_libs:
self._log("\nlibrary : %s, loc=%s" % (lib.target_name, lib.location)) self._log("\nlibrary : %s, loc=%s" % (lib.target_name, lib.location))
lib_name = os.path.basename(lib.location) lib_name = os.path.basename(lib.location)