diff options
16 files changed, 76 insertions, 26 deletions
diff --git a/docs/markdown/Wrap-dependency-system-manual.md b/docs/markdown/Wrap-dependency-system-manual.md index 6e47d5841..868263c12 100644 --- a/docs/markdown/Wrap-dependency-system-manual.md +++ b/docs/markdown/Wrap-dependency-system-manual.md @@ -28,16 +28,16 @@ itself in a way that makes it easy to use (usually this means as a static library). To use this kind of a project as a dependency you could just copy and -extract it inside your project's `subprojects` directory. +extract it inside your project's `subprojects` directory. However there is a simpler way. You can specify a Wrap file that tells Meson -how to download it for you. If you then use this subproject in your build, +how to download it for you. If you then use this subproject in your build, Meson will automatically download and extract it during build. This makes subproject embedding extremely easy. All wrap files must have a name of `<project_name>.wrap` form and be in `subprojects` dir. -Currently Meson has four kinds of wraps: +Currently Meson has four kinds of wraps: - wrap-file - wrap-git - wrap-hg @@ -83,6 +83,12 @@ revision = head directory name. Needed when the source file does not have a leading directory. +Since *0.55.0* it is possible to use only the `source_filename` and +`patch_filename` value in a .wrap file (without `source_url` and `patch_url`) to +specify a local archive in the `subprojects/packagefiles` directory. The `*_hash` +entries are optional when using this method. This method should be prefered over +the old `packagecache` approach described below. + Since *0.49.0* if `source_filename` or `patch_filename` is found in the project's `subprojects/packagecache` directory, it will be used instead of downloading the file, even if `--wrap-mode` option is set to @@ -129,14 +135,14 @@ wrap-git, the repository must contain all Meson build definitions. ## Using wrapped projects -Wraps provide a convenient way of obtaining a project into your subproject directory. +Wraps provide a convenient way of obtaining a project into your subproject directory. Then you use it as a regular subproject (see [subprojects](Subprojects.md)). ## Getting wraps -Usually you don't want to write your wraps by hand. +Usually you don't want to write your wraps by hand. -There is an online repository called [WrapDB](https://wrapdb.mesonbuild.com) that provides +There is an online repository called [WrapDB](https://wrapdb.mesonbuild.com) that provides many dependencies ready to use. You can read more about WrapDB [here](Using-the-WrapDB.md). There is also a Meson subcommand to get and manage wraps (see [using wraptool](Using-wraptool.md)). diff --git a/docs/markdown/snippets/wrap_patch.md b/docs/markdown/snippets/wrap_patch.md new file mode 100644 index 000000000..7d6d9c242 --- /dev/null +++ b/docs/markdown/snippets/wrap_patch.md @@ -0,0 +1,6 @@ +## Local wrap source and patch files + +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. diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 07ab4f0e9..b8d4fec75 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2764,7 +2764,7 @@ external dependencies (including libraries) must go to "dependencies".''') return subproject subproject_dir_abs = os.path.join(self.environment.get_source_dir(), self.subproject_dir) - r = wrap.Resolver(subproject_dir_abs, self.coredata.get_builtin_option('wrap_mode')) + r = wrap.Resolver(subproject_dir_abs, self.coredata.get_builtin_option('wrap_mode'), current_subproject=self.subproject) try: resolved = r.resolve(dirname, method) except wrap.WrapException as e: diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 1715cd317..9d95bff6a 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -27,6 +27,7 @@ import sys import configparser import typing as T +from pathlib import Path from . import WrapMode from ..mesonlib import git, GIT, ProgressBar, MesonException @@ -126,7 +127,7 @@ class PackageDefinition: raise WrapException(m.format(key, self.basename)) def has_patch(self) -> bool: - return 'patch_url' in self.values + return 'patch_filename' in self.values def load_wrap(subdir_root: str, packagename: str) -> PackageDefinition: fname = os.path.join(subdir_root, packagename + '.wrap') @@ -146,10 +147,12 @@ def get_directory(subdir_root: str, packagename: str): return wrap, directory class Resolver: - def __init__(self, subdir_root: str, wrap_mode=WrapMode.default): + def __init__(self, subdir_root: str, wrap_mode=WrapMode.default, current_subproject: str = ''): self.wrap_mode = wrap_mode self.subdir_root = subdir_root + self.current_subproject = current_subproject self.cachedir = os.path.join(self.subdir_root, 'packagecache') + self.filesdir = os.path.join(self.subdir_root, 'packagefiles') def resolve(self, packagename: str, method: str) -> str: self.packagename = packagename @@ -363,7 +366,9 @@ class Resolver: hashvalue = h.hexdigest() return hashvalue, tmpfile.name - def check_hash(self, what: str, path: str) -> None: + def check_hash(self, what: str, path: str, hash_required: bool = True) -> None: + if what + '_hash' not in self.wrap.values and not hash_required: + return expected = self.wrap.get(what + '_hash') h = hashlib.sha256() with open(path, 'rb') as f: @@ -393,17 +398,28 @@ class Resolver: def get_file_internal(self, what: str) -> str: filename = self.wrap.get(what + '_filename') - cache_path = os.path.join(self.cachedir, filename) + if what + '_url' in self.wrap.values: + cache_path = os.path.join(self.cachedir, filename) - if os.path.exists(cache_path): - self.check_hash(what, cache_path) - mlog.log('Using', mlog.bold(self.packagename), what, 'from cache.') + if os.path.exists(cache_path): + self.check_hash(what, cache_path) + mlog.log('Using', mlog.bold(self.packagename), what, 'from cache.') + return cache_path + + if not os.path.isdir(self.cachedir): + os.mkdir(self.cachedir) + self.download(what, cache_path) return cache_path + else: + from ..interpreterbase import FeatureNew + FeatureNew('Local wrap patch files without {}_url'.format(what), '0.55.0').use(self.current_subproject) + path = Path(self.filesdir) / filename + + if not path.exists(): + raise WrapException('File "{}" does not exist'.format(path)) + self.check_hash(what, path.as_posix(), hash_required=False) - if not os.path.isdir(self.cachedir): - os.mkdir(self.cachedir) - self.download(what, cache_path) - return cache_path + return path.as_posix() def apply_patch(self) -> None: path = self.get_file_internal('patch') 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 f4ec2a8c5..cffce2f10 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 @@ -3,7 +3,11 @@ project('mainproj', 'c', ) subproject('zlib') -subproject('foo') +foo = subproject('foo') +bar = subproject('bar') + +libfoo = foo.get_variable('libfoo') +libbar = bar.get_variable('libbar') executable('grabprog', files('src/subprojects/prog.c')) executable('grabprog2', files('src/subprojects/foo/prog2.c')) diff --git a/test cases/common/157 wrap file should not failed/src/meson.build b/test cases/common/157 wrap file should not failed/src/meson.build index 69f666d1a..0c82165d1 100644 --- a/test cases/common/157 wrap file should not failed/src/meson.build +++ b/test cases/common/157 wrap file should not failed/src/meson.build @@ -1,2 +1,6 @@ executable('grabprog3', files('subprojects/prog.c')) executable('grabprog4', files('subprojects/foo/prog2.c')) + +texe = executable('testexe', files('test.c'), link_with: [libfoo, libbar]) + +test('t1', texe) diff --git a/test cases/common/157 wrap file should not failed/src/test.c b/test cases/common/157 wrap file should not failed/src/test.c new file mode 100644 index 000000000..34cf99183 --- /dev/null +++ b/test cases/common/157 wrap file should not failed/src/test.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int bar_dummy_func(void); +int dummy_func(void); + +int main(void) { + printf("Hello world %d\n", bar_dummy_func() + dummy_func()); + return 0; +} diff --git a/test cases/common/157 wrap file should not failed/subprojects/.gitignore b/test cases/common/157 wrap file should not failed/subprojects/.gitignore new file mode 100644 index 000000000..5550e2e0d --- /dev/null +++ b/test cases/common/157 wrap file should not failed/subprojects/.gitignore @@ -0,0 +1,2 @@ +/foo-1.0 +/bar-1.0 diff --git a/test cases/common/157 wrap file should not failed/subprojects/bar.wrap b/test cases/common/157 wrap file should not failed/subprojects/bar.wrap new file mode 100644 index 000000000..4e8f7e392 --- /dev/null +++ b/test cases/common/157 wrap file should not failed/subprojects/bar.wrap @@ -0,0 +1,8 @@ +[wrap-file] +directory = bar-1.0 +lead_directory_missing = true + +source_filename = bar-1.0.tar.xz +source_hash = f0f61948530dc0d33e3028cd71a9f8ee869f6b3665960d8f41d715cf4aed6467 + +patch_filename = bar-1.0-patch.tar.xz diff --git a/test cases/common/157 wrap file should not failed/subprojects/foo-1.0/foo.c b/test cases/common/157 wrap file should not failed/subprojects/foo-1.0/foo.c deleted file mode 100644 index 267b43aa5..000000000 --- a/test cases/common/157 wrap file should not failed/subprojects/foo-1.0/foo.c +++ /dev/null @@ -1,3 +0,0 @@ -int dummy_func(void) { - return 42; -} diff --git a/test cases/common/157 wrap file should not failed/subprojects/foo-1.0/meson.build b/test cases/common/157 wrap file should not failed/subprojects/foo-1.0/meson.build deleted file mode 100644 index 318e81dda..000000000 --- a/test cases/common/157 wrap file should not failed/subprojects/foo-1.0/meson.build +++ /dev/null @@ -1,2 +0,0 @@ -project('shared lib', 'c') -libfoo = shared_library('foo', 'foo.c') diff --git a/test cases/common/157 wrap file should not failed/subprojects/foo.wrap b/test cases/common/157 wrap file should not failed/subprojects/foo.wrap index 90d6d4005..c67c5e5db 100644 --- a/test cases/common/157 wrap file should not failed/subprojects/foo.wrap +++ b/test cases/common/157 wrap file should not failed/subprojects/foo.wrap @@ -3,9 +3,9 @@ directory = foo-1.0 source_url = http://something.invalid source_filename = foo-1.0.tar.xz -source_hash = ae5fc03185654f76b459db16ca25809703f8821aeb39a433902244bb479c4b79 +source_hash = 9ed8f67d75e43d3be161efb6eddf30dd01995a958ca83951ea64234bac8908c1 lead_directory_missing = true patch_url = https://something.invalid/patch patch_filename = foo-1.0-patch.tar.xz -patch_hash = 8f2e286a4b190228d4e0c25ddc91195449cfb5e5c52006355838964b244037da +patch_hash = d0ddc5e60fdb27d808552f5ac8d0bb603ea2cba306538b4427b985535b26c9c5 diff --git a/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0-patch.tar.xz b/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0-patch.tar.xz Binary files differindex 26d2927e3..e26b8e06f 100644 --- a/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0-patch.tar.xz +++ b/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0-patch.tar.xz diff --git a/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0.tar.xz b/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0.tar.xz Binary files differindex 2647ef94c..37eb6cc71 100644 --- a/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0.tar.xz +++ b/test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0.tar.xz diff --git a/test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0-patch.tar.xz b/test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0-patch.tar.xz Binary files differnew file mode 100644 index 000000000..f257a1965 --- /dev/null +++ b/test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0-patch.tar.xz diff --git a/test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0.tar.xz b/test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0.tar.xz Binary files differnew file mode 100644 index 000000000..d90a9e8b0 --- /dev/null +++ b/test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0.tar.xz |
