Skip to content

Commit

Permalink
Harmonize d_import_dirs and include_directories behavior.
Browse files Browse the repository at this point in the history
This commit harmonizes the handling of `d_import_dirs` and
`include_directories`. The treatment of `d_import_dirs` was also
different depending on the context: in `declare_dependency` it was
treated like the `include_directories`, but in `build_target` et al,
it had special treatment. With this commit, they are all treated
by the same function. The documentation has been updated to
reflect this.

Fixes mesonbuild#12742
  • Loading branch information
amcn committed Sep 11, 2024
1 parent 53e1148 commit 160256d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
7 changes: 5 additions & 2 deletions docs/yaml/functions/_build_target_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,11 @@ kwargs:
do not support GNU visibility arguments.
d_import_dirs:
type: list[str]
description: List of directories to look in for string imports used in the D programming language.
type: list[inc | str]
since: 0.62.0
description: |
the directories to add to the string search path (i.e. `-J` switch for DMD).
Must be [[@inc]] objects or plain strings.
d_unittest:
type: bool
Expand Down
25 changes: 7 additions & 18 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,12 @@ def extract_incdirs(self, kwargs, key: str = 'include_directories') -> T.List[bu
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()):
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.')
Expand Down Expand Up @@ -3400,7 +3406,7 @@ def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargs
kwargs['language_args'][lang].extend(args)
kwargs['depend_files'].extend(deps)
if targetclass is not build.Jar:
self.kwarg_strings_to_includedirs(kwargs)
kwargs['d_import_dirs'] = self.extract_incdirs(kwargs, 'd_import_dirs')

# Filter out kwargs from other target types. For example 'soversion'
# passed to library() when default_library == 'static'.
Expand Down Expand Up @@ -3473,23 +3479,6 @@ def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargs
self.project_args_frozen = True
return target

def kwarg_strings_to_includedirs(self, kwargs: kwtypes._BuildTarget) -> None:
if kwargs['d_import_dirs']:
items = kwargs['d_import_dirs']
cleaned_items: T.List[build.IncludeDirs] = []
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)
Expand Down
2 changes: 1 addition & 1 deletion test cases/d/9 features/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('D Features', 'd', default_options : ['debug=false'])
project('D Features', 'd', meson_version: '>=1.6', default_options : ['debug=false'])

dc = meson.get_compiler('d')

Expand Down

0 comments on commit 160256d

Please sign in to comment.