diff --git a/docs/markdown/Build-options.md b/docs/markdown/Build-options.md index 80eec1eeae1d..fe1820cf995e 100644 --- a/docs/markdown/Build-options.md +++ b/docs/markdown/Build-options.md @@ -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 diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 3ee4b3206375..64c4263906e7 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -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 @@ -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: @@ -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 diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index fa35f52f4a3c..7cab862d6228 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -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({}) @@ -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 diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py index cadd30667af1..4aac8412f259 100644 --- a/mesonbuild/mconf.py +++ b/mesonbuild/mconf.py @@ -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), diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 651224ee1bd5..302d69734ab3 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -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",