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
diff --git a/modules/utils.py b/modules/utils.py
new file mode 100644
index 0000000..9e6f29a
--- /dev/null
+++ b/modules/utils.py
@@ -0,0 +1,29 @@
+from subprocess import CalledProcessError
+from subprocess import check_output
+from subprocess import STDOUT
+
+
+class CommandPrinter(object):
+ """Command consumer that just prints the commands that it receives."""
+
+ def consume(self, command, directory):
+ print("{}$ {}".format(directory, ' '.join(command)))
+
+
+class CommandRunner(object):
+ """Command consumer that runs the commands that it receives."""
+
+ def consume(self, command, directory):
+ """
+ Run the given command in the given directory and print the stdout and
+ stderr. If an exception is thrown while running the command, it will be
+ rethrown as a RuntimeError.
+ """
+ # FIXME: This prints the results after the command has finished running.
+ # For long-running commands (e.g. an LLVM build) we'll want live
+ # output.
+ try:
+ print(str(check_output(command, stderr=STDOUT, cwd=directory), 'utf-8'))
+ except CalledProcessError as exc:
+ raise RuntimeError(
+ "Error while running command\n{}".format(str(exc.output, 'utf-8'))) from exc