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 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 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 sources, excluded_sources, excluded_idl = ( | 897 sources, excluded_sources, excluded_idl = ( |
898 _AdjustSourcesAndConvertToFilterHierarchy( | 898 _AdjustSourcesAndConvertToFilterHierarchy( |
899 spec, options, project_dir, sources, excluded_sources, list_excluded)) | 899 spec, options, project_dir, sources, excluded_sources, list_excluded)) |
900 | 900 |
901 # Add in files. | 901 # Add in files. |
902 missing_sources = _VerifySourcesExist(sources, project_dir) | 902 missing_sources = _VerifySourcesExist(sources, project_dir) |
903 p.AddFiles(sources) | 903 p.AddFiles(sources) |
904 | 904 |
905 _AddToolFilesToMSVS(p, spec) | 905 _AddToolFilesToMSVS(p, spec) |
906 _HandlePreCompiledHeaders(p, sources, spec) | 906 _HandlePreCompiledHeaders(p, sources, spec) |
907 _AddActions(actions_to_add, spec, relative_path_of_gyp_file, project.path) | 907 _AddActions(actions_to_add, spec, relative_path_of_gyp_file) |
908 _AddCopies(actions_to_add, spec) | 908 _AddCopies(actions_to_add, spec) |
909 _WriteMSVSUserFile(project.path, version, spec) | 909 _WriteMSVSUserFile(project.path, version, spec) |
910 | 910 |
911 # NOTE: this stanza must appear after all actions have been decided. | 911 # NOTE: this stanza must appear after all actions have been decided. |
912 # Don't excluded sources with actions attached, or they won't run. | 912 # Don't excluded sources with actions attached, or they won't run. |
913 excluded_sources = _FilterActionsFromExcluded( | 913 excluded_sources = _FilterActionsFromExcluded( |
914 excluded_sources, actions_to_add) | 914 excluded_sources, actions_to_add) |
915 _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl, | 915 _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl, |
916 list_excluded) | 916 list_excluded) |
917 _AddAccumulatedActionsToMSVS(p, spec, actions_to_add) | 917 _AddAccumulatedActionsToMSVS(p, spec, actions_to_add) |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 {'UsePrecompiledHeader': '0', | 1433 {'UsePrecompiledHeader': '0', |
1434 'ForcedIncludeFiles': '$(NOINHERIT)'}) | 1434 'ForcedIncludeFiles': '$(NOINHERIT)'}) |
1435 p.AddFileConfig(_FixPath(source), | 1435 p.AddFileConfig(_FixPath(source), |
1436 _ConfigFullName(config_name, config), | 1436 _ConfigFullName(config_name, config), |
1437 {}, tools=[tool]) | 1437 {}, tools=[tool]) |
1438 # Do nothing if there was no precompiled source. | 1438 # Do nothing if there was no precompiled source. |
1439 if extensions_excluded_from_precompile: | 1439 if extensions_excluded_from_precompile: |
1440 DisableForSourceTree(sources) | 1440 DisableForSourceTree(sources) |
1441 | 1441 |
1442 | 1442 |
1443 def _WriteFileIfChanged(filename, data): | 1443 def _AddActions(actions_to_add, spec, relative_path_of_gyp_file): |
1444 if os.path.exists(filename): | |
1445 fh = open(filename, 'r') | |
1446 old_data = fh.read() | |
1447 fh.close() | |
1448 if old_data == data: | |
1449 return | |
1450 fh = open(filename, 'w') | |
1451 fh.write(data) | |
1452 fh.close() | |
1453 | |
1454 | |
1455 def _AddActions(actions_to_add, spec, relative_path_of_gyp_file, vcproj_file): | |
1456 # Add actions. | 1444 # Add actions. |
1457 actions = spec.get('actions', []) | 1445 actions = spec.get('actions', []) |
1458 # Don't setup_env every time. When all the actions are run together in one | 1446 # Don't setup_env every time. When all the actions are run together in one |
1459 # batch file in VS, the PATH will grow too long. | 1447 # batch file in VS, the PATH will grow too long. |
1460 # Membership in this set means that the cygwin environment has been set up, | 1448 # Membership in this set means that the cygwin environment has been set up, |
1461 # and does not need to be set up again. | 1449 # and does not need to be set up again. |
1462 have_setup_env = set() | 1450 have_setup_env = set() |
1463 for a in actions: | 1451 for a in actions: |
1464 # Attach actions to the gyp file if nothing else is there. | 1452 # Attach actions to the gyp file if nothing else is there. |
1465 inputs = a.get('inputs') or [relative_path_of_gyp_file] | 1453 inputs = a.get('inputs') or [relative_path_of_gyp_file] |
1466 attached_to = inputs[0] | 1454 attached_to = inputs[0] |
1467 need_setup_env = attached_to not in have_setup_env | 1455 need_setup_env = attached_to not in have_setup_env |
1468 cmd = _BuildCommandLineForRule(spec, a, has_input_path=False, | 1456 cmd = _BuildCommandLineForRule(spec, a, has_input_path=False, |
1469 do_setup_env=need_setup_env) | 1457 do_setup_env=need_setup_env) |
1470 have_setup_env.add(attached_to) | 1458 have_setup_env.add(attached_to) |
1471 if vcproj_file: | |
1472 # Additionally, on MSVS 2008, we record the command in a file | |
1473 # and add this as a dependency so that when the command changes, | |
1474 # the action gets re-run. This is not necessary on MSVS 2010 | |
1475 # which tracks command changes for us. | |
1476 command_file = '%s_%s.gypcmd' % (vcproj_file, a['action_name']) | |
1477 _WriteFileIfChanged(command_file, cmd) | |
1478 inputs = inputs + [os.path.basename(command_file)] | |
1479 # Add the action. | 1459 # Add the action. |
1480 _AddActionStep(actions_to_add, | 1460 _AddActionStep(actions_to_add, |
1481 inputs=inputs, | 1461 inputs=inputs, |
1482 outputs=a.get('outputs', []), | 1462 outputs=a.get('outputs', []), |
1483 description=a.get('message', a['action_name']), | 1463 description=a.get('message', a['action_name']), |
1484 command=cmd) | 1464 command=cmd) |
1485 | 1465 |
1486 | 1466 |
1487 def _WriteMSVSUserFile(project_path, version, spec): | 1467 def _WriteMSVSUserFile(project_path, version, spec): |
1488 # Add run_as and test targets. | 1468 # Add run_as and test targets. |
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2956 | 2936 |
2957 | 2937 |
2958 def _GenerateMSBuildProject(project, options, version, generator_flags): | 2938 def _GenerateMSBuildProject(project, options, version, generator_flags): |
2959 spec = project.spec | 2939 spec = project.spec |
2960 configurations = spec['configurations'] | 2940 configurations = spec['configurations'] |
2961 project_dir, project_file_name = os.path.split(project.path) | 2941 project_dir, project_file_name = os.path.split(project.path) |
2962 msbuildproj_dir = os.path.dirname(project.path) | 2942 msbuildproj_dir = os.path.dirname(project.path) |
2963 if msbuildproj_dir and not os.path.exists(msbuildproj_dir): | 2943 if msbuildproj_dir and not os.path.exists(msbuildproj_dir): |
2964 os.makedirs(msbuildproj_dir) | 2944 os.makedirs(msbuildproj_dir) |
2965 # Prepare list of sources and excluded sources. | 2945 # Prepare list of sources and excluded sources. |
| 2946 gyp_path = _NormalizedSource(project.build_file) |
| 2947 relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir) |
| 2948 |
2966 gyp_file = os.path.split(project.build_file)[1] | 2949 gyp_file = os.path.split(project.build_file)[1] |
2967 sources, excluded_sources = _PrepareListOfSources(spec, gyp_file) | 2950 sources, excluded_sources = _PrepareListOfSources(spec, gyp_file) |
2968 # Add rules. | 2951 # Add rules. |
2969 actions_to_add = {} | 2952 actions_to_add = {} |
2970 props_files_of_rules = set() | 2953 props_files_of_rules = set() |
2971 targets_files_of_rules = set() | 2954 targets_files_of_rules = set() |
2972 extension_to_rule_name = {} | 2955 extension_to_rule_name = {} |
2973 list_excluded = generator_flags.get('msvs_list_excluded_files', True) | 2956 list_excluded = generator_flags.get('msvs_list_excluded_files', True) |
2974 _GenerateRulesForMSBuild(project_dir, options, spec, | 2957 _GenerateRulesForMSBuild(project_dir, options, spec, |
2975 sources, excluded_sources, | 2958 sources, excluded_sources, |
2976 props_files_of_rules, targets_files_of_rules, | 2959 props_files_of_rules, targets_files_of_rules, |
2977 actions_to_add, extension_to_rule_name) | 2960 actions_to_add, extension_to_rule_name) |
2978 sources, excluded_sources, excluded_idl = ( | 2961 sources, excluded_sources, excluded_idl = ( |
2979 _AdjustSourcesAndConvertToFilterHierarchy(spec, options, | 2962 _AdjustSourcesAndConvertToFilterHierarchy(spec, options, |
2980 project_dir, sources, | 2963 project_dir, sources, |
2981 excluded_sources, | 2964 excluded_sources, |
2982 list_excluded)) | 2965 list_excluded)) |
2983 _AddActions(actions_to_add, spec, project.build_file, None) | 2966 _AddActions(actions_to_add, spec, project.build_file) |
2984 _AddCopies(actions_to_add, spec) | 2967 _AddCopies(actions_to_add, spec) |
2985 | 2968 |
2986 # NOTE: this stanza must appear after all actions have been decided. | 2969 # NOTE: this stanza must appear after all actions have been decided. |
2987 # Don't excluded sources with actions attached, or they won't run. | 2970 # Don't excluded sources with actions attached, or they won't run. |
2988 excluded_sources = _FilterActionsFromExcluded( | 2971 excluded_sources = _FilterActionsFromExcluded( |
2989 excluded_sources, actions_to_add) | 2972 excluded_sources, actions_to_add) |
2990 | 2973 |
2991 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) | 2974 exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) |
2992 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild( | 2975 actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild( |
2993 spec, actions_to_add) | 2976 spec, actions_to_add) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3121 action_spec.extend( | 3104 action_spec.extend( |
3122 # TODO(jeanluc) 'Document' for all or just if as_sources? | 3105 # TODO(jeanluc) 'Document' for all or just if as_sources? |
3123 [['FileType', 'Document'], | 3106 [['FileType', 'Document'], |
3124 ['Command', command], | 3107 ['Command', command], |
3125 ['Message', description], | 3108 ['Message', description], |
3126 ['Outputs', outputs] | 3109 ['Outputs', outputs] |
3127 ]) | 3110 ]) |
3128 if additional_inputs: | 3111 if additional_inputs: |
3129 action_spec.append(['AdditionalInputs', additional_inputs]) | 3112 action_spec.append(['AdditionalInputs', additional_inputs]) |
3130 actions_spec.append(action_spec) | 3113 actions_spec.append(action_spec) |
OLD | NEW |