1 #!/usr/perl5/bin/perl 2 # 3 # Generate report on copyright files 4 # 5 # CDDL HEADER START 6 # 7 # The contents of this file are subject to the terms of the 8 # Common Development and Distribution License, Version 1.0 only 9 # (the "License"). You may not use this file except in compliance 10 # with the License. 11 # 12 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 13 # or http://www.opensolaris.org/os/licensing. 14 # See the License for the specific language governing permissions 15 # and limitations under the License. 16 # 17 # When distributing Covered Code, include this CDDL HEADER in each 18 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 19 # If applicable, add the following below this CDDL HEADER, with the 20 # fields enclosed by brackets "[]" replaced with your own identifying 21 # information: Portions Copyright [yyyy] [name of copyright owner] 22 # 23 # CDDL HEADER END 24 # 25 # 26 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 27 # Use is subject to license terms. 28 # 29 use strict; 30 use warnings; 31 use Cwd; 32 use Getopt::Long qw(:config gnu_compat no_auto_abbrev bundling pass_through); 33 use File::Basename; 34 35 sub usage() { 36 print "report-copyright [options] <spec files...>\n"; 37 print "\n"; 38 print "Options:\n"; 39 print " -b s, --branch=s\n"; 40 print " Use the s branch for links to copyright files, instead\n"; 41 print " of trunk\n"; 42 print " -r r, --repo=r\n"; 43 print " Use the r repository for links to copyright files,\n"; 44 print " instead of spec-files\n"; 45 print " -h, --help\n"; 46 print " Print this usage information\n"; 47 } 48 49 my @specs; 50 my $repo = "spec-files"; 51 my $branch = "trunk"; 52 53 sub process_args { 54 my $arg = shift; 55 56 if ($arg =~ /^-/) { 57 print "Unknown option: $arg\n"; 58 print "Try --help for usage.\n"; 59 exit (1); 60 } 61 62 push (@specs, $arg); 63 } 64 65 sub process_options { 66 67 Getopt::Long::Configure ("bundling"); 68 69 GetOptions ('h|help' => sub { usage (); exit (0); }, 70 'b|branch=s' => sub { shift; $branch = shift; $branch = "branches/$branch"; }, 71 'r|repo=s' => sub { shift; $repo = shift; }, 72 '<>' => \&process_args); 73 } 74 75 my %owners; 76 my %copyright_files; 77 78 # like uniq(1) 79 sub uniq (@) { 80 my @list = @_; 81 my $prev; 82 if (not @list) { 83 return @list; 84 } 85 $prev = $list[0]; 86 my @uniq_list = ($prev); 87 foreach my $str (@list) { 88 next if $str eq $prev; 89 push (@uniq_list, $str); 90 $prev = $str; 91 } 92 return @uniq_list; 93 } 94 95 sub main() { 96 process_options(); 97 98 foreach my $spec (@specs) { 99 next if not defined ($spec); 100 # find the owner from the comments 101 my $RE = '^# [Oo]wner: *.[^ ]*[ ]*$'; 102 my $owner = `grep '$RE' $spec | head -1`; 103 chomp ($owner); 104 if ($owner eq '') { 105 $owner = 'Unknown'; 106 } 107 $owner =~ s/^#\s*[Oo]wner:\s*(\S+)\s*/$1/; 108 $owners{$spec} = $owner; 109 110 # find the copyright file 111 my $cpr = `spectool --with-sun-branding eval '%sunw_copyright' $spec 2>/dev/null`; 112 chomp ($cpr); 113 $copyright_files{$spec} = $cpr; 114 } 115 116 print << "_EOF"; 117 <html> 118 <head> 119 <title>JDS copyright file report for $branch in $repo</title> 120 </head> 121 <body> 122 <font face="arial,sans"> 123 <b>JDS package copyright report for $branch in $repo</b><p> 124 <table border=1 cellspacing=0> 125 <tr><td><b>spec file</b></td><td><b>owner</b></td><td><b>copyright file</b></td></tr> 126 _EOF 127 128 my $missing = 0; 129 foreach my $spec (sort @specs) { 130 my $base = basename ($spec); 131 print "<tr><td>$base</td>\n"; 132 print "<td><a href=\"http://www.opensolaris.org/viewProfile.jspa?username=$owners{$spec}\">$owners{$spec}</a></td>\n"; 133 $base =~ s/\.spec//; 134 if ($copyright_files{$spec} ne "${base}.copyright") { 135 print "<td bgcolor=#ffaaaa>$copyright_files{$spec}</td>\n"; 136 $missing ++; 137 } else { 138 print "<td bgcolor=#aaffaa><a href=\"http://src.opensolaris.org/source/xref/jds/${repo}/${branch}/copyright/${copyright_files{$spec}}\">$copyright_files{$spec}</a></td>\n"; 139 } 140 print "</tr>\n"; 141 } 142 143 my $total = $#specs + 1; 144 my $date = `TZ=GMT date`; 145 146 print << "_EOF"; 147 </table><p> 148 $missing package(s) missing copyright file out of $total. 149 <p> 150 <b>Missing copyright files by owner:</b><small> 151 <table border=1 cellspacing=0> 152 <tr><td><b>owner</b></td><td><b>spec files</b></td></tr> 153 _EOF 154 foreach my $owner (uniq sort values %owners) { 155 my $first_spec = 1; 156 foreach my $spec (sort @specs) { 157 next if $owners{$spec} ne $owner; 158 my $base = basename ($spec); 159 $base =~ s/\.spec//; 160 if ($copyright_files{$spec} ne "${base}.copyright") { 161 if ($first_spec) { 162 print "<tr><td valign=top><a href=\"http://www.opensolaris.org/viewProfile.jspa?username=$owners{$spec}\">$owners{$spec}</a></td>\n"; 163 $first_spec = 0; 164 print "<td>\n"; 165 } 166 print "$base<br>\n"; 167 } 168 } 169 if (not $first_spec) { 170 print "</td></tr>\n"; 171 } 172 } 173 print << "_EOF"; 174 </table> 175 <p><i>report generated on $date</i></small> 176 </font> 177 </body> 178 </html> 179 _EOF 180 } 181 182 main(); 183