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

Side by Side Diff: pylib/gyp/generator/ninja.py

Issue 10893030: ninja windows: Fix special variables not getting emitted when expanded from VS macros (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: copyright Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/rules/gyptest-special-variables.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import copy 5 import copy
6 import hashlib 6 import hashlib
7 import os.path 7 import os.path
8 import re 8 import re
9 import subprocess 9 import subprocess
10 import sys 10 import sys
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 for action in actions: 542 for action in actions:
543 # First write out a rule for the action. 543 # First write out a rule for the action.
544 name = '%s_%s' % (action['action_name'], 544 name = '%s_%s' % (action['action_name'],
545 hashlib.md5(self.qualified_target).hexdigest()) 545 hashlib.md5(self.qualified_target).hexdigest())
546 description = self.GenerateDescription('ACTION', 546 description = self.GenerateDescription('ACTION',
547 action.get('message', None), 547 action.get('message', None),
548 name) 548 name)
549 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action) 549 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action)
550 if self.flavor == 'win' else False) 550 if self.flavor == 'win' else False)
551 args = action['action'] 551 args = action['action']
552 rule_name = self.WriteNewNinjaRule(name, args, description, 552 rule_name, _ = self.WriteNewNinjaRule(name, args, description,
553 is_cygwin, env=env) 553 is_cygwin, env=env)
554 554
555 inputs = [self.GypPathToNinja(i, env) for i in action['inputs']] 555 inputs = [self.GypPathToNinja(i, env) for i in action['inputs']]
556 if int(action.get('process_outputs_as_sources', False)): 556 if int(action.get('process_outputs_as_sources', False)):
557 extra_sources += action['outputs'] 557 extra_sources += action['outputs']
558 if int(action.get('process_outputs_as_mac_bundle_resources', False)): 558 if int(action.get('process_outputs_as_mac_bundle_resources', False)):
559 extra_mac_bundle_resources += action['outputs'] 559 extra_mac_bundle_resources += action['outputs']
560 outputs = [self.GypPathToNinja(o, env) for o in action['outputs']] 560 outputs = [self.GypPathToNinja(o, env) for o in action['outputs']]
561 561
562 # Then write out an edge using the rule. 562 # Then write out an edge using the rule.
563 self.ninja.build(outputs, rule_name, inputs, 563 self.ninja.build(outputs, rule_name, inputs,
(...skipping 14 matching lines...) Expand all
578 # Skip a rule with no action and no inputs. 578 # Skip a rule with no action and no inputs.
579 if 'action' not in rule and not rule.get('rule_sources', []): 579 if 'action' not in rule and not rule.get('rule_sources', []):
580 continue 580 continue
581 args = rule['action'] 581 args = rule['action']
582 description = self.GenerateDescription( 582 description = self.GenerateDescription(
583 'RULE', 583 'RULE',
584 rule.get('message', None), 584 rule.get('message', None),
585 ('%s ' + generator_default_variables['RULE_INPUT_PATH']) % name) 585 ('%s ' + generator_default_variables['RULE_INPUT_PATH']) % name)
586 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(rule) 586 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(rule)
587 if self.flavor == 'win' else False) 587 if self.flavor == 'win' else False)
588 rule_name = self.WriteNewNinjaRule(name, args, description, is_cygwin) 588 rule_name, args = self.WriteNewNinjaRule(
589 name, args, description, is_cygwin)
589 590
590 # TODO: if the command references the outputs directly, we should 591 # TODO: if the command references the outputs directly, we should
591 # simplify it to just use $out. 592 # simplify it to just use $out.
592 593
593 # Rules can potentially make use of some special variables which 594 # Rules can potentially make use of some special variables which
594 # must vary per source file. 595 # must vary per source file.
595 # Compute the list of variables we'll need to provide. 596 # Compute the list of variables we'll need to provide.
596 special_locals = ('source', 'root', 'dirname', 'ext', 'name') 597 special_locals = ('source', 'root', 'dirname', 'ext', 'name')
597 needed_variables = set(['source']) 598 needed_variables = set(['source'])
598 for argument in args: 599 for argument in args:
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 1139
1139 def WriteVariableList(self, var, values): 1140 def WriteVariableList(self, var, values):
1140 assert not isinstance(values, str) 1141 assert not isinstance(values, str)
1141 if values is None: 1142 if values is None:
1142 values = [] 1143 values = []
1143 self.ninja.variable(var, ' '.join(values)) 1144 self.ninja.variable(var, ' '.join(values))
1144 1145
1145 def WriteNewNinjaRule(self, name, args, description, is_cygwin, env=[]): 1146 def WriteNewNinjaRule(self, name, args, description, is_cygwin, env=[]):
1146 """Write out a new ninja "rule" statement for a given command. 1147 """Write out a new ninja "rule" statement for a given command.
1147 1148
1148 Returns the name of the new rule.""" 1149 Returns the name of the new rule, and a copy of |args| with variables
1150 expanded."""
1149 1151
1150 if self.flavor == 'win': 1152 if self.flavor == 'win':
1151 args = [self.msvs_settings.ConvertVSMacros( 1153 args = [self.msvs_settings.ConvertVSMacros(
1152 arg, self.base_to_build, config=self.config_name) 1154 arg, self.base_to_build, config=self.config_name)
1153 for arg in args] 1155 for arg in args]
1154 description = self.msvs_settings.ConvertVSMacros( 1156 description = self.msvs_settings.ConvertVSMacros(
1155 description, config=self.config_name) 1157 description, config=self.config_name)
1156 elif self.flavor == 'mac': 1158 elif self.flavor == 'mac':
1157 args = [gyp.xcode_emulation.ExpandEnvVars(arg, env) for arg in args] 1159 args = [gyp.xcode_emulation.ExpandEnvVars(arg, env) for arg in args]
1158 description = gyp.xcode_emulation.ExpandEnvVars(description, env) 1160 description = gyp.xcode_emulation.ExpandEnvVars(description, env)
1159 1161
1160 # TODO: we shouldn't need to qualify names; we do it because 1162 # TODO: we shouldn't need to qualify names; we do it because
1161 # currently the ninja rule namespace is global, but it really 1163 # currently the ninja rule namespace is global, but it really
1162 # should be scoped to the subninja. 1164 # should be scoped to the subninja.
1163 rule_name = self.name 1165 rule_name = self.name
1164 if self.toolset == 'target': 1166 if self.toolset == 'target':
1165 rule_name += '.' + self.toolset 1167 rule_name += '.' + self.toolset
1166 rule_name += '.' + name 1168 rule_name += '.' + name
1167 rule_name = re.sub('[^a-zA-Z0-9_]', '_', rule_name) 1169 rule_name = re.sub('[^a-zA-Z0-9_]', '_', rule_name)
1168 1170
1169 description = re.sub('[^ a-zA-Z0-9_]', '_', description) 1171 description = re.sub('[^ a-zA-Z0-9_]', '_', description)
1170 1172
1171 args = args[:]
1172
1173 # gyp dictates that commands are run from the base directory. 1173 # gyp dictates that commands are run from the base directory.
1174 # cd into the directory before running, and adjust paths in 1174 # cd into the directory before running, and adjust paths in
1175 # the arguments to point to the proper locations. 1175 # the arguments to point to the proper locations.
1176 rspfile = None 1176 rspfile = None
1177 rspfile_content = None 1177 rspfile_content = None
1178 args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args] 1178 args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args]
1179 if self.flavor == 'win': 1179 if self.flavor == 'win':
1180 rspfile = rule_name + '.$unique_name.rsp' 1180 rspfile = rule_name + '.$unique_name.rsp'
1181 # The cygwin case handles this inside the bash sub-shell. 1181 # The cygwin case handles this inside the bash sub-shell.
1182 run_in = '' if is_cygwin else ' ' + self.build_to_base 1182 run_in = '' if is_cygwin else ' ' + self.build_to_base
(...skipping 13 matching lines...) Expand all
1196 command = ninja_syntax.escape(command) 1196 command = ninja_syntax.escape(command)
1197 command = 'cd %s; ' % self.build_to_base + env + command 1197 command = 'cd %s; ' % self.build_to_base + env + command
1198 1198
1199 # GYP rules/actions express being no-ops by not touching their outputs. 1199 # GYP rules/actions express being no-ops by not touching their outputs.
1200 # Avoid executing downstream dependencies in this case by specifying 1200 # Avoid executing downstream dependencies in this case by specifying
1201 # restat=1 to ninja. 1201 # restat=1 to ninja.
1202 self.ninja.rule(rule_name, command, description, restat=True, 1202 self.ninja.rule(rule_name, command, description, restat=True,
1203 rspfile=rspfile, rspfile_content=rspfile_content) 1203 rspfile=rspfile, rspfile_content=rspfile_content)
1204 self.ninja.newline() 1204 self.ninja.newline()
1205 1205
1206 return rule_name 1206 return rule_name, args
1207 1207
1208 1208
1209 def CalculateVariables(default_variables, params): 1209 def CalculateVariables(default_variables, params):
1210 """Calculate additional variables for use in the build (called by gyp).""" 1210 """Calculate additional variables for use in the build (called by gyp)."""
1211 global generator_additional_non_configuration_keys 1211 global generator_additional_non_configuration_keys
1212 global generator_additional_path_sections 1212 global generator_additional_path_sections
1213 flavor = gyp.common.GetFlavor(params) 1213 flavor = gyp.common.GetFlavor(params)
1214 if flavor == 'mac': 1214 if flavor == 'mac':
1215 default_variables.setdefault('OS', 'mac') 1215 default_variables.setdefault('OS', 'mac')
1216 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib') 1216 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib')
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 1712
1713 user_config = params.get('generator_flags', {}).get('config', None) 1713 user_config = params.get('generator_flags', {}).get('config', None)
1714 if user_config: 1714 if user_config:
1715 GenerateOutputForConfig(target_list, target_dicts, data, params, 1715 GenerateOutputForConfig(target_list, target_dicts, data, params,
1716 user_config) 1716 user_config)
1717 else: 1717 else:
1718 config_names = target_dicts[target_list[0]]['configurations'].keys() 1718 config_names = target_dicts[target_list[0]]['configurations'].keys()
1719 for config_name in config_names: 1719 for config_name in config_names:
1720 GenerateOutputForConfig(target_list, target_dicts, data, params, 1720 GenerateOutputForConfig(target_list, target_dicts, data, params,
1721 config_name) 1721 config_name)
OLDNEW
« no previous file with comments | « no previous file | test/rules/gyptest-special-variables.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698