You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 line
3.8 KiB

  1. # Copyright 2014 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import json
  5. import os
  6. import pipes
  7. import shutil
  8. import subprocess
  9. import sys
  10. script_dir = os.path.dirname(os.path.realpath(__file__))
  11. sys.path.insert(0, os.path.join(script_dir, 'gyp', 'pylib'))
  12. json_data_file = os.path.join(script_dir, 'win_toolchain.json')
  13. import gyp
  14. def SetEnvironmentAndGetRuntimeDllDirs():
  15. """Sets up os.environ to use the depot_tools VS toolchain with gyp, and
  16. returns the location of the VS runtime DLLs so they can be copied into
  17. the output directory after gyp generation.
  18. """
  19. vs2013_runtime_dll_dirs = None
  20. depot_tools_win_toolchain = \
  21. bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
  22. if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain:
  23. if not os.path.exists(json_data_file):
  24. Update()
  25. with open(json_data_file, 'r') as tempf:
  26. toolchain_data = json.load(tempf)
  27. toolchain = toolchain_data['path']
  28. version = toolchain_data['version']
  29. win_sdk = toolchain_data.get('win_sdk')
  30. if not win_sdk:
  31. win_sdk = toolchain_data['win8sdk']
  32. wdk = toolchain_data['wdk']
  33. # TODO(scottmg): The order unfortunately matters in these. They should be
  34. # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call
  35. # below). http://crbug.com/345992
  36. vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs']
  37. os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
  38. os.environ['GYP_MSVS_VERSION'] = version
  39. # We need to make sure windows_sdk_path is set to the automated
  40. # toolchain values in GYP_DEFINES, but don't want to override any
  41. # otheroptions.express
  42. # values there.
  43. gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
  44. gyp_defines_dict['windows_sdk_path'] = win_sdk
  45. os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
  46. for k, v in gyp_defines_dict.iteritems())
  47. os.environ['WINDOWSSDKDIR'] = win_sdk
  48. os.environ['WDK_DIR'] = wdk
  49. # Include the VS runtime in the PATH in case it's not machine-installed.
  50. runtime_path = ';'.join(vs2013_runtime_dll_dirs)
  51. os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
  52. return vs2013_runtime_dll_dirs
  53. def _GetDesiredVsToolchainHashes():
  54. """Load a list of SHA1s corresponding to the toolchains that we want installed
  55. to build with."""
  56. # Use Chromium's VS2013.
  57. return ['ee7d718ec60c2dc5d255bbe325909c2021a7efef']
  58. def FindDepotTools():
  59. """Returns the path to depot_tools in $PATH."""
  60. for path in os.environ['PATH'].split(os.pathsep):
  61. if os.path.isfile(os.path.join(path, 'gclient.py')):
  62. return path
  63. raise Exception("depot_tools not found!")
  64. def Update():
  65. """Requests an update of the toolchain to the specific hashes we have at
  66. this revision. The update outputs a .json of the various configuration
  67. information required to pass to gyp which we use in |GetToolchainDir()|.
  68. """
  69. depot_tools_win_toolchain = \
  70. bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
  71. if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain:
  72. depot_tools_path = FindDepotTools()
  73. get_toolchain_args = [
  74. sys.executable,
  75. os.path.join(depot_tools_path,
  76. 'win_toolchain',
  77. 'get_toolchain_if_necessary.py'),
  78. '--output-json', json_data_file,
  79. ] + _GetDesiredVsToolchainHashes()
  80. subprocess.check_call(get_toolchain_args)
  81. return 0
  82. def main():
  83. if not sys.platform.startswith(('win32', 'cygwin')):
  84. return 0
  85. commands = {
  86. 'update': Update,
  87. }
  88. if len(sys.argv) < 2 or sys.argv[1] not in commands:
  89. print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
  90. return 1
  91. return commands[sys.argv[1]](*sys.argv[2:])
  92. if __name__ == '__main__':
  93. sys.exit(main())