From e353b2e8d48c8ffce579342fac9ccfc62127bec8 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 28 May 2020 13:22:57 -0400 Subject: [PATCH] wrap: Add patch_directory support Copy a tree instead of extracting an archive. Closes: #7216 --- .../markdown/Wrap-dependency-system-manual.md | 3 ++ docs/markdown/snippets/wrap_patch.md | 8 +++++ mesonbuild/wrap/wrap.py | 32 ++++++++++++------- .../meson.build | 2 ++ .../packagefiles/foo-1.0/meson.build | 2 ++ .../subprojects/patchdir.wrap | 9 ++++++ 6 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 test cases/common/157 wrap file should not failed/subprojects/packagefiles/foo-1.0/meson.build create mode 100644 test cases/common/157 wrap file should not failed/subprojects/patchdir.wrap diff --git a/docs/markdown/Wrap-dependency-system-manual.md b/docs/markdown/Wrap-dependency-system-manual.md index 868263c12..f6c658f9c 100644 --- a/docs/markdown/Wrap-dependency-system-manual.md +++ b/docs/markdown/Wrap-dependency-system-manual.md @@ -79,6 +79,9 @@ revision = head - `patch_fallback_url` - fallback URL to be used when download from `patch_url` fails *Since: 0.55.0* - `patch_filename` - filename of the downloaded overlay archive - `patch_hash` - sha256 checksum of the downloaded overlay archive +- `patch_directory` - *Since 0.55.0* Overlay directory, alternative to `patch_filename` in the case + files are local instead of a downloaded archive. The directory must be placed in + `subprojects/packagefiles`. - `lead_directory_missing` - for `wrap-file` create the leading directory name. Needed when the source file does not have a leading directory. diff --git a/docs/markdown/snippets/wrap_patch.md b/docs/markdown/snippets/wrap_patch.md index 7d6d9c242..d5a1f5f01 100644 --- a/docs/markdown/snippets/wrap_patch.md +++ b/docs/markdown/snippets/wrap_patch.md @@ -4,3 +4,11 @@ It is now possible to use the `patch_filename` and `source_filename` value in a `.wrap` file without `*_url` to specify a local source / patch file. All local files must be located in the `subprojects/packagefiles` directory. The `*_hash` entries are optional with this setup. + +## Local wrap patch directory + +Wrap files can now specify `patch_directory` instead of `patch_filename` in the +case overlay files are local. Every files in that directory, and subdirectories, +will be copied to the subproject directory. This can be used for example to add +`meson.build` files to a project not using Meson build system upstream. +The patch directory must be placed in `subprojects/packagefiles` directory. diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 9d95bff6a..44173f7ab 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -126,9 +126,6 @@ class PackageDefinition: m = 'Missing key {!r} in {}' raise WrapException(m.format(key, self.basename)) - def has_patch(self) -> bool: - return 'patch_filename' in self.values - def load_wrap(subdir_root: str, packagename: str) -> PackageDefinition: fname = os.path.join(subdir_root, packagename + '.wrap') if os.path.isfile(fname): @@ -253,8 +250,7 @@ class Resolver: os.mkdir(self.dirname) extract_dir = self.dirname shutil.unpack_archive(path, extract_dir) - if self.wrap.has_patch(): - self.apply_patch() + self.apply_patch() def get_git(self) -> None: if not GIT: @@ -422,13 +418,25 @@ class Resolver: return path.as_posix() def apply_patch(self) -> None: - path = self.get_file_internal('patch') - try: - shutil.unpack_archive(path, self.subdir_root) - except Exception: - with tempfile.TemporaryDirectory() as workdir: - shutil.unpack_archive(path, workdir) - self.copy_tree(workdir, self.subdir_root) + if 'patch_filename' in self.wrap.values and 'patch_directory' in self.wrap.values: + m = 'Wrap file {!r} must not have both "patch_filename" and "patch_directory"' + raise WrapException(m.format(self.wrap.basename)) + if 'patch_filename' in self.wrap.values: + path = self.get_file_internal('patch') + try: + shutil.unpack_archive(path, self.subdir_root) + except Exception: + with tempfile.TemporaryDirectory() as workdir: + shutil.unpack_archive(path, workdir) + self.copy_tree(workdir, self.subdir_root) + elif 'patch_directory' in self.wrap.values: + from ..interpreterbase import FeatureNew + FeatureNew('patch_directory', '0.55.0').use(self.current_subproject) + patch_dir = self.wrap.values['patch_directory'] + src_dir = os.path.join(self.filesdir, patch_dir) + if not os.path.isdir(src_dir): + raise WrapException('patch directory does not exists: {}'.format(patch_dir)) + self.copy_tree(src_dir, self.dirname) def copy_tree(self, root_src_dir: str, root_dst_dir: str) -> None: """ diff --git a/test cases/common/157 wrap file should not failed/meson.build b/test cases/common/157 wrap file should not failed/meson.build index cffce2f10..48d10688a 100644 --- a/test cases/common/157 wrap file should not failed/meson.build +++ b/test cases/common/157 wrap file should not failed/meson.build @@ -12,3 +12,5 @@ libbar = bar.get_variable('libbar') executable('grabprog', files('src/subprojects/prog.c')) executable('grabprog2', files('src/subprojects/foo/prog2.c')) subdir('src') + +subproject('patchdir') diff --git a/test cases/common/157 wrap file should not failed/subprojects/packagefiles/foo-1.0/meson.build b/test cases/common/157 wrap file should not failed/subprojects/packagefiles/foo-1.0/meson.build new file mode 100644 index 000000000..dbaf91f2b --- /dev/null +++ b/test cases/common/157 wrap file should not failed/subprojects/packagefiles/foo-1.0/meson.build @@ -0,0 +1,2 @@ +project('static lib patchdir', 'c') +libfoo = static_library('foo', 'foo.c') diff --git a/test cases/common/157 wrap file should not failed/subprojects/patchdir.wrap b/test cases/common/157 wrap file should not failed/subprojects/patchdir.wrap new file mode 100644 index 000000000..1a2134c3d --- /dev/null +++ b/test cases/common/157 wrap file should not failed/subprojects/patchdir.wrap @@ -0,0 +1,9 @@ +[wrap-file] +directory = foo-1.0-patchdir + +source_url = http://something.invalid +source_filename = foo-1.0.tar.xz +source_hash = 9ed8f67d75e43d3be161efb6eddf30dd01995a958ca83951ea64234bac8908c1 +lead_directory_missing = true + +patch_directory = foo-1.0