diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2019-06-10 19:42:06 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-06-27 21:24:50 +0300 |
commit | 9149aaba9c87250a7fc92686c37057038f57ef99 (patch) | |
tree | 7662c962ef0afad871b14380e16ef192165bbb68 | |
parent | 6e4e0028a1f9f0035ad27e8dc7788bbe67c51053 (diff) | |
download | meson-9149aaba9c87250a7fc92686c37057038f57ef99.zip meson-9149aaba9c87250a7fc92686c37057038f57ef99.tar.gz meson-9149aaba9c87250a7fc92686c37057038f57ef99.tar.bz2 |
`add_{global,project}_{,link_}arguments`: simply native flag behavior
This further simplifies behavior to match the "build vs host" decision
we did with `c_args` vs `build_c_args`. The rules are now simply:
- `native: true` affects `native: true` targets
- `native: false` affects `native: false` targets
- No native flag is the same as `native: false`
I like this because you don't even have to know what "build" and "host"
mean to understand how it works, and it doesn't depend on whether the
overall build is cross or not.
Fixes #4933
-rw-r--r-- | docs/markdown/Release-notes-for-0.48.0.md | 2 | ||||
-rw-r--r-- | docs/markdown/snippets/add_arguments_cross.md | 16 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 34 | ||||
-rw-r--r-- | test cases/common/21 global arg/meson.build | 27 | ||||
-rw-r--r-- | test cases/common/21 global arg/prog.c | 46 |
5 files changed, 58 insertions, 67 deletions
diff --git a/docs/markdown/Release-notes-for-0.48.0.md b/docs/markdown/Release-notes-for-0.48.0.md index 80fc08b..a89f5c9 100644 --- a/docs/markdown/Release-notes-for-0.48.0.md +++ b/docs/markdown/Release-notes-for-0.48.0.md @@ -217,7 +217,7 @@ i18n.merge_file() now behaves as custom_target() in this regard. ## Projects args can be set separately for cross and native builds (potentially breaking change) It has been a longstanding bug (or let's call it a "delayed bug fix") -that if yo do this: +that if you do this: ```meson add_project_arguments('-DFOO', language : 'c') diff --git a/docs/markdown/snippets/add_arguments_cross.md b/docs/markdown/snippets/add_arguments_cross.md new file mode 100644 index 0000000..7c197b6 --- /dev/null +++ b/docs/markdown/snippets/add_arguments_cross.md @@ -0,0 +1,16 @@ +## Projects args can be set separately for build and host machines (potentially breaking change) + +Simplify `native` flag behavior in `add_global_arguments`, +`add_global_link_arguments`, `add_project_arguments` and +`add_project_link_arguments`. The rules are now very simple: + + - `native: true` affects `native: true` targets + + - `native: false` affects `native: false` targets + + - No native flag is the same as `native: false` + +This further simplifies behavior to match the "build vs host" decision done in +last release with `c_args` vs `build_c_args`. The underlying motivation in both +cases is to execute the same commands whether the overall build is native or +cross. diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 59a3642..f5bb4e5 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3829,47 +3829,29 @@ different subdirectory. env = self.unpack_env_kwarg(kwargs) self.build.test_setups[setup_name] = build.TestSetup(exe_wrapper, gdb, timeout_multiplier, env) - # TODO make cross agnostic, just taking into account for_machine - # TODO PerMachine[T], Iterator[T] - def get_argdict_on_crossness(self, dicts_per_machine: PerMachine, kwargs) -> Iterator: - for_native = kwargs.get('native', not self.environment.is_cross_build()) - if not isinstance(for_native, bool): - raise InterpreterException('Keyword native must be a boolean.') - if self.environment.is_cross_build(): - if for_native: - return iter([dicts_per_machine[MachineChoice.BUILD]]) - else: - return iter([dicts_per_machine[MachineChoice.HOST]]) - else: - if for_native: - return iter([dicts_per_machine[MachineChoice.BUILD], - dicts_per_machine[MachineChoice.HOST]]) - else: - return iter([]) - @permittedKwargs(permitted_kwargs['add_global_arguments']) @stringArgs def func_add_global_arguments(self, node, args, kwargs): - for argdict in self.get_argdict_on_crossness(self.build.global_args, kwargs): - self.add_global_arguments(node, argdict, args, kwargs) + for_machine = self.machine_from_native_kwarg(kwargs) + self.add_global_arguments(node, self.build.global_args[for_machine], args, kwargs) @permittedKwargs(permitted_kwargs['add_global_link_arguments']) @stringArgs def func_add_global_link_arguments(self, node, args, kwargs): - for argdict in self.get_argdict_on_crossness(self.build.global_link_args, kwargs): - self.add_global_arguments(node, argdict, args, kwargs) + for_machine = self.machine_from_native_kwarg(kwargs) + self.add_global_arguments(node, self.build.global_link_args[for_machine], args, kwargs) @permittedKwargs(permitted_kwargs['add_project_arguments']) @stringArgs def func_add_project_arguments(self, node, args, kwargs): - for argdict in self.get_argdict_on_crossness(self.build.projects_args, kwargs): - self.add_project_arguments(node, argdict, args, kwargs) + for_machine = self.machine_from_native_kwarg(kwargs) + self.add_project_arguments(node, self.build.projects_args[for_machine], args, kwargs) @permittedKwargs(permitted_kwargs['add_project_link_arguments']) @stringArgs def func_add_project_link_arguments(self, node, args, kwargs): - for argdict in self.get_argdict_on_crossness(self.build.projects_link_args, kwargs): - self.add_project_arguments(node, argdict, args, kwargs) + for_machine = self.machine_from_native_kwarg(kwargs) + self.add_project_arguments(node, self.build.projects_link_args[for_machine], args, kwargs) def add_global_arguments(self, node, argsdict, args, kwargs): if self.is_subproject(): diff --git a/test cases/common/21 global arg/meson.build b/test cases/common/21 global arg/meson.build index 699dae6..5add17e 100644 --- a/test cases/common/21 global arg/meson.build +++ b/test cases/common/21 global arg/meson.build @@ -1,22 +1,23 @@ project('global arg test', 'cpp', 'c') -add_global_arguments('-DMYTHING', language : 'c') -add_global_arguments('-DMYCPPTHING', language : 'cpp') +add_global_arguments('-DMYTHING', language : 'c', native : true) +add_global_arguments('-DMYTHING', language : 'c', native : false) +add_global_arguments('-DMYCPPTHING', language : 'cpp', native : true) +add_global_arguments('-DMYCPPTHING', language : 'cpp', native : false) -add_global_arguments('-DGLOBAL_NATIVE', language : 'c', native : true) -add_global_arguments('-DGLOBAL_CROSS', language : 'c', native : false) +add_global_arguments('-DGLOBAL_BUILD', language : 'c', native : true) +add_global_arguments('-DGLOBAL_HOST', language : 'c', native : false) -if meson.is_cross_build() - c_args = ['-DARG_CROSS'] -else - c_args = ['-DARG_NATIVE'] -endif +build_c_args = ['-DARG_BUILD'] +c_args = ['-DARG_HOST'] -add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp']) +add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp'], native: true) +add_global_arguments('-DMYCANDCPPTHING', language: ['c', 'cpp'], native: false) -exe1 = executable('prog', 'prog.c', c_args : c_args) -exe2 = executable('prog2', 'prog.cc') +exe1 = executable('prog1', 'prog.c', c_args : build_c_args, native : true) +exe2 = executable('prog2', 'prog.c', c_args : c_args, native : false) +exe3 = executable('prog3', 'prog.cc') test('prog1', exe1) test('prog2', exe2) - +test('prog3', exe3) diff --git a/test cases/common/21 global arg/prog.c b/test cases/common/21 global arg/prog.c index fb014c7..74d11aa 100644 --- a/test cases/common/21 global arg/prog.c +++ b/test cases/common/21 global arg/prog.c @@ -1,48 +1,40 @@ #ifndef MYTHING -#error "Global argument not set" + #error "Global argument not set" #endif #ifdef MYCPPTHING -#error "Wrong global argument set" + #error "Wrong global argument set" #endif #ifndef MYCANDCPPTHING -#error "Global argument not set" + #error "Global argument not set" #endif -#ifdef GLOBAL_NATIVE - #ifndef ARG_NATIVE - #error "Global is native but arg_native is not set." - #endif +#if !defined(GLOBAL_HOST) && !defined(GLOBAL_BUILD) + #error "Neither global_host nor glogal_build is set." +#endif - #ifdef GLOBAL_CROSS - #error "Both global native and global cross set." - #endif -#else - #ifndef GLOBAL_CROSS - #error "Neither global_cross nor glogal_native is set." - #endif +#if defined(GLOBAL_HOST) && defined(GLOBAL_BUILD) + #error "Both global build and global host set." +#endif - #ifndef ARG_CROSS - #error "Global is cross but arg_cross is not set." +#ifdef GLOBAL_BUILD + #ifndef ARG_BUILD + #error "Global is build but arg_build is not set." #endif - #ifdef ARG_NATIVE - #error "Global is cross but arg_native is set." + #ifdef ARG_HOST + #error "Global is build but arg host is set." #endif #endif -#ifdef GLOBAL_CROSS - #ifndef ARG_CROSS - #error "Global is cross but arg_cross is not set." - #endif -#else - #ifdef ARG_CROSS - #error "Global is cross but arg_native is set." +#ifdef GLOBAL_HOST + #ifndef ARG_HOST + #error "Global is host but arg_host is not set." #endif - #ifdef ARG_CROSS - #error "Global is native but arg cross is set." + #ifdef ARG_BUILD + #error "Global is host but arg_build is set." #endif #endif |