Skip to content

Commit 723f402

Browse files
bonzinijpakkane
authored andcommitted
coredata: use OptionKey for the keys of cmd_line_options
The cmd_line_options dictionary is described as having OptionKey keys, so make sure that cmd_the keys do have the correct type. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 2d6e308 commit 723f402

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

mesonbuild/coredata.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ def get_option_for_target(self, target: 'BuildTarget', key: T.Union[str, OptionK
416416
def set_from_configure_command(self, options: SharedCMDOptions) -> bool:
417417
unset_opts = getattr(options, 'unset_opts', [])
418418
all_D = options.projectoptions[:]
419-
for keystr, valstr in options.cmd_line_options.items():
420-
all_D.append(f'{keystr}={valstr}')
419+
for key, valstr in options.cmd_line_options.items():
420+
all_D.append(f'{key!s}={valstr}')
421421
return self.optstore.set_from_configure_command(all_D, unset_opts)
422422

423423
def set_option(self, key: OptionKey, value, first_invocation: bool = False) -> bool:
@@ -712,9 +712,10 @@ def parse_cmd_line_options(args: SharedCMDOptions) -> None:
712712
args.cmd_line_options = {}
713713
for o in args.projectoptions:
714714
try:
715-
(key, value) = o.split('=', 1)
715+
keystr, value = o.split('=', 1)
716716
except ValueError:
717717
raise MesonException(f'Option {o!r} must have a value separated by equals sign.')
718+
key = OptionKey.from_string(keystr)
718719
args.cmd_line_options[key] = value
719720

720721
# Merge builtin options set with --option into the dict.
@@ -730,7 +731,7 @@ def parse_cmd_line_options(args: SharedCMDOptions) -> None:
730731
cmdline_name = options.argparse_name_to_arg(name)
731732
raise MesonException(
732733
f'Got argument {name} as both -D{name} and {cmdline_name}. Pick one.')
733-
args.cmd_line_options[key.name] = value
734+
args.cmd_line_options[key] = value
734735
delattr(args, name)
735736

736737

mesonbuild/msetup.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[dict] = None) -
193193
'Some other Meson process is already using this build directory. Exiting.'):
194194
return self._generate(env, capture, vslite_ctx)
195195

196-
def check_unused_options(self, coredata: 'coredata.CoreData', cmd_line_options: T.Any, all_subprojects: T.Mapping[str, object]) -> None:
196+
def check_unused_options(self, coredata: 'coredata.CoreData', cmd_line_options: T.Dict[OptionKey, str], all_subprojects: T.Mapping[str, object]) -> None:
197197
pending = coredata.optstore.pending_options
198198
errlist: T.List[str] = []
199199
known_subprojects = all_subprojects.keys()
@@ -202,9 +202,8 @@ def check_unused_options(self, coredata: 'coredata.CoreData', cmd_line_options:
202202
# because they might be used in future reconfigurations
203203
if coredata.optstore.accept_as_pending_option(opt, known_subprojects):
204204
continue
205-
keystr = str(opt)
206-
if keystr in cmd_line_options:
207-
errlist.append(f'"{keystr}"')
205+
if opt in cmd_line_options:
206+
errlist.append(f'"{opt}"')
208207
if errlist:
209208
errstr = ', '.join(errlist)
210209
raise MesonException(f'Unknown options: {errstr}')
@@ -348,17 +347,18 @@ def run_genvslite_setup(options: CMDOptions) -> None:
348347
# invoke the appropriate 'meson compile ...' build commands upon the normal visual studio build/rebuild/clean actions, instead of using
349348
# the native VS/msbuild system.
350349
builddir_prefix = options.builddir
351-
genvsliteval = options.cmd_line_options.pop('genvslite') # type: ignore [call-overload]
350+
k_genvslite = OptionKey('genvslite')
351+
genvsliteval = options.cmd_line_options.pop(k_genvslite)
352352
# The command line may specify a '--backend' option, which doesn't make sense in conjunction with
353353
# '--genvslite', where we always want to use a ninja back end -
354-
k_backend = 'backend'
354+
k_backend = OptionKey('backend')
355355
if k_backend in options.cmd_line_options.keys():
356-
if options.cmd_line_options[k_backend] != 'ninja': # type: ignore [index]
356+
if options.cmd_line_options[k_backend] != 'ninja':
357357
raise MesonException('Explicitly specifying a backend option with \'genvslite\' is not necessary '
358358
'(the ninja backend is always used) but specifying a non-ninja backend '
359359
'conflicts with a \'genvslite\' setup')
360360
else:
361-
options.cmd_line_options[k_backend] = 'ninja' # type: ignore [index]
361+
options.cmd_line_options[k_backend] = 'ninja'
362362
buildtypes_list = coredata.get_genvs_default_buildtype_list()
363363
vslite_ctx = {}
364364

@@ -369,7 +369,7 @@ def run_genvslite_setup(options: CMDOptions) -> None:
369369
vslite_ctx[buildtypestr] = app.generate(capture=True)
370370
#Now for generating the 'lite' solution and project files, which will use these builds we've just set up, above.
371371
options.builddir = f'{builddir_prefix}_vs'
372-
options.cmd_line_options[OptionKey('genvslite')] = genvsliteval
372+
options.cmd_line_options[k_genvslite] = genvsliteval
373373
app = MesonApp(options)
374374
app.generate(capture=False, vslite_ctx=vslite_ctx)
375375

@@ -385,7 +385,7 @@ def run(options: T.Union[CMDOptions, T.List[str]]) -> int:
385385
# lie
386386
options.pager = False
387387

388-
if 'genvslite' in options.cmd_line_options.keys():
388+
if OptionKey('genvslite') in options.cmd_line_options.keys():
389389
run_genvslite_setup(options)
390390
else:
391391
app = MesonApp(options)

0 commit comments

Comments
 (0)