aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/backends.py
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@gmail.com>2023-01-29 08:42:32 -0500
committerXavier Claessens <xclaesse@gmail.com>2023-03-01 08:56:46 -0500
commitc8490315133166136b6dd8ac8b94c7349240eea0 (patch)
tree2edb69c28e561f3fc15edb0db8b720f11ba70afb /mesonbuild/backend/backends.py
parent61d525cc16a10dcd780d2fc14a7371dc809223d0 (diff)
downloadmeson-c8490315133166136b6dd8ac8b94c7349240eea0.zip
meson-c8490315133166136b6dd8ac8b94c7349240eea0.tar.gz
meson-c8490315133166136b6dd8ac8b94c7349240eea0.tar.bz2
backends: fix source dir stripping from rpaths
Commit e88887be4a08 ("Only remove substring if it is part of string") removed the source dir from the rpath when the following check succeeds: if absdir.startswith(self.environment.get_source_dir()): rel_to_src = absdir[len(self.environment.get_source_dir()) + 1:] For example, absdir '/myproject/foo' starts with source dir '/myproject', so we want to generate the relative path 'foo'. This code doesn't work with absdir '/myproject-libs/foo' though, because we'll incorrectly turn it into a relative path 'libs/foo' after stripping away '/myproject-'. Use os.path.commonpath() instead of str.startswith() so path components are correctly handled. Cc: Niklas Claesson <niklas.claesson@cosylab.com> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Diffstat (limited to 'mesonbuild/backend/backends.py')
-rw-r--r--mesonbuild/backend/backends.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 4a68c57..c7615b7 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -733,6 +733,7 @@ class Backend:
@lru_cache(maxsize=None)
def rpaths_for_non_system_absolute_shared_libraries(self, target: build.BuildTarget, exclude_system: bool = True) -> 'ImmutableListProtocol[str]':
paths: OrderedSet[str] = OrderedSet()
+ srcdir = self.environment.get_source_dir()
for dep in target.external_deps:
if not isinstance(dep, (dependencies.ExternalLibrary, dependencies.PkgConfigDependency)):
continue
@@ -751,8 +752,14 @@ class Backend:
# emulate rpaths by setting PATH, so also accept DLLs here
if os.path.splitext(libpath)[1] not in ['.dll', '.lib', '.so', '.dylib']:
continue
- if libdir.startswith(self.environment.get_source_dir()):
- rel_to_src = libdir[len(self.environment.get_source_dir()) + 1:]
+
+ try:
+ commonpath = os.path.commonpath((libdir, srcdir))
+ except ValueError: # when paths are on different drives on Windows
+ commonpath = ''
+
+ if commonpath == srcdir:
+ rel_to_src = libdir[len(srcdir) + 1:]
assert not os.path.isabs(rel_to_src), f'rel_to_src: {rel_to_src} is absolute'
paths.add(os.path.join(self.build_to_src, rel_to_src))
else: