Can have built binaries in run_targets. Closes #264.

pull/255/head^2
Jussi Pakkanen 9 years ago
parent 32f72fee25
commit 4e8c4035e5
  1. 9
      interpreter.py
  2. 29
      ninjabackend.py
  3. 10
      test cases/common/58 run target/helloprinter.c
  4. 6
      test cases/common/58 run target/meson.build

@ -1451,11 +1451,18 @@ class Interpreter():
self.add_target(name, tg.held_object) self.add_target(name, tg.held_object)
return tg return tg
@stringArgs
@noKwargs @noKwargs
def func_run_target(self, node, args, kwargs): def func_run_target(self, node, args, kwargs):
if len(args) < 2: if len(args) < 2:
raise InterpreterException('Incorrect number of arguments') raise InterpreterException('Incorrect number of arguments')
for i in args:
try:
i = i.held_object
except AttributeError:
pass
if not isinstance(i, (str, build.BuildTarget)):
mlog.debug('Wrong type:', str(i))
raise InterpreterException('Invalid argument to run_target.')
name = args[0] name = args[0]
command = args[1] command = args[1]
cmd_args = args[2:] cmd_args = args[2:]

@ -312,9 +312,32 @@ class NinjaBackend(backends.Backend):
def generate_run_target(self, target, outfile): def generate_run_target(self, target, outfile):
runnerscript = os.path.join(self.environment.get_script_dir(), 'commandrunner.py') runnerscript = os.path.join(self.environment.get_script_dir(), 'commandrunner.py')
elem = NinjaBuildElement(target.name, 'CUSTOM_COMMAND', []) deps = []
cmd = [sys.executable, runnerscript, self.environment.get_source_dir(), self.environment.get_build_dir(), arg_strings = []
target.subdir, target.command] + target.args for i in target.args:
if isinstance(i, str):
arg_strings.append(i)
elif isinstance(i, build.BuildTarget):
deps.append(self.get_target_filename(i))
else:
raise MesonException('Unreachable code.')
elem = NinjaBuildElement(target.name, 'CUSTOM_COMMAND', deps)
cmd = [sys.executable, runnerscript, self.environment.get_source_dir(), self.environment.get_build_dir(), target.subdir]
texe = target.command
try:
texe = texe.held_object
except AttributeError:
pass
if isinstance(texe, build.Executable):
deps.append(self.get_target_filename(texe))
if self.environment.is_cross_build() \
and wrapper is not self.environment.cross_info.config['binaries'].get('exe_wrapper', None):
cmd += [self.environment.cross_info.config['binaries']['exe_wrapper'], self.get_target_filename(texe)]
else:
cmd += [os.path.join(self.environment.get_build_dir(), self.get_target_filename(texe))]
else:
cmd.append(target.command)
cmd += target.args
elem.add_item('COMMAND', cmd) elem.add_item('COMMAND', cmd)
elem.add_item('description', 'Running external command %s.' % target.name) elem.add_item('description', 'Running external command %s.' % target.name)
elem.add_item('pool', 'console') elem.add_item('pool', 'console')

@ -0,0 +1,10 @@
#include<stdio.h>
int main(int argc, char **argv) {
if(argc != 2) {
printf("I can not haz argument.\n");
} else {
printf("I can haz argument: %s\n", argv[1]);
}
return 0;
}

@ -1,3 +1,9 @@
project('run target', 'c') project('run target', 'c')
run_target('mycommand', 'scripts/script.sh') run_target('mycommand', 'scripts/script.sh')
# Make it possible to run built programs.
# In cross builds exe_wrapper should be added if it exists.
exe = executable('helloprinter', 'helloprinter.c')
run_target('runhello', exe, 'argument')

Loading…
Cancel
Save