Index: lldb/utils/xcode.py =================================================================== --- /dev/null +++ lldb/utils/xcode.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +import sys +import os +import errno +import subprocess +import six +from contextlib import contextmanager + + +def mkdir(directory): + try: + os.makedirs(directory) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +@contextmanager +def cwd(path): + oldpwd = os.getcwd() + os.chdir(path) + try: + yield + finally: + os.chdir(oldpwd) + + +def build_llvm(llvm_path): + """Configures and builds LLVM & Clang with Ninja.""" + build_path = os.path.join(os.getcwd(), 'llvm-build') + mkdir(build_path) + with cwd(build_path): + cmake_cmd = [ + "cmake {}".format(llvm_path), "-GNinja", + "-DCMAKE_BUILD_TYPE='Release'", "-DLLVM_ENABLE_ASSERTIONS:BOOL=ON", + "-DLLVM_ENABLE_PROJECTS='clang;libcxx;libcxxabi'" + ] + subprocess.call(' '.join(cmake_cmd), shell=True) + subprocess.call('ninja', shell=True) + return build_path + + +def configure_lldb(llvm_build_path, lldb_path, args): + """Configures an standalone build of LLDB with the Xcode generator.""" + build_path = os.path.join(os.getcwd(), 'lldb-build') + cache_path = os.path.join(lldb_path, 'cmake', 'caches', + 'Apple-lldb-Xcode.cmake') + llvm_dir = os.path.join(llvm_build_path, 'lib', 'cmake', 'llvm') + clang_dir = os.path.join(llvm_build_path, 'lib', 'cmake', 'clang') + mkdir(build_path) + with cwd(build_path): + cmake_cmd = [ + "cmake {}".format(lldb_path), "-GXcode", "-C{}".format(cache_path), + "-DLLVM_DIR='{}'".format(llvm_dir), + "-DClang_DIR='{}'".format(clang_dir) + ] + cmake_cmd.extend(args) + subprocess.call(' '.join(cmake_cmd), shell=True) + subprocess.call('open lldb.xcodeproj', shell=True) + return build_path + + +def main(): + """Generate an Xcode project for LLDB from CMake. + + This scripts creates two build directories in the current directory: one + for LLVM and one for LLDB. The LLVM build uses the Ninja generator, the + LLDB build uses the Xcode generator. + """ + args = sys.argv[1:] + lldb_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + llvm_path = os.path.join(os.path.dirname(lldb_path), 'llvm') + + if not os.path.exists(llvm_path): + printf('This script only works with the LLVM monorepo') + exit(1) + + llvm_build_path = build_llvm(llvm_path) + lldb_build_path = configure_lldb(llvm_build_path, lldb_path, args) + + +if __name__ == "__main__": + main()