diff options
author | rillig <rillig@pkgsrc.org> | 2019-09-12 04:18:28 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2019-09-12 04:18:28 +0000 |
commit | e0c0ed68701c0c075fc1076633c8af03a6b8837a (patch) | |
tree | b578e53c6df683d74ae2341ac6346d271dbce859 /pkgtools/url2pkg | |
parent | 4100b1a29b3200524b436b2e821755db28470b54 (diff) | |
download | pkgsrc-e0c0ed68701c0c075fc1076633c8af03a6b8837a.tar.gz |
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 (limited to 'pkgtools/url2pkg')
-rw-r--r-- | pkgtools/url2pkg/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg.pl | 103 | ||||
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg.t | 43 |
3 files changed, 99 insertions, 51 deletions
diff --git a/pkgtools/url2pkg/Makefile b/pkgtools/url2pkg/Makefile index 4c74304b366..f372bd060fa 100644 --- a/pkgtools/url2pkg/Makefile +++ b/pkgtools/url2pkg/Makefile @@ -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 diff --git a/pkgtools/url2pkg/files/url2pkg.pl b/pkgtools/url2pkg/files/url2pkg.pl index 131f92012fd..fa9035b5766 100644 --- a/pkgtools/url2pkg/files/url2pkg.pl +++ b/pkgtools/url2pkg/files/url2pkg.pl @@ -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 @@ use warnings; # 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 write_lines($@) { 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 @@ my @categories; # 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 add_dependency($$$$) { } } +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_Build_PL() { 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 @@ sub adjust_python_module() { return unless -f "$abs_wrksrc/setup.py"; - my %old_env = %ENV; - $ENV{"PYTHONDONTWRITEBYTECODE"} = "x"; - $ENV{"PYTHONPATH"} = $libdir; - - 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); - } + my $cmd = "cd '$abs_wrksrc' && $pythonbin setup.py build"; + my $env = { + "PYTHONDONTWRITEBYTECODE" => "x", + "PYTHONPATH" => $libdir + }; + read_dependencies($cmd, $env, "py-"); + $pkgname = "\${PYPKGPREFIX}-\${DISTNAME}"; push(@categories, "python"); push(@includes, "../../lang/python/egg.mk"); } diff --git a/pkgtools/url2pkg/files/url2pkg.t b/pkgtools/url2pkg/files/url2pkg.t index d89ff50a75e..6f79ec6f6cc 100644 --- a/pkgtools/url2pkg/files/url2pkg.t +++ b/pkgtools/url2pkg/files/url2pkg.t @@ -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_generate_initial_package_Makefile_lines__GitHub_release_not_containing_ ]); } +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(); |