Chromium Code Reviews| Index: pylib/gyp/generator/msvs.py |
| =================================================================== |
| --- pylib/gyp/generator/msvs.py (revision 836) |
| +++ pylib/gyp/generator/msvs.py (working copy) |
| @@ -4,12 +4,14 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +from copy import deepcopy |
| import ntpath |
| +import os |
| import posixpath |
| -import os |
| import re |
| import subprocess |
| import sys |
| +import uuid |
| import gyp.MSVSNew as MSVSNew |
| import gyp.MSVSProject as MSVSProject |
| @@ -1134,6 +1136,67 @@ |
| default_variables['MSVS_OS_BITS'] = 32 |
| +def _CreatePrebuildTarget(target_dicts, qualified_target): |
| + """ Move all rules/actions from qualified_target to a new target. |
| + |
| + Arguments: |
| + target_dicts: Dict of target properties keyed on target pair. |
| + qualified_target: Target to duplicate. |
| + Returns: |
| + Name of the new target. |
| + """ |
| + [build_file, target, toolset] = gyp.common.ParseQualifiedTarget( |
| + qualified_target) |
| + new_target = '%s:%s_prebuild' % (build_file, target) |
| + if toolset: |
| + new_target += '#%s' % (toolset) |
| + if target_dicts.has_key(new_target): |
| + raise Exception( |
| + 'Targets ending in _prebuild not supported in msvs build ' |
| + '(target %s)' % target) |
| + target_dicts[new_target] = deepcopy(target_dicts[qualified_target]) |
| + target_dicts[new_target]['target_name'] = '%s_prebuild' % (target) |
| + target_dicts[new_target]['original_target_name'] = target |
| + target_dicts[new_target]['type'] = 'none' |
| + for config_name, c in target_dicts[new_target]['configurations'].iteritems(): |
| + if not c.has_key('msvs_configuration_attributes'): |
| + c['msvs_configuration_attributes'] = dict() |
| + c['msvs_configuration_attributes']['IntermediateDirectory' |
| + ] = '$(ConfigurationName)\\obj\\%s' % (target) |
| + |
| + # Remove actions and rules from the original target. |
| + if target_dicts[qualified_target].has_key('rules'): |
| + sources = target_dicts[qualified_target].get('sources', []) |
| + for rule in target_dicts[qualified_target]['rules']: |
| + trigger_files = _FindRuleTriggerFiles(rule, sources) |
| + for tf in trigger_files: |
| + inputs, outputs = _RuleInputsAndOutputs(rule, tf) |
| + if int(rule.get('process_outputs_as_sources', False)): |
| + sources.extend(outputs) |
| + target_dicts[qualified_target]['sources'] = sources |
| + del target_dicts[qualified_target]['rules'] |
| + if target_dicts[qualified_target].has_key('actions'): |
| + sources = target_dicts[qualified_target].get('sources', []) |
| + for action in target_dicts[qualified_target]['actions']: |
| + if int(action.get('process_outputs_as_sources', False)): |
| + sources.extend(action.get('outputs', [])) |
| + target_dicts[qualified_target]['sources'] = sources |
| + del target_dicts[qualified_target]['actions'] |
| + |
| + # Make the original target depend on the new target. |
| + if target_dicts[qualified_target].has_key('dependencies'): |
| + target_dicts[qualified_target]['dependencies'].append(new_target) |
| + else: |
| + target_dicts[qualified_target]['dependencies'] = [new_target] |
| + |
| + # Assign a new GUID to the new target. |
| + default_config = target_dicts[new_target]['configurations'][ |
| + target_dicts[new_target]['default_configuration']] |
| + 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
|
| + |
| + return new_target |
| + |
| + |
| def GenerateOutput(target_list, target_dicts, data, params): |
| """Generate .sln and .vcproj files. |
| @@ -1161,6 +1224,37 @@ |
| configs.add(_ConfigFullName(config_name, c)) |
| configs = list(configs) |
| + # MSVS has some "issues" with checking dependencies for the "Compile |
| + # sources" step with any source files/headers generated by actions/rules. |
| + # To work around this, if a target is building anything directly (not |
| + # type "none"), then a second target as used to run the GYP actions/rules |
| + # and is made a dependency of this target. This way the work is done |
| + # before the dependency checks for what should be recompiled. |
| + new_target_list = [] |
| + for qualified_target in target_list: |
| + # Check whether the target has rules or actions with the |
| + # 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,
|
| + spec = target_dicts[qualified_target] |
| + spec_actions = spec.get('actions', []) |
| + spec_rules = spec.get('rules', []) |
| + process_outputs_as_sources = False |
| + for action in spec_actions: |
| + if int(action.get('process_outputs_as_sources', False)): |
| + process_outputs_as_sources = True |
| + for rule in spec_rules: |
| + if int(rule.get('process_outputs_as_sources', False)): |
| + process_outputs_as_sources = True |
| + |
| + if spec['type'] != 'none' and process_outputs_as_sources: |
| + # Create a new target as copy of the current target. |
| + new_target = _CreatePrebuildTarget(target_dicts, qualified_target) |
| + new_target_list.append(new_target) |
| + |
| + # Save the current target in the list of targets. |
| + new_target_list.append(qualified_target) |
| + |
| + target_list = new_target_list |
| + |
| # Generate each project. |
| projects = {} |
| for qualified_target in target_list: |