Can execute found programs with run_command.

pull/15/head
Jussi Pakkanen 11 years ago
parent c21637a01d
commit c7e7d1a4c3
  1. 8
      dependencies.py
  2. 17
      interpreter.py
  3. 3
      run_tests.py
  4. 7
      test cases/common/55 file grabber/meson.build
  5. 5
      test cases/common/55 file grabber/subdir/meson.build
  6. 1
      test cases/common/55 file grabber/subdir/suba.c
  7. 1
      test cases/common/55 file grabber/subdir/subb.c
  8. 1
      test cases/common/55 file grabber/subdir/subc.c
  9. 7
      test cases/common/55 file grabber/subdir/subprog.c

@ -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

@ -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():

@ -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:

@ -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')

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

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