Skip to content

Commit

Permalink
fixup! interpreter: Add native keyword argument to `meson.override_…
Browse files Browse the repository at this point in the history
…find_program`
  • Loading branch information
dcbaker committed Apr 29, 2021
1 parent 794af33 commit 46c5667
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
1 change: 0 additions & 1 deletion docs/markdown/Reference-manual.md
Expand Up @@ -2093,7 +2093,6 @@ the following methods.

*(changed in 0.58.0)* Correctly tracks and handles overrides for the build
and host system separately.
*(since 0.58.0)* accepts the `native` keyword argument

- `override_dependency(name, dep_object)` *(since 0.54.0)*:
specifies that whenever `dependency(name, ...)` is used, Meson should not
Expand Down
8 changes: 4 additions & 4 deletions docs/markdown/snippets/override_find_program-native.md
Expand Up @@ -11,7 +11,7 @@ meson.override_find_program('exe', exe_for_build)
Meson would raise an error because `'exe'` had already been overwritten. This
has been fixed.

Additionally, a `native` keyword argument has been added. For built
dependencies, or those found with `find_program`, it's generally unnecessary
to use this argument, as Meson already know what those binaries are for. But
for scripts it is necessary.
Meson will automatically track the machine that a compiled executable is for
(as executable has a native keyword argumnet). For script overrides Meson
will always assume the build machine, as otherwise it will try to run with
the host interpreter, and require an exe_wrapper.
13 changes: 5 additions & 8 deletions mesonbuild/interpreter/mesonmain.py
Expand Up @@ -281,19 +281,16 @@ def install_dependency_manifest_method(self, args, kwargs):

@FeatureNew('meson.override_find_program', '0.46.0')
@FeatureNewKwargs('meson.override_find_programs', '0.58.0', ['native'])
@permittedKwargs({'native'})
@typed_pos_args('meson.override_find_programs', str, (ExecutableHolder, mesonlib.File, ExternalProgramHolder))
def override_find_program_method(self, args: T.Tuple[str, T.Union[ExecutableHolder, mesonlib.File, ExternalProgramHolder]], kwargs: T.Dict[str, T.Any]):
name = args[0]
exe: T.Union[build.Executable, mesonlib.File, ExternalProgram] = unholder(args[1])

# We need native when using a file, and someone might want to override
# something for a specific machine, otherwise use the for_machien from
# the program itself.
if isinstance(exe, mesonlib.File) or 'native' in kwargs:
for_machine = self.interpreter.machine_from_native_kwarg(kwargs)
else:
for_machine = exe.for_machine
# If the program is compiled, use the machine it's compiled for. For
# scripts assume they're for the build machine, as otherwise they'll
# want to run with a host interpreter, and error if it cannot be found
# or if it decides it needs an exe_wrapper
for_machine = MachineChoice.BUILD if isinstance(exe, mesonlib.File) else exe.for_machine

if isinstance(exe, mesonlib.File):
abspath = exe.absolute_path(self.interpreter.environment.source_dir,
Expand Down
@@ -1,6 +1,6 @@
project('sub', 'c', version : '1.0')
foobar = executable('foobar', 'foobar.c', native : true)
foobar = executable('foobar', 'foobar.c')
meson.override_find_program('foobar', foobar)

# Force this to be used for the host machine.
meson.override_find_program('foobar2', foobar, native : false)
meson.override_find_program('foobar2', foobar)

0 comments on commit 46c5667

Please sign in to comment.