Bug 1259530 - Add PP_FLAGS to customize preprocessor flags in moz.build; r?glandium
MozReview-Commit-ID: 5oWmeyVR7Fp
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -1392,17 +1392,17 @@ pp_target_results = $(foreach file,$($(1
$(foreach tier,$(PP_TARGETS_TIERS), \
$(eval $(tier):: $(PP_TARGETS_RESULTS_$(tier))) \
)
PP_TARGETS_ALL_RESULTS := $(sort $(foreach tier,$(PP_TARGETS_TIERS),$(PP_TARGETS_RESULTS_$(tier))))
$(PP_TARGETS_ALL_RESULTS):
$(if $(filter-out $(notdir $@),$(notdir $(<:.in=))),$(error Looks like $@ has an unexpected dependency on $< which breaks PP_TARGETS))
$(RM) '$@'
- $(call py_action,preprocessor,--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
+ $(call py_action,preprocessor,--depend $(MDDEPDIR)/$(@F).pp $(PP_TARGET_FLAGS) $($(<F)_FLAGS) $(DEFINES) $(ACDEFINES) '$<' -o '$@')
$(filter %.css,$(PP_TARGETS_ALL_RESULTS)): PP_TARGET_FLAGS+=--marker %
# The depfile is based on the filename, and we don't want conflicts. So check
# there's only one occurrence of any given filename in PP_TARGETS_ALL_RESULTS.
PP_TARGETS_ALL_RESULT_NAMES := $(notdir $(PP_TARGETS_ALL_RESULTS))
$(foreach file,$(sort $(PP_TARGETS_ALL_RESULT_NAMES)), \
$(if $(filter-out 1,$(words $(filter $(file),$(PP_TARGETS_ALL_RESULT_NAMES)))), \
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -16,16 +16,17 @@ contain, you've come to the right place.
from __future__ import absolute_import, unicode_literals
import os
from collections import (
Counter,
OrderedDict,
+ defaultdict,
)
from mozbuild.util import (
HierarchicalStringList,
KeyedDefaultDict,
List,
ListWithAction,
memoize,
memoized_property,
@@ -608,16 +609,22 @@ def TypedListWithAction(typ, action):
"""
class _TypedListWithAction(ContextDerivedValue, TypedList(typ), ListWithAction):
def __init__(self, context, *args):
def _action(item):
return item, action(context, item)
super(_TypedListWithAction, self).__init__(action=_action, *args)
return _TypedListWithAction
+def DefaultDict(typ):
+ class _DefaultDict(defaultdict):
+ def __init__(self):
+ super(_DefaultDict, self).__init__(typ)
+ return _DefaultDict
+
WebPlatformTestManifest = TypedNamedTuple("WebPlatformTestManifest",
[("manifest_path", unicode),
("test_root", unicode)])
ManifestparserManifestList = OrderedListWithAction(read_manifestparser_manifest)
ReftestManifestList = OrderedListWithAction(read_reftest_manifest)
WptManifestList = TypedListWithAction(WebPlatformTestManifest, read_wpt_manifest)
OrderedSourceList = ContextDerivedTypedList(SourcePath, StrictOrderingOnAppendList)
@@ -1095,16 +1102,27 @@ VARIABLES = {
cases, not for general use. If you wish to add entries to OBJDIR_FILES,
please consult a build peer.
"""),
'OBJDIR_PP_FILES': (ContextDerivedTypedHierarchicalStringList(Path), list,
"""Like ``OBJDIR_FILES``, with preprocessing. Use sparingly.
"""),
+ 'PP_FLAGS': (DefaultDict(List), list,
+ """Sets flags to be used by the preprocessor for the specified source file.
+
+ For files that are preprocessed with ``FINAL_TARGET_PP_FILES`` or
+ ``OBJDIR_PP_FILES``, you can use ``PP_FLAGS`` to add a flag for a
+ particular file. For example::
+
+ FINAL_TARGET_PP_FILES += ['foo.py.in']
+ PP_FLAGS['foo.py.in'] += ['-DFOO=bar']
+ """),
+
'FINAL_LIBRARY': (unicode, unicode,
"""Library in which the objects of the current directory will be linked.
This variable contains the name of a library, defined elsewhere with
``LIBRARY_NAME``, in which the objects of the current directory will be
linked.
"""),
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -825,16 +825,20 @@ class TreeMetadataEmitter(LoggingMixin):
local_include.full_path), context)
yield LocalInclude(context, local_include)
for obj in self._handle_linkables(context, passthru, generated_files):
yield obj
generated_files.update(['%s%s' % (k, self.config.substs.get('BIN_SUFFIX', '')) for k in self._binaries.keys()])
+ pp_flags = context.get('PP_FLAGS', {})
+ for f in pp_flags:
+ yield PerSourceFlag(context, f, pp_flags[f])
+
components = []
for var, cls in (
('BRANDING_FILES', BrandingFiles),
('EXPORTS', Exports),
('FINAL_TARGET_FILES', FinalTargetFiles),
('FINAL_TARGET_PP_FILES', FinalTargetPreprocessedFiles),
('OBJDIR_FILES', ObjdirFiles),
('OBJDIR_PP_FILES', ObjdirPreprocessedFiles),