Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of Dependency's include_type in few places #13861

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 docs/yaml/objects/dep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ methods:
description: |
Returns a copy of the dependency object, which has changed the value of `include_type`
to `value`. The `value` argument is optional and
defaults to `'preserve'`.
defaults to `'system'`.

optargs:
value:
Expand Down
9 changes: 2 additions & 7 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ def add_deps(self, deps):
# Those parts that are internal.
self.process_sourcelist(dep.sources)
self.extra_files.extend(f for f in dep.extra_files if f not in self.extra_files)
self.add_include_dirs(dep.include_directories, dep.get_include_type())
self.add_include_dirs(dep.get_include_dirs())
self.objects.extend(dep.objects)
self.link_targets.extend(dep.libraries)
self.link_whole_targets.extend(dep.whole_libraries)
Expand Down Expand Up @@ -1530,17 +1530,12 @@ def add_pch(self, language: str, pchlist: T.List[str]) -> None:
raise MesonException(f'File {f} does not exist.')
self.pch[language] = pchlist

def add_include_dirs(self, args: T.Sequence['IncludeDirs'], set_is_system: T.Optional[str] = None) -> None:
def add_include_dirs(self, args: T.Sequence['IncludeDirs']) -> None:
ids: T.List['IncludeDirs'] = []
for a in args:
if not isinstance(a, IncludeDirs):
raise InvalidArguments('Include directory to be added is not an include directory object.')
ids.append(a)
if set_is_system is None:
set_is_system = 'preserve'
if set_is_system != 'preserve':
is_system = set_is_system == 'system'
ids = [IncludeDirs(x.get_curdir(), x.get_incdirs(), is_system, x.get_extra_build_dirs()) for x in ids]
self.include_dirs += ids

def get_aliases(self) -> T.List[T.Tuple[str, str, str]]:
Expand Down
3 changes: 1 addition & 2 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,9 @@ def build_wrapper_args(self, env: 'Environment',
for d in dependencies:
# Add compile flags needed by dependencies
cargs += d.get_compile_args()
system_incdir = d.get_include_type() == 'system'
for i in d.get_include_dirs():
for idir in i.to_string_list(env.get_source_dir(), env.get_build_dir()):
cargs.extend(self.get_include_args(idir, system_incdir))
cargs.extend(self.get_include_args(idir, i.is_system))
if mode is CompileCheckMode.LINK:
# Add link flags needed to find dependencies
largs += d.get_link_args()
Expand Down
11 changes: 9 additions & 2 deletions mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def __deepcopy__(self, memo: T.Dict[int, 'InternalDependency']) -> 'InternalDepe
for k, v in self.__dict__.items():
if k in {'libraries', 'whole_libraries'}:
setattr(result, k, copy.copy(v))
elif k == 'include_directories':
setattr(result, k, copy.copy(self.get_include_dirs()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you do self.get_include_dirs().copy() below, and copy.copy(self.get_include_dirs()) here.... I think I prefer using the copy() method of list, since it is available

else:
setattr(result, k, copy.deepcopy(v, memo))
return result
Expand All @@ -328,7 +330,7 @@ def get_partial_dependency(self, *, compile_args: bool = False,
final_whole_libraries = self.whole_libraries.copy() if links else []
final_sources = self.sources.copy() if sources else []
final_extra_files = self.extra_files.copy() if extra_files else []
final_includes = self.include_directories.copy() if includes else []
final_includes = self.get_include_dirs().copy() if includes else []
final_deps = [d.get_partial_dependency(
compile_args=compile_args, link_args=link_args, links=links,
includes=includes, sources=sources) for d in self.ext_deps]
Expand All @@ -338,7 +340,12 @@ def get_partial_dependency(self, *, compile_args: bool = False,
final_sources, final_extra_files, final_deps, self.variables, [], [], [])

def get_include_dirs(self) -> T.List['IncludeDirs']:
return self.include_directories
from ..build import IncludeDirs
ids = self.include_directories
if self.include_type != 'preserve':
is_system = self.include_type == 'system'
ids = [IncludeDirs(x.get_curdir(), x.get_incdirs(), is_system, x.get_extra_build_dirs()) for x in ids]
return ids

def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
Expand Down
3 changes: 1 addition & 2 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2958,12 +2958,11 @@ def func_add_project_dependencies(self, node: mparser.FunctionNode, args: T.Tupl

for d in dependencies.get_leaf_external_dependencies(args[0]):
compile_args = list(d.get_compile_args())
system_incdir = d.get_include_type() == 'system'
for i in d.get_include_dirs():
for lang in kwargs['language']:
comp = self.coredata.compilers[for_machine][lang]
for idir in i.to_string_list(self.environment.get_source_dir(), self.environment.get_build_dir()):
compile_args.extend(comp.get_include_args(idir, system_incdir))
compile_args.extend(comp.get_include_args(idir, i.is_system))

self._add_project_arguments(node, self.build.projects_args[for_machine], compile_args, kwargs)
self._add_project_arguments(node, self.build.projects_link_args[for_machine], d.get_link_args(), kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <stdbool.h>

/* Attempt to trigger -Wsizeof-array-div */
extern int arr1[10];
const int C0 = sizeof(arr1) / sizeof(short);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <stdbool.h>

/* Attempt to trigger -Wsizeof-array-div */
extern int arr1[10];
const int C1 = sizeof(arr1) / sizeof(short);
6 changes: 6 additions & 0 deletions test cases/linuxlike/16 isystem includes/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <my_global_lib/my_global.h>
#include <my_local1_lib/my_local1.h>

int main() {
return C0 + C1;
}
23 changes: 23 additions & 0 deletions test cases/linuxlike/16 isystem includes/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
project('isystem includes', 'c', default_options : 'werror=true')

cc = meson.get_compiler('c')

# Canary warning to check suppression in system headers. Chosen randomly from GCC docs.
incwarg = '-Wsizeof-array-div'

add_project_dependencies(
declare_dependency(
include_directories: include_directories('global_include', is_system: true),
),
language: ['c'],
)

local_inc_dep1 = declare_dependency(
include_directories: 'local_include1',
).as_system().partial_dependency(includes : true)

if cc.has_argument(incwarg)
executable('main', 'main.c', c_args: incwarg, dependencies: local_inc_dep1)
else
error('MESON_SKIP_TEST compiler does not support emitting canary warning.')
endif
Loading