pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/pkgtools/lintpkgsrc/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sun Aug 14 12:40:43 UTC 2022

Modified Files:
        pkgsrc/pkgtools/lintpkgsrc/files: lintpkgsrc.pl
        pkgsrc/pkgtools/lintpkgsrc/files/t: glob.t

Log Message:
lintpkgsrc: extract brace expansion, document its various bugs


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.8 -r1.9 pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.91 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.92
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.91 Sun Aug 14 03:18:36 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Sun Aug 14 12:40:43 2022
@@ -1,5 +1,5 @@
 #!@PERL5@
-# $NetBSD: lintpkgsrc.pl,v 1.91 2022/08/14 03:18:36 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.92 2022/08/14 12:40:43 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -246,6 +246,25 @@ sub pkgversion_cmp($va, $op, $vb) {
            : $cmp >= 0;
 }
 
+sub expand_braces($str) {
+       my @todo = ($str);
+
+       my @expanded;
+       # FIXME: see test_expand_braces.
+       while ($str = shift @todo) {
+               # FIXME: see test_expand_braces.
+               if ($str =~ /(.*) \{ ([^{}]+) } (.*)/x) {
+                       # FIXME: see test_expand_braces.
+                       foreach (split(',', $2)) {
+                               push @todo, "$1$_$3";
+                       }
+               } else {
+                       push @expanded, $str;
+               }
+       }
+       @expanded;
+}
+
 # Return a copy of $value in which trivial variable expressions are replaced
 # with their variable values.
 sub expand_exprs($value, $vars) {
@@ -696,21 +715,8 @@ sub get_default_makefile_vars() {
 #
 sub invalid_version($pkgmatch) {
        my ($fail, $ok);
-       my (@pkgmatches);
-
-       my @todo = ($pkgmatch);
-
-       # We handle {} here, everything else in package_globmatch
-       while ($pkgmatch = shift @todo) {
-               if ($pkgmatch =~ /(.*)\{([^{}]+)}(.*)/) {
-                       foreach (split(',', $2)) {
-                               push @todo, "$1$_$3";
-                       }
-               } else {
-                       push @pkgmatches, $pkgmatch;
-               }
-       }
 
+       my @pkgmatches = expand_braces($pkgmatch);
        foreach $pkgmatch (@pkgmatches) {
                my ($pkg, $badver) = package_globmatch($pkgmatch);
 

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t:1.8 pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t:1.9
--- pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t:1.8       Sat Aug 13 12:22:20 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t   Sun Aug 14 12:40:43 2022
@@ -1,4 +1,4 @@
-# $NetBSD: glob.t,v 1.8 2022/08/13 12:22:20 rillig Exp $
+# $NetBSD: glob.t,v 1.9 2022/08/14 12:40:43 rillig Exp $
 #
 # Tests for file globbing and matching.
 
@@ -58,4 +58,26 @@ sub test_glob2regex() {
        ok("a\nb" =~ $re, 1);
 }
 
+sub test_expand_braces() {
+       my @examples = (
+           [ '', ],
+           [ 'abc', 'abc' ],
+           [ '{a,b,c}', 'a', 'b', 'c' ],
+           # FIXME: '<>' is missing.
+           [ '<{opt,}>', '<opt>' ],
+           [ '<{,opt}>', '<>', '<opt>' ],
+           # FIXME: '0', '1', '2' are missing.
+           [ '{0,1,2}', ],
+           # FIXME: '0' is missing.
+           [ '{2,1,0}', '2', '1' ],
+       );
+
+       foreach my $example (@examples) {
+               my ($str, @expected) = @$example;
+               my @actual = expand_braces($str);
+               ok(join(' ', @actual), join(' ', @expected));
+       }
+}
+
 test_glob2regex();
+test_expand_braces();



Home | Main Index | Thread Index | Old Index