aboutsummaryrefslogtreecommitdiff
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
parent629abd6b95e131e2c7d70b2bec01d29e0917eefd (diff)
downloadmeson-optionrefactor.zip
meson-optionrefactor.tar.gz
meson-optionrefactor.tar.bz2
Refactor getting target options to a dedicated method.optionrefactor
-rw-r--r--mesonbuild/backend/backends.py28
-rw-r--r--mesonbuild/backend/ninjabackend.py14
-rw-r--r--mesonbuild/backend/vs2010backend.py12
-rw-r--r--mesonbuild/backend/xcodebackend.py6
4 files changed, 36 insertions, 24 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)
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index acd401e..55ef243 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -923,7 +923,7 @@ class NinjaBackend(backends.Backend):
# Generate rules for building the remaining source files in this target
outname = self.get_target_filename(target)
obj_list = []
- is_unity = target.is_unity
+ is_unity = self.is_unity(target)
header_deps = []
unity_src = []
unity_deps = [] # Generated sources that must be built before compiling a Unity target.
@@ -1684,7 +1684,7 @@ class NinjaBackend(backends.Backend):
valac_outputs.append(vala_c_file)
args = self.generate_basic_compiler_args(target, valac)
- args += valac.get_colorout_args(target.get_option(OptionKey('b_colorout')))
+ args += valac.get_colorout_args(self.get_target_option(target, 'b_colorout'))
# Tell Valac to output everything in our private directory. Sadly this
# means it will also preserve the directory components of Vala sources
# found inside the build tree (generated sources).
@@ -1696,7 +1696,7 @@ class NinjaBackend(backends.Backend):
# Outputted header
hname = os.path.join(self.get_target_dir(target), target.vala_header)
args += ['--header', hname]
- if target.is_unity:
+ if self.is_unity(target):
# Without this the declarations will get duplicated in the .c
# files and cause a build failure when all of them are
# #include-d in one .c file.
@@ -1972,8 +1972,8 @@ class NinjaBackend(backends.Backend):
# https://github.com/rust-lang/rust/issues/39016
if not isinstance(target, build.StaticLibrary):
try:
- buildtype = target.get_option(OptionKey('buildtype'))
- crt = target.get_option(OptionKey('b_vscrt'))
+ buildtype = self.get_target_option(target, 'buildtype')
+ crt = self.get_target_option(target, 'b_vscrt')
args += rustc.get_crt_link_args(crt, buildtype)
except KeyError:
pass
@@ -3424,9 +3424,9 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
# Add things like /NOLOGO; usually can't be overridden
commands += linker.get_linker_always_args()
# Add buildtype linker args: optimization level, etc.
- commands += linker.get_optimization_link_args(target.get_option(OptionKey('optimization')))
+ commands += linker.get_optimization_link_args(self.get_target_option(target, 'optimization'))
# Add /DEBUG and the pdb filename when using MSVC
- if target.get_option(OptionKey('debug')):
+ if self.get_target_option(target, 'debug'):
commands += self.get_link_debugfile_args(linker, target)
debugfile = self.get_link_debugfile_name(linker, target)
if debugfile is not None:
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index 20ad266..f4091db 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -1003,7 +1003,7 @@ class Vs2010Backend(backends.Backend):
# Compile args added from the env or cross file: CFLAGS/CXXFLAGS, etc. We want these
# to override all the defaults, but not the per-target compile args.
for l in file_args.keys():
- file_args[l] += target.get_option(OptionKey('args', machine=target.for_machine, lang=l))
+ file_args[l] += self.get_target_option(target, OptionKey('args', machine=target.for_machine, lang=l))
for args in file_args.values():
# This is where Visual Studio will insert target_args, target_defines,
# etc, which are added later from external deps (see below).
@@ -1293,7 +1293,7 @@ class Vs2010Backend(backends.Backend):
if True in ((dep.name == 'openmp') for dep in target.get_external_deps()):
ET.SubElement(clconf, 'OpenMPSupport').text = 'true'
# CRT type; debug or release
- vscrt_type = target.get_option(OptionKey('b_vscrt'))
+ vscrt_type = self.get_target_option(target, 'b_vscrt')
vscrt_val = compiler.get_crt_val(vscrt_type, self.buildtype)
if vscrt_val == 'mdd':
ET.SubElement(type_config, 'UseDebugLibraries').text = 'true'
@@ -1331,7 +1331,7 @@ class Vs2010Backend(backends.Backend):
# Exception handling has to be set in the xml in addition to the "AdditionalOptions" because otherwise
# cl will give warning D9025: overriding '/Ehs' with cpp_eh value
if 'cpp' in target.compilers:
- eh = target.get_option(OptionKey('eh', machine=target.for_machine, lang='cpp'))
+ eh = self.get_target_option(target, OptionKey('eh', machine=target.for_machine, lang='cpp'))
if eh == 'a':
ET.SubElement(clconf, 'ExceptionHandling').text = 'Async'
elif eh == 's':
@@ -1349,10 +1349,10 @@ class Vs2010Backend(backends.Backend):
ET.SubElement(clconf, 'PreprocessorDefinitions').text = ';'.join(target_defines)
ET.SubElement(clconf, 'FunctionLevelLinking').text = 'true'
# Warning level
- warning_level = T.cast('str', target.get_option(OptionKey('warning_level')))
+ warning_level = T.cast('str', self.get_targetoption(target, 'warning_level'))
warning_level = 'EnableAllWarnings' if warning_level == 'everything' else 'Level' + str(1 + int(warning_level))
ET.SubElement(clconf, 'WarningLevel').text = warning_level
- if target.get_option(OptionKey('werror')):
+ if self.get_target_option(target, 'werror'):
ET.SubElement(clconf, 'TreatWarningAsError').text = 'true'
# Optimization flags
o_flags = split_o_flags_args(build_args)
@@ -1525,7 +1525,7 @@ class Vs2010Backend(backends.Backend):
# /nologo
ET.SubElement(link, 'SuppressStartupBanner').text = 'true'
# /release
- if not target.get_option(OptionKey('debug')):
+ if not self.get_target_option(target, 'debug'):
ET.SubElement(link, 'SetChecksum').text = 'true'
# Visual studio doesn't simply allow the src files of a project to be added with the 'Condition=...' attribute,
diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py
index abdac0c..e5ef0dc 100644
--- a/mesonbuild/backend/xcodebackend.py
+++ b/mesonbuild/backend/xcodebackend.py
@@ -1568,7 +1568,7 @@ class XCodeBackend(backends.Backend):
if compiler is None:
continue
# Start with warning args
- warn_args = compiler.get_warn_args(target.get_option(OptionKey('warning_level')))
+ warn_args = compiler.get_warn_args(self.get_target_option(target, 'warning_level'))
copt_proxy = target.get_options()
std_args = compiler.get_option_compile_args(copt_proxy)
# Add compile args added using add_project_arguments()
@@ -1621,9 +1621,9 @@ class XCodeBackend(backends.Backend):
if target.suffix:
suffix = '.' + target.suffix
settings_dict.add_item('EXECUTABLE_SUFFIX', suffix)
- settings_dict.add_item('GCC_GENERATE_DEBUGGING_SYMBOLS', BOOL2XCODEBOOL[target.get_option(OptionKey('debug'))])
+ settings_dict.add_item('GCC_GENERATE_DEBUGGING_SYMBOLS', BOOL2XCODEBOOL[self.get_target_option(target, 'debug')])
settings_dict.add_item('GCC_INLINES_ARE_PRIVATE_EXTERN', 'NO')
- opt_flag = OPT2XCODEOPT[target.get_option(OptionKey('optimization'))]
+ opt_flag = OPT2XCODEOPT[self.get_target:option(target, 'optimization')]
if opt_flag is not None:
settings_dict.add_item('GCC_OPTIMIZATION_LEVEL', opt_flag)
if target.has_pch: