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: update to 2.35



details:   https://anonhg.NetBSD.org/pkgsrc/rev/5ddd2487b9c3
branches:  trunk
changeset: 401127:5ddd2487b9c3
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Sep 12 04:18:28 2019 +0000

description:
pkgtools/url2pkg: update to 2.35

Changes since 2.34:

* Python packages get a PKGNAME variable containing PYPKGPREFIX
* Refactoring: merged duplicate code for reading dependencies

diffstat:

 pkgtools/url2pkg/Makefile         |    4 +-
 pkgtools/url2pkg/files/url2pkg.pl |  103 +++++++++++++++++++++----------------
 pkgtools/url2pkg/files/url2pkg.t  |   43 ++++++++++++++-
 3 files changed, 99 insertions(+), 51 deletions(-)

diffs (234 lines):

diff -r 26adb28b8f47 -r 5ddd2487b9c3 pkgtools/url2pkg/Makefile
--- a/pkgtools/url2pkg/Makefile Thu Sep 12 02:49:33 2019 +0000
+++ b/pkgtools/url2pkg/Makefile Thu Sep 12 04:18:28 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.97 2019/09/11 05:25:55 rillig Exp $
+# $NetBSD: Makefile,v 1.98 2019/09/12 04:18:28 rillig Exp $
 
-PKGNAME=       url2pkg-2.34
+PKGNAME=       url2pkg-2.35
 CATEGORIES=    pkgtools
 
 MAINTAINER=    pkgsrc-users%NetBSD.org@localhost
diff -r 26adb28b8f47 -r 5ddd2487b9c3 pkgtools/url2pkg/files/url2pkg.pl
--- a/pkgtools/url2pkg/files/url2pkg.pl Thu Sep 12 02:49:33 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.pl Thu Sep 12 04:18:28 2019 +0000
@@ -1,5 +1,5 @@
 #! @PERL5@
-# $NetBSD: url2pkg.pl,v 1.66 2019/09/12 02:49:33 rillig Exp $
+# $NetBSD: url2pkg.pl,v 1.67 2019/09/12 04:18:28 rillig Exp $
 #
 
 # Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -37,9 +37,10 @@
 # Build-time Configuration.
 #
 
-my $make               = "@MAKE@";
-my $libdir             = "@LIBDIR@";
-my $pythonbin          = "@PYTHONBIN@";
+my $make               = '@MAKE@';
+my $libdir             = '@LIBDIR@';
+my $pythonbin          = '@PYTHONBIN@';
+my $pkgsrcdir          = '@PKGSRCDIR@';
 
 use constant true      => 1;
 use constant false     => 0;
@@ -99,8 +100,9 @@
 sub find_package($) {
        my ($pkgbase) = @_;
 
-       my @candidates = <../../*/$pkgbase>;
-       return scalar(@candidates) == 1 ? $candidates[0] : "";
+       my @candidates = <$pkgsrcdir/*/$pkgbase>;
+       return "" unless @candidates == 1;
+       return $candidates[0] =~ s/\Q$pkgsrcdir\E/..\/../r;
 }
 
 # appends the given variable assignments to the lines, aligning the
@@ -244,13 +246,13 @@
 
 # the dependencies of the package, in the form
 # "package>=version:../../category/package".
-my @depends;
-my @build_depends;
-my @test_depends;
+our @depends;
+our @build_depends;
+our @test_depends;
 
 # .include, interleaved with BUILDLINK3_API_DEPENDS.
 # These lines are added at the bottom of the Makefile.
-my @bl3_lines;
+our @bl3_lines;
 
 # a list of pathnames relative to the package path.
 # All these files will be included at the bottom of the Makefile.
@@ -301,6 +303,42 @@
        }
 }
 
+sub read_dependencies($$$) {
+       my ($cmd, $env, $pkgnameprefix) = @_;
+       my @dep_lines;
+
+       my %prev_ENV = %ENV;
+       foreach my $name (keys %$env) {
+               $ENV{$name} = $env->{$name};
+       }
+       open(DEPS, "$cmd |") or die;
+       %ENV = %prev_ENV;
+
+       while (defined (my $line = <DEPS>)) {
+               chomp($line);
+
+               next unless $line =~ qr"^(\w+)\t([^\s:>]+)(>[^\s:]+|)(?::(\.\./\.\./\S+))?$";
+               push(@dep_lines, [$1, $2, $3 || ">=0", $4 || ""]);
+       }
+       close(DEPS) or die;
+
+       foreach my $dep_line (@dep_lines) {
+               my ($type, $pkgbase, $constraint, $dir) = @$dep_line;
+
+               if ($dir eq "" && $pkgnameprefix ne "") {
+                       $dir = find_package("$pkgnameprefix$pkgbase");
+                       if ($dir ne "") {
+                               $pkgbase = "$pkgnameprefix$pkgbase";
+                       }
+               }
+               if ($dir eq "") {
+                       $dir = find_package($pkgbase);
+               }
+
+               add_dependency($type, $pkgbase, $constraint, $dir);
+       }
+}
+
 sub adjust_configure() {
        my $gnu_configure = false;
 
@@ -368,17 +406,9 @@
 sub adjust_perl_module_Makefile_PL() {
 
        # To avoid fix_up_makefile error for p5-HTML-Quoted, generate Makefile first.
-       system("cd '$abs_wrksrc' && perl -I. Makefile.PL < /dev/null") or do {};
-
-       open(DEPS, "cd '$abs_wrksrc' && perl -I$libdir -I. Makefile.PL |") or die;
-       while (defined(my $dep = <DEPS>)) {
-               chomp($dep);
+       system("cd '$abs_wrksrc' && perl -I. Makefile.PL < /dev/null") == 0 or do {};
 
-               if ($dep =~ qr"^(\w+)\t(\S+)(>\S+|):(\.\./\.\./\S+)$") {
-                       add_dependency($1, $2, $3, $4);
-               }
-       }
-       close(DEPS) or die;
+       read_dependencies("cd '$abs_wrksrc' && perl -I$libdir -I. Makefile.PL", {}, "");
 }
 
 sub adjust_perl_module() {
@@ -406,33 +436,14 @@
 
        return unless -f "$abs_wrksrc/setup.py";
 
-       my %old_env = %ENV;
-       $ENV{"PYTHONDONTWRITEBYTECODE"} = "x";
-       $ENV{"PYTHONPATH"} = $libdir;
+       my $cmd = "cd '$abs_wrksrc' && $pythonbin setup.py build";
+       my $env = {
+               "PYTHONDONTWRITEBYTECODE" => "x",
+               "PYTHONPATH" => $libdir
+       };
+       read_dependencies($cmd, $env, "py-");
 
-       my @dep_lines;
-       open(DEPS, "cd '$abs_wrksrc' && $pythonbin setup.py build |") or die;
-       %ENV = %old_env;
-       while (defined(my $line = <DEPS>)) {
-               chomp($line);
-               if ($line =~ qr"^(\w+)\t(\S+?)(>=.*|)$") {
-                       push(@dep_lines, [$1, $2, $3]);
-               }
-       }
-       close(DEPS) or die;
-
-       foreach my $dep_line (@dep_lines) {
-               my ($type, $pkgbase, $constraint) = @$dep_line;
-               my $dep_dir = find_package("py-$pkgbase");
-               if ($dep_dir ne "") {
-                       $pkgbase = "py-$pkgbase";
-               } else {
-                       $dep_dir = find_package($pkgbase);
-               }
-
-               add_dependency($type, $pkgbase, $constraint, $dep_dir);
-       }
-
+       $pkgname = "\${PYPKGPREFIX}-\${DISTNAME}";
        push(@categories, "python");
        push(@includes, "../../lang/python/egg.mk");
 }
diff -r 26adb28b8f47 -r 5ddd2487b9c3 pkgtools/url2pkg/files/url2pkg.t
--- a/pkgtools/url2pkg/files/url2pkg.t  Thu Sep 12 02:49:33 2019 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.t  Thu Sep 12 04:18:28 2019 +0000
@@ -1,5 +1,5 @@
 # -*- perl -*-
-# $NetBSD: url2pkg.t,v 1.7 2019/09/12 02:35:07 rillig Exp $
+# $NetBSD: url2pkg.t,v 1.8 2019/09/12 04:18:28 rillig Exp $
 
 require "url2pkg.pl";
 
@@ -157,14 +157,51 @@
        ]);
 }
 
+sub test_read_dependencies() {
+       my $cmd = "printf '%s\n' \"\$URL2PKG_DEPENDENCIES\"";
+       my @dep_lines = (
+               "DEPENDS\tpackage>=version:../../pkgtools/pkglint",
+               "DEPENDS\tpackage>=version:../../pkgtools/x11-links",
+               "BUILD_DEPENDS\turl2pkg>=1.0",
+               "TEST_DEPENDS\tpkglint",
+               "A line that is not a dependency at all",
+               ""
+       );
+       my $env = { "URL2PKG_DEPENDENCIES" => join("\n", @dep_lines) };
+
+       read_dependencies($cmd, $env, "");
+
+       is($ENV{"URL2PKG_DEPENDENCIES"}, undef);
+       is_deeply(\@main::depends, [
+               "package>=version:../../pkgtools/pkglint"
+       ]);
+       is_deeply(\@main::bl3_lines, [
+               ".include \"../../pkgtools/x11-links/buildlink3.mk\""
+       ]);
+       is_deeply(\@main::build_depends, [
+               "url2pkg>=1.0:../../pkgtools/url2pkg"
+       ]);
+       is_deeply(\@main::test_depends, [
+               "pkglint>=0:../../pkgtools/pkglint"
+       ]);
+}
+
+sub set_up_test() {
+       @main::depends = ();
+       @main::build_depends = ();
+       @main::test_depends = ();
+       @main::bl3_lines = ();
+}
+
 sub t_main() {
        my $pkgsrcdir = $ENV{"PKGSRCDIR"} or die;
        chdir("$pkgsrcdir/pkgtools/url2pkg") or die;
 
        no strict 'refs';
        foreach my $testname (sort grep { $_ =~ qr"^test_" } keys %{"main::"}) {
-               my $testfunc = \&{"main::$testname"};
-               $testfunc->() if defined($testfunc);
+               next if $testname eq "test_depends";  # it's an array
+               set_up_test();
+               &{"main::$testname"}();
        }
 
        done_testing();



Home | Main Index | Thread Index | Old Index