diff options
author | rillig <rillig@pkgsrc.org> | 2019-09-13 06:22:33 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2019-09-13 06:22:33 +0000 |
commit | 67b4c3af068fddef41dd1f4e242b5f990591f719 (patch) | |
tree | 46f5d109da0dbaab04aee364ca1d8c04fe27123c /pkgtools/url2pkg | |
parent | 60937a27752d53317e58b86b30ab76a862915a00 (diff) | |
download | pkgsrc-67b4c3af068fddef41dd1f4e242b5f990591f719.tar.gz |
pkgtools/url2pkg: use MetaCPAN HOMEPAGE for Perl modules
Diffstat (limited to 'pkgtools/url2pkg')
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg.pl | 72 | ||||
-rw-r--r-- | pkgtools/url2pkg/files/url2pkg.t | 15 |
2 files changed, 65 insertions, 22 deletions
diff --git a/pkgtools/url2pkg/files/url2pkg.pl b/pkgtools/url2pkg/files/url2pkg.pl index 28fb86f0770..4d5ef7a5f29 100644 --- a/pkgtools/url2pkg/files/url2pkg.pl +++ b/pkgtools/url2pkg/files/url2pkg.pl @@ -1,5 +1,5 @@ #! @PERL5@ -# $NetBSD: url2pkg.pl,v 1.71 2019/09/13 05:38:27 rillig Exp $ +# $NetBSD: url2pkg.pl,v 1.72 2019/09/13 06:22:33 rillig Exp $ # # Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -32,10 +32,6 @@ use strict; use warnings; -# -# Build-time Configuration. -# - my $make = '@MAKE@'; my $libdir = '@LIBDIR@'; my $pythonbin = '@PYTHONBIN@'; @@ -44,10 +40,6 @@ my $pkgsrcdir = '@PKGSRCDIR@'; use constant true => 1; use constant false => 0; -# -# Some helper subroutines. -# - sub run_editor($$) { my ($fname, $lineno) = @_; @@ -134,7 +126,7 @@ sub lines_set($$$) { my $i = 0; foreach my $line (@$lines) { - if ($line =~ qr"^#?\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { + if ($line =~ qr"^#?\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") { my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); $lines->[$i] = "$varname$op$indent$new_value"; @@ -154,8 +146,8 @@ sub lines_append($$$) { my $i = 0; foreach my $line (@$lines) { - if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*)(#.*|)$") { - my ($op, $indent, $old_value, $comment) = ($1, $2, $3, $4); + if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") { + my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); my $before = $old_value =~ qr"\S$" ? " " : ""; my $after = $comment eq "" ? "" : " "; @@ -184,6 +176,24 @@ sub lines_remove($$) { return false; } +# returns the variable value from the only variable assignment, or an empty +# string. +sub lines_get($$) { + my ($lines, $varname) = @_; + + my $only_value = ""; + foreach my $line (@$lines) { + if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") { + my ($op, $indent, $value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); + + return "" if $only_value ne ""; + $only_value = $value; + } + } + return $only_value; +} + + # removes a variable assignment from the lines if its value is the # expected one. sub lines_remove_if($$$) { @@ -191,7 +201,7 @@ sub lines_remove_if($$$) { my $i = 0; foreach my $line (@$lines) { - if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { + if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") { my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); if ($old_value eq $expected_value) { @@ -285,6 +295,9 @@ our @todos; our $pkgname_prefix = ""; # example: ${PYPKGPREFIX}- our $pkgname_transform = ""; # example: :S,-v,-, +# all lines of the package Makefile, for direct modification. +our $makefile_lines; + our $regenerate_distinfo = false; # Example: @@ -427,7 +440,21 @@ sub adjust_perl_module_Makefile_PL() { read_dependencies("cd '$abs_wrksrc' && perl -I$libdir -I. Makefile.PL", {}, ""); } -sub adjust_perl_module() { +sub adjust_perl_module_homepage($) { + my ($url) = @_; + + if (lines_get($makefile_lines, "MASTER_SITES") =~ qr"\$\{MASTER_SITE_PERL_CPAN:") { + my $homepage = lines_get($makefile_lines, "HOMEPAGE"); + if ($homepage ne "" && index($url, $homepage) == 0) { + my $module_name = $distname =~ s/-v?[0-9].*//r =~ s/-/::/gr; + lines_set($makefile_lines, "HOMEPAGE", "https://metacpan.org/pod/$module_name"); + } + } +} + +sub adjust_perl_module($) { + my ($url) = @_; + if (-f "$abs_wrksrc/Build.PL") { adjust_perl_module_Build_PL(); } elsif (-f "$abs_wrksrc/Makefile.PL") { @@ -441,6 +468,7 @@ sub adjust_perl_module() { push(@includes, "../../lang/perl5/module.mk"); $pkgname_prefix = "p5-"; push(@categories, "perl5"); + adjust_perl_module_homepage($url); unlink("PLIST") or do {}; } @@ -744,32 +772,34 @@ sub determine_wrksrc() { sub adjust_package_from_extracted_distfiles($) { my ($url) = @_; + print("url2pkg> Adjusting the Makefile\n"); + chomp($abs_wrkdir = `$make show-var VARNAME=WRKDIR`); determine_wrksrc(); chomp(@wrksrc_files = `cd "$abs_wrksrc" && find * -type f -print`); chomp(@wrksrc_dirs = `cd "$abs_wrksrc" && find * -type d -print`); + my @makefile_lines = read_lines("Makefile"); + $makefile_lines = \@makefile_lines; + adjust_configure(); adjust_cmake(); adjust_meson(); adjust_gconf2_schemas(); adjust_libtool(); - adjust_perl_module(); + adjust_perl_module($url); adjust_python_module(); adjust_cargo(); adjust_pkg_config(); adjust_po(); adjust_use_languages(); - print("url2pkg> Adjusting the Makefile\n"); - - my @prev_lines = read_lines("Makefile"); - my $marker_index = lines_index(\@prev_lines, qr"^# url2pkg-marker"); + my $marker_index = lines_index($makefile_lines, qr"^# url2pkg-marker"); if ($marker_index == -1) { die("$0: ERROR: didn't find the url2pkg marker in the Makefile.\n"); } - my @lines = @prev_lines[0 .. $marker_index - 1]; + my @lines = @$makefile_lines[0 .. $marker_index - 1]; if (lines_index(\@lines, qr"^PKGNAME=") == -1) { my $distname_index = lines_index(\@lines, qr"^DISTNAME=(\t+)"); @@ -798,7 +828,7 @@ sub adjust_package_from_extracted_distfiles($) { push(@lines, @bl3_lines); push(@lines, map { $_ = ".include \"$_\"" } @includes); - push(@lines, @prev_lines[$marker_index + 1 .. $#prev_lines]); + push(@lines, $makefile_lines->[$marker_index + 1 .. $#$makefile_lines]); lines_append(\@lines, "CATEGORIES", join(" ", @categories)); diff --git a/pkgtools/url2pkg/files/url2pkg.t b/pkgtools/url2pkg/files/url2pkg.t index 0610250a0da..2a58e931b27 100644 --- a/pkgtools/url2pkg/files/url2pkg.t +++ b/pkgtools/url2pkg/files/url2pkg.t @@ -1,5 +1,5 @@ # -*- perl -*- -# $NetBSD: url2pkg.t,v 1.10 2019/09/12 18:23:00 rillig Exp $ +# $NetBSD: url2pkg.t,v 1.11 2019/09/13 06:22:33 rillig Exp $ require "url2pkg.pl"; @@ -113,6 +113,18 @@ sub test_lines_index() { is($1, undef); # capturing groups do not work here } +sub test_lines_get() { + my $lines = [ + "VAR=value", + "VAR=\tvalue # comment", + "UNIQUE=\tunique" + ]; + + is(lines_get($lines, "VAR"), ""); # too many values + is(lines_get($lines, "ENOENT"), ""); # no value at all + is(lines_get($lines, "UNIQUE"), "unique"); +} + sub test_generate_initial_package_Makefile_lines__GitHub_archive() { my $url = "https://github.com/org/proj/archive/v1.0.0.tar.gz"; @@ -264,6 +276,7 @@ sub set_up_test() { $main::pkgname_prefix = ""; $main::pkgname_transform = ""; + $main::makefile_lines = []; $main::regenerate_distinfo = 0; } |