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 "unxubit8", 48 "unxaixp", 49 "unxbsda", 50 "unxbsdi2", 51 "unxbsdi", 52 "unxbsds", 53 "unxfbsdi", 54 "unxfbsd", 55 "unxfbsdx", 56 "unxhpgr", 57 "unxhpxr", 58 "unxirgm", 59 "unxirxm3", 60 "unxirxm", 61 "unxlnga", 62 "unxlngm68k", 63 "unxlngmips", 64 "unxlngp", 65 "unxlngppc4", 66 "unxlngppc64", 67 "unxlngppc", 68 "unxlngr", 69 "unxlngs3904", 70 "unxlngs390x", 71 "unxlngs", 72 "unxlnxi", 73 "unxmacxp", 74 "unxsogi", 75 "unxsogs" 76 ); 77 78 79# ......................................................................... 80# retrieves the repository URL of the SVN working copy in the current directory 81sub retrieve_repo_url 82{ 83 open( SVN, "svn info 2>&1 |" ); 84 my @result = <SVN>; 85 close( SVN ); 86 87 foreach (@result) 88 { 89 chomp; 90 next if ( ! /^URL: / ); 91 s/^URL: //; 92 return $_; 93 } 94 return undef; 95} 96 97# ......................................................................... 98# gets the "modules" below the given SVN repository URL, by calling "svn list" 99sub get_modules 100{ 101 my @modules = (); 102 103 open( SVN, "svn list $_ 2>&1 |" ); 104 my @result = <SVN>; 105 close( SVN ); 106 107 foreach (@result) 108 { 109 chomp; 110 s/\/$//; 111 push @modules, $_; 112 } 113 114 return @modules; 115} 116 117# ......................................................................... 118sub set_ignore_property 119{ 120 my ($repo_url, @modules) = @_; 121 122 # max length of a module name 123 my $max_len = 0; 124 foreach ( @modules ) { $max_len = length( $_ ) if ( length( $_ ) > $max_len ); } 125 126 my $updated = 0; 127 128 my $current = 0; 129 my $count = $#modules + 1; 130 foreach $module ( @modules ) 131 { 132 ++$current; 133 134 # print progress 135 if ( $verbosity > 1 ) 136 { 137 my $progress = "$module "; 138 $progress .= "(" . $current . "/" . $count . ")"; 139 140 my $dots = 3 + ( $max_len - length($module) ); 141 $dots += int( digits( $count ) ) - int( digits( $current ) ); 142 143 $progress .= ( "." x $dots ); 144 $progress .= " "; 145 146 print STDOUT $progress; 147 } 148 elsif ( $verbosity > 0 ) 149 { 150 print STDOUT "."; 151 } 152 153 # retrieve the current ignore list 154 open( SVN, "svn propget svn:ignore $module 2>&1 |" ); 155 my @ignore_list = <SVN>; 156 close( SVN ); 157 158 # the last item in the list is an empty string, usually. Don't let it confuse the below 159 # code 160 my $supposed_empty = pop @ignore_list; 161 chomp( $supposed_empty ); 162 push( @ignore_list, $supposed_empty ) if ( !( $supposed_empty =~ /^$/ ) ); 163 164 # filter out obsolte entries 165 my @stripped_ignore_list = (); 166 foreach $ignore_entry (@ignore_list) 167 { 168 chomp( $ignore_entry ); 169 next if ( $ignore_entry =~ /^$/ ); 170 171 if ( ( exists $obsolete_platforms{$ignore_entry} ) 172 || ( exists $obsolete_platforms{"$ignore_entry.pro"} ) 173 ) 174 { 175 next; 176 } 177 push @stripped_ignore_list, $ignore_entry; 178 } 179 my $removed = $#ignore_list - $#stripped_ignore_list; 180 @ignore_list = @stripped_ignore_list; 181 182 # append the platforms which should appear in the ignore list 183 my %ignore_list = (); 184 foreach (@ignore_list) { $ignore_list{$_} = 1; } 185 foreach $platform_entry ( @platforms ) 186 { 187 $ignore_list{$platform_entry} = 1; 188 $ignore_list{"$platform_entry.pro"} = 1; 189 } 190 my @extended_ignore_list = keys %ignore_list; 191 my $added = $#extended_ignore_list - $#ignore_list; 192 @ignore_list = @extended_ignore_list; 193 194 if ( $removed || $added ) 195 { 196 # create a temporary file taking the new content of the svn_ignore property 197 my $temp_dir = tempdir( CLEANUP => 1 ); 198 my ($fh, $filename) = tempfile( DIR => $dir ); 199 open( IGNORE, ">$filename" ); 200 print IGNORE join "\n", @ignore_list; 201 close( IGNORE ); 202 203 # actually set the property 204 open( SVN, "svn propset -F $filename svn:ignore $module 2>&1 |" ); 205 206 ++$updated; 207 } 208 209 # statistics 210 print STDOUT "done (removed/added: $removed/$added)\n" if $verbosity > 1; 211 } 212 213 print STDOUT "\n" if $verbosity eq 1; 214 print STDOUT "$updated module(s) updated\n" if $verbosity > 0; 215} 216 217# ......................................................................... 218sub digits 219{ 220 my ($number, $base) = @_; 221 $base = 10 if !defined $base; 222 return log($number)/log($base); 223} 224 225# ......................................................................... 226# 'main' 227 228# initialize verbosity 229my $verbose = $ENV{VERBOSE}; 230if ( defined $verbose ) 231{ 232 $verbose = uc( $verbose ); 233 $verbosity = 2 if ( $verbose eq "TRUE" ); 234 $verbosity = 0 if ( $verbose eq "FALSE" ); 235} 236 237# work on the current directory 238my $working_copy_root = cwd(); 239die "current directory does not contain an SVN working copy" if !-d $working_copy_root . "/\.svn"; 240 241# retrieve repository URL 242my $repo_url = retrieve_repo_url(); 243die "unable to retrieve repository URL" if !defined $repo_url; 244print STDOUT "repository URL: $repo_url\n" if $verbosity > 1; 245 246# list modules 247my @modules = get_modules( $repo_url ); 248print STDOUT "processing " . ( $#modules + 1 ) . " modules\n" if $verbosity > 0; 249 250# process modules, by setting the svn:ignore property 251set_ignore_property( $repo_url, @modules ); 252