build/tools/check_path_lenghts.pl
branchRCL_3
changeset 18 ea3e26ea6629
parent 6 c8ecf89eb77f
equal deleted inserted replaced
6:c8ecf89eb77f 18:ea3e26ea6629
     1 #
       
     2 # Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:  See the usage-method below.
       
    15 #
       
    16 use File::Find;
       
    17 use File::Spec;
       
    18 use Getopt::Long;
       
    19 use strict;
       
    20 
       
    21 
       
    22 # the 140 has not yet been officially defined. (7.7.2006)
       
    23 my $limit = 140;
       
    24 my $isFirstError = 1;
       
    25 my @dirList;
       
    26 my $resultFile = undef;
       
    27 
       
    28 
       
    29 my $errString = qq(
       
    30 The following filenames with path are longer than the allowed length,
       
    31 which is $limit characters.
       
    32 
       
    33 );
       
    34 
       
    35 
       
    36 ###########################################################################
       
    37 ###########################################################################
       
    38 sub usage
       
    39 {
       
    40     print "---------------------------------------------\n";
       
    41     print "THIS SCRIPT IS STILL UNDER EVALUATION. SOME INFORMATION\n";
       
    42     print "GIVEN IN THIS HELP HAS NOT YET BEEN AGREED ON\n";
       
    43     print "---------------------------------------------\n";
       
    44     print "\n";
       
    45     print "This script is intended to check the architectural domain (ADO)\n";
       
    46     print "directory hierarchy content in S60-build\n";
       
    47     print "It checks that the maximum path length does not exceed\n";
       
    48     print "the limitations specified for ADO structure.\n";
       
    49     print "All file names are listed, which exceed the specified limitation.\n";
       
    50     print "\n";
       
    51     print "Usage:\n";
       
    52     print "  $0 [-h|-help] [-t <theResultFilename>] -d <dir1> -d <dir2> \n";
       
    53     print "\n";
       
    54     print "Options:\n";
       
    55     print "  -h                  : Show this help\n";
       
    56     print "  -help               : Show this help\n";
       
    57     print "  -t <theFilename>    : The name of the file, where the errors are written.\n";
       
    58     print "                        If not specified errors are written to STDOUT\n";
       
    59     print "  -d <dir1>           : Absoluth path to the ADOs directory. The last item in the dir\n";
       
    60     print "                        should be the ADO name.\n";
       
    61     print "\n";
       
    62     print "Return values:\n";
       
    63     print "    0 : no errors found (or help wanted)\n";
       
    64     print "   -1 : errors found in check\n";
       
    65     print "   -2 : erronous command line parameters or in result file opening\n";
       
    66     print "\n";
       
    67     print "Usage example:\n";
       
    68     print "   in the below example replace \"<myadoname>\" with real ado name\n";
       
    69     print "   for example  <myadoname> == messaging\n";
       
    70     print "   perl $0 -t \my_path_results.txt -d \s60\app\<myadoname>\n";
       
    71     print "\n";
       
    72     print "Limitations:\n";
       
    73     print "  - No spaces allowed in the file or directory names !!!\n";
       
    74     print "\n";
       
    75 }
       
    76 
       
    77 ###########################################################################
       
    78 ###########################################################################
       
    79 sub errorUsage
       
    80 {
       
    81     usage;
       
    82     exit(-2);
       
    83 }
       
    84 ###########################################################################
       
    85 ###########################################################################
       
    86 sub okUsage
       
    87 {
       
    88     usage;
       
    89     exit(0);
       
    90 }
       
    91 
       
    92 ###########################################################################
       
    93 # Parses the command line parameters from ARGV
       
    94 #
       
    95 # Params: -
       
    96 #
       
    97 # Return: -		    
       
    98 #
       
    99 ###########################################################################
       
   100 sub parseCmdLine
       
   101 {
       
   102     my $incorrectParam = 0;
       
   103     
       
   104     if( ! GetOptions('t=s'      => \$resultFile,
       
   105 		     'd=s'      => \@dirList,
       
   106 		     'h'        => \&okUsage,
       
   107 		     'help'     => \&okUsage,
       
   108 		     '<>'       => \&errorUsage))
       
   109     {
       
   110 	exit(-2);
       
   111     }
       
   112 
       
   113     if(scalar(@dirList) == 0)
       
   114     {
       
   115 	print STDERR  "\nERROR: At least one directory has to be specified with -d\n";
       
   116 	exit(-2);
       
   117     }
       
   118 
       
   119     foreach  (@dirList)
       
   120     {
       
   121 	if(/\s+/)
       
   122 	{
       
   123 	    print STDERR "\nERROR: No spaces allowed in directory names\n";
       
   124 	    exit(-2);
       
   125 	}
       
   126     }
       
   127 }
       
   128 
       
   129 sub handleFileopenError
       
   130 {
       
   131     print STDERR  "\nERROR: Unable to open  $resultFile\n";
       
   132     exit(-2);
       
   133 }
       
   134 
       
   135 parseCmdLine;
       
   136 if(defined($resultFile))
       
   137 {
       
   138     open(FILEOUT,">$resultFile") || handleFileopenError;
       
   139 }
       
   140 
       
   141 ###########################################################################
       
   142 # print results
       
   143 ###########################################################################
       
   144 sub printError
       
   145 {
       
   146 
       
   147     if(defined($resultFile))
       
   148     {
       
   149 	if($isFirstError > 0)
       
   150 	{
       
   151 	    $isFirstError = 0;
       
   152 	    print FILEOUT $errString;
       
   153 	}
       
   154 	print FILEOUT join("",@_);;
       
   155     }
       
   156     else
       
   157     {
       
   158 	if($isFirstError > 0)
       
   159 	{
       
   160 	    $isFirstError = 0;
       
   161 	    print STDOUT $errString;
       
   162 	}
       
   163 	print STDOUT join("",@_);
       
   164     }
       
   165 }
       
   166 
       
   167 ###########################################
       
   168 # Conversion routine. 
       
   169 #  - makes all dir separators to be "/"
       
   170 #  - removes any drive letter from beginig of path
       
   171 #########################################
       
   172 sub convertPath
       
   173 {
       
   174     my $path = shift;
       
   175     $path =~ s/\\/\//g;
       
   176     $path =~ s/^[A-Za-z]\://;
       
   177     
       
   178     return $path;
       
   179 }
       
   180 
       
   181 ###########################################
       
   182 # This function is called for each file by 
       
   183 # the "find" functionality.
       
   184 ###########################################
       
   185 my $currentlyHandling = "";
       
   186 my $first = 1;
       
   187 my $currentReplacement = "";
       
   188 sub handleFile
       
   189 {
       
   190     my $file = $_;
       
   191     my $fileDir = convertPath(File::Spec->catfile(File::Spec->splitdir($File::Find::dir)));
       
   192     if($fileDir !~ /^$currentlyHandling/i ||  $first == 1)
       
   193     {
       
   194 	$first = 0;
       
   195       	$currentlyHandling = $fileDir;
       
   196     	my @items = File::Spec->splitdir($fileDir);
       
   197   	pop @items;
       
   198 	$currentReplacement =  convertPath(File::Spec->catfile(@items));
       
   199 	$currentReplacement .= "/";
       
   200     }
       
   201 
       
   202     my $total = convertPath($File::Find::name);
       
   203 
       
   204     $total =~ s/^$currentReplacement//g;
       
   205     
       
   206     if(length($total) > $limit)
       
   207     {
       
   208 	printError "$total : " . length($total),"\n";
       
   209     }
       
   210 
       
   211 }
       
   212 
       
   213 
       
   214 # Gets the list of header files into the @filenames
       
   215 find(\&handleFile,@dirList);
       
   216 
       
   217 
       
   218 if(defined($resultFile))
       
   219 {
       
   220     close FILEOUT;
       
   221 }