pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/url2pkg/files pkgtools/url2pkg: strip leading...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/6a161a34ec02
branches:  trunk
changeset: 401133:6a161a34ec02
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Sep 12 05:45:34 2019 +0000

description:
pkgtools/url2pkg: strip leading v from distfile version number

diffstat:

 pkgtools/url2pkg/files/url2pkg.pl |  98 +++++++++++++++++++++-----------------
 pkgtools/url2pkg/files/url2pkg.t  |  59 +++++++++++++++++++++++-
 2 files changed, 112 insertions(+), 45 deletions(-)

diffs (truncated from 332 to 300 lines):

diff -r c68a6c1239f8 -r 6a161a34ec02 pkgtools/url2pkg/files/url2pkg.pl
--- a/pkgtools/url2pkg/files/url2pkg.pl Thu Sep 12 04:46:26 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.pl Thu Sep 12 05:45:34 2019 +0000
@@ -1,5 +1,5 @@
 #! @PERL5@
-# $NetBSD: url2pkg.pl,v 1.67 2019/09/12 04:18:28 rillig Exp $
+# $NetBSD: url2pkg.pl,v 1.68 2019/09/12 05:45:34 rillig Exp $
 #
 
 # Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -206,6 +206,15 @@
        return false;
 }
 
+sub lines_index($$) {
+       my ($lines, $re) = @_;
+
+       foreach my $i (0..$#$lines) {
+               return $i if $lines->[$i] =~ $re;
+       }
+       return -1;
+}
+
 sub make(@) {
        my @args = @_;
 
@@ -221,18 +230,18 @@
 #
 
 # the package name, including the version number.
-my $distname;
+our $distname;
 
 # the absolute pathname to the working directory, containing
 # the extracted distfiles.
-my $abs_wrkdir;
+our $abs_wrkdir;
 
 # the absolute pathname to a subdirectory of $abs_wrkdir, typically
 # containing package-provided Makefiles or configure scripts.
-my $abs_wrksrc;
+our $abs_wrksrc;
 
-my @wrksrc_files;
-my @wrksrc_dirs;
+our @wrksrc_files;
+our @wrksrc_dirs;
 # the regular files and directories relative to abs_wrksrc.
 
 #
@@ -242,7 +251,7 @@
 
 # categories for the package, in addition to the usual
 # parent directory.
-my @categories;
+our @categories;
 
 # the dependencies of the package, in the form
 # "package>=version:../../category/package".
@@ -256,24 +265,25 @@
 
 # a list of pathnames relative to the package path.
 # All these files will be included at the bottom of the Makefile.
-my @includes;
+our @includes;
 
 # a list of variable assignments that will make up the fourth
 # paragraph of the package Makefile, where the build configuration
 # takes place.
-my @build_vars;
+our @build_vars;
 
 # similar to the @build_vars, but separated by an empty line in
 # the Makefile, thereby forming the fifth paragraph.
-my @extra_vars;
+our @extra_vars;
 
 # these are inserted below the second paragraph in the Makefile.
-my @todos;
+our @todos;
 
-# the package name, in case it differs from $distname.
-my $pkgname = "";
+# the package name is $pkgname_prefix${DISTNAME$pkgname_transform}.
+our $pkgname_prefix = "";  # example: ${PYPKGPREFIX}-
+our $pkgname_transform = "";  # example: :S,-v,-,
 
-my $regenerate_distinfo = false;
+our $regenerate_distinfo = false;
 
 # Example:
 # add_dependency("DEPENDS", "package", ">=1", "../../category/package");
@@ -420,10 +430,10 @@
                return;
        }
 
-       my $packlist = $distname =~ s/-[0-9].*//r =~ s/-/\//gr;
+       my $packlist = $distname =~ s/-v?[0-9].*//r =~ s/-/\//gr;
        push(@build_vars, var("PERL5_PACKLIST", "=", "auto/$packlist/.packlist"));
        push(@includes, "../../lang/perl5/module.mk");
-       $pkgname = "p5-\${DISTNAME}";
+       $pkgname_prefix = "p5-";
        push(@categories, "perl5");
 
        unlink("PLIST") or do {};
@@ -443,7 +453,7 @@
        };
        read_dependencies($cmd, $env, "py-");
 
-       $pkgname = "\${PYPKGPREFIX}-\${DISTNAME}";
+       $pkgname_prefix = "\${PYPKGPREFIX}-";
        push(@categories, "python");
        push(@includes, "../../lang/python/egg.mk");
 }
@@ -553,21 +563,22 @@
        }
 
        if ($url =~ qr"^https://github\.com/";) {
-               if ($url =~ qr"^https://github\.com/(.*)/(.*)/archive/(.*)(\.tar\.gz|\.zip)$") {
+               if ($url =~ qr"^https://github\.com/(.+)/(.+)/archive/(.+)(\.tar\.gz|\.zip)$") {
                        my ($org, $proj, $tag, $ext) = ($1, $2, $3, $4);
 
+                       $github_project = $proj;
                        $master_sites = "\${MASTER_SITE_GITHUB:=$org/}";
                        $homepage = "https://github.com/$org/$proj/";;
-                       $github_project = $proj;
                        if (index($tag, $github_project) == -1) {
-                               $pkgname = "\${GITHUB_PROJECT}-\${DISTNAME}";
+                               $pkgname_prefix = "\${GITHUB_PROJECT}-";
                                $dist_subdir = "\${GITHUB_PROJECT}";
                        }
                        $distfile = "$tag$ext";
 
-               } elsif ($url =~ qr"^https://github\.com/(.*)/(.*)/releases/download/(.*)/(.*)(\.tar\.gz|\.zip)$") {
+               } elsif ($url =~ qr"^https://github\.com/(.+)/(.+)/releases/download/(.+)/(.+)(\.tar\.gz|\.zip)$") {
                        my ($org, $proj, $tag, $base, $ext) = ($1, $2, $3, $4, $5);
 
+                       $github_project = $proj;
                        $master_sites = "\${MASTER_SITE_GITHUB:=$org/}";
                        $homepage = "https://github.com/$org/$proj/";;
                        if (index($base, $proj) == -1) {
@@ -600,6 +611,12 @@
                $extract_sufx = "# none";
        }
 
+       if ($distname =~ qr"^v\d") {
+               $pkgname_transform = ":S,^v,,";
+       } elsif ($distname =~ qr"-v\d" && $distname !~ qr"-v.*-v\d") {
+               $pkgname_transform = ":S,-v,-,";
+       }
+
        `pwd` =~ qr".*/([^/]+)/[^/]+$" or die;
        $categories = $1 eq "wip" ? "# TODO: add primary category" : $1;
 
@@ -607,6 +624,9 @@
                $extract_sufx = "";
        }
 
+       my $pkgname = "$pkgname_prefix\${DISTNAME$pkgname_transform}";
+       $pkgname = "" if $pkgname eq "\${DISTNAME}";
+
        my @lines;
        push(@lines, "# \$" . "NetBSD\$");
        push(@lines, "");
@@ -614,6 +634,7 @@
        lines_add_vars(\@lines, [
                var("GITHUB_PROJECT", "=", $github_project),
                var("DISTNAME", "=", $distname),
+               var("PKGNAME", "=", $pkgname),
                var("CATEGORIES", "=", $categories),
                var("MASTER_SITES", "=", $master_sites),
                var("GITHUB_RELEASE", "=", $github_release),
@@ -740,27 +761,22 @@
        print("url2pkg> Adjusting the Makefile\n");
 
        my $seen_marker = false;
-       my @lines;
 
-       open(MF1, "<", "Makefile") or die;
-
-       # Copy the user-edited part of the Makefile.
-       while (defined(my $line = <MF1>)) {
-               chomp($line);
+       my @prev_lines = read_lines("Makefile");
+       my $marker_index = lines_index(\@prev_lines, qr"^# url2pkg-marker");
+       if ($marker_index == -1) {
+               die("$0: ERROR: didn't find the url2pkg marker in the Makefile.\n");
+       }
 
-               if ($line =~ qr"^# url2pkg-marker\b") {
-                       $seen_marker = true;
-                       last;
-               }
-               push(@lines, $line);
+       my @lines = @prev_lines[0 .. $marker_index - 1];
 
-               if ($pkgname ne "" && $line =~ qr"^DISTNAME=(\t+)") {
-                       push(@lines, "PKGNAME=$1$pkgname");
+       if (lines_index(\@lines, qr"^PKGNAME=") == -1) {
+               my $distname_index = lines_index(\@lines, qr"^DISTNAME=(\t+)");
+               if ($distname_index != -1) {
+                       my $pkgname_line = "PKGNAME=\t$pkgname_prefix\${DISTNAME$pkgname_transform}";
+                       splice(@lines, $distname_index + 1, 0, $pkgname_line);
                }
        }
-       if (!$seen_marker) {
-               die("$0: ERROR: didn't find the url2pkg marker in the file.\n");
-       }
 
        if (@todos) {
                foreach my $todo (@todos) {
@@ -781,13 +797,7 @@
        push(@lines, @bl3_lines);
        push(@lines, map { $_ = ".include \"$_\"" } @includes);
 
-       # Copy the rest of the user-edited part of the Makefile.
-       while (defined(my $line = <MF1>)) {
-               chomp($line);
-               push(@lines, $line);
-       }
-
-       close(MF1);
+       push(@lines, @prev_lines[$marker_index + 1 .. $#prev_lines]);
 
        lines_append(\@lines, "CATEGORIES", join(" ", @categories));
 
diff -r c68a6c1239f8 -r 6a161a34ec02 pkgtools/url2pkg/files/url2pkg.t
--- a/pkgtools/url2pkg/files/url2pkg.t  Thu Sep 12 04:46:26 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.t  Thu Sep 12 05:45:34 2019 +0000
@@ -1,5 +1,5 @@
 # -*- perl -*-
-# $NetBSD: url2pkg.t,v 1.8 2019/09/12 04:18:28 rillig Exp $
+# $NetBSD: url2pkg.t,v 1.9 2019/09/12 05:45:34 rillig Exp $
 
 require "url2pkg.pl";
 
@@ -83,6 +83,20 @@
        is_deeply($lines, ["VARNAME+=\tvalue appended"]);
 }
 
+sub test_lines_index() {
+       my $lines = ["1", "2", "345"];
+
+       is(lines_index($lines, "1"), 0);
+       is(lines_index($lines, "2"), 1);
+       is(lines_index($lines, "345"), 2);
+       is(lines_index($lines, "4"), 2);
+
+       is(lines_index($lines, qr"^(\d\d)\d$"), 2);
+       is(lines_index($lines, qr"^\d\s\d$"), -1);
+       is(lines_index($lines, qr"(\d)"), 0);
+       is($1, undef);  # capturing groups do not work here
+}
+
 sub test_generate_initial_package_Makefile_lines__GitHub_archive() {
        my $url = "https://github.com/org/proj/archive/v1.0.0.tar.gz";;
 
@@ -93,6 +107,7 @@
                "",
                "GITHUB_PROJECT=\tproj",
                "DISTNAME=\tv1.0.0",
+               "PKGNAME=\t\${GITHUB_PROJECT}-\${DISTNAME:S,^v,,}",
                "CATEGORIES=\tpkgtools",
                "MASTER_SITES=\t\${MASTER_SITE_GITHUB:=org/}",
                "DIST_SUBDIR=\t\${GITHUB_PROJECT}",
@@ -115,6 +130,7 @@
        is_deeply(\@lines, [
                "# \$" . "NetBSD\$",
                "",
+               "GITHUB_PROJECT=\tproj",
                "DISTNAME=\tproj",
                "CATEGORIES=\tpkgtools",
                "MASTER_SITES=\t\${MASTER_SITE_GITHUB:=org/}",
@@ -157,6 +173,29 @@
        ]);
 }
 
+sub test_generate_initial_package_Makefile_lines__distname_version_with_v() {
+       my $url = "https://cpan.example.org/Algorithm-CheckDigits-v1.3.2.tar.gz";;
+
+       my @lines = generate_initial_package_Makefile_lines($url);
+
+       is_deeply(\@lines, [
+               "# \$" . "NetBSD\$",
+               "",
+               "DISTNAME=\tAlgorithm-CheckDigits-v1.3.2",
+               "PKGNAME=\t\${DISTNAME:S,-v,-,}",
+               "CATEGORIES=\tpkgtools",
+               "MASTER_SITES=\thttps://cpan.example.org/";,
+               "",
+               "MAINTAINER=\tINSERT_YOUR_MAIL_ADDRESS_HERE",
+               "HOMEPAGE=\thttps://cpan.example.org/";,
+               "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\""
+       ]);
+}
+



Home | Main Index | Thread Index | Old Index