wrap: Add patch_directory support

Copy a tree instead of extracting an archive.

Closes: #7216
pull/7183/head
Xavier Claessens 5 years ago committed by Jussi Pakkanen
parent 246e5437aa
commit e353b2e8d4
  1. 3
      docs/markdown/Wrap-dependency-system-manual.md
  2. 8
      docs/markdown/snippets/wrap_patch.md
  3. 32
      mesonbuild/wrap/wrap.py
  4. 2
      test cases/common/157 wrap file should not failed/meson.build
  5. 2
      test cases/common/157 wrap file should not failed/subprojects/packagefiles/foo-1.0/meson.build
  6. 9
      test cases/common/157 wrap file should not failed/subprojects/patchdir.wrap

@ -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.

@ -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.

@ -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:
"""

@ -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')

@ -0,0 +1,2 @@
project('static lib patchdir', 'c')
libfoo = static_library('foo', 'foo.c')

@ -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
Loading…
Cancel
Save