summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-12-10 10:44:36 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-12-16 10:08:34 -0800
commit02006281ad4a1c39479456c95d6195b9914e3dd4 (patch)
tree7cef2fb4844f685211945b46fade0ab312179db0
parente2c46bf8e41888ec9a2d7c80737a81f5af6e0095 (diff)
downloadmeson-02006281ad4a1c39479456c95d6195b9914e3dd4.tar.gz
interpreter: use typed_kwargs for build_target(include_directories)
This allows some additional cleanup, as we had code specifically for doing version checking that was not only used here, and that can be removed.
-rw-r--r--mesonbuild/interpreter/compiler.py4
-rw-r--r--mesonbuild/interpreter/interpreter.py26
-rw-r--r--mesonbuild/interpreter/kwargs.py1
-rw-r--r--mesonbuild/interpreter/type_checking.py1
4 files changed, 13 insertions, 19 deletions
diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py
index 6b5c6a741..de71a2056 100644
--- a/mesonbuild/interpreter/compiler.py
+++ b/mesonbuild/interpreter/compiler.py
@@ -235,7 +235,7 @@ class CompilerHolder(ObjectHolder['Compiler']):
def _determine_args(self, kwargs: BaseCompileKW,
mode: CompileCheckMode = CompileCheckMode.LINK) -> T.List[str]:
args: T.List[str] = []
- for i in self.interpreter.extract_incdirs(kwargs):
+ for i in self.interpreter.extract_incdirs(kwargs['include_directories']):
for idir in i.to_string_list(self.environment.get_source_dir(), self.environment.get_build_dir()):
args.extend(self.compiler.get_include_args(idir, False))
if not kwargs['no_builtin_args']:
@@ -913,7 +913,7 @@ class CompilerHolder(ObjectHolder['Compiler']):
compiler,
self.interpreter.backend,
kwargs['compile_args'],
- self.interpreter.extract_incdirs(kwargs),
+ self.interpreter.extract_incdirs(kwargs['include_directories']),
kwargs['dependencies'],
kwargs['depends'])
self.interpreter.add_target(tg.name, tg)
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index b24b9e761..10970b552 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -685,7 +685,7 @@ class Interpreter(InterpreterBase, HoldableObject):
def func_declare_dependency(self, node: mparser.BaseNode, args: T.List[TYPE_var],
kwargs: kwtypes.FuncDeclareDependency) -> dependencies.Dependency:
deps = kwargs['dependencies']
- incs = self.extract_incdirs(kwargs)
+ incs = self.extract_incdirs(kwargs['include_directories'])
libs = kwargs['link_with']
libs_whole = kwargs['link_whole']
objects = kwargs['objects']
@@ -698,7 +698,7 @@ class Interpreter(InterpreterBase, HoldableObject):
if version is None:
version = self.project_version
d_module_versions = kwargs['d_module_versions']
- d_import_dirs = self.extract_incdirs(kwargs, 'd_import_dirs')
+ d_import_dirs = self.extract_incdirs(kwargs['d_import_dirs'], True)
srcdir = self.environment.source_dir
subproject_dir = os.path.abspath(os.path.join(srcdir, self.subproject_dir))
project_root = os.path.abspath(os.path.join(srcdir, self.root_subdir))
@@ -2792,29 +2792,21 @@ class Interpreter(InterpreterBase, HoldableObject):
install_tag=install_tag, data_type='configure'))
return mesonlib.File.from_built_file(self.subdir, output)
- def extract_incdirs(self, kwargs, key: str = 'include_directories', strings_since: T.Optional[str] = None) -> T.List[build.IncludeDirs]:
- prospectives = extract_as_list(kwargs, key)
- if strings_since:
- for i in prospectives:
- if isinstance(i, str):
- FeatureNew.single_use(f'{key} kwarg of type string', strings_since, self.subproject,
- f'Use include_directories({i!r}) instead', location=self.current_node)
- break
-
+ def extract_incdirs(self, prospectives: T.List[T.Union[str, build.IncludeDirs]],
+ is_d_import_dirs: bool = False
+ ) -> T.List[build.IncludeDirs]:
result: T.List[build.IncludeDirs] = []
for p in prospectives:
if isinstance(p, build.IncludeDirs):
result.append(p)
- elif isinstance(p, str):
- if key == 'd_import_dirs' and os.path.normpath(p).startswith(self.environment.get_source_dir()):
+ else:
+ if is_d_import_dirs and os.path.normpath(p).startswith(self.environment.get_source_dir()):
FeatureDeprecated.single_use('Building absolute path to source dir is not supported',
'0.45', self.subproject,
'Use a relative path instead.',
location=self.current_node)
p = os.path.relpath(p, os.path.join(self.environment.get_source_dir(), self.subdir))
result.append(self.build_incdir_object([p]))
- else:
- raise InterpreterException('Include directory objects can only be created from strings or include directories.')
return result
@typed_pos_args('include_directories', varargs=str)
@@ -3481,7 +3473,7 @@ class Interpreter(InterpreterBase, HoldableObject):
if targetclass is not build.Jar:
self.check_for_jar_sources(sources, targetclass)
- kwargs['d_import_dirs'] = self.extract_incdirs(kwargs, 'd_import_dirs')
+ kwargs['d_import_dirs'] = self.extract_incdirs(kwargs['d_import_dirs'], True)
missing: T.List[str] = []
for each in itertools.chain(kwargs['c_pch'] or [], kwargs['cpp_pch'] or []):
if each is not None:
@@ -3525,7 +3517,7 @@ class Interpreter(InterpreterBase, HoldableObject):
node=node)
outputs.update(o)
- kwargs['include_directories'] = self.extract_incdirs(kwargs, strings_since='0.50.0')
+ kwargs['include_directories'] = self.extract_incdirs(kwargs['include_directories'])
if targetclass is build.Executable:
kwargs = T.cast('kwtypes.Executable', kwargs)
diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py
index 1e206422f..517ccee15 100644
--- a/mesonbuild/interpreter/kwargs.py
+++ b/mesonbuild/interpreter/kwargs.py
@@ -339,6 +339,7 @@ class _BaseBuildTarget(TypedDict):
build_rpath: str
extra_files: T.List[FileOrString]
gnu_symbol_visibility: str
+ include_directories: T.List[build.IncludeDirs]
install: bool
install_mode: FileMode
install_tag: T.Optional[str]
diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py
index 743046caf..c3f647465 100644
--- a/mesonbuild/interpreter/type_checking.py
+++ b/mesonbuild/interpreter/type_checking.py
@@ -715,6 +715,7 @@ _BUILD_TARGET_KWS: T.List[KwargInfo] = [
*_ALL_TARGET_KWS,
*_LANGUAGE_KWS,
BT_SOURCES_KW,
+ INCLUDE_DIRECTORIES.evolve(since_values={ContainerTypeInfo(list, str): '0.50.0'}),
INCLUDE_DIRECTORIES.evolve(name='d_import_dirs'),
_NAME_PREFIX_KW,
_NAME_PREFIX_KW.evolve(name='name_suffix', validator=_name_suffix_validator),