Add add_languages(native:)

v2:
Retain not using logical-and, to avoid short-circuiting side-effects
of add_languages()
pull/6532/head
Jon Turney 6 years ago
parent 31d89a4ed2
commit 7a159ff1e1
No known key found for this signature in database
GPG Key ID: C7C86F0370285C81
  1. 24
      docs/markdown/Reference-manual.md
  2. 5
      docs/markdown/snippets/native_compiler_not_required.md
  3. 21
      mesonbuild/interpreter.py
  4. 3
      test cases/common/85 add language/meson.build

@ -54,9 +54,9 @@ Like `add_global_arguments` but the arguments are passed to the linker.
bool add_languages(*langs*)
```
Add support for new programming languages. Equivalent to having them
in the `project` declaration. This function is usually used to add
languages that are only used on some platforms like this:
Add programming languages used by the project. Equivalent to having them in the
`project` declaration. This function is usually used to add languages that are
only used under some conditions, like this:
```meson
project('foobar', 'c')
@ -68,12 +68,18 @@ if add_languages('cpp', required : false)
endif
```
Takes one keyword argument, `required`. It defaults to `true`, which
means that if any of the languages specified is not found, Meson will
halt. Returns true if all languages specified were found and false
otherwise. Since *0.47.0* the value of a
[`feature`](Build-options.md#features) option can also be passed to
the `required` keyword argument.
Takes the following keyword arguments:
- `required` defaults to `true`, which means that if any of the languages
specified is not found, Meson will halt. Since *0.47.0* the value of a
[`feature`](Build-options.md#features) option can also be passed.
- `native` if set to `true`, the language will be used to compile for the build
machine, if `false`, for the host machine. If omitted, the language may be
used for either. Since *0.54.0*. The default may change to `false` in a future
meson version.
Returns `true` if all languages specified were found and `false` otherwise.
### add_project_arguments()

@ -0,0 +1,5 @@
## Native (build machine) compilers not always required
`add_languages()` gained a `native:` keyword, indicating if a native or cross
compiler is to be used. Currently, for backwards compatibility, if the keyword
is absent, that means both are used.

@ -2080,7 +2080,7 @@ _base_test_args = {'args', 'depends', 'env', 'should_fail', 'timeout', 'workdir'
permitted_kwargs = {'add_global_arguments': {'language', 'native'},
'add_global_link_arguments': {'language', 'native'},
'add_languages': {'required'},
'add_languages': {'required', 'native'},
'add_project_link_arguments': {'language', 'native'},
'add_project_arguments': {'language', 'native'},
'add_test_setup': {'exe_wrapper', 'gdb', 'timeout_multiplier', 'env', 'is_default'},
@ -2908,11 +2908,13 @@ external dependencies (including libraries) must go to "dependencies".''')
self.build.projects[self.subproject] = proj_name
mlog.log('Project name:', mlog.bold(proj_name))
mlog.log('Project version:', mlog.bold(self.project_version))
self.add_languages(proj_langs, True)
self.add_languages(proj_langs, True, MachineChoice.BUILD)
self.add_languages(proj_langs, True, MachineChoice.HOST)
self.set_backend()
if not self.is_subproject():
self.check_stdlibs()
@FeatureNewKwargs('add_languages', '0.54.0', ['native'])
@permittedKwargs(permitted_kwargs['add_languages'])
@stringArgs
def func_add_languages(self, node, args, kwargs):
@ -2921,7 +2923,15 @@ external dependencies (including libraries) must go to "dependencies".''')
for lang in sorted(args, key=compilers.sort_clink):
mlog.log('Compiler for language', mlog.bold(lang), 'skipped: feature', mlog.bold(feature), 'disabled')
return False
return self.add_languages(args, required)
if 'native' in kwargs:
return self.add_languages(args, required, self.machine_from_native_kwarg(kwargs))
else:
# absent 'native' means 'both' for backwards compatibility
mlog.warning('add_languages is missing native:, assuming languages are required for both host and build.',
location=self.current_node)
success = self.add_languages(args, required, MachineChoice.BUILD)
success &= self.add_languages(args, required, MachineChoice.HOST)
return success
def get_message_string_arg(self, arg):
if isinstance(arg, list):
@ -3009,9 +3019,8 @@ external dependencies (including libraries) must go to "dependencies".''')
self.validate_arguments(args, 0, [])
raise Exception()
def add_languages(self, args: T.Sequence[str], required: bool) -> bool:
success = self.add_languages_for(args, required, MachineChoice.BUILD)
success &= self.add_languages_for(args, required, MachineChoice.HOST)
def add_languages(self, args: T.Sequence[str], required: bool, for_machine: MachineChoice) -> bool:
success = self.add_languages_for(args, required, for_machine)
if not self.coredata.is_cross_build():
self.coredata.copy_build_options_from_regular_ones()
return success

@ -6,3 +6,6 @@ assert(add_languages('cpp'), 'Add_languages returned false on success')
assert(not add_languages('klingon', required : false), 'Add_languages returned true on failure.')
test('C++', executable('cppprog', 'prog.cc'))
add_languages('c', native: true)
add_languages('c', native: false)

Loading…
Cancel
Save