interpreter: allow find_program to use the native file

pull/4216/head
Dylan Baker 7 years ago
parent cb2a66cdef
commit 42ddc30cfe
  1. 19
      mesonbuild/interpreter.py
  2. 26
      run_unittests.py
  3. 6
      test cases/unit/46 native file binary/meson.build
  4. 2
      test cases/unit/46 native file binary/meson_options.txt

@ -2748,8 +2748,7 @@ external dependencies (including libraries) must go to "dependencies".''')
self.coredata. base_options[optname] = oobj
self.emit_base_options_warnings(enabled_opts)
def program_from_cross_file(self, prognames, silent=False):
cross_info = self.environment.cross_info
def _program_from_file(self, prognames, bins, silent):
for p in prognames:
if hasattr(p, 'held_object'):
p = p.held_object
@ -2762,6 +2761,14 @@ external dependencies (including libraries) must go to "dependencies".''')
return ExternalProgramHolder(prog)
return None
def program_from_cross_file(self, prognames, silent=False):
bins = self.environment.cross_info.config['binaries']
return self._program_from_file(prognames, bins, silent)
def program_from_config_file(self, prognames, silent=False):
bins = self.environment.config_info.binaries
return self._program_from_file(prognames, bins, silent)
def program_from_system(self, args, silent=False):
# Search for scripts relative to current subdir.
# Do not cache found programs because find_program('foobar')
@ -2816,10 +2823,14 @@ external dependencies (including libraries) must go to "dependencies".''')
def find_program_impl(self, args, native=False, required=True, silent=True):
if not isinstance(args, list):
args = [args]
progobj = self.program_from_overrides(args, silent=silent)
if progobj is None and self.build.environment.is_cross_build():
if not native:
if progobj is None:
if self.build.environment.is_cross_build() and not native:
progobj = self.program_from_cross_file(args, silent=silent)
else:
progobj = self.program_from_config_file(args, silent=silent)
if progobj is None:
progobj = self.program_from_system(args, silent=silent)
if required and (progobj is None or not progobj.found()):

@ -4522,6 +4522,32 @@ class NativeFileTests(BasePlatformTests):
f.write('py -3 {} %*'.format(filename))
return batfile
def test_multiple_native_files_override(self):
wrapper = self.helper_create_binary_wrapper('bash', version='foo')
config = self.helper_create_native_file({'binaries': {'bash': wrapper}})
wrapper = self.helper_create_binary_wrapper('bash', version='12345')
config2 = self.helper_create_native_file({'binaries': {'bash': wrapper}})
self.init(self.testcase, extra_args=[
'--native-file', config, '--native-file', config2,
'-Dcase=find_program'])
def test_multiple_native_files(self):
wrapper = self.helper_create_binary_wrapper('bash', version='12345')
config = self.helper_create_native_file({'binaries': {'bash': wrapper}})
wrapper = self.helper_create_binary_wrapper('python')
config2 = self.helper_create_native_file({'binaries': {'python': wrapper}})
self.init(self.testcase, extra_args=[
'--native-file', config, '--native-file', config2,
'-Dcase=find_program'])
def _simple_test(self, case, binary):
wrapper = self.helper_create_binary_wrapper(binary, version='12345')
config = self.helper_create_native_file({'binaries': {binary: wrapper}})
self.init(self.testcase, extra_args=['--native-file', config, '-Dcase={}'.format(case)])
def test_find_program(self):
self._simple_test('find_program', 'bash')
def unset_envs():
# For unit tests we must fully control all command lines

@ -1,3 +1,9 @@
project('test project')
case = get_option('case')
if case == 'find_program'
prog = find_program('bash')
result = run_command(prog, ['--version'])
assert(result.stdout().strip().endswith('12345'), 'Didn\'t load bash from config file')
endif

@ -1,5 +1,5 @@
option(
'case',
type : 'combo',
choices : []
choices : ['find_program']
)

Loading…
Cancel
Save