25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

115 satır
3.9 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. version_is_pro = version[-1] != 'e'
  30. win8sdk = toolchain_data['win8sdk']
  31. wdk = toolchain_data['wdk']
  32. # TODO(scottmg): The order unfortunately matters in these. They should be
  33. # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call
  34. # below). http://crbug.com/345992
  35. vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs']
  36. os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
  37. os.environ['GYP_MSVS_VERSION'] = version
  38. # We need to make sure windows_sdk_path is set to the automated
  39. # toolchain values in GYP_DEFINES, but don't want to override any
  40. # otheroptions.express
  41. # values there.
  42. gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
  43. gyp_defines_dict['windows_sdk_path'] = win8sdk
  44. os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
  45. for k, v in gyp_defines_dict.iteritems())
  46. os.environ['WINDOWSSDKDIR'] = win8sdk
  47. os.environ['WDK_DIR'] = wdk
  48. # Include the VS runtime in the PATH in case it's not machine-installed.
  49. runtime_path = ';'.join(vs2013_runtime_dll_dirs)
  50. os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
  51. return vs2013_runtime_dll_dirs
  52. def _GetDesiredVsToolchainHashes():
  53. """Load a list of SHA1s corresponding to the toolchains that we want installed
  54. to build with."""
  55. sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash')
  56. with open(sha1path, 'rb') as f:
  57. return f.read().strip().splitlines()
  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. json_data_file = os.path.join(script_dir, 'win_toolchain.json')
  74. get_toolchain_args = [
  75. sys.executable,
  76. os.path.join(depot_tools_path,
  77. 'win_toolchain',
  78. 'get_toolchain_if_necessary.py'),
  79. '--output-json', json_data_file,
  80. ] + _GetDesiredVsToolchainHashes()
  81. subprocess.check_call(get_toolchain_args)
  82. return 0
  83. def main():
  84. if not sys.platform.startswith(('win32', 'cygwin')):
  85. return 0
  86. commands = {
  87. 'update': Update,
  88. }
  89. if len(sys.argv) < 2 or sys.argv[1] not in commands:
  90. print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
  91. return 1
  92. return commands[sys.argv[1]](*sys.argv[2:])
  93. if __name__ == '__main__':
  94. sys.exit(main())