Skip to content

Commit

Permalink
options: rename get_value_safe -> get_value and get_value -> get_valu…
Browse files Browse the repository at this point in the history
…e_unsafe

Because using the safe variant should be the default option, and the
unsafe should be a "I really know what I'm doing"
  • Loading branch information
dcbaker committed Jan 30, 2025
1 parent 502f3e4 commit fe33d21
Show file tree
Hide file tree
Showing 30 changed files with 168 additions and 168 deletions.
12 changes: 6 additions & 6 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[T.Dict] = None)
outfile.write('# Do not edit by hand.\n\n')
outfile.write('ninja_required_version = 1.8.2\n\n')

num_pools = self.environment.coredata.optstore.get_value_safe('backend_max_links', int)
num_pools = self.environment.coredata.optstore.get_value('backend_max_links', int)
if num_pools > 0:
outfile.write(f'''pool link_pool
depth = {num_pools}
Expand Down Expand Up @@ -672,7 +672,7 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[T.Dict] = None)
mlog.log_timestamp("Dist generated")
key = OptionKey('b_coverage')
if (key in self.environment.coredata.optstore and
self.environment.coredata.optstore.get_value_safe(key, bool)):
self.environment.coredata.optstore.get_value(key, bool)):
gcovr_exe, gcovr_version, lcov_exe, lcov_version, genhtml_exe, llvm_cov_exe = environment.find_coverage_tools(self.environment.coredata)
mlog.debug(f'Using {gcovr_exe} ({gcovr_version}), {lcov_exe} and {llvm_cov_exe} for code coverage')
if gcovr_exe or (lcov_exe and genhtml_exe):
Expand Down Expand Up @@ -2325,7 +2325,7 @@ def _rsp_options(self, tool: T.Union['Compiler', 'StaticLinker', 'DynamicLinker'
return options

def generate_static_link_rules(self) -> None:
num_pools = self.environment.coredata.optstore.get_value_safe('backend_max_links', int)
num_pools = self.environment.coredata.optstore.get_value('backend_max_links', int)
if 'java' in self.environment.coredata.compilers.host:
self.generate_java_link()
for for_machine in MachineChoice:
Expand Down Expand Up @@ -2373,7 +2373,7 @@ def generate_static_link_rules(self) -> None:
self.add_rule(NinjaRule(rule, cmdlist, args, description, **options, extra=pool))

def generate_dynamic_link_rules(self) -> None:
num_pools = self.environment.coredata.optstore.get_value_safe('backend_max_links', int)
num_pools = self.environment.coredata.optstore.get_value('backend_max_links', int)
for for_machine in MachineChoice:
complist = self.environment.coredata.compilers[for_machine]
for langname, compiler in complist.items():
Expand Down Expand Up @@ -3746,7 +3746,7 @@ def generate_clangtool(self, name: str, extra_arg: T.Optional[str] = None) -> No
if extra_arg:
target_name += f'-{extra_arg}'
extra_args.append(f'--{extra_arg}')
colorout = self.environment.coredata.optstore.get_value_safe('b_colorout', str, 'always')
colorout = self.environment.coredata.optstore.get_value('b_colorout', str, 'always')
extra_args.extend(['--color', colorout])
if not os.path.exists(os.path.join(self.environment.source_dir, '.clang-' + name)) and \
not os.path.exists(os.path.join(self.environment.source_dir, '_clang-' + name)):
Expand Down Expand Up @@ -3841,7 +3841,7 @@ def generate_ending(self) -> None:
if ctlist:
elem.add_dep(self.generate_custom_target_clean(ctlist))

if self.environment.coredata.optstore.get_value_safe('b_coverage', bool, False):
if self.environment.coredata.optstore.get_value('b_coverage', bool, False):
self.generate_gcov_clean()
elem.add_dep('clean-gcda')
elem.add_dep('clean-gcno')
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def generate_solution(self, sln_filename: str, projlist: T.List[Project]) -> Non
replace_if_different(sln_filename, sln_filename_tmp)

def generate_projects(self, vslite_ctx: dict = None) -> T.List[Project]:
startup_project = self.environment.coredata.optstore.get_value_safe('backend_startup_project', str)
startup_project = self.environment.coredata.optstore.get_value('backend_startup_project', str)
projlist: T.List[Project] = []
startup_idx = 0
for (i, (name, target)) in enumerate(self.build.targets.items()):
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def get_options(self) -> coredata.OptionsView:
def get_option(self, key: 'OptionKey') -> T.Union[str, int, bool]:
# TODO: if it's possible to annotate get_option or validate_option_value
# in the future we might be able to remove the cast here
return T.cast('T.Union[str, int, bool]', self.options.get_value(key))
return T.cast('T.Union[str, int, bool]', self.options.get_value_unsafe(key))

@staticmethod
def parse_overrides(kwargs: T.Dict[str, T.Any]) -> T.Dict[OptionKey, str]:
Expand Down Expand Up @@ -1263,7 +1263,7 @@ def _extract_pic_pie(self, kwargs: T.Dict[str, T.Any], arg: str, option: str) ->
if kwargs.get(arg) is not None:
val = T.cast('bool', kwargs[arg])
elif k in self.environment.coredata.optstore:
val = self.environment.coredata.optstore.get_value_safe(k, bool)
val = self.environment.coredata.optstore.get_value(k, bool)
else:
val = False

Expand Down Expand Up @@ -1974,7 +1974,7 @@ def __init__(
kwargs):
key = OptionKey('b_pie')
if 'pie' not in kwargs and key in environment.coredata.optstore:
kwargs['pie'] = environment.coredata.optstore.get_value_safe(key, bool)
kwargs['pie'] = environment.coredata.optstore.get_value(key, bool)
super().__init__(name, subdir, subproject, for_machine, sources, structured_sources, objects,
environment, compilers, kwargs)
self.win_subsystem = kwargs.get('win_subsystem') or 'console'
Expand Down Expand Up @@ -2178,7 +2178,7 @@ def post_init(self) -> None:
self.suffix = 'a'
else:
if 'c' in self.compilers and self.compilers['c'].get_id() == 'tasking':
self.suffix = 'ma' if self.options.get_value_safe('b_lto', bool) and not self.prelink else 'a'
self.suffix = 'ma' if self.options.get_value('b_lto', bool) and not self.prelink else 'a'
else:
self.suffix = 'a'
self.filename = self.prefix + self.name + '.' + self.suffix
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/cmake/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
def cmake_is_debug(env: 'Environment') -> bool:
if OptionKey('b_vscrt') in env.coredata.optstore:
is_debug = env.coredata.get_option(OptionKey('buildtype')) == 'debug'
if env.coredata.optstore.get_value_safe('b_vscrt', str) in {'mdd', 'mtd'}:
if env.coredata.optstore.get_value('b_vscrt', str) in {'mdd', 'mtd'}:
is_debug = True
return is_debug
else:
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/cmake/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, environment: 'Environment', version: str, for_machine: Machin
self.cmakebin = None
return

self.prefix_paths = self.environment.coredata.optstore.get_value_safe(OptionKey('cmake_prefix_path', machine=self.for_machine), list)
self.prefix_paths = self.environment.coredata.optstore.get_value(OptionKey('cmake_prefix_path', machine=self.for_machine), list)
if self.prefix_paths:
self.extra_cmake_args += ['-DCMAKE_PREFIX_PATH={}'.format(';'.join(self.prefix_paths))]

Expand Down
32 changes: 16 additions & 16 deletions mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('-std=' + std)
return args
Expand All @@ -142,7 +142,7 @@ def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
if self.info.is_windows() or self.info.is_cygwin():
# without a typedict mypy can't understand this.
key = self.form_compileropt_key('winlibs')
return options.get_value_safe(key, list).copy()
return options.get_value(key, list).copy()
return []


Expand Down Expand Up @@ -218,7 +218,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('-std=' + std)
return args
Expand Down Expand Up @@ -262,15 +262,15 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('-std=' + std)
return args

def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
if self.info.is_windows() or self.info.is_cygwin():
key = self.form_compileropt_key('winlibs')
libs: T.List[str] = options.get_value_safe(key, list).copy()
libs: T.List[str] = options.get_value(key, list).copy()
return libs
return []

Expand Down Expand Up @@ -380,7 +380,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('-std=' + std)
return args
Expand All @@ -407,7 +407,7 @@ def get_options(self) -> MutableKeyedOptionDictType:
def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
# need a TypeDict to make this work
key = self.form_compileropt_key('winlibs')
return options.get_value_safe(key, list).copy()
return options.get_value(key, list).copy()


class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
Expand Down Expand Up @@ -440,7 +440,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
# As of MVSC 16.8, /std:c11 and /std:c17 are the only valid C standard options.
if std == 'c11':
args.append('/std:c11')
Expand All @@ -461,7 +461,7 @@ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoic

def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != "none":
return [f'/clang:-std={std}']
return []
Expand Down Expand Up @@ -494,7 +494,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std == 'c89':
mlog.log("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.", once=True)
elif std != 'none':
Expand Down Expand Up @@ -528,7 +528,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('--' + std)
return args
Expand Down Expand Up @@ -561,7 +561,7 @@ def get_no_stdinc_args(self) -> T.List[str]:
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std == 'c89':
args.append('-lang=c')
elif std == 'c99':
Expand Down Expand Up @@ -609,7 +609,7 @@ def get_no_stdinc_args(self) -> T.List[str]:
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('-ansi')
args.append('-std=' + std)
Expand Down Expand Up @@ -693,7 +693,7 @@ def get_no_stdinc_args(self) -> T.List[str]:
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('--' + std)
return args
Expand Down Expand Up @@ -727,7 +727,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('-lang')
args.append(std)
Expand Down Expand Up @@ -755,7 +755,7 @@ def get_options(self) -> 'MutableKeyedOptionDictType':
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = []
key = self.form_compileropt_key('std')
std = options.get_value_safe(key, str)
std = options.get_value(key, str)
if std != 'none':
args.append('-lang ' + std)
return args
Expand Down
48 changes: 24 additions & 24 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType',
try:
if option not in boptions:
return False
return options.get_value_safe(option, bool) # could also be str?
return options.get_value(option, bool) # could also be str?
except KeyError:
return False

Expand All @@ -272,38 +272,38 @@ def are_asserts_disabled(options: KeyedOptionDictType) -> bool:
:param options: OptionDictionary
:return: whether to disable assertions or not
"""
return (options.get_value_safe('b_ndebug', str) == 'true' or
(options.get_value_safe('b_ndebug', str) == 'if-release' and
options.get_value_safe('buildtype', str) in {'release', 'plain'}))
return (options.get_value('b_ndebug', str) == 'true' or
(options.get_value('b_ndebug', str) == 'if-release' and
options.get_value('buildtype', str) in {'release', 'plain'}))


def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler', env: 'Environment') -> T.List[str]:
args: T.List[str] = []
try:
if options.get_value_safe(OptionKey('b_lto'), bool):
if options.get_value(OptionKey('b_lto'), bool):
args.extend(compiler.get_lto_compile_args(
threads=options.get_value_safe(OptionKey('b_lto_threads'), int, 0),
mode=options.get_value_safe(OptionKey('b_lto_mode'), str, 'default')))
threads=options.get_value(OptionKey('b_lto_threads'), int, 0),
mode=options.get_value(OptionKey('b_lto_mode'), str, 'default')))
except (KeyError, AttributeError):
pass
try:
args += compiler.get_colorout_args(options.get_value_safe(OptionKey('b_colorout'), str))
args += compiler.get_colorout_args(options.get_value(OptionKey('b_colorout'), str))
except (KeyError, AttributeError):
pass
try:
args += compiler.sanitizer_compile_args(options.get_value_safe(OptionKey('b_sanitize'), str))
args += compiler.sanitizer_compile_args(options.get_value(OptionKey('b_sanitize'), str))
except (KeyError, AttributeError):
pass
try:
pgo_val = options.get_value_safe(OptionKey('b_pgo'), str)
pgo_val = options.get_value(OptionKey('b_pgo'), str)
if pgo_val == 'generate':
args.extend(compiler.get_profile_generate_args())
elif pgo_val == 'use':
args.extend(compiler.get_profile_use_args())
except (KeyError, AttributeError):
pass
try:
if options.get_value_safe(OptionKey('b_coverage'), bool):
if options.get_value(OptionKey('b_coverage'), bool):
args += compiler.get_coverage_args()
except (KeyError, AttributeError):
pass
Expand All @@ -316,8 +316,8 @@ def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler',
args.append('-fembed-bitcode')
try:
try:
crt_val = options.get_value_safe(OptionKey('b_vscrt'), str)
buildtype = options.get_value_safe(OptionKey('buildtype'), str)
crt_val = options.get_value(OptionKey('b_vscrt'), str)
buildtype = options.get_value(OptionKey('buildtype'), str)
args += compiler.get_crt_compile_args(crt_val, buildtype)
except AttributeError:
pass
Expand All @@ -329,35 +329,35 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
is_shared_module: bool, build_dir: str) -> T.List[str]:
args: T.List[str] = []
try:
if options.get_value_safe('b_lto', bool):
if options.get_value_safe('werror', bool):
if options.get_value('b_lto', bool):
if options.get_value('werror', bool):
args.extend(linker.get_werror_args())

thinlto_cache_dir = None
if options.get_value_safe(OptionKey('b_thinlto_cache'), bool, False):
thinlto_cache_dir = options.get_value_safe(OptionKey('b_thinlto_cache_dir'), str, '')
if options.get_value(OptionKey('b_thinlto_cache'), bool, False):
thinlto_cache_dir = options.get_value(OptionKey('b_thinlto_cache_dir'), str, '')
if thinlto_cache_dir == '':
thinlto_cache_dir = os.path.join(build_dir, 'meson-private', 'thinlto-cache')
args.extend(linker.get_lto_link_args(
threads=options.get_value_safe(OptionKey('b_lto_threads'), int, 0),
mode=options.get_value_safe(OptionKey('b_lto_mode'), str, 'default'),
threads=options.get_value(OptionKey('b_lto_threads'), int, 0),
mode=options.get_value(OptionKey('b_lto_mode'), str, 'default'),
thinlto_cache_dir=thinlto_cache_dir))
except (KeyError, AttributeError):
pass
try:
args += linker.sanitizer_link_args(options.get_value_safe('b_sanitize', str))
args += linker.sanitizer_link_args(options.get_value('b_sanitize', str))
except (KeyError, AttributeError):
pass
try:
pgo_val = options.get_value_safe('b_pgo', str)
pgo_val = options.get_value('b_pgo', str)
if pgo_val == 'generate':
args.extend(linker.get_profile_generate_args())
elif pgo_val == 'use':
args.extend(linker.get_profile_use_args())
except (KeyError, AttributeError):
pass
try:
if options.get_value_safe('b_coverage', bool):
if options.get_value('b_coverage', bool):
args += linker.get_coverage_link_args()
except (KeyError, AttributeError):
pass
Expand All @@ -384,8 +384,8 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',

try:
try:
crt_val = options.get_value_safe(OptionKey('b_vscrt'), str)
buildtype = options.get_value_safe(OptionKey('buildtype'), str)
crt_val = options.get_value(OptionKey('b_vscrt'), str)
buildtype = options.get_value(OptionKey('buildtype'), str)
args += linker.get_crt_link_args(crt_val, buildtype)
except AttributeError:
pass
Expand Down
Loading

0 comments on commit fe33d21

Please sign in to comment.