Bug 1247567 - Include per-source flags in the CompileDB. r=glandium
MozReview-Commit-ID: Ivm4DeG8z94
--- a/python/mozbuild/mozbuild/compilation/database.py
+++ b/python/mozbuild/mozbuild/compilation/database.py
@@ -11,16 +11,17 @@ from mozbuild.compilation import util
from mozbuild.backend.common import CommonBackend
from mozbuild.frontend.data import (
Sources,
GeneratedSources,
DirectoryTraversal,
Defines,
Linkable,
LocalInclude,
+ PerSourceFlag,
VariablePassthru,
SimpleProgram,
)
from mozbuild.shellutil import (
quote as shell_quote,
)
from mozbuild.util import expand_variables
import mozpack.path as mozpath
@@ -41,16 +42,17 @@ class CompileDBBackend(CommonBackend):
# The cache for per-directory flags
self._flags = {}
self._envs = {}
self._includes = defaultdict(list)
self._defines = defaultdict(list)
self._local_flags = defaultdict(dict)
+ self._per_source_flags = defaultdict(list)
self._extra_includes = defaultdict(list)
self._gyp_dirs = set()
self._dist_include_testing = '-I%s' % mozpath.join(
self.environment.topobjdir, 'dist', 'include', 'testing')
def consume_object(self, obj):
# Those are difficult directories, that will be handled later.
if obj.relativedir in (
@@ -105,16 +107,19 @@ class CompileDBBackend(CommonBackend):
self._local_flags[obj.objdir][var] = obj.variables[var]
if (obj.variables.get('DISABLE_STL_WRAPPING') and
'STL_FLAGS' in self._local_flags[obj.objdir]):
del self._local_flags[obj.objdir]['STL_FLAGS']
if (obj.variables.get('ALLOW_COMPILER_WARNINGS') and
'WARNINGS_AS_ERRORS' in self._local_flags[obj.objdir]):
del self._local_flags[obj.objdir]['WARNINGS_AS_ERRORS']
+ elif isinstance(obj, PerSourceFlag):
+ self._per_source_flags[obj.file_name].extend(obj.flags)
+
return True
def consume_finished(self):
CommonBackend.consume_finished(self)
db = []
for (directory, filename, unified), cmd in self._db.iteritems():
@@ -152,16 +157,19 @@ class CompileDBBackend(CommonBackend):
for a in cmd:
a = expand_variables(a, variables).split()
if not a:
continue
if isinstance(a, types.StringTypes):
c.append(a)
else:
c.extend(a)
+ per_source_flags = self._per_source_flags.get(filename)
+ if per_source_flags is not None:
+ c.extend(per_source_flags)
db.append({
'directory': directory,
'command': ' '.join(shell_quote(a) for a in c),
'file': filename,
})
import json
# Output the database (a JSON file) to objdir/compile_commands.json