| OLD | NEW |
| 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 from __future__ import print_function |
| 6 |
| 7 import collections |
| 5 import copy | 8 import copy |
| 6 import ntpath | 9 import ntpath |
| 7 import os | 10 import os |
| 8 import posixpath | 11 import posixpath |
| 9 import re | 12 import re |
| 10 import subprocess | 13 import subprocess |
| 11 import sys | 14 import sys |
| 12 | 15 |
| 13 import gyp.common | 16 import gyp.common |
| 14 import gyp.easy_xml as easy_xml | 17 import gyp.easy_xml as easy_xml |
| 15 import gyp.generator.ninja as ninja_generator | 18 import gyp.generator.ninja as ninja_generator |
| 16 import gyp.MSVSNew as MSVSNew | 19 import gyp.MSVSNew as MSVSNew |
| 17 import gyp.MSVSProject as MSVSProject | 20 import gyp.MSVSProject as MSVSProject |
| 18 import gyp.MSVSSettings as MSVSSettings | 21 import gyp.MSVSSettings as MSVSSettings |
| 19 import gyp.MSVSToolFile as MSVSToolFile | 22 import gyp.MSVSToolFile as MSVSToolFile |
| 20 import gyp.MSVSUserFile as MSVSUserFile | 23 import gyp.MSVSUserFile as MSVSUserFile |
| 21 import gyp.MSVSUtil as MSVSUtil | 24 import gyp.MSVSUtil as MSVSUtil |
| 22 import gyp.MSVSVersion as MSVSVersion | 25 import gyp.MSVSVersion as MSVSVersion |
| 23 from gyp.common import GypError | 26 from gyp.common import GypError |
| 24 from gyp.common import OrderedSet | 27 from gyp.common import OrderedSet |
| 25 | 28 |
| 26 # TODO: Remove once bots are on 2.7, http://crbug.com/241769 | |
| 27 def _import_OrderedDict(): | |
| 28 import collections | |
| 29 try: | |
| 30 return collections.OrderedDict | |
| 31 except AttributeError: | |
| 32 import gyp.ordered_dict | |
| 33 return gyp.ordered_dict.OrderedDict | |
| 34 OrderedDict = _import_OrderedDict() | |
| 35 | |
| 36 | 29 |
| 37 # Regular expression for validating Visual Studio GUIDs. If the GUID | 30 # Regular expression for validating Visual Studio GUIDs. If the GUID |
| 38 # contains lowercase hex letters, MSVS will be fine. However, | 31 # contains lowercase hex letters, MSVS will be fine. However, |
| 39 # IncrediBuild BuildConsole will parse the solution file, but then | 32 # IncrediBuild BuildConsole will parse the solution file, but then |
| 40 # silently skip building the target causing hard to track down errors. | 33 # silently skip building the target causing hard to track down errors. |
| 41 # Note that this only happens with the BuildConsole, and does not occur | 34 # Note that this only happens with the BuildConsole, and does not occur |
| 42 # if IncrediBuild is executed from inside Visual Studio. This regex | 35 # if IncrediBuild is executed from inside Visual Studio. This regex |
| 43 # validates that the string looks like a GUID with all uppercase hex | 36 # validates that the string looks like a GUID with all uppercase hex |
| 44 # letters. | 37 # letters. |
| 45 VALID_MSVS_GUID_CHARS = re.compile(r'^[A-F0-9\-]+$') | 38 VALID_MSVS_GUID_CHARS = re.compile(r'^[A-F0-9\-]+$') |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 For example: | 186 For example: |
| 194 _ConvertSourcesToFilterHierarchy([['a', 'bob1.c'], ['b', 'bob2.c']], | 187 _ConvertSourcesToFilterHierarchy([['a', 'bob1.c'], ['b', 'bob2.c']], |
| 195 prefix=['joe']) | 188 prefix=['joe']) |
| 196 --> | 189 --> |
| 197 [MSVSProject.Filter('a', contents=['joe\\a\\bob1.c']), | 190 [MSVSProject.Filter('a', contents=['joe\\a\\bob1.c']), |
| 198 MSVSProject.Filter('b', contents=['joe\\b\\bob2.c'])] | 191 MSVSProject.Filter('b', contents=['joe\\b\\bob2.c'])] |
| 199 """ | 192 """ |
| 200 if not prefix: prefix = [] | 193 if not prefix: prefix = [] |
| 201 result = [] | 194 result = [] |
| 202 excluded_result = [] | 195 excluded_result = [] |
| 203 folders = OrderedDict() | 196 folders = collections.OrderedDict() |
| 204 # Gather files into the final result, excluded, or folders. | 197 # Gather files into the final result, excluded, or folders. |
| 205 for s in sources: | 198 for s in sources: |
| 206 if len(s) == 1: | 199 if len(s) == 1: |
| 207 filename = _NormalizedSource('\\'.join(prefix + s)) | 200 filename = _NormalizedSource('\\'.join(prefix + s)) |
| 208 if filename in excluded: | 201 if filename in excluded: |
| 209 excluded_result.append(filename) | 202 excluded_result.append(filename) |
| 210 else: | 203 else: |
| 211 result.append(filename) | 204 result.append(filename) |
| 212 elif msvs_version and not msvs_version.UsesVcxproj(): | 205 elif msvs_version and not msvs_version.UsesVcxproj(): |
| 213 # For MSVS 2008 and earlier, we need to process all files before walking | 206 # For MSVS 2008 and earlier, we need to process all files before walking |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 inputs = _FixPaths(inputs) | 420 inputs = _FixPaths(inputs) |
| 428 outputs = _FixPaths(outputs) | 421 outputs = _FixPaths(outputs) |
| 429 tool = MSVSProject.Tool( | 422 tool = MSVSProject.Tool( |
| 430 'VCCustomBuildTool', | 423 'VCCustomBuildTool', |
| 431 {'Description': description, | 424 {'Description': description, |
| 432 'AdditionalDependencies': ';'.join(inputs), | 425 'AdditionalDependencies': ';'.join(inputs), |
| 433 'Outputs': ';'.join(outputs), | 426 'Outputs': ';'.join(outputs), |
| 434 'CommandLine': cmd, | 427 'CommandLine': cmd, |
| 435 }) | 428 }) |
| 436 # Add to the properties of primary input for each config. | 429 # Add to the properties of primary input for each config. |
| 437 for config_name, c_data in spec['configurations'].iteritems(): | 430 for config_name, c_data in spec['configurations'].items(): |
| 438 p.AddFileConfig(_FixPath(primary_input), | 431 p.AddFileConfig(_FixPath(primary_input), |
| 439 _ConfigFullName(config_name, c_data), tools=[tool]) | 432 _ConfigFullName(config_name, c_data), tools=[tool]) |
| 440 | 433 |
| 441 | 434 |
| 442 def _AddAccumulatedActionsToMSVS(p, spec, actions_dict): | 435 def _AddAccumulatedActionsToMSVS(p, spec, actions_dict): |
| 443 """Add actions accumulated into an actions_dict, merging as needed. | 436 """Add actions accumulated into an actions_dict, merging as needed. |
| 444 | 437 |
| 445 Arguments: | 438 Arguments: |
| 446 p: the target project | 439 p: the target project |
| 447 spec: the target project dict | 440 spec: the target project dict |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 # Concatenate back into a single string | 726 # Concatenate back into a single string |
| 734 s = '"'.join(segments) | 727 s = '"'.join(segments) |
| 735 if len(segments) % 2 == 0: | 728 if len(segments) % 2 == 0: |
| 736 # String ends while still quoted according to VCProj's convention. This | 729 # String ends while still quoted according to VCProj's convention. This |
| 737 # means the delimiter and the next list item that follow this one in the | 730 # means the delimiter and the next list item that follow this one in the |
| 738 # .vcproj file will be misinterpreted as part of this item. There is nothing | 731 # .vcproj file will be misinterpreted as part of this item. There is nothing |
| 739 # we can do about this. Adding an extra quote would correct the problem in | 732 # we can do about this. Adding an extra quote would correct the problem in |
| 740 # the VCProj but cause the same problem on the final command-line. Moving | 733 # the VCProj but cause the same problem on the final command-line. Moving |
| 741 # the item to the end of the list does works, but that's only possible if | 734 # the item to the end of the list does works, but that's only possible if |
| 742 # there's only one such item. Let's just warn the user. | 735 # there's only one such item. Let's just warn the user. |
| 743 print >> sys.stderr, ('Warning: MSVS may misinterpret the odd number of ' + | 736 print(('Warning: MSVS may misinterpret the odd number of ' + |
| 744 'quotes in ' + s) | 737 'quotes in ' + s), file=sys.stderr) |
| 745 return s | 738 return s |
| 746 | 739 |
| 747 | 740 |
| 748 def _EscapeCppDefineForMSVS(s): | 741 def _EscapeCppDefineForMSVS(s): |
| 749 """Escapes a CPP define so that it will reach the compiler unaltered.""" | 742 """Escapes a CPP define so that it will reach the compiler unaltered.""" |
| 750 s = _EscapeEnvironmentVariableExpansion(s) | 743 s = _EscapeEnvironmentVariableExpansion(s) |
| 751 s = _EscapeCommandLineArgumentForMSVS(s) | 744 s = _EscapeCommandLineArgumentForMSVS(s) |
| 752 s = _EscapeVCProjCommandLineArgListItem(s) | 745 s = _EscapeVCProjCommandLineArgListItem(s) |
| 753 # cl.exe replaces literal # characters with = in preprocesor definitions for | 746 # cl.exe replaces literal # characters with = in preprocesor definitions for |
| 754 # some reason. Octal-encode to work around that. | 747 # some reason. Octal-encode to work around that. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 for source in sources: | 940 for source in sources: |
| 948 name, ext = os.path.splitext(source) | 941 name, ext = os.path.splitext(source) |
| 949 is_compiled_file = ext in [ | 942 is_compiled_file = ext in [ |
| 950 '.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.s', '.S'] | 943 '.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.s', '.S'] |
| 951 if not is_compiled_file: | 944 if not is_compiled_file: |
| 952 continue | 945 continue |
| 953 basename = os.path.basename(name) # Don't include extension. | 946 basename = os.path.basename(name) # Don't include extension. |
| 954 basenames.setdefault(basename, []).append(source) | 947 basenames.setdefault(basename, []).append(source) |
| 955 | 948 |
| 956 error = '' | 949 error = '' |
| 957 for basename, files in basenames.iteritems(): | 950 for basename, files in basenames.items(): |
| 958 if len(files) > 1: | 951 if len(files) > 1: |
| 959 error += ' %s: %s\n' % (basename, ' '.join(files)) | 952 error += ' %s: %s\n' % (basename, ' '.join(files)) |
| 960 | 953 |
| 961 if error: | 954 if error: |
| 962 print('static library %s has several files with the same basename:\n' % | 955 print('static library %s has several files with the same basename:\n' % |
| 963 spec['target_name'] + error + 'MSVC08 cannot handle that.') | 956 spec['target_name'] + error + 'MSVC08 cannot handle that.') |
| 964 raise GypError('Duplicate basenames in sources section, see list above') | 957 raise GypError('Duplicate basenames in sources section, see list above') |
| 965 | 958 |
| 966 | 959 |
| 967 def _GenerateMSVSProject(project, options, version, generator_flags): | 960 def _GenerateMSVSProject(project, options, version, generator_flags): |
| (...skipping 11 matching lines...) Expand all Loading... |
| 979 platforms = _GetUniquePlatforms(spec) | 972 platforms = _GetUniquePlatforms(spec) |
| 980 p = MSVSProject.Writer(project.path, version, spec['target_name'], | 973 p = MSVSProject.Writer(project.path, version, spec['target_name'], |
| 981 project.guid, platforms) | 974 project.guid, platforms) |
| 982 | 975 |
| 983 # Get directory project file is in. | 976 # Get directory project file is in. |
| 984 project_dir = os.path.split(project.path)[0] | 977 project_dir = os.path.split(project.path)[0] |
| 985 gyp_path = _NormalizedSource(project.build_file) | 978 gyp_path = _NormalizedSource(project.build_file) |
| 986 relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir) | 979 relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir) |
| 987 | 980 |
| 988 config_type = _GetMSVSConfigurationType(spec, project.build_file) | 981 config_type = _GetMSVSConfigurationType(spec, project.build_file) |
| 989 for config_name, config in spec['configurations'].iteritems(): | 982 for config_name, config in spec['configurations'].items(): |
| 990 _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config) | 983 _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config) |
| 991 | 984 |
| 992 # MSVC08 and prior version cannot handle duplicate basenames in the same | 985 # MSVC08 and prior version cannot handle duplicate basenames in the same |
| 993 # target. | 986 # target. |
| 994 # TODO: Take excluded sources into consideration if possible. | 987 # TODO: Take excluded sources into consideration if possible. |
| 995 _ValidateSourcesForMSVSProject(spec, version) | 988 _ValidateSourcesForMSVSProject(spec, version) |
| 996 | 989 |
| 997 # Prepare list of sources and excluded sources. | 990 # Prepare list of sources and excluded sources. |
| 998 gyp_file = os.path.split(project.build_file)[1] | 991 gyp_file = os.path.split(project.build_file)[1] |
| 999 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, | 992 sources, excluded_sources = _PrepareListOfSources(spec, generator_flags, |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 | 1338 |
| 1346 def _ConvertToolsToExpectedForm(tools): | 1339 def _ConvertToolsToExpectedForm(tools): |
| 1347 """Convert tools to a form expected by Visual Studio. | 1340 """Convert tools to a form expected by Visual Studio. |
| 1348 | 1341 |
| 1349 Arguments: | 1342 Arguments: |
| 1350 tools: A dictionary of settings; the tool name is the key. | 1343 tools: A dictionary of settings; the tool name is the key. |
| 1351 Returns: | 1344 Returns: |
| 1352 A list of Tool objects. | 1345 A list of Tool objects. |
| 1353 """ | 1346 """ |
| 1354 tool_list = [] | 1347 tool_list = [] |
| 1355 for tool, settings in tools.iteritems(): | 1348 for tool, settings in tools.items(): |
| 1356 # Collapse settings with lists. | 1349 # Collapse settings with lists. |
| 1357 settings_fixed = {} | 1350 settings_fixed = {} |
| 1358 for setting, value in settings.iteritems(): | 1351 for setting, value in settings.items(): |
| 1359 if type(value) == list: | 1352 if type(value) == list: |
| 1360 if ((tool == 'VCLinkerTool' and | 1353 if ((tool == 'VCLinkerTool' and |
| 1361 setting == 'AdditionalDependencies') or | 1354 setting == 'AdditionalDependencies') or |
| 1362 setting == 'AdditionalOptions'): | 1355 setting == 'AdditionalOptions'): |
| 1363 settings_fixed[setting] = ' '.join(value) | 1356 settings_fixed[setting] = ' '.join(value) |
| 1364 else: | 1357 else: |
| 1365 settings_fixed[setting] = ';'.join(value) | 1358 settings_fixed[setting] = ';'.join(value) |
| 1366 else: | 1359 else: |
| 1367 settings_fixed[setting] = value | 1360 settings_fixed[setting] = value |
| 1368 # Add in this tool. | 1361 # Add in this tool. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1523 if using_idl: | 1516 if using_idl: |
| 1524 excluded_idl = [i for i in sources if i.endswith('.idl')] | 1517 excluded_idl = [i for i in sources if i.endswith('.idl')] |
| 1525 else: | 1518 else: |
| 1526 excluded_idl = [] | 1519 excluded_idl = [] |
| 1527 return excluded_idl | 1520 return excluded_idl |
| 1528 | 1521 |
| 1529 | 1522 |
| 1530 def _GetPrecompileRelatedFiles(spec): | 1523 def _GetPrecompileRelatedFiles(spec): |
| 1531 # Gather a list of precompiled header related sources. | 1524 # Gather a list of precompiled header related sources. |
| 1532 precompiled_related = [] | 1525 precompiled_related = [] |
| 1533 for _, config in spec['configurations'].iteritems(): | 1526 for _, config in spec['configurations'].items(): |
| 1534 for k in precomp_keys: | 1527 for k in precomp_keys: |
| 1535 f = config.get(k) | 1528 f = config.get(k) |
| 1536 if f: | 1529 if f: |
| 1537 precompiled_related.append(_FixPath(f)) | 1530 precompiled_related.append(_FixPath(f)) |
| 1538 return precompiled_related | 1531 return precompiled_related |
| 1539 | 1532 |
| 1540 | 1533 |
| 1541 def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl, | 1534 def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl, |
| 1542 list_excluded): | 1535 list_excluded): |
| 1543 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) | 1536 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) |
| 1544 for file_name, excluded_configs in exclusions.iteritems(): | 1537 for file_name, excluded_configs in exclusions.items(): |
| 1545 if (not list_excluded and | 1538 if (not list_excluded and |
| 1546 len(excluded_configs) == len(spec['configurations'])): | 1539 len(excluded_configs) == len(spec['configurations'])): |
| 1547 # If we're not listing excluded files, then they won't appear in the | 1540 # If we're not listing excluded files, then they won't appear in the |
| 1548 # project, so don't try to configure them to be excluded. | 1541 # project, so don't try to configure them to be excluded. |
| 1549 pass | 1542 pass |
| 1550 else: | 1543 else: |
| 1551 for config_name, config in excluded_configs: | 1544 for config_name, config in excluded_configs: |
| 1552 p.AddFileConfig(file_name, _ConfigFullName(config_name, config), | 1545 p.AddFileConfig(file_name, _ConfigFullName(config_name, config), |
| 1553 {'ExcludedFromBuild': 'true'}) | 1546 {'ExcludedFromBuild': 'true'}) |
| 1554 | 1547 |
| 1555 | 1548 |
| 1556 def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl): | 1549 def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl): |
| 1557 exclusions = {} | 1550 exclusions = {} |
| 1558 # Exclude excluded sources from being built. | 1551 # Exclude excluded sources from being built. |
| 1559 for f in excluded_sources: | 1552 for f in excluded_sources: |
| 1560 excluded_configs = [] | 1553 excluded_configs = [] |
| 1561 for config_name, config in spec['configurations'].iteritems(): | 1554 for config_name, config in spec['configurations'].items(): |
| 1562 precomped = [_FixPath(config.get(i, '')) for i in precomp_keys] | 1555 precomped = [_FixPath(config.get(i, '')) for i in precomp_keys] |
| 1563 # Don't do this for ones that are precompiled header related. | 1556 # Don't do this for ones that are precompiled header related. |
| 1564 if f not in precomped: | 1557 if f not in precomped: |
| 1565 excluded_configs.append((config_name, config)) | 1558 excluded_configs.append((config_name, config)) |
| 1566 exclusions[f] = excluded_configs | 1559 exclusions[f] = excluded_configs |
| 1567 # If any non-native rules use 'idl' as an extension exclude idl files. | 1560 # If any non-native rules use 'idl' as an extension exclude idl files. |
| 1568 # Exclude them now. | 1561 # Exclude them now. |
| 1569 for f in excluded_idl: | 1562 for f in excluded_idl: |
| 1570 excluded_configs = [] | 1563 excluded_configs = [] |
| 1571 for config_name, config in spec['configurations'].iteritems(): | 1564 for config_name, config in spec['configurations'].items(): |
| 1572 excluded_configs.append((config_name, config)) | 1565 excluded_configs.append((config_name, config)) |
| 1573 exclusions[f] = excluded_configs | 1566 exclusions[f] = excluded_configs |
| 1574 return exclusions | 1567 return exclusions |
| 1575 | 1568 |
| 1576 | 1569 |
| 1577 def _AddToolFilesToMSVS(p, spec): | 1570 def _AddToolFilesToMSVS(p, spec): |
| 1578 # Add in tool files (rules). | 1571 # Add in tool files (rules). |
| 1579 tool_files = OrderedSet() | 1572 tool_files = OrderedSet() |
| 1580 for _, config in spec['configurations'].iteritems(): | 1573 for _, config in spec['configurations'].items(): |
| 1581 for f in config.get('msvs_tool_files', []): | 1574 for f in config.get('msvs_tool_files', []): |
| 1582 tool_files.add(f) | 1575 tool_files.add(f) |
| 1583 for f in tool_files: | 1576 for f in tool_files: |
| 1584 p.AddToolFile(f) | 1577 p.AddToolFile(f) |
| 1585 | 1578 |
| 1586 | 1579 |
| 1587 def _HandlePreCompiledHeaders(p, sources, spec): | 1580 def _HandlePreCompiledHeaders(p, sources, spec): |
| 1588 # Pre-compiled header source stubs need a different compiler flag | 1581 # Pre-compiled header source stubs need a different compiler flag |
| 1589 # (generate precompiled header) and any source file not of the same | 1582 # (generate precompiled header) and any source file not of the same |
| 1590 # kind (i.e. C vs. C++) as the precompiled header source stub needs | 1583 # kind (i.e. C vs. C++) as the precompiled header source stub needs |
| 1591 # to have use of precompiled headers disabled. | 1584 # to have use of precompiled headers disabled. |
| 1592 extensions_excluded_from_precompile = [] | 1585 extensions_excluded_from_precompile = [] |
| 1593 for config_name, config in spec['configurations'].iteritems(): | 1586 for config_name, config in spec['configurations'].items(): |
| 1594 source = config.get('msvs_precompiled_source') | 1587 source = config.get('msvs_precompiled_source') |
| 1595 if source: | 1588 if source: |
| 1596 source = _FixPath(source) | 1589 source = _FixPath(source) |
| 1597 # UsePrecompiledHeader=1 for if using precompiled headers. | 1590 # UsePrecompiledHeader=1 for if using precompiled headers. |
| 1598 tool = MSVSProject.Tool('VCCLCompilerTool', | 1591 tool = MSVSProject.Tool('VCCLCompilerTool', |
| 1599 {'UsePrecompiledHeader': '1'}) | 1592 {'UsePrecompiledHeader': '1'}) |
| 1600 p.AddFileConfig(source, _ConfigFullName(config_name, config), | 1593 p.AddFileConfig(source, _ConfigFullName(config_name, config), |
| 1601 {}, tools=[tool]) | 1594 {}, tools=[tool]) |
| 1602 basename, extension = os.path.splitext(source) | 1595 basename, extension = os.path.splitext(source) |
| 1603 if extension == '.c': | 1596 if extension == '.c': |
| 1604 extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx'] | 1597 extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx'] |
| 1605 else: | 1598 else: |
| 1606 extensions_excluded_from_precompile = ['.c'] | 1599 extensions_excluded_from_precompile = ['.c'] |
| 1607 def DisableForSourceTree(source_tree): | 1600 def DisableForSourceTree(source_tree): |
| 1608 for source in source_tree: | 1601 for source in source_tree: |
| 1609 if isinstance(source, MSVSProject.Filter): | 1602 if isinstance(source, MSVSProject.Filter): |
| 1610 DisableForSourceTree(source.contents) | 1603 DisableForSourceTree(source.contents) |
| 1611 else: | 1604 else: |
| 1612 basename, extension = os.path.splitext(source) | 1605 basename, extension = os.path.splitext(source) |
| 1613 if extension in extensions_excluded_from_precompile: | 1606 if extension in extensions_excluded_from_precompile: |
| 1614 for config_name, config in spec['configurations'].iteritems(): | 1607 for config_name, config in spec['configurations'].items(): |
| 1615 tool = MSVSProject.Tool('VCCLCompilerTool', | 1608 tool = MSVSProject.Tool('VCCLCompilerTool', |
| 1616 {'UsePrecompiledHeader': '0', | 1609 {'UsePrecompiledHeader': '0', |
| 1617 'ForcedIncludeFiles': '$(NOINHERIT)'}) | 1610 'ForcedIncludeFiles': '$(NOINHERIT)'}) |
| 1618 p.AddFileConfig(_FixPath(source), | 1611 p.AddFileConfig(_FixPath(source), |
| 1619 _ConfigFullName(config_name, config), | 1612 _ConfigFullName(config_name, config), |
| 1620 {}, tools=[tool]) | 1613 {}, tools=[tool]) |
| 1621 # Do nothing if there was no precompiled source. | 1614 # Do nothing if there was no precompiled source. |
| 1622 if extensions_excluded_from_precompile: | 1615 if extensions_excluded_from_precompile: |
| 1623 DisableForSourceTree(sources) | 1616 DisableForSourceTree(sources) |
| 1624 | 1617 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1655 environment = run_as.get('environment', []) | 1648 environment = run_as.get('environment', []) |
| 1656 working_directory = run_as.get('working_directory', '.') | 1649 working_directory = run_as.get('working_directory', '.') |
| 1657 elif int(spec.get('test', 0)): | 1650 elif int(spec.get('test', 0)): |
| 1658 action = ['$(TargetPath)', '--gtest_print_time'] | 1651 action = ['$(TargetPath)', '--gtest_print_time'] |
| 1659 environment = [] | 1652 environment = [] |
| 1660 working_directory = '.' | 1653 working_directory = '.' |
| 1661 else: | 1654 else: |
| 1662 return # Nothing to add | 1655 return # Nothing to add |
| 1663 # Write out the user file. | 1656 # Write out the user file. |
| 1664 user_file = _CreateMSVSUserFile(project_path, version, spec) | 1657 user_file = _CreateMSVSUserFile(project_path, version, spec) |
| 1665 for config_name, c_data in spec['configurations'].iteritems(): | 1658 for config_name, c_data in spec['configurations'].items(): |
| 1666 user_file.AddDebugSettings(_ConfigFullName(config_name, c_data), | 1659 user_file.AddDebugSettings(_ConfigFullName(config_name, c_data), |
| 1667 action, environment, working_directory) | 1660 action, environment, working_directory) |
| 1668 user_file.WriteIfChanged() | 1661 user_file.WriteIfChanged() |
| 1669 | 1662 |
| 1670 | 1663 |
| 1671 def _AddCopies(actions_to_add, spec): | 1664 def _AddCopies(actions_to_add, spec): |
| 1672 copies = _GetCopies(spec) | 1665 copies = _GetCopies(spec) |
| 1673 for inputs, outputs, cmd, description in copies: | 1666 for inputs, outputs, cmd, description in copies: |
| 1674 _AddActionStep(actions_to_add, inputs=inputs, outputs=outputs, | 1667 _AddActionStep(actions_to_add, inputs=inputs, outputs=outputs, |
| 1675 description=description, command=cmd) | 1668 description=description, command=cmd) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1706 parent, folder = os.path.split(path) | 1699 parent, folder = os.path.split(path) |
| 1707 parent_dict = _GetPathDict(root, parent) | 1700 parent_dict = _GetPathDict(root, parent) |
| 1708 if folder not in parent_dict: | 1701 if folder not in parent_dict: |
| 1709 parent_dict[folder] = dict() | 1702 parent_dict[folder] = dict() |
| 1710 return parent_dict[folder] | 1703 return parent_dict[folder] |
| 1711 | 1704 |
| 1712 | 1705 |
| 1713 def _DictsToFolders(base_path, bucket, flat): | 1706 def _DictsToFolders(base_path, bucket, flat): |
| 1714 # Convert to folders recursively. | 1707 # Convert to folders recursively. |
| 1715 children = [] | 1708 children = [] |
| 1716 for folder, contents in bucket.iteritems(): | 1709 for folder, contents in bucket.items(): |
| 1717 if type(contents) == dict: | 1710 if type(contents) == dict: |
| 1718 folder_children = _DictsToFolders(os.path.join(base_path, folder), | 1711 folder_children = _DictsToFolders(os.path.join(base_path, folder), |
| 1719 contents, flat) | 1712 contents, flat) |
| 1720 if flat: | 1713 if flat: |
| 1721 children += folder_children | 1714 children += folder_children |
| 1722 else: | 1715 else: |
| 1723 folder_children = MSVSNew.MSVSFolder(os.path.join(base_path, folder), | 1716 folder_children = MSVSNew.MSVSFolder(os.path.join(base_path, folder), |
| 1724 name='(' + folder + ')', | 1717 name='(' + folder + ')', |
| 1725 entries=folder_children) | 1718 entries=folder_children) |
| 1726 children.append(folder_children) | 1719 children.append(folder_children) |
| 1727 else: | 1720 else: |
| 1728 children.append(contents) | 1721 children.append(contents) |
| 1729 return children | 1722 return children |
| 1730 | 1723 |
| 1731 | 1724 |
| 1732 def _CollapseSingles(parent, node): | 1725 def _CollapseSingles(parent, node): |
| 1733 # Recursively explorer the tree of dicts looking for projects which are | 1726 # Recursively explorer the tree of dicts looking for projects which are |
| 1734 # the sole item in a folder which has the same name as the project. Bring | 1727 # the sole item in a folder which has the same name as the project. Bring |
| 1735 # such projects up one level. | 1728 # such projects up one level. |
| 1736 if (type(node) == dict and | 1729 if (type(node) == dict and |
| 1737 len(node) == 1 and | 1730 len(node) == 1 and |
| 1738 node.keys()[0] == parent + '.vcproj'): | 1731 next(iter(node)) == parent + '.vcproj'): |
| 1739 return node[node.keys()[0]] | 1732 return node[next(iter(node))] |
| 1740 if type(node) != dict: | 1733 if type(node) != dict: |
| 1741 return node | 1734 return node |
| 1742 for child in node: | 1735 for child in node: |
| 1743 node[child] = _CollapseSingles(child, node[child]) | 1736 node[child] = _CollapseSingles(child, node[child]) |
| 1744 return node | 1737 return node |
| 1745 | 1738 |
| 1746 | 1739 |
| 1747 def _GatherSolutionFolders(sln_projects, project_objects, flat): | 1740 def _GatherSolutionFolders(sln_projects, project_objects, flat): |
| 1748 root = {} | 1741 root = {} |
| 1749 # Convert into a tree of dicts on path. | 1742 # Convert into a tree of dicts on path. |
| 1750 for p in sln_projects: | 1743 for p in sln_projects: |
| 1751 gyp_file, target = gyp.common.ParseQualifiedTarget(p)[0:2] | 1744 gyp_file, target = gyp.common.ParseQualifiedTarget(p)[0:2] |
| 1752 gyp_dir = os.path.dirname(gyp_file) | 1745 gyp_dir = os.path.dirname(gyp_file) |
| 1753 path_dict = _GetPathDict(root, gyp_dir) | 1746 path_dict = _GetPathDict(root, gyp_dir) |
| 1754 path_dict[target + '.vcproj'] = project_objects[p] | 1747 path_dict[target + '.vcproj'] = project_objects[p] |
| 1755 # Walk down from the top until we hit a folder that has more than one entry. | 1748 # Walk down from the top until we hit a folder that has more than one entry. |
| 1756 # In practice, this strips the top-level "src/" dir from the hierarchy in | 1749 # In practice, this strips the top-level "src/" dir from the hierarchy in |
| 1757 # the solution. | 1750 # the solution. |
| 1758 while len(root) == 1 and type(root[root.keys()[0]]) == dict: | 1751 while len(root) == 1 and type(root[next(iter(root))]) == dict: |
| 1759 root = root[root.keys()[0]] | 1752 root = root[next(iter(root))] |
| 1760 # Collapse singles. | 1753 # Collapse singles. |
| 1761 root = _CollapseSingles('', root) | 1754 root = _CollapseSingles('', root) |
| 1762 # Merge buckets until everything is a root entry. | 1755 # Merge buckets until everything is a root entry. |
| 1763 return _DictsToFolders('', root, flat) | 1756 return _DictsToFolders('', root, flat) |
| 1764 | 1757 |
| 1765 | 1758 |
| 1766 def _GetPathOfProject(qualified_target, spec, options, msvs_version): | 1759 def _GetPathOfProject(qualified_target, spec, options, msvs_version): |
| 1767 default_config = _GetDefaultConfiguration(spec) | 1760 default_config = _GetDefaultConfiguration(spec) |
| 1768 proj_filename = default_config.get('msvs_existing_vcproj') | 1761 proj_filename = default_config.get('msvs_existing_vcproj') |
| 1769 if not proj_filename: | 1762 if not proj_filename: |
| 1770 proj_filename = (spec['target_name'] + options.suffix + | 1763 proj_filename = (spec['target_name'] + options.suffix + |
| 1771 msvs_version.ProjectExtension()) | 1764 msvs_version.ProjectExtension()) |
| 1772 | 1765 |
| 1773 build_file = gyp.common.BuildFile(qualified_target) | 1766 build_file = gyp.common.BuildFile(qualified_target) |
| 1774 proj_path = os.path.join(os.path.dirname(build_file), proj_filename) | 1767 proj_path = os.path.join(os.path.dirname(build_file), proj_filename) |
| 1775 fix_prefix = None | 1768 fix_prefix = None |
| 1776 if options.generator_output: | 1769 if options.generator_output: |
| 1777 project_dir_path = os.path.dirname(os.path.abspath(proj_path)) | 1770 project_dir_path = os.path.dirname(os.path.abspath(proj_path)) |
| 1778 proj_path = os.path.join(options.generator_output, proj_path) | 1771 proj_path = os.path.join(options.generator_output, proj_path) |
| 1779 fix_prefix = gyp.common.RelativePath(project_dir_path, | 1772 fix_prefix = gyp.common.RelativePath(project_dir_path, |
| 1780 os.path.dirname(proj_path)) | 1773 os.path.dirname(proj_path)) |
| 1781 return proj_path, fix_prefix | 1774 return proj_path, fix_prefix |
| 1782 | 1775 |
| 1783 | 1776 |
| 1784 def _GetPlatformOverridesOfProject(spec): | 1777 def _GetPlatformOverridesOfProject(spec): |
| 1785 # Prepare a dict indicating which project configurations are used for which | 1778 # Prepare a dict indicating which project configurations are used for which |
| 1786 # solution configurations for this target. | 1779 # solution configurations for this target. |
| 1787 config_platform_overrides = {} | 1780 config_platform_overrides = {} |
| 1788 for config_name, c in spec['configurations'].iteritems(): | 1781 for config_name, c in spec['configurations'].items(): |
| 1789 config_fullname = _ConfigFullName(config_name, c) | 1782 config_fullname = _ConfigFullName(config_name, c) |
| 1790 platform = c.get('msvs_target_platform', _ConfigPlatform(c)) | 1783 platform = c.get('msvs_target_platform', _ConfigPlatform(c)) |
| 1791 fixed_config_fullname = '%s|%s' % ( | 1784 fixed_config_fullname = '%s|%s' % ( |
| 1792 _ConfigBaseName(config_name, _ConfigPlatform(c)), platform) | 1785 _ConfigBaseName(config_name, _ConfigPlatform(c)), platform) |
| 1793 config_platform_overrides[config_fullname] = fixed_config_fullname | 1786 config_platform_overrides[config_fullname] = fixed_config_fullname |
| 1794 return config_platform_overrides | 1787 return config_platform_overrides |
| 1795 | 1788 |
| 1796 | 1789 |
| 1797 def _CreateProjectObjects(target_list, target_dicts, options, msvs_version): | 1790 def _CreateProjectObjects(target_list, target_dicts, options, msvs_version): |
| 1798 """Create a MSVSProject object for the targets found in target list. | 1791 """Create a MSVSProject object for the targets found in target list. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 | 1910 |
| 1918 if gyp.common.GetFlavor(params) == 'ninja': | 1911 if gyp.common.GetFlavor(params) == 'ninja': |
| 1919 default_variables['SHARED_INTERMEDIATE_DIR'] = '$(OutDir)gen' | 1912 default_variables['SHARED_INTERMEDIATE_DIR'] = '$(OutDir)gen' |
| 1920 | 1913 |
| 1921 | 1914 |
| 1922 def PerformBuild(data, configurations, params): | 1915 def PerformBuild(data, configurations, params): |
| 1923 options = params['options'] | 1916 options = params['options'] |
| 1924 msvs_version = params['msvs_version'] | 1917 msvs_version = params['msvs_version'] |
| 1925 devenv = os.path.join(msvs_version.path, 'Common7', 'IDE', 'devenv.com') | 1918 devenv = os.path.join(msvs_version.path, 'Common7', 'IDE', 'devenv.com') |
| 1926 | 1919 |
| 1927 for build_file, build_file_dict in data.iteritems(): | 1920 for build_file, build_file_dict in data.items(): |
| 1928 (build_file_root, build_file_ext) = os.path.splitext(build_file) | 1921 (build_file_root, build_file_ext) = os.path.splitext(build_file) |
| 1929 if build_file_ext != '.gyp': | 1922 if build_file_ext != '.gyp': |
| 1930 continue | 1923 continue |
| 1931 sln_path = build_file_root + options.suffix + '.sln' | 1924 sln_path = build_file_root + options.suffix + '.sln' |
| 1932 if options.generator_output: | 1925 if options.generator_output: |
| 1933 sln_path = os.path.join(options.generator_output, sln_path) | 1926 sln_path = os.path.join(options.generator_output, sln_path) |
| 1934 | 1927 |
| 1935 for config in configurations: | 1928 for config in configurations: |
| 1936 arguments = [devenv, sln_path, '/Build', config] | 1929 arguments = [devenv, sln_path, '/Build', config] |
| 1937 print 'Building [%s]: %s' % (config, arguments) | 1930 print('Building [%s]: %s' % (config, arguments)) |
| 1938 rtn = subprocess.check_call(arguments) | 1931 rtn = subprocess.check_call(arguments) |
| 1939 | 1932 |
| 1940 | 1933 |
| 1941 def CalculateGeneratorInputInfo(params): | 1934 def CalculateGeneratorInputInfo(params): |
| 1942 if params.get('flavor') == 'ninja': | 1935 if params.get('flavor') == 'ninja': |
| 1943 toplevel = params['options'].toplevel_dir | 1936 toplevel = params['options'].toplevel_dir |
| 1944 qualified_out_dir = os.path.normpath(os.path.join( | 1937 qualified_out_dir = os.path.normpath(os.path.join( |
| 1945 toplevel, ninja_generator.ComputeOutputDir(params), | 1938 toplevel, ninja_generator.ComputeOutputDir(params), |
| 1946 'gypfiles-msvs-ninja')) | 1939 'gypfiles-msvs-ninja')) |
| 1947 | 1940 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 target_list, target_dicts, generator_default_variables) | 1972 target_list, target_dicts, generator_default_variables) |
| 1980 | 1973 |
| 1981 # Optionally configure each spec to use ninja as the external builder. | 1974 # Optionally configure each spec to use ninja as the external builder. |
| 1982 if params.get('flavor') == 'ninja': | 1975 if params.get('flavor') == 'ninja': |
| 1983 _InitNinjaFlavor(params, target_list, target_dicts) | 1976 _InitNinjaFlavor(params, target_list, target_dicts) |
| 1984 | 1977 |
| 1985 # Prepare the set of configurations. | 1978 # Prepare the set of configurations. |
| 1986 configs = set() | 1979 configs = set() |
| 1987 for qualified_target in target_list: | 1980 for qualified_target in target_list: |
| 1988 spec = target_dicts[qualified_target] | 1981 spec = target_dicts[qualified_target] |
| 1989 for config_name, config in spec['configurations'].iteritems(): | 1982 for config_name, config in spec['configurations'].items(): |
| 1990 configs.add(_ConfigFullName(config_name, config)) | 1983 configs.add(_ConfigFullName(config_name, config)) |
| 1991 configs = list(configs) | 1984 configs = list(configs) |
| 1992 | 1985 |
| 1993 # Figure out all the projects that will be generated and their guids | 1986 # Figure out all the projects that will be generated and their guids |
| 1994 project_objects = _CreateProjectObjects(target_list, target_dicts, options, | 1987 project_objects = _CreateProjectObjects(target_list, target_dicts, options, |
| 1995 msvs_version) | 1988 msvs_version) |
| 1996 | 1989 |
| 1997 # Generate each project. | 1990 # Generate each project. |
| 1998 missing_sources = [] | 1991 missing_sources = [] |
| 1999 for project in project_objects.values(): | 1992 for project in project_objects.values(): |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2022 websiteProperties=False, | 2015 websiteProperties=False, |
| 2023 version=msvs_version) | 2016 version=msvs_version) |
| 2024 sln.Write() | 2017 sln.Write() |
| 2025 | 2018 |
| 2026 if missing_sources: | 2019 if missing_sources: |
| 2027 error_message = "Missing input files:\n" + \ | 2020 error_message = "Missing input files:\n" + \ |
| 2028 '\n'.join(set(missing_sources)) | 2021 '\n'.join(set(missing_sources)) |
| 2029 if generator_flags.get('msvs_error_on_missing_sources', False): | 2022 if generator_flags.get('msvs_error_on_missing_sources', False): |
| 2030 raise GypError(error_message) | 2023 raise GypError(error_message) |
| 2031 else: | 2024 else: |
| 2032 print >> sys.stdout, "Warning: " + error_message | 2025 print("Warning: " + error_message, file=sys.stdout) |
| 2033 | 2026 |
| 2034 | 2027 |
| 2035 def _GenerateMSBuildFiltersFile(filters_path, source_files, | 2028 def _GenerateMSBuildFiltersFile(filters_path, source_files, |
| 2036 rule_dependencies, extension_to_rule_name): | 2029 rule_dependencies, extension_to_rule_name): |
| 2037 """Generate the filters file. | 2030 """Generate the filters file. |
| 2038 | 2031 |
| 2039 This file is used by Visual Studio to organize the presentation of source | 2032 This file is used by Visual Studio to organize the presentation of source |
| 2040 files into folders. | 2033 files into folders. |
| 2041 | 2034 |
| 2042 Arguments: | 2035 Arguments: |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2619 return (configuration, platform) | 2612 return (configuration, platform) |
| 2620 | 2613 |
| 2621 | 2614 |
| 2622 def _GetConfigurationCondition(name, settings): | 2615 def _GetConfigurationCondition(name, settings): |
| 2623 return (r"'$(Configuration)|$(Platform)'=='%s|%s'" % | 2616 return (r"'$(Configuration)|$(Platform)'=='%s|%s'" % |
| 2624 _GetConfigurationAndPlatform(name, settings)) | 2617 _GetConfigurationAndPlatform(name, settings)) |
| 2625 | 2618 |
| 2626 | 2619 |
| 2627 def _GetMSBuildProjectConfigurations(configurations): | 2620 def _GetMSBuildProjectConfigurations(configurations): |
| 2628 group = ['ItemGroup', {'Label': 'ProjectConfigurations'}] | 2621 group = ['ItemGroup', {'Label': 'ProjectConfigurations'}] |
| 2629 for (name, settings) in sorted(configurations.iteritems()): | 2622 for (name, settings) in sorted(configurations.items()): |
| 2630 configuration, platform = _GetConfigurationAndPlatform(name, settings) | 2623 configuration, platform = _GetConfigurationAndPlatform(name, settings) |
| 2631 designation = '%s|%s' % (configuration, platform) | 2624 designation = '%s|%s' % (configuration, platform) |
| 2632 group.append( | 2625 group.append( |
| 2633 ['ProjectConfiguration', {'Include': designation}, | 2626 ['ProjectConfiguration', {'Include': designation}, |
| 2634 ['Configuration', configuration], | 2627 ['Configuration', configuration], |
| 2635 ['Platform', platform]]) | 2628 ['Platform', platform]]) |
| 2636 return [group] | 2629 return [group] |
| 2637 | 2630 |
| 2638 | 2631 |
| 2639 def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name): | 2632 def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name): |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2673 target_platform_version]) | 2666 target_platform_version]) |
| 2674 if spec.get('msvs_enable_winphone'): | 2667 if spec.get('msvs_enable_winphone'): |
| 2675 properties[0].append(['ApplicationType', 'Windows Phone']) | 2668 properties[0].append(['ApplicationType', 'Windows Phone']) |
| 2676 else: | 2669 else: |
| 2677 properties[0].append(['ApplicationType', 'Windows Store']) | 2670 properties[0].append(['ApplicationType', 'Windows Store']) |
| 2678 | 2671 |
| 2679 return properties | 2672 return properties |
| 2680 | 2673 |
| 2681 def _GetMSBuildConfigurationDetails(spec, build_file): | 2674 def _GetMSBuildConfigurationDetails(spec, build_file): |
| 2682 properties = {} | 2675 properties = {} |
| 2683 for name, settings in spec['configurations'].iteritems(): | 2676 for name, settings in spec['configurations'].items(): |
| 2684 msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file) | 2677 msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file) |
| 2685 condition = _GetConfigurationCondition(name, settings) | 2678 condition = _GetConfigurationCondition(name, settings) |
| 2686 character_set = msbuild_attributes.get('CharacterSet') | 2679 character_set = msbuild_attributes.get('CharacterSet') |
| 2687 _AddConditionalProperty(properties, condition, 'ConfigurationType', | 2680 _AddConditionalProperty(properties, condition, 'ConfigurationType', |
| 2688 msbuild_attributes['ConfigurationType']) | 2681 msbuild_attributes['ConfigurationType']) |
| 2689 if character_set: | 2682 if character_set: |
| 2690 if 'msvs_enable_winrt' not in spec : | 2683 if 'msvs_enable_winrt' not in spec : |
| 2691 _AddConditionalProperty(properties, condition, 'CharacterSet', | 2684 _AddConditionalProperty(properties, condition, 'CharacterSet', |
| 2692 character_set) | 2685 character_set) |
| 2693 return _GetMSBuildPropertyGroup(spec, 'Configuration', properties) | 2686 return _GetMSBuildPropertyGroup(spec, 'Configuration', properties) |
| 2694 | 2687 |
| 2695 | 2688 |
| 2696 def _GetMSBuildLocalProperties(msbuild_toolset): | 2689 def _GetMSBuildLocalProperties(msbuild_toolset): |
| 2697 # Currently the only local property we support is PlatformToolset | 2690 # Currently the only local property we support is PlatformToolset |
| 2698 properties = {} | 2691 properties = {} |
| 2699 if msbuild_toolset: | 2692 if msbuild_toolset: |
| 2700 properties = [ | 2693 properties = [ |
| 2701 ['PropertyGroup', {'Label': 'Locals'}, | 2694 ['PropertyGroup', {'Label': 'Locals'}, |
| 2702 ['PlatformToolset', msbuild_toolset], | 2695 ['PlatformToolset', msbuild_toolset], |
| 2703 ] | 2696 ] |
| 2704 ] | 2697 ] |
| 2705 return properties | 2698 return properties |
| 2706 | 2699 |
| 2707 | 2700 |
| 2708 def _GetMSBuildPropertySheets(configurations): | 2701 def _GetMSBuildPropertySheets(configurations): |
| 2709 user_props = r'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props' | 2702 user_props = r'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props' |
| 2710 additional_props = {} | 2703 additional_props = {} |
| 2711 props_specified = False | 2704 props_specified = False |
| 2712 for name, settings in sorted(configurations.iteritems()): | 2705 for name, settings in sorted(configurations.items()): |
| 2713 configuration = _GetConfigurationCondition(name, settings) | 2706 configuration = _GetConfigurationCondition(name, settings) |
| 2714 if settings.has_key('msbuild_props'): | 2707 if 'msbuild_props' in settings: |
| 2715 additional_props[configuration] = _FixPaths(settings['msbuild_props']) | 2708 additional_props[configuration] = _FixPaths(settings['msbuild_props']) |
| 2716 props_specified = True | 2709 props_specified = True |
| 2717 else: | 2710 else: |
| 2718 additional_props[configuration] = '' | 2711 additional_props[configuration] = '' |
| 2719 | 2712 |
| 2720 if not props_specified: | 2713 if not props_specified: |
| 2721 return [ | 2714 return [ |
| 2722 ['ImportGroup', | 2715 ['ImportGroup', |
| 2723 {'Label': 'PropertySheets'}, | 2716 {'Label': 'PropertySheets'}, |
| 2724 ['Import', | 2717 ['Import', |
| 2725 {'Project': user_props, | 2718 {'Project': user_props, |
| 2726 'Condition': "exists('%s')" % user_props, | 2719 'Condition': "exists('%s')" % user_props, |
| 2727 'Label': 'LocalAppDataPlatform' | 2720 'Label': 'LocalAppDataPlatform' |
| 2728 } | 2721 } |
| 2729 ] | 2722 ] |
| 2730 ] | 2723 ] |
| 2731 ] | 2724 ] |
| 2732 else: | 2725 else: |
| 2733 sheets = [] | 2726 sheets = [] |
| 2734 for condition, props in additional_props.iteritems(): | 2727 for condition, props in additional_props.items(): |
| 2735 import_group = [ | 2728 import_group = [ |
| 2736 'ImportGroup', | 2729 'ImportGroup', |
| 2737 {'Label': 'PropertySheets', | 2730 {'Label': 'PropertySheets', |
| 2738 'Condition': condition | 2731 'Condition': condition |
| 2739 }, | 2732 }, |
| 2740 ['Import', | 2733 ['Import', |
| 2741 {'Project': user_props, | 2734 {'Project': user_props, |
| 2742 'Condition': "exists('%s')" % user_props, | 2735 'Condition': "exists('%s')" % user_props, |
| 2743 'Label': 'LocalAppDataPlatform' | 2736 'Label': 'LocalAppDataPlatform' |
| 2744 } | 2737 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2757 if a in ['IntermediateDirectory', 'OutputDirectory']: | 2750 if a in ['IntermediateDirectory', 'OutputDirectory']: |
| 2758 directory = MSVSSettings.ConvertVCMacrosToMSBuild(msvs_attributes[a]) | 2751 directory = MSVSSettings.ConvertVCMacrosToMSBuild(msvs_attributes[a]) |
| 2759 if not directory.endswith('\\'): | 2752 if not directory.endswith('\\'): |
| 2760 directory += '\\' | 2753 directory += '\\' |
| 2761 msbuild_attributes[a] = directory | 2754 msbuild_attributes[a] = directory |
| 2762 elif a == 'CharacterSet': | 2755 elif a == 'CharacterSet': |
| 2763 msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a]) | 2756 msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a]) |
| 2764 elif a == 'ConfigurationType': | 2757 elif a == 'ConfigurationType': |
| 2765 msbuild_attributes[a] = _ConvertMSVSConfigurationType(msvs_attributes[a]) | 2758 msbuild_attributes[a] = _ConvertMSVSConfigurationType(msvs_attributes[a]) |
| 2766 else: | 2759 else: |
| 2767 print 'Warning: Do not know how to convert MSVS attribute ' + a | 2760 print('Warning: Do not know how to convert MSVS attribute ' + a) |
| 2768 return msbuild_attributes | 2761 return msbuild_attributes |
| 2769 | 2762 |
| 2770 | 2763 |
| 2771 def _ConvertMSVSCharacterSet(char_set): | 2764 def _ConvertMSVSCharacterSet(char_set): |
| 2772 if char_set.isdigit(): | 2765 if char_set.isdigit(): |
| 2773 char_set = { | 2766 char_set = { |
| 2774 '0': 'MultiByte', | 2767 '0': 'MultiByte', |
| 2775 '1': 'Unicode', | 2768 '1': 'Unicode', |
| 2776 '2': 'MultiByte', | 2769 '2': 'MultiByte', |
| 2777 }[char_set] | 2770 }[char_set] |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2848 cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs) | 2841 cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs) |
| 2849 new_paths.append(cyg_path) | 2842 new_paths.append(cyg_path) |
| 2850 # TODO(jeanluc) Change the convention to have both a cygwin_dir and a | 2843 # TODO(jeanluc) Change the convention to have both a cygwin_dir and a |
| 2851 # python_dir. | 2844 # python_dir. |
| 2852 python_path = cyg_path.replace('cygwin\\bin', 'python_26') | 2845 python_path = cyg_path.replace('cygwin\\bin', 'python_26') |
| 2853 new_paths.append(python_path) | 2846 new_paths.append(python_path) |
| 2854 if new_paths: | 2847 if new_paths: |
| 2855 new_paths = '$(ExecutablePath);' + ';'.join(new_paths) | 2848 new_paths = '$(ExecutablePath);' + ';'.join(new_paths) |
| 2856 | 2849 |
| 2857 properties = {} | 2850 properties = {} |
| 2858 for (name, configuration) in sorted(configurations.iteritems()): | 2851 for (name, configuration) in sorted(configurations.items()): |
| 2859 condition = _GetConfigurationCondition(name, configuration) | 2852 condition = _GetConfigurationCondition(name, configuration) |
| 2860 attributes = _GetMSBuildAttributes(spec, configuration, build_file) | 2853 attributes = _GetMSBuildAttributes(spec, configuration, build_file) |
| 2861 msbuild_settings = configuration['finalized_msbuild_settings'] | 2854 msbuild_settings = configuration['finalized_msbuild_settings'] |
| 2862 _AddConditionalProperty(properties, condition, 'IntDir', | 2855 _AddConditionalProperty(properties, condition, 'IntDir', |
| 2863 attributes['IntermediateDirectory']) | 2856 attributes['IntermediateDirectory']) |
| 2864 _AddConditionalProperty(properties, condition, 'OutDir', | 2857 _AddConditionalProperty(properties, condition, 'OutDir', |
| 2865 attributes['OutputDirectory']) | 2858 attributes['OutputDirectory']) |
| 2866 _AddConditionalProperty(properties, condition, 'TargetName', | 2859 _AddConditionalProperty(properties, condition, 'TargetName', |
| 2867 attributes['TargetName']) | 2860 attributes['TargetName']) |
| 2868 | 2861 |
| 2869 if attributes.get('TargetPath'): | 2862 if attributes.get('TargetPath'): |
| 2870 _AddConditionalProperty(properties, condition, 'TargetPath', | 2863 _AddConditionalProperty(properties, condition, 'TargetPath', |
| 2871 attributes['TargetPath']) | 2864 attributes['TargetPath']) |
| 2872 if attributes.get('TargetExt'): | 2865 if attributes.get('TargetExt'): |
| 2873 _AddConditionalProperty(properties, condition, 'TargetExt', | 2866 _AddConditionalProperty(properties, condition, 'TargetExt', |
| 2874 attributes['TargetExt']) | 2867 attributes['TargetExt']) |
| 2875 | 2868 |
| 2876 if new_paths: | 2869 if new_paths: |
| 2877 _AddConditionalProperty(properties, condition, 'ExecutablePath', | 2870 _AddConditionalProperty(properties, condition, 'ExecutablePath', |
| 2878 new_paths) | 2871 new_paths) |
| 2879 tool_settings = msbuild_settings.get('', {}) | 2872 tool_settings = msbuild_settings.get('', {}) |
| 2880 for name, value in sorted(tool_settings.iteritems()): | 2873 for name, value in sorted(tool_settings.items()): |
| 2881 formatted_value = _GetValueFormattedForMSBuild('', name, value) | 2874 formatted_value = _GetValueFormattedForMSBuild('', name, value) |
| 2882 _AddConditionalProperty(properties, condition, name, formatted_value) | 2875 _AddConditionalProperty(properties, condition, name, formatted_value) |
| 2883 return _GetMSBuildPropertyGroup(spec, None, properties) | 2876 return _GetMSBuildPropertyGroup(spec, None, properties) |
| 2884 | 2877 |
| 2885 | 2878 |
| 2886 def _AddConditionalProperty(properties, condition, name, value): | 2879 def _AddConditionalProperty(properties, condition, name, value): |
| 2887 """Adds a property / conditional value pair to a dictionary. | 2880 """Adds a property / conditional value pair to a dictionary. |
| 2888 | 2881 |
| 2889 Arguments: | 2882 Arguments: |
| 2890 properties: The dictionary to be modified. The key is the name of the | 2883 properties: The dictionary to be modified. The key is the name of the |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2939 if v in properties and v != node])) | 2932 if v in properties and v != node])) |
| 2940 return edges | 2933 return edges |
| 2941 properties_ordered = gyp.common.TopologicallySorted( | 2934 properties_ordered = gyp.common.TopologicallySorted( |
| 2942 properties.keys(), GetEdges) | 2935 properties.keys(), GetEdges) |
| 2943 # Walk properties in the reverse of a topological sort on | 2936 # Walk properties in the reverse of a topological sort on |
| 2944 # user_of_variable -> used_variable as this ensures variables are | 2937 # user_of_variable -> used_variable as this ensures variables are |
| 2945 # defined before they are used. | 2938 # defined before they are used. |
| 2946 # NOTE: reverse(topsort(DAG)) = topsort(reverse_edges(DAG)) | 2939 # NOTE: reverse(topsort(DAG)) = topsort(reverse_edges(DAG)) |
| 2947 for name in reversed(properties_ordered): | 2940 for name in reversed(properties_ordered): |
| 2948 values = properties[name] | 2941 values = properties[name] |
| 2949 for value, conditions in sorted(values.iteritems()): | 2942 for value, conditions in sorted(values.items()): |
| 2950 if len(conditions) == num_configurations: | 2943 if len(conditions) == num_configurations: |
| 2951 # If the value is the same all configurations, | 2944 # If the value is the same all configurations, |
| 2952 # just add one unconditional entry. | 2945 # just add one unconditional entry. |
| 2953 group.append([name, value]) | 2946 group.append([name, value]) |
| 2954 else: | 2947 else: |
| 2955 for condition in conditions: | 2948 for condition in conditions: |
| 2956 group.append([name, {'Condition': condition}, value]) | 2949 group.append([name, {'Condition': condition}, value]) |
| 2957 return [group] | 2950 return [group] |
| 2958 | 2951 |
| 2959 | 2952 |
| 2960 def _GetMSBuildToolSettingsSections(spec, configurations): | 2953 def _GetMSBuildToolSettingsSections(spec, configurations): |
| 2961 groups = [] | 2954 groups = [] |
| 2962 for (name, configuration) in sorted(configurations.iteritems()): | 2955 for (name, configuration) in sorted(configurations.items()): |
| 2963 msbuild_settings = configuration['finalized_msbuild_settings'] | 2956 msbuild_settings = configuration['finalized_msbuild_settings'] |
| 2964 group = ['ItemDefinitionGroup', | 2957 group = ['ItemDefinitionGroup', |
| 2965 {'Condition': _GetConfigurationCondition(name, configuration)} | 2958 {'Condition': _GetConfigurationCondition(name, configuration)} |
| 2966 ] | 2959 ] |
| 2967 for tool_name, tool_settings in sorted(msbuild_settings.iteritems()): | 2960 for tool_name, tool_settings in sorted(msbuild_settings.items()): |
| 2968 # Skip the tool named '' which is a holder of global settings handled | 2961 # Skip the tool named '' which is a holder of global settings handled |
| 2969 # by _GetMSBuildConfigurationGlobalProperties. | 2962 # by _GetMSBuildConfigurationGlobalProperties. |
| 2970 if tool_name: | 2963 if tool_name: |
| 2971 if tool_settings: | 2964 if tool_settings: |
| 2972 tool = [tool_name] | 2965 tool = [tool_name] |
| 2973 for name, value in sorted(tool_settings.iteritems()): | 2966 for name, value in sorted(tool_settings.items()): |
| 2974 formatted_value = _GetValueFormattedForMSBuild(tool_name, name, | 2967 formatted_value = _GetValueFormattedForMSBuild(tool_name, name, |
| 2975 value) | 2968 value) |
| 2976 tool.append([name, formatted_value]) | 2969 tool.append([name, formatted_value]) |
| 2977 group.append(tool) | 2970 group.append(tool) |
| 2978 groups.append(group) | 2971 groups.append(group) |
| 2979 return groups | 2972 return groups |
| 2980 | 2973 |
| 2981 | 2974 |
| 2982 def _FinalizeMSBuildSettings(spec, configuration): | 2975 def _FinalizeMSBuildSettings(spec, configuration): |
| 2983 if 'msbuild_settings' in configuration: | 2976 if 'msbuild_settings' in configuration: |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3163 excluded_configurations = exclusions.get(source, []) | 3156 excluded_configurations = exclusions.get(source, []) |
| 3164 if len(excluded_configurations) == len(spec['configurations']): | 3157 if len(excluded_configurations) == len(spec['configurations']): |
| 3165 detail.append(['ExcludedFromBuild', 'true']) | 3158 detail.append(['ExcludedFromBuild', 'true']) |
| 3166 else: | 3159 else: |
| 3167 for config_name, configuration in sorted(excluded_configurations): | 3160 for config_name, configuration in sorted(excluded_configurations): |
| 3168 condition = _GetConfigurationCondition(config_name, configuration) | 3161 condition = _GetConfigurationCondition(config_name, configuration) |
| 3169 detail.append(['ExcludedFromBuild', | 3162 detail.append(['ExcludedFromBuild', |
| 3170 {'Condition': condition}, | 3163 {'Condition': condition}, |
| 3171 'true']) | 3164 'true']) |
| 3172 # Add precompile if needed | 3165 # Add precompile if needed |
| 3173 for config_name, configuration in spec['configurations'].iteritems(): | 3166 for config_name, configuration in spec['configurations'].items(): |
| 3174 precompiled_source = configuration.get('msvs_precompiled_source', '') | 3167 precompiled_source = configuration.get('msvs_precompiled_source', '') |
| 3175 if precompiled_source != '': | 3168 if precompiled_source != '': |
| 3176 precompiled_source = _FixPath(precompiled_source) | 3169 precompiled_source = _FixPath(precompiled_source) |
| 3177 if not extensions_excluded_from_precompile: | 3170 if not extensions_excluded_from_precompile: |
| 3178 # If the precompiled header is generated by a C source, we must | 3171 # If the precompiled header is generated by a C source, we must |
| 3179 # not try to use it for C++ sources, and vice versa. | 3172 # not try to use it for C++ sources, and vice versa. |
| 3180 basename, extension = os.path.splitext(precompiled_source) | 3173 basename, extension = os.path.splitext(precompiled_source) |
| 3181 if extension == '.c': | 3174 if extension == '.c': |
| 3182 extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx'] | 3175 extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx'] |
| 3183 else: | 3176 else: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3209 group = ['ItemGroup'] | 3202 group = ['ItemGroup'] |
| 3210 for dependency in project.dependencies: | 3203 for dependency in project.dependencies: |
| 3211 guid = dependency.guid | 3204 guid = dependency.guid |
| 3212 project_dir = os.path.split(project.path)[0] | 3205 project_dir = os.path.split(project.path)[0] |
| 3213 relative_path = gyp.common.RelativePath(dependency.path, project_dir) | 3206 relative_path = gyp.common.RelativePath(dependency.path, project_dir) |
| 3214 project_ref = ['ProjectReference', | 3207 project_ref = ['ProjectReference', |
| 3215 {'Include': relative_path}, | 3208 {'Include': relative_path}, |
| 3216 ['Project', guid], | 3209 ['Project', guid], |
| 3217 ['ReferenceOutputAssembly', 'false'] | 3210 ['ReferenceOutputAssembly', 'false'] |
| 3218 ] | 3211 ] |
| 3219 for config in dependency.spec.get('configurations', {}).itervalues(): | 3212 for config in dependency.spec.get('configurations', {}).values(): |
| 3220 # If it's disabled in any config, turn it off in the reference. | 3213 # If it's disabled in any config, turn it off in the reference. |
| 3221 if config.get('msvs_2010_disable_uldi_when_referenced', 0): | 3214 if config.get('msvs_2010_disable_uldi_when_referenced', 0): |
| 3222 project_ref.append(['UseLibraryDependencyInputs', 'false']) | 3215 project_ref.append(['UseLibraryDependencyInputs', 'false']) |
| 3223 break | 3216 break |
| 3224 group.append(project_ref) | 3217 group.append(project_ref) |
| 3225 references.append(group) | 3218 references.append(group) |
| 3226 return references | 3219 return references |
| 3227 | 3220 |
| 3228 | 3221 |
| 3229 def _GenerateMSBuildProject(project, options, version, generator_flags): | 3222 def _GenerateMSBuildProject(project, options, version, generator_flags): |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3275 | 3268 |
| 3276 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) | 3269 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) |
| 3277 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild( | 3270 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild( |
| 3278 spec, actions_to_add) | 3271 spec, actions_to_add) |
| 3279 | 3272 |
| 3280 _GenerateMSBuildFiltersFile(project.path + '.filters', sources, | 3273 _GenerateMSBuildFiltersFile(project.path + '.filters', sources, |
| 3281 rule_dependencies, | 3274 rule_dependencies, |
| 3282 extension_to_rule_name) | 3275 extension_to_rule_name) |
| 3283 missing_sources = _VerifySourcesExist(sources, project_dir) | 3276 missing_sources = _VerifySourcesExist(sources, project_dir) |
| 3284 | 3277 |
| 3285 for configuration in configurations.itervalues(): | 3278 for configuration in configurations.values(): |
| 3286 _FinalizeMSBuildSettings(spec, configuration) | 3279 _FinalizeMSBuildSettings(spec, configuration) |
| 3287 | 3280 |
| 3288 # Add attributes to root element | 3281 # Add attributes to root element |
| 3289 | 3282 |
| 3290 import_default_section = [ | 3283 import_default_section = [ |
| 3291 ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.Default.props'}]] | 3284 ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.Default.props'}]] |
| 3292 import_cpp_props_section = [ | 3285 import_cpp_props_section = [ |
| 3293 ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.props'}]] | 3286 ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.props'}]] |
| 3294 import_cpp_targets_section = [ | 3287 import_cpp_targets_section = [ |
| 3295 ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.targets'}]] | 3288 ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.targets'}]] |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3400 Arguments: | 3393 Arguments: |
| 3401 spec: the target project dict | 3394 spec: the target project dict |
| 3402 actions_to_add: dictionary keyed on input name, which maps to a list of | 3395 actions_to_add: dictionary keyed on input name, which maps to a list of |
| 3403 dicts describing the actions attached to that input file. | 3396 dicts describing the actions attached to that input file. |
| 3404 | 3397 |
| 3405 Returns: | 3398 Returns: |
| 3406 A pair of (action specification, the sources handled by this action). | 3399 A pair of (action specification, the sources handled by this action). |
| 3407 """ | 3400 """ |
| 3408 sources_handled_by_action = OrderedSet() | 3401 sources_handled_by_action = OrderedSet() |
| 3409 actions_spec = [] | 3402 actions_spec = [] |
| 3410 for primary_input, actions in actions_to_add.iteritems(): | 3403 for primary_input, actions in actions_to_add.items(): |
| 3411 inputs = OrderedSet() | 3404 inputs = OrderedSet() |
| 3412 outputs = OrderedSet() | 3405 outputs = OrderedSet() |
| 3413 descriptions = [] | 3406 descriptions = [] |
| 3414 commands = [] | 3407 commands = [] |
| 3415 for action in actions: | 3408 for action in actions: |
| 3416 inputs.update(OrderedSet(action['inputs'])) | 3409 inputs.update(OrderedSet(action['inputs'])) |
| 3417 outputs.update(OrderedSet(action['outputs'])) | 3410 outputs.update(OrderedSet(action['outputs'])) |
| 3418 descriptions.append(action['description']) | 3411 descriptions.append(action['description']) |
| 3419 cmd = action['command'] | 3412 cmd = action['command'] |
| 3420 # For most actions, add 'call' so that actions that invoke batch files | 3413 # For most actions, add 'call' so that actions that invoke batch files |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3458 action_spec.extend( | 3451 action_spec.extend( |
| 3459 # TODO(jeanluc) 'Document' for all or just if as_sources? | 3452 # TODO(jeanluc) 'Document' for all or just if as_sources? |
| 3460 [['FileType', 'Document'], | 3453 [['FileType', 'Document'], |
| 3461 ['Command', command], | 3454 ['Command', command], |
| 3462 ['Message', description], | 3455 ['Message', description], |
| 3463 ['Outputs', outputs] | 3456 ['Outputs', outputs] |
| 3464 ]) | 3457 ]) |
| 3465 if additional_inputs: | 3458 if additional_inputs: |
| 3466 action_spec.append(['AdditionalInputs', additional_inputs]) | 3459 action_spec.append(['AdditionalInputs', additional_inputs]) |
| 3467 actions_spec.append(action_spec) | 3460 actions_spec.append(action_spec) |
| OLD | NEW |