diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2022-03-24 14:15:02 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2023-03-03 11:18:58 -0800 |
commit | 34e05c01c7fe877e782b2c71f8d36e1164cac0fe (patch) | |
tree | a6c0e64046929596f596fa046ec2b20f35409bba | |
parent | 21e6a3a3c42eef0a32204e9797bf5b31f8efc9e3 (diff) | |
download | meson-34e05c01c7fe877e782b2c71f8d36e1164cac0fe.tar.gz |
interpreter: simplify include_directory extraction
This moves the FeatureNew check for strings out of the helper, and into
the typed_kwargs decorator. This also changes the warning for passing an
absolute path to d_import_dirs to a FeatureDeprecated check. Since we've
hit 1.0, we shouldn't remove deprecated functionality until 2.0, thus
let's treated this as a deprecated "feature", and provide a nicer
message.
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 53 | ||||
-rw-r--r-- | test cases/d/9 features/meson.build | 2 | ||||
-rw-r--r-- | test cases/d/9 features/test.json | 7 |
3 files changed, 25 insertions, 37 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 9fc23c87f..2dd47568c 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -40,6 +40,7 @@ from ..backend.backends import ExecutableSerialisation from . import interpreterobjects as OBJ from . import compiler as compilerOBJ +from . import type_checking from .mesonmain import MesonMain from .dependencyfallbacks import DependencyFallbacksHolder from .interpreterobjects import ( @@ -99,6 +100,7 @@ from . import primitives as P_OBJ from pathlib import Path from enum import Enum +import functools import os import shutil import uuid @@ -698,7 +700,7 @@ class Interpreter(InterpreterBase, HoldableObject): D_MODULE_VERSIONS_KW.evolve(since='0.62.0'), KwargInfo('link_args', ContainerTypeInfo(list, str), listify=True, default=[]), DEPENDENCIES_KW, - INCLUDE_DIRECTORIES, + INCLUDE_DIRECTORIES.evolve(feature_validator=functools.partial(type_checking.include_dir_string_new, '0.50.0')), LINK_WITH_KW, LINK_WHOLE_KW.evolve(since='0.46.0'), SOURCES_KW, @@ -708,7 +710,7 @@ class Interpreter(InterpreterBase, HoldableObject): ) def func_declare_dependency(self, node, args, kwargs): deps = kwargs['dependencies'] - incs = self.extract_incdirs(kwargs) + incs = self._convert_include_dirs(kwargs['include_directories']) libs = kwargs['link_with'] libs_whole = kwargs['link_whole'] objects = kwargs['objects'] @@ -720,9 +722,8 @@ 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._convert_include_dirs(kwargs['d_import_dirs'], is_d_lang=True) srcdir = Path(self.environment.source_dir) - # convert variables which refer to an -uninstalled.pc style datadir for k, v in variables.items(): try: p = Path(v) @@ -2705,23 +2706,20 @@ 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'): - prospectives = extract_as_list(kwargs, key) - if key == 'include_directories': - for i in prospectives: - if isinstance(i, str): - FeatureNew.single_use('include_directories kwarg of type string', '0.50.0', self.subproject, - f'Use include_directories({i!r}) instead', location=self.current_node) - break - - result = [] + def _convert_include_dirs(self, prospectives: T.Iterable[T.Union[str, build.IncludeDirs]], *, is_d_lang: bool = False) -> T.List[build.IncludeDirs]: + result: T.List[build.IncludeDirs] = [] + strings: T.List[str] = [] for p in prospectives: if isinstance(p, build.IncludeDirs): result.append(p) - elif isinstance(p, str): - result.append(self.build_incdir_object([p])) else: - raise InterpreterException('Include directory objects can only be created from strings or include directories.') + if is_d_lang and os.path.normpath(p).startswith(self.environment.source_dir): + FeatureDeprecated.single_use('Absolute paths to the source directory for d_import_dirs', '0.45.0', self.subproject, + 'use a relative path instead.', self.current_node) + p = os.path.relpath(p, os.path.join(self.environment.source_dir, self.subdir)) + strings.append(p) + if strings: + result.append(self.build_incdir_object(strings)) return result @typed_pos_args('include_directories', varargs=str) @@ -3204,7 +3202,8 @@ class Interpreter(InterpreterBase, HoldableObject): ef = extract_as_list(kwargs, 'extra_files') kwargs['extra_files'] = self.source_strings_to_files(ef) self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources) - self.kwarg_strings_to_includedirs(kwargs) + kwargs['include_directories'] = self._convert_include_dirs(kwargs['include_directories']) + kwargs['d_import_dirs'] = self._convert_include_dirs(kwargs['d_import_dirs'], is_d_lang=True) # Filter out kwargs from other target types. For example 'soversion' # passed to library() when default_library == 'static'. @@ -3259,7 +3258,6 @@ class Interpreter(InterpreterBase, HoldableObject): node=node) outputs.update(o) - kwargs['include_directories'] = self.extract_incdirs(kwargs) target = targetclass(name, self.subdir, self.subproject, for_machine, srcs, struct, kwargs['objects'], self.environment, self.compilers[for_machine], kwargs) @@ -3269,23 +3267,6 @@ class Interpreter(InterpreterBase, HoldableObject): self.project_args_frozen = True return target - def kwarg_strings_to_includedirs(self, kwargs): - if 'd_import_dirs' in kwargs: - items = mesonlib.extract_as_list(kwargs, 'd_import_dirs') - cleaned_items = [] - for i in items: - if isinstance(i, str): - # BW compatibility. This was permitted so we must support it - # for a few releases so people can transition to "correct" - # path declarations. - if os.path.normpath(i).startswith(self.environment.get_source_dir()): - mlog.warning('''Building a path to the source dir is not supported. Use a relative path instead. -This will become a hard error in the future.''', location=self.current_node) - i = os.path.relpath(i, os.path.join(self.environment.get_source_dir(), self.subdir)) - i = self.build_incdir_object([i]) - cleaned_items.append(i) - kwargs['d_import_dirs'] = cleaned_items - def add_stdlib_info(self, target): for l in target.compilers.keys(): dep = self.build.stdlibs[target.for_machine].get(l, None) diff --git a/test cases/d/9 features/meson.build b/test cases/d/9 features/meson.build index 06f03414d..c603f7ed3 100644 --- a/test cases/d/9 features/meson.build +++ b/test cases/d/9 features/meson.build @@ -1,4 +1,4 @@ -project('D Features', 'd', default_options : ['debug=false']) +project('D Features', 'd', default_options : ['debug=false'], meson_version : '>= 1.0') # ONLY FOR BACKWARDS COMPATIBILITY. # DO NOT DO THIS IN NEW CODE! diff --git a/test cases/d/9 features/test.json b/test cases/d/9 features/test.json new file mode 100644 index 000000000..1b62854be --- /dev/null +++ b/test cases/d/9 features/test.json @@ -0,0 +1,7 @@ +{ + "stdout": [ + { + "line": "test cases/d/9 features/meson.build:13: WARNING: Project targets '>= 1.0' but uses feature deprecated since '0.45.0': Absolute paths to the source directory for d_import_dirs. use a relative path instead." + } + ] +} |