Skip to content

Commit 175ed05

Browse files
committed
coredata: remove get_option_for_subproject
This is just a wrapper around `OptionStore.get_option_for`, but without taking an `OptionKey`. This complicates the subproject passing, since `OptionKey` is designed to encapsulate the option name and subproject.
1 parent 6270123 commit 175ed05

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

mesonbuild/compilers/compilers.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ def are_asserts_disabled(target: 'BuildTarget', env: 'Environment') -> bool:
280280
(env.coredata.get_option_for_target(target, 'b_ndebug') == 'if-release' and
281281
env.coredata.get_option_for_target(target, 'buildtype') in {'release', 'plain'}))
282282

283+
283284
def are_asserts_disabled_for_subproject(subproject: str, env: 'Environment') -> bool:
284-
return (env.coredata.get_option_for_subproject('b_ndebug', subproject) == 'true' or
285-
(env.coredata.get_option_for_subproject('b_ndebug', subproject) == 'if-release' and
286-
env.coredata.get_option_for_subproject('buildtype', subproject) in {'release', 'plain'}))
285+
key = OptionKey('b_ndebug', subproject)
286+
return (env.coredata.optstore.get_value_for(key) == 'true' or
287+
(env.coredata.optstore.get_value_for(key) == 'if-release' and
288+
env.coredata.optstore.get_value_for(key.evolve(name='buildtype')) in {'release', 'plain'}))
287289

288290

289291
def get_base_compile_args(target: 'BuildTarget', compiler: 'Compiler', env: 'Environment') -> T.List[str]:
@@ -1400,7 +1402,7 @@ def get_compileropt_value(self,
14001402
if target:
14011403
return env.coredata.get_option_for_target(target, key)
14021404
else:
1403-
return env.coredata.get_option_for_subproject(key, subproject)
1405+
return env.coredata.optstore.get_value_for(key.evolve(subproject=subproject))
14041406

14051407
def _update_language_stds(self, opts: MutableKeyedOptionDictType, value: T.List[str]) -> None:
14061408
key = self.form_compileropt_key('std')

mesonbuild/compilers/cpp.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,11 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
764764

765765
def get_option_link_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
766766
# need a typeddict for this
767-
key = self.form_compileropt_key('winlibs')
767+
key = self.form_compileropt_key('winlibs').evolve(subproject=subproject)
768768
if target:
769769
value = env.coredata.get_option_for_target(target, key)
770770
else:
771-
value = env.coredata.get_option_for_subproject(key, subproject)
771+
value = env.coredata.optstore.get_value_for(key)
772772
return T.cast('T.List[str]', value)[:]
773773

774774
def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType':
@@ -845,11 +845,11 @@ def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', sub
845845
# which means setting the C++ standard version to C++14, in compilers that support it
846846
# (i.e., after VS2015U3)
847847
# if one is using anything before that point, one cannot set the standard.
848-
stdkey = self.form_compileropt_key('std')
848+
stdkey = self.form_compileropt_key('std').evolve(subproject=subproject)
849849
if target is not None:
850850
std = env.coredata.get_option_for_target(target, stdkey)
851851
else:
852-
std = env.coredata.get_option_for_subproject(stdkey, subproject)
852+
std = env.coredata.optstore.get_value_for(stdkey)
853853
if std in {'vc++11', 'c++11'}:
854854
mlog.warning(self.id, 'does not support C++11;',
855855
'attempting best effort; setting the standard to C++14',

mesonbuild/compilers/cuda.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,11 @@ def get_ccbin_args(self,
794794
target: 'T.Optional[BuildTarget]',
795795
env: 'Environment',
796796
subproject: T.Optional[str] = None) -> T.List[str]:
797-
key = self.form_compileropt_key('ccbindir')
797+
key = self.form_compileropt_key('ccbindir').evolve(subproject=subproject)
798798
if target:
799799
ccbindir = env.coredata.get_option_for_target(target, key)
800800
else:
801-
ccbindir = env.coredata.get_option_for_subproject(key, subproject)
801+
ccbindir = env.coredata.optstore.get_value_for(key)
802802
if isinstance(ccbindir, str) and ccbindir != '':
803803
return [self._shield_nvcc_list_arg('-ccbin='+ccbindir, False)]
804804
else:

mesonbuild/compilers/mixins/elbrus.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# Copyright © 2023-2024 Intel Corporation
2+
# Copyright © 2023-2025 Intel Corporation
33

44
from __future__ import annotations
55

@@ -85,11 +85,11 @@ def get_pch_suffix(self) -> str:
8585

8686
def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
8787
args: T.List[str] = []
88-
key = OptionKey(f'{self.language}_std', machine=self.for_machine)
88+
key = OptionKey(f'{self.language}_std', subproject=subproject, machine=self.for_machine)
8989
if target:
9090
std = env.coredata.get_option_for_target(target, key)
9191
else:
92-
std = env.coredata.get_option_for_subproject(key, subproject)
92+
std = env.coredata.optstore.get_value_for(key)
9393
assert isinstance(std, str)
9494
if std != 'none':
9595
args.append('-std=' + std)

mesonbuild/compilers/objc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_
7878

7979
def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
8080
args: T.List[str] = []
81-
key = OptionKey('c_std', machine=self.for_machine)
81+
key = OptionKey('c_std', subproject=subproject, machine=self.for_machine)
8282
if target:
8383
std = env.coredata.get_option_for_target(target, key)
8484
else:
85-
std = env.coredata.get_option_for_subproject(key, subproject)
85+
std = env.coredata.optstore.get_value_for(key)
8686
assert isinstance(std, str)
8787
if std != 'none':
8888
args.append('-std=' + std)

mesonbuild/compilers/objcpp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_
8383

8484
def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
8585
args: T.List[str] = []
86-
key = OptionKey('cpp_std', machine=self.for_machine)
86+
key = OptionKey('cpp_std', subproject=subproject, machine=self.for_machine)
8787
if target:
8888
std = env.coredata.get_option_for_target(target, key)
8989
else:
90-
std = env.coredata.get_option_for_subproject(key, subproject)
90+
std = env.coredata.optstore.get_value_for(key)
9191
assert isinstance(std, str)
9292
if std != 'none':
9393
args.append('-std=' + std)

mesonbuild/coredata.py

-8
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,6 @@ def get_option_for_target(self, target: 'BuildTarget', key: T.Union[str, OptionK
414414
return option_object.validate_value(override)
415415
return value
416416

417-
def get_option_for_subproject(self, key: T.Union[str, OptionKey], subproject) -> ElementaryOptionValues:
418-
if isinstance(key, str):
419-
key = OptionKey(key, subproject=subproject)
420-
if key.subproject != subproject:
421-
# This should be an error, fix before merging.
422-
key = key.evolve(subproject=subproject)
423-
return self.optstore.get_value_for(key)
424-
425417
def set_option(self, key: OptionKey, value, first_invocation: bool = False) -> bool:
426418
dirty = False
427419
try:

0 commit comments

Comments
 (0)