diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-11-10 15:15:34 -0800 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-11-10 15:15:34 -0800 |
commit | 201098535443ef6588b0fd176a425fdf3213ee70 (patch) | |
tree | 3259766e34c4a70f087c0ea52c16e0bc74eb11a7 /tools/gyp/pylib/gyp/generator/msvs.py | |
parent | 3dcc9b93e1e4d80aa15a40a9d82a6b9f0bef0ec0 (diff) | |
download | android-node-v8-201098535443ef6588b0fd176a425fdf3213ee70.tar.gz android-node-v8-201098535443ef6588b0fd176a425fdf3213ee70.tar.bz2 android-node-v8-201098535443ef6588b0fd176a425fdf3213ee70.zip |
gyp: update to bebdcea
Diffstat (limited to 'tools/gyp/pylib/gyp/generator/msvs.py')
-rw-r--r-- | tools/gyp/pylib/gyp/generator/msvs.py | 205 |
1 files changed, 176 insertions, 29 deletions
diff --git a/tools/gyp/pylib/gyp/generator/msvs.py b/tools/gyp/pylib/gyp/generator/msvs.py index 51acf2eb3e..2f2c3cffd6 100644 --- a/tools/gyp/pylib/gyp/generator/msvs.py +++ b/tools/gyp/pylib/gyp/generator/msvs.py @@ -66,6 +66,10 @@ generator_additional_non_configuration_keys = [ 'msvs_cygwin_shell', 'msvs_large_pdb', 'msvs_shard', + 'msvs_external_builder', + 'msvs_external_builder_out_dir', + 'msvs_external_builder_build_cmd', + 'msvs_external_builder_clean_cmd', ] @@ -221,7 +225,7 @@ def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False): tool = tools[tool_name] if tool.get(setting): if only_if_unset: return - if type(tool[setting]) == list: + if type(tool[setting]) == list and type(value) == list: tool[setting] += value else: raise TypeError( @@ -459,8 +463,7 @@ def _FindRuleTriggerFiles(rule, sources): Returns: The list of sources that trigger a particular rule. """ - rule_ext = rule['extension'] - return [s for s in sources if s.endswith('.' + rule_ext)] + return rule.get('rule_sources', []) def _RuleInputsAndOutputs(rule, trigger_file): @@ -784,10 +787,10 @@ def _GenerateRulesForMSVS(p, output_dir, options, spec, if rules_external: _GenerateExternalRules(rules_external, output_dir, spec, sources, options, actions_to_add) - _AdjustSourcesForRules(rules, sources, excluded_sources) + _AdjustSourcesForRules(spec, rules, sources, excluded_sources) -def _AdjustSourcesForRules(rules, sources, excluded_sources): +def _AdjustSourcesForRules(spec, rules, sources, excluded_sources): # Add outputs generated by each rule (if applicable). for rule in rules: # Done if not processing outputs as sources. @@ -800,7 +803,8 @@ def _AdjustSourcesForRules(rules, sources, excluded_sources): outputs = set(_FixPaths(outputs)) inputs.remove(_FixPath(trigger_file)) sources.update(inputs) - excluded_sources.update(inputs) + if not spec.get('msvs_external_builder'): + excluded_sources.update(inputs) sources.update(outputs) @@ -1027,12 +1031,13 @@ def _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config): spec: The target dictionary containing the properties of the target. config_type: The configuration type, a number as defined by Microsoft. config_name: The name of the configuration. - config: The dictionnary that defines the special processing to be done + config: The dictionary that defines the special processing to be done for this configuration. """ # Get the information for this configuration include_dirs, resource_include_dirs = _GetIncludeDirs(config) libraries = _GetLibraries(spec) + library_dirs = _GetLibraryDirs(config) out_file, vc_tool, _ = _GetOutputFilePathAndTool(spec, msbuild=False) defines = _GetDefines(config) defines = [_EscapeCppDefineForMSVS(d) for d in defines] @@ -1062,6 +1067,8 @@ def _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config): 'AdditionalIncludeDirectories', resource_include_dirs) # Add in libraries. _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', libraries) + _ToolAppend(tools, 'VCLinkerTool', 'AdditionalLibraryDirectories', + library_dirs) if out_file: _ToolAppend(tools, vc_tool, 'OutputFile', out_file, only_if_unset=True) # Add defines. @@ -1101,7 +1108,7 @@ def _GetIncludeDirs(config): """Returns the list of directories to be used for #include directives. Arguments: - config: The dictionnary that defines the special processing to be done + config: The dictionary that defines the special processing to be done for this configuration. Returns: The list of directory paths. @@ -1117,6 +1124,21 @@ def _GetIncludeDirs(config): return include_dirs, resource_include_dirs +def _GetLibraryDirs(config): + """Returns the list of directories to be used for library search paths. + + Arguments: + config: The dictionary that defines the special processing to be done + for this configuration. + Returns: + The list of directory paths. + """ + + library_dirs = config.get('library_dirs', []) + library_dirs = _FixPaths(library_dirs) + return library_dirs + + def _GetLibraries(spec): """Returns the list of libraries for this configuration. @@ -1181,11 +1203,29 @@ def _GetOutputFilePathAndTool(spec, msbuild): return out_file, vc_tool, msbuild_tool +def _GetOutputTargetExt(spec): + """Returns the extension for this target, including the dot + + If product_extension is specified, set target_extension to this to avoid + MSB8012, returns None otherwise. Ignores any target_extension settings in + the input files. + + Arguments: + spec: The target dictionary containing the properties of the target. + Returns: + A string with the extension, or None + """ + target_extension = spec.get('product_extension') + if target_extension: + return '.' + target_extension + return None + + def _GetDefines(config): """Returns the list of preprocessor definitions for this configuation. Arguments: - config: The dictionnary that defines the special processing to be done + config: The dictionary that defines the special processing to be done for this configuration. Returns: The list of preprocessor definitions. @@ -1222,7 +1262,7 @@ def _ConvertToolsToExpectedForm(tools): """Convert tools to a form expected by Visual Studio. Arguments: - tools: A dictionnary of settings; the tool name is the key. + tools: A dictionary of settings; the tool name is the key. Returns: A list of Tool objects. """ @@ -1251,8 +1291,8 @@ def _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name): Arguments: p: The target project being generated. spec: the target project dict. - tools: A dictionnary of settings; the tool name is the key. - config: The dictionnary that defines the special processing to be done + tools: A dictionary of settings; the tool name is the key. + config: The dictionary that defines the special processing to be done for this configuration. config_type: The configuration type, a number as defined by Microsoft. config_name: The name of the configuration. @@ -1324,7 +1364,8 @@ def _PrepareListOfSources(spec, generator_flags, gyp_file): # Add all inputs to sources and excluded sources. inputs = set(inputs) sources.update(inputs) - excluded_sources.update(inputs) + if not spec.get('msvs_external_builder'): + excluded_sources.update(inputs) if int(a.get('process_outputs_as_sources', False)): _AddNormalizedSources(sources, a.get('outputs', [])) # Add in 'copies' inputs and outputs. @@ -1695,14 +1736,58 @@ def _CreateProjectObjects(target_list, target_dicts, options, msvs_version): obj.set_msbuild_toolset( _GetMsbuildToolsetOfProject(proj_path, spec, msvs_version)) projects[qualified_target] = obj - # Set all the dependencies + # Set all the dependencies, but not if we are using an external builder like + # ninja for project in projects.values(): - deps = project.spec.get('dependencies', []) - deps = [projects[d] for d in deps] - project.set_dependencies(deps) + if not project.spec.get('msvs_external_builder'): + deps = project.spec.get('dependencies', []) + deps = [projects[d] for d in deps] + project.set_dependencies(deps) return projects +def _InitNinjaFlavor(options, target_list, target_dicts): + """Initialize targets for the ninja flavor. + + This sets up the necessary variables in the targets to generate msvs projects + that use ninja as an external builder. The variables in the spec are only set + if they have not been set. This allows individual specs to override the + default values initialized here. + Arguments: + options: Options provided to the generator. + target_list: List of target pairs: 'base/base.gyp:base'. + target_dicts: Dict of target properties keyed on target pair. + """ + for qualified_target in target_list: + spec = target_dicts[qualified_target] + if spec.get('msvs_external_builder'): + # The spec explicitly defined an external builder, so don't change it. + continue + + path_to_ninja = spec.get('msvs_path_to_ninja', 'ninja.exe') + + spec['msvs_external_builder'] = 'ninja' + if not spec.get('msvs_external_builder_out_dir'): + spec['msvs_external_builder_out_dir'] = \ + options.depth + '/out/$(Configuration)' + if not spec.get('msvs_external_builder_build_cmd'): + spec['msvs_external_builder_build_cmd'] = [ + path_to_ninja, + '-C', + '$(OutDir)', + '$(ProjectName)', + ] + if not spec.get('msvs_external_builder_clean_cmd'): + spec['msvs_external_builder_clean_cmd'] = [ + path_to_ninja, + '-C', + '$(OutDir)', + '-t', + 'clean', + '$(ProjectName)', + ] + + def CalculateVariables(default_variables, params): """Generated variables that require params to be known.""" @@ -1727,6 +1812,9 @@ def CalculateVariables(default_variables, params): else: default_variables['MSVS_OS_BITS'] = 32 + if gyp.common.GetFlavor(params) == 'ninja': + default_variables['SHARED_INTERMEDIATE_DIR'] = '$(OutDir)gen' + def PerformBuild(data, configurations, params): options = params['options'] @@ -1774,6 +1862,10 @@ def GenerateOutput(target_list, target_dicts, data, params): (target_list, target_dicts) = MSVSUtil.InsertLargePdbShims( target_list, target_dicts, generator_default_variables) + # Optionally configure each spec to use ninja as the external builder. + if params.get('flavor') == 'ninja': + _InitNinjaFlavor(options, target_list, target_dicts) + # Prepare the set of configurations. configs = set() for qualified_target in target_list: @@ -1964,7 +2056,7 @@ def _GenerateRulesForMSBuild(output_dir, options, spec, if rules_external: _GenerateExternalRules(rules_external, output_dir, spec, sources, options, actions_to_add) - _AdjustSourcesForRules(rules, sources, excluded_sources) + _AdjustSourcesForRules(spec, rules, sources, excluded_sources) class MSBuildRule(object): @@ -2560,6 +2652,10 @@ def _GetMSBuildAttributes(spec, config, build_file): target_name = prefix + product_name msbuild_attributes['TargetName'] = target_name + if spec.get('msvs_external_builder'): + external_out_dir = spec.get('msvs_external_builder_out_dir', '.') + msbuild_attributes['OutputDirectory'] = _FixPath(external_out_dir) + '\\' + # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile' # (depending on the tool used) to avoid MSB8012 warning. msbuild_tool_map = { @@ -2574,6 +2670,9 @@ def _GetMSBuildAttributes(spec, config, build_file): out_file = msbuild_settings[msbuild_tool].get('OutputFile') if out_file: msbuild_attributes['TargetPath'] = _FixPath(out_file) + target_ext = msbuild_settings[msbuild_tool].get('TargetExt') + if target_ext: + msbuild_attributes['TargetExt'] = target_ext return msbuild_attributes @@ -2609,6 +2708,9 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file): if attributes.get('TargetPath'): _AddConditionalProperty(properties, condition, 'TargetPath', attributes['TargetPath']) + if attributes.get('TargetExt'): + _AddConditionalProperty(properties, condition, 'TargetExt', + attributes['TargetExt']) if new_paths: _AddConditionalProperty(properties, condition, 'ExecutablePath', @@ -2727,7 +2829,9 @@ def _FinalizeMSBuildSettings(spec, configuration): msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(msvs_settings) include_dirs, resource_include_dirs = _GetIncludeDirs(configuration) libraries = _GetLibraries(spec) + library_dirs = _GetLibraryDirs(configuration) out_file, _, msbuild_tool = _GetOutputFilePathAndTool(spec, msbuild=True) + target_ext = _GetOutputTargetExt(spec) defines = _GetDefines(configuration) if converted: # Visual Studio 2010 has TR1 @@ -2760,9 +2864,14 @@ def _FinalizeMSBuildSettings(spec, configuration): # set, to prevent inheriting default libraries from the enviroment. _ToolSetOrAppend(msbuild_settings, 'Link', 'AdditionalDependencies', libraries) + _ToolAppend(msbuild_settings, 'Link', 'AdditionalLibraryDirectories', + library_dirs) if out_file: _ToolAppend(msbuild_settings, msbuild_tool, 'OutputFile', out_file, only_if_unset=True) + if target_ext: + _ToolAppend(msbuild_settings, msbuild_tool, 'TargetExt', target_ext, + only_if_unset=True) # Add defines. _ToolAppend(msbuild_settings, 'ClCompile', 'PreprocessorDefinitions', defines) @@ -2778,7 +2887,7 @@ def _FinalizeMSBuildSettings(spec, configuration): _ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeaderFile', precompiled_header) _ToolAppend(msbuild_settings, 'ClCompile', - 'ForcedIncludeFiles', precompiled_header) + 'ForcedIncludeFiles', [precompiled_header]) # Loadable modules don't generate import libraries; # tell dependent projects to not expect one. if spec['type'] == 'loadable_module': @@ -2958,22 +3067,32 @@ def _GenerateMSBuildProject(project, options, version, generator_flags): targets_files_of_rules = set() extension_to_rule_name = {} list_excluded = generator_flags.get('msvs_list_excluded_files', True) - _GenerateRulesForMSBuild(project_dir, options, spec, - sources, excluded_sources, - props_files_of_rules, targets_files_of_rules, - actions_to_add, extension_to_rule_name) + + # Don't generate rules if we are using an external builder like ninja. + if not spec.get('msvs_external_builder'): + _GenerateRulesForMSBuild(project_dir, options, spec, + sources, excluded_sources, + props_files_of_rules, targets_files_of_rules, + actions_to_add, extension_to_rule_name) + else: + rules = spec.get('rules', []) + _AdjustSourcesForRules(spec, rules, sources, excluded_sources) + sources, excluded_sources, excluded_idl = ( _AdjustSourcesAndConvertToFilterHierarchy(spec, options, project_dir, sources, excluded_sources, list_excluded)) - _AddActions(actions_to_add, spec, project.build_file) - _AddCopies(actions_to_add, spec) - # NOTE: this stanza must appear after all actions have been decided. - # Don't excluded sources with actions attached, or they won't run. - excluded_sources = _FilterActionsFromExcluded( - excluded_sources, actions_to_add) + # Don't add actions if we are using an external builder like ninja. + if not spec.get('msvs_external_builder'): + _AddActions(actions_to_add, spec, project.build_file) + _AddCopies(actions_to_add, spec) + + # NOTE: this stanza must appear after all actions have been decided. + # Don't excluded sources with actions attached, or they won't run. + excluded_sources = _FilterActionsFromExcluded( + excluded_sources, actions_to_add) exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl) actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild( @@ -3022,6 +3141,9 @@ def _GenerateMSBuildProject(project, options, version, generator_flags): content += import_cpp_targets_section content += _GetMSBuildExtensionTargets(targets_files_of_rules) + if spec.get('msvs_external_builder'): + content += _GetMSBuildExternalBuilderTargets(spec) + # TODO(jeanluc) File a bug to get rid of runas. We had in MSVS: # has_run_as = _WriteMSVSUserFile(project.path, version, spec) @@ -3030,6 +3152,31 @@ def _GenerateMSBuildProject(project, options, version, generator_flags): return missing_sources +def _GetMSBuildExternalBuilderTargets(spec): + """Return a list of MSBuild targets for external builders. + + Right now, only "Build" and "Clean" targets are generated. + + Arguments: + spec: The gyp target spec. + Returns: + List of MSBuild 'Target' specs. + """ + build_cmd = _BuildCommandLineForRuleRaw( + spec, spec['msvs_external_builder_build_cmd'], + False, False, False, False) + build_target = ['Target', {'Name': 'Build'}] + build_target.append(['Exec', {'Command': build_cmd}]) + + clean_cmd = _BuildCommandLineForRuleRaw( + spec, spec['msvs_external_builder_clean_cmd'], + False, False, False, False) + clean_target = ['Target', {'Name': 'Clean'}] + clean_target.append(['Exec', {'Command': clean_cmd}]) + + return [build_target, clean_target] + + def _GetMSBuildExtensions(props_files_of_rules): extensions = ['ImportGroup', {'Label': 'ExtensionSettings'}] for props_file in props_files_of_rules: |