From 2696f818c530261b76cafa233fcd5fa65aeacec9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 17 Mar 2019 00:25:11 +0100 Subject: Add command for running executables from the build directory --- extras/autowaf.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/extras/autowaf.py b/extras/autowaf.py index 297ca0b..4267c68 100644 --- a/extras/autowaf.py +++ b/extras/autowaf.py @@ -94,6 +94,11 @@ def set_options(opt, debug_by_default=False): dest='test_wrapper', help='command prefix for tests (e.g. valgrind)') + # Run options + run_opts = opt.add_option_group('Run options') + run_opts.add_option('--cmd', type='string', dest='cmd', + help='command to run from build directory') + class ConfigureContext(Configure.ConfigurationContext): """configures the project""" @@ -779,6 +784,25 @@ class ExecutionEnvironment: def __exit__(self, type, value, traceback): os.environ = self.original_environ +class RunContext(Build.BuildContext): + "runs an executable from the build directory" + cmd = 'run' + + def execute(self): + self.restore() + if not self.all_envs: + self.load_envs() + + with ExecutionEnvironment(self.env.AUTOWAF_RUN_ENV) as env: + if Options.options.verbose: + Logs.pprint('GREEN', str(env) + '\n') + + if Options.options.cmd: + Logs.pprint('GREEN', 'Running %s' % Options.options.cmd) + subprocess.call(Options.options.cmd, shell=True) + else: + Logs.error("error: Missing --cmd option for run command") + def show_diff(from_lines, to_lines, from_filename, to_filename): import difflib import sys -- cgit v1.2.1