summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/compilers.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2024-06-09 01:03:49 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2024-06-14 17:19:53 +0300
commit9a6fcd4d9a0c7bb248c5d0587632b741a3301e03 (patch)
treef066ab0ee942d2f12579bb075cb3afbdf3386f0b /mesonbuild/compilers/compilers.py
parentc0d86024f5e647858f88bc400b45b3ad88a25c97 (diff)
downloadmeson-9a6fcd4d9a0c7bb248c5d0587632b741a3301e03.tar.gz
Replace direct indexing with named methods.
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
-rw-r--r--mesonbuild/compilers/compilers.py60
1 files changed, 30 insertions, 30 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index ef0ea70f7..1e386bbbb 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -254,7 +254,7 @@ def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType',
try:
if option not in boptions:
return False
- ret = options[option].value
+ ret = options.get_value(option)
assert isinstance(ret, bool), 'must return bool' # could also be str
return ret
except KeyError:
@@ -264,8 +264,8 @@ def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType',
def get_option_value(options: 'KeyedOptionDictType', opt: OptionKey, fallback: '_T') -> '_T':
"""Get the value of an option, or the fallback value."""
try:
- v: '_T' = options[opt].value
- except KeyError:
+ v: '_T' = options.get_value(opt)
+ except (KeyError, AttributeError):
return fallback
assert isinstance(v, type(fallback)), f'Should have {type(fallback)!r} but was {type(v)!r}'
@@ -279,52 +279,52 @@ def are_asserts_disabled(options: KeyedOptionDictType) -> bool:
:param options: OptionDictionary
:return: whether to disable assertions or not
"""
- return (options[OptionKey('b_ndebug')].value == 'true' or
- (options[OptionKey('b_ndebug')].value == 'if-release' and
- options[OptionKey('buildtype')].value in {'release', 'plain'}))
+ return (options.get_value('b_ndebug') == 'true' or
+ (options.get_value('b_ndebug') == 'if-release' and
+ options.get_value('buildtype') in {'release', 'plain'}))
def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler', env: 'Environment') -> T.List[str]:
args: T.List[str] = []
try:
- if options[OptionKey('b_lto')].value:
+ if options.get_value(OptionKey('b_lto')):
args.extend(compiler.get_lto_compile_args(
threads=get_option_value(options, OptionKey('b_lto_threads'), 0),
mode=get_option_value(options, OptionKey('b_lto_mode'), 'default')))
- except KeyError:
+ except (KeyError, AttributeError):
pass
try:
- args += compiler.get_colorout_args(options[OptionKey('b_colorout')].value)
- except KeyError:
+ args += compiler.get_colorout_args(options.get_value(OptionKey('b_colorout')))
+ except (KeyError, AttributeError):
pass
try:
- args += compiler.sanitizer_compile_args(options[OptionKey('b_sanitize')].value)
- except KeyError:
+ args += compiler.sanitizer_compile_args(options.get_value(OptionKey('b_sanitize')))
+ except (KeyError, AttributeError):
pass
try:
- pgo_val = options[OptionKey('b_pgo')].value
+ pgo_val = options.get_value(OptionKey('b_pgo'))
if pgo_val == 'generate':
args.extend(compiler.get_profile_generate_args())
elif pgo_val == 'use':
args.extend(compiler.get_profile_use_args())
- except KeyError:
+ except (KeyError, AttributeError):
pass
try:
- if options[OptionKey('b_coverage')].value:
+ if options.get_value(OptionKey('b_coverage')):
args += compiler.get_coverage_args()
- except KeyError:
+ except (KeyError, AttributeError):
pass
try:
args += compiler.get_assert_args(are_asserts_disabled(options), env)
- except KeyError:
+ except (KeyError, AttributeError):
pass
# This does not need a try...except
if option_enabled(compiler.base_options, options, OptionKey('b_bitcode')):
args.append('-fembed-bitcode')
try:
- crt_val = options[OptionKey('b_vscrt')].value
- buildtype = options[OptionKey('buildtype')].value
try:
+ crt_val = options.get_value(OptionKey('b_vscrt'))
+ buildtype = options.get_value(OptionKey('buildtype'))
args += compiler.get_crt_compile_args(crt_val, buildtype)
except AttributeError:
pass
@@ -336,8 +336,8 @@ 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[OptionKey('b_lto')].value:
- if options[OptionKey('werror')].value:
+ if options.get_value('b_lto'):
+ if options.get_value('werror'):
args.extend(linker.get_werror_args())
thinlto_cache_dir = None
@@ -349,24 +349,24 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
threads=get_option_value(options, OptionKey('b_lto_threads'), 0),
mode=get_option_value(options, OptionKey('b_lto_mode'), 'default'),
thinlto_cache_dir=thinlto_cache_dir))
- except KeyError:
+ except (KeyError, AttributeError):
pass
try:
- args += linker.sanitizer_link_args(options[OptionKey('b_sanitize')].value)
- except KeyError:
+ args += linker.sanitizer_link_args(options.get_value('b_sanitize'))
+ except (KeyError, AttributeError):
pass
try:
- pgo_val = options[OptionKey('b_pgo')].value
+ pgo_val = options.get_value('b_pgo')
if pgo_val == 'generate':
args.extend(linker.get_profile_generate_args())
elif pgo_val == 'use':
args.extend(linker.get_profile_use_args())
- except KeyError:
+ except (KeyError, AttributeError):
pass
try:
- if options[OptionKey('b_coverage')].value:
+ if options.get_value('b_coverage'):
args += linker.get_coverage_link_args()
- except KeyError:
+ except (KeyError, AttributeError):
pass
as_needed = option_enabled(linker.base_options, options, OptionKey('b_asneeded'))
@@ -390,9 +390,9 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler',
args.extend(linker.get_allow_undefined_link_args())
try:
- crt_val = options[OptionKey('b_vscrt')].value
- buildtype = options[OptionKey('buildtype')].value
try:
+ crt_val = options.get_value(OptionKey('b_vscrt'))
+ buildtype = options.get_value(OptionKey('buildtype'))
args += linker.get_crt_link_args(crt_val, buildtype)
except AttributeError:
pass