bldsystemtools/sysdeftools/validate/checklinks.pl
changeset 0 83f4b4db085c
child 2 99082257a271
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Script to validate the unit links in a system definition or package definition XML file
       
    15 
       
    16 use strict;
       
    17 
       
    18 if (! scalar @ARGV) {&help()}
       
    19 
       
    20 
       
    21 my $debug = 0;
       
    22 my $skipfilter;	# skip anything with a named filter
       
    23 my $xslt = "../../../buildtools/bldsystemtools/buildsystemtools/joinsysdef.xsl";
       
    24 my $xalan = "../../../buildtools/devlib/devlibhelp/tools/doc_tree/lib/apache/xalan.jar";
       
    25 my $sysdef = shift;
       
    26 while($sysdef=~/^-/) { #arguments
       
    27 	 if($sysdef eq '-nofilter') {$skipfilter = shift}
       
    28 	 elsif($sysdef eq '-v') {$debug = 1}
       
    29 	 else { &help("Invalid command line option $sysdef")} 
       
    30 	 $sysdef = shift; 
       
    31 }
       
    32 my $dir = $sysdef;
       
    33 $dir =~ s,[^\\/]+$,,;
       
    34 my $root="../../../..";
       
    35  my $full;
       
    36  
       
    37 if($sysdef=~/system_definition\.xml/) {	# if running on a sysdef, ensure it's joined before continuing
       
    38 	($full = `java -jar $dir$xalan -in $sysdef -xsl $dir$xslt`) || die "bad XML syntax";
       
    39 }else {	# assume any other file has no hrefs to include (valid by convention)
       
    40 	$root='';
       
    41 	open S, $sysdef;
       
    42 	$full=join('',<S>);
       
    43 	close S;
       
    44 }
       
    45 $full=~s/<!--.*?-->//sg; # remove all comments;
       
    46 my $count=1;
       
    47 
       
    48 my $filter = '';
       
    49 foreach (split(/</,$full)) {	# loop through all elements
       
    50 	my $found = 0;
       
    51 	if(/^component/) {		# save the current filter so we know if we need to skip the named filter
       
    52 		$filter='';
       
    53 		if(/filter="([^"]+)"/) {$filter=$1}
       
    54 	}
       
    55 	elsif(s/^unit//) {
       
    56 		my $f=",$filter,";		# commas are the separators - safe to have extra ones for testing
       
    57 		if(/filter="([^"]+)"/) {$f.=",$1,"}
       
    58 		if($skipfilter ne '' && $f=~/,$filter,/) {next}	# don't test anything with s60 filter
       
    59 		if(/\smrp="(.*?)"/) {
       
    60 			my $file = &fileLocation($1);
       
    61 			if($debug) {print "MRP ",-s $file," $file\n"}		# debug code		
       
    62 			if(!(-s $file)){
       
    63 				print  STDERR "$count: Cannot find MRP file $file\n";	
       
    64 				$found=1;
       
    65 			}
       
    66 		}
       
    67 		if(/\sbldFile="(.*?)"/) {
       
    68 			my $file = &fileLocation("$1/bld.inf");
       
    69 			if($debug) {print "Bld ",-s $file ," $file\n"}		# debug code		
       
    70 			if(!(-s $file) ){
       
    71 				print  STDERR "$count: Cannot find bld.inf file $file\n";
       
    72 				$found=1;
       
    73 			}
       
    74 		}
       
    75 		if(/\sbase="(.*?)"/) {
       
    76 			my $file = &fileLocation($1);
       
    77 			if($debug) {print "Base $file\n"}		# debug code		
       
    78 			if(!(-d $file) ){
       
    79 				print  STDERR "$count: Cannot find base dir $file\n";
       
    80 				$found=1;
       
    81 			}
       
    82 		}
       
    83 	}	
       
    84 	$count+=$found;	
       
    85 }
       
    86 
       
    87 exit $count;
       
    88 
       
    89 sub fileLocation {
       
    90 	my $file = "$dir$root$_[0]";
       
    91 	$file=~tr/\//\\/;
       
    92 	while($file=~s/\\[^\\.]+\\\.\.\\/\\/){}
       
    93 	return $file;
       
    94 }
       
    95 sub help {
       
    96 	print "$0: ",($_[0] eq '' ? "syntax"  : $_[0]); 
       
    97 	print "\nSyntax: [-v] [-nofilter filter] system_definition.xml 
       
    98 Validate the unit links in a system definition or package definition XML
       
    99 file. This only prints errors in the files. If it exits silently, the links
       
   100 are all valid.
       
   101 	Call with -nos60 filter to skip checking presence of fitler=\"s60\" units
       
   102 	Requires system definition files to be in the standard location
       
   103 	in deviceplatformrelease,
       
   104 	and the presence of joinsysdef.xsl and xalan.jar in their expected
       
   105 	locations.
       
   106 	Package definition files can be anywhere.";
       
   107 exit 1;
       
   108 }