Skip to content

Commit

Permalink
interpreter: add support for --force-fallback-for
Browse files Browse the repository at this point in the history
This new command line option allows specifying dependencies for
which to force fallback.

See the documentation for more information

Fixes: mesonbuild#7218
  • Loading branch information
MathieuDuponchelle authored and xclaesse committed Jun 16, 2020
1 parent f40e156 commit 20709af
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/markdown/Builtin-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ for details.
| warning_level {0, 1, 2, 3} | 1 | Set the warning level. From 0 = none to 3 = highest | no |
| werror | false | Treat warnings as errors | no |
| wrap_mode {default, nofallback,<br>nodownload, forcefallback} | default | Wrap mode to use | no |
| force_fallback_for | [] | Force fallback for those dependencies | no |

<a name="build-type-options"></a>
For setting optimization levels and toggling debug, you can either set the
Expand Down
16 changes: 16 additions & 0 deletions docs/markdown/Subprojects.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ the following command-line options:
calls, and those are meant to be used for sources that cannot be
provided by the system, such as copylibs.

This option may be overriden by `--force-fallback-for` for specific
dependencies.

* **--wrap-mode=forcefallback**

Meson will not look at the system for any dependencies which have
Expand All @@ -220,6 +223,19 @@ the following command-line options:
want to specifically build against the library sources provided by
your subprojects.

* **--force-fallback-for=list,of,dependencies**

Meson will not look at the system for any dependencies listed there,
provided a fallback was supplied when the dependency was declared.

This option takes precedence over `--wrap-mode=nofallback`, and when
used in combination with `--wrap-mode=nodownload` will only work
if the dependency has already been downloaded.

This is useful when your project has many fallback dependencies,
but you only want to build against the library sources for a few
of them.

## Download subprojects

*Since 0.49.0*
Expand Down
10 changes: 10 additions & 0 deletions docs/markdown/snippets/force_fallback_for.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Force fallback for

A newly-added `--force-fallback-for` command line option can now be used to
force fallback for specific subprojects.

Example:

```
meson build --force-fallback-for=foo,bar
```
1 change: 1 addition & 0 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ def add_to_argparse(self, name: str, parser: argparse.ArgumentParser, prefix: st
('warning_level', BuiltinOption(UserComboOption, 'Compiler warning level to use', '1', choices=['0', '1', '2', '3'])),
('werror', BuiltinOption(UserBooleanOption, 'Treat warnings as errors', False, yielding=False)),
('wrap_mode', BuiltinOption(UserComboOption, 'Wrap mode', 'default', choices=['default', 'nofallback', 'nodownload', 'forcefallback'])),
('force_fallback_for', BuiltinOption(UserArrayOption, 'Force fallback for those subprojects', [])),
])

builtin_options_per_machine = OrderedDict([
Expand Down
11 changes: 9 additions & 2 deletions mesonbuild/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3568,7 +3568,8 @@ def dependency_impl(self, name, display_name, kwargs):
return self.get_subproject_dep(name, display_name, dirname, varname, kwargs)

wrap_mode = self.coredata.get_builtin_option('wrap_mode')
forcefallback = wrap_mode == WrapMode.forcefallback and has_fallback
force_fallback_for = self.coredata.get_builtin_option('force_fallback_for')
forcefallback = (wrap_mode == WrapMode.forcefallback or name in force_fallback_for) and has_fallback
if name != '' and not forcefallback:
self._handle_featurenew_dependencies(name)
kwargs['required'] = required and not has_fallback
Expand Down Expand Up @@ -3622,7 +3623,13 @@ def get_subproject_infos(self, kwargs):

def dependency_fallback(self, name, display_name, kwargs):
required = kwargs.get('required', True)
if self.coredata.get_builtin_option('wrap_mode') == WrapMode.nofallback:

# Explicitly listed fallback preferences for specific subprojects
# take precedence over wrap-mode
if name in self.coredata.get_builtin_option('force_fallback_for'):
mlog.log('Looking for a fallback subproject for the dependency',
mlog.bold(display_name), 'because:\nUse of fallback was forced for that specific subproject')
elif self.coredata.get_builtin_option('wrap_mode') == WrapMode.nofallback:
mlog.log('Not looking for a fallback subproject for the dependency',
mlog.bold(display_name), 'because:\nUse of fallback '
'dependencies is disabled.')
Expand Down
6 changes: 6 additions & 0 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,12 @@ def test_forcefallback(self):
self.build()
self.run_tests()

def test_force_fallback_for(self):
testdir = os.path.join(self.unit_test_dir, '31 forcefallback')
self.init(testdir, extra_args=['--force-fallback-for=zlib,foo'])
self.build()
self.run_tests()

def test_env_ops_dont_stack(self):
'''
Test that env ops prepend/append do not stack, and that this usage issues a warning
Expand Down

0 comments on commit 20709af

Please sign in to comment.