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

Side by Side Diff: pylib/gyp/generator/msvs.py

Issue 12256017: Remove default import library inheritance/configuration. (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@lkgr
Patch Set: Rebase to head in preparation for landing. Created 7 years, 10 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
« no previous file with comments | « no previous file | pylib/gyp/msvs_emulation.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 import copy 5 import copy
6 import ntpath 6 import ntpath
7 import os 7 import os
8 import posixpath 8 import posixpath
9 import re 9 import re
10 import subprocess 10 import subprocess
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 excluded=excluded, 198 excluded=excluded,
199 list_excluded=list_excluded) 199 list_excluded=list_excluded)
200 contents = MSVSProject.Filter(f, contents=contents) 200 contents = MSVSProject.Filter(f, contents=contents)
201 result.append(contents) 201 result.append(contents)
202 202
203 return result 203 return result
204 204
205 205
206 def _ToolAppend(tools, tool_name, setting, value, only_if_unset=False): 206 def _ToolAppend(tools, tool_name, setting, value, only_if_unset=False):
207 if not value: return 207 if not value: return
208 _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset)
209
210
211 def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False):
208 # TODO(bradnelson): ugly hack, fix this more generally!!! 212 # TODO(bradnelson): ugly hack, fix this more generally!!!
209 if 'Directories' in setting or 'Dependencies' in setting: 213 if 'Directories' in setting or 'Dependencies' in setting:
210 if type(value) == str: 214 if type(value) == str:
211 value = value.replace('/', '\\') 215 value = value.replace('/', '\\')
212 else: 216 else:
213 value = [i.replace('/', '\\') for i in value] 217 value = [i.replace('/', '\\') for i in value]
214 if not tools.get(tool_name): 218 if not tools.get(tool_name):
215 tools[tool_name] = dict() 219 tools[tool_name] = dict()
216 tool = tools[tool_name] 220 tool = tools[tool_name]
217 if tool.get(setting): 221 if tool.get(setting):
218 if only_if_unset: return 222 if only_if_unset: return
219 if type(tool[setting]) == list: 223 if type(tool[setting]) == list:
220 tool[setting] += value 224 tool[setting] += value
221 else: 225 else:
222 raise TypeError( 226 raise TypeError(
223 'Appending "%s" to a non-list setting "%s" for tool "%s" is ' 227 'Appending "%s" to a non-list setting "%s" for tool "%s" is '
224 'not allowed, previous value: %s' % ( 228 'not allowed, previous value: %s' % (
225 value, setting, tool_name, str(tool[setting]))) 229 value, setting, tool_name, str(tool[setting])))
226 else: 230 else:
227 tool[setting] = value 231 tool[setting] = value
228 232
229 233
230 def _ConfigPlatform(config_data): 234 def _ConfigPlatform(config_data):
231 return config_data.get('msvs_configuration_platform', 'Win32') 235 return config_data.get('msvs_configuration_platform', 'Win32')
232 236
233 237
234 def _ConfigBaseName(config_name, platform_name): 238 def _ConfigBaseName(config_name, platform_name):
235 if config_name.endswith('_' + platform_name): 239 if config_name.endswith('_' + platform_name):
236 return config_name[0:-len(platform_name)-1] 240 return config_name[0:-len(platform_name) - 1]
237 else: 241 else:
238 return config_name 242 return config_name
239 243
240 244
241 def _ConfigFullName(config_name, config_data): 245 def _ConfigFullName(config_name, config_data):
242 platform_name = _ConfigPlatform(config_data) 246 platform_name = _ConfigPlatform(config_data)
243 return '%s|%s' % (_ConfigBaseName(config_name, platform_name), platform_name) 247 return '%s|%s' % (_ConfigBaseName(config_name, platform_name), platform_name)
244 248
245 249
246 def _BuildCommandLineForRuleRaw(spec, cmd, cygwin_shell, has_input_path, 250 def _BuildCommandLineForRuleRaw(spec, cmd, cygwin_shell, has_input_path,
(...skipping 17 matching lines...) Expand all
264 '`cygpath -m "${INTDIR}"`') for i in direct_cmd] 268 '`cygpath -m "${INTDIR}"`') for i in direct_cmd]
265 direct_cmd = [i.replace('$(OutDir)', 269 direct_cmd = [i.replace('$(OutDir)',
266 '`cygpath -m "${OUTDIR}"`') for i in direct_cmd] 270 '`cygpath -m "${OUTDIR}"`') for i in direct_cmd]
267 direct_cmd = [i.replace('$(InputDir)', 271 direct_cmd = [i.replace('$(InputDir)',
268 '`cygpath -m "${INPUTDIR}"`') for i in direct_cmd] 272 '`cygpath -m "${INPUTDIR}"`') for i in direct_cmd]
269 if has_input_path: 273 if has_input_path:
270 direct_cmd = [i.replace('$(InputPath)', 274 direct_cmd = [i.replace('$(InputPath)',
271 '`cygpath -m "${INPUTPATH}"`') 275 '`cygpath -m "${INPUTPATH}"`')
272 for i in direct_cmd] 276 for i in direct_cmd]
273 direct_cmd = ['\\"%s\\"' % i.replace('"', '\\\\\\"') for i in direct_cmd] 277 direct_cmd = ['\\"%s\\"' % i.replace('"', '\\\\\\"') for i in direct_cmd]
274 #direct_cmd = gyp.common.EncodePOSIXShellList(direct_cmd) 278 # direct_cmd = gyp.common.EncodePOSIXShellList(direct_cmd)
275 direct_cmd = ' '.join(direct_cmd) 279 direct_cmd = ' '.join(direct_cmd)
276 # TODO(quote): regularize quoting path names throughout the module 280 # TODO(quote): regularize quoting path names throughout the module
277 cmd = '' 281 cmd = ''
278 if do_setup_env: 282 if do_setup_env:
279 cmd += 'call "$(ProjectDir)%(cygwin_dir)s\\setup_env.bat" && ' 283 cmd += 'call "$(ProjectDir)%(cygwin_dir)s\\setup_env.bat" && '
280 cmd += 'set CYGWIN=nontsec&& ' 284 cmd += 'set CYGWIN=nontsec&& '
281 if direct_cmd.find('NUMBER_OF_PROCESSORS') >= 0: 285 if direct_cmd.find('NUMBER_OF_PROCESSORS') >= 0:
282 cmd += 'set /a NUMBER_OF_PROCESSORS_PLUS_1=%%NUMBER_OF_PROCESSORS%%+1&& ' 286 cmd += 'set /a NUMBER_OF_PROCESSORS_PLUS_1=%%NUMBER_OF_PROCESSORS%%+1&& '
283 if direct_cmd.find('INTDIR') >= 0: 287 if direct_cmd.find('INTDIR') >= 0:
284 cmd += 'set INTDIR=$(IntDir)&& ' 288 cmd += 'set INTDIR=$(IntDir)&& '
(...skipping 15 matching lines...) Expand all
300 # after the other without aborting in Incredibuild, since IB makes a bat 304 # after the other without aborting in Incredibuild, since IB makes a bat
301 # file out of the raw command string, and some commands (like python) are 305 # file out of the raw command string, and some commands (like python) are
302 # actually batch files themselves. 306 # actually batch files themselves.
303 command.insert(0, 'call') 307 command.insert(0, 'call')
304 # Fix the paths 308 # Fix the paths
305 # TODO(quote): This is a really ugly heuristic, and will miss path fixing 309 # TODO(quote): This is a really ugly heuristic, and will miss path fixing
306 # for arguments like "--arg=path" or "/opt:path". 310 # for arguments like "--arg=path" or "/opt:path".
307 # If the argument starts with a slash or dash, it's probably a command line 311 # If the argument starts with a slash or dash, it's probably a command line
308 # switch 312 # switch
309 arguments = [i if (i[:1] in "/-") else _FixPath(i) for i in cmd[1:]] 313 arguments = [i if (i[:1] in "/-") else _FixPath(i) for i in cmd[1:]]
310 arguments = [i.replace('$(InputDir)','%INPUTDIR%') for i in arguments] 314 arguments = [i.replace('$(InputDir)', '%INPUTDIR%') for i in arguments]
311 arguments = [MSVSSettings.FixVCMacroSlashes(i) for i in arguments] 315 arguments = [MSVSSettings.FixVCMacroSlashes(i) for i in arguments]
312 if quote_cmd: 316 if quote_cmd:
313 # Support a mode for using cmd directly. 317 # Support a mode for using cmd directly.
314 # Convert any paths to native form (first element is used directly). 318 # Convert any paths to native form (first element is used directly).
315 # TODO(quote): regularize quoting path names throughout the module 319 # TODO(quote): regularize quoting path names throughout the module
316 arguments = ['"%s"' % i for i in arguments] 320 arguments = ['"%s"' % i for i in arguments]
317 # Collapse into a single command. 321 # Collapse into a single command.
318 return input_dir_preamble + ' '.join(command + arguments) 322 return input_dir_preamble + ' '.join(command + arguments)
319 323
320 324
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 return s 718 return s
715 719
716 720
717 quote_replacer_regex2 = re.compile(r'(\\+)"') 721 quote_replacer_regex2 = re.compile(r'(\\+)"')
718 722
719 723
720 def _EscapeCommandLineArgumentForMSBuild(s): 724 def _EscapeCommandLineArgumentForMSBuild(s):
721 """Escapes a Windows command-line argument for use by MSBuild.""" 725 """Escapes a Windows command-line argument for use by MSBuild."""
722 726
723 def _Replace(match): 727 def _Replace(match):
724 return (len(match.group(1))/2*4)*'\\' + '\\"' 728 return (len(match.group(1)) / 2 * 4) * '\\' + '\\"'
725 729
726 # Escape all quotes so that they are interpreted literally. 730 # Escape all quotes so that they are interpreted literally.
727 s = quote_replacer_regex2.sub(_Replace, s) 731 s = quote_replacer_regex2.sub(_Replace, s)
728 return s 732 return s
729 733
730 734
731 def _EscapeMSBuildSpecialCharacters(s): 735 def _EscapeMSBuildSpecialCharacters(s):
732 escape_dictionary = { 736 escape_dictionary = {
733 '%': '%25', 737 '%': '%25',
734 '$': '%24', 738 '$': '%24',
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 prebuild = config.get('msvs_prebuild') 1039 prebuild = config.get('msvs_prebuild')
1036 postbuild = config.get('msvs_postbuild') 1040 postbuild = config.get('msvs_postbuild')
1037 def_file = _GetModuleDefinition(spec) 1041 def_file = _GetModuleDefinition(spec)
1038 precompiled_header = config.get('msvs_precompiled_header') 1042 precompiled_header = config.get('msvs_precompiled_header')
1039 1043
1040 # Prepare the list of tools as a dictionary. 1044 # Prepare the list of tools as a dictionary.
1041 tools = dict() 1045 tools = dict()
1042 # Add in user specified msvs_settings. 1046 # Add in user specified msvs_settings.
1043 msvs_settings = config.get('msvs_settings', {}) 1047 msvs_settings = config.get('msvs_settings', {})
1044 MSVSSettings.ValidateMSVSSettings(msvs_settings) 1048 MSVSSettings.ValidateMSVSSettings(msvs_settings)
1049
1050 # Prevent default library inheritance from the environment.
1051 _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', ['$(NOINHERIT)'])
1052
1045 for tool in msvs_settings: 1053 for tool in msvs_settings:
1046 settings = config['msvs_settings'][tool] 1054 settings = config['msvs_settings'][tool]
1047 for setting in settings: 1055 for setting in settings:
1048 _ToolAppend(tools, tool, setting, settings[setting]) 1056 _ToolAppend(tools, tool, setting, settings[setting])
1049 # Add the information to the appropriate tool 1057 # Add the information to the appropriate tool
1050 _ToolAppend(tools, 'VCCLCompilerTool', 1058 _ToolAppend(tools, 'VCCLCompilerTool',
1051 'AdditionalIncludeDirectories', include_dirs) 1059 'AdditionalIncludeDirectories', include_dirs)
1052 _ToolAppend(tools, 'VCResourceCompilerTool', 1060 _ToolAppend(tools, 'VCResourceCompilerTool',
1053 'AdditionalIncludeDirectories', resource_include_dirs) 1061 'AdditionalIncludeDirectories', resource_include_dirs)
1054 # Add in libraries. 1062 # Add in libraries.
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 websiteProperties=False, 1808 websiteProperties=False,
1801 version=msvs_version) 1809 version=msvs_version)
1802 sln.Write() 1810 sln.Write()
1803 1811
1804 if missing_sources: 1812 if missing_sources:
1805 error_message = "Missing input files:\n" + \ 1813 error_message = "Missing input files:\n" + \
1806 '\n'.join(set(missing_sources)) 1814 '\n'.join(set(missing_sources))
1807 if generator_flags.get('msvs_error_on_missing_sources', False): 1815 if generator_flags.get('msvs_error_on_missing_sources', False):
1808 raise GypError(error_message) 1816 raise GypError(error_message)
1809 else: 1817 else:
1810 print >>sys.stdout, "Warning: " + error_message 1818 print >> sys.stdout, "Warning: " + error_message
1811 1819
1812 1820
1813 def _GenerateMSBuildFiltersFile(filters_path, source_files, 1821 def _GenerateMSBuildFiltersFile(filters_path, source_files,
1814 extension_to_rule_name): 1822 extension_to_rule_name):
1815 """Generate the filters file. 1823 """Generate the filters file.
1816 1824
1817 This file is used by Visual Studio to organize the presentation of source 1825 This file is used by Visual Studio to organize the presentation of source
1818 files into folders. 1826 files into folders.
1819 1827
1820 Arguments: 1828 Arguments:
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 precompiled_header = configuration.get('msvs_precompiled_header') 2743 precompiled_header = configuration.get('msvs_precompiled_header')
2736 2744
2737 # Add the information to the appropriate tool 2745 # Add the information to the appropriate tool
2738 # TODO(jeanluc) We could optimize and generate these settings only if 2746 # TODO(jeanluc) We could optimize and generate these settings only if
2739 # the corresponding files are found, e.g. don't generate ResourceCompile 2747 # the corresponding files are found, e.g. don't generate ResourceCompile
2740 # if you don't have any resources. 2748 # if you don't have any resources.
2741 _ToolAppend(msbuild_settings, 'ClCompile', 2749 _ToolAppend(msbuild_settings, 'ClCompile',
2742 'AdditionalIncludeDirectories', include_dirs) 2750 'AdditionalIncludeDirectories', include_dirs)
2743 _ToolAppend(msbuild_settings, 'ResourceCompile', 2751 _ToolAppend(msbuild_settings, 'ResourceCompile',
2744 'AdditionalIncludeDirectories', resource_include_dirs) 2752 'AdditionalIncludeDirectories', resource_include_dirs)
2745 # Add in libraries. 2753 # Add in libraries, note that even for empty libraries, we want this
2746 _ToolAppend(msbuild_settings, 'Link', 'AdditionalDependencies', libraries) 2754 # set, to prevent inheriting default libraries from the enviroment.
2755 _ToolSetOrAppend(msbuild_settings, 'Link', 'AdditionalDependencies',
2756 libraries)
2747 if out_file: 2757 if out_file:
2748 _ToolAppend(msbuild_settings, msbuild_tool, 'OutputFile', out_file, 2758 _ToolAppend(msbuild_settings, msbuild_tool, 'OutputFile', out_file,
2749 only_if_unset=True) 2759 only_if_unset=True)
2750 # Add defines. 2760 # Add defines.
2751 _ToolAppend(msbuild_settings, 'ClCompile', 2761 _ToolAppend(msbuild_settings, 'ClCompile',
2752 'PreprocessorDefinitions', defines) 2762 'PreprocessorDefinitions', defines)
2753 _ToolAppend(msbuild_settings, 'ResourceCompile', 2763 _ToolAppend(msbuild_settings, 'ResourceCompile',
2754 'PreprocessorDefinitions', defines) 2764 'PreprocessorDefinitions', defines)
2755 # Add disabled warnings. 2765 # Add disabled warnings.
2756 _ToolAppend(msbuild_settings, 'ClCompile', 2766 _ToolAppend(msbuild_settings, 'ClCompile',
(...skipping 13 matching lines...) Expand all
2770 # Set the module definition file if any. 2780 # Set the module definition file if any.
2771 if def_file: 2781 if def_file:
2772 _ToolAppend(msbuild_settings, 'Link', 'ModuleDefinitionFile', def_file) 2782 _ToolAppend(msbuild_settings, 'Link', 'ModuleDefinitionFile', def_file)
2773 configuration['finalized_msbuild_settings'] = msbuild_settings 2783 configuration['finalized_msbuild_settings'] = msbuild_settings
2774 2784
2775 2785
2776 def _GetValueFormattedForMSBuild(tool_name, name, value): 2786 def _GetValueFormattedForMSBuild(tool_name, name, value):
2777 if type(value) == list: 2787 if type(value) == list:
2778 # For some settings, VS2010 does not automatically extends the settings 2788 # For some settings, VS2010 does not automatically extends the settings
2779 # TODO(jeanluc) Is this what we want? 2789 # TODO(jeanluc) Is this what we want?
2780 if name in ['AdditionalDependencies', 2790 if name in ['AdditionalIncludeDirectories',
2781 'AdditionalIncludeDirectories',
2782 'AdditionalLibraryDirectories', 2791 'AdditionalLibraryDirectories',
2783 'AdditionalOptions', 2792 'AdditionalOptions',
2784 'DelayLoadDLLs', 2793 'DelayLoadDLLs',
2785 'DisableSpecificWarnings', 2794 'DisableSpecificWarnings',
2786 'PreprocessorDefinitions']: 2795 'PreprocessorDefinitions']:
2787 value.append('%%(%s)' % name) 2796 value.append('%%(%s)' % name)
2788 # For most tools, entries in a list should be separated with ';' but some 2797 # For most tools, entries in a list should be separated with ';' but some
2789 # settings use a space. Check for those first. 2798 # settings use a space. Check for those first.
2790 exceptions = { 2799 exceptions = {
2791 'ClCompile': ['AdditionalOptions'], 2800 'ClCompile': ['AdditionalOptions'],
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
3093 action_spec.extend( 3102 action_spec.extend(
3094 # TODO(jeanluc) 'Document' for all or just if as_sources? 3103 # TODO(jeanluc) 'Document' for all or just if as_sources?
3095 [['FileType', 'Document'], 3104 [['FileType', 'Document'],
3096 ['Command', command], 3105 ['Command', command],
3097 ['Message', description], 3106 ['Message', description],
3098 ['Outputs', outputs] 3107 ['Outputs', outputs]
3099 ]) 3108 ])
3100 if additional_inputs: 3109 if additional_inputs:
3101 action_spec.append(['AdditionalInputs', additional_inputs]) 3110 action_spec.append(['AdditionalInputs', additional_inputs])
3102 actions_spec.append(action_spec) 3111 actions_spec.append(action_spec)
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/msvs_emulation.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698