aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/backends.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2024-04-14 13:42:38 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2024-04-14 13:42:38 +0300
commit8a5dfed0268aa71d866015da00a68ff9a3938baa (patch)
tree3f99b725211f83fc34e875b8a70e775962d115d9 /mesonbuild/backend/backends.py
parent629abd6b95e131e2c7d70b2bec01d29e0917eefd (diff)
downloadmeson-optionrefactor.zip
meson-optionrefactor.tar.gz
meson-optionrefactor.tar.bz2
Refactor getting target options to a dedicated method.optionrefactor
Diffstat (limited to 'mesonbuild/backend/backends.py')
-rw-r--r--mesonbuild/backend/backends.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index af730f8..8098b21 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -420,7 +420,7 @@ class Backend:
abs_files: T.List[str] = []
result: T.List[mesonlib.File] = []
compsrcs = classify_unity_sources(target.compilers.values(), unity_src)
- unity_size = target.get_option(OptionKey('unity_size'))
+ unity_size = self.get_target_option(target, 'unity_size')
assert isinstance(unity_size, int), 'for mypy'
def init_language_file(suffix: str, unity_file_number: int) -> T.TextIO:
@@ -905,7 +905,7 @@ class Backend:
# With unity builds, sources don't map directly to objects,
# we only support extracting all the objects in this mode,
# so just return all object files.
- if extobj.target.is_unity:
+ if self.is_unity(extobj.target):
compsrcs = classify_unity_sources(extobj.target.compilers.values(), sources)
sources = []
unity_size = extobj.target.get_option(OptionKey('unity_size'))
@@ -961,7 +961,7 @@ class Backend:
def target_uses_pch(self, target: build.BuildTarget) -> bool:
try:
- return T.cast('bool', target.get_option(OptionKey('b_pch')))
+ return T.cast('bool', self.get_target_option(target, 'b_pch'))
except KeyError:
return False
@@ -995,22 +995,22 @@ class Backend:
# Add things like /NOLOGO or -pipe; usually can't be overridden
commands += compiler.get_always_args()
# warning_level is a string, but mypy can't determine that
- commands += compiler.get_warn_args(T.cast('str', target.get_option(OptionKey('warning_level'))))
+ commands += compiler.get_warn_args(T.cast('str', self.get_target_option(target, 'warning_level')))
# Add -Werror if werror=true is set in the build options set on the
# command-line or default_options inside project(). This only sets the
# action to be done for warnings if/when they are emitted, so it's ok
# to set it after or get_warn_args().
- if target.get_option(OptionKey('werror')):
+ if self.get_target_option(target, 'werror'):
commands += compiler.get_werror_args()
# Add compile args for c_* or cpp_* build options set on the
# command-line or default_options inside project().
commands += compiler.get_option_compile_args(copt_proxy)
- optimization = target.get_option(OptionKey('optimization'))
+ optimization = self.get_target_option(target, 'optimization')
assert isinstance(optimization, str), 'for mypy'
commands += compiler.get_optimization_args(optimization)
- debug = target.get_option(OptionKey('debug'))
+ debug = self.get_target_option(target, 'debug')
assert isinstance(debug, bool), 'for mypy'
commands += compiler.get_debug_args(debug)
@@ -1720,7 +1720,7 @@ class Backend:
# TODO: Create GNUStrip/AppleStrip/etc. hierarchy for more
# fine-grained stripping of static archives.
can_strip = not isinstance(t, build.StaticLibrary)
- should_strip = can_strip and t.get_option(OptionKey('strip'))
+ should_strip = can_strip and self.get_target_option(t, 'strip')
assert isinstance(should_strip, bool), 'for mypy'
# Install primary build output (library/executable/jar, etc)
# Done separately because of strip/aliases/rpath
@@ -2045,3 +2045,15 @@ class Backend:
all_sources = T.cast('_ALL_SOURCES_TYPE', target.sources) + T.cast('_ALL_SOURCES_TYPE', target.generated)
return self.compiler_to_generator(target, target.compiler, all_sources,
target.output_templ, target.depends)
+
+ def is_unity(self, target):
+ return target.is_unity2
+
+ def get_target_option(self, target, name):
+ if isinstance(name, str):
+ key = OptionKey(name)
+ elif isinstance(name, OptionKey):
+ key = name
+ else:
+ sys.exit('Internal error: invalid option type')
+ return target.get_option2(key)