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

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

Issue 245923003: Fix msvs-ninja OutputDirectory path. (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: FindVisualStudioInstallation to locate MSBuild. Created 6 years, 6 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
« no previous file with comments | « buildbot/buildbot_run.py ('k') | test/ios/gyptest-xcode-ninja.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
11 import sys 11 import sys
12 12
13 import gyp.common 13 import gyp.common
14 import gyp.easy_xml as easy_xml 14 import gyp.easy_xml as easy_xml
15 import gyp.generator.ninja as ninja_generator
15 import gyp.MSVSNew as MSVSNew 16 import gyp.MSVSNew as MSVSNew
16 import gyp.MSVSProject as MSVSProject 17 import gyp.MSVSProject as MSVSProject
17 import gyp.MSVSSettings as MSVSSettings 18 import gyp.MSVSSettings as MSVSSettings
18 import gyp.MSVSToolFile as MSVSToolFile 19 import gyp.MSVSToolFile as MSVSToolFile
19 import gyp.MSVSUserFile as MSVSUserFile 20 import gyp.MSVSUserFile as MSVSUserFile
20 import gyp.MSVSUtil as MSVSUtil 21 import gyp.MSVSUtil as MSVSUtil
21 import gyp.MSVSVersion as MSVSVersion 22 import gyp.MSVSVersion as MSVSVersion
22 from gyp.common import GypError 23 from gyp.common import GypError
23 from gyp.common import OrderedSet 24 from gyp.common import OrderedSet
24 25
(...skipping 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 # Set all the dependencies, but not if we are using an external builder like 1781 # Set all the dependencies, but not if we are using an external builder like
1781 # ninja 1782 # ninja
1782 for project in projects.values(): 1783 for project in projects.values():
1783 if not project.spec.get('msvs_external_builder'): 1784 if not project.spec.get('msvs_external_builder'):
1784 deps = project.spec.get('dependencies', []) 1785 deps = project.spec.get('dependencies', [])
1785 deps = [projects[d] for d in deps] 1786 deps = [projects[d] for d in deps]
1786 project.set_dependencies(deps) 1787 project.set_dependencies(deps)
1787 return projects 1788 return projects
1788 1789
1789 1790
1790 def _InitNinjaFlavor(options, target_list, target_dicts): 1791 def _InitNinjaFlavor(params, target_list, target_dicts):
1791 """Initialize targets for the ninja flavor. 1792 """Initialize targets for the ninja flavor.
1792 1793
1793 This sets up the necessary variables in the targets to generate msvs projects 1794 This sets up the necessary variables in the targets to generate msvs projects
1794 that use ninja as an external builder. The variables in the spec are only set 1795 that use ninja as an external builder. The variables in the spec are only set
1795 if they have not been set. This allows individual specs to override the 1796 if they have not been set. This allows individual specs to override the
1796 default values initialized here. 1797 default values initialized here.
1797 Arguments: 1798 Arguments:
1798 options: Options provided to the generator. 1799 params: Params provided to the generator.
1799 target_list: List of target pairs: 'base/base.gyp:base'. 1800 target_list: List of target pairs: 'base/base.gyp:base'.
1800 target_dicts: Dict of target properties keyed on target pair. 1801 target_dicts: Dict of target properties keyed on target pair.
1801 """ 1802 """
1802 for qualified_target in target_list: 1803 for qualified_target in target_list:
1803 spec = target_dicts[qualified_target] 1804 spec = target_dicts[qualified_target]
1804 if spec.get('msvs_external_builder'): 1805 if spec.get('msvs_external_builder'):
1805 # The spec explicitly defined an external builder, so don't change it. 1806 # The spec explicitly defined an external builder, so don't change it.
1806 continue 1807 continue
1807 1808
1808 path_to_ninja = spec.get('msvs_path_to_ninja', 'ninja.exe') 1809 path_to_ninja = spec.get('msvs_path_to_ninja', 'ninja.exe')
1809 1810
1810 spec['msvs_external_builder'] = 'ninja' 1811 spec['msvs_external_builder'] = 'ninja'
1811 if not spec.get('msvs_external_builder_out_dir'): 1812 if not spec.get('msvs_external_builder_out_dir'):
1812 spec['msvs_external_builder_out_dir'] = \ 1813 spec['msvs_external_builder_out_dir'] = \
1813 options.depth + '/out/$(Configuration)' 1814 ninja_generator.ComputeOutputDir(params) + '\\$(Configuration)'
Shezan Baig (Bloomberg) 2014/05/31 05:09:55 I ran into another issue with this when I was tryi
bungeman-chromium 2014/06/02 14:55:47 I see now. msvs_external_builder_out_dir is always
1814 if not spec.get('msvs_external_builder_build_cmd'): 1815 if not spec.get('msvs_external_builder_build_cmd'):
1815 spec['msvs_external_builder_build_cmd'] = [ 1816 spec['msvs_external_builder_build_cmd'] = [
1816 path_to_ninja, 1817 path_to_ninja,
1817 '-C', 1818 '-C',
1818 '$(OutDir)', 1819 '$(OutDir)',
1819 '$(ProjectName)', 1820 '$(ProjectName)',
1820 ] 1821 ]
1821 if not spec.get('msvs_external_builder_clean_cmd'): 1822 if not spec.get('msvs_external_builder_clean_cmd'):
1822 spec['msvs_external_builder_clean_cmd'] = [ 1823 spec['msvs_external_builder_clean_cmd'] = [
1823 path_to_ninja, 1824 path_to_ninja,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 # Optionally shard targets marked with 'msvs_shard': SHARD_COUNT. 1899 # Optionally shard targets marked with 'msvs_shard': SHARD_COUNT.
1899 (target_list, target_dicts) = MSVSUtil.ShardTargets(target_list, target_dicts) 1900 (target_list, target_dicts) = MSVSUtil.ShardTargets(target_list, target_dicts)
1900 1901
1901 # Optionally use the large PDB workaround for targets marked with 1902 # Optionally use the large PDB workaround for targets marked with
1902 # 'msvs_large_pdb': 1. 1903 # 'msvs_large_pdb': 1.
1903 (target_list, target_dicts) = MSVSUtil.InsertLargePdbShims( 1904 (target_list, target_dicts) = MSVSUtil.InsertLargePdbShims(
1904 target_list, target_dicts, generator_default_variables) 1905 target_list, target_dicts, generator_default_variables)
1905 1906
1906 # Optionally configure each spec to use ninja as the external builder. 1907 # Optionally configure each spec to use ninja as the external builder.
1907 if params.get('flavor') == 'ninja': 1908 if params.get('flavor') == 'ninja':
1908 _InitNinjaFlavor(options, target_list, target_dicts) 1909 _InitNinjaFlavor(params, target_list, target_dicts)
1909 1910
1910 # Prepare the set of configurations. 1911 # Prepare the set of configurations.
1911 configs = set() 1912 configs = set()
1912 for qualified_target in target_list: 1913 for qualified_target in target_list:
1913 spec = target_dicts[qualified_target] 1914 spec = target_dicts[qualified_target]
1914 for config_name, config in spec['configurations'].iteritems(): 1915 for config_name, config in spec['configurations'].iteritems():
1915 configs.add(_ConfigFullName(config_name, config)) 1916 configs.add(_ConfigFullName(config_name, config))
1916 configs = list(configs) 1917 configs = list(configs)
1917 1918
1918 # Figure out all the projects that will be generated and their guids 1919 # Figure out all the projects that will be generated and their guids
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 return [ 2554 return [
2554 ['PropertyGroup', {'Label': 'Globals'}, 2555 ['PropertyGroup', {'Label': 'Globals'},
2555 ['ProjectGuid', guid], 2556 ['ProjectGuid', guid],
2556 ['Keyword', 'Win32Proj'], 2557 ['Keyword', 'Win32Proj'],
2557 ['RootNamespace', namespace], 2558 ['RootNamespace', namespace],
2558 ['IgnoreWarnCompileDuplicatedFilename', 'true'], 2559 ['IgnoreWarnCompileDuplicatedFilename', 'true'],
2559 ] 2560 ]
2560 ] 2561 ]
2561 2562
2562 2563
2563 def _GetMSBuildConfigurationDetails(spec, build_file): 2564 def _GetMSBuildConfigurationDetails(spec, build_file, project_path):
2564 properties = {} 2565 properties = {}
2565 for name, settings in spec['configurations'].iteritems(): 2566 for name, settings in spec['configurations'].iteritems():
2566 msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file) 2567 msbuild_attributes = _GetMSBuildAttributes(spec, settings,
2568 build_file, project_path)
2567 condition = _GetConfigurationCondition(name, settings) 2569 condition = _GetConfigurationCondition(name, settings)
2568 character_set = msbuild_attributes.get('CharacterSet') 2570 character_set = msbuild_attributes.get('CharacterSet')
2569 _AddConditionalProperty(properties, condition, 'ConfigurationType', 2571 _AddConditionalProperty(properties, condition, 'ConfigurationType',
2570 msbuild_attributes['ConfigurationType']) 2572 msbuild_attributes['ConfigurationType'])
2571 if character_set: 2573 if character_set:
2572 _AddConditionalProperty(properties, condition, 'CharacterSet', 2574 _AddConditionalProperty(properties, condition, 'CharacterSet',
2573 character_set) 2575 character_set)
2574 return _GetMSBuildPropertyGroup(spec, 'Configuration', properties) 2576 return _GetMSBuildPropertyGroup(spec, 'Configuration', properties)
2575 2577
2576 2578
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2663 if config_type.isdigit(): 2665 if config_type.isdigit():
2664 config_type = { 2666 config_type = {
2665 '1': 'Application', 2667 '1': 'Application',
2666 '2': 'DynamicLibrary', 2668 '2': 'DynamicLibrary',
2667 '4': 'StaticLibrary', 2669 '4': 'StaticLibrary',
2668 '10': 'Utility' 2670 '10': 'Utility'
2669 }[config_type] 2671 }[config_type]
2670 return config_type 2672 return config_type
2671 2673
2672 2674
2673 def _GetMSBuildAttributes(spec, config, build_file): 2675 def _GetMSBuildAttributes(spec, config, build_file, project_path):
2674 if 'msbuild_configuration_attributes' not in config: 2676 if 'msbuild_configuration_attributes' not in config:
2675 msbuild_attributes = _ConvertMSVSBuildAttributes(spec, config, build_file) 2677 msbuild_attributes = _ConvertMSVSBuildAttributes(spec, config, build_file)
2676 2678
2677 else: 2679 else:
2678 config_type = _GetMSVSConfigurationType(spec, build_file) 2680 config_type = _GetMSVSConfigurationType(spec, build_file)
2679 config_type = _ConvertMSVSConfigurationType(config_type) 2681 config_type = _ConvertMSVSConfigurationType(config_type)
2680 msbuild_attributes = config.get('msbuild_configuration_attributes', {}) 2682 msbuild_attributes = config.get('msbuild_configuration_attributes', {})
2681 msbuild_attributes.setdefault('ConfigurationType', config_type) 2683 msbuild_attributes.setdefault('ConfigurationType', config_type)
2682 output_dir = msbuild_attributes.get('OutputDirectory', 2684 output_dir = msbuild_attributes.get('OutputDirectory',
2683 '$(SolutionDir)$(Configuration)') 2685 '$(SolutionDir)$(Configuration)')
2684 msbuild_attributes['OutputDirectory'] = _FixPath(output_dir) + '\\' 2686 msbuild_attributes['OutputDirectory'] = _FixPath(output_dir) + '\\'
2685 if 'IntermediateDirectory' not in msbuild_attributes: 2687 if 'IntermediateDirectory' not in msbuild_attributes:
2686 intermediate = _FixPath('$(Configuration)') + '\\' 2688 intermediate = _FixPath('$(Configuration)') + '\\'
2687 msbuild_attributes['IntermediateDirectory'] = intermediate 2689 msbuild_attributes['IntermediateDirectory'] = intermediate
2688 if 'CharacterSet' in msbuild_attributes: 2690 if 'CharacterSet' in msbuild_attributes:
2689 msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet( 2691 msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet(
2690 msbuild_attributes['CharacterSet']) 2692 msbuild_attributes['CharacterSet'])
2691 if 'TargetName' not in msbuild_attributes: 2693 if 'TargetName' not in msbuild_attributes:
2692 prefix = spec.get('product_prefix', '') 2694 prefix = spec.get('product_prefix', '')
2693 product_name = spec.get('product_name', '$(ProjectName)') 2695 product_name = spec.get('product_name', '$(ProjectName)')
2694 target_name = prefix + product_name 2696 target_name = prefix + product_name
2695 msbuild_attributes['TargetName'] = target_name 2697 msbuild_attributes['TargetName'] = target_name
2696 2698
2697 if spec.get('msvs_external_builder'): 2699 if spec.get('msvs_external_builder'):
2698 external_out_dir = spec.get('msvs_external_builder_out_dir', '.') 2700 external_out_dir = spec.get('msvs_external_builder_out_dir', '.')
2699 msbuild_attributes['OutputDirectory'] = _FixPath(external_out_dir) + '\\' 2701 project_dir = os.path.dirname(project_path)
2702 msbuild_attributes['OutputDirectory'] = \
2703 gyp.common.RelativePath(external_out_dir, project_dir) + '\\'
bungeman-chromium 2014/06/02 14:55:47 The external_out_dir is relative to the gyp file i
2700 2704
2701 # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile' 2705 # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile'
2702 # (depending on the tool used) to avoid MSB8012 warning. 2706 # (depending on the tool used) to avoid MSB8012 warning.
2703 msbuild_tool_map = { 2707 msbuild_tool_map = {
2704 'executable': 'Link', 2708 'executable': 'Link',
2705 'shared_library': 'Link', 2709 'shared_library': 'Link',
2706 'loadable_module': 'Link', 2710 'loadable_module': 'Link',
2707 'static_library': 'Lib', 2711 'static_library': 'Lib',
2708 } 2712 }
2709 msbuild_tool = msbuild_tool_map.get(spec['type']) 2713 msbuild_tool = msbuild_tool_map.get(spec['type'])
2710 if msbuild_tool: 2714 if msbuild_tool:
2711 msbuild_settings = config['finalized_msbuild_settings'] 2715 msbuild_settings = config['finalized_msbuild_settings']
2712 out_file = msbuild_settings[msbuild_tool].get('OutputFile') 2716 out_file = msbuild_settings[msbuild_tool].get('OutputFile')
2713 if out_file: 2717 if out_file:
2714 msbuild_attributes['TargetPath'] = _FixPath(out_file) 2718 msbuild_attributes['TargetPath'] = _FixPath(out_file)
2715 target_ext = msbuild_settings[msbuild_tool].get('TargetExt') 2719 target_ext = msbuild_settings[msbuild_tool].get('TargetExt')
2716 if target_ext: 2720 if target_ext:
2717 msbuild_attributes['TargetExt'] = target_ext 2721 msbuild_attributes['TargetExt'] = target_ext
2718 2722
2719 return msbuild_attributes 2723 return msbuild_attributes
2720 2724
2721 2725
2722 def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file): 2726 def _GetMSBuildConfigurationGlobalProperties(spec, configurations,
2727 build_file, project_path):
2723 # TODO(jeanluc) We could optimize out the following and do it only if 2728 # TODO(jeanluc) We could optimize out the following and do it only if
2724 # there are actions. 2729 # there are actions.
2725 # TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'. 2730 # TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
2726 new_paths = [] 2731 new_paths = []
2727 cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.'])[0] 2732 cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.'])[0]
2728 if cygwin_dirs: 2733 if cygwin_dirs:
2729 cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs) 2734 cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs)
2730 new_paths.append(cyg_path) 2735 new_paths.append(cyg_path)
2731 # TODO(jeanluc) Change the convention to have both a cygwin_dir and a 2736 # TODO(jeanluc) Change the convention to have both a cygwin_dir and a
2732 # python_dir. 2737 # python_dir.
2733 python_path = cyg_path.replace('cygwin\\bin', 'python_26') 2738 python_path = cyg_path.replace('cygwin\\bin', 'python_26')
2734 new_paths.append(python_path) 2739 new_paths.append(python_path)
2735 if new_paths: 2740 if new_paths:
2736 new_paths = '$(ExecutablePath);' + ';'.join(new_paths) 2741 new_paths = '$(ExecutablePath);' + ';'.join(new_paths)
2737 2742
2738 properties = {} 2743 properties = {}
2739 for (name, configuration) in sorted(configurations.iteritems()): 2744 for (name, configuration) in sorted(configurations.iteritems()):
2740 condition = _GetConfigurationCondition(name, configuration) 2745 condition = _GetConfigurationCondition(name, configuration)
2741 attributes = _GetMSBuildAttributes(spec, configuration, build_file) 2746 attributes = _GetMSBuildAttributes(spec, configuration,
2747 build_file, project_path)
2742 msbuild_settings = configuration['finalized_msbuild_settings'] 2748 msbuild_settings = configuration['finalized_msbuild_settings']
2743 _AddConditionalProperty(properties, condition, 'IntDir', 2749 _AddConditionalProperty(properties, condition, 'IntDir',
2744 attributes['IntermediateDirectory']) 2750 attributes['IntermediateDirectory'])
2745 _AddConditionalProperty(properties, condition, 'OutDir', 2751 _AddConditionalProperty(properties, condition, 'OutDir',
2746 attributes['OutputDirectory']) 2752 attributes['OutputDirectory'])
2747 _AddConditionalProperty(properties, condition, 'TargetName', 2753 _AddConditionalProperty(properties, condition, 'TargetName',
2748 attributes['TargetName']) 2754 attributes['TargetName'])
2749 2755
2750 if attributes.get('TargetPath'): 2756 if attributes.get('TargetPath'):
2751 _AddConditionalProperty(properties, condition, 'TargetPath', 2757 _AddConditionalProperty(properties, condition, 'TargetPath',
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
3161 content = [ 3167 content = [
3162 'Project', 3168 'Project',
3163 {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003', 3169 {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003',
3164 'ToolsVersion': version.ProjectVersion(), 3170 'ToolsVersion': version.ProjectVersion(),
3165 'DefaultTargets': 'Build' 3171 'DefaultTargets': 'Build'
3166 }] 3172 }]
3167 3173
3168 content += _GetMSBuildProjectConfigurations(configurations) 3174 content += _GetMSBuildProjectConfigurations(configurations)
3169 content += _GetMSBuildGlobalProperties(spec, project.guid, project_file_name) 3175 content += _GetMSBuildGlobalProperties(spec, project.guid, project_file_name)
3170 content += import_default_section 3176 content += import_default_section
3171 content += _GetMSBuildConfigurationDetails(spec, project.build_file) 3177 content += _GetMSBuildConfigurationDetails(spec,
3178 project.build_file, project.path)
3172 content += _GetMSBuildLocalProperties(project.msbuild_toolset) 3179 content += _GetMSBuildLocalProperties(project.msbuild_toolset)
3173 content += import_cpp_props_section 3180 content += import_cpp_props_section
3174 content += _GetMSBuildExtensions(props_files_of_rules) 3181 content += _GetMSBuildExtensions(props_files_of_rules)
3175 content += _GetMSBuildPropertySheets(configurations) 3182 content += _GetMSBuildPropertySheets(configurations)
3176 content += macro_section 3183 content += macro_section
3177 content += _GetMSBuildConfigurationGlobalProperties(spec, configurations, 3184 content += _GetMSBuildConfigurationGlobalProperties(spec, configurations,
3178 project.build_file) 3185 project.build_file,
3186 project.path)
3179 content += _GetMSBuildToolSettingsSections(spec, configurations) 3187 content += _GetMSBuildToolSettingsSections(spec, configurations)
3180 content += _GetMSBuildSources( 3188 content += _GetMSBuildSources(
3181 spec, sources, exclusions, extension_to_rule_name, actions_spec, 3189 spec, sources, exclusions, extension_to_rule_name, actions_spec,
3182 sources_handled_by_action, list_excluded) 3190 sources_handled_by_action, list_excluded)
3183 content += _GetMSBuildProjectReferences(project) 3191 content += _GetMSBuildProjectReferences(project)
3184 content += import_cpp_targets_section 3192 content += import_cpp_targets_section
3185 content += _GetMSBuildExtensionTargets(targets_files_of_rules) 3193 content += _GetMSBuildExtensionTargets(targets_files_of_rules)
3186 3194
3187 if spec.get('msvs_external_builder'): 3195 if spec.get('msvs_external_builder'):
3188 content += _GetMSBuildExternalBuilderTargets(spec) 3196 content += _GetMSBuildExternalBuilderTargets(spec)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3310 action_spec.extend( 3318 action_spec.extend(
3311 # TODO(jeanluc) 'Document' for all or just if as_sources? 3319 # TODO(jeanluc) 'Document' for all or just if as_sources?
3312 [['FileType', 'Document'], 3320 [['FileType', 'Document'],
3313 ['Command', command], 3321 ['Command', command],
3314 ['Message', description], 3322 ['Message', description],
3315 ['Outputs', outputs] 3323 ['Outputs', outputs]
3316 ]) 3324 ])
3317 if additional_inputs: 3325 if additional_inputs:
3318 action_spec.append(['AdditionalInputs', additional_inputs]) 3326 action_spec.append(['AdditionalInputs', additional_inputs])
3319 actions_spec.append(action_spec) 3327 actions_spec.append(action_spec)
OLDNEW
« no previous file with comments | « buildbot/buildbot_run.py ('k') | test/ios/gyptest-xcode-ninja.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698