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.system_test | 9 import gyp.system_test |
9 import gyp.xcode_emulation | 10 import gyp.xcode_emulation |
10 import os.path | 11 import os.path |
11 import re | 12 import re |
12 import subprocess | 13 import subprocess |
13 import sys | 14 import sys |
14 | 15 |
15 import gyp.ninja_syntax as ninja_syntax | 16 import gyp.ninja_syntax as ninja_syntax |
16 | 17 |
17 generator_default_variables = { | 18 generator_default_variables = { |
(...skipping 30 matching lines...) Expand all Loading... |
48 # - how to decide what the host compiler is (should not just be $cc). | 49 # - how to decide what the host compiler is (should not just be $cc). |
49 # - need ld_host as well. | 50 # - need ld_host as well. |
50 generator_supports_multiple_toolsets = False | 51 generator_supports_multiple_toolsets = False |
51 | 52 |
52 | 53 |
53 def StripPrefix(arg, prefix): | 54 def StripPrefix(arg, prefix): |
54 if arg.startswith(prefix): | 55 if arg.startswith(prefix): |
55 return arg[len(prefix):] | 56 return arg[len(prefix):] |
56 return arg | 57 return arg |
57 | 58 |
58 | 59 def QuoteShellArgument(arg, flavor): |
59 def QuoteShellArgument(arg): | |
60 """Quote a string such that it will be interpreted as a single argument | 60 """Quote a string such that it will be interpreted as a single argument |
61 by the shell.""" | 61 by the shell.""" |
62 # Rather than attempting to enumerate the bad shell characters, just | 62 # Rather than attempting to enumerate the bad shell characters, just |
63 # whitelist common OK ones and quote anything else. | 63 # whitelist common OK ones and quote anything else. |
64 if re.match(r'^[a-zA-Z0-9_=-]+$', arg): | 64 if re.match(r'^[a-zA-Z0-9_=-]+$', arg): |
65 return arg # No quoting necessary. | 65 return arg # No quoting necessary. |
| 66 if flavor == 'win': |
| 67 return gyp.msvs_emulation.QuoteCmdExeArgument(arg) |
66 return "'" + arg.replace("'", "'" + '"\'"' + "'") + "'" | 68 return "'" + arg.replace("'", "'" + '"\'"' + "'") + "'" |
67 | 69 |
68 | |
69 def InvertRelativePath(path): | 70 def InvertRelativePath(path): |
70 """Given a relative path like foo/bar, return the inverse relative path: | 71 """Given a relative path like foo/bar, return the inverse relative path: |
71 the path from the relative path back to the origin dir. | 72 the path from the relative path back to the origin dir. |
72 | 73 |
73 E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path))) | 74 E.g. os.path.normpath(os.path.join(path, InvertRelativePath(path))) |
74 should always produce the empty string.""" | 75 should always produce the empty string.""" |
75 | 76 |
76 if not path: | 77 if not path: |
77 return path | 78 return path |
78 # Only need to handle relative paths into subdirectories for now. | 79 # Only need to handle relative paths into subdirectories for now. |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist( | 550 info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist( |
550 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), | 551 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), |
551 self.xcode_settings, self.GypPathToNinja) | 552 self.xcode_settings, self.GypPathToNinja) |
552 if not info_plist: | 553 if not info_plist: |
553 return | 554 return |
554 if defines: | 555 if defines: |
555 # Create an intermediate file to store preprocessed results. | 556 # Create an intermediate file to store preprocessed results. |
556 intermediate_plist = self.GypPathToUniqueOutput( | 557 intermediate_plist = self.GypPathToUniqueOutput( |
557 os.path.basename(info_plist)) | 558 os.path.basename(info_plist)) |
558 defines = ' '.join( | 559 defines = ' '.join( |
559 [QuoteShellArgument(ninja_syntax.escape('-D' + d)) for d in defines]) | 560 [QuoteShellArgument(ninja_syntax.escape('-D' + d), self.flavor) |
| 561 for d in defines]) |
560 info_plist = self.ninja.build(intermediate_plist, 'infoplist', info_plist, | 562 info_plist = self.ninja.build(intermediate_plist, 'infoplist', info_plist, |
561 variables=[('defines',defines)]) | 563 variables=[('defines',defines)]) |
562 | 564 |
563 env = self.GetXcodeEnv(additional_settings=extra_env) | 565 env = self.GetXcodeEnv(additional_settings=extra_env) |
564 env = self.ComputeExportEnvString(env) | 566 env = self.ComputeExportEnvString(env) |
565 | 567 |
566 self.ninja.build(out, 'mac_tool', info_plist, | 568 self.ninja.build(out, 'mac_tool', info_plist, |
567 variables=[('mactool_cmd', 'copy-info-plist'), | 569 variables=[('mactool_cmd', 'copy-info-plist'), |
568 ('env', env)]) | 570 ('env', env)]) |
569 bundle_depends.append(out) | 571 bundle_depends.append(out) |
(...skipping 12 matching lines...) Expand all Loading... |
582 cflags_objc = ['$cflags_c'] + \ | 584 cflags_objc = ['$cflags_c'] + \ |
583 self.xcode_settings.GetCflagsObjC(config_name) | 585 self.xcode_settings.GetCflagsObjC(config_name) |
584 cflags_objcc = ['$cflags_cc'] + \ | 586 cflags_objcc = ['$cflags_cc'] + \ |
585 self.xcode_settings.GetCflagsObjCC(config_name) | 587 self.xcode_settings.GetCflagsObjCC(config_name) |
586 else: | 588 else: |
587 cflags = config.get('cflags', []) | 589 cflags = config.get('cflags', []) |
588 cflags_c = config.get('cflags_c', []) | 590 cflags_c = config.get('cflags_c', []) |
589 cflags_cc = config.get('cflags_cc', []) | 591 cflags_cc = config.get('cflags_cc', []) |
590 | 592 |
591 self.WriteVariableList('defines', | 593 self.WriteVariableList('defines', |
592 [QuoteShellArgument(ninja_syntax.escape('-D' + d)) | 594 [QuoteShellArgument(ninja_syntax.escape('-D' + d), self.flavor) |
593 for d in config.get('defines', [])]) | 595 for d in config.get('defines', [])]) |
594 self.WriteVariableList('includes', | 596 self.WriteVariableList('includes', |
595 ['-I' + self.GypPathToNinja(i) | 597 ['-I' + self.GypPathToNinja(i) |
596 for i in config.get('include_dirs', [])]) | 598 for i in config.get('include_dirs', [])]) |
597 | 599 |
598 pch_commands = precompiled_header.GetGchBuildCommands() | 600 pch_commands = precompiled_header.GetGchBuildCommands() |
599 if self.flavor == 'mac': | 601 if self.flavor == 'mac': |
600 self.WriteVariableList('cflags_pch_c', | 602 self.WriteVariableList('cflags_pch_c', |
601 [precompiled_header.GetInclude('c')]) | 603 [precompiled_header.GetInclude('c')]) |
602 self.WriteVariableList('cflags_pch_cc', | 604 self.WriteVariableList('cflags_pch_cc', |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 strip_save_file) | 780 strip_save_file) |
779 return self.GetXcodeEnv(additional_settings=postbuild_settings) | 781 return self.GetXcodeEnv(additional_settings=postbuild_settings) |
780 | 782 |
781 def GetPostbuildCommand(self, spec, output, output_binary, | 783 def GetPostbuildCommand(self, spec, output, output_binary, |
782 is_command_start=False): | 784 is_command_start=False): |
783 """Returns a shell command that runs all the postbuilds, and removes | 785 """Returns a shell command that runs all the postbuilds, and removes |
784 |output| if any of them fails. If |is_command_start| is False, then the | 786 |output| if any of them fails. If |is_command_start| is False, then the |
785 returned string will start with ' && '.""" | 787 returned string will start with ' && '.""" |
786 if not self.xcode_settings or spec['type'] == 'none' or not output: | 788 if not self.xcode_settings or spec['type'] == 'none' or not output: |
787 return '' | 789 return '' |
788 output = QuoteShellArgument(output) | 790 output = QuoteShellArgument(output, self.flavor) |
789 target_postbuilds = self.xcode_settings.GetTargetPostbuilds( | 791 target_postbuilds = self.xcode_settings.GetTargetPostbuilds( |
790 self.config_name, output, QuoteShellArgument(output_binary), quiet=True) | 792 self.config_name, |
| 793 output, |
| 794 QuoteShellArgument(output_binary, self.flavor), |
| 795 quiet=True) |
791 postbuilds = gyp.xcode_emulation.GetSpecPostbuildCommands( | 796 postbuilds = gyp.xcode_emulation.GetSpecPostbuildCommands( |
792 spec, self.GypPathToNinja, quiet=True) | 797 spec, self.GypPathToNinja, quiet=True) |
793 postbuilds = target_postbuilds + postbuilds | 798 postbuilds = target_postbuilds + postbuilds |
794 if not postbuilds: | 799 if not postbuilds: |
795 return '' | 800 return '' |
796 env = self.ComputeExportEnvString(self.GetXcodePostbuildEnv()) | 801 env = self.ComputeExportEnvString(self.GetXcodePostbuildEnv()) |
797 commands = env + ' F=0; ' + \ | 802 commands = env + ' F=0; ' + \ |
798 ' '.join([ninja_syntax.escape(command) + ' || F=$$?;' | 803 ' '.join([ninja_syntax.escape(command) + ' || F=$$?;' |
799 for command in postbuilds]) | 804 for command in postbuilds]) |
800 command_string = env + commands + ' ((exit $$F) || rm -rf %s) ' % output + \ | 805 command_string = env + commands + ' ((exit $$F) || rm -rf %s) ' % output + \ |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 | 1252 |
1248 user_config = params.get('generator_flags', {}).get('config', None) | 1253 user_config = params.get('generator_flags', {}).get('config', None) |
1249 if user_config: | 1254 if user_config: |
1250 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1255 GenerateOutputForConfig(target_list, target_dicts, data, params, |
1251 user_config) | 1256 user_config) |
1252 else: | 1257 else: |
1253 config_names = target_dicts[target_list[0]]['configurations'].keys() | 1258 config_names = target_dicts[target_list[0]]['configurations'].keys() |
1254 for config_name in config_names: | 1259 for config_name in config_names: |
1255 GenerateOutputForConfig(target_list, target_dicts, data, params, | 1260 GenerateOutputForConfig(target_list, target_dicts, data, params, |
1256 config_name) | 1261 config_name) |
OLD | NEW |