Fix ekeyword to handle multiline KEYWORDS
authorfuzzyray <fuzzyray@gentoo.org>
Fri, 24 Apr 2009 16:37:09 +0000 (16:37 -0000)
committerfuzzyray <fuzzyray@gentoo.org>
Fri, 24 Apr 2009 16:37:09 +0000 (16:37 -0000)
svn path=/; revision=549

trunk/ChangeLog
trunk/src/ekeyword/ChangeLog
trunk/src/ekeyword/ekeyword

index 42415d4b417e2f630c5e0fe486c97dd46cce2bd3..3007bc5f2120031cce47a01337096328a1aac983 100644 (file)
@@ -1,3 +1,6 @@
+2009-04-24: Paul Varner <fuzzyray@gentoo.org>
+       * ekeyword: Fix to handle multiline KEYWORDS (Bug #267250)
+
 2009-01-08: Paul Varner <fuzzyray@gentoo.org>
        * equery: Fix package.py to account for PORTDIR being a symbolic link
        when checking if a package is in an overlay. (Bug #253968)
index c3f142a2a5de35f8c98a52909d6e75f91c02d52d..68d99e5551175ae084ec0a0ba015f9e3e0d7ae4a 100644 (file)
@@ -1,3 +1,6 @@
+24 Apr 2009 Paul Varner <fuzzyray@gentoo.org>
+       * Handle multiline KEYWORDS
+
 07 Jan 2009 Mike Frysinger <vapier@gentoo.org>
        * Support intended KEYWORDS
        * Convert every instance of KEYWORDS in the file
index 4f8bb05a1a7079804f5ac3558cc2134a4727cadf..dd6a573df3062e26bebb89aac02f72127a32301b 100755 (executable)
@@ -41,66 +41,74 @@ for my $f (@ARGV) {
        select O;
 
        while (<I>) {
-               /^\s*KEYWORDS=/ or print, next;
+               if (/^\s*KEYWORDS=/) {
 
-               # extract the quoted section from KEYWORDS
-               (my $quoted = $_) =~ s/^.*?["'](.*?)["'].*/$1/s;
-
-               # replace -* with -STAR for our convenience below
-               $quoted =~ s/-\*/-STAR/;
+                       # extract the quoted section from KEYWORDS
+                       while (not /^KEYWORDS=["'].*?["']/) {
+                               chomp;
+                               my $next = <I>;
+                               $_ = join "", $_, $next;
+                       }
+                       (my $quoted = $_) =~ s/^.*?["'](.*?)["'].*/$1/s;
 
-               for my $k (@kw) {
-                       my ($leader, $arch, $star) = ($k =~ /$kw_re/o);
+                       # replace -* with -STAR for our convenience below
+                       $quoted =~ s/-\*/-STAR/;
 
-                       # handle -* and ^*
-                       if (defined $star) {
-                               $leader = substr $star,0,1;
-                               $arch = 'STAR';
-                       }
+                       for my $k (@kw) {
+                               my ($leader, $arch, $star) = ($k =~ /$kw_re/o);
 
-                       # remove keywords
-                       if ($leader eq '^') {
-                               if ($arch eq 'all') {
-                                       $quoted = '';
-                               } else {
-                                       $quoted =~ s/[-~]?\Q$arch\E\b//;
+                               # handle -* and ^*
+                               if (defined $star) {
+                                       $leader = substr $star,0,1;
+                                       $arch = 'STAR';
                                }
 
-                       # add or modify keywords
-                       } else {
-                               if ($arch eq 'all') {
-                                       # modify all non-masked keywords in the list
-                                       $quoted =~ s/(^|\s)~?(?=\w)/$1$leader/g;
+                               # remove keywords
+                               if ($leader eq '^') {
+                                       if ($arch eq 'all') {
+                                               $quoted = '';
+                                       } else {
+                                               $quoted =~ s/[-~]?\Q$arch\E\b//;
+                                       }
+
+                               # add or modify keywords
                                } else {
-                                       # modify or add keyword
-                                       unless ($quoted =~ s/[-~]?\Q$arch\E(\s|$)/$leader$arch$1/) {
-                                               # modification failed, need to add
-                                               if ($arch eq 'STAR') {
-                                                       $quoted = "$leader$arch $quoted";
-                                               } else {
-                                                       $quoted .= " $leader$arch";
+                                       if ($arch eq 'all') {
+                                               # modify all non-masked keywords in the list
+                                               $quoted =~ s/(^|\s)~?(?=\w)/$1$leader/g;
+                                       } else {
+                                               # modify or add keyword
+                                               unless ($quoted =~ s/[-~]?\Q$arch\E(\s|$)/$leader$arch$1/) {
+                                                       # modification failed, need to add
+                                                       if ($arch eq 'STAR') {
+                                                               $quoted = "$leader$arch $quoted";
+                                                       } else {
+                                                               $quoted .= " $leader$arch";
+                                                       }
                                                }
                                        }
                                }
                        }
-               }
 
-               # replace -STAR with -*
-               $quoted =~ s/-STAR\b/-*/;
+                       # replace -STAR with -*
+                       $quoted =~ s/-STAR\b/-*/;
 
-               # sort keywords and fix spacing
-               $quoted = join " ", sort {
-                       (my $sa = $a) =~ s/^\W//;
-                       (my $sb = $b) =~ s/^\W//;
-                       return -1 if $sa eq '*';
-                       return +1 if $sb eq '*';
-                       $sa cmp $sb;
-               } split " ", $quoted;
+                       # sort keywords and fix spacing
+                       $quoted = join " ", sort {
+                               (my $sa = $a) =~ s/^\W//;
+                               (my $sb = $b) =~ s/^\W//;
+                               return -1 if $sa eq '*';
+                               return +1 if $sb eq '*';
+                               $sa cmp $sb;
+                       } split " ", $quoted;
 
-               # re-insert quoted to KEYWORDS
-               s/(["']).*?["']/$1$quoted$1/;
+                       # re-insert quoted to KEYWORDS
+                       s/(["']).*?["']/$1$quoted$1/;
 
-               print $_ or die "Can't write $f.new: $!\n";
+                       print $_ or die "Can't write $f.new: $!\n";
+               } else {
+                       print, next;
+               }
        }
 
        close I;
@@ -109,7 +117,7 @@ for my $f (@ARGV) {
 
        system "diff -U 0 $f $f.new | sed -n '/KEYWORDS=/s:^:  :p'";
        rename "$f.new", "$f" or die "Can't rename: $!\n";
-    $files++;
+       $files++;
 }
 
 if ($files == 0) {