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

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

Issue 10749020: Adds support for the library_dirs key, which appears in the documentation but was never actually im… (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: library_dirs Created 7 years, 5 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
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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 """Adds a configuration to the MSVS project. 1024 """Adds a configuration to the MSVS project.
1025 1025
1026 Many settings in a vcproj file are specific to a configuration. This 1026 Many settings in a vcproj file are specific to a configuration. This
1027 function the main part of the vcproj file that's configuration specific. 1027 function the main part of the vcproj file that's configuration specific.
1028 1028
1029 Arguments: 1029 Arguments:
1030 p: The target project being generated. 1030 p: The target project being generated.
1031 spec: The target dictionary containing the properties of the target. 1031 spec: The target dictionary containing the properties of the target.
1032 config_type: The configuration type, a number as defined by Microsoft. 1032 config_type: The configuration type, a number as defined by Microsoft.
1033 config_name: The name of the configuration. 1033 config_name: The name of the configuration.
1034 config: The dictionnary that defines the special processing to be done 1034 config: The dictionary that defines the special processing to be done
1035 for this configuration. 1035 for this configuration.
1036 """ 1036 """
1037 # Get the information for this configuration 1037 # Get the information for this configuration
1038 include_dirs, resource_include_dirs = _GetIncludeDirs(config) 1038 include_dirs, resource_include_dirs = _GetIncludeDirs(config)
1039 libraries = _GetLibraries(spec) 1039 libraries = _GetLibraries(spec)
1040 library_dirs = _GetLibraryDirs(config)
1040 out_file, vc_tool, _ = _GetOutputFilePathAndTool(spec, msbuild=False) 1041 out_file, vc_tool, _ = _GetOutputFilePathAndTool(spec, msbuild=False)
1041 defines = _GetDefines(config) 1042 defines = _GetDefines(config)
1042 defines = [_EscapeCppDefineForMSVS(d) for d in defines] 1043 defines = [_EscapeCppDefineForMSVS(d) for d in defines]
1043 disabled_warnings = _GetDisabledWarnings(config) 1044 disabled_warnings = _GetDisabledWarnings(config)
1044 prebuild = config.get('msvs_prebuild') 1045 prebuild = config.get('msvs_prebuild')
1045 postbuild = config.get('msvs_postbuild') 1046 postbuild = config.get('msvs_postbuild')
1046 def_file = _GetModuleDefinition(spec) 1047 def_file = _GetModuleDefinition(spec)
1047 precompiled_header = config.get('msvs_precompiled_header') 1048 precompiled_header = config.get('msvs_precompiled_header')
1048 1049
1049 # Prepare the list of tools as a dictionary. 1050 # Prepare the list of tools as a dictionary.
1050 tools = dict() 1051 tools = dict()
1051 # Add in user specified msvs_settings. 1052 # Add in user specified msvs_settings.
1052 msvs_settings = config.get('msvs_settings', {}) 1053 msvs_settings = config.get('msvs_settings', {})
1053 MSVSSettings.ValidateMSVSSettings(msvs_settings) 1054 MSVSSettings.ValidateMSVSSettings(msvs_settings)
1054 1055
1055 # Prevent default library inheritance from the environment. 1056 # Prevent default library inheritance from the environment.
1056 _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', ['$(NOINHERIT)']) 1057 _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', ['$(NOINHERIT)'])
1057 1058
1058 for tool in msvs_settings: 1059 for tool in msvs_settings:
1059 settings = config['msvs_settings'][tool] 1060 settings = config['msvs_settings'][tool]
1060 for setting in settings: 1061 for setting in settings:
1061 _ToolAppend(tools, tool, setting, settings[setting]) 1062 _ToolAppend(tools, tool, setting, settings[setting])
1062 # Add the information to the appropriate tool 1063 # Add the information to the appropriate tool
1063 _ToolAppend(tools, 'VCCLCompilerTool', 1064 _ToolAppend(tools, 'VCCLCompilerTool',
1064 'AdditionalIncludeDirectories', include_dirs) 1065 'AdditionalIncludeDirectories', include_dirs)
1065 _ToolAppend(tools, 'VCResourceCompilerTool', 1066 _ToolAppend(tools, 'VCResourceCompilerTool',
1066 'AdditionalIncludeDirectories', resource_include_dirs) 1067 'AdditionalIncludeDirectories', resource_include_dirs)
1067 # Add in libraries. 1068 # Add in libraries.
1068 _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', libraries) 1069 _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', libraries)
1070 _ToolAppend(tools, 'VCLinkerTool', 'AdditionalLibraryDirectories',
1071 library_dirs)
1069 if out_file: 1072 if out_file:
1070 _ToolAppend(tools, vc_tool, 'OutputFile', out_file, only_if_unset=True) 1073 _ToolAppend(tools, vc_tool, 'OutputFile', out_file, only_if_unset=True)
1071 # Add defines. 1074 # Add defines.
1072 _ToolAppend(tools, 'VCCLCompilerTool', 'PreprocessorDefinitions', defines) 1075 _ToolAppend(tools, 'VCCLCompilerTool', 'PreprocessorDefinitions', defines)
1073 _ToolAppend(tools, 'VCResourceCompilerTool', 'PreprocessorDefinitions', 1076 _ToolAppend(tools, 'VCResourceCompilerTool', 'PreprocessorDefinitions',
1074 defines) 1077 defines)
1075 # Change program database directory to prevent collisions. 1078 # Change program database directory to prevent collisions.
1076 _ToolAppend(tools, 'VCCLCompilerTool', 'ProgramDataBaseFileName', 1079 _ToolAppend(tools, 'VCCLCompilerTool', 'ProgramDataBaseFileName',
1077 '$(IntDir)$(ProjectName)\\vc80.pdb', only_if_unset=True) 1080 '$(IntDir)$(ProjectName)\\vc80.pdb', only_if_unset=True)
1078 # Add disabled warnings. 1081 # Add disabled warnings.
(...skipping 19 matching lines...) Expand all
1098 if def_file: 1101 if def_file:
1099 _ToolAppend(tools, 'VCLinkerTool', 'ModuleDefinitionFile', def_file) 1102 _ToolAppend(tools, 'VCLinkerTool', 'ModuleDefinitionFile', def_file)
1100 1103
1101 _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name) 1104 _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name)
1102 1105
1103 1106
1104 def _GetIncludeDirs(config): 1107 def _GetIncludeDirs(config):
1105 """Returns the list of directories to be used for #include directives. 1108 """Returns the list of directories to be used for #include directives.
1106 1109
1107 Arguments: 1110 Arguments:
1108 config: The dictionnary that defines the special processing to be done 1111 config: The dictionary that defines the special processing to be done
1109 for this configuration. 1112 for this configuration.
1110 Returns: 1113 Returns:
1111 The list of directory paths. 1114 The list of directory paths.
1112 """ 1115 """
1113 # TODO(bradnelson): include_dirs should really be flexible enough not to 1116 # TODO(bradnelson): include_dirs should really be flexible enough not to
1114 # require this sort of thing. 1117 # require this sort of thing.
1115 include_dirs = ( 1118 include_dirs = (
1116 config.get('include_dirs', []) + 1119 config.get('include_dirs', []) +
1117 config.get('msvs_system_include_dirs', [])) 1120 config.get('msvs_system_include_dirs', []))
1118 resource_include_dirs = config.get('resource_include_dirs', include_dirs) 1121 resource_include_dirs = config.get('resource_include_dirs', include_dirs)
1119 include_dirs = _FixPaths(include_dirs) 1122 include_dirs = _FixPaths(include_dirs)
1120 resource_include_dirs = _FixPaths(resource_include_dirs) 1123 resource_include_dirs = _FixPaths(resource_include_dirs)
1121 return include_dirs, resource_include_dirs 1124 return include_dirs, resource_include_dirs
1122 1125
1123 1126
1127 def _GetLibraryDirs(config):
1128 """Returns the list of directories to be used for library search paths.
1129
1130 Arguments:
1131 config: The dictionary that defines the special processing to be done
1132 for this configuration.
1133 Returns:
1134 The list of directory paths.
1135 """
1136
1137 library_dirs = config.get('library_dirs', [])
1138 library_dirs = _FixPaths(library_dirs)
1139 return library_dirs
1140
1141
1124 def _GetLibraries(spec): 1142 def _GetLibraries(spec):
1125 """Returns the list of libraries for this configuration. 1143 """Returns the list of libraries for this configuration.
1126 1144
1127 Arguments: 1145 Arguments:
1128 spec: The target dictionary containing the properties of the target. 1146 spec: The target dictionary containing the properties of the target.
1129 Returns: 1147 Returns:
1130 The list of directory paths. 1148 The list of directory paths.
1131 """ 1149 """
1132 libraries = spec.get('libraries', []) 1150 libraries = spec.get('libraries', [])
1133 # Strip out -l, as it is not used on windows (but is needed so we can pass 1151 # Strip out -l, as it is not used on windows (but is needed so we can pass
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 prefix = spec.get('product_prefix', '') 1200 prefix = spec.get('product_prefix', '')
1183 product_name = spec.get('product_name', '$(ProjectName)') 1201 product_name = spec.get('product_name', '$(ProjectName)')
1184 out_file = ntpath.join(out_dir, prefix + product_name + suffix) 1202 out_file = ntpath.join(out_dir, prefix + product_name + suffix)
1185 return out_file, vc_tool, msbuild_tool 1203 return out_file, vc_tool, msbuild_tool
1186 1204
1187 1205
1188 def _GetDefines(config): 1206 def _GetDefines(config):
1189 """Returns the list of preprocessor definitions for this configuation. 1207 """Returns the list of preprocessor definitions for this configuation.
1190 1208
1191 Arguments: 1209 Arguments:
1192 config: The dictionnary that defines the special processing to be done 1210 config: The dictionary that defines the special processing to be done
1193 for this configuration. 1211 for this configuration.
1194 Returns: 1212 Returns:
1195 The list of preprocessor definitions. 1213 The list of preprocessor definitions.
1196 """ 1214 """
1197 defines = [] 1215 defines = []
1198 for d in config.get('defines', []): 1216 for d in config.get('defines', []):
1199 if type(d) == list: 1217 if type(d) == list:
1200 fd = '='.join([str(dpart) for dpart in d]) 1218 fd = '='.join([str(dpart) for dpart in d])
1201 else: 1219 else:
1202 fd = str(d) 1220 fd = str(d)
(...skipping 16 matching lines...) Expand all
1219 'Multiple module definition files in one target, target %s lists ' 1237 'Multiple module definition files in one target, target %s lists '
1220 'multiple .def files: %s' % ( 1238 'multiple .def files: %s' % (
1221 spec['target_name'], ' '.join(def_files))) 1239 spec['target_name'], ' '.join(def_files)))
1222 return def_file 1240 return def_file
1223 1241
1224 1242
1225 def _ConvertToolsToExpectedForm(tools): 1243 def _ConvertToolsToExpectedForm(tools):
1226 """Convert tools to a form expected by Visual Studio. 1244 """Convert tools to a form expected by Visual Studio.
1227 1245
1228 Arguments: 1246 Arguments:
1229 tools: A dictionnary of settings; the tool name is the key. 1247 tools: A dictionary of settings; the tool name is the key.
1230 Returns: 1248 Returns:
1231 A list of Tool objects. 1249 A list of Tool objects.
1232 """ 1250 """
1233 tool_list = [] 1251 tool_list = []
1234 for tool, settings in tools.iteritems(): 1252 for tool, settings in tools.iteritems():
1235 # Collapse settings with lists. 1253 # Collapse settings with lists.
1236 settings_fixed = {} 1254 settings_fixed = {}
1237 for setting, value in settings.iteritems(): 1255 for setting, value in settings.iteritems():
1238 if type(value) == list: 1256 if type(value) == list:
1239 if ((tool == 'VCLinkerTool' and 1257 if ((tool == 'VCLinkerTool' and
1240 setting == 'AdditionalDependencies') or 1258 setting == 'AdditionalDependencies') or
1241 setting == 'AdditionalOptions'): 1259 setting == 'AdditionalOptions'):
1242 settings_fixed[setting] = ' '.join(value) 1260 settings_fixed[setting] = ' '.join(value)
1243 else: 1261 else:
1244 settings_fixed[setting] = ';'.join(value) 1262 settings_fixed[setting] = ';'.join(value)
1245 else: 1263 else:
1246 settings_fixed[setting] = value 1264 settings_fixed[setting] = value
1247 # Add in this tool. 1265 # Add in this tool.
1248 tool_list.append(MSVSProject.Tool(tool, settings_fixed)) 1266 tool_list.append(MSVSProject.Tool(tool, settings_fixed))
1249 return tool_list 1267 return tool_list
1250 1268
1251 1269
1252 def _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name): 1270 def _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name):
1253 """Add to the project file the configuration specified by config. 1271 """Add to the project file the configuration specified by config.
1254 1272
1255 Arguments: 1273 Arguments:
1256 p: The target project being generated. 1274 p: The target project being generated.
1257 spec: the target project dict. 1275 spec: the target project dict.
1258 tools: A dictionnary of settings; the tool name is the key. 1276 tools: A dictionary of settings; the tool name is the key.
1259 config: The dictionnary that defines the special processing to be done 1277 config: The dictionary that defines the special processing to be done
1260 for this configuration. 1278 for this configuration.
1261 config_type: The configuration type, a number as defined by Microsoft. 1279 config_type: The configuration type, a number as defined by Microsoft.
1262 config_name: The name of the configuration. 1280 config_name: The name of the configuration.
1263 """ 1281 """
1264 attributes = _GetMSVSAttributes(spec, config, config_type) 1282 attributes = _GetMSVSAttributes(spec, config, config_type)
1265 # Add in this configuration. 1283 # Add in this configuration.
1266 tool_list = _ConvertToolsToExpectedForm(tools) 1284 tool_list = _ConvertToolsToExpectedForm(tools)
1267 p.AddConfig(_ConfigFullName(config_name, config), 1285 p.AddConfig(_ConfigFullName(config_name, config),
1268 attrs=attributes, tools=tool_list) 1286 attrs=attributes, tools=tool_list)
1269 1287
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 if 'msbuild_settings' in configuration: 2798 if 'msbuild_settings' in configuration:
2781 converted = False 2799 converted = False
2782 msbuild_settings = configuration['msbuild_settings'] 2800 msbuild_settings = configuration['msbuild_settings']
2783 MSVSSettings.ValidateMSBuildSettings(msbuild_settings) 2801 MSVSSettings.ValidateMSBuildSettings(msbuild_settings)
2784 else: 2802 else:
2785 converted = True 2803 converted = True
2786 msvs_settings = configuration.get('msvs_settings', {}) 2804 msvs_settings = configuration.get('msvs_settings', {})
2787 msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(msvs_settings) 2805 msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(msvs_settings)
2788 include_dirs, resource_include_dirs = _GetIncludeDirs(configuration) 2806 include_dirs, resource_include_dirs = _GetIncludeDirs(configuration)
2789 libraries = _GetLibraries(spec) 2807 libraries = _GetLibraries(spec)
2808 library_dirs = _GetLibraryDirs(configuration)
2790 out_file, _, msbuild_tool = _GetOutputFilePathAndTool(spec, msbuild=True) 2809 out_file, _, msbuild_tool = _GetOutputFilePathAndTool(spec, msbuild=True)
2791 defines = _GetDefines(configuration) 2810 defines = _GetDefines(configuration)
2792 if converted: 2811 if converted:
2793 # Visual Studio 2010 has TR1 2812 # Visual Studio 2010 has TR1
2794 defines = [d for d in defines if d != '_HAS_TR1=0'] 2813 defines = [d for d in defines if d != '_HAS_TR1=0']
2795 # Warn of ignored settings 2814 # Warn of ignored settings
2796 ignored_settings = ['msvs_prebuild', 'msvs_postbuild', 'msvs_tool_files'] 2815 ignored_settings = ['msvs_prebuild', 'msvs_postbuild', 'msvs_tool_files']
2797 for ignored_setting in ignored_settings: 2816 for ignored_setting in ignored_settings:
2798 value = configuration.get(ignored_setting) 2817 value = configuration.get(ignored_setting)
2799 if value: 2818 if value:
(...skipping 13 matching lines...) Expand all
2813 # the corresponding files are found, e.g. don't generate ResourceCompile 2832 # the corresponding files are found, e.g. don't generate ResourceCompile
2814 # if you don't have any resources. 2833 # if you don't have any resources.
2815 _ToolAppend(msbuild_settings, 'ClCompile', 2834 _ToolAppend(msbuild_settings, 'ClCompile',
2816 'AdditionalIncludeDirectories', include_dirs) 2835 'AdditionalIncludeDirectories', include_dirs)
2817 _ToolAppend(msbuild_settings, 'ResourceCompile', 2836 _ToolAppend(msbuild_settings, 'ResourceCompile',
2818 'AdditionalIncludeDirectories', resource_include_dirs) 2837 'AdditionalIncludeDirectories', resource_include_dirs)
2819 # Add in libraries, note that even for empty libraries, we want this 2838 # Add in libraries, note that even for empty libraries, we want this
2820 # set, to prevent inheriting default libraries from the enviroment. 2839 # set, to prevent inheriting default libraries from the enviroment.
2821 _ToolSetOrAppend(msbuild_settings, 'Link', 'AdditionalDependencies', 2840 _ToolSetOrAppend(msbuild_settings, 'Link', 'AdditionalDependencies',
2822 libraries) 2841 libraries)
2842 _ToolAppend(msbuild_settings, 'Link', 'AdditionalLibraryDirectories',
2843 library_dirs)
2823 if out_file: 2844 if out_file:
2824 _ToolAppend(msbuild_settings, msbuild_tool, 'OutputFile', out_file, 2845 _ToolAppend(msbuild_settings, msbuild_tool, 'OutputFile', out_file,
2825 only_if_unset=True) 2846 only_if_unset=True)
2826 # Add defines. 2847 # Add defines.
2827 _ToolAppend(msbuild_settings, 'ClCompile', 2848 _ToolAppend(msbuild_settings, 'ClCompile',
2828 'PreprocessorDefinitions', defines) 2849 'PreprocessorDefinitions', defines)
2829 _ToolAppend(msbuild_settings, 'ResourceCompile', 2850 _ToolAppend(msbuild_settings, 'ResourceCompile',
2830 'PreprocessorDefinitions', defines) 2851 'PreprocessorDefinitions', defines)
2831 # Add disabled warnings. 2852 # Add disabled warnings.
2832 _ToolAppend(msbuild_settings, 'ClCompile', 2853 _ToolAppend(msbuild_settings, 'ClCompile',
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
3206 action_spec.extend( 3227 action_spec.extend(
3207 # TODO(jeanluc) 'Document' for all or just if as_sources? 3228 # TODO(jeanluc) 'Document' for all or just if as_sources?
3208 [['FileType', 'Document'], 3229 [['FileType', 'Document'],
3209 ['Command', command], 3230 ['Command', command],
3210 ['Message', description], 3231 ['Message', description],
3211 ['Outputs', outputs] 3232 ['Outputs', outputs]
3212 ]) 3233 ])
3213 if additional_inputs: 3234 if additional_inputs:
3214 action_spec.append(['AdditionalInputs', additional_inputs]) 3235 action_spec.append(['AdditionalInputs', additional_inputs])
3215 actions_spec.append(action_spec) 3236 actions_spec.append(action_spec)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698