1: 2eval 'exec perl -wS $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# 27# 28# checkdeliver.pl - compare delivered files on solver with those on SRC_ROOT 29# 30 31use strict; 32use Getopt::Long; 33use File::stat; 34use IO::Handle; 35 36use lib ("$ENV{SOLARENV}/bin/modules"); 37 38#### globals ##### 39 40my $err = 0; 41my $srcrootdir = ''; 42my $solverdir = ''; 43my $platform = ''; 44my $logfile = ''; 45my $milestoneext = ''; 46my $local_env = 0; 47my @exceptionmodlist = ( 48 "postprocess", 49 "instset.*native", 50 "smoketest.*native", 51 "testgraphical" 52 ); # modules not yet delivered 53 54#### main ##### 55 56print_logged("checkdeliver.pl - checking delivered binaries\n"); 57 58get_globals(); # get global variables 59my $deliverlists_ref = get_deliver_lists(); # get deliver log files 60foreach my $listfile ( @$deliverlists_ref ) { 61 $err += check( $listfile ); # check delivered files 62} 63print_logged("OK\n") if ( ! $err ); 64exit $err; 65 66#### subroutines #### 67 68sub get_globals 69# set global variables using environment variables and command line options 70{ 71 my $help; 72 73 # set global variables according to environment 74 $platform = $ENV{INPATH}; 75 $srcrootdir = $ENV{SOURCE_ROOT_DIR}; 76 $solverdir = $ENV{SOLARVERSION}; 77 $milestoneext = $ENV{UPDMINOREXT}; 78 79 # override environment with command line options 80 GetOptions('help' => \$help, 81 'l=s' => \$logfile, 82 'p=s' => \$platform 83 ) or usage (1); 84 85 if ( $help ) { 86 usage(0); 87 } 88 89 #do some sanity checks 90 if ( ! ( $platform && $srcrootdir && $solverdir ) ) { 91 die "Error: please set environment\n"; 92 } 93 if ( ! -d $solverdir ) { 94 die "Error: cannot find solver directory '$solverdir'\n"; 95 } 96 97 # Check for local env., taken from solenv/bin/modules/installer/control.pm 98 # In this case the content of SOLARENV starts with the content of SOL_TMP 99 my $solarenv = ""; 100 my $sol_tmp; 101 if ( $ENV{'SOLARENV'} ) { 102 $solarenv = $ENV{'SOLARENV'}; 103 } 104 if ( $ENV{'SOL_TMP'} ) { 105 $sol_tmp = $ENV{'SOL_TMP'}; 106 } 107 if ( defined $sol_tmp && ( $solarenv =~ /^\s*\Q$sol_tmp\E/ )) { 108 # Content of SOLARENV starts with the content of SOL_TMP: Local environment 109 $local_env = 1; 110 } 111} 112 113sub get_deliver_lists 114# find deliver log files on solver 115{ 116 my @files; 117 my $pattern = "$solverdir/$platform/inc"; 118 $pattern .= "$milestoneext" if ( $milestoneext ); 119 $pattern .= "/*/deliver.log"; 120 121 @files = glob( $pattern ); 122 # do not check modules not yet built 123 foreach my $exceptionpattern ( @exceptionmodlist ) { 124 @files = grep ! /\/$exceptionpattern\//, @files; 125 } 126 if ( ! @files ) { 127 print_logged( "Error: cannot find deliver log files\n" ); 128 exit 1; 129 } 130 return \@files; 131} 132 133sub check 134# reads deliver log file given as parameter and compares pairs of files listed there. 135{ 136 my $listname = shift; 137 my $error = 0; 138 my %delivered; 139 my $module; 140 my $repository; 141 STDOUT->autoflush(1); 142 # which module are we checking? 143 if ( $listname =~ /\/([\w-]+?)\/deliver\.log$/o) { 144 $module = $1; 145 } else { 146 print_logged( "Error: cannot determine module name from \'$listname\'\n" ); 147 return 1; 148 } 149 150 if ( -z $listname ) { 151 print_logged( "Warning: empty deliver log file \'$listname\'. Module '$module' not delivered correctly?\n\n" ); 152 return 0; 153 } 154 155 # read deliver log file 156 if ( ! open( DELIVERLOG, "< $listname" ) ) { 157 print_logged( "Error: cannot open file \'$listname\'\n$!" ); 158 exit 2; 159 } 160 while ( <DELIVERLOG> ) { 161 next if ( /^LINK / ); 162 # What's this modules' repository? 163 if ( /COPY\s+(.+?)\/$module\/prj\/build.lst/ ) { 164# if ( /COPY (\w[\w\s-]*?)\/$module\/prj\/build.lst/ ) { 165 $repository = $1; 166 } 167 # For now we concentrate on binaries, located in 'bin' or 'lib' and 'misc/build/<...>/[bin|lib]'. 168 next if ( (! /\/$module\/$platform\/[bl]i[nb]\//) && (! /\/$module\/$platform\/misc\/build\//)); 169 next if (! /[bl]i[nb]/); 170 next if ( /\.html$/ ); 171 chomp; 172 if ( /^\w+? (\S+) (\S+)\s*$/o ) { 173 my $origin = $1; 174 $delivered{$origin} = $2; 175 } else { 176 print_logged( "Warning: cannot parse \'$listname\' line\n\'$_\'\n" ); 177 } 178 } 179 close( DELIVERLOG ); 180 181 if ( ! $repository ) { 182 print_logged( "Error parsing \'$listname\': cannot determine repository. Module '$module' not delivered correctly?\n\n" ); 183 $error ++; 184 return $error; 185 } 186 187 my $path = "$srcrootdir/$repository/$module"; 188 # is module physically accessible? 189 # there are valid use cases where we build against a prebuild solver without having 190 # all modules at disk 191 my $canread = is_moduledirectory( $path ); 192 if ( ! $canread ) { 193 # do not bother about non existing modules in local environment 194 # or on childworkspaces 195 if (( $local_env ) || ( $ENV{CWS_WORK_STAMP} )) { 196 return $error; 197 } 198 # in a master build it is considered an error to have deliver leftovers 199 # from non existing (removed) modules 200 print_logged( "Error: module '$module' not found.\n" ); 201 $error++; 202 return $error; 203 } 204 if ( $canread == 2 ) { 205 # module is linked and not built, no need for checking 206 # should not happen any more nowadays ... 207 return $error; 208 } 209 210 # compare all delivered files with their origin 211 # no strict 'diff' allowed here, as deliver may alter files (hedabu, strip, ...) 212 foreach my $file ( sort keys %delivered ) { 213 my $ofile = "$srcrootdir/$file"; 214 my $sfile = "$solverdir/$delivered{$file}"; 215 if ( $milestoneext ) { 216 # deliver log files do not contain milestone extension on solver 217 $sfile =~ s/\/$platform\/(...)\//\/$platform\/$1$milestoneext\//; 218 } 219 my $orgfile_stats = stat($ofile); 220 next if ( -d _ ); # compare files, not directories 221 my $delivered_stats = lstat($sfile); 222 next if ( -d _ ); # compare files, not directories 223 if ( $^O !~ /^MSWin/ ) { 224 # Windows does not know about links. 225 # Therefore lstat() is not a lstat, and the following check would break 226 next if ( -l _ ); # compare files, not links 227 } 228 229 if ( $orgfile_stats && $delivered_stats ) { 230 # Stripping (on unix like platforms) and signing (for Windows) 231 # changes file size. Therefore we have to compare for file dates. 232 # File modification time also can change after deliver, f.e. by 233 # rebasing, but only increase. It must not happen that a file on 234 # solver is older than its source. 235 if ( ( $orgfile_stats->mtime - $delivered_stats->mtime ) gt 1 ) { 236 print_logged( "Error: " ); 237 print_logged( "delivered file is older than its source '$ofile' '$sfile'\n" ); 238 $error ++; 239 } 240 } elsif ( !$orgfile_stats && $delivered_stats ) { 241 # This is not an error if we have a solver and did not build the 242 # module! 243 } elsif ( !$orgfile_stats && !$delivered_stats ) { 244 # This is not necessarily an error. 245 # Instead, this seems to be an error of the deliver.log file. 246 } else { 247 print_logged( "Error: no such file '$ofile'\n" ) if ( ! $orgfile_stats ); 248 print_logged( "Error: no such file '$sfile'\n" ) if ( ! $delivered_stats ); 249 $error ++; 250 } 251 } 252 if ( $error ) { 253 print_logged( "$error errors found: Module '$module' not delivered correctly?\n\n" ); 254 } 255 STDOUT->autoflush(0); 256 return $error; 257} 258 259sub is_moduledirectory 260# Test whether we find a module having a d.lst file at a given path. 261# Return value: 1: path is valid directory 262# 2: path.link is a valid link 263# 0: module not found 264{ 265 my $dirname = shift; 266 if ( -e "$dirname/prj/d.lst" ) { 267 return 1; 268 } elsif ( -e "$dirname.link/prj/d.lst" ) { 269 return 2 270 } else { 271 return 0; 272 } 273} 274 275sub print_logged 276# Print routine. 277# If a log file name is specified with '-l' option, print_logged() prints to that file 278# as well as to STDOUT. If '-l' option is not set, print_logged() just writes to STDOUT 279{ 280 my $message = shift; 281 print "$message"; 282 if ( $logfile ) { 283 open ( LOGFILE, ">> $logfile" ) or die "Can't open logfile '$logfile'\n"; 284 print LOGFILE "$message"; 285 close ( LOGFILE) ; 286 } 287} 288 289 290sub usage 291# print usage message and exit 292{ 293 my $retval = shift; 294 print STDERR "Usage: checkdeliver.pl [-h] [-p <platform>]\n"; 295 print STDERR "Compares delivered files on solver with original ones in build tree\n"; 296 print STDERR "Options:\n"; 297 print STDERR " -h print this usage message\n"; 298 print STDERR " -p platform specify platform\n"; 299 300 exit $retval; 301} 302