aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/interpreter.py19
-rwxr-xr-xrun_unittests.py26
-rw-r--r--test cases/unit/46 native file binary/meson.build6
-rw-r--r--test cases/unit/46 native file binary/meson_options.txt2
4 files changed, 48 insertions, 5 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 73c21fd..e820afb 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -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()):
diff --git a/run_unittests.py b/run_unittests.py
index 007a05b..b375629 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -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
diff --git a/test cases/unit/46 native file binary/meson.build b/test cases/unit/46 native file binary/meson.build
index 2e458b0..3c99929 100644
--- a/test cases/unit/46 native file binary/meson.build
+++ b/test cases/unit/46 native file binary/meson.build
@@ -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
diff --git a/test cases/unit/46 native file binary/meson_options.txt b/test cases/unit/46 native file binary/meson_options.txt
index df535db..83d34e8 100644
--- a/test cases/unit/46 native file binary/meson_options.txt
+++ b/test cases/unit/46 native file binary/meson_options.txt
@@ -1,5 +1,5 @@
option(
'case',
type : 'combo',
- choices : []
+ choices : ['find_program']
)