Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: pylib/gyp/generator/ninja.py

Issue 10381103: ninja: rules chained only by output of first one failing Base URL: https://gyp.googlecode.com/svn/trunk
Patch Set: only update sources if process_outputs_as_sources Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/chained-rules/action.input » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/generator/ninja.py
diff --git a/pylib/gyp/generator/ninja.py b/pylib/gyp/generator/ninja.py
index 8809edb88bfe6dd6bd123f6e75261904e9b8b34c..174adcbf5faaddd8d56a45fada04ba3e573ba4b7 100644
--- a/pylib/gyp/generator/ninja.py
+++ b/pylib/gyp/generator/ninja.py
@@ -304,6 +304,49 @@ class NinjaWriter:
self.ninja.newline()
return targets[0]
+ def _SourcesHandledByRule(self, rule, sources):
+ """Get a list of files that from |sources| that |rule| handles."""
+ rule_ext = rule['extension']
+ result = []
+ for s in sources:
Evan Martin 2012/05/18 17:19:06 s/s/source/
scottmg 2012/05/18 18:06:30 Done.
+ if s.endswith('.' + rule_ext):
+ inputs, outputs = self._GetInputsAndOutputsForRule(rule, s)
+ if s in outputs:
+ # Don't the outputs of this rule with this rule, even if by
Evan Martin 2012/05/18 17:19:06 This comment accidentally a word.
scottmg 2012/05/18 18:06:30 Done.
+ # extension we ought to.
+ continue
+ result.append(s)
+ return result
+
+ def _GetInputsAndOutputsForRule(self, rule, source):
+ """Get the expanded inputs and outputs of the given |rule| for a
+ particular |source|."""
+ dirname, basename = os.path.split(source)
+ root, ext = os.path.splitext(basename)
+ outputs = [self.ExpandRuleVariables(o, root, dirname,
+ source, ext, basename)
+ for o in rule['outputs']]
+ inputs = [self.ExpandRuleVariables(i, root, dirname,
+ source, ext, basename)
+ for i in rule.get('inputs', [])]
+ return inputs, outputs
+
+ def _GetSources(self, spec):
+ """Get all sources for the given |spec|. In addition to the sources
+ directly specified in the gyp file, it includes sources generated by
+ actions and copies. Outputs of rules are not included because otherwise
+ rules that generate the same extension as they process cause much
+ confusion. Rule outputs are added when the rule is processed."""
+ sources = spec.get('sources', [])
+ for action in spec.get('actions', []):
+ #sources.extend(action['inputs'])
Evan Martin 2012/05/18 17:19:06 Probably should delete dead code
scottmg 2012/05/18 18:06:30 Done.
+ if int(action.get('process_outputs_as_sources', False)):
+ sources.extend(action.get('outputs', []))
+ for copy in spec.get('copies', []):
+ sources.extend(copy.get('files', []))
+ return set(sources)
+
+
def WriteSpec(self, spec, config_name, generator_flags):
"""The main entry point for NinjaWriter: write the build rules for a spec.
@@ -349,13 +392,16 @@ class NinjaWriter:
self.target.preaction_stamp = actions_depends
self.target.precompile_stamp = compile_depends
+ # Build a list of sources. We do this as a pre-process so that we have
+ # access to generated outputs for actions for other actions and rules.
+ sources = self._GetSources(spec)
+
# Write out actions, rules, and copies. These must happen before we
# compile any sources, so compute a list of predependencies for sources
# while we do it.
- extra_sources = []
mac_bundle_depends = []
self.target.actions_stamp = self.WriteActionsRulesCopies(
- spec, extra_sources, actions_depends, mac_bundle_depends)
+ spec, sources, actions_depends, mac_bundle_depends)
# If we have actions/rules/copies, we depend directly on those, but
# otherwise we depend on dependent target's actions/rules/copies etc.
@@ -365,7 +411,6 @@ class NinjaWriter:
# Write out the compilation steps, if any.
link_deps = []
- sources = spec.get('sources', []) + extra_sources
if sources:
link_deps = self.WriteSources(
config_name, config, sources, compile_depends_stamp,
@@ -437,7 +482,7 @@ class NinjaWriter:
self._WinIdlRule(source, prebuild, outputs)
return outputs
- def WriteActionsRulesCopies(self, spec, extra_sources, prebuild,
+ def WriteActionsRulesCopies(self, spec, sources, prebuild,
mac_bundle_depends):
"""Write out the Actions, Rules, and Copies steps. Return a path
representing the outputs of these steps."""
@@ -445,10 +490,10 @@ class NinjaWriter:
extra_mac_bundle_resources = []
if 'actions' in spec:
- outputs += self.WriteActions(spec['actions'], extra_sources, prebuild,
+ outputs += self.WriteActions(spec['actions'], sources, prebuild,
extra_mac_bundle_resources)
if 'rules' in spec:
- outputs += self.WriteRules(spec['rules'], extra_sources, prebuild,
+ outputs += self.WriteRules(spec['rules'], sources, prebuild,
extra_mac_bundle_resources)
if 'copies' in spec:
outputs += self.WriteCopies(spec['copies'], prebuild)
@@ -480,7 +525,7 @@ class NinjaWriter:
else:
return '%s %s: %s' % (verb, self.name, fallback)
- def WriteActions(self, actions, extra_sources, prebuild,
+ def WriteActions(self, actions, sources, prebuild,
extra_mac_bundle_resources):
# Actions cd into the base directory.
env = self.GetXcodeEnv()
@@ -502,8 +547,6 @@ class NinjaWriter:
is_cygwin, env=env)
inputs = [self.GypPathToNinja(i, env) for i in action['inputs']]
- if int(action.get('process_outputs_as_sources', False)):
- extra_sources += action['outputs']
if int(action.get('process_outputs_as_mac_bundle_resources', False)):
extra_mac_bundle_resources += action['outputs']
outputs = [self.GypPathToNinja(o, env) for o in action['outputs']]
@@ -517,8 +560,7 @@ class NinjaWriter:
return all_outputs
- def WriteRules(self, rules, extra_sources, prebuild,
- extra_mac_bundle_resources):
Evan Martin 2012/05/18 17:19:06 It's so pleasing to see this param go, it always f
+ def WriteRules(self, rules, sources, prebuild, extra_mac_bundle_resources):
all_outputs = []
for rule in rules:
# First write out a rule for the rule action.
@@ -552,21 +594,15 @@ class NinjaWriter:
return path.replace('\\', '/')
return path
+ rule_sources = self._SourcesHandledByRule(rule, sources)
# For each source file, write an edge that generates all the outputs.
- for source in rule.get('rule_sources', []):
+ for source in rule_sources:
dirname, basename = os.path.split(source)
root, ext = os.path.splitext(basename)
-
- # Gather the list of inputs and outputs, expanding $vars if possible.
- outputs = [self.ExpandRuleVariables(o, root, dirname,
- source, ext, basename)
- for o in rule['outputs']]
- inputs = [self.ExpandRuleVariables(i, root, dirname,
- source, ext, basename)
- for i in rule.get('inputs', [])]
+ inputs, outputs = self._GetInputsAndOutputsForRule(rule, source)
if int(rule.get('process_outputs_as_sources', False)):
- extra_sources += outputs
+ sources.update(outputs)
if int(rule.get('process_outputs_as_mac_bundle_resources', False)):
extra_mac_bundle_resources += outputs
« no previous file with comments | « no previous file | test/chained-rules/action.input » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698