Skip to content

Commit

Permalink
Do not disable subprojects that has user defined options
Browse files Browse the repository at this point in the history
When using a fallback for `dependency('foo', required: false)` and the
user has set some options on the subproject via a machine file or
`-Dfoo:opt=value`, consider the user wanted to use that subproject and
make the error fatal.
  • Loading branch information
xclaesse committed Oct 3, 2023
1 parent 05a94b3 commit 0841f9c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,12 @@ def disabled_subproject(self, subp_name: str, disabled_feature: T.Optional[str]
self.subprojects[subp_name] = sub
return sub

def _has_user_defined_options(self, subproject: str) -> bool:
for k, v in self.coredata.options.items():
if k.subproject == subproject and v.source >= mesonlib.OptionSource.MACHINE_FILE:
return True
return False

def do_subproject(self, subp_name: str, kwargs: kwtypes.DoSubproject, force_method: T.Optional[wrap.Method] = None) -> SubprojectHolder:
disabled, required, feature = extract_required_kwarg(kwargs, self.subproject)
if disabled:
Expand Down Expand Up @@ -944,6 +950,8 @@ def do_subproject(self, subp_name: str, kwargs: kwtypes.DoSubproject, force_meth
# fatal and VS CI treat any logs with "ERROR:" as fatal.
mlog.exception(e, prefix=mlog.yellow('Exception:'))
mlog.log('\nSubproject', mlog.bold(subdir), 'is buildable:', mlog.red('NO'), '(disabling)')
if self._has_user_defined_options(subp_name):
raise InterpreterException(f'Cannot disable subproject {subp_name} because it has user defined options')
return self.disabled_subproject(subp_name, exception=e)
raise e

Expand Down

0 comments on commit 0841f9c

Please sign in to comment.