Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5fffd56
modules/gnome: Fix annotations of GenerateGir
dcbaker Apr 6, 2026
aecb028
compilers: Don't pass Environment into compiler methods
dcbaker Apr 3, 2026
c41b0ce
options: Move get_option_for_target to Options
dcbaker Mar 11, 2026
37d9e4f
Use the OptionStore version of get_option_for_target
dcbaker Mar 11, 2026
1926548
coredata: use Language for get_language_args and _link_args
dcbaker Mar 11, 2026
aeaf31c
options: move get_external_args and _link_args to Options
dcbaker Mar 11, 2026
fd1280c
Use OptionStore.get_external_args
dcbaker Mar 11, 2026
a8178ac
Use OptionStore.get_external_link_args
dcbaker Mar 11, 2026
ca3a11c
options: Rename option getters to _untyped
dcbaker Mar 11, 2026
c96cef4
options: Add type safe getters for option values
dcbaker Mar 11, 2026
7b8b692
Options: Add default value for safe getters
dcbaker Mar 11, 2026
1d8fcc9
make use of type safe get_value_for
dcbaker Mar 11, 2026
5415f9a
modules: replace state.get_option with OptionStore type safe getters
dcbaker Mar 11, 2026
eb04331
Make use of type safe get_option_for_target
dcbaker Mar 11, 2026
dbccdcc
options: Add a getter for a maybe target
dcbaker Mar 11, 2026
247f085
compilers: Fix the signature of get_option_{std,compile,link}_args
dcbaker Mar 11, 2026
1ef2408
compilers: Add a subproject parameter to the `form_compileropt_key` m…
dcbaker Mar 12, 2026
2114f5b
compilers: Replace get_compileropt_value with direct optstore calls
dcbaker Mar 12, 2026
711defa
backend: delete get_target_option
dcbaker Mar 12, 2026
cdf0fa9
compilers: replace get_option_value_for_target with OptionStore methods
dcbaker Mar 12, 2026
2958e54
compilers: Use get_option_for_maybe_target
dcbaker Apr 3, 2026
12bbf92
compilers: Remove option_enabled
dcbaker Apr 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mesonbuild/ast/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def build_target(self, node: BaseNode, args: T.List[TYPE_var], kwargs_raw: T.Dic
return new_target

def build_library(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Dict[str, TYPE_var]) -> T.Union[IntrospectionBuildTarget, UnknownValue]:
default_library = self.coredata.optstore.get_value_for(OptionKey('default_library', subproject=self.subproject))
default_library = self.coredata.optstore.get_value_for(OptionKey('default_library', subproject=self.subproject), str)
if default_library == 'shared':
return self.build_target(node, args, kwargs, SharedLibrary)
elif default_library == 'static':
Expand Down
64 changes: 25 additions & 39 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .. import compilers
from ..compilers import detect, lang_suffixes
from ..mesonlib import (
File, MachineChoice, MesonException, MesonBugException, OrderedSet,
File, MachineChoice, MesonException, OrderedSet,
ExecutableSerialisation, EnvironmentException,
classify_unity_sources, get_compiler_for_source,
get_rsp_threshold, unique_list
Expand All @@ -43,7 +43,6 @@
from ..interpreter import Test
from ..linkers.linkers import StaticLinker
from ..mesonlib import FileMode, FileOrString
from ..options import ElementaryOptionValues

from typing_extensions import Literal, TypedDict, NotRequired

Expand Down Expand Up @@ -379,7 +378,7 @@ def get_target_dir(self, target: build.AnyTargetType) -> str:
if isinstance(target, build.RunTarget):
# this produces no output, only a dummy top-level name
dirname = ''
elif self.environment.coredata.optstore.get_value_for(OptionKey('layout')) == 'mirror':
elif self.environment.coredata.optstore.get_value_for(OptionKey('layout'), str) == 'mirror':
dirname = target.get_builddir()
else:
dirname = 'meson-out'
Expand Down Expand Up @@ -438,8 +437,7 @@ def generate_unity_files(self, target: build.BuildTarget, unity_src: str) -> T.L
abs_files: T.List[str] = []
result: T.List[mesonlib.File] = []
compsrcs = classify_unity_sources(target.compilers.values(), unity_src)
unity_size = self.get_target_option(target, 'unity_size')
assert isinstance(unity_size, int), 'for mypy'
unity_size = self.environment.coredata.optstore.get_option_for_target(target, OptionKey('unity_size'), int)

def init_language_file(suffix: str, unity_file_number: int) -> T.TextIO:
unity_src = self.get_unity_source_file(target, suffix, unity_file_number)
Expand Down Expand Up @@ -801,7 +799,7 @@ def object_filename_from_source(self, target: build.BuildTarget, compiler: Compi
object_suffix = machine.get_object_suffix()
# For the TASKING compiler, in case of LTO or prelinking the object suffix has to be .mil
if compiler.get_id() == 'tasking':
use_lto = self.get_target_option(target, 'b_lto')
use_lto = self.environment.coredata.optstore.get_option_for_target(target, OptionKey('b_lto'), bool)
if use_lto or (isinstance(target, build.StaticLibrary) and target.prelink):
if not source.rsplit('.', 1)[1] in lang_suffixes['c']:
if isinstance(target, build.StaticLibrary) and not target.prelink:
Expand Down Expand Up @@ -853,8 +851,8 @@ def _determine_ext_objs(self, extobj: 'build.ExtractedObjects') -> T.List[str]:
if self.is_unity(extobj.target):
compsrcs = classify_unity_sources(extobj.target.compilers.values(), sources)
sources = []
unity_size = self.get_target_option(extobj.target, 'unity_size')
assert isinstance(unity_size, int), 'for mypy'
unity_size = self.environment.coredata.optstore.get_option_for_target(
extobj.target, OptionKey('unity_size'), int)

for comp, srcs in compsrcs.items():
if comp.language in LANGS_CANT_UNITY:
Expand Down Expand Up @@ -905,10 +903,8 @@ def create_msvc_pch_implementation(self, target: build.BuildTarget, lang: str, p
return pch_rel_to_build

def target_uses_pch(self, target: build.BuildTarget) -> bool:
try:
return T.cast('bool', self.get_target_option(target, 'b_pch'))
except (KeyError, AttributeError):
return False
return self.environment.coredata.optstore.get_option_for_target(
target, OptionKey('b_pch'), bool, default=False)

@staticmethod
def escape_extra_args(args: T.List[str]) -> T.List[str]:
Expand Down Expand Up @@ -939,24 +935,25 @@ def generate_basic_compiler_args(self, target: build.BuildTarget, compiler: 'Com
# 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', self.get_target_option(target, 'warning_level')))
commands += compiler.get_warn_args(self.environment.coredata.optstore.get_option_for_target(
target, OptionKey('warning_level'), str))
# 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 self.get_target_option(target, 'werror'):
if self.environment.coredata.optstore.get_option_for_target(target, OptionKey('werror'), bool):
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(target, target.subproject)
commands += compiler.get_option_std_args(target, target.subproject)
commands += compiler.get_option_compile_args(target)
commands += compiler.get_option_std_args(target)

optimization = self.get_target_option(target, 'optimization')
assert isinstance(optimization, str), 'for mypy'
optimization = self.environment.coredata.optstore.get_option_for_target(
target, OptionKey('optimization'), str)
commands += compiler.get_optimization_args(optimization)

debug = self.get_target_option(target, 'debug')
assert isinstance(debug, bool), 'for mypy'
debug = self.environment.coredata.optstore.get_option_for_target(
target, OptionKey('debug'), bool)
commands += compiler.get_debug_args(debug)

# Add compile args added using add_project_arguments()
Expand All @@ -967,7 +964,7 @@ def generate_basic_compiler_args(self, target: build.BuildTarget, compiler: 'Com
# Compile args added from the env: CFLAGS/CXXFLAGS, etc, or the cross
# file. We want these to override all the defaults, but not the
# per-target compile args.
commands += self.environment.coredata.get_external_args(target.for_machine, compiler.get_language())
commands += self.environment.coredata.optstore.get_external_args(target.for_machine, compiler.get_language())
# Using both /Z7 or /ZI and /Zi at the same times produces a compiler warning.
# We do not add /Z7 or /ZI by default. If it is being used it is because the user has explicitly enabled it.
# /Zi needs to be removed in that case to avoid cl's warning to that effect (D9025 : overriding '/Zi' with '/ZI')
Expand Down Expand Up @@ -1298,8 +1295,7 @@ def construct_target_rel_paths(self, t: build.AnyTargetType, workdir: T.Optional
def generate_depmf_install(self, d: InstallData) -> None:
depmf_path = self.build.dep_manifest_name
if depmf_path is None:
option_dir = self.environment.coredata.optstore.get_value_for(OptionKey('licensedir'))
assert isinstance(option_dir, str), 'for mypy'
option_dir = self.environment.coredata.optstore.get_value_for(OptionKey('licensedir'), str)
if option_dir:
depmf_path = os.path.join(option_dir, 'depmf.json')
else:
Expand Down Expand Up @@ -1649,7 +1645,8 @@ def create_install_data(self) -> InstallData:
# TODO go through all candidates, like others
strip_bin = [detect.defaults['strip'][0]]

umask = self.environment.coredata.optstore.get_value_for(OptionKey('install_umask'))
# Cannot used typed getter because of union type
umask = self.environment.coredata.optstore.get_value_for_untyped(OptionKey('install_umask'))
assert isinstance(umask, (str, int)), 'for mypy'

d = InstallData(self.environment.get_source_dir(),
Expand Down Expand Up @@ -1681,9 +1678,7 @@ def guess_install_tag(self, fname: str, outdir: T.Optional[str] = None) -> T.Opt
bindir = Path(prefix, self.environment.get_bindir())
libdir = Path(prefix, self.environment.get_libdir())
incdir = Path(prefix, self.environment.get_includedir())
_ldir = self.environment.coredata.optstore.get_value_for(OptionKey('localedir'))
assert isinstance(_ldir, str), 'for mypy'
localedir = Path(prefix, _ldir)
localedir = Path(prefix, self.environment.coredata.optstore.get_value_for(OptionKey('localedir'), str))
dest_path = Path(prefix, outdir, Path(fname).name) if outdir else Path(prefix, fname)
if bindir in dest_path.parents:
return 'runtime'
Expand Down Expand Up @@ -1738,8 +1733,8 @@ def generate_target_install(self, d: InstallData) -> None:
# 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 self.get_target_option(t, 'strip')
assert isinstance(should_strip, bool), 'for mypy'
should_strip = can_strip and self.environment.coredata.optstore.get_option_for_target(
t, OptionKey('strip'), bool)
# Install primary build output (library/executable/jar, etc)
# Done separately because of strip/aliases/rpath
if first_outdir is not False:
Expand Down Expand Up @@ -2082,20 +2077,11 @@ def compile_target_to_generator(self, target: build.CompileTarget) -> build.Gene
def is_unity(self, target: build.BuildTarget) -> bool:
if isinstance(target, build.CompileTarget):
return False
val = self.get_target_option(target, 'unity')
val = self.environment.coredata.optstore.get_option_for_target(target, OptionKey('unity'), str)
if val == 'on':
return True
if val == 'off':
return False
if val == 'subprojects':
return target.subproject != ''
raise MesonException(f'Internal error: invalid option type for "unity": {val}')

def get_target_option(self, target: build.BuildTarget, name: T.Union[str, OptionKey]) -> ElementaryOptionValues:
if isinstance(name, str):
key = OptionKey(name, subproject=target.subproject)
elif isinstance(name, OptionKey):
key = name
else:
raise MesonBugException('Internal error: invalid option type.')
return self.environment.coredata.get_option_for_target(target, key)
Loading
Loading