Skip to content

Commit f397d2a

Browse files
dcbakerbonzini
authored andcommitted
interpreter: add native argument to override_find_program()
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 3404279 commit f397d2a

File tree

7 files changed

+43
-5
lines changed

7 files changed

+43
-5
lines changed

docs/markdown/snippets/subproject_and_override_program_native.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ Subprojects may now be built for the host or build machine (or both). This means
44
that build time dependencies can be built for the matching running the build in a
55
cross compile setup. When a subproject is run for the build machine it will act
66
just like a normal build == host setup, except that no targets will be installed.
7+
8+
This necessarily means that `meson.override_find_program()` must differentiate
9+
between programs for the host and those for the build machine, as you may need
10+
two versions of the same program, which have different outputs based on the
11+
machine they are for. For backwards compatibility reasons the default is for the
12+
host machine. Inside a native subproject the host and build machine will both be
13+
the build machine.

docs/yaml/builtins/meson.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,15 @@ methods:
392392
type: exe | file | external_program
393393
description: The program to set as the override for `progname`.
394394

395+
native:
396+
type: bool
397+
since: 1.11.0
398+
default: false
399+
description : |
400+
If set to `true`, the override is for the build machine, and will be returned
401+
by `find_program(..., native : true)`, otherwise for the host machine. This
402+
is an important distinction when cross compiling.
403+
395404
- name: override_dependency
396405
returns: void
397406
since: 0.54.0

mesonbuild/interpreter/mesonmain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ def install_dependency_manifest_method(self, args: T.Tuple[str], kwargs: 'TYPE_k
320320

321321
@FeatureNew('meson.override_find_program', '0.46.0')
322322
@typed_pos_args('meson.override_find_program', str, (mesonlib.File, ExternalProgram, build.Executable))
323-
@noKwargs
323+
@typed_kwargs('meson.override_find_program', NATIVE_KW.evolve(since='1.11.0'))
324324
@InterpreterObject.method('override_find_program')
325-
def override_find_program_method(self, args: T.Tuple[str, T.Union[mesonlib.File, ExternalProgram, build.Executable]], kwargs: 'TYPE_kwargs') -> None:
325+
def override_find_program_method(self, args: T.Tuple[str, T.Union[mesonlib.File, ExternalProgram, build.Executable]], kwargs: NativeKW) -> None:
326326
name, exe = args
327327
if isinstance(exe, mesonlib.File):
328328
abspath = exe.absolute_path(self.interpreter.environment.source_dir,
@@ -332,7 +332,7 @@ def override_find_program_method(self, args: T.Tuple[str, T.Union[mesonlib.File,
332332
exe = OverrideProgram(name, self.interpreter.project_version, command=[abspath])
333333
elif isinstance(exe, build.Executable):
334334
exe = build.OverrideExecutable(exe, self.interpreter.project_version)
335-
self.interpreter.add_find_program_override(name, exe)
335+
self.interpreter.add_find_program_override(name, exe, kwargs['native'])
336336

337337
@typed_kwargs(
338338
'meson.override_dependency',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int main(void) {
4+
printf("const char * gen_main(void) {\n");
5+
printf(" return \"int main() \";\n");
6+
printf("}\n");
7+
return 0;
8+
}

test cases/native/10 native subproject/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ project('native subproject', 'c', meson_version : '>= 1.11.0')
44
subproject('both', native : true)
55
subproject('both', native : false)
66

7+
maingen = executable('maingen', 'maingen.c', native : true)
8+
meson.override_find_program('maingen', maingen, native : true)
79
gen = subproject('buildtool', native : true).get_variable('e')
810

911
ct = custom_target(
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <stdio.h>
22

3+
const char * gen_main(void);
4+
35
int main() {
4-
printf("int main() { return 0; }\n");
6+
printf("%s", gen_main());
7+
printf("{ return 0; }\n");
58
return 0;
69
}

test cases/native/10 native subproject/subprojects/buildtool/meson.build

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
project('buildtool', 'c', meson_version : '>= 1.11.0')
22

3-
e = executable('buildtool', 'buildtool.c')
3+
maingen = find_program('maingen')
4+
5+
ct = custom_target(
6+
'gen',
7+
command : [maingen],
8+
output : 'gen.c',
9+
capture : true,
10+
)
11+
12+
e = executable('buildtool', 'buildtool.c', ct)
413

514
meson.override_find_program('buildtool', e)
615

0 commit comments

Comments
 (0)