Merge pull request #6818 from mensinda/localPatch

Wrap: add local files support via *_filename
pull/7225/head
Jussi Pakkanen 5 years ago committed by GitHub
commit c61f75adbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      docs/markdown/Wrap-dependency-system-manual.md
  2. 6
      docs/markdown/snippets/wrap_patch.md
  3. 2
      mesonbuild/interpreter.py
  4. 38
      mesonbuild/wrap/wrap.py
  5. 6
      test cases/common/157 wrap file should not failed/meson.build
  6. 4
      test cases/common/157 wrap file should not failed/src/meson.build
  7. 9
      test cases/common/157 wrap file should not failed/src/test.c
  8. 2
      test cases/common/157 wrap file should not failed/subprojects/.gitignore
  9. 8
      test cases/common/157 wrap file should not failed/subprojects/bar.wrap
  10. 3
      test cases/common/157 wrap file should not failed/subprojects/foo-1.0/foo.c
  11. 2
      test cases/common/157 wrap file should not failed/subprojects/foo-1.0/meson.build
  12. 4
      test cases/common/157 wrap file should not failed/subprojects/foo.wrap
  13. BIN
      test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0-patch.tar.xz
  14. BIN
      test cases/common/157 wrap file should not failed/subprojects/packagecache/foo-1.0.tar.xz
  15. BIN
      test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0-patch.tar.xz
  16. BIN
      test cases/common/157 wrap file should not failed/subprojects/packagefiles/bar-1.0.tar.xz

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

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

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

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

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

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

@ -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;
}

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

@ -1,2 +0,0 @@
project('shared lib', 'c')
libfoo = shared_library('foo', 'foo.c')

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

Loading…
Cancel
Save