Skip to content

Commit

Permalink
coredata: remove get_option_for_subproject
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcbaker committed Mar 5, 2025
1 parent 12e5d0e commit 2f20100
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
10 changes: 6 additions & 4 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,12 @@ def are_asserts_disabled(target: 'BuildTarget', env: 'Environment') -> bool:
(env.coredata.get_option_for_target(target, 'b_ndebug') == 'if-release' and
env.coredata.get_option_for_target(target, 'buildtype') in {'release', 'plain'}))


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


def get_base_compile_args(target: 'BuildTarget', compiler: 'Compiler', env: 'Environment') -> T.List[str]:
Expand Down Expand Up @@ -1386,7 +1388,7 @@ def get_compileropt_value(self,
if target:
return env.coredata.get_option_for_target(target, key)
else:
return env.coredata.get_option_for_subproject(key, subproject)
return env.coredata.optstore.get_value_for(key.evolve(subproject=subproject))

def _update_language_stds(self, opts: MutableKeyedOptionDictType, value: T.List[str]) -> None:
key = self.form_compileropt_key('std')
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,11 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):

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

def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType':
Expand Down Expand Up @@ -845,11 +845,11 @@ def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', sub
# which means setting the C++ standard version to C++14, in compilers that support it
# (i.e., after VS2015U3)
# if one is using anything before that point, one cannot set the standard.
stdkey = self.form_compileropt_key('std')
stdkey = self.form_compileropt_key('std').evolve(subproject=subproject)
if target is not None:
std = env.coredata.get_option_for_target(target, stdkey)
else:
std = env.coredata.get_option_for_subproject(stdkey, subproject)
std = env.coredata.optstore.get_value_for(stdkey)
if std in {'vc++11', 'c++11'}:
mlog.warning(self.id, 'does not support C++11;',
'attempting best effort; setting the standard to C++14',
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,11 @@ def get_ccbin_args(self,
target: 'T.Optional[BuildTarget]',
env: 'Environment',
subproject: T.Optional[str] = None) -> T.List[str]:
key = self.form_compileropt_key('ccbindir')
key = self.form_compileropt_key('ccbindir').evolve(subproject=subproject)
if target:
ccbindir = env.coredata.get_option_for_target(target, key)
else:
ccbindir = env.coredata.get_option_for_subproject(key, subproject)
ccbindir = env.coredata.optstore.get_value_for(key)
if isinstance(ccbindir, str) and ccbindir != '':
return [self._shield_nvcc_list_arg('-ccbin='+ccbindir, False)]
else:
Expand Down
6 changes: 3 additions & 3 deletions mesonbuild/compilers/mixins/elbrus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2023-2024 Intel Corporation
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations

Expand Down Expand Up @@ -85,11 +85,11 @@ def get_pch_suffix(self) -> str:

def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
args: T.List[str] = []
key = OptionKey(f'{self.language}_std', machine=self.for_machine)
key = OptionKey(f'{self.language}_std', subproject=subproject, machine=self.for_machine)
if target:
std = env.coredata.get_option_for_target(target, key)
else:
std = env.coredata.get_option_for_subproject(key, subproject)
std = env.coredata.optstore.get_value_for(key)
assert isinstance(std, str)
if std != 'none':
args.append('-std=' + std)
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/objc.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_

def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
args: T.List[str] = []
key = OptionKey('c_std', machine=self.for_machine)
key = OptionKey('c_std', subproject=subproject, machine=self.for_machine)
if target:
std = env.coredata.get_option_for_target(target, key)
else:
std = env.coredata.get_option_for_subproject(key, subproject)
std = env.coredata.optstore.get_value_for(key)
assert isinstance(std, str)
if std != 'none':
args.append('-std=' + std)
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/objcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_

def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]:
args: T.List[str] = []
key = OptionKey('cpp_std', machine=self.for_machine)
key = OptionKey('cpp_std', subproject=subproject, machine=self.for_machine)
if target:
std = env.coredata.get_option_for_target(target, key)
else:
std = env.coredata.get_option_for_subproject(key, subproject)
std = env.coredata.optstore.get_value_for(key)
assert isinstance(std, str)
if std != 'none':
args.append('-std=' + std)
Expand Down
8 changes: 0 additions & 8 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,6 @@ def get_option_for_target(self, target: 'BuildTarget', key: T.Union[str, OptionK
return option_object.validate_value(override)
return value

def get_option_for_subproject(self, key: T.Union[str, OptionKey], subproject) -> ElementaryOptionValues:
if isinstance(key, str):
key = OptionKey(key, subproject=subproject)
if key.subproject != subproject:
# This should be an error, fix before merging.
key = key.evolve(subproject=subproject)
return self.optstore.get_value_for(key)

def set_option(self, key: OptionKey, value, first_invocation: bool = False) -> bool:
dirty = False
try:
Expand Down

0 comments on commit 2f20100

Please sign in to comment.