find_program: Support passing mesonlib.File objects

This means you can pass files() and the return value of configure_file()
to find_program() now.
pull/1356/head
Nirbheek Chauhan 8 years ago
parent 18bce47691
commit 280346da3a
  1. 16
      mesonbuild/interpreter.py
  2. 8
      test cases/common/105 find program path/meson.build

@ -1759,7 +1759,6 @@ class Interpreter(InterpreterBase):
break
self.coredata.base_options[optname] = oobj
@stringArgs
def func_find_program(self, node, args, kwargs):
if len(args) == 0:
raise InterpreterException('No program name specified.')
@ -1769,8 +1768,21 @@ class Interpreter(InterpreterBase):
# Search for scripts relative to current subdir.
# Do not cache found programs because find_program('foobar')
# might give different results when run from different source dirs.
search_dir = os.path.join(self.environment.get_source_dir(), self.subdir)
source_dir = os.path.join(self.environment.get_source_dir(), self.subdir)
for exename in args:
if isinstance(exename, mesonlib.File):
if exename.is_built:
search_dir = os.path.join(self.environment.get_build_dir(),
exename.subdir)
else:
search_dir = os.path.join(self.environment.get_source_dir(),
exename.subdir)
exename = exename.fname
elif isinstance(exename, str):
search_dir = source_dir
else:
raise InvalidArguments('find_program only accepts strings and '
'files, not {!r}'.format(exename))
extprog = dependencies.ExternalProgram(exename, search_dir=search_dir)
progobj = ExternalProgramHolder(extprog)
if progobj.found():

@ -8,3 +8,11 @@ if not python.found()
endif
run_command(python, prog.path())
progf = files('program.py')
py = configure_file(input : 'program.py',
output : 'builtprogram.py',
configuration : configuration_data())
find_program(py)
find_program(progf)

Loading…
Cancel
Save