aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDiana Picus <diana.picus@linaro.org>2017-11-24 16:19:41 +0100
committerDiana Picus <diana.picus@linaro.org>2017-12-15 13:08:13 +0100
commit052b7d37cefe8975f699110a5c9508b2501a97e0 (patch)
tree8d78edb8da899bfdfbab43abd6a36db816a3fd4e /scripts
parent5fec8b75ddf572779af5dc2a639c8eb15c6bfc9f (diff)
downloadlinaro-scripts-052b7d37cefe8975f699110a5c9508b2501a97e0.tar.gz
Add llvm.py configure
Add a subcommand that runs CMake in a given build directory, with a custom generator and custom CMake definitions. Also update llvm-build to use it instead of calling CMake directly, and add calls to it in llvm-projs as well to make sure we update the build directories whenever we enable or disable a project. One known issue with the current code is that the output of the CMake command is not printed out live, but rather after the command has finished execution. This is going to be more important for llvm.py build than for llvm.py configure, so we can fix it in a future commit. Change-Id: I263b2d47c2083a1778608253bbd437149375c539
Diffstat (limited to 'scripts')
-rw-r--r--scripts/llvm.py62
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(