Skip to content

Commit

Permalink
Add 'override-requirements' global option
Browse files Browse the repository at this point in the history
  • Loading branch information
xclaesse committed Apr 10, 2018
1 parent ec1a1f0 commit 405c6fe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions docs/markdown/Build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ d = dependency('foo', required : get_option('foo_option'))
app = executable('myapp', 'main.c', dependencies : [d])
```

If the value of a `requirement` option is set to `not-required`, that value is
overriden by the global `override_requirements` option (which defaults to
`not-required`). This is intended to be used by packagers who want to have full
control on which dependencies are required and which are disabled, and not rely
on build-deps being installed (at the right version) to get a feature enabled.
They could set `override_requirements=required` to enable all features and
disabled only the few they explicitly don't want, if any.

This type is available since version 0.46.0

## Using build options
Expand Down
8 changes: 5 additions & 3 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ def validate_value(self, value, user_input=True):
return newvalue

class UserRequirementOption(UserComboOption):
static_choices = ['required', 'not-required', 'disabled']
def __init__(self, name, description, value, yielding=None):
super().__init__(name, description,
['required', 'not-required', 'disabled'],
value, yielding)
super().__init__(name, description, self.static_choices, value, yielding)


# This class contains all data that must persist over multiple
Expand Down Expand Up @@ -356,6 +355,8 @@ def get_builtin_option_choices(optname):
return None
elif builtin_options[optname][0] == UserBooleanOption:
return [True, False]
elif builtin_options[optname][0] == UserRequirementOption:
return UserRequirementOption.static_choices
else:
return builtin_options[optname][2]
else:
Expand Down Expand Up @@ -408,6 +409,7 @@ def get_builtin_option_default(optname, prefix='', noneIfSuppress=False):
'backend': [UserComboOption, 'Backend to use.', backendlist, 'ninja'],
'stdsplit': [UserBooleanOption, 'Split stdout and stderr in test logs.', True],
'errorlogs': [UserBooleanOption, "Whether to print the logs from failing tests.", True],
'override_requirements': [UserRequirementOption, "Override value of all 'not-required' requirements user options.", 'not-required'],
}

# Special prefix-dependent defaults for installation directories that reside in
Expand Down
6 changes: 4 additions & 2 deletions mesonbuild/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,11 @@ def merge_from_method(self, args, kwargs):
self.held_object.values[k] = v

class RequirementHolder(InterpreterObject):
def __init__(self, value):
def __init__(self, value, interp):
super().__init__()
self.value = value
if self.value == 'not-required':
self.value = interp.coredata.get_builtin_option('override_requirements')
self.methods.update({'get_value': self.get_value_method})

@permittedMethodKwargs({})
Expand Down Expand Up @@ -1960,7 +1962,7 @@ def get_option(self, nodes, args, kwargs):
def func_get_option(self, nodes, args, kwargs):
opt = self.get_option(nodes, args, kwargs)
if isinstance(opt, coredata.UserRequirementOption):
return RequirementHolder(opt.value)
return RequirementHolder(opt.value, self)
return getattr(opt, 'value', opt)

@noKwargs
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/mconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def print_conf(self):
print(' Build dir ', self.build.environment.build_dir)
print('\nCore options:\n')
carr = []
for key in ['buildtype', 'warning_level', 'werror', 'strip', 'unity', 'default_library']:
for key in ['buildtype', 'warning_level', 'werror', 'strip', 'unity',
'default_library', 'override_requirements']:
carr.append({'name': key,
'descr': coredata.get_builtin_option_description(key),
'value': self.coredata.get_builtin_option(key),
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/mesonmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def create_parser():
add_builtin_argument(p, 'warnlevel', dest='warning_level')
add_builtin_argument(p, 'stdsplit', action='store_false')
add_builtin_argument(p, 'errorlogs', action='store_false')
add_builtin_argument(p, 'override-requirements')
p.add_argument('--cross-file', default=None,
help='File describing cross compilation environment.')
p.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option",
Expand Down

0 comments on commit 405c6fe

Please sign in to comment.