def _FinalizeMSBuildSettings(spec, configuration):
  if 'msbuild_settings' in configuration:
    converted = False
    msbuild_settings = configuration['msbuild_settings']
    MSVSSettings.ValidateMSBuildSettings(msbuild_settings)
  else:
    converted = True
    msvs_settings = configuration.get('msvs_settings', {})
    msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(msvs_settings)
  include_dirs, midl_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
    defines = [d for d in defines if d != '_HAS_TR1=0']
    # Warn of ignored settings
    ignored_settings = ['msvs_tool_files']
    for ignored_setting in ignored_settings:
      value = configuration.get(ignored_setting)
      if value:
        print ('Warning: The automatic conversion to MSBuild does not handle '
               '%s.  Ignoring setting of %s' % (ignored_setting, str(value)))

  defines = [_EscapeCppDefineForMSBuild(d) for d in defines]
  disabled_warnings = _GetDisabledWarnings(configuration)
  prebuild = configuration.get('msvs_prebuild')
  postbuild = configuration.get('msvs_postbuild')
  def_file = _GetModuleDefinition(spec)
  precompiled_header = configuration.get('msvs_precompiled_header')

  # Add the information to the appropriate tool
  # TODO(jeanluc) We could optimize and generate these settings only if
  # the corresponding files are found, e.g. don't generate ResourceCompile
  # if you don't have any resources.
  _ToolAppend(msbuild_settings, 'ClCompile',
              'AdditionalIncludeDirectories', include_dirs)
  _ToolAppend(msbuild_settings, 'Midl',
              'AdditionalIncludeDirectories', midl_include_dirs)
  _ToolAppend(msbuild_settings, 'ResourceCompile',
              'AdditionalIncludeDirectories', resource_include_dirs)
  # Add in libraries, note that even for empty libraries, we want this
  # 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)
  _ToolAppend(msbuild_settings, 'ResourceCompile',
              'PreprocessorDefinitions', defines)
  # Add disabled warnings.
  _ToolAppend(msbuild_settings, 'ClCompile',
              'DisableSpecificWarnings', disabled_warnings)
  # Turn on precompiled headers if appropriate.
  if precompiled_header:
    precompiled_header = os.path.split(precompiled_header)[1]
    _ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeader', 'Use')
    _ToolAppend(msbuild_settings, 'ClCompile',
                'PrecompiledHeaderFile', precompiled_header)
    _ToolAppend(msbuild_settings, 'ClCompile',
                'ForcedIncludeFiles', [precompiled_header])
  else:
    _ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeader', 'NotUsing')
  # Turn off WinRT compilation
  _ToolAppend(msbuild_settings, 'ClCompile', 'CompileAsWinRT', 'false')
  # Turn on import libraries if appropriate
  if spec.get('msvs_requires_importlibrary'):
   _ToolAppend(msbuild_settings, '', 'IgnoreImportLibrary', 'false')
  # Loadable modules don't generate import libraries;
  # tell dependent projects to not expect one.
  if spec['type'] == 'loadable_module':
    _ToolAppend(msbuild_settings, '', 'IgnoreImportLibrary', 'true')
  # Set the module definition file if any.
  if def_file:
    _ToolAppend(msbuild_settings, 'Link', 'ModuleDefinitionFile', def_file)
  configuration['finalized_msbuild_settings'] = msbuild_settings
  if prebuild:
    _ToolAppend(msbuild_settings, 'PreBuildEvent', 'Command', prebuild)
  if postbuild:
    _ToolAppend(msbuild_settings, 'PostBuildEvent', 'Command', postbuild)
dataset/ETHPy150Open adblockplus/gyp/pylib/gyp/generator/msvs.py/_FinalizeMSBuildSettings/original