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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 123 |
124 self.msvs_cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.']) | 124 self.msvs_cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.']) |
125 | 125 |
126 def ConvertVSMacros(self, s): | 126 def ConvertVSMacros(self, s): |
127 """Convert from VS macro names to something equivalent.""" | 127 """Convert from VS macro names to something equivalent.""" |
128 if '$' in s: | 128 if '$' in s: |
129 replacements = { | 129 replacements = { |
130 '$(VSInstallDir)': self.vs_version.Path(), | 130 '$(VSInstallDir)': self.vs_version.Path(), |
131 '$(VCInstallDir)': os.path.join(self.vs_version.Path(), 'VC'), | 131 '$(VCInstallDir)': os.path.join(self.vs_version.Path(), 'VC'), |
132 '$(OutDir)\\': '', | 132 '$(OutDir)\\': '', |
133 '$(IntDir)': '$!INTERMEDIATE_DIR', | |
Nico
2012/04/05 04:37:11
Does msvc differentiate between intermediate_dir (
scottmg
2012/04/05 17:52:42
Hmm, good question. It looks like $(IntDir) is the
| |
134 '$(InputName)': '${root}', | |
133 } | 135 } |
134 dxsdk_dir = os.environ.get('DXSDK_DIR') | 136 dxsdk_dir = os.environ.get('DXSDK_DIR') |
135 if dxsdk_dir: | 137 if dxsdk_dir: |
136 replacements['$(DXSDK_DIR)'] = dxsdk_dir + '\\' | 138 replacements['$(DXSDK_DIR)'] = dxsdk_dir + '\\' |
137 for old, new in replacements.iteritems(): | 139 for old, new in replacements.iteritems(): |
138 s = s.replace(old, new) | 140 s = s.replace(old, new) |
139 return s | 141 return s |
140 | 142 |
141 def AdjustLibraries(self, libraries): | 143 def AdjustLibraries(self, libraries): |
142 """Strip -l from library if it's specified with that.""" | 144 """Strip -l from library if it's specified with that.""" |
143 return [lib[2:] if lib.startswith('-l') else lib for lib in libraries] | 145 return [lib[2:] if lib.startswith('-l') else lib for lib in libraries] |
144 | 146 |
145 def _GetAndMunge(self, field, path, default, prefix, append, map): | 147 def _GetAndMunge(self, field, path, default, prefix, append, map): |
146 """Retrieve a value from |field| at |path| or return |default|. If | 148 """Retrieve a value from |field| at |path| or return |default|. If |
147 |append| is specified, and the item is found, it will be appended to that | 149 |append| is specified, and the item is found, it will be appended to that |
148 object instead of returned. If |map| is specified, results will be | 150 object instead of returned. If |map| is specified, results will be |
149 remapped through |map| before being returned or appended.""" | 151 remapped through |map| before being returned or appended.""" |
150 result = _GenericRetrieve(field, default, path) | 152 result = _GenericRetrieve(field, default, path) |
151 result = _DoRemapping(result, map) | 153 result = _DoRemapping(result, map) |
152 result = _AddPrefix(result, prefix) | 154 result = _AddPrefix(result, prefix) |
153 return _AppendOrReturn(append, result) | 155 return _AppendOrReturn(append, result) |
154 | 156 |
155 class _GetWrapper(object): | 157 class _GetWrapper(object): |
156 def __init__(self, parent, field, base_path, append=None): | 158 def __init__(self, parent, field, base_path, append=None): |
157 self.parent = parent | 159 self.parent = parent |
158 self.field = field | 160 self.field = field |
159 self.base_path = [base_path] | 161 self.base_path = [base_path] |
160 self.append = append | 162 self.append = append |
161 def __call__(self, name, map=None, prefix=''): | 163 def __call__(self, name, map=None, prefix='', default=None): |
162 return self.parent._GetAndMunge(self.field, self.base_path + [name], | 164 return self.parent._GetAndMunge(self.field, self.base_path + [name], |
163 default=None, prefix=prefix, append=self.append, map=map) | 165 default=default, prefix=prefix, append=self.append, map=map) |
164 | 166 |
165 def _Setting(self, path, config, | 167 def _Setting(self, path, config, |
166 default=None, prefix='', append=None, map=None): | 168 default=None, prefix='', append=None, map=None): |
167 """_GetAndMunge for msvs_settings.""" | 169 """_GetAndMunge for msvs_settings.""" |
168 return self._GetAndMunge( | 170 return self._GetAndMunge( |
169 self.msvs_settings[config], path, default, prefix, append, map) | 171 self.msvs_settings[config], path, default, prefix, append, map) |
170 | 172 |
171 def _ConfigAttrib(self, path, config, | 173 def _ConfigAttrib(self, path, config, |
172 default=None, prefix='', append=None, map=None): | 174 default=None, prefix='', append=None, map=None): |
173 """_GetAndMunge for msvs_configuration_attributes.""" | 175 """_GetAndMunge for msvs_configuration_attributes.""" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 'call "%s\\setup_env.bat" && set CYGWIN=nontsec && ' % cygwin_dir + | 321 'call "%s\\setup_env.bat" && set CYGWIN=nontsec && ' % cygwin_dir + |
320 'bash -c "%s ; %s"' % (cd, bash_cmd)) | 322 'bash -c "%s ; %s"' % (cd, bash_cmd)) |
321 return cmd | 323 return cmd |
322 | 324 |
323 def IsRuleRunUnderCygwin(self, rule): | 325 def IsRuleRunUnderCygwin(self, rule): |
324 """Determine if an action should be run under cygwin. If the variable is | 326 """Determine if an action should be run under cygwin. If the variable is |
325 unset, or set to 1 we use cygwin.""" | 327 unset, or set to 1 we use cygwin.""" |
326 return int(rule.get('msvs_cygwin_shell', | 328 return int(rule.get('msvs_cygwin_shell', |
327 self.spec.get('msvs_cygwin_shell', 1))) != 0 | 329 self.spec.get('msvs_cygwin_shell', 1))) != 0 |
328 | 330 |
331 def GetIdlBuildData(self, source, config): | |
332 """Determine the implicit outputs for an idl file. Returns output | |
333 directory, outputs, and variables and flags that are required.""" | |
334 midl_get = self._GetWrapper(self, self.msvs_settings[config], 'VCMIDLTool') | |
335 def midl(name, default=None): | |
336 return self.ConvertVSMacros(midl_get(name, default=default)) | |
337 tlb = midl('TypeLibraryName', default='${root}.tlb') | |
338 header = midl('HeaderFileName', default='${root}.h') | |
339 dlldata = midl('DLLDataFileName', default='dlldata.c') | |
340 iid = midl('InterfaceIdentifierFileName', default='${root}_i.c') | |
341 proxy = midl('ProxyFileName', default='${root}_p.c') | |
342 # Note that .tlb is not included in the outputs as it is not always | |
343 # generated depending on the content of the input idl file. | |
344 outdir = midl('OutputDirectory') | |
Nico
2012/04/05 04:37:11
It looks like this gets ConvertVSMacros()d here al
scottmg
2012/04/05 17:52:42
Done.
| |
345 output = [header, dlldata, iid, proxy] | |
346 variables = [('tlb', tlb), | |
347 ('h', header), | |
348 ('dlldata', dlldata), | |
349 ('iid', iid), | |
350 ('proxy', proxy)] | |
351 # TODO(scottmg): Non-default configuration maybe? | |
352 flags = ['/char', 'signed', '/env', 'win32', '/Oicf'] | |
353 return outdir, output, variables, flags | |
354 | |
329 vs_version = None | 355 vs_version = None |
330 def GetVSVersion(generator_flags): | 356 def GetVSVersion(generator_flags): |
331 global vs_version | 357 global vs_version |
332 if not vs_version: | 358 if not vs_version: |
333 vs_version = gyp.MSVSVersion.SelectVisualStudioVersion( | 359 vs_version = gyp.MSVSVersion.SelectVisualStudioVersion( |
334 generator_flags.get('msvs_version', 'auto')) | 360 generator_flags.get('msvs_version', 'auto')) |
335 return vs_version | 361 return vs_version |
336 | 362 |
337 def _GetBinaryPath(generator_flags, tool): | 363 def _GetBinaryPath(generator_flags, tool): |
338 vs = GetVSVersion(generator_flags) | 364 vs = GetVSVersion(generator_flags) |
339 return ('"' + | 365 return ('"' + |
340 os.path.normpath(os.path.join(vs.Path(), "VC/bin", tool)) + | 366 os.path.normpath(os.path.join(vs.Path(), "VC/bin", tool)) + |
341 '"') | 367 '"') |
342 | 368 |
343 def GetCLPath(generator_flags): | 369 def GetCLPath(generator_flags): |
344 return _GetBinaryPath(generator_flags, 'cl.exe') | 370 return _GetBinaryPath(generator_flags, 'cl.exe') |
345 | 371 |
346 def GetLinkPath(generator_flags): | 372 def GetLinkPath(generator_flags): |
347 return _GetBinaryPath(generator_flags, 'link.exe') | 373 return _GetBinaryPath(generator_flags, 'link.exe') |
348 | 374 |
349 def GetLibPath(generator_flags): | 375 def GetLibPath(generator_flags): |
350 return _GetBinaryPath(generator_flags, 'lib.exe') | 376 return _GetBinaryPath(generator_flags, 'lib.exe') |
351 | 377 |
352 def GetMidlPath(generator_flags): | 378 def GetMidlPath(generator_flags): |
353 return _GetBinaryPath(generator_flags, 'midl.exe') | 379 return _GetBinaryPath(generator_flags, 'midl.exe') |
OLD | NEW |