Fri Sep 13 06:22:34 2019 UTC ()
pkgtools/url2pkg: use MetaCPAN HOMEPAGE for Perl modules


(rillig)
diff -r1.71 -r1.72 pkgsrc/pkgtools/url2pkg/files/url2pkg.pl
diff -r1.10 -r1.11 pkgsrc/pkgtools/url2pkg/files/url2pkg.t

cvs diff -r1.71 -r1.72 pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.pl (expand / switch to unified diff)

--- pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.pl 2019/09/13 05:38:27 1.71
+++ pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.pl 2019/09/13 06:22:33 1.72
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! @PERL5@ 1#! @PERL5@
2# $NetBSD: url2pkg.pl,v 1.71 2019/09/13 05:38:27 rillig Exp $ 2# $NetBSD: url2pkg.pl,v 1.72 2019/09/13 06:22:33 rillig Exp $
3# 3#
4 4
5# Copyright (c) 2010 The NetBSD Foundation, Inc. 5# Copyright (c) 2010 The NetBSD Foundation, Inc.
6# All rights reserved. 6# All rights reserved.
7# 7#
8# This code is derived from software contributed to The NetBSD Foundation 8# This code is derived from software contributed to The NetBSD Foundation
9# by Roland Illig. 9# by Roland Illig.
10# 10#
11# Redistribution and use in source and binary forms, with or without 11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions 12# modification, are permitted provided that the following conditions
13# are met: 13# are met:
14# 1. Redistributions of source code must retain the above copyright 14# 1. Redistributions of source code must retain the above copyright
15# notice, this list of conditions and the following disclaimer. 15# notice, this list of conditions and the following disclaimer.
@@ -22,42 +22,34 @@ @@ -22,42 +22,34 @@
22# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE. 30# POSSIBILITY OF SUCH DAMAGE.
31 31
32use strict; 32use strict;
33use warnings; 33use warnings;
34 34
35# 
36# Build-time Configuration. 
37# 
38 
39my $make = '@MAKE@'; 35my $make = '@MAKE@';
40my $libdir = '@LIBDIR@'; 36my $libdir = '@LIBDIR@';
41my $pythonbin = '@PYTHONBIN@'; 37my $pythonbin = '@PYTHONBIN@';
42my $pkgsrcdir = '@PKGSRCDIR@'; 38my $pkgsrcdir = '@PKGSRCDIR@';
43 39
44use constant true => 1; 40use constant true => 1;
45use constant false => 0; 41use constant false => 0;
46 42
47# 
48# Some helper subroutines. 
49# 
50 
51sub run_editor($$) { 43sub run_editor($$) {
52 my ($fname, $lineno) = @_; 44 my ($fname, $lineno) = @_;
53 45
54 my $editor = $ENV{"PKGEDITOR"} || $ENV{"EDITOR"} || "vi"; 46 my $editor = $ENV{"PKGEDITOR"} || $ENV{"EDITOR"} || "vi";
55 47
56 my @args; 48 my @args;
57 push(@args, $editor); 49 push(@args, $editor);
58 push(@args, "+$lineno") if $editor =~ qr"(^|/)(mcedit|nano|pico|vi|vim)$"; 50 push(@args, "+$lineno") if $editor =~ qr"(^|/)(mcedit|nano|pico|vi|vim)$";
59 push(@args, $fname); 51 push(@args, $fname);
60 52
61 system { $args[0] } (@args); 53 system { $args[0] } (@args);
62} 54}
63 55
@@ -124,48 +116,48 @@ sub lines_add_vars($$) { @@ -124,48 +116,48 @@ sub lines_add_vars($$) {
124 next if $value eq ""; 116 next if $value eq "";
125 my $tabs = "\t" x (($width - length("$name$op") + 7) / 8); 117 my $tabs = "\t" x (($width - length("$name$op") + 7) / 8);
126 push(@$lines, "$name$op$tabs$value"); 118 push(@$lines, "$name$op$tabs$value");
127 } 119 }
128 push(@$lines, ""); 120 push(@$lines, "");
129} 121}
130 122
131# changes the value of an existing variable in the lines. 123# changes the value of an existing variable in the lines.
132sub lines_set($$$) { 124sub lines_set($$$) {
133 my ($lines, $varname, $new_value) = @_; 125 my ($lines, $varname, $new_value) = @_;
134 126
135 my $i = 0; 127 my $i = 0;
136 foreach my $line (@$lines) { 128 foreach my $line (@$lines) {
137 if ($line =~ qr"^#?\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { 129 if ($line =~ qr"^#?\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") {
138 my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); 130 my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5);
139 131
140 $lines->[$i] = "$varname$op$indent$new_value"; 132 $lines->[$i] = "$varname$op$indent$new_value";
141 return true; 133 return true;
142 } 134 }
143 $i++; 135 $i++;
144 } 136 }
145 137
146 return false; 138 return false;
147} 139}
148 140
149# appends to the value of an existing variable in the lines. 141# appends to the value of an existing variable in the lines.
150sub lines_append($$$) { 142sub lines_append($$$) {
151 my ($lines, $varname, $value) = @_; 143 my ($lines, $varname, $value) = @_;
152 144
153 return if $value eq ""; 145 return if $value eq "";
154 146
155 my $i = 0; 147 my $i = 0;
156 foreach my $line (@$lines) { 148 foreach my $line (@$lines) {
157 if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*)(#.*|)$") { 149 if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") {
158 my ($op, $indent, $old_value, $comment) = ($1, $2, $3, $4); 150 my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5);
159 151
160 my $before = $old_value =~ qr"\S$" ? " " : ""; 152 my $before = $old_value =~ qr"\S$" ? " " : "";
161 my $after = $comment eq "" ? "" : " "; 153 my $after = $comment eq "" ? "" : " ";
162 $lines->[$i] = "$varname$op$indent$old_value$before$value$after$comment"; 154 $lines->[$i] = "$varname$op$indent$old_value$before$value$after$comment";
163 return true; 155 return true;
164 } 156 }
165 $i++; 157 $i++;
166 } 158 }
167 159
168 return false; 160 return false;
169} 161}
170 162
171# removes a variable assignment from the lines. 163# removes a variable assignment from the lines.
@@ -174,34 +166,52 @@ sub lines_remove($$) { @@ -174,34 +166,52 @@ sub lines_remove($$) {
174 166
175 my $i = 0; 167 my $i = 0;
176 foreach my $line (@$lines) { 168 foreach my $line (@$lines) {
177 if ($line =~ qr"^\Q$varname\E(\+?=)") { 169 if ($line =~ qr"^\Q$varname\E(\+?=)") {
178 splice(@$lines, $i, 1); 170 splice(@$lines, $i, 1);
179 return true; 171 return true;
180 } 172 }
181 $i++; 173 $i++;
182 } 174 }
183 175
184 return false; 176 return false;
185} 177}
186 178
 179# returns the variable value from the only variable assignment, or an empty
 180# string.
 181sub lines_get($$) {
 182 my ($lines, $varname) = @_;
 183
 184 my $only_value = "";
 185 foreach my $line (@$lines) {
 186 if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") {
 187 my ($op, $indent, $value, $space_after_value, $comment) = ($1, $2, $3, $4, $5);
 188
 189 return "" if $only_value ne "";
 190 $only_value = $value;
 191 }
 192 }
 193 return $only_value;
 194}
 195
 196
187# removes a variable assignment from the lines if its value is the 197# removes a variable assignment from the lines if its value is the
188# expected one. 198# expected one.
189sub lines_remove_if($$$) { 199sub lines_remove_if($$$) {
190 my ($lines, $varname, $expected_value) = @_; 200 my ($lines, $varname, $expected_value) = @_;
191 201
192 my $i = 0; 202 my $i = 0;
193 foreach my $line (@$lines) { 203 foreach my $line (@$lines) {
194 if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]+)([^#\\]*?)(\s*)(#.*|)$") { 204 if ($line =~ qr"^\Q$varname\E(\+?=)([ \t]*)([^#\\]*?)(\s*)(#.*|)$") {
195 my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5); 205 my ($op, $indent, $old_value, $space_after_value, $comment) = ($1, $2, $3, $4, $5);
196 206
197 if ($old_value eq $expected_value) { 207 if ($old_value eq $expected_value) {
198 splice(@$lines, $i, 1); 208 splice(@$lines, $i, 1);
199 return true; 209 return true;
200 } 210 }
201 } 211 }
202 $i++; 212 $i++;
203 } 213 }
204 214
205 return false; 215 return false;
206} 216}
207 217
@@ -275,26 +285,29 @@ our @build_vars; @@ -275,26 +285,29 @@ our @build_vars;
275# the Makefile, thereby forming the fifth paragraph. 285# the Makefile, thereby forming the fifth paragraph.
276our @extra_vars; 286our @extra_vars;
277 287
278# variables from the initial Makefile whose values are replaced 288# variables from the initial Makefile whose values are replaced
279our %update_vars; 289our %update_vars;
280 290
281# these are inserted below the second paragraph in the Makefile. 291# these are inserted below the second paragraph in the Makefile.
282our @todos; 292our @todos;
283 293
284# the package name is $pkgname_prefix${DISTNAME$pkgname_transform}. 294# the package name is $pkgname_prefix${DISTNAME$pkgname_transform}.
285our $pkgname_prefix = ""; # example: ${PYPKGPREFIX}- 295our $pkgname_prefix = ""; # example: ${PYPKGPREFIX}-
286our $pkgname_transform = ""; # example: :S,-v,-, 296our $pkgname_transform = ""; # example: :S,-v,-,
287 297
 298# all lines of the package Makefile, for direct modification.
 299our $makefile_lines;
 300
288our $regenerate_distinfo = false; 301our $regenerate_distinfo = false;
289 302
290# Example: 303# Example:
291# add_dependency("DEPENDS", "package", ">=1", "../../category/package"); 304# add_dependency("DEPENDS", "package", ">=1", "../../category/package");
292# 305#
293sub add_dependency($$$$) { 306sub add_dependency($$$$) {
294 my ($type, $pkgbase, $constraint, $dep_dir) = @_; 307 my ($type, $pkgbase, $constraint, $dep_dir) = @_;
295 308
296 if ($dep_dir ne "" && -f "$dep_dir/buildlink3.mk") { 309 if ($dep_dir ne "" && -f "$dep_dir/buildlink3.mk") {
297 # TODO: add type to bl3_lines (BUILDLINK_DEPENDS) 310 # TODO: add type to bl3_lines (BUILDLINK_DEPENDS)
298 # TODO: add constraint to bl3_lines (BUILDLINK_API_DEPENDS) 311 # TODO: add constraint to bl3_lines (BUILDLINK_API_DEPENDS)
299 push(@bl3_lines, ".include \"$dep_dir/buildlink3.mk\""); 312 push(@bl3_lines, ".include \"$dep_dir/buildlink3.mk\"");
300 return; 313 return;
@@ -417,40 +430,55 @@ sub adjust_perl_module_Build_PL() { @@ -417,40 +430,55 @@ sub adjust_perl_module_Build_PL() {
417 430
418# Example packages: 431# Example packages:
419# devel/p5-Algorithm-Diff (no dependencies) 432# devel/p5-Algorithm-Diff (no dependencies)
420# devel/p5-Carp-Assert-More (dependencies without version numbers) 433# devel/p5-Carp-Assert-More (dependencies without version numbers)
421# www/p5-HTML-Quoted (dependency with version number) 434# www/p5-HTML-Quoted (dependency with version number)
422sub adjust_perl_module_Makefile_PL() { 435sub adjust_perl_module_Makefile_PL() {
423 436
424 # To avoid fix_up_makefile error for p5-HTML-Quoted, generate Makefile first. 437 # To avoid fix_up_makefile error for p5-HTML-Quoted, generate Makefile first.
425 system("cd '$abs_wrksrc' && perl -I. Makefile.PL < /dev/null") == 0 or do {}; 438 system("cd '$abs_wrksrc' && perl -I. Makefile.PL < /dev/null") == 0 or do {};
426 439
427 read_dependencies("cd '$abs_wrksrc' && perl -I$libdir -I. Makefile.PL", {}, ""); 440 read_dependencies("cd '$abs_wrksrc' && perl -I$libdir -I. Makefile.PL", {}, "");
428} 441}
429 442
430sub adjust_perl_module() { 443sub adjust_perl_module_homepage($) {
 444 my ($url) = @_;
 445
 446 if (lines_get($makefile_lines, "MASTER_SITES") =~ qr"\$\{MASTER_SITE_PERL_CPAN:") {
 447 my $homepage = lines_get($makefile_lines, "HOMEPAGE");
 448 if ($homepage ne "" && index($url, $homepage) == 0) {
 449 my $module_name = $distname =~ s/-v?[0-9].*//r =~ s/-/::/gr;
 450 lines_set($makefile_lines, "HOMEPAGE", "https://metacpan.org/pod/$module_name");
 451 }
 452 }
 453}
 454
 455sub adjust_perl_module($) {
 456 my ($url) = @_;
 457
431 if (-f "$abs_wrksrc/Build.PL") { 458 if (-f "$abs_wrksrc/Build.PL") {
432 adjust_perl_module_Build_PL(); 459 adjust_perl_module_Build_PL();
433 } elsif (-f "$abs_wrksrc/Makefile.PL") { 460 } elsif (-f "$abs_wrksrc/Makefile.PL") {
434 adjust_perl_module_Makefile_PL(); 461 adjust_perl_module_Makefile_PL();
435 } else { 462 } else {
436 return; 463 return;
437 } 464 }
438 465
439 my $packlist = $distname =~ s/-v?[0-9].*//r =~ s/-/\//gr; 466 my $packlist = $distname =~ s/-v?[0-9].*//r =~ s/-/\//gr;
440 push(@build_vars, var("PERL5_PACKLIST", "=", "auto/$packlist/.packlist")); 467 push(@build_vars, var("PERL5_PACKLIST", "=", "auto/$packlist/.packlist"));
441 push(@includes, "../../lang/perl5/module.mk"); 468 push(@includes, "../../lang/perl5/module.mk");
442 $pkgname_prefix = "p5-"; 469 $pkgname_prefix = "p5-";
443 push(@categories, "perl5"); 470 push(@categories, "perl5");
 471 adjust_perl_module_homepage($url);
444 472
445 unlink("PLIST") or do {}; 473 unlink("PLIST") or do {};
446} 474}
447 475
448# Example packages: 476# Example packages:
449# 477#
450# devel/py-ZopeComponent (dependencies, test dependencies) 478# devel/py-ZopeComponent (dependencies, test dependencies)
451sub adjust_python_module() { 479sub adjust_python_module() {
452 480
453 return unless -f "$abs_wrksrc/setup.py"; 481 return unless -f "$abs_wrksrc/setup.py";
454 482
455 my $cmd = "cd '$abs_wrksrc' && $pythonbin setup.py build"; 483 my $cmd = "cd '$abs_wrksrc' && $pythonbin setup.py build";
456 my $env = { 484 my $env = {
@@ -734,52 +762,54 @@ sub determine_wrksrc() { @@ -734,52 +762,54 @@ sub determine_wrksrc() {
734 push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}/$files[0]")); 762 push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}/$files[0]"));
735 } 763 }
736 $abs_wrksrc = "$abs_wrkdir/$files[0]"; 764 $abs_wrksrc = "$abs_wrkdir/$files[0]";
737 } else { 765 } else {
738 push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}" . 766 push(@build_vars, var("WRKSRC", "=", "\${WRKDIR}" .
739 ((@files > 1) ? " # More than one possibility -- please check manually." : ""))); 767 ((@files > 1) ? " # More than one possibility -- please check manually." : "")));
740 $abs_wrksrc = $abs_wrkdir; 768 $abs_wrksrc = $abs_wrkdir;
741 } 769 }
742} 770}
743 771
744sub adjust_package_from_extracted_distfiles($) { 772sub adjust_package_from_extracted_distfiles($) {
745 my ($url) = @_; 773 my ($url) = @_;
746 774
 775 print("url2pkg> Adjusting the Makefile\n");
 776
747 chomp($abs_wrkdir = `$make show-var VARNAME=WRKDIR`); 777 chomp($abs_wrkdir = `$make show-var VARNAME=WRKDIR`);
748 determine_wrksrc(); 778 determine_wrksrc();
749 chomp(@wrksrc_files = `cd "$abs_wrksrc" && find * -type f -print`); 779 chomp(@wrksrc_files = `cd "$abs_wrksrc" && find * -type f -print`);
750 chomp(@wrksrc_dirs = `cd "$abs_wrksrc" && find * -type d -print`); 780 chomp(@wrksrc_dirs = `cd "$abs_wrksrc" && find * -type d -print`);
751 781
 782 my @makefile_lines = read_lines("Makefile");
 783 $makefile_lines = \@makefile_lines;
 784
752 adjust_configure(); 785 adjust_configure();
753 adjust_cmake(); 786 adjust_cmake();
754 adjust_meson(); 787 adjust_meson();
755 adjust_gconf2_schemas(); 788 adjust_gconf2_schemas();
756 adjust_libtool(); 789 adjust_libtool();
757 adjust_perl_module(); 790 adjust_perl_module($url);
758 adjust_python_module(); 791 adjust_python_module();
759 adjust_cargo(); 792 adjust_cargo();
760 adjust_pkg_config(); 793 adjust_pkg_config();
761 adjust_po(); 794 adjust_po();
762 adjust_use_languages(); 795 adjust_use_languages();
763 796
764 print("url2pkg> Adjusting the Makefile\n"); 797 my $marker_index = lines_index($makefile_lines, qr"^# url2pkg-marker");
765 
766 my @prev_lines = read_lines("Makefile"); 
767 my $marker_index = lines_index(\@prev_lines, qr"^# url2pkg-marker"); 
768 if ($marker_index == -1) { 798 if ($marker_index == -1) {
769 die("$0: ERROR: didn't find the url2pkg marker in the Makefile.\n"); 799 die("$0: ERROR: didn't find the url2pkg marker in the Makefile.\n");
770 } 800 }
771 801
772 my @lines = @prev_lines[0 .. $marker_index - 1]; 802 my @lines = @$makefile_lines[0 .. $marker_index - 1];
773 803
774 if (lines_index(\@lines, qr"^PKGNAME=") == -1) { 804 if (lines_index(\@lines, qr"^PKGNAME=") == -1) {
775 my $distname_index = lines_index(\@lines, qr"^DISTNAME=(\t+)"); 805 my $distname_index = lines_index(\@lines, qr"^DISTNAME=(\t+)");
776 if ($distname_index != -1) { 806 if ($distname_index != -1) {
777 my $pkgname_line = "PKGNAME=\t$pkgname_prefix\${DISTNAME$pkgname_transform}"; 807 my $pkgname_line = "PKGNAME=\t$pkgname_prefix\${DISTNAME$pkgname_transform}";
778 splice(@lines, $distname_index + 1, 0, $pkgname_line); 808 splice(@lines, $distname_index + 1, 0, $pkgname_line);
779 } 809 }
780 } 810 }
781 811
782 if (@todos) { 812 if (@todos) {
783 foreach my $todo (@todos) { 813 foreach my $todo (@todos) {
784 push(@lines, "# TODO: $todo"); 814 push(@lines, "# TODO: $todo");
785 } 815 }
@@ -788,27 +818,27 @@ sub adjust_package_from_extracted_distfi @@ -788,27 +818,27 @@ sub adjust_package_from_extracted_distfi
788 818
789 my @depend_vars; 819 my @depend_vars;
790 push(@depend_vars, map { var("BUILD_DEPENDS", "+=", $_) } @build_depends); 820 push(@depend_vars, map { var("BUILD_DEPENDS", "+=", $_) } @build_depends);
791 push(@depend_vars, map { var("DEPENDS", "+=", $_) } @depends); 821 push(@depend_vars, map { var("DEPENDS", "+=", $_) } @depends);
792 push(@depend_vars, map { var("TEST_DEPENDS", "+=", $_) } @test_depends); 822 push(@depend_vars, map { var("TEST_DEPENDS", "+=", $_) } @test_depends);
793 lines_add_vars(\@lines, \@depend_vars); 823 lines_add_vars(\@lines, \@depend_vars);
794 824
795 lines_add_vars(\@lines, \@build_vars); 825 lines_add_vars(\@lines, \@build_vars);
796 lines_add_vars(\@lines, \@extra_vars); 826 lines_add_vars(\@lines, \@extra_vars);
797 827
798 push(@lines, @bl3_lines); 828 push(@lines, @bl3_lines);
799 push(@lines, map { $_ = ".include \"$_\"" } @includes); 829 push(@lines, map { $_ = ".include \"$_\"" } @includes);
800 830
801 push(@lines, @prev_lines[$marker_index + 1 .. $#prev_lines]); 831 push(@lines, $makefile_lines->[$marker_index + 1 .. $#$makefile_lines]);
802 832
803 lines_append(\@lines, "CATEGORIES", join(" ", @categories)); 833 lines_append(\@lines, "CATEGORIES", join(" ", @categories));
804 834
805 adjust_lines_python_module(\@lines, $url); 835 adjust_lines_python_module(\@lines, $url);
806 836
807 foreach my $varname (keys %update_vars) { 837 foreach my $varname (keys %update_vars) {
808 lines_set(\@lines, $varname, $update_vars{$varname}); 838 lines_set(\@lines, $varname, $update_vars{$varname});
809 } 839 }
810 840
811 write_lines("Makefile", @lines); 841 write_lines("Makefile", @lines);
812 842
813 if ($regenerate_distinfo) { 843 if ($regenerate_distinfo) {
814 make("distinfo"); 844 make("distinfo");

cvs diff -r1.10 -r1.11 pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.t (expand / switch to unified diff)

--- pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.t 2019/09/12 18:23:00 1.10
+++ pkgsrc/pkgtools/url2pkg/files/Attic/url2pkg.t 2019/09/13 06:22:33 1.11
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1# -*- perl -*- 1# -*- perl -*-
2# $NetBSD: url2pkg.t,v 1.10 2019/09/12 18:23:00 rillig Exp $ 2# $NetBSD: url2pkg.t,v 1.11 2019/09/13 06:22:33 rillig Exp $
3 3
4require "url2pkg.pl"; 4require "url2pkg.pl";
5 5
6use Test::More; 6use Test::More;
7 7
8use strict; 8use strict;
9use warnings; 9use warnings;
10 10
11sub test_lines_add_vars__simple() { 11sub test_lines_add_vars__simple() {
12 my $lines = []; 12 my $lines = [];
13 13
14 lines_add_vars($lines, [ 14 lines_add_vars($lines, [
15 var("1", "=", "one"), 15 var("1", "=", "one"),
@@ -103,26 +103,38 @@ sub test_lines_index() { @@ -103,26 +103,38 @@ sub test_lines_index() {
103 my $lines = ["1", "2", "345"]; 103 my $lines = ["1", "2", "345"];
104 104
105 is(lines_index($lines, "1"), 0); 105 is(lines_index($lines, "1"), 0);
106 is(lines_index($lines, "2"), 1); 106 is(lines_index($lines, "2"), 1);
107 is(lines_index($lines, "345"), 2); 107 is(lines_index($lines, "345"), 2);
108 is(lines_index($lines, "4"), 2); 108 is(lines_index($lines, "4"), 2);
109 109
110 is(lines_index($lines, qr"^(\d\d)\d$"), 2); 110 is(lines_index($lines, qr"^(\d\d)\d$"), 2);
111 is(lines_index($lines, qr"^\d\s\d$"), -1); 111 is(lines_index($lines, qr"^\d\s\d$"), -1);
112 is(lines_index($lines, qr"(\d)"), 0); 112 is(lines_index($lines, qr"(\d)"), 0);
113 is($1, undef); # capturing groups do not work here 113 is($1, undef); # capturing groups do not work here
114} 114}
115 115
 116sub test_lines_get() {
 117 my $lines = [
 118 "VAR=value",
 119 "VAR=\tvalue # comment",
 120 "UNIQUE=\tunique"
 121 ];
 122
 123 is(lines_get($lines, "VAR"), ""); # too many values
 124 is(lines_get($lines, "ENOENT"), ""); # no value at all
 125 is(lines_get($lines, "UNIQUE"), "unique");
 126}
 127
116sub test_generate_initial_package_Makefile_lines__GitHub_archive() { 128sub test_generate_initial_package_Makefile_lines__GitHub_archive() {
117 my $url = "https://github.com/org/proj/archive/v1.0.0.tar.gz"; 129 my $url = "https://github.com/org/proj/archive/v1.0.0.tar.gz";
118 130
119 my @lines = generate_initial_package_Makefile_lines($url); 131 my @lines = generate_initial_package_Makefile_lines($url);
120 132
121 is_deeply(\@lines, [ 133 is_deeply(\@lines, [
122 "# \$" . "NetBSD\$", 134 "# \$" . "NetBSD\$",
123 "", 135 "",
124 "GITHUB_PROJECT=\tproj", 136 "GITHUB_PROJECT=\tproj",
125 "DISTNAME=\tv1.0.0", 137 "DISTNAME=\tv1.0.0",
126 "PKGNAME=\t\${GITHUB_PROJECT}-\${DISTNAME:S,^v,,}", 138 "PKGNAME=\t\${GITHUB_PROJECT}-\${DISTNAME:S,^v,,}",
127 "CATEGORIES=\tpkgtools", 139 "CATEGORIES=\tpkgtools",
128 "MASTER_SITES=\t\${MASTER_SITE_GITHUB:=org/}", 140 "MASTER_SITES=\t\${MASTER_SITE_GITHUB:=org/}",
@@ -254,26 +266,27 @@ sub set_up_test() { @@ -254,26 +266,27 @@ sub set_up_test() {
254 266
255 @main::depends = (); 267 @main::depends = ();
256 @main::build_depends = (); 268 @main::build_depends = ();
257 @main::test_depends = (); 269 @main::test_depends = ();
258 @main::bl3_lines = (); 270 @main::bl3_lines = ();
259 @main::includes = (); 271 @main::includes = ();
260 @main::build_vars = (); 272 @main::build_vars = ();
261 @main::extra_vars = (); 273 @main::extra_vars = ();
262 %main::update_vars = (); 274 %main::update_vars = ();
263 @main::todos = (); 275 @main::todos = ();
264 276
265 $main::pkgname_prefix = ""; 277 $main::pkgname_prefix = "";
266 $main::pkgname_transform = ""; 278 $main::pkgname_transform = "";
 279 $main::makefile_lines = [];
267 $main::regenerate_distinfo = 0; 280 $main::regenerate_distinfo = 0;
268} 281}
269 282
270sub t_main() { 283sub t_main() {
271 my $pkgsrcdir = $ENV{"PKGSRCDIR"} or die; 284 my $pkgsrcdir = $ENV{"PKGSRCDIR"} or die;
272 chdir("$pkgsrcdir/pkgtools/url2pkg") or die; 285 chdir("$pkgsrcdir/pkgtools/url2pkg") or die;
273 286
274 no strict 'refs'; 287 no strict 'refs';
275 foreach my $testname (sort grep { $_ =~ qr"^test_" } keys %{"main::"}) { 288 foreach my $testname (sort grep { $_ =~ qr"^test_" } keys %{"main::"}) {
276 next if $testname eq "test_depends"; # it's an array 289 next if $testname eq "test_depends"; # it's an array
277 set_up_test(); 290 set_up_test();
278 &{"main::$testname"}(); 291 &{"main::$testname"}();
279 } 292 }