Commit 8caa594c authored by dcheng's avatar dcheng Committed by Commit bot

Add the ability to build Chrome tools to the Win Clang build script.

BUG=424436,467287

Committed: https://crrev.com/475949d9430b6a759ce759f2133dd3a1577d0d0b
Cr-Commit-Position: refs/heads/master@{#324089}

Review URL: https://codereview.chromium.org/1068603002

Cr-Commit-Position: refs/heads/master@{#324164}
parent c3a23f04
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
"""Windows can't run .sh files, so this is a Python implementation of """Windows can't run .sh files, so this is a Python implementation of
update.sh. This script should replace update.sh on all platforms eventually.""" update.sh. This script should replace update.sh on all platforms eventually."""
import argparse
import os import os
import re import re
import shutil import shutil
...@@ -30,6 +31,7 @@ if (re.search(r'\b(asan)=1', os.environ.get('GYP_DEFINES', '')) and ...@@ -30,6 +31,7 @@ if (re.search(r'\b(asan)=1', os.environ.get('GYP_DEFINES', '')) and
THIS_DIR = os.path.abspath(os.path.dirname(__file__)) THIS_DIR = os.path.abspath(os.path.dirname(__file__))
CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..')) CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..'))
LLVM_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm') LLVM_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm')
CHROME_TOOLS_SHIM_DIR = os.path.join(LLVM_DIR, 'tools', 'chrometools')
LLVM_BUILD_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm-build', LLVM_BUILD_DIR = os.path.join(CHROMIUM_DIR, 'third_party', 'llvm-build',
'Release+Asserts') 'Release+Asserts')
COMPILER_RT_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, '32bit-compiler-rt') COMPILER_RT_BUILD_DIR = os.path.join(LLVM_BUILD_DIR, '32bit-compiler-rt')
...@@ -129,6 +131,32 @@ def Checkout(name, url, dir): ...@@ -129,6 +131,32 @@ def Checkout(name, url, dir):
RunCommand(command) RunCommand(command)
def DeleteChromeToolsShim():
shutil.rmtree(CHROME_TOOLS_SHIM_DIR)
def CreateChromeToolsShim():
"""Hooks the Chrome tools into the LLVM build.
Several Chrome tools have dependencies on LLVM/Clang libraries. The LLVM build
detects implicit tools in the tools subdirectory, so this helper install a
shim CMakeLists.txt that forwards to the real directory for the Chrome tools.
Note that the shim directory name intentionally has no - or _. The implicit
tool detection logic munges them in a weird way."""
assert not any(i in os.path.basename(CHROME_TOOLS_SHIM_DIR) for i in '-_')
os.mkdir(CHROME_TOOLS_SHIM_DIR)
with file(os.path.join(CHROME_TOOLS_SHIM_DIR, 'CMakeLists.txt'), 'w') as f:
f.write('# Automatically generated by tools/clang/scripts/update.py. ' +
'Do not edit.\n')
f.write('# Since tools/clang is located in another directory, use the \n')
f.write('# two arg version to specify where build artifacts go. CMake\n')
f.write('# disallows reuse of the same binary dir for multiple source\n')
f.write('# dirs, so the build artifacts need to go into a subdirectory.\n')
f.write('add_subdirectory(${CHROMIUM_TOOLS_SRC} ' +
'${CMAKE_CURRENT_BINARY_DIR}/a)\n')
def AddCMakeToPath(): def AddCMakeToPath():
"""Look for CMake and add it to PATH if it's not there already.""" """Look for CMake and add it to PATH if it's not there already."""
try: try:
...@@ -181,30 +209,39 @@ def SubversionCmakeArg(): ...@@ -181,30 +209,39 @@ def SubversionCmakeArg():
return '' return ''
def UpdateClang(): def UpdateClang(args):
print 'Updating Clang to %s...' % (LLVM_WIN_REVISION) print 'Updating Clang to %s...' % (LLVM_WIN_REVISION)
if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION: if LLVM_WIN_REVISION != 'HEAD' and ReadStampFile() == LLVM_WIN_REVISION:
print 'Already up to date.' print 'Already up to date.'
return 0 return 0
AddCMakeToPath() AddCMakeToPath()
if args.clobber:
ClobberChromiumBuildFiles() ClobberChromiumBuildFiles()
# Reset the stamp file in case the build is unsuccessful. # Reset the stamp file in case the build is unsuccessful.
WriteStampFile('') WriteStampFile('')
DeleteChromeToolsShim();
Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR) Checkout('LLVM', LLVM_REPO_URL + '/llvm/trunk', LLVM_DIR)
Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR) Checkout('Clang', LLVM_REPO_URL + '/cfe/trunk', CLANG_DIR)
Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR) Checkout('LLD', LLVM_REPO_URL + '/lld/trunk', LLD_DIR)
Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR) Checkout('compiler-rt', LLVM_REPO_URL + '/compiler-rt/trunk', COMPILER_RT_DIR)
CreateChromeToolsShim();
if not os.path.exists(LLVM_BUILD_DIR): if not os.path.exists(LLVM_BUILD_DIR):
os.makedirs(LLVM_BUILD_DIR) os.makedirs(LLVM_BUILD_DIR)
os.chdir(LLVM_BUILD_DIR) os.chdir(LLVM_BUILD_DIR)
cmake_args = ['-GNinja', '-DCMAKE_BUILD_TYPE=Release',
'-DLLVM_ENABLE_ASSERTIONS=ON', SubversionCmakeArg(),
'-DCHROMIUM_TOOLS_SRC=%s' % os.path.join(
CHROMIUM_DIR, 'tools', 'clang')]
if args.tools:
cmake_args.append('-DCHROMIUM_TOOLS=%s' % ';'.join(args.tools))
RunCommand(GetVSVersion().SetupScript('x64') + RunCommand(GetVSVersion().SetupScript('x64') +
['&&', 'cmake', '-GNinja', '-DCMAKE_BUILD_TYPE=Release', ['&&', 'cmake'] + cmake_args + [LLVM_DIR])
'-DLLVM_ENABLE_ASSERTIONS=ON', SubversionCmakeArg(), LLVM_DIR])
RunCommand(GetVSVersion().SetupScript('x64') + ['&&', 'ninja', 'all']) RunCommand(GetVSVersion().SetupScript('x64') + ['&&', 'ninja', 'all'])
# Do an x86 build of compiler-rt to get the 32-bit ASan run-time. # Do an x86 build of compiler-rt to get the 32-bit ASan run-time.
...@@ -213,8 +250,7 @@ def UpdateClang(): ...@@ -213,8 +250,7 @@ def UpdateClang():
os.makedirs(COMPILER_RT_BUILD_DIR) os.makedirs(COMPILER_RT_BUILD_DIR)
os.chdir(COMPILER_RT_BUILD_DIR) os.chdir(COMPILER_RT_BUILD_DIR)
RunCommand(GetVSVersion().SetupScript('x86') + RunCommand(GetVSVersion().SetupScript('x86') +
['&&', 'cmake', '-GNinja', '-DCMAKE_BUILD_TYPE=Release', ['&&', 'cmake'] + cmake_args + [LLVM_DIR])
'-DLLVM_ENABLE_ASSERTIONS=ON', LLVM_DIR])
RunCommand(GetVSVersion().SetupScript('x86') + ['&&', 'ninja', 'compiler-rt']) RunCommand(GetVSVersion().SetupScript('x86') + ['&&', 'ninja', 'compiler-rt'])
# TODO(hans): Make this (and the .gypi and .isolate files) version number # TODO(hans): Make this (and the .gypi and .isolate files) version number
...@@ -276,7 +312,13 @@ def main(): ...@@ -276,7 +312,13 @@ def main():
print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).'
return 0 return 0
return UpdateClang() parser = argparse.ArgumentParser(description='Build Clang.')
parser.add_argument('--no-clobber', dest='clobber', action='store_false')
parser.add_argument('--tools', nargs='*')
# For now, this flag is only used for the non-Windows flow, but argparser gets
# mad if it sees a flag it doesn't recognize.
parser.add_argument('--if-needed', action='store_true')
return UpdateClang(parser.parse_args())
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment