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

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: Fixed build target names 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 | no next file » | 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
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 # The msvs specific sections that hold paths 57 # The msvs specific sections that hold paths
58 generator_additional_path_sections = [ 58 generator_additional_path_sections = [
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_ninja_out_dir',
66 'msvs_cygwin_shell', 67 'msvs_cygwin_shell',
67 'msvs_large_pdb', 68 'msvs_large_pdb',
68 'msvs_shard', 69 'msvs_shard',
69 ] 70 ]
70 71
71 72
72 # List of precompiled header related keys. 73 # List of precompiled header related keys.
73 precomp_keys = [ 74 precomp_keys = [
74 'msvs_precompiled_header', 75 'msvs_precompiled_header',
75 'msvs_precompiled_source', 76 'msvs_precompiled_source',
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 903
903 platforms = _GetUniquePlatforms(spec) 904 platforms = _GetUniquePlatforms(spec)
904 p = MSVSProject.Writer(project.path, version, spec['target_name'], 905 p = MSVSProject.Writer(project.path, version, spec['target_name'],
905 project.guid, platforms) 906 project.guid, platforms)
906 907
907 # Get directory project file is in. 908 # Get directory project file is in.
908 project_dir = os.path.split(project.path)[0] 909 project_dir = os.path.split(project.path)[0]
909 gyp_path = _NormalizedSource(project.build_file) 910 gyp_path = _NormalizedSource(project.build_file)
910 relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir) 911 relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
911 912
912 config_type = _GetMSVSConfigurationType(spec, project.build_file) 913 config_type = _GetMSVSConfigurationType(spec, project.build_file, None)
913 for config_name, config in spec['configurations'].iteritems(): 914 for config_name, config in spec['configurations'].iteritems():
914 _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config) 915 _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config)
915 916
916 # Prepare list of sources and excluded sources. 917 # Prepare list of sources and excluded sources.
917 gyp_file = os.path.split(project.build_file)[1] 918 gyp_file = os.path.split(project.build_file)[1]
918 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, 919 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags,
919 gyp_file) 920 gyp_file)
920 921
921 # Add rules. 922 # Add rules.
922 actions_to_add = {} 923 actions_to_add = {}
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 Returns: 980 Returns:
980 The MSVSUserFile object created. 981 The MSVSUserFile object created.
981 """ 982 """
982 (domain, username) = _GetDomainAndUserName() 983 (domain, username) = _GetDomainAndUserName()
983 vcuser_filename = '.'.join([proj_path, domain, username, 'user']) 984 vcuser_filename = '.'.join([proj_path, domain, username, 'user'])
984 user_file = MSVSUserFile.Writer(vcuser_filename, version, 985 user_file = MSVSUserFile.Writer(vcuser_filename, version,
985 spec['target_name']) 986 spec['target_name'])
986 return user_file 987 return user_file
987 988
988 989
989 def _GetMSVSConfigurationType(spec, build_file): 990 def _GetMSVSConfigurationType(spec, build_file, external_builder):
990 """Returns the configuration type for this project. 991 """Returns the configuration type for this project.
991 992
992 It's a number defined by Microsoft. May raise an exception. 993 It's a number defined by Microsoft. May raise an exception.
993 994
994 Args: 995 Args:
995 spec: The target dictionary containing the properties of the target. 996 spec: The target dictionary containing the properties of the target.
996 build_file: The path of the gyp file. 997 build_file: The path of the gyp file.
998 external_builder: The external builder specified in the generator flags.
997 Returns: 999 Returns:
998 An integer, the configuration type. 1000 An integer, the configuration type.
999 """ 1001 """
1002 if external_builder != None:
1003 return '10' # Utility type
1000 try: 1004 try:
1001 config_type = { 1005 config_type = {
1002 'executable': '1', # .exe 1006 'executable': '1', # .exe
1003 'shared_library': '2', # .dll 1007 'shared_library': '2', # .dll
1004 'loadable_module': '2', # .dll 1008 'loadable_module': '2', # .dll
1005 'static_library': '4', # .lib 1009 'static_library': '4', # .lib
1006 'none': '10', # Utility type 1010 'none': '10', # Utility type
1007 }[spec['type']] 1011 }[spec['type']]
1008 except KeyError: 1012 except KeyError:
1009 if spec.get('type'): 1013 if spec.get('type'):
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 config_platform_overrides = {} 1653 config_platform_overrides = {}
1650 for config_name, c in spec['configurations'].iteritems(): 1654 for config_name, c in spec['configurations'].iteritems():
1651 config_fullname = _ConfigFullName(config_name, c) 1655 config_fullname = _ConfigFullName(config_name, c)
1652 platform = c.get('msvs_target_platform', _ConfigPlatform(c)) 1656 platform = c.get('msvs_target_platform', _ConfigPlatform(c))
1653 fixed_config_fullname = '%s|%s' % ( 1657 fixed_config_fullname = '%s|%s' % (
1654 _ConfigBaseName(config_name, _ConfigPlatform(c)), platform) 1658 _ConfigBaseName(config_name, _ConfigPlatform(c)), platform)
1655 config_platform_overrides[config_fullname] = fixed_config_fullname 1659 config_platform_overrides[config_fullname] = fixed_config_fullname
1656 return config_platform_overrides 1660 return config_platform_overrides
1657 1661
1658 1662
1659 def _CreateProjectObjects(target_list, target_dicts, options, msvs_version): 1663 def _CreateProjectObjects(target_list, target_dicts, options, msvs_version,
1664 set_dependencies):
1660 """Create a MSVSProject object for the targets found in target list. 1665 """Create a MSVSProject object for the targets found in target list.
1661 1666
1662 Arguments: 1667 Arguments:
1663 target_list: the list of targets to generate project objects for. 1668 target_list: the list of targets to generate project objects for.
1664 target_dicts: the dictionary of specifications. 1669 target_dicts: the dictionary of specifications.
1665 options: global generator options. 1670 options: global generator options.
1666 msvs_version: the MSVSVersion object. 1671 msvs_version: the MSVSVersion object.
1672 set_dependencies: flag to control whether to set dependencies or not.
1667 Returns: 1673 Returns:
1668 A set of created projects, keyed by target. 1674 A set of created projects, keyed by target.
1669 """ 1675 """
1670 global fixpath_prefix 1676 global fixpath_prefix
1671 # Generate each project. 1677 # Generate each project.
1672 projects = {} 1678 projects = {}
1673 for qualified_target in target_list: 1679 for qualified_target in target_list:
1674 spec = target_dicts[qualified_target] 1680 spec = target_dicts[qualified_target]
1675 if spec['toolset'] != 'target': 1681 if spec['toolset'] != 'target':
1676 raise GypError( 1682 raise GypError(
(...skipping 11 matching lines...) Expand all
1688 guid=guid, 1694 guid=guid,
1689 spec=spec, 1695 spec=spec,
1690 build_file=build_file, 1696 build_file=build_file,
1691 config_platform_overrides=overrides, 1697 config_platform_overrides=overrides,
1692 fixpath_prefix=fixpath_prefix) 1698 fixpath_prefix=fixpath_prefix)
1693 # Set project toolset if any (MS build only) 1699 # Set project toolset if any (MS build only)
1694 if msvs_version.UsesVcxproj(): 1700 if msvs_version.UsesVcxproj():
1695 obj.set_msbuild_toolset( 1701 obj.set_msbuild_toolset(
1696 _GetMsbuildToolsetOfProject(proj_path, spec, msvs_version)) 1702 _GetMsbuildToolsetOfProject(proj_path, spec, msvs_version))
1697 projects[qualified_target] = obj 1703 projects[qualified_target] = obj
1698 # Set all the dependencies 1704
1699 for project in projects.values(): 1705 if set_dependencies:
1700 deps = project.spec.get('dependencies', []) 1706 # Set all the dependencies
1701 deps = [projects[d] for d in deps] 1707 for project in projects.values():
1702 project.set_dependencies(deps) 1708 deps = project.spec.get('dependencies', [])
1709 deps = [projects[d] for d in deps]
1710 project.set_dependencies(deps)
1703 return projects 1711 return projects
1704 1712
1705 1713
1706 def CalculateVariables(default_variables, params): 1714 def CalculateVariables(default_variables, params):
1707 """Generated variables that require params to be known.""" 1715 """Generated variables that require params to be known."""
1708 1716
1709 generator_flags = params.get('generator_flags', {}) 1717 generator_flags = params.get('generator_flags', {})
1710 1718
1711 # Select project file format version (if unset, default to auto detecting). 1719 # Select project file format version (if unset, default to auto detecting).
1712 msvs_version = MSVSVersion.SelectVisualStudioVersion( 1720 msvs_version = MSVSVersion.SelectVisualStudioVersion(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 target_list, target_dicts, generator_default_variables) 1783 target_list, target_dicts, generator_default_variables)
1776 1784
1777 # Prepare the set of configurations. 1785 # Prepare the set of configurations.
1778 configs = set() 1786 configs = set()
1779 for qualified_target in target_list: 1787 for qualified_target in target_list:
1780 spec = target_dicts[qualified_target] 1788 spec = target_dicts[qualified_target]
1781 for config_name, config in spec['configurations'].iteritems(): 1789 for config_name, config in spec['configurations'].iteritems():
1782 configs.add(_ConfigFullName(config_name, config)) 1790 configs.add(_ConfigFullName(config_name, config))
1783 configs = list(configs) 1791 configs = list(configs)
1784 1792
1785 # Figure out all the projects that will be generated and their guids 1793 # Figure out all the projects that will be generated and their guids, but
1794 # don't set dependencies if we are using an external builder like ninja
1795 set_dependencies = generator_flags.get('msvs_external_builder', None) == None
1786 project_objects = _CreateProjectObjects(target_list, target_dicts, options, 1796 project_objects = _CreateProjectObjects(target_list, target_dicts, options,
1787 msvs_version) 1797 msvs_version, set_dependencies)
1788 1798
1789 # Generate each project. 1799 # Generate each project.
1790 missing_sources = [] 1800 missing_sources = []
1791 for project in project_objects.values(): 1801 for project in project_objects.values():
1792 fixpath_prefix = project.fixpath_prefix 1802 fixpath_prefix = project.fixpath_prefix
1793 missing_sources.extend(_GenerateProject(project, options, msvs_version, 1803 missing_sources.extend(_GenerateProject(project, options, msvs_version,
1794 generator_flags)) 1804 generator_flags))
1795 fixpath_prefix = None 1805 fixpath_prefix = None
1796 1806
1797 for build_file in data: 1807 for build_file in data:
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 namespace = os.path.splitext(gyp_file_name)[0] 2429 namespace = os.path.splitext(gyp_file_name)[0]
2420 return [ 2430 return [
2421 ['PropertyGroup', {'Label': 'Globals'}, 2431 ['PropertyGroup', {'Label': 'Globals'},
2422 ['ProjectGuid', guid], 2432 ['ProjectGuid', guid],
2423 ['Keyword', 'Win32Proj'], 2433 ['Keyword', 'Win32Proj'],
2424 ['RootNamespace', namespace], 2434 ['RootNamespace', namespace],
2425 ] 2435 ]
2426 ] 2436 ]
2427 2437
2428 2438
2429 def _GetMSBuildConfigurationDetails(spec, build_file): 2439 def _GetMSBuildConfigurationDetails(spec, build_file, external_builder):
2430 properties = {} 2440 properties = {}
2431 for name, settings in spec['configurations'].iteritems(): 2441 for name, settings in spec['configurations'].iteritems():
2432 msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file) 2442 msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file,
2443 external_builder)
2433 condition = _GetConfigurationCondition(name, settings) 2444 condition = _GetConfigurationCondition(name, settings)
2434 character_set = msbuild_attributes.get('CharacterSet') 2445 character_set = msbuild_attributes.get('CharacterSet')
2435 _AddConditionalProperty(properties, condition, 'ConfigurationType', 2446 _AddConditionalProperty(properties, condition, 'ConfigurationType',
2436 msbuild_attributes['ConfigurationType']) 2447 msbuild_attributes['ConfigurationType'])
2437 if character_set: 2448 if character_set:
2438 _AddConditionalProperty(properties, condition, 'CharacterSet', 2449 _AddConditionalProperty(properties, condition, 'CharacterSet',
2439 character_set) 2450 character_set)
2440 return _GetMSBuildPropertyGroup(spec, 'Configuration', properties) 2451 return _GetMSBuildPropertyGroup(spec, 'Configuration', properties)
2441 2452
2442 2453
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 'Condition': "exists('%s')" % user_props, 2500 'Condition': "exists('%s')" % user_props,
2490 'Label': 'LocalAppDataPlatform' 2501 'Label': 'LocalAppDataPlatform'
2491 } 2502 }
2492 ] 2503 ]
2493 ] 2504 ]
2494 for props_file in props: 2505 for props_file in props:
2495 import_group.append(['Import', {'Project':props_file}]) 2506 import_group.append(['Import', {'Project':props_file}])
2496 sheets.append(import_group) 2507 sheets.append(import_group)
2497 return sheets 2508 return sheets
2498 2509
2499 def _ConvertMSVSBuildAttributes(spec, config, build_file): 2510 def _ConvertMSVSBuildAttributes(spec, config, build_file, external_builder):
2500 config_type = _GetMSVSConfigurationType(spec, build_file) 2511 config_type = _GetMSVSConfigurationType(spec, build_file, external_builder)
2501 msvs_attributes = _GetMSVSAttributes(spec, config, config_type) 2512 msvs_attributes = _GetMSVSAttributes(spec, config, config_type)
2502 msbuild_attributes = {} 2513 msbuild_attributes = {}
2503 for a in msvs_attributes: 2514 for a in msvs_attributes:
2504 if a in ['IntermediateDirectory', 'OutputDirectory']: 2515 if a in ['IntermediateDirectory', 'OutputDirectory']:
2505 directory = MSVSSettings.ConvertVCMacrosToMSBuild(msvs_attributes[a]) 2516 directory = MSVSSettings.ConvertVCMacrosToMSBuild(msvs_attributes[a])
2506 if not directory.endswith('\\'): 2517 if not directory.endswith('\\'):
2507 directory += '\\' 2518 directory += '\\'
2508 msbuild_attributes[a] = directory 2519 msbuild_attributes[a] = directory
2509 elif a == 'CharacterSet': 2520 elif a == 'CharacterSet':
2510 msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a]) 2521 msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a])
(...skipping 18 matching lines...) Expand all
2529 if config_type.isdigit(): 2540 if config_type.isdigit():
2530 config_type = { 2541 config_type = {
2531 '1': 'Application', 2542 '1': 'Application',
2532 '2': 'DynamicLibrary', 2543 '2': 'DynamicLibrary',
2533 '4': 'StaticLibrary', 2544 '4': 'StaticLibrary',
2534 '10': 'Utility' 2545 '10': 'Utility'
2535 }[config_type] 2546 }[config_type]
2536 return config_type 2547 return config_type
2537 2548
2538 2549
2539 def _GetMSBuildAttributes(spec, config, build_file): 2550 def _GetMSBuildAttributes(spec, config, build_file, external_builder):
2540 if 'msbuild_configuration_attributes' not in config: 2551 if 'msbuild_configuration_attributes' not in config:
2541 msbuild_attributes = _ConvertMSVSBuildAttributes(spec, config, build_file) 2552 msbuild_attributes = _ConvertMSVSBuildAttributes(spec, config, build_file,
2542 2553 external_builder)
2543 else: 2554 else:
2544 config_type = _GetMSVSConfigurationType(spec, build_file) 2555 config_type = _GetMSVSConfigurationType(spec, build_file, external_builder)
2545 config_type = _ConvertMSVSConfigurationType(config_type) 2556 config_type = _ConvertMSVSConfigurationType(config_type)
2546 msbuild_attributes = config.get('msbuild_configuration_attributes', {}) 2557 msbuild_attributes = config.get('msbuild_configuration_attributes', {})
2547 msbuild_attributes.setdefault('ConfigurationType', config_type) 2558 msbuild_attributes.setdefault('ConfigurationType', config_type)
2548 output_dir = msbuild_attributes.get('OutputDirectory', 2559 output_dir = msbuild_attributes.get('OutputDirectory',
2549 '$(SolutionDir)$(Configuration)') 2560 '$(SolutionDir)$(Configuration)')
2550 msbuild_attributes['OutputDirectory'] = _FixPath(output_dir) + '\\' 2561 msbuild_attributes['OutputDirectory'] = _FixPath(output_dir) + '\\'
2551 if 'IntermediateDirectory' not in msbuild_attributes: 2562 if 'IntermediateDirectory' not in msbuild_attributes:
2552 intermediate = _FixPath('$(Configuration)') + '\\' 2563 intermediate = _FixPath('$(Configuration)') + '\\'
2553 msbuild_attributes['IntermediateDirectory'] = intermediate 2564 msbuild_attributes['IntermediateDirectory'] = intermediate
2554 if 'CharacterSet' in msbuild_attributes: 2565 if 'CharacterSet' in msbuild_attributes:
2555 msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet( 2566 msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet(
2556 msbuild_attributes['CharacterSet']) 2567 msbuild_attributes['CharacterSet'])
2557 if 'TargetName' not in msbuild_attributes: 2568 if 'TargetName' not in msbuild_attributes:
2558 prefix = spec.get('product_prefix', '') 2569 prefix = spec.get('product_prefix', '')
2559 product_name = spec.get('product_name', '$(ProjectName)') 2570 product_name = spec.get('product_name', '$(ProjectName)')
2560 target_name = prefix + product_name 2571 target_name = prefix + product_name
2561 msbuild_attributes['TargetName'] = target_name 2572 msbuild_attributes['TargetName'] = target_name
2562 2573
2574 if external_builder == 'ninja':
scottmg 2013/04/15 19:37:58 it feels a bit odd to try to genericize to "extern
Dirk Pranke 2013/04/16 00:41:04 Maybe we should at least validate the value of ext
2575 ninja_out_dir = spec.get('msvs_ninja_out_dir', '.') + '/$(Configuration)'
2576 msbuild_attributes['OutputDirectory'] = _FixPath(ninja_out_dir) + '\\'
2577
2563 # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile' 2578 # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile'
2564 # (depending on the tool used) to avoid MSB8012 warning. 2579 # (depending on the tool used) to avoid MSB8012 warning.
2565 msbuild_tool_map = { 2580 msbuild_tool_map = {
2566 'executable': 'Link', 2581 'executable': 'Link',
2567 'shared_library': 'Link', 2582 'shared_library': 'Link',
2568 'loadable_module': 'Link', 2583 'loadable_module': 'Link',
2569 'static_library': 'Lib', 2584 'static_library': 'Lib',
2570 } 2585 }
2571 msbuild_tool = msbuild_tool_map.get(spec['type']) 2586 msbuild_tool = msbuild_tool_map.get(spec['type'])
2572 if msbuild_tool: 2587 if msbuild_tool:
2573 msbuild_settings = config['finalized_msbuild_settings'] 2588 msbuild_settings = config['finalized_msbuild_settings']
2574 out_file = msbuild_settings[msbuild_tool].get('OutputFile') 2589 out_file = msbuild_settings[msbuild_tool].get('OutputFile')
2575 if out_file: 2590 if out_file:
2576 msbuild_attributes['TargetPath'] = _FixPath(out_file) 2591 msbuild_attributes['TargetPath'] = _FixPath(out_file)
2577 2592
2578 return msbuild_attributes 2593 return msbuild_attributes
2579 2594
2580 2595
2581 def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file): 2596 def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file,
2597 external_builder):
2582 # TODO(jeanluc) We could optimize out the following and do it only if 2598 # TODO(jeanluc) We could optimize out the following and do it only if
2583 # there are actions. 2599 # there are actions.
2584 # TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'. 2600 # TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
2585 new_paths = [] 2601 new_paths = []
2586 cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.'])[0] 2602 cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.'])[0]
2587 if cygwin_dirs: 2603 if cygwin_dirs:
2588 cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs) 2604 cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs)
2589 new_paths.append(cyg_path) 2605 new_paths.append(cyg_path)
2590 # TODO(jeanluc) Change the convention to have both a cygwin_dir and a 2606 # TODO(jeanluc) Change the convention to have both a cygwin_dir and a
2591 # python_dir. 2607 # python_dir.
2592 python_path = cyg_path.replace('cygwin\\bin', 'python_26') 2608 python_path = cyg_path.replace('cygwin\\bin', 'python_26')
2593 new_paths.append(python_path) 2609 new_paths.append(python_path)
2594 if new_paths: 2610 if new_paths:
2595 new_paths = '$(ExecutablePath);' + ';'.join(new_paths) 2611 new_paths = '$(ExecutablePath);' + ';'.join(new_paths)
2596 2612
2597 properties = {} 2613 properties = {}
2598 for (name, configuration) in sorted(configurations.iteritems()): 2614 for (name, configuration) in sorted(configurations.iteritems()):
2599 condition = _GetConfigurationCondition(name, configuration) 2615 condition = _GetConfigurationCondition(name, configuration)
2600 attributes = _GetMSBuildAttributes(spec, configuration, build_file) 2616 attributes = _GetMSBuildAttributes(spec, configuration, build_file,
2617 external_builder)
2601 msbuild_settings = configuration['finalized_msbuild_settings'] 2618 msbuild_settings = configuration['finalized_msbuild_settings']
2602 _AddConditionalProperty(properties, condition, 'IntDir', 2619 _AddConditionalProperty(properties, condition, 'IntDir',
2603 attributes['IntermediateDirectory']) 2620 attributes['IntermediateDirectory'])
2604 _AddConditionalProperty(properties, condition, 'OutDir', 2621 _AddConditionalProperty(properties, condition, 'OutDir',
2605 attributes['OutputDirectory']) 2622 attributes['OutputDirectory'])
2606 _AddConditionalProperty(properties, condition, 'TargetName', 2623 _AddConditionalProperty(properties, condition, 'TargetName',
2607 attributes['TargetName']) 2624 attributes['TargetName'])
2608 2625
2626 if external_builder != None:
Dirk Pranke 2013/04/16 00:41:04 Nit: this can probably be just 'if external_builde
2627 # External builders are Utility projects, so we need to explicitly
2628 # specify the target extension, based on the spec's type.
2629 ext_map = {
2630 'executable': '.exe',
2631 'shared_library': '.dll',
2632 'loadable_module': '.dll',
scottmg 2013/04/15 19:37:58 this looks a lot like the table in MSVSUtil.py, co
2633 'static_library': '.lib',
2634 }
2635 ext = ext_map.get(spec['type'])
2636 if ext:
2637 _AddConditionalProperty(properties, condition, 'TargetExt', ext)
2638
2609 if attributes.get('TargetPath'): 2639 if attributes.get('TargetPath'):
2610 _AddConditionalProperty(properties, condition, 'TargetPath', 2640 _AddConditionalProperty(properties, condition, 'TargetPath',
2611 attributes['TargetPath']) 2641 attributes['TargetPath'])
2612 2642
2613 if new_paths: 2643 if new_paths:
2614 _AddConditionalProperty(properties, condition, 'ExecutablePath', 2644 _AddConditionalProperty(properties, condition, 'ExecutablePath',
2615 new_paths) 2645 new_paths)
2616 tool_settings = msbuild_settings.get('', {}) 2646 tool_settings = msbuild_settings.get('', {})
2617 for name, value in sorted(tool_settings.iteritems()): 2647 for name, value in sorted(tool_settings.iteritems()):
2618 formatted_value = _GetValueFormattedForMSBuild('', name, value) 2648 formatted_value = _GetValueFormattedForMSBuild('', name, value)
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2942 spec = project.spec 2972 spec = project.spec
2943 configurations = spec['configurations'] 2973 configurations = spec['configurations']
2944 project_dir, project_file_name = os.path.split(project.path) 2974 project_dir, project_file_name = os.path.split(project.path)
2945 msbuildproj_dir = os.path.dirname(project.path) 2975 msbuildproj_dir = os.path.dirname(project.path)
2946 if msbuildproj_dir and not os.path.exists(msbuildproj_dir): 2976 if msbuildproj_dir and not os.path.exists(msbuildproj_dir):
2947 os.makedirs(msbuildproj_dir) 2977 os.makedirs(msbuildproj_dir)
2948 # Prepare list of sources and excluded sources. 2978 # Prepare list of sources and excluded sources.
2949 gyp_path = _NormalizedSource(project.build_file) 2979 gyp_path = _NormalizedSource(project.build_file)
2950 relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir) 2980 relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
2951 2981
2982 external_builder = generator_flags.get('msvs_external_builder', None)
Dirk Pranke 2013/04/16 00:41:04 Nit: we should verify that external_builder == 'ni
2983
2952 gyp_file = os.path.split(project.build_file)[1] 2984 gyp_file = os.path.split(project.build_file)[1]
2953 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, 2985 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags,
2954 gyp_file) 2986 gyp_file)
2955 # Add rules. 2987 # Add rules.
2956 actions_to_add = {} 2988 actions_to_add = {}
2957 props_files_of_rules = set() 2989 props_files_of_rules = set()
2958 targets_files_of_rules = set() 2990 targets_files_of_rules = set()
2959 extension_to_rule_name = {} 2991 extension_to_rule_name = {}
2960 list_excluded = generator_flags.get('msvs_list_excluded_files', True) 2992 list_excluded = generator_flags.get('msvs_list_excluded_files', True)
2961 _GenerateRulesForMSBuild(project_dir, options, spec, 2993
2962 sources, excluded_sources, 2994 # Don't generate rules if we are using an external builder like ninja.
2963 props_files_of_rules, targets_files_of_rules, 2995 if external_builder != None:
Dirk Pranke 2013/04/16 00:41:04 same nit.
2964 actions_to_add, extension_to_rule_name) 2996 _GenerateRulesForMSBuild(project_dir, options, spec,
2997 sources, excluded_sources,
2998 props_files_of_rules, targets_files_of_rules,
2999 actions_to_add, extension_to_rule_name)
3000
2965 sources, excluded_sources, excluded_idl = ( 3001 sources, excluded_sources, excluded_idl = (
2966 _AdjustSourcesAndConvertToFilterHierarchy(spec, options, 3002 _AdjustSourcesAndConvertToFilterHierarchy(spec, options,
2967 project_dir, sources, 3003 project_dir, sources,
2968 excluded_sources, 3004 excluded_sources,
2969 list_excluded)) 3005 list_excluded))
2970 _AddActions(actions_to_add, spec, project.build_file)
2971 _AddCopies(actions_to_add, spec)
2972 3006
2973 # NOTE: this stanza must appear after all actions have been decided. 3007 # 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. 3008 if external_builder != None:
Dirk Pranke 2013/04/16 00:41:04 same nit.
2975 excluded_sources = _FilterActionsFromExcluded( 3009 _AddActions(actions_to_add, spec, project.build_file)
2976 excluded_sources, actions_to_add) 3010 _AddCopies(actions_to_add, spec)
3011
3012 # NOTE: this stanza must appear after all actions have been decided.
3013 # Don't excluded sources with actions attached, or they won't run.
3014 excluded_sources = _FilterActionsFromExcluded(
3015 excluded_sources, actions_to_add)
2977 3016
2978 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) 3017 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
2979 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild( 3018 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild(
2980 spec, actions_to_add) 3019 spec, actions_to_add)
2981 3020
2982 _GenerateMSBuildFiltersFile(project.path + '.filters', sources, 3021 _GenerateMSBuildFiltersFile(project.path + '.filters', sources,
2983 extension_to_rule_name) 3022 extension_to_rule_name)
2984 missing_sources = _VerifySourcesExist(sources, project_dir) 3023 missing_sources = _VerifySourcesExist(sources, project_dir)
2985 3024
2986 for configuration in configurations.itervalues(): 3025 for configuration in configurations.itervalues():
(...skipping 12 matching lines...) Expand all
2999 content = [ 3038 content = [
3000 'Project', 3039 'Project',
3001 {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003', 3040 {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003',
3002 'ToolsVersion': version.ProjectVersion(), 3041 'ToolsVersion': version.ProjectVersion(),
3003 'DefaultTargets': 'Build' 3042 'DefaultTargets': 'Build'
3004 }] 3043 }]
3005 3044
3006 content += _GetMSBuildProjectConfigurations(configurations) 3045 content += _GetMSBuildProjectConfigurations(configurations)
3007 content += _GetMSBuildGlobalProperties(spec, project.guid, project_file_name) 3046 content += _GetMSBuildGlobalProperties(spec, project.guid, project_file_name)
3008 content += import_default_section 3047 content += import_default_section
3009 content += _GetMSBuildConfigurationDetails(spec, project.build_file) 3048 content += _GetMSBuildConfigurationDetails(spec, project.build_file,
3049 external_builder)
3010 content += _GetMSBuildLocalProperties(project.msbuild_toolset) 3050 content += _GetMSBuildLocalProperties(project.msbuild_toolset)
3011 content += import_cpp_props_section 3051 content += import_cpp_props_section
3012 content += _GetMSBuildExtensions(props_files_of_rules) 3052 content += _GetMSBuildExtensions(props_files_of_rules)
3013 content += _GetMSBuildPropertySheets(configurations) 3053 content += _GetMSBuildPropertySheets(configurations)
3014 content += macro_section 3054 content += macro_section
3015 content += _GetMSBuildConfigurationGlobalProperties(spec, configurations, 3055 content += _GetMSBuildConfigurationGlobalProperties(spec, configurations,
3016 project.build_file) 3056 project.build_file,
3057 external_builder)
3017 content += _GetMSBuildToolSettingsSections(spec, configurations) 3058 content += _GetMSBuildToolSettingsSections(spec, configurations)
3018 content += _GetMSBuildSources( 3059 content += _GetMSBuildSources(
3019 spec, sources, exclusions, extension_to_rule_name, actions_spec, 3060 spec, sources, exclusions, extension_to_rule_name, actions_spec,
3020 sources_handled_by_action, list_excluded) 3061 sources_handled_by_action, list_excluded)
3021 content += _GetMSBuildProjectReferences(project) 3062 content += _GetMSBuildProjectReferences(project)
3022 content += import_cpp_targets_section 3063 content += import_cpp_targets_section
3023 content += _GetMSBuildExtensionTargets(targets_files_of_rules) 3064 content += _GetMSBuildExtensionTargets(targets_files_of_rules)
3024 3065
3066 if external_builder == 'ninja':
3067 content += _GetMSBuildNinjaTarget(spec, 'Build',
3068 ['-j', '${NUMBER_OF_PROCESSORS_PLUS_1}'])
scottmg 2013/04/15 19:37:58 ninja determines -j automatically, don't specify i
3069 content += _GetMSBuildNinjaTarget(spec, 'Clean', ['-t', 'clean'])
3070
3025 # TODO(jeanluc) File a bug to get rid of runas. We had in MSVS: 3071 # TODO(jeanluc) File a bug to get rid of runas. We had in MSVS:
3026 # has_run_as = _WriteMSVSUserFile(project.path, version, spec) 3072 # has_run_as = _WriteMSVSUserFile(project.path, version, spec)
3027 3073
3028 easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True) 3074 easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True)
3029 3075
3030 return missing_sources 3076 return missing_sources
3031 3077
3078 def _GetMSBuildNinjaTarget(spec, msbuild_target_name, ninja_args):
scottmg 2013/04/15 19:37:58 docstring
3079 cmd = [
3080 'ninja.exe',
scottmg 2013/04/15 19:37:58 i don't love the hardcoding here either. perhaps a
3081 '-C',
3082 '$(OutDir)',
3083 ]
3084 cmd.extend(ninja_args)
3085 cmd.append(spec['target_name'])
3086 cmd = _BuildCommandLineForRuleRaw(spec, cmd, True, False, True, True)
3087 target = ['Target', {'Name': msbuild_target_name}]
3088 target.append(['Exec', {'Command': cmd}])
3089 return [target]
3032 3090
3033 def _GetMSBuildExtensions(props_files_of_rules): 3091 def _GetMSBuildExtensions(props_files_of_rules):
3034 extensions = ['ImportGroup', {'Label': 'ExtensionSettings'}] 3092 extensions = ['ImportGroup', {'Label': 'ExtensionSettings'}]
3035 for props_file in props_files_of_rules: 3093 for props_file in props_files_of_rules:
3036 extensions.append(['Import', {'Project': props_file}]) 3094 extensions.append(['Import', {'Project': props_file}])
3037 return [extensions] 3095 return [extensions]
3038 3096
3039 3097
3040 def _GetMSBuildExtensionTargets(targets_files_of_rules): 3098 def _GetMSBuildExtensionTargets(targets_files_of_rules):
3041 targets_node = ['ImportGroup', {'Label': 'ExtensionTargets'}] 3099 targets_node = ['ImportGroup', {'Label': 'ExtensionTargets'}]
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3108 action_spec.extend( 3166 action_spec.extend(
3109 # TODO(jeanluc) 'Document' for all or just if as_sources? 3167 # TODO(jeanluc) 'Document' for all or just if as_sources?
3110 [['FileType', 'Document'], 3168 [['FileType', 'Document'],
3111 ['Command', command], 3169 ['Command', command],
3112 ['Message', description], 3170 ['Message', description],
3113 ['Outputs', outputs] 3171 ['Outputs', outputs]
3114 ]) 3172 ])
3115 if additional_inputs: 3173 if additional_inputs:
3116 action_spec.append(['AdditionalInputs', additional_inputs]) 3174 action_spec.append(['AdditionalInputs', additional_inputs])
3117 actions_spec.append(action_spec) 3175 actions_spec.append(action_spec)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698