pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/url2pkg pkgtools/url2pkg: add secondary categ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/a0d470021823
branches:  trunk
changeset: 338092:a0d470021823
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Aug 18 13:32:21 2019 +0000

description:
pkgtools/url2pkg: add secondary category for Perl and Python modules

diffstat:

 pkgtools/url2pkg/Makefile         |    7 +-
 pkgtools/url2pkg/files/url2pkg.pl |   40 ++++++++++-
 pkgtools/url2pkg/files/url2pkg.t  |  125 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+), 7 deletions(-)

diffs (256 lines):

diff -r 82c8db87a89b -r a0d470021823 pkgtools/url2pkg/Makefile
--- a/pkgtools/url2pkg/Makefile Sun Aug 18 12:55:29 2019 +0000
+++ b/pkgtools/url2pkg/Makefile Sun Aug 18 13:32:21 2019 +0000
@@ -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 @@
 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 -r 82c8db87a89b -r a0d470021823 pkgtools/url2pkg/files/url2pkg.pl
--- a/pkgtools/url2pkg/files/url2pkg.pl Sun Aug 18 12:55:29 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.pl Sun Aug 18 13:32:21 2019 +0000
@@ -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 @@
        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 @@
 # 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 @@
 # 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 @@
        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 @@
                }
 
                add_dependency($type, $pkgbase, $constraint, $dep_dir);
+       }
 
-       }
+       push(@categories, "python");
 }
 
 sub adjust_cargo() {
@@ -462,10 +491,8 @@
                $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($) {
        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 @@
 
        close(MF1);
 
+       update_var_append(\@lines, 'CATEGORIES', join(' ', @categories));
+
        write_lines("Makefile-url2pkg.new", @lines);
 
        if ($seen_marker) {
diff -r 82c8db87a89b -r a0d470021823 pkgtools/url2pkg/files/url2pkg.t
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.t  Sun Aug 18 13:32:21 2019 +0000
@@ -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();



Home | Main Index | Thread Index | Old Index