aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2022-07-15 04:15:48 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2022-08-08 19:10:00 +0530
commit7c6f0256b359025a946be3e3411fdf6c2f58fe2b (patch)
treeeff3b7a3debc391a51e5b24cd12281d2d2503019
parente06506e68ed479ada7b1a30263bece8d7caae7f7 (diff)
downloadmeson-7c6f0256b359025a946be3e3411fdf6c2f58fe2b.zip
meson-7c6f0256b359025a946be3e3411fdf6c2f58fe2b.tar.gz
meson-7c6f0256b359025a946be3e3411fdf6c2f58fe2b.tar.bz2
wrap: Fix diff_files not finding the patch to apply
When `self.wrap.filesdir` is a relative path, which happens when `meson subprojects update` is run, the path to the patch must be provided relative to the working directory in which `patch` or `git` is run. `self.wrap.filesdir` is absolute when `Resolve()` is invoked by the Meson interpreter, which is why this wasn't detected by the tests.
-rw-r--r--mesonbuild/wrap/wrap.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 00ef9a0..e1751b7 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -647,14 +647,15 @@ class Resolver:
path = Path(self.wrap.filesdir) / filename
if not path.exists():
raise WrapException(f'Diff file "{path}" does not exist')
+ relpath = os.path.relpath(str(path), self.dirname)
if PATCH:
- cmd = [PATCH, '-f', '-p1', '-i', str(path)]
+ cmd = [PATCH, '-f', '-p1', '-i', relpath]
elif GIT:
# If the `patch` command is not available, fall back to `git
# apply`. The `--work-tree` is necessary in case we're inside a
# Git repository: by default, Git will try to apply the patch to
# the repository root.
- cmd = [GIT, '--work-tree', '.', 'apply', '-p1', str(path)]
+ cmd = [GIT, '--work-tree', '.', 'apply', '-p1', relpath]
else:
raise WrapException('Missing "patch" or "git" commands to apply diff files')