aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDiana Picus <diana.picus@linaro.org>2018-01-19 16:14:26 +0100
committerDiana Picus <diana.picus@linaro.org>2018-01-23 08:25:34 +0100
commit37126b8bb583f22bca62af4d7864f9b70bf9b0e9 (patch)
tree6b3d96bde8274ff83c2a11b9afe634fe133bc3b7 /scripts
parent41f49b14abd6e4c805e76186a7c6e6d6e82c31da (diff)
downloadlinaro-scripts-37126b8bb583f22bca62af4d7864f9b70bf9b0e9.tar.gz
Add support for building LLVM
Add a llvm.py subcommand for building LLVM in a given build directory. The build directory must have already been configured with CMake. The build command that is run will be either a 'ninja' command or a 'make' command, depending on whether the build directory contains a 'build.ninja' or a 'Makefile'. If it contains neither of those, an error is generated. I initially wanted to put the implementation for this in the LLVMBuildConfig, but it doesn't really need anything from there. For now I left it as a free-standing function. It doesn't have any knowledge of LLVM whatsoever, so an argument could be made for moving it into the "utils" package rather than the "llvm" package. In the future, we may want to remove the LLVMBuildConfig class and see if there's a better way to organize the code for configuring and building. One disadvantage with using python here is that we lose the nice progress bars that we could see when running 'ninja check' from the bash scripts. I'm not sure how to fix that, suggestions welcome. Change-Id: I48cf464a6412238a26eb5bcfb4723946983c86f2
Diffstat (limited to 'scripts')
-rw-r--r--scripts/llvm.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/llvm.py b/scripts/llvm.py
index d1bf29d..ff8ecb1 100644
--- a/scripts/llvm.py
+++ b/scripts/llvm.py
@@ -4,6 +4,7 @@ import os
from sys import argv
from sys import exit
+from modules.llvm import build_llvm
from modules.llvm import LLVMBuildConfig
from modules.llvm import LLVMSubproject
from modules.llvm import LLVMSourceConfig
@@ -116,6 +117,21 @@ def configure_build(args):
die("Failed to configure {} because:\n{}".format(args.build, str(exc)))
+def run_build(args):
+ """Run a build command in a given directory."""
+ build_dir = args.build
+
+ if args.dry:
+ consumer = CommandPrinter()
+ else:
+ consumer = CommandRunner()
+
+ try:
+ build_llvm(consumer, args.build, args.flags)
+ except RuntimeError as exc:
+ die("Failed to build {} because:\n{}".format(args.build, str(exc)))
+
+
##########################################################################
# Command line parsing #
##########################################################################
@@ -215,6 +231,36 @@ configure.add_argument(
help="Print the CMake command instead of executing it.")
configure.set_defaults(run_command=configure_build)
+# Subcommand for building a target
+build = subcommands.add_parser(
+ 'build',
+ help="Run a build command in the given directory."
+ "The build command can be either a 'ninja' or a 'make' command, depending "
+ "on what the build directory contains. First, we look for a 'build.ninja' "
+ "file. If that is not found, we look for a 'Makefile'. If that is not "
+ "found either, the script fails.")
+build.add_argument(
+ '--build-dir',
+ dest='build',
+ required=True,
+ help="Path to the build directory. It must have already been configured.")
+build.add_argument(
+ '-n', '--dry-run',
+ dest='dry',
+ action='store_true',
+ default=False,
+ help="Print the build command instead of executing it.")
+build.add_argument(
+ '--build-flag',
+ dest='flags',
+ metavar='FLAG',
+ default=[],
+ action='append',
+ help="Additional flags for the build command (e.g. targets to build). "
+ "May be passed several times. If your flag starts with a '-', use "
+ "'--build-flag=-FLAG' to pass it.")
+build.set_defaults(run_command=run_build)
+
args = options.parse_args()
if args.subcommand == "projects" and args.add and not args.repos:
projs.error(