diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2011-12-03 21:26:50 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2011-12-03 21:28:17 +0100 |
commit | e90623edc2befb06602ff8c3e01809ba0a21d593 (patch) | |
tree | 142a84aa010f924262925eb2b959d292d6624576 /tools/gyp/pylib/gyp/generator/ninja.py | |
parent | 49ba55b10045969d9dba89ee11a53ca2d35d8f7f (diff) | |
download | android-node-v8-e90623edc2befb06602ff8c3e01809ba0a21d593.tar.gz android-node-v8-e90623edc2befb06602ff8c3e01809ba0a21d593.tar.bz2 android-node-v8-e90623edc2befb06602ff8c3e01809ba0a21d593.zip |
gyp: upgrade to r1103
Diffstat (limited to 'tools/gyp/pylib/gyp/generator/ninja.py')
-rw-r--r-- | tools/gyp/pylib/gyp/generator/ninja.py | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/tools/gyp/pylib/gyp/generator/ninja.py b/tools/gyp/pylib/gyp/generator/ninja.py index f044f3746c..b307da650d 100644 --- a/tools/gyp/pylib/gyp/generator/ninja.py +++ b/tools/gyp/pylib/gyp/generator/ninja.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - # Copyright (c) 2011 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -65,12 +63,6 @@ def QuoteShellArgument(arg): return "'" + arg.replace("'", "'" + '"\'"' + "'") + "'" -def MaybeQuoteShellArgument(arg): - if '"' in arg or ' ' in arg: - return QuoteShellArgument(arg) - return arg - - def InvertRelativePath(path): """Given a relative path like foo/bar, return the inverse relative path: the path from the relative path back to the origin dir. @@ -154,6 +146,15 @@ class NinjaWriter: return path + def ExpandRuleVariables(self, path, root, dirname, source, ext, name): + path = path.replace(generator_default_variables['RULE_INPUT_ROOT'], root) + path = path.replace(generator_default_variables['RULE_INPUT_DIRNAME'], + dirname) + path = path.replace(generator_default_variables['RULE_INPUT_PATH'], source) + path = path.replace(generator_default_variables['RULE_INPUT_EXT'], ext) + path = path.replace(generator_default_variables['RULE_INPUT_NAME'], name) + return path + def GypPathToNinja(self, path): """Translate a gyp path to a ninja path. @@ -211,7 +212,8 @@ class NinjaWriter: def WriteSpec(self, spec, config): """The main entry point for NinjaWriter: write the build rules for a spec. - Returns the path to the build output, or None.""" + Returns the path to the build output, or None, and a list of targets for + dependencies of its compile steps.""" self.name = spec['target_name'] self.toolset = spec['toolset'] @@ -226,43 +228,56 @@ class NinjaWriter: spec['type'] = 'none' # Compute predepends for all rules. - # prebuild is the dependencies this target depends on before - # running any of its internal steps. - prebuild = [] + # actions_depends is the dependencies this target depends on before running + # any of its action/rule/copy steps. + # compile_depends is the dependencies this target depends on before running + # any of its compile steps. + actions_depends = [] + compile_depends = [] if 'dependencies' in spec: for dep in spec['dependencies']: if dep in self.target_outputs: - prebuild.append(self.target_outputs[dep][0]) - prebuild = self.WriteCollapsedDependencies('predepends', prebuild) + input, precompile_input, linkable = self.target_outputs[dep] + actions_depends.append(input) + compile_depends.extend(precompile_input) + actions_depends = self.WriteCollapsedDependencies('actions_depends', + actions_depends) # 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 = [] - sources_predepends = self.WriteActionsRulesCopies(spec, extra_sources, - prebuild) + sources_depends = self.WriteActionsRulesCopies(spec, extra_sources, + actions_depends) + + # If we have actions/rules/copies, we depend directly on those, but + # otherwise we depend on dependent target's actions/rules/copies etc. + # We never need to explicitly depend on previous target's link steps, + # because no compile ever depends on them. + compile_depends = self.WriteCollapsedDependencies('compile_depends', + sources_depends or compile_depends) # Write out the compilation steps, if any. link_deps = [] sources = spec.get('sources', []) + extra_sources if sources: - link_deps = self.WriteSources(config, sources, - sources_predepends or prebuild) + link_deps = self.WriteSources(config, sources, compile_depends) # Some actions/rules output 'sources' that are already object files. link_deps += [self.GypPathToNinja(f) for f in sources if f.endswith('.o')] # The final output of our target depends on the last output of the # above steps. output = None - final_deps = link_deps or sources_predepends or prebuild + final_deps = link_deps or sources_depends or actions_depends if final_deps: - output = self.WriteTarget(spec, config, final_deps) + output = self.WriteTarget(spec, config, final_deps, + order_only=actions_depends) if self.name != output and self.toolset == 'target': # Write a short name to build this target. This benefits both the # "build chrome" case as well as the gyp tests, which expect to be # able to run actions and build libraries by their short name. self.ninja.build(self.name, 'phony', output) - return output + return output, compile_depends def WriteActionsRulesCopies(self, spec, extra_sources, prebuild): """Write out the Actions, Rules, and Copies steps. Return any outputs @@ -351,9 +366,8 @@ class NinjaWriter: # Gather the list of outputs, expanding $vars if possible. outputs = [] for output in rule['outputs']: - outputs.append(output.replace( - generator_default_variables['RULE_INPUT_ROOT'], root).replace( - generator_default_variables['RULE_INPUT_DIRNAME'], dirname)) + outputs.append(self.ExpandRuleVariables(output, root, dirname, + source, ext, basename)) if int(rule.get('process_outputs_as_sources', False)): extra_sources += outputs @@ -409,14 +423,17 @@ class NinjaWriter: self.ninja.variable('cxx', '$cxx_host') self.WriteVariableList('defines', - ['-D' + MaybeQuoteShellArgument(ninja_syntax.escape(d)) + [QuoteShellArgument(ninja_syntax.escape('-D' + d)) for d in config.get('defines', [])]) self.WriteVariableList('includes', ['-I' + self.GypPathToNinja(i) for i in config.get('include_dirs', [])]) - self.WriteVariableList('cflags', config.get('cflags')) - self.WriteVariableList('cflags_c', config.get('cflags_c')) - self.WriteVariableList('cflags_cc', config.get('cflags_cc')) + self.WriteVariableList('cflags', map(self.ExpandSpecial, + config.get('cflags', []))) + self.WriteVariableList('cflags_c', map(self.ExpandSpecial, + config.get('cflags_c', []))) + self.WriteVariableList('cflags_cc', map(self.ExpandSpecial, + config.get('cflags_cc', []))) self.ninja.newline() outputs = [] for source in sources: @@ -437,7 +454,7 @@ class NinjaWriter: self.ninja.newline() return outputs - def WriteTarget(self, spec, config, final_deps): + def WriteTarget(self, spec, config, final_deps, order_only): if spec['type'] == 'none': # This target doesn't have any explicit final output, but is instead # used for its effects before the final output (e.g. copies steps). @@ -460,7 +477,7 @@ class NinjaWriter: if output_uses_linker: extra_deps = set() for dep in spec['dependencies']: - input, linkable = self.target_outputs.get(dep, (None, False)) + input, _, linkable = self.target_outputs.get(dep, (None, [], False)) if not input: continue if linkable: @@ -494,6 +511,7 @@ class NinjaWriter: self.ninja.build(output, command, final_deps, implicit=list(implicit_deps), + order_only=order_only, variables=extra_bindings) return output @@ -711,10 +729,10 @@ def GenerateOutput(target_list, target_dicts, data, params): output_file))) master_ninja.subninja(output_file) - output = writer.WriteSpec(spec, config) + output, compile_depends = writer.WriteSpec(spec, config) if output: linkable = spec['type'] in ('static_library', 'shared_library') - target_outputs[qualified_target] = (output, linkable) + target_outputs[qualified_target] = (output, compile_depends, linkable) if qualified_target in all_targets: all_outputs.add(output) |