aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-06-02 09:56:59 -0400
committerXavier Claessens <xclaesse@gmail.com>2023-06-01 18:57:40 -0400
commit1781a481ee2cd4acdaf5b76e3b567e882ccd7b38 (patch)
treefb17ba81e679cbf676908cd998656ec5a588dd3c
parent26da7ec9f535205f9a6b102380087a1383c092c3 (diff)
downloadmeson-1781a481ee2cd4acdaf5b76e3b567e882ccd7b38.zip
meson-1781a481ee2cd4acdaf5b76e3b567e882ccd7b38.tar.gz
meson-1781a481ee2cd4acdaf5b76e3b567e882ccd7b38.tar.bz2
pkgconfig: Add include directories from internal deps in -uninstalled.pc
Fixes: #8651
-rw-r--r--mesonbuild/modules/pkgconfig.py41
-rw-r--r--test cases/common/44 pkgconfig-gen/dependencies/meson.build8
-rw-r--r--test cases/common/44 pkgconfig-gen/dependencies/test2.c8
-rw-r--r--test cases/common/44 pkgconfig-gen/inc1/inc1.h1
-rw-r--r--test cases/common/44 pkgconfig-gen/inc2/inc2.h1
-rw-r--r--test cases/common/44 pkgconfig-gen/meson.build8
-rw-r--r--test cases/common/44 pkgconfig-gen/test.json3
7 files changed, 47 insertions, 23 deletions
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
index dcd1ea8..ce27f1e 100644
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -99,6 +99,7 @@ class DependenciesHelper:
def __init__(self, state: ModuleState, name: str, metadata: T.Dict[str, MetaData]) -> None:
self.state = state
self.name = name
+ self.metadata = metadata
self.pub_libs: T.List[LIBS] = []
self.pub_reqs: T.List[str] = []
self.priv_libs: T.List[LIBS] = []
@@ -106,7 +107,7 @@ class DependenciesHelper:
self.cflags: T.List[str] = []
self.version_reqs: T.DefaultDict[str, T.Set[str]] = defaultdict(set)
self.link_whole_targets: T.List[T.Union[build.CustomTarget, build.CustomTargetIndex, build.StaticLibrary]] = []
- self.metadata = metadata
+ self.uninstalled_incdirs: mesonlib.OrderedSet[str] = mesonlib.OrderedSet()
def add_pub_libs(self, libs: T.List[ANY_DEP]) -> None:
p_libs, reqs, cflags = self._process_libs(libs, True)
@@ -173,6 +174,15 @@ class DependenciesHelper:
def add_cflags(self, cflags: T.List[str]) -> None:
self.cflags += mesonlib.stringlistify(cflags)
+ def _add_uninstalled_incdirs(self, incdirs: T.List[build.IncludeDirs], subdir: T.Optional[str] = None) -> None:
+ for i in incdirs:
+ curdir = i.get_curdir()
+ for d in i.get_incdirs():
+ path = os.path.join(curdir, d)
+ self.uninstalled_incdirs.add(path)
+ if subdir is not None:
+ self.uninstalled_incdirs.add(subdir)
+
def _process_libs(
self, libs: T.List[ANY_DEP], public: bool
) -> T.Tuple[T.List[T.Union[str, build.SharedLibrary, build.StaticLibrary, build.CustomTarget, build.CustomTargetIndex]], T.List[str], T.List[str]]:
@@ -198,6 +208,7 @@ class DependenciesHelper:
processed_libs += obj.get_link_args()
processed_cflags += obj.get_compile_args()
self._add_lib_dependencies(obj.libraries, obj.whole_libraries, obj.ext_deps, public, private_external_deps=True)
+ self._add_uninstalled_incdirs(obj.get_include_dirs())
elif isinstance(obj, dependencies.Dependency):
if obj.found():
processed_libs += obj.get_link_args()
@@ -210,8 +221,10 @@ class DependenciesHelper:
# than needed build deps.
# See https://bugs.freedesktop.org/show_bug.cgi?id=105572
processed_libs.append(obj)
+ self._add_uninstalled_incdirs(obj.get_include_dirs(), obj.get_subdir())
elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)):
processed_libs.append(obj)
+ self._add_uninstalled_incdirs(obj.get_include_dirs(), obj.get_subdir())
# If there is a static library in `Libs:` all its deps must be
# public too, otherwise the generated pc file will never be
# usable without --static.
@@ -556,27 +569,6 @@ class PkgConfigModule(NewExtensionModule):
if isinstance(l, (build.CustomTarget, build.CustomTargetIndex)) or 'cs' not in l.compilers:
yield f'-l{lname}'
- def get_uninstalled_include_dirs(libs: T.List[LIBS]) -> T.List[str]:
- result: T.List[str] = []
- for l in libs:
- if isinstance(l, (str, build.CustomTarget, build.CustomTargetIndex)):
- continue
- if l.get_subdir() not in result:
- result.append(l.get_subdir())
- for i in l.get_include_dirs():
- curdir = i.get_curdir()
- for d in i.get_incdirs():
- path = os.path.join(curdir, d)
- if path not in result:
- result.append(path)
- return result
-
- def generate_uninstalled_cflags(libs: T.List[LIBS]) -> T.Iterable[str]:
- for d in get_uninstalled_include_dirs(libs):
- for basedir in ['${prefix}', '${srcdir}']:
- path = PurePath(basedir, d)
- yield '-I%s' % self._escape(path.as_posix())
-
if len(deps.pub_libs) > 0:
ofile.write('Libs: {}\n'.format(' '.join(generate_libs_flags(deps.pub_libs))))
if len(deps.priv_libs) > 0:
@@ -584,7 +576,10 @@ class PkgConfigModule(NewExtensionModule):
cflags: T.List[str] = []
if uninstalled:
- cflags += generate_uninstalled_cflags(deps.pub_libs + deps.priv_libs)
+ for d in deps.uninstalled_incdirs:
+ for basedir in ['${prefix}', '${srcdir}']:
+ path = self._escape(PurePath(basedir, d).as_posix())
+ cflags.append(f'-I{path}')
else:
for d in subdirs:
if d == '.':
diff --git a/test cases/common/44 pkgconfig-gen/dependencies/meson.build b/test cases/common/44 pkgconfig-gen/dependencies/meson.build
index 6e27ae8..f80f58a 100644
--- a/test cases/common/44 pkgconfig-gen/dependencies/meson.build
+++ b/test cases/common/44 pkgconfig-gen/dependencies/meson.build
@@ -60,3 +60,11 @@ pkgg.generate(main_lib2,
libraries : internal_lib,
filebase : 'pub-lib-order',
)
+
+# This will be built against both simple7.pc and simple7-uninstalled.pc, check
+# that include directories works in both cases.
+simple7 = dependency('simple7')
+exe = executable('test2', 'test2.c',
+ dependencies: simple7,
+)
+test('Test2', exe)
diff --git a/test cases/common/44 pkgconfig-gen/dependencies/test2.c b/test cases/common/44 pkgconfig-gen/dependencies/test2.c
new file mode 100644
index 0000000..83979d5
--- /dev/null
+++ b/test cases/common/44 pkgconfig-gen/dependencies/test2.c
@@ -0,0 +1,8 @@
+#include <inc1.h>
+#include <inc2.h>
+
+int main(void) {
+ if (INC1 + INC2 != 3)
+ return 1;
+ return 0;
+}
diff --git a/test cases/common/44 pkgconfig-gen/inc1/inc1.h b/test cases/common/44 pkgconfig-gen/inc1/inc1.h
new file mode 100644
index 0000000..04ff366
--- /dev/null
+++ b/test cases/common/44 pkgconfig-gen/inc1/inc1.h
@@ -0,0 +1 @@
+#define INC1 1
diff --git a/test cases/common/44 pkgconfig-gen/inc2/inc2.h b/test cases/common/44 pkgconfig-gen/inc2/inc2.h
new file mode 100644
index 0000000..b4b5ae1
--- /dev/null
+++ b/test cases/common/44 pkgconfig-gen/inc2/inc2.h
@@ -0,0 +1 @@
+#define INC2 2
diff --git a/test cases/common/44 pkgconfig-gen/meson.build b/test cases/common/44 pkgconfig-gen/meson.build
index 6e84bb1..adf3e27 100644
--- a/test cases/common/44 pkgconfig-gen/meson.build
+++ b/test cases/common/44 pkgconfig-gen/meson.build
@@ -185,3 +185,11 @@ endtestcase
testcase expect_error('pkgconfig.generate: if a library is not passed as a positional argument, the \'description\' keyword argument is required.')
pkgg.generate(name: 'foobar')
endtestcase
+
+# Make sure the -uninstalled.pc file contains both include directories.
+# See dependencies/test2.c that gets built against both simple7.pc and
+# simple7-uninstalled.pc.
+simple7 = library('simple7', include_directories: 'inc1')
+dep = declare_dependency(include_directories: 'inc2')
+install_headers('inc1/inc1.h', 'inc2/inc2.h')
+pkgg.generate(simple7, libraries: dep)
diff --git a/test cases/common/44 pkgconfig-gen/test.json b/test cases/common/44 pkgconfig-gen/test.json
index b5987ee..01786d4 100644
--- a/test cases/common/44 pkgconfig-gen/test.json
+++ b/test cases/common/44 pkgconfig-gen/test.json
@@ -1,6 +1,8 @@
{
"installed": [
{"type": "file", "file": "usr/include/simple.h"},
+ {"type": "file", "file": "usr/include/inc1.h"},
+ {"type": "file", "file": "usr/include/inc2.h"},
{"type": "file", "file": "usr/lib/libstat2.a"},
{"type": "file", "file": "usr/lib/pkgconfig/simple.pc"},
{"type": "file", "file": "usr/lib/pkgconfig/libanswer.pc"},
@@ -13,6 +15,7 @@
{"type": "file", "file": "usr/lib/pkgconfig/simple3.pc"},
{"type": "file", "file": "usr/lib/pkgconfig/simple5.pc"},
{"type": "file", "file": "usr/lib/pkgconfig/simple6.pc"},
+ {"type": "file", "file": "usr/lib/pkgconfig/simple7.pc"},
{"type": "file", "file": "usr/lib/pkgconfig/ct.pc"},
{"type": "file", "file": "usr/lib/pkgconfig/ct0.pc"},
{"type": "file", "file": "usr/share/pkgconfig/libhello_nolib.pc"}