| OLD | NEW |
| 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 gyp | 6 import gyp |
| 7 import gyp.common | 7 import gyp.common |
| 8 import gyp.msvs_emulation | 8 import gyp.msvs_emulation |
| 9 import gyp.MSVSVersion | 9 import gyp.MSVSVersion |
| 10 import gyp.system_test | 10 import gyp.system_test |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 env = self.GetXcodeEnv() | 486 env = self.GetXcodeEnv() |
| 487 if self.flavor == 'win': | 487 if self.flavor == 'win': |
| 488 env = self.msvs_settings.GetVSMacroEnv('$!PRODUCT_DIR') | 488 env = self.msvs_settings.GetVSMacroEnv('$!PRODUCT_DIR') |
| 489 all_outputs = [] | 489 all_outputs = [] |
| 490 for action in actions: | 490 for action in actions: |
| 491 # First write out a rule for the action. | 491 # First write out a rule for the action. |
| 492 name = re.sub(r'[ {}$]', '_', action['action_name']) | 492 name = re.sub(r'[ {}$]', '_', action['action_name']) |
| 493 description = self.GenerateDescription('ACTION', | 493 description = self.GenerateDescription('ACTION', |
| 494 action.get('message', None), | 494 action.get('message', None), |
| 495 name) | 495 name) |
| 496 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action) | 496 win_shell_flags = (self.msvs_settings.GetRuleShellFlags(action) |
| 497 if self.flavor == 'win' else False) | 497 if self.flavor == 'win' else None) |
| 498 args = action['action'] | 498 args = action['action'] |
| 499 args = [self.msvs_settings.ConvertVSMacros(arg, self.base_to_build) | 499 args = [self.msvs_settings.ConvertVSMacros(arg, self.base_to_build) |
| 500 for arg in args] if self.flavor == 'win' else args | 500 for arg in args] if self.flavor == 'win' else args |
| 501 rule_name = self.WriteNewNinjaRule(name, args, description, | 501 rule_name = self.WriteNewNinjaRule(name, args, description, |
| 502 is_cygwin, env=env) | 502 win_shell_flags, env=env) |
| 503 | 503 |
| 504 inputs = [self.GypPathToNinja(i, env) for i in action['inputs']] | 504 inputs = [self.GypPathToNinja(i, env) for i in action['inputs']] |
| 505 if int(action.get('process_outputs_as_sources', False)): | 505 if int(action.get('process_outputs_as_sources', False)): |
| 506 extra_sources += action['outputs'] | 506 extra_sources += action['outputs'] |
| 507 if int(action.get('process_outputs_as_mac_bundle_resources', False)): | 507 if int(action.get('process_outputs_as_mac_bundle_resources', False)): |
| 508 extra_mac_bundle_resources += action['outputs'] | 508 extra_mac_bundle_resources += action['outputs'] |
| 509 outputs = [self.GypPathToNinja(o, env) for o in action['outputs']] | 509 outputs = [self.GypPathToNinja(o, env) for o in action['outputs']] |
| 510 | 510 |
| 511 # Then write out an edge using the rule. | 511 # Then write out an edge using the rule. |
| 512 self.ninja.build(outputs, rule_name, inputs, | 512 self.ninja.build(outputs, rule_name, inputs, |
| 513 order_only=prebuild) | 513 order_only=prebuild) |
| 514 all_outputs += outputs | 514 all_outputs += outputs |
| 515 | 515 |
| 516 self.ninja.newline() | 516 self.ninja.newline() |
| 517 | 517 |
| 518 return all_outputs | 518 return all_outputs |
| 519 | 519 |
| 520 def WriteRules(self, rules, extra_sources, prebuild, | 520 def WriteRules(self, rules, extra_sources, prebuild, |
| 521 extra_mac_bundle_resources): | 521 extra_mac_bundle_resources): |
| 522 all_outputs = [] | 522 all_outputs = [] |
| 523 for rule in rules: | 523 for rule in rules: |
| 524 # First write out a rule for the rule action. | 524 # First write out a rule for the rule action. |
| 525 name = rule['rule_name'] | 525 name = rule['rule_name'] |
| 526 args = rule['action'] | 526 args = rule['action'] |
| 527 description = self.GenerateDescription( | 527 description = self.GenerateDescription( |
| 528 'RULE', | 528 'RULE', |
| 529 rule.get('message', None), | 529 rule.get('message', None), |
| 530 ('%s ' + generator_default_variables['RULE_INPUT_PATH']) % name) | 530 ('%s ' + generator_default_variables['RULE_INPUT_PATH']) % name) |
| 531 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(rule) | 531 win_shell_flags = (self.msvs_settings.GetRuleShellFlags(rule) |
| 532 if self.flavor == 'win' else False) | 532 if self.flavor == 'win' else None) |
| 533 args = [self.msvs_settings.ConvertVSMacros(arg, self.base_to_build) | 533 args = [self.msvs_settings.ConvertVSMacros(arg, self.base_to_build) |
| 534 for arg in args] if self.flavor == 'win' else args | 534 for arg in args] if self.flavor == 'win' else args |
| 535 rule_name = self.WriteNewNinjaRule(name, args, description, is_cygwin) | 535 rule_name = self.WriteNewNinjaRule( |
| 536 name, args, description, win_shell_flags) |
| 536 | 537 |
| 537 # TODO: if the command references the outputs directly, we should | 538 # TODO: if the command references the outputs directly, we should |
| 538 # simplify it to just use $out. | 539 # simplify it to just use $out. |
| 539 | 540 |
| 540 # Rules can potentially make use of some special variables which | 541 # Rules can potentially make use of some special variables which |
| 541 # must vary per source file. | 542 # must vary per source file. |
| 542 # Compute the list of variables we'll need to provide. | 543 # Compute the list of variables we'll need to provide. |
| 543 special_locals = ('source', 'root', 'dirname', 'ext', 'name') | 544 special_locals = ('source', 'root', 'dirname', 'ext', 'name') |
| 544 needed_variables = set(['source']) | 545 needed_variables = set(['source']) |
| 545 for argument in args: | 546 for argument in args: |
| 546 for var in special_locals: | 547 for var in special_locals: |
| 547 if ('${%s}' % var) in argument: | 548 if ('${%s}' % var) in argument: |
| 548 needed_variables.add(var) | 549 needed_variables.add(var) |
| 549 | 550 |
| 550 def cygwin_munge(path): | 551 def cygwin_munge(path): |
| 551 if is_cygwin: | 552 if win_shell_flags and win_shell_flags.cygwin: |
| 552 return path.replace('\\', '/') | 553 return path.replace('\\', '/') |
| 553 return path | 554 return path |
| 554 | 555 |
| 555 # For each source file, write an edge that generates all the outputs. | 556 # For each source file, write an edge that generates all the outputs. |
| 556 for source in rule.get('rule_sources', []): | 557 for source in rule.get('rule_sources', []): |
| 557 dirname, basename = os.path.split(source) | 558 dirname, basename = os.path.split(source) |
| 558 root, ext = os.path.splitext(basename) | 559 root, ext = os.path.splitext(basename) |
| 559 | 560 |
| 560 # Gather the list of inputs and outputs, expanding $vars if possible. | 561 # Gather the list of inputs and outputs, expanding $vars if possible. |
| 561 outputs = [self.ExpandRuleVariables(o, root, dirname, | 562 outputs = [self.ExpandRuleVariables(o, root, dirname, |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 return os.path.join(libdir, filename) | 1057 return os.path.join(libdir, filename) |
| 1057 else: | 1058 else: |
| 1058 return self.GypPathToUniqueOutput(filename, qualified=False) | 1059 return self.GypPathToUniqueOutput(filename, qualified=False) |
| 1059 | 1060 |
| 1060 def WriteVariableList(self, var, values): | 1061 def WriteVariableList(self, var, values): |
| 1061 assert not isinstance(values, str) | 1062 assert not isinstance(values, str) |
| 1062 if values is None: | 1063 if values is None: |
| 1063 values = [] | 1064 values = [] |
| 1064 self.ninja.variable(var, ' '.join(values)) | 1065 self.ninja.variable(var, ' '.join(values)) |
| 1065 | 1066 |
| 1066 def WriteNewNinjaRule(self, name, args, description, is_cygwin, env={}): | 1067 def WriteNewNinjaRule(self, name, args, description, win_shell_flags, env={}): |
| 1067 """Write out a new ninja "rule" statement for a given command. | 1068 """Write out a new ninja "rule" statement for a given command. |
| 1068 | 1069 |
| 1069 Returns the name of the new rule.""" | 1070 Returns the name of the new rule.""" |
| 1070 | 1071 |
| 1071 # TODO: we shouldn't need to qualify names; we do it because | 1072 # TODO: we shouldn't need to qualify names; we do it because |
| 1072 # currently the ninja rule namespace is global, but it really | 1073 # currently the ninja rule namespace is global, but it really |
| 1073 # should be scoped to the subninja. | 1074 # should be scoped to the subninja. |
| 1074 rule_name = self.name | 1075 rule_name = self.name |
| 1075 if self.toolset == 'target': | 1076 if self.toolset == 'target': |
| 1076 rule_name += '.' + self.toolset | 1077 rule_name += '.' + self.toolset |
| 1077 rule_name += '.' + name | 1078 rule_name += '.' + name |
| 1078 rule_name = rule_name.translate(string.maketrans(' ()', '___')) | 1079 rule_name = rule_name.translate(string.maketrans(' ()', '___')) |
| 1079 | 1080 |
| 1080 args = args[:] | 1081 args = args[:] |
| 1081 | 1082 |
| 1082 if self.flavor == 'win': | 1083 if self.flavor == 'win': |
| 1083 description = self.msvs_settings.ConvertVSMacros(description) | 1084 description = self.msvs_settings.ConvertVSMacros(description) |
| 1084 | 1085 |
| 1085 # gyp dictates that commands are run from the base directory. | 1086 # gyp dictates that commands are run from the base directory. |
| 1086 # cd into the directory before running, and adjust paths in | 1087 # cd into the directory before running, and adjust paths in |
| 1087 # the arguments to point to the proper locations. | 1088 # the arguments to point to the proper locations. |
| 1088 if self.flavor == 'win': | 1089 if self.flavor == 'win': |
| 1089 cd = 'cmd /s /c "' | 1090 cd = 'cmd /s /c "' |
| 1090 if not is_cygwin: | 1091 if not win_shell_flags.cygwin: |
| 1091 # cd command added by BuildCygwinBashCommandLine in cygwin case. | 1092 # cd command added by BuildCygwinBashCommandLine in cygwin case. |
| 1092 cd += 'cd %s && ' % self.build_to_base | 1093 cd += 'cd %s && ' % self.build_to_base |
| 1093 else: | 1094 else: |
| 1094 cd = 'cd %s; ' % self.build_to_base | 1095 cd = 'cd %s; ' % self.build_to_base |
| 1095 args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args] | 1096 args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args] |
| 1096 env = self.ComputeExportEnvString(env) if self.flavor != 'win' else '' | 1097 env = self.ComputeExportEnvString(env) if self.flavor != 'win' else '' |
| 1097 if self.flavor == 'win': | 1098 if self.flavor == 'win': |
| 1098 if is_cygwin: | 1099 if win_shell_flags.cygwin: |
| 1099 command = self.msvs_settings.BuildCygwinBashCommandLine( | 1100 command = self.msvs_settings.BuildCygwinBashCommandLine( |
| 1100 args, self.build_to_base) | 1101 args, self.build_to_base) |
| 1101 else: | 1102 else: |
| 1102 # If there's no command, fake one to match the dangling |&&| above. | 1103 # If there's no command, fake one to match the dangling |&&| above. |
| 1103 command = gyp.msvs_emulation.EncodeRspFileList(args) or 'cmd /c' | 1104 command = gyp.msvs_emulation.EncodeRspFileList( |
| 1105 args, win_shell_flags.quote) or 'cmd /c' |
| 1104 command += '"' # Close quote opened in |cd|. | 1106 command += '"' # Close quote opened in |cd|. |
| 1105 else: | 1107 else: |
| 1106 command = gyp.common.EncodePOSIXShellList(args) | 1108 command = gyp.common.EncodePOSIXShellList(args) |
| 1107 if env: | 1109 if env: |
| 1108 # If an environment is passed in, variables in the command should be | 1110 # If an environment is passed in, variables in the command should be |
| 1109 # read from it, instead of from ninja's internal variables. | 1111 # read from it, instead of from ninja's internal variables. |
| 1110 command = ninja_syntax.escape(command) | 1112 command = ninja_syntax.escape(command) |
| 1111 | 1113 |
| 1112 command = cd + env + command | 1114 command = cd + env + command |
| 1113 # GYP rules/actions express being no-ops by not touching their outputs. | 1115 # GYP rules/actions express being no-ops by not touching their outputs. |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1487 | 1489 |
| 1488 user_config = params.get('generator_flags', {}).get('config', None) | 1490 user_config = params.get('generator_flags', {}).get('config', None) |
| 1489 if user_config: | 1491 if user_config: |
| 1490 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1492 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 1491 user_config) | 1493 user_config) |
| 1492 else: | 1494 else: |
| 1493 config_names = target_dicts[target_list[0]]['configurations'].keys() | 1495 config_names = target_dicts[target_list[0]]['configurations'].keys() |
| 1494 for config_name in config_names: | 1496 for config_name in config_names: |
| 1495 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1497 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 1496 config_name) | 1498 config_name) |
| OLD | NEW |