Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

114 řádky
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. TOOLCHAIN_VERSION = '2015'
  15. TOOLCHAIN_HASH = 'd5dc33b15d1b2c086f2f6632e2fd15882f80dbd3'
  16. def SetEnvironmentAndGetRuntimeDllDirs():
  17. """Sets up os.environ to use the depot_tools VS toolchain with gyp, and
  18. returns the location of the VS runtime DLLs so they can be copied into
  19. the output directory after gyp generation.
  20. """
  21. vs_runtime_dll_dirs = None
  22. depot_tools_win_toolchain = \
  23. bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
  24. if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain:
  25. if not os.path.exists(json_data_file):
  26. Update()
  27. with open(json_data_file, 'r') as tempf:
  28. toolchain_data = json.load(tempf)
  29. toolchain = toolchain_data['path']
  30. version = toolchain_data['version']
  31. win_sdk = toolchain_data.get('win_sdk')
  32. if not win_sdk:
  33. win_sdk = toolchain_data['win8sdk']
  34. wdk = toolchain_data['wdk']
  35. # TODO(scottmg): The order unfortunately matters in these. They should be
  36. # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call
  37. # below). http://crbug.com/345992
  38. vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
  39. os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
  40. os.environ['GYP_MSVS_VERSION'] = version
  41. # We need to make sure windows_sdk_path is set to the automated
  42. # toolchain values in GYP_DEFINES, but don't want to override any
  43. # otheroptions.express
  44. # values there.
  45. gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
  46. gyp_defines_dict['windows_sdk_path'] = win_sdk
  47. os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
  48. for k, v in gyp_defines_dict.iteritems())
  49. os.environ['WINDOWSSDKDIR'] = win_sdk
  50. os.environ['WDK_DIR'] = wdk
  51. # Include the VS runtime in the PATH in case it's not machine-installed.
  52. runtime_path = ';'.join(vs_runtime_dll_dirs)
  53. os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
  54. return vs_runtime_dll_dirs
  55. def FindDepotTools():
  56. """Returns the path to depot_tools in $PATH."""
  57. for path in os.environ['PATH'].split(os.pathsep):
  58. if os.path.isfile(os.path.join(path, 'gclient.py')):
  59. return path
  60. raise Exception("depot_tools not found!")
  61. def Update():
  62. """Requests an update of the toolchain to the specific hashes we have at
  63. this revision. The update outputs a .json of the various configuration
  64. information required to pass to gyp which we use in |GetToolchainDir()|.
  65. """
  66. depot_tools_win_toolchain = \
  67. bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
  68. if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain:
  69. depot_tools_path = FindDepotTools()
  70. # Necessary so that get_toolchain_if_necessary.py will put the VS toolkit
  71. # in the correct directory.
  72. os.environ['GYP_MSVS_VERSION'] = TOOLCHAIN_VERSION
  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, TOOLCHAIN_HASH,
  79. ]
  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())