OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Windows can't run .sh files, so this is a Python implementation of | 6 """Windows can't run .sh files, so this is a Python implementation of |
7 update.sh. This script should replace update.sh on all platforms eventually.""" | 7 update.sh. This script should replace update.sh on all platforms eventually.""" |
8 | 8 |
9 import argparse | |
10 import os | 9 import os |
11 import re | 10 import re |
12 import shutil | 11 import shutil |
13 import subprocess | 12 import subprocess |
14 import stat | 13 import stat |
15 import sys | 14 import sys |
16 import time | 15 import time |
17 | 16 |
18 # Do NOT CHANGE this if you don't know what you're doing -- see | 17 # Do NOT CHANGE this if you don't know what you're doing -- see |
19 # https://code.google.com/p/chromium/wiki/UpdatingClang | 18 # https://code.google.com/p/chromium/wiki/UpdatingClang |
20 # Reverting problematic clang rolls is safe, though. | 19 # Reverting problematic clang rolls is safe, though. |
21 # Note: this revision is only used for Windows. Other platforms use update.sh. | 20 # Note: this revision is only used for Windows. Other platforms use update.sh. |
22 LLVM_WIN_REVISION = 'HEAD' | 21 LLVM_WIN_REVISION = 'HEAD' |
23 | 22 |
24 # ASan on Windows is useful enough to use it even while the clang/win is still | 23 # ASan on Windows is useful enough to use it even while the clang/win is still |
25 # in bringup. Use a pinned revision to make it slightly more stable. | 24 # in bringup. Use a pinned revision to make it slightly more stable. |
26 if (re.search(r'\b(asan)=1', os.environ.get('GYP_DEFINES', '')) and | 25 if (re.search(r'\b(asan)=1', os.environ.get('GYP_DEFINES', '')) and |
27 not 'LLVM_FORCE_HEAD_REVISION' in os.environ): | 26 not 'LLVM_FORCE_HEAD_REVISION' in os.environ): |
28 LLVM_WIN_REVISION = '233530' | 27 LLVM_WIN_REVISION = '233530' |
29 | 28 |
30 # Path constants. (All of these should be absolute paths.) | 29 # Path constants. (All of these should be absolute paths.) |
31 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | 30 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
32 CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..')) | 31 CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..')) |
33 LLVM_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm') | 32 LLVM_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm') |
34 CHROME_TOOLS_SHIM_DIR = os.path.join(LLVM_DIR, 'tools', 'chrometools') | |
35 LLVM_BUILD_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm-build', | 33 LLVM_BUILD_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm-build', |
36 'Release+Asserts') | 34 'Release+Asserts') |
37 COMPILER_RT_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, '32bit-compiler-rt') | 35 COMPILER_RT_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, '32bit-compiler-rt') |
38 CLANG_DIR = os.path.join(LLVM_DIR, 'tools', 'clang') | 36 CLANG_DIR = os.path.join(LLVM_DIR, 'tools', 'clang') |
39 LLD_DIR = os.path.join(LLVM_DIR, 'tools', 'lld') | 37 LLD_DIR = os.path.join(LLVM_DIR, 'tools', 'lld') |
40 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'projects', 'compiler-rt') | 38 COMPILER_RT_DIR = os.path.join(LLVM_DIR, 'projects', 'compiler-rt') |
41 STAMP_FILE = os.path.join(LLVM_BUILD_DIR, 'cr_build_revision') | 39 STAMP_FILE = os.path.join(LLVM_BUILD_DIR, 'cr_build_revision') |
42 VERSION = '3.7.0' | 40 VERSION = '3.7.0' |
43 | 41 |
44 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' | 42 LLVM_REPO_URL='https://llvm.org/svn/llvm-project' |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return | 122 return |
125 | 123 |
126 if os.path.isdir(dir): | 124 if os.path.isdir(dir): |
127 print "Removing %s." % (dir) | 125 print "Removing %s." % (dir) |
128 RmTree(dir) | 126 RmTree(dir) |
129 | 127 |
130 print "Retrying." | 128 print "Retrying." |
131 RunCommand(command) | 129 RunCommand(command) |
132 | 130 |
133 | 131 |
134 def DeleteChromeToolsShim(): | |
135 shutil.rmtree(CHROME_TOOLS_SHIM_DIR) | |
136 | |
137 | |
138 def CreateChromeToolsShim(): | |
139 """Hooks the Chrome tools into the LLVM build. | |
140 | |
141 Several Chrome tools have dependencies on LLVM/Clang libraries. The LLVM build | |
142 detects implicit tools in the tools subdirectory, so this helper install a | |
143 shim CMakeLists.txt that forwards to the real directory for the Chrome tools. | |
144 | |
145 Note that the shim directory name intentionally has no - or _. The implicit | |
146 tool detection logic munges them in a weird way.""" | |
147 assert not any(i in os.path.basename(CHROME_TOOLS_SHIM_DIR) for i in '-_') | |
148 os.mkdir(CHROME_TOOLS_SHIM_DIR) | |
149 with file(os.path.join(CHROME_TOOLS_SHIM_DIR, 'CMakeLists.txt'), 'w') as f: | |
150 f.write('# Automatically generated by tools/clang/scripts/update.py. ' + | |
151 'Do not edit.\n') | |
152 f.write('# Since tools/clang is located in another directory, use the \n') | |
153 f.write('# two arg version to specify where build artifacts go. CMake\n') | |
154 f.write('# disallows reuse of the same binary dir for multiple source\n') | |
155 f.write('# dirs, so the build artifacts need to go into a subdirectory.\n') | |
156 f.write('add_subdirectory(${CHROMIUM_TOOLS_SRC} ' + | |
157 '${CMAKE_CURRENT_BINARY_DIR}/a)\n') | |
158 | |
159 | |
160 def AddCMakeToPath(): | 132 def AddCMakeToPath(): |
161 """Look for CMake and add it to PATH if it's not there already.""" | 133 """Look for CMake and add it to PATH if it's not there already.""" |
162 try: | 134 try: |
163 # First check if cmake is already on PATH. | 135 # First check if cmake is already on PATH. |
164 subprocess.call(['cmake', '--version']) | 136 subprocess.call(['cmake', '--version']) |
165 return | 137 return |
166 except OSError as e: | 138 except OSError as e: |
167 if e.errno != os.errno.ENOENT: | 139 if e.errno != os.errno.ENOENT: |
168 raise | 140 raise |
169 | 141 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 # svn.bat in depot_tools will be ignored. | 174 # svn.bat in depot_tools will be ignored. |
203 default_pathext = ('.com', '.exe', '.bat', '.cmd') | 175 default_pathext = ('.com', '.exe', '.bat', '.cmd') |
204 for path in os.environ.get('PATH', '').split(os.pathsep): | 176 for path in os.environ.get('PATH', '').split(os.pathsep): |
205 for ext in default_pathext: | 177 for ext in default_pathext: |
206 candidate = os.path.join(path, 'svn' + ext) | 178 candidate = os.path.join(path, 'svn' + ext) |
207 if os.path.isfile(candidate): | 179 if os.path.isfile(candidate): |
208 return '-DSubversion_SVN_EXECUTABLE=%s' % candidate | 180 return '-DSubversion_SVN_EXECUTABLE=%s' % candidate |
209 return '' | 181 return '' |
210 | 182 |
211 | 183 |
212 def UpdateClang(args): | 184 def UpdateClang(): |
213 print 'Updating Clang to %s...' % (LLVM_WIN_REVISION) | 185 print 'Updating Clang to %s...' % (LLVM_WIN_REVISION) |
214 if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION: | 186 if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION: |
215 print 'Already up to date.' | 187 print 'Already up to date.' |
216 return 0 | 188 return 0 |
217 | 189 |
218 AddCMakeToPath() | 190 AddCMakeToPath() |
219 if args.clobber: | 191 ClobberChromiumBuildFiles() |
220 ClobberChromiumBuildFiles() | |
221 | 192 |
222 # Reset the stamp file in case the build is unsuccessful. | 193 # Reset the stamp file in case the build is unsuccessful. |
223 WriteStampFile('') | 194 WriteStampFile('') |
224 | 195 |
225 DeleteChromeToolsShim(); | |
226 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) | 196 Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) |
227 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) | 197 Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) |
228 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) | 198 Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) |
229 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) | 199 Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) |
230 CreateChromeToolsShim(); | |
231 | 200 |
232 if not os.path.exists(LLVM_BUILD_DIR): | 201 if not os.path.exists(LLVM_BUILD_DIR): |
233 os.makedirs(LLVM_BUILD_DIR) | 202 os.makedirs(LLVM_BUILD_DIR) |
234 os.chdir(LLVM_BUILD_DIR) | 203 os.chdir(LLVM_BUILD_DIR) |
235 | 204 |
236 cmake_args = ['-GNinja', '-DCMAKE_BUILD_TYPE=Release', | |
237 '-DLLVM_ENABLE_ASSERTIONS=ON', SubversionCmakeArg(), | |
238 '-DCHROMIUM_TOOLS_SRC=%s' % os.path.join( | |
239 CHROMIUM_DIR, 'tools', 'clang')] | |
240 if args.tools: | |
241 cmake_args.append('-DCHROMIUM_TOOLS=%s' % ';'.join(args.tools)) | |
242 | |
243 RunCommand(GetVSVersion().SetupScript('x64') + | 205 RunCommand(GetVSVersion().SetupScript('x64') + |
244 ['&&', 'cmake'] + cmake_args + [LLVM_DIR]) | 206 ['&&', 'cmake', '-GNinja', '-DCMAKE_BUILD_TYPE=Release', |
| 207 '-DLLVM_ENABLE_ASSERTIONS=ON', SubversionCmakeArg(), LLVM_DIR]) |
245 RunCommand(GetVSVersion().SetupScript('x64') + ['&&', 'ninja', 'all']) | 208 RunCommand(GetVSVersion().SetupScript('x64') + ['&&', 'ninja', 'all']) |
246 | 209 |
247 # Do an x86 build of compiler-rt to get the 32-bit ASan run-time. | 210 # Do an x86 build of compiler-rt to get the 32-bit ASan run-time. |
248 # TODO(hans): Remove once the regular build above produces this. | 211 # TODO(hans): Remove once the regular build above produces this. |
249 if not os.path.exists(COMPILER_RT_BUILD_DIR): | 212 if not os.path.exists(COMPILER_RT_BUILD_DIR): |
250 os.makedirs(COMPILER_RT_BUILD_DIR) | 213 os.makedirs(COMPILER_RT_BUILD_DIR) |
251 os.chdir(COMPILER_RT_BUILD_DIR) | 214 os.chdir(COMPILER_RT_BUILD_DIR) |
252 RunCommand(GetVSVersion().SetupScript('x86') + | 215 RunCommand(GetVSVersion().SetupScript('x86') + |
253 ['&&', 'cmake'] + cmake_args + [LLVM_DIR]) | 216 ['&&', 'cmake', '-GNinja', '-DCMAKE_BUILD_TYPE=Release', |
| 217 '-DLLVM_ENABLE_ASSERTIONS=ON', LLVM_DIR]) |
254 RunCommand(GetVSVersion().SetupScript('x86') + ['&&', 'ninja', 'compiler-rt']) | 218 RunCommand(GetVSVersion().SetupScript('x86') + ['&&', 'ninja', 'compiler-rt']) |
255 | 219 |
256 # TODO(hans): Make this (and the .gypi and .isolate files) version number | 220 # TODO(hans): Make this (and the .gypi and .isolate files) version number |
257 # independent. | 221 # independent. |
258 asan_rt_lib_src_dir = os.path.join(COMPILER_RT_BUILD_DIR, 'lib', 'clang', | 222 asan_rt_lib_src_dir = os.path.join(COMPILER_RT_BUILD_DIR, 'lib', 'clang', |
259 VERSION, 'lib', 'windows') | 223 VERSION, 'lib', 'windows') |
260 asan_rt_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', | 224 asan_rt_lib_dst_dir = os.path.join(LLVM_BUILD_DIR, 'lib', 'clang', |
261 VERSION, 'lib', 'windows') | 225 VERSION, 'lib', 'windows') |
262 CopyDirectoryContents(asan_rt_lib_src_dir, asan_rt_lib_dst_dir, | 226 CopyDirectoryContents(asan_rt_lib_src_dir, asan_rt_lib_dst_dir, |
263 r'^.*-i386\.lib$') | 227 r'^.*-i386\.lib$') |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 stderr=os.fdopen(os.dup(sys.stdin.fileno()))) | 269 stderr=os.fdopen(os.dup(sys.stdin.fileno()))) |
306 | 270 |
307 if not re.search(r'\b(clang|asan)=1', os.environ.get('GYP_DEFINES', '')): | 271 if not re.search(r'\b(clang|asan)=1', os.environ.get('GYP_DEFINES', '')): |
308 print 'Skipping Clang update (clang=1 was not set in GYP_DEFINES).' | 272 print 'Skipping Clang update (clang=1 was not set in GYP_DEFINES).' |
309 return 0 | 273 return 0 |
310 | 274 |
311 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): | 275 if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): |
312 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' | 276 print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' |
313 return 0 | 277 return 0 |
314 | 278 |
315 parser = argparse.ArgumentParser(description='Build Clang.') | 279 return UpdateClang() |
316 parser.add_argument('--no-clobber', dest='clobber', action='store_false') | |
317 parser.add_argument('--tools', nargs='*') | |
318 return UpdateClang(parser.parse_args()) | |
319 | 280 |
320 | 281 |
321 if __name__ == '__main__': | 282 if __name__ == '__main__': |
322 sys.exit(main()) | 283 sys.exit(main()) |
OLD | NEW |