pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/url2pkg



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sun Aug 18 13:32:22 UTC 2019

Modified Files:
        pkgsrc/pkgtools/url2pkg: Makefile
        pkgsrc/pkgtools/url2pkg/files: url2pkg.pl
Added Files:
        pkgsrc/pkgtools/url2pkg/files: url2pkg.t

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


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 pkgsrc/pkgtools/url2pkg/Makefile
cvs rdiff -u -r1.56 -r1.57 pkgsrc/pkgtools/url2pkg/files/url2pkg.pl
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/url2pkg/files/url2pkg.t

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/url2pkg/Makefile
diff -u pkgsrc/pkgtools/url2pkg/Makefile:1.94 pkgsrc/pkgtools/url2pkg/Makefile:1.95
--- pkgsrc/pkgtools/url2pkg/Makefile:1.94       Sun Aug 18 11:26:33 2019
+++ pkgsrc/pkgtools/url2pkg/Makefile    Sun Aug 18 13:32:21 2019
@@ -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"
 

Index: pkgsrc/pkgtools/url2pkg/files/url2pkg.pl
diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg.pl:1.56 pkgsrc/pkgtools/url2pkg/files/url2pkg.pl:1.57
--- pkgsrc/pkgtools/url2pkg/files/url2pkg.pl:1.56       Sun Aug 18 11:26:33 2019
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg.pl    Sun Aug 18 13:32:21 2019
@@ -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_li
                $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_li
 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_distfi
 
        close(MF1);
 
+       update_var_append(\@lines, 'CATEGORIES', join(' ', @categories));
+
        write_lines("Makefile-url2pkg.new", @lines);
 
        if ($seen_marker) {

Added files:

Index: pkgsrc/pkgtools/url2pkg/files/url2pkg.t
diff -u /dev/null pkgsrc/pkgtools/url2pkg/files/url2pkg.t:1.1
--- /dev/null   Sun Aug 18 13:32:22 2019
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg.t     Sun Aug 18 13:32:21 2019
@@ -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