diff options
author | rillig <rillig@pkgsrc.org> | 2020-10-17 22:39:00 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-10-17 22:39:00 +0000 |
commit | 6ff5c0120f5a75c12bf6edb84a695e05ecd06032 (patch) | |
tree | e9b6fbbb04dfebc296aa1ed54e5808e4d81cf646 | |
parent | 9632f9c4de928e23688e543ddc6e8bc0dcfe703d (diff) | |
download | pkgsrc-6ff5c0120f5a75c12bf6edb84a695e05ecd06032.tar.gz |
pkgtools/url2pkg: update to 20.3.0
Changes since 20.2.0:
Fixed detection for V2 Cargo.lock files. Patch provided by snow flurry
via tech-pkg, slightly adjusted. The test case for Cargo.lock file
detection had been incomplete and unrealistic. It has been extended to
show the relevant section of a whole package.
https://mail-index.netbsd.org/tech-pkg/2020/10/12/msg023897.html
https://mail-index.netbsd.org/tech-pkg/2020/10/13/msg023901.html
https://mail-index.netbsd.org/tech-pkg/2020/10/13/msg023902.html
-rw-r--r-- | pkgtools/url2pkg/Makefile | 5 | ||||
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg.py | 33 | ||||
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg_test.py | 55 |
3 files changed, 81 insertions, 12 deletions
diff --git a/pkgtools/url2pkg/Makefile b/pkgtools/url2pkg/Makefile index c7ee36e8a07..965fd42cca4 100644 --- a/pkgtools/url2pkg/Makefile +++ b/pkgtools/url2pkg/Makefile @@ -1,7 +1,6 @@ -# $NetBSD: Makefile,v 1.114 2020/08/31 18:10:59 wiz Exp $ +# $NetBSD: Makefile,v 1.115 2020/10/17 22:39:00 rillig Exp $ -PKGNAME= url2pkg-20.2.0 -PKGREVISION= 1 +PKGNAME= url2pkg-20.3.0 CATEGORIES= pkgtools MAINTAINER= rillig@NetBSD.org diff --git a/pkgtools/url2pkg/files/url2pkg.py b/pkgtools/url2pkg/files/url2pkg.py index ec2ea38b8e3..77313a58baf 100644 --- a/pkgtools/url2pkg/files/url2pkg.py +++ b/pkgtools/url2pkg/files/url2pkg.py @@ -1,5 +1,5 @@ #! @PYTHONBIN@ -# $NetBSD: url2pkg.py,v 1.27 2019/11/18 07:50:51 rillig Exp $ +# $NetBSD: url2pkg.py,v 1.28 2020/10/17 22:39:01 rillig Exp $ # Copyright (c) 2019 The NetBSD Foundation, Inc. # All rights reserved. @@ -922,9 +922,32 @@ class Adjuster: if not self.wrksrc_isfile('Cargo.lock'): return - # "checksum cargo-package-name cargo-package-version - for (name, version) in self.wrksrc_grep('Cargo.lock', r'^"checksum\s(\S+)\s(\S+)'): - self.build_vars.append(Var('CARGO_CRATE_DEPENDS', '+=', f'{name}-{version}')) + # pull name and version from package entries + with self.wrksrc_open('Cargo.lock') as f: + name = '' + version = '' + for line in f: + if line.startswith('[[package]]'): + # new package, reset name and version to be safe + name = '' + version = '' + continue + + m = re.match(r'^name\s=\s"(\S+)"', line) + if m: + name = m[1] + + m = re.match(r'^version\s=\s"(\S+)"', line) + if m: + version = m[1] + + if re.match(r'^source\s=\s"(\S+)"', line): + if name != '' and version != '': + self.build_vars.append(Var( + 'CARGO_CRATE_DEPENDS', '+=', f'{name}-{version}' + )) + name = '' + version = '' self.includes.append('../../lang/rust/cargo.mk') @@ -1033,7 +1056,7 @@ class Adjuster: lines = Lines(*self.makefile_lines.lines[: marker_index]) if lines.get('PKGNAME') == '' and \ - (self.pkgname_prefix != '' or self.pkgname_transform != ''): + (self.pkgname_prefix != '' or self.pkgname_transform != ''): distname_index = lines.index(r'^DISTNAME=(\t+)') if distname_index != -1: pkgname_line = f'PKGNAME=\t{self.pkgname_prefix}${{DISTNAME{self.pkgname_transform}}}' diff --git a/pkgtools/url2pkg/files/url2pkg_test.py b/pkgtools/url2pkg/files/url2pkg_test.py index a57b920cafe..89b1e03b330 100644 --- a/pkgtools/url2pkg/files/url2pkg_test.py +++ b/pkgtools/url2pkg/files/url2pkg_test.py @@ -1,7 +1,8 @@ -# $NetBSD: url2pkg_test.py,v 1.26 2019/11/18 07:56:02 rillig Exp $ +# $NetBSD: url2pkg_test.py,v 1.27 2020/10/17 22:39:01 rillig Exp $ import pytest from url2pkg import * +from textwrap import dedent mkcvsid = '# $''NetBSD$' g: Globals @@ -943,15 +944,61 @@ def test_Adjuster_adjust_cargo__not_found(tmp_path: Path): assert str_vars(adjuster.build_vars) == [] -def test_Adjuster_adjust_cargo__found(tmp_path: Path): +def test_Adjuster_adjust_cargo__before_0_39(tmp_path: Path): adjuster = Adjuster(g, '', Lines()) adjuster.abs_wrksrc = tmp_path - (tmp_path / 'Cargo.lock').write_text('"checksum cargo-pkg 1.2.3 1234"') + (tmp_path / 'Cargo.lock').write_text(dedent('''\ + [[package]] + name = "aes-ctr" + version = "0.3.0" + source = "registry+https://github.com/rust-lang/crates.io-index" + dependencies = [ + "aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + ] + + [metadata] + ... + "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "..." + ... + ''')) adjuster.adjust_cargo() assert str_vars(adjuster.build_vars) == [ - 'CARGO_CRATE_DEPENDS+=cargo-pkg-1.2.3', + 'CARGO_CRATE_DEPENDS+=aes-ctr-0.3.0', + ] + + +def test_Adjuster_adjust_cargo__since_0_39(tmp_path: Path): + """ + https://github.com/rust-lang/cargo/pull/7070/commits/34bca035ae133abe7e62acd0e90698943d471080 + + There is no [metadata] section anymore. + The checksum has been moved directly into the [[package]] section. + """ + adjuster = Adjuster(g, '', Lines()) + adjuster.abs_wrksrc = tmp_path + (tmp_path / 'Cargo.lock').write_text(dedent('''\ + [[package]] + name = "aes-ctr" + version = "0.3.0" + source = "registry+https://github.com/rust-lang/crates.io-index" + checksum = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" + dependencies = [ + "aes-soft", + "aesni", + "ctr", + "stream-cipher", + ] + ''')) + + adjuster.adjust_cargo() + + assert str_vars(adjuster.build_vars) == [ + 'CARGO_CRATE_DEPENDS+=aes-ctr-0.3.0', ] |