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