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

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

Issue 2866042: Effectively duplicates targets that contain rules/actions, therefore enabling... (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: '' Created 10 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 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2009 Google Inc. All rights reserved. 3 # Copyright (c) 2009 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 from copy import deepcopy
7 import ntpath 8 import ntpath
9 import os
8 import posixpath 10 import posixpath
9 import os
10 import re 11 import re
11 import subprocess 12 import subprocess
12 import sys 13 import sys
14 import uuid
13 15
14 import gyp.MSVSNew as MSVSNew 16 import gyp.MSVSNew as MSVSNew
15 import gyp.MSVSProject as MSVSProject 17 import gyp.MSVSProject as MSVSProject
16 import gyp.MSVSToolFile as MSVSToolFile 18 import gyp.MSVSToolFile as MSVSToolFile
17 import gyp.MSVSUserFile as MSVSUserFile 19 import gyp.MSVSUserFile as MSVSUserFile
18 import gyp.MSVSVersion as MSVSVersion 20 import gyp.MSVSVersion as MSVSVersion
19 import gyp.common 21 import gyp.common
20 22
21 23
22 # Regular expression for validating Visual Studio GUIDs. If the GUID 24 # Regular expression for validating Visual Studio GUIDs. If the GUID
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 # PROCESSOR_ARCHITECTURE (which reflects the word size of the current 1129 # PROCESSOR_ARCHITECTURE (which reflects the word size of the current
1128 # process), it is also necessary to check PROCESSOR_ARCITEW6432 (which 1130 # process), it is also necessary to check PROCESSOR_ARCITEW6432 (which
1129 # contains the actual word size of the system when running thru WOW64). 1131 # contains the actual word size of the system when running thru WOW64).
1130 if (os.environ.get('PROCESSOR_ARCHITECTURE', '').find('64') >= 0 or 1132 if (os.environ.get('PROCESSOR_ARCHITECTURE', '').find('64') >= 0 or
1131 os.environ.get('PROCESSOR_ARCHITEW6432', '').find('64') >= 0): 1133 os.environ.get('PROCESSOR_ARCHITEW6432', '').find('64') >= 0):
1132 default_variables['MSVS_OS_BITS'] = 64 1134 default_variables['MSVS_OS_BITS'] = 64
1133 else: 1135 else:
1134 default_variables['MSVS_OS_BITS'] = 32 1136 default_variables['MSVS_OS_BITS'] = 32
1135 1137
1136 1138
1139 def _CreatePrebuildTarget(target_dicts, qualified_target):
1140 """ Move all rules/actions from qualified_target to a new target.
1141
1142 Arguments:
1143 target_dicts: Dict of target properties keyed on target pair.
1144 qualified_target: Target to duplicate.
1145 Returns:
1146 Name of the new target.
1147 """
1148 [build_file, target, toolset] = gyp.common.ParseQualifiedTarget(
1149 qualified_target)
1150 new_target = '%s:%s_prebuild' % (build_file, target)
1151 if toolset:
1152 new_target += '#%s' % (toolset)
1153 if target_dicts.has_key(new_target):
1154 raise Exception(
1155 'Targets ending in _prebuild not supported in msvs build '
1156 '(target %s)' % target)
1157 target_dicts[new_target] = deepcopy(target_dicts[qualified_target])
1158 target_dicts[new_target]['target_name'] = '%s_prebuild' % (target)
1159 target_dicts[new_target]['original_target_name'] = target
1160 target_dicts[new_target]['type'] = 'none'
1161 for config_name, c in target_dicts[new_target]['configurations'].iteritems():
1162 if not c.has_key('msvs_configuration_attributes'):
1163 c['msvs_configuration_attributes'] = dict()
1164 c['msvs_configuration_attributes']['IntermediateDirectory'
1165 ] = '$(ConfigurationName)\\obj\\%s' % (target)
1166
1167 # Remove actions and rules from the original target.
1168 if target_dicts[qualified_target].has_key('rules'):
1169 sources = target_dicts[qualified_target].get('sources', [])
1170 for rule in target_dicts[qualified_target]['rules']:
1171 trigger_files = _FindRuleTriggerFiles(rule, sources)
1172 for tf in trigger_files:
1173 inputs, outputs = _RuleInputsAndOutputs(rule, tf)
1174 if int(rule.get('process_outputs_as_sources', False)):
1175 sources.extend(outputs)
1176 target_dicts[qualified_target]['sources'] = sources
1177 del target_dicts[qualified_target]['rules']
1178 if target_dicts[qualified_target].has_key('actions'):
1179 sources = target_dicts[qualified_target].get('sources', [])
1180 for action in target_dicts[qualified_target]['actions']:
1181 if int(action.get('process_outputs_as_sources', False)):
1182 sources.extend(action.get('outputs', []))
1183 target_dicts[qualified_target]['sources'] = sources
1184 del target_dicts[qualified_target]['actions']
1185
1186 # Make the original target depend on the new target.
1187 if target_dicts[qualified_target].has_key('dependencies'):
1188 target_dicts[qualified_target]['dependencies'].append(new_target)
1189 else:
1190 target_dicts[qualified_target]['dependencies'] = [new_target]
1191
1192 # Assign a new GUID to the new target.
1193 default_config = target_dicts[new_target]['configurations'][
1194 target_dicts[new_target]['default_configuration']]
1195 default_config['msvs_guid'] = str(uuid.uuid4()).upper()
Mark Mentovai 2010/07/07 17:45:28 I’d prefer if these were deterministic so that the
1196
1197 return new_target
1198
1199
1137 def GenerateOutput(target_list, target_dicts, data, params): 1200 def GenerateOutput(target_list, target_dicts, data, params):
1138 """Generate .sln and .vcproj files. 1201 """Generate .sln and .vcproj files.
1139 1202
1140 This is the entry point for this generator. 1203 This is the entry point for this generator.
1141 Arguments: 1204 Arguments:
1142 target_list: List of target pairs: 'base/base.gyp:base'. 1205 target_list: List of target pairs: 'base/base.gyp:base'.
1143 target_dicts: Dict of target properties keyed on target pair. 1206 target_dicts: Dict of target properties keyed on target pair.
1144 data: Dictionary containing per .gyp data. 1207 data: Dictionary containing per .gyp data.
1145 """ 1208 """
1146 global fixpath_prefix 1209 global fixpath_prefix
1147 1210
1148 options = params['options'] 1211 options = params['options']
1149 generator_flags = params.get('generator_flags', {}) 1212 generator_flags = params.get('generator_flags', {})
1150 1213
1151 # Get the project file format version back out of where we stashed it in 1214 # Get the project file format version back out of where we stashed it in
1152 # GeneratorCalculatedVariables. 1215 # GeneratorCalculatedVariables.
1153 msvs_version = params['msvs_version'] 1216 msvs_version = params['msvs_version']
1154 1217
1155 # Prepare the set of configurations. 1218 # Prepare the set of configurations.
1156 configs = set() 1219 configs = set()
1157 for qualified_target in target_list: 1220 for qualified_target in target_list:
1158 build_file = gyp.common.BuildFile(qualified_target) 1221 build_file = gyp.common.BuildFile(qualified_target)
1159 spec = target_dicts[qualified_target] 1222 spec = target_dicts[qualified_target]
1160 for config_name, c in spec['configurations'].iteritems(): 1223 for config_name, c in spec['configurations'].iteritems():
1161 configs.add(_ConfigFullName(config_name, c)) 1224 configs.add(_ConfigFullName(config_name, c))
1162 configs = list(configs) 1225 configs = list(configs)
1163 1226
1227 # MSVS has some "issues" with checking dependencies for the "Compile
1228 # sources" step with any source files/headers generated by actions/rules.
1229 # To work around this, if a target is building anything directly (not
1230 # type "none"), then a second target as used to run the GYP actions/rules
1231 # and is made a dependency of this target. This way the work is done
1232 # before the dependency checks for what should be recompiled.
1233 new_target_list = []
1234 for qualified_target in target_list:
1235 # Check whether the target has rules or actions with the
1236 # process_outputs_as_sources flag set.
Mark Mentovai 2010/07/14 17:34:55 When we split the targets up this way on the Mac,
1237 spec = target_dicts[qualified_target]
1238 spec_actions = spec.get('actions', [])
1239 spec_rules = spec.get('rules', [])
1240 process_outputs_as_sources = False
1241 for action in spec_actions:
1242 if int(action.get('process_outputs_as_sources', False)):
1243 process_outputs_as_sources = True
1244 for rule in spec_rules:
1245 if int(rule.get('process_outputs_as_sources', False)):
1246 process_outputs_as_sources = True
1247
1248 if spec['type'] != 'none' and process_outputs_as_sources:
1249 # Create a new target as copy of the current target.
1250 new_target = _CreatePrebuildTarget(target_dicts, qualified_target)
1251 new_target_list.append(new_target)
1252
1253 # Save the current target in the list of targets.
1254 new_target_list.append(qualified_target)
1255
1256 target_list = new_target_list
1257
1164 # Generate each project. 1258 # Generate each project.
1165 projects = {} 1259 projects = {}
1166 for qualified_target in target_list: 1260 for qualified_target in target_list:
1167 build_file = gyp.common.BuildFile(qualified_target) 1261 build_file = gyp.common.BuildFile(qualified_target)
1168 spec = target_dicts[qualified_target] 1262 spec = target_dicts[qualified_target]
1169 if spec['toolset'] != 'target': 1263 if spec['toolset'] != 'target':
1170 raise Exception( 1264 raise Exception(
1171 'Multiple toolsets not supported in msvs build (target %s)' % 1265 'Multiple toolsets not supported in msvs build (target %s)' %
1172 qualified_target) 1266 qualified_target)
1173 default_config = spec['configurations'][spec['default_configuration']] 1267 default_config = spec['configurations'][spec['default_configuration']]
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 # Create folder hierarchy. 1301 # Create folder hierarchy.
1208 root_entries = _GatherSolutionFolders( 1302 root_entries = _GatherSolutionFolders(
1209 project_objs, flat=msvs_version.FlatSolution()) 1303 project_objs, flat=msvs_version.FlatSolution())
1210 # Create solution. 1304 # Create solution.
1211 sln = MSVSNew.MSVSSolution(sln_path, 1305 sln = MSVSNew.MSVSSolution(sln_path,
1212 entries=root_entries, 1306 entries=root_entries,
1213 variants=configs, 1307 variants=configs,
1214 websiteProperties=False, 1308 websiteProperties=False,
1215 version=msvs_version) 1309 version=msvs_version)
1216 sln.Write() 1310 sln.Write()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698