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

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

Issue 13867004: Integrate ninja build with Visual Studio (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: added tests and msvs-ninja flavor Created 7 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
« no previous file with comments | « no previous file | test/lib/TestGyp.py » ('j') | test/msvs/external_builder/external.gyp » ('J')
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 'msvs_cygwin_dirs', 59 'msvs_cygwin_dirs',
60 'msvs_props', 60 'msvs_props',
61 ] 61 ]
62 62
63 63
64 generator_additional_non_configuration_keys = [ 64 generator_additional_non_configuration_keys = [
65 'msvs_cygwin_dirs', 65 'msvs_cygwin_dirs',
66 'msvs_cygwin_shell', 66 'msvs_cygwin_shell',
67 'msvs_large_pdb', 67 'msvs_large_pdb',
68 'msvs_shard', 68 'msvs_shard',
69 'msvs_external_builder',
70 'msvs_external_builder_out_dir',
71 'msvs_external_builder_build_cmd',
72 'msvs_external_builder_clean_cmd',
69 ] 73 ]
70 74
71 75
72 # List of precompiled header related keys. 76 # List of precompiled header related keys.
73 precomp_keys = [ 77 precomp_keys = [
74 'msvs_precompiled_header', 78 'msvs_precompiled_header',
75 'msvs_precompiled_source', 79 'msvs_precompiled_source',
76 ] 80 ]
77 81
78 82
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 guid=guid, 1692 guid=guid,
1689 spec=spec, 1693 spec=spec,
1690 build_file=build_file, 1694 build_file=build_file,
1691 config_platform_overrides=overrides, 1695 config_platform_overrides=overrides,
1692 fixpath_prefix=fixpath_prefix) 1696 fixpath_prefix=fixpath_prefix)
1693 # Set project toolset if any (MS build only) 1697 # Set project toolset if any (MS build only)
1694 if msvs_version.UsesVcxproj(): 1698 if msvs_version.UsesVcxproj():
1695 obj.set_msbuild_toolset( 1699 obj.set_msbuild_toolset(
1696 _GetMsbuildToolsetOfProject(proj_path, spec, msvs_version)) 1700 _GetMsbuildToolsetOfProject(proj_path, spec, msvs_version))
1697 projects[qualified_target] = obj 1701 projects[qualified_target] = obj
1698 # Set all the dependencies 1702 # Set all the dependencies, but not if we are using an external builder like
1703 # ninja
1699 for project in projects.values(): 1704 for project in projects.values():
1700 deps = project.spec.get('dependencies', []) 1705 if not project.spec.get('msvs_external_builder'):
1701 deps = [projects[d] for d in deps] 1706 deps = project.spec.get('dependencies', [])
1702 project.set_dependencies(deps) 1707 deps = [projects[d] for d in deps]
1708 project.set_dependencies(deps)
1703 return projects 1709 return projects
1704 1710
1711 def _InitNinjaFlavor(options, target_list, target_dicts):
scottmg 2013/04/16 22:48:00 nit; 2 line space
1712 """Initialize targets for the ninja flavor.
1713
1714 This sets up the necessary variables in the targets to generate msvs projects
1715 that use ninja as an external builder. The variables in the spec are only set
1716 if they have not been set. This allows individual specs to override the
1717 default values initialized here.
1718 Arguments:
1719 options: Options provided to the generator.
1720 target_list: List of target pairs: 'base/base.gyp:base'.
1721 target_dicts: Dict of target properties keyed on target pair.
1722 """
1723 for qualified_target in target_list:
1724 spec = target_dicts[qualified_target]
1725 if spec.get('msvs_external_builder'):
1726 # The spec explicitly defined an external builder, so don't change it.
1727 continue
1728
1729 path_to_ninja = spec.get('msvs_path_to_ninja', 'ninja.exe')
1730
1731 spec['msvs_external_builder'] = 'ninja'
1732 if not spec.get('msvs_external_builder_out_dir'):
1733 spec['msvs_external_builder_out_dir'] = \
1734 options.depth + '/out/$(Configuration)'
1735 if not spec.get('msvs_external_builder_build_cmd'):
1736 spec['msvs_external_builder_build_cmd'] = [
1737 path_to_ninja,
1738 '-C',
1739 '$(OutDir)',
1740 '$(ProjectName)',
1741 ]
1742 if not spec.get('msvs_external_builder_clean_cmd'):
1743 spec['msvs_external_builder_clean_cmd'] = [
1744 path_to_ninja,
1745 '-C',
1746 '$(OutDir)',
1747 '-t',
1748 'clean',
1749 '$(ProjectName)',
1750 ]
scottmg 2013/04/16 22:48:00 nit; 2 line space
1705 1751
1706 def CalculateVariables(default_variables, params): 1752 def CalculateVariables(default_variables, params):
1707 """Generated variables that require params to be known.""" 1753 """Generated variables that require params to be known."""
1708 1754
1709 generator_flags = params.get('generator_flags', {}) 1755 generator_flags = params.get('generator_flags', {})
1710 1756
1711 # Select project file format version (if unset, default to auto detecting). 1757 # Select project file format version (if unset, default to auto detecting).
1712 msvs_version = MSVSVersion.SelectVisualStudioVersion( 1758 msvs_version = MSVSVersion.SelectVisualStudioVersion(
1713 generator_flags.get('msvs_version', 'auto')) 1759 generator_flags.get('msvs_version', 'auto'))
1714 # Stash msvs_version for later (so we don't have to probe the system twice). 1760 # Stash msvs_version for later (so we don't have to probe the system twice).
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 generator_flags = params.get('generator_flags', {}) 1813 generator_flags = params.get('generator_flags', {})
1768 1814
1769 # Optionally shard targets marked with 'msvs_shard': SHARD_COUNT. 1815 # Optionally shard targets marked with 'msvs_shard': SHARD_COUNT.
1770 (target_list, target_dicts) = MSVSUtil.ShardTargets(target_list, target_dicts) 1816 (target_list, target_dicts) = MSVSUtil.ShardTargets(target_list, target_dicts)
1771 1817
1772 # Optionally use the large PDB workaround for targets marked with 1818 # Optionally use the large PDB workaround for targets marked with
1773 # 'msvs_large_pdb': 1. 1819 # 'msvs_large_pdb': 1.
1774 (target_list, target_dicts) = MSVSUtil.InsertLargePdbShims( 1820 (target_list, target_dicts) = MSVSUtil.InsertLargePdbShims(
1775 target_list, target_dicts, generator_default_variables) 1821 target_list, target_dicts, generator_default_variables)
1776 1822
1823 # Optionally configure each spec to use ninja as the external builder.
1824 if params.get('flavor') == 'ninja':
1825 _InitNinjaFlavor(options, target_list, target_dicts)
1826
1777 # Prepare the set of configurations. 1827 # Prepare the set of configurations.
1778 configs = set() 1828 configs = set()
1779 for qualified_target in target_list: 1829 for qualified_target in target_list:
1780 spec = target_dicts[qualified_target] 1830 spec = target_dicts[qualified_target]
1781 for config_name, config in spec['configurations'].iteritems(): 1831 for config_name, config in spec['configurations'].iteritems():
1782 configs.add(_ConfigFullName(config_name, config)) 1832 configs.add(_ConfigFullName(config_name, config))
1783 configs = list(configs) 1833 configs = list(configs)
1784 1834
1785 # Figure out all the projects that will be generated and their guids 1835 # Figure out all the projects that will be generated and their guids
1786 project_objects = _CreateProjectObjects(target_list, target_dicts, options, 1836 project_objects = _CreateProjectObjects(target_list, target_dicts, options,
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 msbuild_attributes['IntermediateDirectory'] = intermediate 2603 msbuild_attributes['IntermediateDirectory'] = intermediate
2554 if 'CharacterSet' in msbuild_attributes: 2604 if 'CharacterSet' in msbuild_attributes:
2555 msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet( 2605 msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet(
2556 msbuild_attributes['CharacterSet']) 2606 msbuild_attributes['CharacterSet'])
2557 if 'TargetName' not in msbuild_attributes: 2607 if 'TargetName' not in msbuild_attributes:
2558 prefix = spec.get('product_prefix', '') 2608 prefix = spec.get('product_prefix', '')
2559 product_name = spec.get('product_name', '$(ProjectName)') 2609 product_name = spec.get('product_name', '$(ProjectName)')
2560 target_name = prefix + product_name 2610 target_name = prefix + product_name
2561 msbuild_attributes['TargetName'] = target_name 2611 msbuild_attributes['TargetName'] = target_name
2562 2612
2613 if spec.get('msvs_external_builder'):
2614 external_out_dir = spec.get('msvs_external_builder_out_dir', '.')
2615 msbuild_attributes['OutputDirectory'] = _FixPath(external_out_dir) + '\\'
2616
2563 # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile' 2617 # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile'
2564 # (depending on the tool used) to avoid MSB8012 warning. 2618 # (depending on the tool used) to avoid MSB8012 warning.
2565 msbuild_tool_map = { 2619 msbuild_tool_map = {
2566 'executable': 'Link', 2620 'executable': 'Link',
2567 'shared_library': 'Link', 2621 'shared_library': 'Link',
2568 'loadable_module': 'Link', 2622 'loadable_module': 'Link',
2569 'static_library': 'Lib', 2623 'static_library': 'Lib',
2570 } 2624 }
2571 msbuild_tool = msbuild_tool_map.get(spec['type']) 2625 msbuild_tool = msbuild_tool_map.get(spec['type'])
2572 if msbuild_tool: 2626 if msbuild_tool:
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
2951 3005
2952 gyp_file = os.path.split(project.build_file)[1] 3006 gyp_file = os.path.split(project.build_file)[1]
2953 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, 3007 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags,
2954 gyp_file) 3008 gyp_file)
2955 # Add rules. 3009 # Add rules.
2956 actions_to_add = {} 3010 actions_to_add = {}
2957 props_files_of_rules = set() 3011 props_files_of_rules = set()
2958 targets_files_of_rules = set() 3012 targets_files_of_rules = set()
2959 extension_to_rule_name = {} 3013 extension_to_rule_name = {}
2960 list_excluded = generator_flags.get('msvs_list_excluded_files', True) 3014 list_excluded = generator_flags.get('msvs_list_excluded_files', True)
2961 _GenerateRulesForMSBuild(project_dir, options, spec, 3015
2962 sources, excluded_sources, 3016 # Don't generate rules if we are using an external builder like ninja.
2963 props_files_of_rules, targets_files_of_rules, 3017 if not spec.get('msvs_external_builder'):
2964 actions_to_add, extension_to_rule_name) 3018 _GenerateRulesForMSBuild(project_dir, options, spec,
3019 sources, excluded_sources,
3020 props_files_of_rules, targets_files_of_rules,
3021 actions_to_add, extension_to_rule_name)
3022
2965 sources, excluded_sources, excluded_idl = ( 3023 sources, excluded_sources, excluded_idl = (
2966 _AdjustSourcesAndConvertToFilterHierarchy(spec, options, 3024 _AdjustSourcesAndConvertToFilterHierarchy(spec, options,
2967 project_dir, sources, 3025 project_dir, sources,
2968 excluded_sources, 3026 excluded_sources,
2969 list_excluded)) 3027 list_excluded))
2970 _AddActions(actions_to_add, spec, project.build_file)
2971 _AddCopies(actions_to_add, spec)
2972 3028
2973 # NOTE: this stanza must appear after all actions have been decided. 3029 # Don't add actions if we are using an external builder like ninja.
2974 # Don't excluded sources with actions attached, or they won't run. 3030 if not spec.get('msvs_external_builder'):
2975 excluded_sources = _FilterActionsFromExcluded( 3031 _AddActions(actions_to_add, spec, project.build_file)
2976 excluded_sources, actions_to_add) 3032 _AddCopies(actions_to_add, spec)
3033
3034 # NOTE: this stanza must appear after all actions have been decided.
3035 # Don't excluded sources with actions attached, or they won't run.
3036 excluded_sources = _FilterActionsFromExcluded(
3037 excluded_sources, actions_to_add)
2977 3038
2978 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) 3039 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
2979 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild( 3040 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild(
2980 spec, actions_to_add) 3041 spec, actions_to_add)
2981 3042
2982 _GenerateMSBuildFiltersFile(project.path + '.filters', sources, 3043 _GenerateMSBuildFiltersFile(project.path + '.filters', sources,
2983 extension_to_rule_name) 3044 extension_to_rule_name)
2984 missing_sources = _VerifySourcesExist(sources, project_dir) 3045 missing_sources = _VerifySourcesExist(sources, project_dir)
2985 3046
2986 for configuration in configurations.itervalues(): 3047 for configuration in configurations.itervalues():
(...skipping 28 matching lines...) Expand all
3015 content += _GetMSBuildConfigurationGlobalProperties(spec, configurations, 3076 content += _GetMSBuildConfigurationGlobalProperties(spec, configurations,
3016 project.build_file) 3077 project.build_file)
3017 content += _GetMSBuildToolSettingsSections(spec, configurations) 3078 content += _GetMSBuildToolSettingsSections(spec, configurations)
3018 content += _GetMSBuildSources( 3079 content += _GetMSBuildSources(
3019 spec, sources, exclusions, extension_to_rule_name, actions_spec, 3080 spec, sources, exclusions, extension_to_rule_name, actions_spec,
3020 sources_handled_by_action, list_excluded) 3081 sources_handled_by_action, list_excluded)
3021 content += _GetMSBuildProjectReferences(project) 3082 content += _GetMSBuildProjectReferences(project)
3022 content += import_cpp_targets_section 3083 content += import_cpp_targets_section
3023 content += _GetMSBuildExtensionTargets(targets_files_of_rules) 3084 content += _GetMSBuildExtensionTargets(targets_files_of_rules)
3024 3085
3086 if spec.get('msvs_external_builder'):
3087 content += _GetMSBuildExternalBuilderTargets(spec)
3088
3025 # TODO(jeanluc) File a bug to get rid of runas. We had in MSVS: 3089 # TODO(jeanluc) File a bug to get rid of runas. We had in MSVS:
3026 # has_run_as = _WriteMSVSUserFile(project.path, version, spec) 3090 # has_run_as = _WriteMSVSUserFile(project.path, version, spec)
3027 3091
3028 easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True) 3092 easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True)
3029 3093
3030 return missing_sources 3094 return missing_sources
3031 3095
3096 def _GetMSBuildExternalBuilderTargets(spec):
scottmg 2013/04/16 22:48:00 nit; 2 line space
3097 """Return a list of MSBuild targets for external builders.
3098
3099 Right now, only "Build" and "Clean" targets are generated.
3100
3101 Arguments:
3102 spec: The gyp target spec.
3103 Returns:
3104 List of MSBuild 'Target' specs.
3105 """
3106 build_cmd = _BuildCommandLineForRuleRaw(
3107 spec, spec['msvs_external_builder_build_cmd'],
3108 False, False, False, False)
3109 build_target = ['Target', {'Name': 'Build'}]
3110 build_target.append(['Exec', {'Command': build_cmd}])
3111
3112 clean_cmd = _BuildCommandLineForRuleRaw(
3113 spec, spec['msvs_external_builder_clean_cmd'],
3114 False, False, False, False)
3115 clean_target = ['Target', {'Name': 'Clean'}]
3116 clean_target.append(['Exec', {'Command': clean_cmd}])
3117
3118 return [build_target, clean_target]
3032 3119
scottmg 2013/04/16 22:48:00 nit; 2 line space
3033 def _GetMSBuildExtensions(props_files_of_rules): 3120 def _GetMSBuildExtensions(props_files_of_rules):
3034 extensions = ['ImportGroup', {'Label': 'ExtensionSettings'}] 3121 extensions = ['ImportGroup', {'Label': 'ExtensionSettings'}]
3035 for props_file in props_files_of_rules: 3122 for props_file in props_files_of_rules:
3036 extensions.append(['Import', {'Project': props_file}]) 3123 extensions.append(['Import', {'Project': props_file}])
3037 return [extensions] 3124 return [extensions]
3038 3125
3039 3126
3040 def _GetMSBuildExtensionTargets(targets_files_of_rules): 3127 def _GetMSBuildExtensionTargets(targets_files_of_rules):
3041 targets_node = ['ImportGroup', {'Label': 'ExtensionTargets'}] 3128 targets_node = ['ImportGroup', {'Label': 'ExtensionTargets'}]
3042 for targets_file in sorted(targets_files_of_rules): 3129 for targets_file in sorted(targets_files_of_rules):
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3108 action_spec.extend( 3195 action_spec.extend(
3109 # TODO(jeanluc) 'Document' for all or just if as_sources? 3196 # TODO(jeanluc) 'Document' for all or just if as_sources?
3110 [['FileType', 'Document'], 3197 [['FileType', 'Document'],
3111 ['Command', command], 3198 ['Command', command],
3112 ['Message', description], 3199 ['Message', description],
3113 ['Outputs', outputs] 3200 ['Outputs', outputs]
3114 ]) 3201 ])
3115 if additional_inputs: 3202 if additional_inputs:
3116 action_spec.append(['AdditionalInputs', additional_inputs]) 3203 action_spec.append(['AdditionalInputs', additional_inputs])
3117 actions_spec.append(action_spec) 3204 actions_spec.append(action_spec)
OLDNEW
« no previous file with comments | « no previous file | test/lib/TestGyp.py » ('j') | test/msvs/external_builder/external.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698