wrap: Port to v2 protocol

Fixes: #8754.
pull/8796/head
Xavier Claessens 4 years ago
parent df4d2bd247
commit 62c53b834d
  1. 7
      mesonbuild/msubprojects.py
  2. 2
      mesonbuild/wrap/wrap.py
  3. 88
      mesonbuild/wrap/wraptool.py

@ -4,22 +4,23 @@ from pathlib import Path
from . import mlog from . import mlog
from .mesonlib import quiet_git, verbose_git, GitException, Popen_safe, MesonException, windows_proof_rmtree from .mesonlib import quiet_git, verbose_git, GitException, Popen_safe, MesonException, windows_proof_rmtree
from .wrap.wrap import API_ROOT, PackageDefinition, Resolver, WrapException, ALL_TYPES from .wrap.wrap import PackageDefinition, Resolver, WrapException, ALL_TYPES
from .wrap import wraptool from .wrap import wraptool
ALL_TYPES_STRING = ', '.join(ALL_TYPES) ALL_TYPES_STRING = ', '.join(ALL_TYPES)
def update_wrapdb_file(wrap): def update_wrapdb_file(wrap):
try:
patch_url = wrap.get('patch_url') patch_url = wrap.get('patch_url')
branch, revision = wraptool.parse_patch_url(patch_url) branch, revision = wraptool.parse_patch_url(patch_url)
except WrapException:
return
new_branch, new_revision = wraptool.get_latest_version(wrap.name) new_branch, new_revision = wraptool.get_latest_version(wrap.name)
if new_branch != branch or new_revision != revision: if new_branch != branch or new_revision != revision:
wraptool.update_wrap_file(wrap.filename, wrap.name, new_branch, new_revision) wraptool.update_wrap_file(wrap.filename, wrap.name, new_branch, new_revision)
mlog.log(' -> New wrap file downloaded.') mlog.log(' -> New wrap file downloaded.')
def update_file(r, wrap, repo_dir, options): def update_file(r, wrap, repo_dir, options):
patch_url = wrap.values.get('patch_url', '')
if patch_url.startswith(API_ROOT):
update_wrapdb_file(wrap) update_wrapdb_file(wrap)
if not os.path.isdir(repo_dir): if not os.path.isdir(repo_dir):
# The subproject is not needed, or it is a tarball extracted in # The subproject is not needed, or it is a tarball extracted in

@ -42,10 +42,8 @@ try:
# regarding 'imported but unused' can be safely ignored # regarding 'imported but unused' can be safely ignored
import ssl # noqa import ssl # noqa
has_ssl = True has_ssl = True
API_ROOT = 'https://wrapdb.mesonbuild.com/v1/'
except ImportError: except ImportError:
has_ssl = False has_ssl = False
API_ROOT = 'http://wrapdb.mesonbuild.com/v1/'
REQ_TIMEOUT = 600.0 REQ_TIMEOUT = 600.0
SSL_WARNING_PRINTED = False SSL_WARNING_PRINTED = False

@ -19,8 +19,9 @@ import shutil
import typing as T import typing as T
from glob import glob from glob import glob
from urllib.parse import urlparse
from .wrap import API_ROOT, open_wrapdburl from urllib.request import urlopen
from .wrap import WrapException
from .. import mesonlib from .. import mesonlib
@ -57,38 +58,30 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None:
p.add_argument('project_path') p.add_argument('project_path')
p.set_defaults(wrap_func=promote) p.set_defaults(wrap_func=promote)
def get_result(urlstring: str) -> T.Dict[str, T.Any]: def get_releases() -> T.Dict[str, T.Any]:
u = open_wrapdburl(urlstring) url = urlopen('https://wrapdb.mesonbuild.com/v2/releases.json')
data = u.read().decode('utf-8') return T.cast(T.Dict[str, T.Any], json.loads(url.read().decode()))
jd = json.loads(data)
if jd['output'] != 'ok':
print('Got bad output from server.', file=sys.stderr)
raise SystemExit(data)
assert isinstance(jd, dict)
return jd
def get_projectlist() -> T.List[str]:
jd = get_result(API_ROOT + 'projects')
projects = jd['projects']
assert isinstance(projects, list)
return projects
def list_projects(options: 'argparse.Namespace') -> None: def list_projects(options: 'argparse.Namespace') -> None:
projects = get_projectlist() releases = get_releases()
for p in projects: for p in releases.keys():
print(p) print(p)
def search(options: 'argparse.Namespace') -> None: def search(options: 'argparse.Namespace') -> None:
name = options.name name = options.name
jd = get_result(API_ROOT + 'query/byname/' + name) releases = get_releases()
for p in jd['projects']: for p in releases.keys():
if p.startswith(name):
print(p) print(p)
def get_latest_version(name: str) -> tuple: def get_latest_version(name: str) -> tuple:
jd = get_result(API_ROOT + 'query/get_latest/' + name) releases = get_releases()
branch = jd['branch'] info = releases.get(name)
revision = jd['revision'] if not info:
return branch, revision raise WrapException(f'Wrap {name} not found in wrapdb')
latest_version = info['versions'][0]
version, revision = latest_version.rsplit('-', 1)
return version, revision
def install(options: 'argparse.Namespace') -> None: def install(options: 'argparse.Namespace') -> None:
name = options.name name = options.name
@ -99,16 +92,28 @@ def install(options: 'argparse.Namespace') -> None:
wrapfile = os.path.join('subprojects', name + '.wrap') wrapfile = os.path.join('subprojects', name + '.wrap')
if os.path.exists(wrapfile): if os.path.exists(wrapfile):
raise SystemExit('Wrap file already exists.') raise SystemExit('Wrap file already exists.')
(branch, revision) = get_latest_version(name) (version, revision) = get_latest_version(name)
u = open_wrapdburl(API_ROOT + f'projects/{name}/{branch}/{revision}/get_wrap') url = urlopen(f'https://wrapdb.mesonbuild.com/v2/{name}_{version}-{revision}/{name}.wrap')
data = u.read()
with open(wrapfile, 'wb') as f: with open(wrapfile, 'wb') as f:
f.write(data) f.write(url.read())
print('Installed', name, 'branch', branch, 'revision', revision) print(f'Installed {name} version {version} revision {revision}')
def parse_patch_url(patch_url: str) -> T.Tuple[str, int]: def parse_patch_url(patch_url: str) -> T.Tuple[str, int]:
arr = patch_url.split('/') u = urlparse(patch_url)
if u.netloc != 'wrapdb.mesonbuild.com':
raise WrapException(f'URL {patch_url} does not seems to be a wrapdb patch')
arr = u.path.strip('/').split('/')
if arr[0] == 'v1':
# e.g. https://wrapdb.mesonbuild.com/v1/projects/zlib/1.2.11/5/get_zip
return arr[-3], int(arr[-2]) return arr[-3], int(arr[-2])
elif arr[0] == 'v2':
# e.g. https://wrapdb.mesonbuild.com/v2/zlib_1.2.11-5/get_patch
tag = arr[-2]
name, version = tag.rsplit('_', 1)
version, revision = version.rsplit('-', 1)
return version, int(revision)
else:
raise WrapException(f'Invalid wrapdb URL {patch_url}')
def get_current_version(wrapfile: str) -> T.Tuple[str, int, str, str, str]: def get_current_version(wrapfile: str) -> T.Tuple[str, int, str, str, str]:
cp = configparser.ConfigParser(interpolation=None) cp = configparser.ConfigParser(interpolation=None)
@ -118,11 +123,10 @@ def get_current_version(wrapfile: str) -> T.Tuple[str, int, str, str, str]:
branch, revision = parse_patch_url(patch_url) branch, revision = parse_patch_url(patch_url)
return branch, revision, wrap_data['directory'], wrap_data['source_filename'], wrap_data['patch_filename'] return branch, revision, wrap_data['directory'], wrap_data['source_filename'], wrap_data['patch_filename']
def update_wrap_file(wrapfile: str, name: str, new_branch: str, new_revision: str) -> None: def update_wrap_file(wrapfile: str, name: str, new_version: str, new_revision: str) -> None:
u = open_wrapdburl(API_ROOT + f'projects/{name}/{new_branch}/{new_revision}/get_wrap') url = urlopen(f'https://wrapdb.mesonbuild.com/v2/{name}_{new_version}-{new_revision}/{name}.wrap')
data = u.read()
with open(wrapfile, 'wb') as f: with open(wrapfile, 'wb') as f:
f.write(data) f.write(url.read())
def update(options: 'argparse.Namespace') -> None: def update(options: 'argparse.Namespace') -> None:
name = options.name name = options.name
@ -146,17 +150,17 @@ def update(options: 'argparse.Namespace') -> None:
os.unlink(os.path.join('subprojects/packagecache', patch_file)) os.unlink(os.path.join('subprojects/packagecache', patch_file))
except FileNotFoundError: except FileNotFoundError:
pass pass
print('Updated', name, 'to branch', new_branch, 'revision', new_revision) print(f'Updated {name} version {new_branch} revision {new_revision}')
def info(options: 'argparse.Namespace') -> None: def info(options: 'argparse.Namespace') -> None:
name = options.name name = options.name
jd = get_result(API_ROOT + 'projects/' + name) releases = get_releases()
versions = jd['versions'] info = releases.get(name)
if not versions: if not info:
raise SystemExit('No available versions of' + name) raise WrapException(f'Wrap {name} not found in wrapdb')
print(f'Available versions of {name}:') print(f'Available versions of {name}:')
for v in versions: for v in info['versions']:
print(' ', v['branch'], v['revision']) print(' ', v)
def do_promotion(from_path: str, spdir_name: str) -> None: def do_promotion(from_path: str, spdir_name: str) -> None:
if os.path.isfile(from_path): if os.path.isfile(from_path):

Loading…
Cancel
Save