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 """ | 5 """ |
6 This module helps emulate Visual Studio 2008 behavior on top of other | 6 This module helps emulate Visual Studio 2008 behavior on top of other |
7 build systems, primarily ninja. | 7 build systems, primarily ninja. |
8 """ | 8 """ |
9 | 9 |
10 import os | 10 import os |
11 import re | 11 import re |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 | 14 |
15 from gyp.common import OrderedSet | 15 from gyp.common import OrderedSet |
| 16 import gyp.MSVSUtil |
16 import gyp.MSVSVersion | 17 import gyp.MSVSVersion |
17 | 18 |
| 19 |
18 windows_quoter_regex = re.compile(r'(\\*)"') | 20 windows_quoter_regex = re.compile(r'(\\*)"') |
19 | 21 |
| 22 |
20 def QuoteForRspFile(arg): | 23 def QuoteForRspFile(arg): |
21 """Quote a command line argument so that it appears as one argument when | 24 """Quote a command line argument so that it appears as one argument when |
22 processed via cmd.exe and parsed by CommandLineToArgvW (as is typical for | 25 processed via cmd.exe and parsed by CommandLineToArgvW (as is typical for |
23 Windows programs).""" | 26 Windows programs).""" |
24 # See http://goo.gl/cuFbX and http://goo.gl/dhPnp including the comment | 27 # See http://goo.gl/cuFbX and http://goo.gl/dhPnp including the comment |
25 # threads. This is actually the quoting rules for CommandLineToArgvW, not | 28 # threads. This is actually the quoting rules for CommandLineToArgvW, not |
26 # for the shell, because the shell doesn't do anything in Windows. This | 29 # for the shell, because the shell doesn't do anything in Windows. This |
27 # works more or less because most programs (including the compiler, etc.) | 30 # works more or less because most programs (including the compiler, etc.) |
28 # use that function to handle command line arguments. | 31 # use that function to handle command line arguments. |
29 | 32 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 ] | 216 ] |
214 unsupported = [] | 217 unsupported = [] |
215 for field in unsupported_fields: | 218 for field in unsupported_fields: |
216 for config in configs.values(): | 219 for config in configs.values(): |
217 if field in config: | 220 if field in config: |
218 unsupported += ["%s not supported (target %s)." % | 221 unsupported += ["%s not supported (target %s)." % |
219 (field, spec['target_name'])] | 222 (field, spec['target_name'])] |
220 if unsupported: | 223 if unsupported: |
221 raise Exception('\n'.join(unsupported)) | 224 raise Exception('\n'.join(unsupported)) |
222 | 225 |
| 226 def GetExtension(self): |
| 227 """Returns the extension for the target, with no leading dot. |
| 228 |
| 229 Uses 'product_extension' if specified, otherwise uses MSVS defaults based on |
| 230 the target type. |
| 231 """ |
| 232 ext = self.spec.get('product_extension', None) |
| 233 if ext: |
| 234 return ext |
| 235 return gyp.MSVSUtil.TARGET_TYPE_EXT.get(self.spec['type'], '') |
| 236 |
223 def GetVSMacroEnv(self, base_to_build=None, config=None): | 237 def GetVSMacroEnv(self, base_to_build=None, config=None): |
224 """Get a dict of variables mapping internal VS macro names to their gyp | 238 """Get a dict of variables mapping internal VS macro names to their gyp |
225 equivalents.""" | 239 equivalents.""" |
226 target_platform = 'Win32' if self.GetArch(config) == 'x86' else 'x64' | 240 target_platform = 'Win32' if self.GetArch(config) == 'x86' else 'x64' |
227 target_name = self.spec.get('product_prefix', '') + \ | 241 target_name = self.spec.get('product_prefix', '') + \ |
228 self.spec.get('product_name', self.spec['target_name']) | 242 self.spec.get('product_name', self.spec['target_name']) |
229 target_dir = base_to_build + '\\' if base_to_build else '' | 243 target_dir = base_to_build + '\\' if base_to_build else '' |
| 244 target_ext = '.' + self.GetExtension() |
| 245 target_file_name = target_name + target_ext |
| 246 |
230 replacements = { | 247 replacements = { |
| 248 '$(InputName)': '${root}', |
| 249 '$(InputPath)': '${source}', |
| 250 '$(IntDir)': '$!INTERMEDIATE_DIR', |
231 '$(OutDir)\\': target_dir, | 251 '$(OutDir)\\': target_dir, |
232 '$(TargetDir)\\': target_dir, | |
233 '$(IntDir)': '$!INTERMEDIATE_DIR', | |
234 '$(InputPath)': '${source}', | |
235 '$(InputName)': '${root}', | |
236 '$(ProjectName)': self.spec['target_name'], | |
237 '$(TargetName)': target_name, | |
238 '$(PlatformName)': target_platform, | 252 '$(PlatformName)': target_platform, |
239 '$(ProjectDir)\\': '', | 253 '$(ProjectDir)\\': '', |
| 254 '$(ProjectName)': self.spec['target_name'], |
| 255 '$(TargetDir)\\': target_dir, |
| 256 '$(TargetExt)': target_ext, |
| 257 '$(TargetFileName)': target_file_name, |
| 258 '$(TargetName)': target_name, |
| 259 '$(TargetPath)': os.path.join(target_dir, target_file_name), |
240 } | 260 } |
241 replacements.update(GetGlobalVSMacroEnv(self.vs_version)) | 261 replacements.update(GetGlobalVSMacroEnv(self.vs_version)) |
242 return replacements | 262 return replacements |
243 | 263 |
244 def ConvertVSMacros(self, s, base_to_build=None, config=None): | 264 def ConvertVSMacros(self, s, base_to_build=None, config=None): |
245 """Convert from VS macro names to something equivalent.""" | 265 """Convert from VS macro names to something equivalent.""" |
246 env = self.GetVSMacroEnv(base_to_build, config=config) | 266 env = self.GetVSMacroEnv(base_to_build, config=config) |
247 return ExpandMacros(s, env) | 267 return ExpandMacros(s, env) |
248 | 268 |
249 def AdjustLibraries(self, libraries): | 269 def AdjustLibraries(self, libraries): |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 | 1049 |
1030 # To determine processor word size on Windows, in addition to checking | 1050 # To determine processor word size on Windows, in addition to checking |
1031 # PROCESSOR_ARCHITECTURE (which reflects the word size of the current | 1051 # PROCESSOR_ARCHITECTURE (which reflects the word size of the current |
1032 # process), it is also necessary to check PROCESSOR_ARCHITEW6432 (which | 1052 # process), it is also necessary to check PROCESSOR_ARCHITEW6432 (which |
1033 # contains the actual word size of the system when running thru WOW64). | 1053 # contains the actual word size of the system when running thru WOW64). |
1034 if ('64' in os.environ.get('PROCESSOR_ARCHITECTURE', '') or | 1054 if ('64' in os.environ.get('PROCESSOR_ARCHITECTURE', '') or |
1035 '64' in os.environ.get('PROCESSOR_ARCHITEW6432', '')): | 1055 '64' in os.environ.get('PROCESSOR_ARCHITEW6432', '')): |
1036 default_variables['MSVS_OS_BITS'] = 64 | 1056 default_variables['MSVS_OS_BITS'] = 64 |
1037 else: | 1057 else: |
1038 default_variables['MSVS_OS_BITS'] = 32 | 1058 default_variables['MSVS_OS_BITS'] = 32 |
OLD | NEW |