Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: pylib/gyp/msvs_emulation.py

Issue 9990006: ninja windows: Support magic idl build rules (Closed) Base URL: https://gyp.googlecode.com/svn/trunk
Patch Set: copyright header Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pylib/gyp/generator/ninja.py ('k') | pylib/gyp/win_tool.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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',
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
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 HasExplicitIdlRules(self, spec):
332 """Determine if there's an explicit rule for idl files. When there isn't we
333 need to generate implicit rules to build MIDL .idl files."""
334 for rule in spec.get('rules', []):
335 if rule['extension'] == 'idl' and int(rule.get('msvs_external_rule', 0)):
336 return True
337 return False
338
339 def GetIdlBuildData(self, source, config):
340 """Determine the implicit outputs for an idl file. Returns output
341 directory, outputs, and variables and flags that are required."""
342 midl_get = self._GetWrapper(self, self.msvs_settings[config], 'VCMIDLTool')
343 def midl(name, default=None):
344 return self.ConvertVSMacros(midl_get(name, default=default))
345 tlb = midl('TypeLibraryName', default='${root}.tlb')
346 header = midl('HeaderFileName', default='${root}.h')
347 dlldata = midl('DLLDataFileName', default='dlldata.c')
348 iid = midl('InterfaceIdentifierFileName', default='${root}_i.c')
349 proxy = midl('ProxyFileName', default='${root}_p.c')
350 # Note that .tlb is not included in the outputs as it is not always
351 # generated depending on the content of the input idl file.
352 outdir = midl('OutputDirectory')
353 output = [header, dlldata, iid, proxy]
354 variables = [('tlb', tlb),
355 ('h', header),
356 ('dlldata', dlldata),
357 ('iid', iid),
358 ('proxy', proxy)]
359 # TODO(scottmg): Are there configuration settings to set these flags?
360 flags = ['/char', 'signed', '/env', 'win32', '/Oicf']
361 return outdir, output, variables, flags
362
329 vs_version = None 363 vs_version = None
330 def GetVSVersion(generator_flags): 364 def GetVSVersion(generator_flags):
331 global vs_version 365 global vs_version
332 if not vs_version: 366 if not vs_version:
333 vs_version = gyp.MSVSVersion.SelectVisualStudioVersion( 367 vs_version = gyp.MSVSVersion.SelectVisualStudioVersion(
334 generator_flags.get('msvs_version', 'auto')) 368 generator_flags.get('msvs_version', 'auto'))
335 return vs_version 369 return vs_version
336 370
337 def _GetBinaryPath(generator_flags, tool): 371 def _GetBinaryPath(generator_flags, tool):
338 vs = GetVSVersion(generator_flags) 372 vs = GetVSVersion(generator_flags)
339 return ('"' + 373 return ('"' +
340 os.path.normpath(os.path.join(vs.Path(), "VC/bin", tool)) + 374 os.path.normpath(os.path.join(vs.Path(), "VC/bin", tool)) +
341 '"') 375 '"')
342 376
343 def GetCLPath(generator_flags): 377 def GetCLPath(generator_flags):
344 return _GetBinaryPath(generator_flags, 'cl.exe') 378 return _GetBinaryPath(generator_flags, 'cl.exe')
345 379
346 def GetLinkPath(generator_flags): 380 def GetLinkPath(generator_flags):
347 return _GetBinaryPath(generator_flags, 'link.exe') 381 return _GetBinaryPath(generator_flags, 'link.exe')
348 382
349 def GetLibPath(generator_flags): 383 def GetLibPath(generator_flags):
350 return _GetBinaryPath(generator_flags, 'lib.exe') 384 return _GetBinaryPath(generator_flags, 'lib.exe')
351 385
352 def GetMidlPath(generator_flags): 386 def GetMidlPath(generator_flags):
353 return _GetBinaryPath(generator_flags, 'midl.exe') 387 return _GetBinaryPath(generator_flags, 'midl.exe')
OLDNEW
« no previous file with comments | « pylib/gyp/generator/ninja.py ('k') | pylib/gyp/win_tool.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698