diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/llvm.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/llvm.py b/scripts/llvm.py index 27b8cb7..2489171 100644 --- a/scripts/llvm.py +++ b/scripts/llvm.py @@ -4,11 +4,15 @@ import os from sys import argv from sys import exit +from modules.llvm import LLVMBuildConfig from modules.llvm import LLVMSubproject from modules.llvm import LLVMSourceConfig from modules.llvm import get_remote_branch from modules.llvm import push_branch +from modules.utils import CommandPrinter +from modules.utils import CommandRunner +from linaropy.cd import cd from linaropy.git.clone import Clone from linaropy.proj import Proj @@ -91,6 +95,32 @@ def push_current_branch(args): die("Failed to push branch because: " + str(exc) + str(exc.__cause__)) +def configure_build(args): + """Configure a given build directory.""" + + proj = Proj() + + llvm_worktree_root = get_worktree_root(args.env) + sourceConfig = LLVMSourceConfig(proj, llvm_worktree_root) + + buildConfig = LLVMBuildConfig(sourceConfig, args.build) + + if args.defs: + args.defs = ["-D{}".format(v) for v in args.defs] + + if args.dry: + consumer = CommandPrinter() + else: + if not os.path.exists(args.build): + os.makedirs(args.build) + consumer = CommandRunner() + + try: + buildConfig.cmake(consumer, args.defs, args.generator) + except RuntimeError as exc: + die("Failed to configure {} because:\n{}".format(args.build, str(exc))) + + ########################################################################## # Command line parsing # ########################################################################## @@ -147,6 +177,38 @@ push = subcommands.add_parser( "for all enabled subprojects.") push.set_defaults(run_command=push_current_branch) +# Subcommand for configuring a build directory +configure = subcommands.add_parser( + 'configure', + help="Run CMake in the given build directory.") +configure.add_argument( + '--build-dir', + dest='build', + required=True, + help="Path to the build directory. It will be created if it does not exist") +configure.add_argument( + '--cmake-generator', + dest='generator', + default='Ninja', + help="CMake generator to use (default is Ninja).") +configure.add_argument( + '--cmake-def', + dest='defs', + metavar='VAR=VALUE', + default=[], + action='append', + # We add the -D in front of the variable ourselves because the argument + # parsing gets confused otherwise (and quoting doesn't help). + help="Additional CMake definitions, e.g. CMAKE_BUILD_TYPE=Release." + "May be passed several times. The -D is added automatically.") +configure.add_argument( + '-n', '--dry-run', + dest='dry', + action='store_true', + default=False, + help="Print the CMake command instead of executing it.") +configure.set_defaults(run_command=configure_build) + args = options.parse_args() if args.subcommand == "projects" and args.add and not args.repos: projs.error( |