diff options
author | rillig <rillig@pkgsrc.org> | 2019-08-18 13:32:21 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2019-08-18 13:32:21 +0000 |
commit | b6ab92b5f44fd83a54b3091b8b9807e3cbb57839 (patch) | |
tree | 3a533f96b9995278e244f33d14348e408fe2a91f /pkgtools | |
parent | d368b4ef4e4dfca65157da6d22554e19535e9b42 (diff) | |
download | pkgsrc-b6ab92b5f44fd83a54b3091b8b9807e3cbb57839.tar.gz |
pkgtools/url2pkg: add secondary category for Perl and Python modules
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/url2pkg/Makefile | 7 | ||||
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg.pl | 40 | ||||
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg.t | 125 |
3 files changed, 165 insertions, 7 deletions
diff --git a/pkgtools/url2pkg/Makefile b/pkgtools/url2pkg/Makefile index 4cbacfba568..815f3db30fa 100644 --- a/pkgtools/url2pkg/Makefile +++ b/pkgtools/url2pkg/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.94 2019/08/18 11:26:33 rillig Exp $ +# $NetBSD: Makefile,v 1.95 2019/08/18 13:32:21 rillig Exp $ PKGNAME= url2pkg-2.32 CATEGORIES= pkgtools @@ -16,7 +16,10 @@ USE_TOOLS+= perl:run AUTO_MKDIRS= yes do-extract: - cd ${FILESDIR} && cp *.pl *.pm *.py ${WRKSRC}/ + ${RUN} cd ${FILESDIR} && cp *.* ${WRKSRC}/ + +do-test: + ${RUN} cd ${WRKSRC} && env PKGSRCDIR=${PKGSRCDIR} perl -I. url2pkg.t .include "../../mk/bsd.prefs.mk" diff --git a/pkgtools/url2pkg/files/url2pkg.pl b/pkgtools/url2pkg/files/url2pkg.pl index 21fafde166e..c7a8363e319 100644 --- a/pkgtools/url2pkg/files/url2pkg.pl +++ b/pkgtools/url2pkg/files/url2pkg.pl @@ -1,5 +1,5 @@ #! @PERL5@ -# $NetBSD: url2pkg.pl,v 1.56 2019/08/18 11:26:33 rillig Exp $ +# $NetBSD: url2pkg.pl,v 1.57 2019/08/18 13:32:21 rillig Exp $ # # Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -111,6 +111,26 @@ sub find_package($) { return scalar(@candidates) == 1 ? $candidates[0] : ""; } +# appends the given value to the variable assignment. +sub update_var_append($$$) { + my ($lines, $varname, $value) = @_; + + return if $value eq ''; + + my $i = 0; + foreach my $line (@$lines) { + if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*)(#.*|)$") { + my ($op, $indent, $old_value, $comment) = ($1, $2, $3, $4); + + my $before = $old_value =~ qr'\S$' ? ' ' : ''; + my $after = $comment eq '' ? '' : ' '; + $lines->[$i] = "$varname$op$indent$old_value$before$value$after$comment"; + return; + } + $i++; + } +} + # The following adjust_* subroutines are called after the distfiles have # been downloaded and extracted. They inspect the extracted files # and adjust the variable definitions in the package Makefile. @@ -139,6 +159,10 @@ my @wrksrc_dirs; # will later appear in the package Makefile: # +# categories for the package, in addition to the usual +# parent directory. +my @categories; + # the dependencies of the package, in the form # "package>=version:../../category/package". my @depends; @@ -168,6 +192,9 @@ my @todos; # the package name, in case it differs from $distname. my $pkgname = ""; +# Example: +# add_dependency('DEPENDS', 'package', '>=1', '../../category/package'); +# sub add_dependency($$$$) { my ($type, $pkgbase, $constraint, $dep_dir) = @_; @@ -275,6 +302,7 @@ sub adjust_perl_module() { push(@build_vars, var("PERL5_PACKLIST", "=", "auto/$packlist/.packlist")); push(@includes, "../../lang/perl5/module.mk"); $pkgname = "p5-\${DISTNAME}"; + push(@categories, "perl5"); } sub adjust_python_module() { @@ -306,8 +334,9 @@ sub adjust_python_module() { } add_dependency($type, $pkgbase, $constraint, $dep_dir); - } + + push(@categories, "python"); } sub adjust_cargo() { @@ -462,10 +491,8 @@ sub generate_initial_package_Makefile_lines($) { $extract_sufx = "# none"; } - rename("Makefile", "Makefile-url2pkg.bak") or do {}; - `pwd` =~ qr".*/([^/]+)/[^/]+$" or die; - $categories = $1 eq "wip" ? "# TODO" : $1; + $categories = $1 eq "wip" ? "# TODO: add primary category" : $1; if ($extract_sufx eq ".tar.gz" || $extract_sufx eq ".gem") { $extract_sufx = ""; @@ -501,6 +528,7 @@ sub generate_initial_package_Makefile_lines($) { sub generate_initial_package($) { my ($url) = @_; + rename("Makefile", "Makefile-url2pkg.bak") or do {}; write_lines("Makefile", generate_initial_package_Makefile_lines($url)); write_lines("PLIST", "\@comment \$" . "NetBSD\$"); @@ -612,6 +640,8 @@ sub adjust_package_from_extracted_distfiles() close(MF1); + update_var_append(\@lines, 'CATEGORIES', join(' ', @categories)); + write_lines("Makefile-url2pkg.new", @lines); if ($seen_marker) { diff --git a/pkgtools/url2pkg/files/url2pkg.t b/pkgtools/url2pkg/files/url2pkg.t new file mode 100644 index 00000000000..9659b74f773 --- /dev/null +++ b/pkgtools/url2pkg/files/url2pkg.t @@ -0,0 +1,125 @@ +# -*- perl -*- +# $NetBSD: url2pkg.t,v 1.1 2019/08/18 13:32:21 rillig Exp $ + +require 'url2pkg.pl'; + +use Test::More; + +use strict; +use warnings; + +sub test_add_section__simple() { + my $lines = []; + + add_section($lines, [ + var('1', '=', 'one'), + var('6', '=', 'six'), + ]); + + is_deeply($lines, [ + "1=\tone", + "6=\tsix", + '', + ]); +} + +sub test_add_section__alignment() { + my $lines = []; + + add_section($lines, [ + var('short', '=', 'value'), + var('long_name', '=', 'value # comment'), + ]); + + is_deeply($lines, [ + "short=\t\tvalue", + "long_name=\tvalue # comment", + '', + ]); +} + +sub test_add_section__operators() { + my $lines = []; + + add_section($lines, [ + var('123456', '+=', 'value'), + ]); + + is_deeply($lines, [ + "123456+=\tvalue", + '', + ]); +} + +sub test_var_append__not_found() { + my $lines = []; + + update_var_append($lines, 'VARNAME', 'value'); + + is_deeply($lines, []); +} + +sub test_var_append__only_comment() { + my $lines = ["VARNAME=\t\t\t# none"]; + + update_var_append($lines, 'VARNAME', 'value'); + + is_deeply($lines, ["VARNAME=\t\t\tvalue # none"]); +} + +sub test_var_append__value_with_comment() { + my $lines = ["VARNAME=\tvalue # comment"]; + + update_var_append($lines, 'VARNAME', 'appended'); + + is_deeply($lines, ["VARNAME=\tvalue appended # comment"]); +} + +sub test_var_append__value_without_comment() { + my $lines = ["VARNAME+=\tvalue"]; + + update_var_append($lines, 'VARNAME', 'appended'); + + is_deeply($lines, ["VARNAME+=\tvalue appended"]); +} + +sub test_generate_initial_package_Makefile_lines__GitHub() { + my $url = 'https://github.com/org/proj/archive/v1.0.0.tar.gz'; + my $pkgsrcdir = $ENV{'PKGSRCDIR'} or die; + chdir("$pkgsrcdir/pkgtools/url2pkg") or die; + + my @lines = generate_initial_package_Makefile_lines($url); + + is_deeply(\@lines, [ + "# \$" . "NetBSD\$", + "", + "GITHUB_PROJECT=\tproj", + "DISTNAME=\tv1.0.0", + "CATEGORIES=\tpkgtools", + "MASTER_SITES=\t\${MASTER_SITE_GITHUB:=org/}", + "DIST_SUBDIR=\t\${GITHUB_PROJECT}", + "", + "MAINTAINER=\tINSERT_YOUR_MAIL_ADDRESS_HERE", + "HOMEPAGE=\thttps://github.com/org/proj/", + "COMMENT=\tTODO: Short description of the package", + "#LICENSE=\t# TODO: (see mk/license.mk)", + "", + "# url2pkg-marker (please do not remove this line.)", + ".include \"../../mk/bsd.pkg.mk\"" + ]); +} + +sub test_all() { + test_add_section__simple(); + test_add_section__alignment(); + test_add_section__operators(); + test_var_append__not_found(); + test_var_append__only_comment(); + test_var_append__value_with_comment(); + test_var_append__value_without_comment(); + test_generate_initial_package_Makefile_lines__GitHub(); + + done_testing(); +} + +test_all(); |