Skip to content

Commit

Permalink
pkgtools/url2pkg: update to 23.4.0
Browse files Browse the repository at this point in the history
Changes since 23.3.3:

Place Rust dependencies in a separate file cargo-depends.mk.
  • Loading branch information
rillig committed Nov 23, 2024
1 parent a797953 commit fff5169
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkgtools/url2pkg/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# $NetBSD: Makefile,v 1.141 2024/10/26 19:05:45 schmonz Exp $
# $NetBSD: Makefile,v 1.142 2024/11/23 22:30:29 rillig Exp $

PKGNAME= url2pkg-23.3.3
PKGNAME= url2pkg-23.4.0
CATEGORIES= pkgtools

MAINTAINER= rillig@NetBSD.org
Expand Down
25 changes: 20 additions & 5 deletions pkgtools/url2pkg/files/url2pkg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! @PYTHONBIN@
# $NetBSD: url2pkg.py,v 1.56 2024/10/26 19:05:45 schmonz Exp $
# $NetBSD: url2pkg.py,v 1.57 2024/11/23 22:30:30 rillig Exp $

# Copyright (c) 2019 The NetBSD Foundation, Inc.
# All rights reserved.
Expand Down Expand Up @@ -688,6 +688,9 @@ class Adjuster:
tool_depends: List[str]
test_depends: List[str]

# the Rust dependencies of the package, in the form "package-version".
cargo_crate_depends: List[str]

# .include, interleaved with BUILDLINK3_API_DEPENDS.
# These lines are added at the bottom of the Makefile.
bl3_lines: List[str]
Expand Down Expand Up @@ -736,6 +739,7 @@ def __init__(self, g: Globals, url: str, initial_lines: Lines):
self.build_depends = []
self.tool_depends = []
self.test_depends = []
self.cargo_crate_depends = []
self.bl3_lines = []
self.includes = []
self.build_vars = []
Expand Down Expand Up @@ -862,14 +866,15 @@ def add_dependencies(self, dep_lines: List[Tuple[str, str, str, str]],
self.add_dependency(kind, pkgbase, constraint, dep_dir)

def sort_dependencies(self):
def key(d):
def key(d: str) -> str:
a = d.removeprefix('# TODO: ')
return re.sub('[<>=].*', '', a)

self.depends.sort(key=key)
self.build_depends.sort(key=key)
self.tool_depends.sort(key=key)
self.test_depends.sort(key=key)
self.cargo_crate_depends.sort(key=key)

def set_or_add(self, varname: str, value: str):
if not self.makefile_lines.set(varname, value):
Expand Down Expand Up @@ -1083,9 +1088,7 @@ def adjust_cargo(self):

if re.match(r'^source\s=\s"(\S+)"', line):
if name != '' and version != '':
self.build_vars.append(Var(
'CARGO_CRATE_DEPENDS', '+=', f'{name}-{version}'
))
self.cargo_crate_depends.append(f'{name}-{version}')
name = ''
version = ''

Expand Down Expand Up @@ -1229,6 +1232,10 @@ def generate_lines(self) -> Lines:
lines.add_vars(*build_vars)
lines.add_vars(*self.extra_vars)

if self.cargo_crate_depends:
lines.add('.include "cargo-depends.mk"')
lines.add('')

lines.add(*self.bl3_lines)
lines.add(*(f'.include "{include}"' for include in self.includes))

Expand Down Expand Up @@ -1274,6 +1281,14 @@ def scan(basedir: Union[Path, Any],
descr = (self.g.pkgdir / 'DESCR')
descr.is_file() or Lines(*self.descr_lines).write_to(descr)

if self.cargo_crate_depends:
lines = Lines()
lines.add('# $NetBSD: url2pkg.py,v 1.57 2024/11/23 22:30:30 rillig Exp $')
lines.add('')
for dep in self.cargo_crate_depends:
lines.add(f'CARGO_CRATE_DEPENDS+=\t{dep}')
lines.write_to(self.g.pkgdir / 'cargo-depends.mk')

if self.regenerate_distinfo:
self.g.bmake('distinfo')

Expand Down
12 changes: 6 additions & 6 deletions pkgtools/url2pkg/files/url2pkg_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# $NetBSD: url2pkg_test.py,v 1.52 2024/10/26 19:05:45 schmonz Exp $
# $NetBSD: url2pkg_test.py,v 1.53 2024/11/23 22:30:30 rillig Exp $

# URLs for manual testing:
#
Expand Down Expand Up @@ -1063,7 +1063,7 @@ def test_Adjuster_adjust_cargo__not_found(tmp_path: Path):

adjuster.adjust_cargo()

assert str_vars(adjuster.build_vars) == []
assert adjuster.cargo_crate_depends == []


def test_Adjuster_adjust_cargo__before_0_39(tmp_path: Path):
Expand All @@ -1089,8 +1089,8 @@ def test_Adjuster_adjust_cargo__before_0_39(tmp_path: Path):

adjuster.adjust_cargo()

assert str_vars(adjuster.build_vars) == [
'CARGO_CRATE_DEPENDS+=aes-ctr-0.3.0',
assert adjuster.cargo_crate_depends == [
'aes-ctr-0.3.0',
]


Expand Down Expand Up @@ -1119,8 +1119,8 @@ def test_Adjuster_adjust_cargo__since_0_39(tmp_path: Path):

adjuster.adjust_cargo()

assert str_vars(adjuster.build_vars) == [
'CARGO_CRATE_DEPENDS+=aes-ctr-0.3.0',
assert adjuster.cargo_crate_depends == [
'aes-ctr-0.3.0',
]


Expand Down

0 comments on commit fff5169

Please sign in to comment.