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 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 new_includes = [i for i in includes if i not in all_system_includes] | 178 new_includes = [i for i in includes if i not in all_system_includes] |
179 config['msvs_system_include_dirs'] = new_includes | 179 config['msvs_system_include_dirs'] = new_includes |
180 return expanded_system_includes | 180 return expanded_system_includes |
181 | 181 |
182 | 182 |
183 class MsvsSettings(object): | 183 class MsvsSettings(object): |
184 """A class that understands the gyp 'msvs_...' values (especially the | 184 """A class that understands the gyp 'msvs_...' values (especially the |
185 msvs_settings field). They largely correpond to the VS2008 IDE DOM. This | 185 msvs_settings field). They largely correpond to the VS2008 IDE DOM. This |
186 class helps map those settings to command line options.""" | 186 class helps map those settings to command line options.""" |
187 | 187 |
188 # A dictionary of default target extensions by type. | |
scottmg
2014/10/03 22:19:59
this is very similar to MSVSUtil.py, could it reus
chrisha
2014/10/06 13:40:49
Indeed it is. Removed it from here, and reused the
| |
189 _DEFAULT_EXTENSIONS_BY_TYPE = { | |
190 'loadable_module': 'dll', | |
191 'shared_library': 'dll', | |
192 'static_library': 'lib', | |
193 'executable': 'exe', | |
194 } | |
195 | |
188 def __init__(self, spec, generator_flags): | 196 def __init__(self, spec, generator_flags): |
189 self.spec = spec | 197 self.spec = spec |
190 self.vs_version = GetVSVersion(generator_flags) | 198 self.vs_version = GetVSVersion(generator_flags) |
191 | 199 |
192 supported_fields = [ | 200 supported_fields = [ |
193 ('msvs_configuration_attributes', dict), | 201 ('msvs_configuration_attributes', dict), |
194 ('msvs_settings', dict), | 202 ('msvs_settings', dict), |
195 ('msvs_system_include_dirs', list), | 203 ('msvs_system_include_dirs', list), |
196 ('msvs_disabled_warnings', list), | 204 ('msvs_disabled_warnings', list), |
197 ('msvs_precompiled_header', str), | 205 ('msvs_precompiled_header', str), |
(...skipping 15 matching lines...) Expand all Loading... | |
213 ] | 221 ] |
214 unsupported = [] | 222 unsupported = [] |
215 for field in unsupported_fields: | 223 for field in unsupported_fields: |
216 for config in configs.values(): | 224 for config in configs.values(): |
217 if field in config: | 225 if field in config: |
218 unsupported += ["%s not supported (target %s)." % | 226 unsupported += ["%s not supported (target %s)." % |
219 (field, spec['target_name'])] | 227 (field, spec['target_name'])] |
220 if unsupported: | 228 if unsupported: |
221 raise Exception('\n'.join(unsupported)) | 229 raise Exception('\n'.join(unsupported)) |
222 | 230 |
231 def GetExtension(self): | |
232 """Returns the extension for the target, with no leading dot. | |
233 | |
234 Uses 'product_extension' if specified, otherwise uses MSVS defaults based on | |
235 the target type. | |
236 """ | |
237 ext = self.spec.get('product_extension', None) | |
238 if ext: | |
239 return ext | |
240 return self._DEFAULT_EXTENSIONS_BY_TYPE.get(self.spec['type'], '') | |
241 | |
223 def GetVSMacroEnv(self, base_to_build=None, config=None): | 242 def GetVSMacroEnv(self, base_to_build=None, config=None): |
224 """Get a dict of variables mapping internal VS macro names to their gyp | 243 """Get a dict of variables mapping internal VS macro names to their gyp |
225 equivalents.""" | 244 equivalents.""" |
226 target_platform = 'Win32' if self.GetArch(config) == 'x86' else 'x64' | 245 target_platform = 'Win32' if self.GetArch(config) == 'x86' else 'x64' |
227 target_name = self.spec.get('product_prefix', '') + \ | 246 target_name = self.spec.get('product_prefix', '') + \ |
228 self.spec.get('product_name', self.spec['target_name']) | 247 self.spec.get('product_name', self.spec['target_name']) |
229 target_dir = base_to_build + '\\' if base_to_build else '' | 248 target_dir = base_to_build + '\\' if base_to_build else '' |
249 target_ext = '.' + self.GetExtension() | |
250 target_file_name = target_name + target_ext | |
251 | |
230 replacements = { | 252 replacements = { |
253 '$(InputName)': '${root}', | |
254 '$(InputPath)': '${source}', | |
255 '$(IntDir)': '$!INTERMEDIATE_DIR', | |
231 '$(OutDir)\\': target_dir, | 256 '$(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, | 257 '$(PlatformName)': target_platform, |
239 '$(ProjectDir)\\': '', | 258 '$(ProjectDir)\\': '', |
259 '$(ProjectName)': self.spec['target_name'], | |
260 '$(TargetDir)\\': target_dir, | |
261 '$(TargetExt)': target_ext, | |
262 '$(TargetFileName)': target_file_name, | |
263 '$(TargetName)': target_name, | |
264 '$(TargetPath)': os.path.join(target_dir, target_file_name), | |
240 } | 265 } |
241 replacements.update(GetGlobalVSMacroEnv(self.vs_version)) | 266 replacements.update(GetGlobalVSMacroEnv(self.vs_version)) |
242 return replacements | 267 return replacements |
243 | 268 |
244 def ConvertVSMacros(self, s, base_to_build=None, config=None): | 269 def ConvertVSMacros(self, s, base_to_build=None, config=None): |
245 """Convert from VS macro names to something equivalent.""" | 270 """Convert from VS macro names to something equivalent.""" |
246 env = self.GetVSMacroEnv(base_to_build, config=config) | 271 env = self.GetVSMacroEnv(base_to_build, config=config) |
247 return ExpandMacros(s, env) | 272 return ExpandMacros(s, env) |
248 | 273 |
249 def AdjustLibraries(self, libraries): | 274 def AdjustLibraries(self, libraries): |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 | 1054 |
1030 # To determine processor word size on Windows, in addition to checking | 1055 # To determine processor word size on Windows, in addition to checking |
1031 # PROCESSOR_ARCHITECTURE (which reflects the word size of the current | 1056 # PROCESSOR_ARCHITECTURE (which reflects the word size of the current |
1032 # process), it is also necessary to check PROCESSOR_ARCHITEW6432 (which | 1057 # process), it is also necessary to check PROCESSOR_ARCHITEW6432 (which |
1033 # contains the actual word size of the system when running thru WOW64). | 1058 # contains the actual word size of the system when running thru WOW64). |
1034 if ('64' in os.environ.get('PROCESSOR_ARCHITECTURE', '') or | 1059 if ('64' in os.environ.get('PROCESSOR_ARCHITECTURE', '') or |
1035 '64' in os.environ.get('PROCESSOR_ARCHITEW6432', '')): | 1060 '64' in os.environ.get('PROCESSOR_ARCHITEW6432', '')): |
1036 default_variables['MSVS_OS_BITS'] = 64 | 1061 default_variables['MSVS_OS_BITS'] = 64 |
1037 else: | 1062 else: |
1038 default_variables['MSVS_OS_BITS'] = 32 | 1063 default_variables['MSVS_OS_BITS'] = 32 |
OLD | NEW |