Builder.py (SCons-4.3.0) | : | Builder.py (SCons-4.4.0) | ||
---|---|---|---|---|
skipping to change at line 133 | skipping to change at line 133 | |||
return [path[:-len(suf)], path[-len(suf):]] | return [path[:-len(suf)], path[-len(suf):]] | |||
return SCons.Util.splitext(path) | return SCons.Util.splitext(path) | |||
class DictCmdGenerator(SCons.Util.Selector): | class DictCmdGenerator(SCons.Util.Selector): | |||
"""This is a callable class that can be used as a | """This is a callable class that can be used as a | |||
command generator function. It holds on to a dictionary | command generator function. It holds on to a dictionary | |||
mapping file suffixes to Actions. It uses that dictionary | mapping file suffixes to Actions. It uses that dictionary | |||
to return the proper action based on the file suffix of | to return the proper action based on the file suffix of | |||
the source file.""" | the source file.""" | |||
def __init__(self, dict=None, source_ext_match=1): | def __init__(self, mapping=None, source_ext_match=True): | |||
SCons.Util.Selector.__init__(self, dict) | super().__init__(mapping) | |||
self.source_ext_match = source_ext_match | self.source_ext_match = source_ext_match | |||
def src_suffixes(self): | def src_suffixes(self): | |||
return list(self.keys()) | return list(self.keys()) | |||
def add_action(self, suffix, action): | def add_action(self, suffix, action): | |||
"""Add a suffix-action pair to the mapping. | """Add a suffix-action pair to the mapping. | |||
""" | """ | |||
self[suffix] = action | self[suffix] = action | |||
skipping to change at line 225 | skipping to change at line 225 | |||
} | } | |||
class OverrideWarner(UserDict): | class OverrideWarner(UserDict): | |||
"""A class for warning about keyword arguments that we use as | """A class for warning about keyword arguments that we use as | |||
overrides in a Builder call. | overrides in a Builder call. | |||
This class exists to handle the fact that a single Builder call | This class exists to handle the fact that a single Builder call | |||
can actually invoke multiple builders. This class only emits the | can actually invoke multiple builders. This class only emits the | |||
warnings once, no matter how many Builders are invoked. | warnings once, no matter how many Builders are invoked. | |||
""" | """ | |||
def __init__(self, dict): | def __init__(self, mapping): | |||
UserDict.__init__(self, dict) | super().__init__(mapping) | |||
if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.Overr ideWarner') | if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.Overr ideWarner') | |||
self.already_warned = None | self.already_warned = None | |||
def warn(self): | def warn(self): | |||
if self.already_warned: | if self.already_warned: | |||
return | return | |||
for k in self.keys(): | for k in self.keys(): | |||
if k in misleading_keywords: | if k in misleading_keywords: | |||
alt = misleading_keywords[k] | alt = misleading_keywords[k] | |||
msg = "Did you mean to use `%s' instead of `%s'?" % (alt, k) | msg = "Did you mean to use `%s' instead of `%s'?" % (alt, k) | |||
SCons.Warnings.warn(SCons.Warnings.MisleadingKeywordsWarning, ms g) | SCons.Warnings.warn(SCons.Warnings.MisleadingKeywordsWarning, ms g) | |||
self.already_warned = 1 | self.already_warned = 1 | |||
def Builder(**kw): | def Builder(**kw): | |||
"""A factory for builder objects.""" | """A factory for builder objects.""" | |||
composite = None | composite = None | |||
if 'generator' in kw: | if 'generator' in kw: | |||
if 'action' in kw: | if 'action' in kw: | |||
raise UserError("You must not specify both an action and a generator .") | raise UserError("You must not specify both an action and a generator .") | |||
kw['action'] = SCons.Action.CommandGeneratorAction(kw['generator'], {}) | kw['action'] = SCons.Action.CommandGeneratorAction(kw['generator'], {}) | |||
del kw['generator'] | del kw['generator'] | |||
elif 'action' in kw: | elif 'action' in kw: | |||
source_ext_match = kw.get('source_ext_match', 1) | source_ext_match = kw.get('source_ext_match', True) | |||
if 'source_ext_match' in kw: | if 'source_ext_match' in kw: | |||
del kw['source_ext_match'] | del kw['source_ext_match'] | |||
if SCons.Util.is_Dict(kw['action']): | if SCons.Util.is_Dict(kw['action']): | |||
composite = DictCmdGenerator(kw['action'], source_ext_match) | composite = DictCmdGenerator(kw['action'], source_ext_match) | |||
kw['action'] = SCons.Action.CommandGeneratorAction(composite, {}) | kw['action'] = SCons.Action.CommandGeneratorAction(composite, {}) | |||
kw['src_suffix'] = composite.src_suffixes() | kw['src_suffix'] = composite.src_suffixes() | |||
else: | else: | |||
kw['action'] = SCons.Action.Action(kw['action']) | kw['action'] = SCons.Action.Action(kw['action']) | |||
if 'emitter' in kw: | if 'emitter' in kw: | |||
skipping to change at line 879 | skipping to change at line 880 | |||
return suffixes | return suffixes | |||
class CompositeBuilder(SCons.Util.Proxy): | class CompositeBuilder(SCons.Util.Proxy): | |||
"""A Builder Proxy whose main purpose is to always have | """A Builder Proxy whose main purpose is to always have | |||
a DictCmdGenerator as its action, and to provide access | a DictCmdGenerator as its action, and to provide access | |||
to the DictCmdGenerator's add_action() method. | to the DictCmdGenerator's add_action() method. | |||
""" | """ | |||
def __init__(self, builder, cmdgen): | def __init__(self, builder, cmdgen): | |||
if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.Compo siteBuilder') | if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.Compo siteBuilder') | |||
SCons.Util.Proxy.__init__(self, builder) | super().__init__(builder) | |||
# cmdgen should always be an instance of DictCmdGenerator. | # cmdgen should always be an instance of DictCmdGenerator. | |||
self.cmdgen = cmdgen | self.cmdgen = cmdgen | |||
self.builder = builder | self.builder = builder | |||
__call__ = SCons.Util.Delegate('__call__') | __call__ = SCons.Util.Delegate('__call__') | |||
def add_action(self, suffix, action): | def add_action(self, suffix, action): | |||
self.cmdgen.add_action(suffix, action) | self.cmdgen.add_action(suffix, action) | |||
self.set_src_suffix(self.cmdgen.src_suffixes()) | self.set_src_suffix(self.cmdgen.src_suffixes()) | |||
End of changes. 5 change blocks. | ||||
6 lines changed or deleted | 7 lines changed or added |