Received: by mail.netbsd.org (Postfix, from userid 605) id 8B8BC84D3E; Fri, 13 Sep 2019 06:22:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id 1070184CD3 for ; Fri, 13 Sep 2019 06:22:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([IPv6:::1]) by localhost (mail.netbsd.org [IPv6:::1]) (amavisd-new, port 10025) with ESMTP id hyZ1xy_6KRJ3 for ; Fri, 13 Sep 2019 06:22:34 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.netbsd.org [199.233.217.197]) by mail.netbsd.org (Postfix) with ESMTP id 4AD8C84C8B for ; Fri, 13 Sep 2019 06:22:34 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id 17976FBF4; Fri, 13 Sep 2019 06:22:34 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_1568355754117030" MIME-Version: 1.0 Date: Fri, 13 Sep 2019 06:22:34 +0000 From: "Roland Illig" Subject: CVS commit: pkgsrc/pkgtools/url2pkg/files To: pkgsrc-changes@NetBSD.org Reply-To: rillig@netbsd.org X-Mailer: log_accum Message-Id: <20190913062234.17976FBF4@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: pkgsrc-changes.NetBSD.org Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_1568355754117030 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: rillig Date: Fri Sep 13 06:22:34 UTC 2019 Modified Files: pkgsrc/pkgtools/url2pkg/files: url2pkg.pl url2pkg.t Log Message: pkgtools/url2pkg: use MetaCPAN HOMEPAGE for Perl modules To generate a diff of this commit: cvs rdiff -u -r1.71 -r1.72 pkgsrc/pkgtools/url2pkg/files/url2pkg.pl cvs rdiff -u -r1.10 -r1.11 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. --_----------=_1568355754117030 Content-Disposition: inline Content-Length: 6831 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Modified files: Index: pkgsrc/pkgtools/url2pkg/files/url2pkg.pl diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg.pl:1.71 pkgsrc/pkgtools/url2pkg/files/url2pkg.pl:1.72 --- pkgsrc/pkgtools/url2pkg/files/url2pkg.pl:1.71 Fri Sep 13 05:38:27 2019 +++ pkgsrc/pkgtools/url2pkg/files/url2pkg.pl Fri Sep 13 06:22:33 2019 @@ -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_distfi 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)); Index: pkgsrc/pkgtools/url2pkg/files/url2pkg.t diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg.t:1.10 pkgsrc/pkgtools/url2pkg/files/url2pkg.t:1.11 --- pkgsrc/pkgtools/url2pkg/files/url2pkg.t:1.10 Thu Sep 12 18:23:00 2019 +++ pkgsrc/pkgtools/url2pkg/files/url2pkg.t Fri Sep 13 06:22:33 2019 @@ -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; } --_----------=_1568355754117030--