| 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 if self.toolset != 'target': | 496 if self.toolset != 'target': |
| 497 verb += '(%s)' % self.toolset | 497 verb += '(%s)' % self.toolset |
| 498 if message: | 498 if message: |
| 499 return '%s %s' % (verb, self.ExpandSpecial(message)) | 499 return '%s %s' % (verb, self.ExpandSpecial(message)) |
| 500 else: | 500 else: |
| 501 return '%s %s: %s' % (verb, self.name, fallback) | 501 return '%s %s: %s' % (verb, self.name, fallback) |
| 502 | 502 |
| 503 def WriteActions(self, actions, extra_sources, prebuild, | 503 def WriteActions(self, actions, extra_sources, prebuild, |
| 504 extra_mac_bundle_resources): | 504 extra_mac_bundle_resources): |
| 505 # Actions cd into the base directory. | 505 # Actions cd into the base directory. |
| 506 env = self.GetXcodeEnv() | 506 env = self.GetSortedXcodeEnv() |
| 507 if self.flavor == 'win': | 507 if self.flavor == 'win': |
| 508 env = self.msvs_settings.GetVSMacroEnv('$!PRODUCT_DIR') | 508 env = self.msvs_settings.GetVSMacroEnv('$!PRODUCT_DIR') |
| 509 all_outputs = [] | 509 all_outputs = [] |
| 510 for action in actions: | 510 for action in actions: |
| 511 # First write out a rule for the action. | 511 # First write out a rule for the action. |
| 512 name = re.sub(r'[ {}$]', '_', action['action_name']) | 512 name = re.sub(r'[ {}$]', '_', action['action_name']) |
| 513 description = self.GenerateDescription('ACTION', | 513 description = self.GenerateDescription('ACTION', |
| 514 action.get('message', None), | 514 action.get('message', None), |
| 515 name) | 515 name) |
| 516 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action) | 516 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 implicit=inputs, | 615 implicit=inputs, |
| 616 order_only=prebuild, | 616 order_only=prebuild, |
| 617 variables=extra_bindings) | 617 variables=extra_bindings) |
| 618 | 618 |
| 619 all_outputs.extend(outputs) | 619 all_outputs.extend(outputs) |
| 620 | 620 |
| 621 return all_outputs | 621 return all_outputs |
| 622 | 622 |
| 623 def WriteCopies(self, copies, prebuild): | 623 def WriteCopies(self, copies, prebuild): |
| 624 outputs = [] | 624 outputs = [] |
| 625 env = self.GetXcodeEnv() | 625 env = self.GetSortedXcodeEnv() |
| 626 for copy in copies: | 626 for copy in copies: |
| 627 for path in copy['files']: | 627 for path in copy['files']: |
| 628 # Normalize the path so trailing slashes don't confuse us. | 628 # Normalize the path so trailing slashes don't confuse us. |
| 629 path = os.path.normpath(path) | 629 path = os.path.normpath(path) |
| 630 basename = os.path.split(path)[1] | 630 basename = os.path.split(path)[1] |
| 631 src = self.GypPathToNinja(path, env) | 631 src = self.GypPathToNinja(path, env) |
| 632 dst = self.GypPathToNinja(os.path.join(copy['destination'], basename), | 632 dst = self.GypPathToNinja(os.path.join(copy['destination'], basename), |
| 633 env) | 633 env) |
| 634 outputs += self.ninja.build(dst, 'copy', src, order_only=prebuild) | 634 outputs += self.ninja.build(dst, 'copy', src, order_only=prebuild) |
| 635 | 635 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 652 if not info_plist: | 652 if not info_plist: |
| 653 return | 653 return |
| 654 if defines: | 654 if defines: |
| 655 # Create an intermediate file to store preprocessed results. | 655 # Create an intermediate file to store preprocessed results. |
| 656 intermediate_plist = self.GypPathToUniqueOutput( | 656 intermediate_plist = self.GypPathToUniqueOutput( |
| 657 os.path.basename(info_plist)) | 657 os.path.basename(info_plist)) |
| 658 defines = ' '.join([Define(d, self.flavor) for d in defines]) | 658 defines = ' '.join([Define(d, self.flavor) for d in defines]) |
| 659 info_plist = self.ninja.build(intermediate_plist, 'infoplist', info_plist, | 659 info_plist = self.ninja.build(intermediate_plist, 'infoplist', info_plist, |
| 660 variables=[('defines',defines)]) | 660 variables=[('defines',defines)]) |
| 661 | 661 |
| 662 env = self.GetXcodeEnv(additional_settings=extra_env) | 662 env = self.GetSortedXcodeEnv(additional_settings=extra_env) |
| 663 env = self.ComputeExportEnvString(env) | 663 env = self.ComputeExportEnvString(env) |
| 664 | 664 |
| 665 self.ninja.build(out, 'mac_tool', info_plist, | 665 self.ninja.build(out, 'mac_tool', info_plist, |
| 666 variables=[('mactool_cmd', 'copy-info-plist'), | 666 variables=[('mactool_cmd', 'copy-info-plist'), |
| 667 ('env', env)]) | 667 ('env', env)]) |
| 668 bundle_depends.append(out) | 668 bundle_depends.append(out) |
| 669 | 669 |
| 670 def WriteSources(self, config_name, config, sources, predepends, | 670 def WriteSources(self, config_name, config, sources, predepends, |
| 671 precompiled_header): | 671 precompiled_header): |
| 672 """Write build rules to compile all of |sources|.""" | 672 """Write build rules to compile all of |sources|.""" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 if package_framework: | 899 if package_framework: |
| 900 variables.append(('version', self.xcode_settings.GetFrameworkVersion())) | 900 variables.append(('version', self.xcode_settings.GetFrameworkVersion())) |
| 901 self.ninja.build(output, 'package_framework', mac_bundle_depends, | 901 self.ninja.build(output, 'package_framework', mac_bundle_depends, |
| 902 variables=variables) | 902 variables=variables) |
| 903 else: | 903 else: |
| 904 self.ninja.build(output, 'stamp', mac_bundle_depends, | 904 self.ninja.build(output, 'stamp', mac_bundle_depends, |
| 905 variables=variables) | 905 variables=variables) |
| 906 self.target.bundle = output | 906 self.target.bundle = output |
| 907 return output | 907 return output |
| 908 | 908 |
| 909 def GetXcodeEnv(self, additional_settings=None): | 909 def GetSortedXcodeEnv(self, additional_settings=None): |
| 910 """Returns the variables Xcode would set for build steps.""" | 910 """Returns the variables Xcode would set for build steps.""" |
| 911 assert self.abs_build_dir | 911 assert self.abs_build_dir |
| 912 abs_build_dir = self.abs_build_dir | 912 abs_build_dir = self.abs_build_dir |
| 913 return gyp.xcode_emulation.GetXcodeEnv( | 913 return gyp.xcode_emulation.GetSortedXcodeEnv( |
| 914 self.xcode_settings, abs_build_dir, | 914 self.xcode_settings, abs_build_dir, |
| 915 os.path.join(abs_build_dir, self.build_to_base), self.config_name, | 915 os.path.join(abs_build_dir, self.build_to_base), self.config_name, |
| 916 additional_settings) | 916 additional_settings) |
| 917 | 917 |
| 918 def GetXcodePostbuildEnv(self): | 918 def GetSortedXcodePostbuildEnv(self): |
| 919 """Returns the variables Xcode would set for postbuild steps.""" | 919 """Returns the variables Xcode would set for postbuild steps.""" |
| 920 postbuild_settings = {} | 920 postbuild_settings = {} |
| 921 # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack. | 921 # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack. |
| 922 # TODO(thakis): It would be nice to have some general mechanism instead. | 922 # TODO(thakis): It would be nice to have some general mechanism instead. |
| 923 strip_save_file = self.xcode_settings.GetPerTargetSetting( | 923 strip_save_file = self.xcode_settings.GetPerTargetSetting( |
| 924 'CHROMIUM_STRIP_SAVE_FILE') | 924 'CHROMIUM_STRIP_SAVE_FILE') |
| 925 if strip_save_file: | 925 if strip_save_file: |
| 926 postbuild_settings['CHROMIUM_STRIP_SAVE_FILE'] = strip_save_file | 926 postbuild_settings['CHROMIUM_STRIP_SAVE_FILE'] = strip_save_file |
| 927 return self.GetXcodeEnv(additional_settings=postbuild_settings) | 927 return self.GetSortedXcodeEnv(additional_settings=postbuild_settings) |
| 928 | 928 |
| 929 def GetPostbuildCommand(self, spec, output, output_binary, | 929 def GetPostbuildCommand(self, spec, output, output_binary, |
| 930 is_command_start=False): | 930 is_command_start=False): |
| 931 """Returns a shell command that runs all the postbuilds, and removes | 931 """Returns a shell command that runs all the postbuilds, and removes |
| 932 |output| if any of them fails. If |is_command_start| is False, then the | 932 |output| if any of them fails. If |is_command_start| is False, then the |
| 933 returned string will start with ' && '.""" | 933 returned string will start with ' && '.""" |
| 934 if not self.xcode_settings or spec['type'] == 'none' or not output: | 934 if not self.xcode_settings or spec['type'] == 'none' or not output: |
| 935 return '' | 935 return '' |
| 936 output = QuoteShellArgument(output, self.flavor) | 936 output = QuoteShellArgument(output, self.flavor) |
| 937 target_postbuilds = self.xcode_settings.GetTargetPostbuilds( | 937 target_postbuilds = self.xcode_settings.GetTargetPostbuilds( |
| 938 self.config_name, | 938 self.config_name, |
| 939 os.path.normpath(os.path.join(self.base_to_build, output)), | 939 os.path.normpath(os.path.join(self.base_to_build, output)), |
| 940 QuoteShellArgument( | 940 QuoteShellArgument( |
| 941 os.path.normpath(os.path.join(self.base_to_build, output_binary)), | 941 os.path.normpath(os.path.join(self.base_to_build, output_binary)), |
| 942 self.flavor), | 942 self.flavor), |
| 943 quiet=True) | 943 quiet=True) |
| 944 postbuilds = gyp.xcode_emulation.GetSpecPostbuildCommands(spec, quiet=True) | 944 postbuilds = gyp.xcode_emulation.GetSpecPostbuildCommands(spec, quiet=True) |
| 945 postbuilds = target_postbuilds + postbuilds | 945 postbuilds = target_postbuilds + postbuilds |
| 946 if not postbuilds: | 946 if not postbuilds: |
| 947 return '' | 947 return '' |
| 948 # Postbuilds expect to be run in the gyp file's directory, so insert an | 948 # Postbuilds expect to be run in the gyp file's directory, so insert an |
| 949 # implicit postbuild to cd to there. | 949 # implicit postbuild to cd to there. |
| 950 postbuilds.insert(0, gyp.common.EncodePOSIXShellList( | 950 postbuilds.insert(0, gyp.common.EncodePOSIXShellList( |
| 951 ['cd', self.build_to_base])) | 951 ['cd', self.build_to_base])) |
| 952 env = self.ComputeExportEnvString(self.GetXcodePostbuildEnv()) | 952 env = self.ComputeExportEnvString(self.GetSortedXcodePostbuildEnv()) |
| 953 # G will be non-null if any postbuild fails. Run all postbuilds in a | 953 # G will be non-null if any postbuild fails. Run all postbuilds in a |
| 954 # subshell. | 954 # subshell. |
| 955 commands = env + ' (F=0; ' + \ | 955 commands = env + ' (F=0; ' + \ |
| 956 ' '.join([ninja_syntax.escape(command) + ' || F=$$?;' | 956 ' '.join([ninja_syntax.escape(command) + ' || F=$$?;' |
| 957 for command in postbuilds]) | 957 for command in postbuilds]) |
| 958 command_string = (commands + ' exit $$F); G=$$?; ' | 958 command_string = (commands + ' exit $$F); G=$$?; ' |
| 959 # Remove the final output if any postbuild failed. | 959 # Remove the final output if any postbuild failed. |
| 960 '((exit $$G) || rm -rf %s) ' % output + '&& exit $$G)') | 960 '((exit $$G) || rm -rf %s) ' % output + '&& exit $$G)') |
| 961 if is_command_start: | 961 if is_command_start: |
| 962 return '(' + command_string + ' && ' | 962 return '(' + command_string + ' && ' |
| 963 else: | 963 else: |
| 964 return '$ && (' + command_string | 964 return '$ && (' + command_string |
| 965 | 965 |
| 966 def ComputeExportEnvString(self, env): | 966 def ComputeExportEnvString(self, env): |
| 967 """Given an environment, returns a string looking like | 967 """Given an environment, returns a string looking like |
| 968 'export FOO=foo; export BAR="${FOO} bar;' | 968 'export FOO=foo; export BAR="${FOO} bar;' |
| 969 that exports |env| to the shell.""" | 969 that exports |env| to the shell.""" |
| 970 export_str = [] | 970 export_str = [] |
| 971 for k in gyp.xcode_emulation.TopologicallySortedEnvVarKeys(env): | 971 for k, v in env: |
| 972 export_str.append('export %s=%s;' % | 972 export_str.append('export %s=%s;' % |
| 973 (k, ninja_syntax.escape(gyp.common.EncodePOSIXShellArgument(env[k])))) | 973 (k, ninja_syntax.escape(gyp.common.EncodePOSIXShellArgument(v)))) |
| 974 return ' '.join(export_str) | 974 return ' '.join(export_str) |
| 975 | 975 |
| 976 def ComputeMacBundleOutput(self): | 976 def ComputeMacBundleOutput(self): |
| 977 """Return the 'output' (full output path) to a bundle output directory.""" | 977 """Return the 'output' (full output path) to a bundle output directory.""" |
| 978 assert self.is_mac_bundle | 978 assert self.is_mac_bundle |
| 979 path = self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']) | 979 path = self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']) |
| 980 return os.path.join(path, self.xcode_settings.GetWrapperName()) | 980 return os.path.join(path, self.xcode_settings.GetWrapperName()) |
| 981 | 981 |
| 982 def ComputeMacBundleBinaryOutput(self): | 982 def ComputeMacBundleBinaryOutput(self): |
| 983 """Return the 'output' (full output path) to the binary in a bundle.""" | 983 """Return the 'output' (full output path) to the binary in a bundle.""" |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 | 1528 |
| 1529 user_config = params.get('generator_flags', {}).get('config', None) | 1529 user_config = params.get('generator_flags', {}).get('config', None) |
| 1530 if user_config: | 1530 if user_config: |
| 1531 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1531 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 1532 user_config) | 1532 user_config) |
| 1533 else: | 1533 else: |
| 1534 config_names = target_dicts[target_list[0]]['configurations'].keys() | 1534 config_names = target_dicts[target_list[0]]['configurations'].keys() |
| 1535 for config_name in config_names: | 1535 for config_name in config_names: |
| 1536 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1536 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 1537 config_name) | 1537 config_name) |
| OLD | NEW |