Skip to content

Commit 5768692

Browse files
bonzinijpakkane
authored andcommitted
msetup, options: reverse direction of unknown options check
Remove knowledge of the internal pending_options from msetup; operate on the command line and check against the option store. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a7280b9 commit 5768692

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

mesonbuild/msetup.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,21 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[dict] = None) -
194194
return self._generate(env, capture, vslite_ctx)
195195

196196
def check_unused_options(self, coredata: 'coredata.CoreData', cmd_line_options: T.Dict[OptionKey, str], all_subprojects: T.Mapping[str, object]) -> None:
197-
pending = coredata.optstore.pending_options
198197
errlist: T.List[str] = []
199198
known_subprojects = all_subprojects.keys()
200-
for opt in pending:
201-
# It is not an error to set wrong option for unknown subprojects
202-
# because they might be used in future reconfigurations
203-
if coredata.optstore.accept_as_pending_option(opt, known_subprojects):
199+
for opt in cmd_line_options:
200+
# Accept options that exist or could appear in subsequent reconfigurations,
201+
# including options for subprojects that were not used
202+
if opt in coredata.optstore or \
203+
opt.evolve(subproject=None) in coredata.optstore or \
204+
coredata.optstore.accept_as_pending_option(opt):
204205
continue
205-
if opt in cmd_line_options:
206-
errlist.append(f'"{opt}"')
206+
if opt.subproject and opt.subproject not in known_subprojects:
207+
continue
208+
# "foo=true" may also refer to toplevel project option ":foo"
209+
if opt.subproject is None and coredata.optstore.is_project_option(opt.as_root()):
210+
continue
211+
errlist.append(f'"{opt}"')
207212
if errlist:
208213
errstr = ', '.join(errlist)
209214
raise MesonException(f'Unknown options: {errstr}')

mesonbuild/options.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,16 +1332,9 @@ def initialize_from_top_level_project_call(self,
13321332
if not key.subproject:
13331333
self.set_option_maybe_root(key, valstr, True)
13341334

1335-
def accept_as_pending_option(self, key: OptionKey, known_subprojects: T.Optional[T.Container[str]] = None,
1336-
first_invocation: bool = False) -> bool:
1337-
# Fail on unknown options that we can know must exist at this point in time.
1338-
# Subproject and compiler options are resolved later.
1339-
#
1335+
def accept_as_pending_option(self, key: OptionKey, first_invocation: bool = False) -> bool:
13401336
# Some base options (sanitizers etc) might get added later.
13411337
# Permitting them all is not strictly correct.
1342-
if key.subproject:
1343-
if known_subprojects is None or key.subproject not in known_subprojects:
1344-
return True
13451338
if self.is_compiler_option(key):
13461339
return True
13471340
if first_invocation and self.is_backend_option(key):

unittests/optiontests.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,13 @@ def test_b_nonexistent(self):
227227
def test_backend_option_pending(self):
228228
optstore = OptionStore(False)
229229
# backend options are known after the first invocation
230-
self.assertTrue(optstore.accept_as_pending_option(OptionKey('backend_whatever'), set(), True))
231-
self.assertFalse(optstore.accept_as_pending_option(OptionKey('backend_whatever'), set(), False))
230+
self.assertTrue(optstore.accept_as_pending_option(OptionKey('backend_whatever'), True))
231+
self.assertFalse(optstore.accept_as_pending_option(OptionKey('backend_whatever'), False))
232232

233233
def test_reconfigure_b_nonexistent(self):
234234
optstore = OptionStore(False)
235235
optstore.set_from_configure_command(['b_ndebug=true'], [])
236236

237-
def test_subproject_nonexistent(self):
238-
optstore = OptionStore(False)
239-
subprojects = {'found'}
240-
self.assertFalse(optstore.accept_as_pending_option(OptionKey('foo', subproject='found'), subprojects))
241-
self.assertTrue(optstore.accept_as_pending_option(OptionKey('foo', subproject='whatisthis'), subprojects))
242-
243237
def test_subproject_proj_opt_with_same_name(self):
244238
name = 'tests'
245239
subp = 'subp'

0 commit comments

Comments
 (0)