1: 2 eval 'exec perl -S $0 ${1+"$@"}' 3 if 0; 4#************************************************************** 5# 6# Licensed to the Apache Software Foundation (ASF) under one 7# or more contributor license agreements. See the NOTICE file 8# distributed with this work for additional information 9# regarding copyright ownership. The ASF licenses this file 10# to you under the Apache License, Version 2.0 (the 11# "License"); you may not use this file except in compliance 12# with the License. You may obtain a copy of the License at 13# 14# http://www.apache.org/licenses/LICENSE-2.0 15# 16# Unless required by applicable law or agreed to in writing, 17# software distributed under the License is distributed on an 18# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19# KIND, either express or implied. See the License for the 20# specific language governing permissions and limitations 21# under the License. 22# 23#************************************************************** 24 25 26 27use Cwd; 28use File::Temp qw/ tempfile tempdir /; 29 30my $verbosity = 1; # will be adjusted to the value of $Env{VERBOSE} below 31 32# platforms which are not supported anymore, and thus can be filtered from the svn:ignore list 33my %obsolete_platforms = ( 34 ); 35 # (none so far) 36 37# platforms whose output trees should appear in all modules' svn:ignore list 38my @platforms = ( 39 "common", 40 "unxlngi6", 41 "unxlngx6", 42 "unxsols4", 43 "unxsolu4", 44 "unxsoli4", 45 "wntmsci12", 46 "unxmacxi", 47 "unxmacxp", 48 "unxmacci", 49 "unxmaccx", 50 "unxmaccr", 51 "unxubit8", 52 "unxaixp", 53 "unxbsda", 54 "unxbsdi2", 55 "unxbsdi", 56 "unxbsds", 57 "unxfbsdi", 58 "unxfbsd", 59 "unxfbsdx", 60 "unxhpgr", 61 "unxhpxr", 62 "unxirgm", 63 "unxirxm3", 64 "unxirxm", 65 "unxlnga", 66 "unxlngm68k", 67 "unxlngmips", 68 "unxlngp", 69 "unxlngppc4", 70 "unxlngppc64", 71 "unxlngppc", 72 "unxlngr", 73 "unxlngs3904", 74 "unxlngs390x", 75 "unxlngs", 76 "unxlnxi", 77 "unxsogi", 78 "unxsogs" 79 ); 80 81 82# ......................................................................... 83# retrieves the repository URL of the SVN working copy in the current directory 84sub retrieve_repo_url 85{ 86 open( SVN, "svn info 2>&1 |" ); 87 my @result = <SVN>; 88 close( SVN ); 89 90 foreach (@result) 91 { 92 chomp; 93 next if ( ! /^URL: / ); 94 s/^URL: //; 95 return $_; 96 } 97 return undef; 98} 99 100# ......................................................................... 101# gets the "modules" below the given SVN repository URL, by calling "svn list" 102sub get_modules 103{ 104 my @modules = (); 105 106 open( SVN, "svn list $_ 2>&1 |" ); 107 my @result = <SVN>; 108 close( SVN ); 109 110 foreach (@result) 111 { 112 chomp; 113 s/\/$//; 114 push @modules, $_; 115 } 116 117 return @modules; 118} 119 120# ......................................................................... 121sub set_ignore_property 122{ 123 my ($repo_url, @modules) = @_; 124 125 # max length of a module name 126 my $max_len = 0; 127 foreach ( @modules ) { $max_len = length( $_ ) if ( length( $_ ) > $max_len ); } 128 129 my $updated = 0; 130 131 my $current = 0; 132 my $count = $#modules + 1; 133 foreach $module ( @modules ) 134 { 135 ++$current; 136 137 # print progress 138 if ( $verbosity > 1 ) 139 { 140 my $progress = "$module "; 141 $progress .= "(" . $current . "/" . $count . ")"; 142 143 my $dots = 3 + ( $max_len - length($module) ); 144 $dots += int( digits( $count ) ) - int( digits( $current ) ); 145 146 $progress .= ( "." x $dots ); 147 $progress .= " "; 148 149 print STDOUT $progress; 150 } 151 elsif ( $verbosity > 0 ) 152 { 153 print STDOUT "."; 154 } 155 156 # retrieve the current ignore list 157 open( SVN, "svn propget svn:ignore $module 2>&1 |" ); 158 my @ignore_list = <SVN>; 159 close( SVN ); 160 161 # the last item in the list is an empty string, usually. Don't let it confuse the below 162 # code 163 my $supposed_empty = pop @ignore_list; 164 chomp( $supposed_empty ); 165 push( @ignore_list, $supposed_empty ) if ( !( $supposed_empty =~ /^$/ ) ); 166 167 # filter out obsolte entries 168 my @stripped_ignore_list = (); 169 foreach $ignore_entry (@ignore_list) 170 { 171 chomp( $ignore_entry ); 172 next if ( $ignore_entry =~ /^$/ ); 173 174 if ( ( exists $obsolete_platforms{$ignore_entry} ) 175 || ( exists $obsolete_platforms{"$ignore_entry.pro"} ) 176 ) 177 { 178 next; 179 } 180 push @stripped_ignore_list, $ignore_entry; 181 } 182 my $removed = $#ignore_list - $#stripped_ignore_list; 183 @ignore_list = @stripped_ignore_list; 184 185 # append the platforms which should appear in the ignore list 186 my %ignore_list = (); 187 foreach (@ignore_list) { $ignore_list{$_} = 1; } 188 foreach $platform_entry ( @platforms ) 189 { 190 $ignore_list{$platform_entry} = 1; 191 $ignore_list{"$platform_entry.pro"} = 1; 192 } 193 my @extended_ignore_list = keys %ignore_list; 194 my $added = $#extended_ignore_list - $#ignore_list; 195 @ignore_list = @extended_ignore_list; 196 197 if ( $removed || $added ) 198 { 199 # create a temporary file taking the new content of the svn_ignore property 200 my $temp_dir = tempdir( CLEANUP => 1 ); 201 my ($fh, $filename) = tempfile( DIR => $dir ); 202 open( IGNORE, ">$filename" ); 203 print IGNORE join "\n", @ignore_list; 204 close( IGNORE ); 205 206 # actually set the property 207 open( SVN, "svn propset -F $filename svn:ignore $module 2>&1 |" ); 208 209 ++$updated; 210 } 211 212 # statistics 213 print STDOUT "done (removed/added: $removed/$added)\n" if $verbosity > 1; 214 } 215 216 print STDOUT "\n" if $verbosity eq 1; 217 print STDOUT "$updated module(s) updated\n" if $verbosity > 0; 218} 219 220# ......................................................................... 221sub digits 222{ 223 my ($number, $base) = @_; 224 $base = 10 if !defined $base; 225 return log($number)/log($base); 226} 227 228# ......................................................................... 229# 'main' 230 231# initialize verbosity 232my $verbose = $ENV{VERBOSE}; 233if ( defined $verbose ) 234{ 235 $verbose = uc( $verbose ); 236 $verbosity = 2 if ( $verbose eq "TRUE" ); 237 $verbosity = 0 if ( $verbose eq "FALSE" ); 238} 239 240# work on the current directory 241my $working_copy_root = cwd(); 242die "current directory does not contain an SVN working copy" if !-d $working_copy_root . "/\.svn"; 243 244# retrieve repository URL 245my $repo_url = retrieve_repo_url(); 246die "unable to retrieve repository URL" if !defined $repo_url; 247print STDOUT "repository URL: $repo_url\n" if $verbosity > 1; 248 249# list modules 250my @modules = get_modules( $repo_url ); 251print STDOUT "processing " . ( $#modules + 1 ) . " modules\n" if $verbosity > 0; 252 253# process modules, by setting the svn:ignore property 254set_ignore_property( $repo_url, @modules ); 255