From b3ab02277796cfc79772ecd6100f8d9f58a4bb4d Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Mon, 30 Dec 2019 14:58:41 -0500 Subject: [PATCH] pkgconfig: Fix code that make relative path When subdir is '/foo/bar' and prefix '/foo' it was returning '/bar', which is an absolute path. It was then constructing '-L${prefix}//bar' with bogus double slash. When subdir is '/fooo/bar' and prefix '/foo' it was returning 'o/bar'. --- mesonbuild/modules/pkgconfig.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 2341bd20c..82b335ea5 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -256,8 +256,12 @@ class PkgConfigModule(ExtensionModule): prefix = prefix.as_posix() if isinstance(subdir, PurePath): subdir = subdir.as_posix() - if subdir.startswith(prefix): - subdir = subdir.replace(prefix, '') + try: + if os.path.commonpath([prefix, subdir]) == prefix: + skip = len(prefix) + 1 + subdir = subdir[skip:] + except ValueError: + pass return subdir def generate_pkgconfig_file(self, state, deps, subdirs, name, description,