OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 import os | 6 import os |
7 import pipes | 7 import pipes |
8 import shutil | 8 import shutil |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 import tempfile | |
12 | 11 |
13 | 12 |
14 script_dir = os.path.dirname(os.path.realpath(__file__)) | 13 script_dir = os.path.dirname(os.path.realpath(__file__)) |
15 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | 14 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
16 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 15 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
17 sys.path.insert(1, os.path.join(chrome_src, 'tools')) | 16 sys.path.insert(1, os.path.join(chrome_src, 'tools')) |
18 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 17 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
| 18 json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
19 | 19 |
20 | 20 |
21 import gyp | 21 import gyp |
22 | 22 |
23 | 23 |
24 def GetDesiredVsToolchainHashes(): | 24 def SetEnvironmentAndGetRuntimeDllDirs(): |
25 """Load a list of SHA1s corresponding to the toolchains that we want installed | 25 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and |
26 to build with.""" | 26 returns the location of the VS runtime DLLs so they can be copied into |
27 sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') | 27 the output directory after gyp generation. |
28 with open(sha1path, 'rb') as f: | |
29 return f.read().strip().splitlines() | |
30 | |
31 | |
32 def DownloadVsToolchain(): | |
33 """Download the Visual Studio toolchain on Windows. | |
34 | |
35 If on Windows, request that depot_tools install/update the automatic | |
36 toolchain, and then use it (unless opted-out) and return a tuple containing | |
37 the x64 and x86 paths. Otherwise return None. | |
38 """ | 28 """ |
39 vs2013_runtime_dll_dirs = None | 29 vs2013_runtime_dll_dirs = None |
40 depot_tools_win_toolchain = \ | 30 depot_tools_win_toolchain = \ |
41 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 31 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
42 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: | 32 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: |
43 import find_depot_tools | 33 with open(json_data_file, 'r') as tempf: |
44 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | |
45 temp_handle, data_file = tempfile.mkstemp(suffix='.json') | |
46 os.close(temp_handle) | |
47 get_toolchain_args = [ | |
48 sys.executable, | |
49 os.path.join(depot_tools_path, | |
50 'win_toolchain', | |
51 'get_toolchain_if_necessary.py'), | |
52 '--output-json', data_file, | |
53 ] + GetDesiredVsToolchainHashes() | |
54 subprocess.check_call(get_toolchain_args) | |
55 | |
56 with open(data_file, 'r') as tempf: | |
57 toolchain_data = json.load(tempf) | 34 toolchain_data = json.load(tempf) |
58 os.unlink(data_file) | |
59 | 35 |
60 toolchain = toolchain_data['path'] | 36 toolchain = toolchain_data['path'] |
61 version = toolchain_data['version'] | 37 version = toolchain_data['version'] |
62 version_is_pro = version[-1] != 'e' | 38 version_is_pro = version[-1] != 'e' |
63 win8sdk = toolchain_data['win8sdk'] | 39 win8sdk = toolchain_data['win8sdk'] |
64 wdk = toolchain_data['wdk'] | 40 wdk = toolchain_data['wdk'] |
65 # TODO(scottmg): The order unfortunately matters in these. They should be | 41 # TODO(scottmg): The order unfortunately matters in these. They should be |
66 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call | 42 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call |
67 # below). http://crbug.com/345992 | 43 # below). http://crbug.com/345992 |
68 vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs'] | 44 vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs'] |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): | 101 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): |
126 os.makedirs(out_release_nacl64) | 102 os.makedirs(out_release_nacl64) |
127 copy_runtime(out_debug, x86, 'msvc%s120d.dll') | 103 copy_runtime(out_debug, x86, 'msvc%s120d.dll') |
128 copy_runtime(out_release, x86, 'msvc%s120.dll') | 104 copy_runtime(out_release, x86, 'msvc%s120.dll') |
129 copy_runtime(out_debug_x64, x64, 'msvc%s120d.dll') | 105 copy_runtime(out_debug_x64, x64, 'msvc%s120d.dll') |
130 copy_runtime(out_release_x64, x64, 'msvc%s120.dll') | 106 copy_runtime(out_release_x64, x64, 'msvc%s120.dll') |
131 copy_runtime(out_debug_nacl64, x64, 'msvc%s120d.dll') | 107 copy_runtime(out_debug_nacl64, x64, 'msvc%s120d.dll') |
132 copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll') | 108 copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll') |
133 | 109 |
134 | 110 |
135 def main(): | 111 def _GetDesiredVsToolchainHashes(): |
136 if len(sys.argv) < 2: | 112 """Load a list of SHA1s corresponding to the toolchains that we want installed |
137 print >>sys.stderr, 'Expected either "get_toolchain_dir" or "copy_dlls"' | 113 to build with.""" |
138 return 1 | 114 sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') |
139 if sys.argv[1] == 'get_toolchain_dir': | 115 with open(sha1path, 'rb') as f: |
140 DownloadVsToolchain() | 116 return f.read().strip().splitlines() |
141 print '["%s", "%s"]' % ( | 117 |
142 os.environ['GYP_MSVS_OVERRIDE_PATH'], os.environ['WINDOWSSDKDIR']) | 118 |
143 else: | 119 def Update(): |
144 print >>sys.stderr, 'TODO: not implemented "%s"' % sys.argv[1] | 120 """Requests an update of the toolchain to the specific hashes we have at |
145 return 1 | 121 this revision. The update outputs a .json of the various configuration |
| 122 information required to pass to gyp which we use in |GetToolchainDir()|. |
| 123 """ |
| 124 depot_tools_win_toolchain = \ |
| 125 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
| 126 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: |
| 127 import find_depot_tools |
| 128 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| 129 json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
| 130 get_toolchain_args = [ |
| 131 sys.executable, |
| 132 os.path.join(depot_tools_path, |
| 133 'win_toolchain', |
| 134 'get_toolchain_if_necessary.py'), |
| 135 '--output-json', json_data_file, |
| 136 ] + _GetDesiredVsToolchainHashes() |
| 137 subprocess.check_call(get_toolchain_args) |
| 138 |
146 return 0 | 139 return 0 |
147 | 140 |
148 | 141 |
| 142 def GetToolchainDir(): |
| 143 """Gets location information about the current toolchain (must have been |
| 144 previously updated by 'update').""" |
| 145 SetEnvironmentAndGetRuntimeDllDirs() |
| 146 print '["%s", "%s"]' % ( |
| 147 os.environ['GYP_MSVS_OVERRIDE_PATH'], os.environ['WINDOWSSDKDIR']) |
| 148 |
| 149 |
| 150 def main(): |
| 151 if not sys.platform.startswith(('win32', 'cygwin')): |
| 152 return 0 |
| 153 commands = { |
| 154 'update': Update, |
| 155 'get_toolchain_dir': GetToolchainDir, |
| 156 # TODO(scottmg): Add copy_dlls for GN builds (gyp_chromium calls |
| 157 # CopyVsRuntimeDlls via import, currently). |
| 158 } |
| 159 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
| 160 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
| 161 return 1 |
| 162 return commands[sys.argv[1]]() |
| 163 |
| 164 |
149 if __name__ == '__main__': | 165 if __name__ == '__main__': |
150 sys.exit(main()) | 166 sys.exit(main()) |
OLD | NEW |