Can execute found programs with run_command.

This commit is contained in:
Jussi Pakkanen 2014-04-20 13:58:20 +03:00
parent c21637a01d
commit c7e7d1a4c3
9 changed files with 44 additions and 6 deletions

View File

@ -127,17 +127,21 @@ class PkgConfigDependency(Dependency):
return self.is_found
class ExternalProgram():
def __init__(self, name, fullpath=None, silent=False):
def __init__(self, name, fullpath=None, silent=False, search_dir=None):
self.name = name
if fullpath is not None:
self.fullpath = fullpath
else:
self.fullpath = shutil.which(name)
if self.fullpath is None and search_dir is not None:
trial = os.path.join(search_dir, name)
if os.access(trial, os.X_OK):
self.fullpath = trial
if not silent:
if self.found():
mlog.log('Program', mlog.bold(name), 'found:', mlog.green('YES'), '(%s)' % self.fullpath)
else:
mlog.log('Program', mlog.bold(name), 'found:,', mlog.red('NO'))
mlog.log('Program', mlog.bold(name), 'found:', mlog.red('NO'))
def found(self):
return self.fullpath is not None

View File

@ -754,9 +754,18 @@ class Interpreter():
raise InvalidArguments('Incorrect argument type.')
def func_run_command(self, node, args, kwargs):
for i in args:
if len(args) < 1:
raise InterpreterException('Not enough arguments')
cmd = args[0]
cargs = args[1:]
if isinstance(cmd, ExternalProgramHolder):
cmd = cmd.get_command()
elif not isinstance(cmd, str):
raise InterpreterException('First argument is of incorrect type.')
for i in cargs:
if not isinstance(i, str):
raise InterpreterObject('Run_command arguments must be strings.')
raise InterpreterException('Run_command arguments must be strings.')
args = [cmd] + cargs
return RunProcess(args, self.environment.source_dir, self.environment.build_dir, self.subdir)
def func_gettext(self, nodes, args, kwargs):
@ -931,7 +940,9 @@ class Interpreter():
if exename in self.coredata.ext_progs and\
self.coredata.ext_progs[exename].found():
return ExternalProgramHolder(self.coredata.ext_progs[exename])
extprog = dependencies.ExternalProgram(exename)
# Search for scripts relative to current subdir.
search_dir = os.path.join(self.environment.get_source_dir(), self.subdir)
extprog = dependencies.ExternalProgram(exename, search_dir=search_dir)
progobj = ExternalProgramHolder(extprog)
self.coredata.ext_progs[exename] = extprog
if required and not progobj.found():

View File

@ -25,7 +25,8 @@ test_build_dir = 'work area'
install_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'install dir')
meson_command = './meson.py'
unity_flags = ['--unity']
#unity_flags = ['--unity']
unity_flags = []
msbuild_exe = shutil.which('msbuild')
if msbuild_exe is not None:

View File

@ -11,10 +11,14 @@ project('grabber', 'c')
if build.name() == 'windows'
c = run_command('grabber.bat')
grabber = find_program('grabber')
else
c = run_command('grabber.sh')
grabber = find_program('grabber.sh')
endif
# First test running command explicitly.
if c.returncode() != 0
error('Executing script failed.')
endif
@ -26,3 +30,6 @@ sources = c.stdout().strip().split(newline)
e = executable('prog', sources)
test('grabtest', e)
# Then test using program with find_program
subdir('subdir')

View File

@ -0,0 +1,5 @@
sc = run_command(grabber)
subsources = sc.stdout().strip().split(newline)
se = executable('subprog', subsources)
test('subgrabtest', se)

View File

@ -0,0 +1 @@
int funca() { return 0; }

View File

@ -0,0 +1 @@
int funcb() { return 0; }

View File

@ -0,0 +1 @@
int funcc() { return 0; }

View File

@ -0,0 +1,7 @@
int funca();
int funcb();
int funcc();
int main(int argc, char **argv) {
return funca() + funcb() + funcc();
}