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 |
|
17 use File::Find; |
|
18 use File::Spec; |
|
19 use Getopt::Long; |
|
20 use strict; |
|
21 |
|
22 my $isFirstError = 1; |
|
23 my @dirList; |
|
24 my $resultFile = undef; |
|
25 my %extHash; # hash which contains the wanted extensions as keys |
|
26 |
|
27 my $errString = qq( |
|
28 The following filenames are not unique inside ADO. Note that if those |
|
29 files are not part of compilation (listed in used bld.inf) => there |
|
30 are no immediate problems. |
|
31 |
|
32 ); |
|
33 |
|
34 |
|
35 ########################################### |
|
36 # Conversion routine. |
|
37 # - makes all dir separators to be "/" |
|
38 # - removes any drive letter from beginig of path |
|
39 ######################################### |
|
40 sub convertPath |
|
41 { |
|
42 my $path = shift; |
|
43 $path =~ s/\\/\//g; |
|
44 $path =~ s/^[A-Za-z]\://; |
|
45 $path =~ tr/A-Z/a-z/; |
|
46 |
|
47 return $path; |
|
48 } |
|
49 |
|
50 ########################################################################### |
|
51 ########################################################################### |
|
52 sub usage |
|
53 { |
|
54 print "\n"; |
|
55 print "This script is intended to check the architectural domain (ADO)\n"; |
|
56 print "directory hierarchy content in S60-build.\n"; |
|
57 print "It checks that the filenames with given extensions\n"; |
|
58 print "are uniq inside the give ADO structure.\n"; |
|
59 print "\n"; |
|
60 print "Usage:\n"; |
|
61 print " $0 [-h|-help] [-t <theResultFilename>] [-e ext1 -e ext2] -d <dir1> -d <dir2> \n"; |
|
62 print "\n"; |
|
63 print "Options:\n"; |
|
64 print " -h : Show this help\n"; |
|
65 print " -help : Show this help\n"; |
|
66 print " -t <theFilename> : The name of the file, where the errors are written.\n"; |
|
67 print " If not specified errors are written to STDOUT\n"; |
|
68 print " -d <dir1> : Absoluth path to the ADOs directory. The last item in the dir\n"; |
|
69 print " should be the ADO name.\n"; |
|
70 print " -e <ext1> : file extensions that are checked.\n"; |
|
71 print " If none given, then default value is \"-e mmp,mk\". \n"; |
|
72 print " If one is specified then the default ones are not handled by default.\n"; |
|
73 print "\n"; |
|
74 print "Return values:\n"; |
|
75 print " 0 : no errors found (or help wanted)\n"; |
|
76 print " -1 : errors found in check\n"; |
|
77 print " -2 : erronous command line parameters or in result file opening\n"; |
|
78 print "\n"; |
|
79 print "Usage example:\n"; |
|
80 print " in the below example replace \"<myadoname>\" with real ado name\n"; |
|
81 print " for example <myadoname> == messaging\n"; |
|
82 print " perl $0 -t \my_path_results.txt -d \s60\app\<myadoname>\n"; |
|
83 print "\n"; |
|
84 print " Below one only checks txt-files\n"; |
|
85 print " perl $0 -t \my_path_results.txt -e txt -d \s60\app\<myadoname>\n"; |
|
86 print "\n"; |
|
87 print "Limitations:\n"; |
|
88 print " - No spaces allowed in the file or directory names !!!\n"; |
|
89 print "\n"; |
|
90 } |
|
91 |
|
92 ########################################################################### |
|
93 ########################################################################### |
|
94 sub errorUsage |
|
95 { |
|
96 usage; |
|
97 exit(-2); |
|
98 } |
|
99 ########################################################################### |
|
100 ########################################################################### |
|
101 sub okUsage |
|
102 { |
|
103 usage; |
|
104 exit(0); |
|
105 } |
|
106 |
|
107 ########################################################################### |
|
108 # print results |
|
109 ########################################################################### |
|
110 sub printError |
|
111 { |
|
112 |
|
113 if(defined($resultFile)) |
|
114 { |
|
115 if($isFirstError > 0) |
|
116 { |
|
117 $isFirstError = 0; |
|
118 print FILEOUT $errString; |
|
119 } |
|
120 print FILEOUT join("",@_);; |
|
121 } |
|
122 else |
|
123 { |
|
124 if($isFirstError > 0) |
|
125 { |
|
126 $isFirstError = 0; |
|
127 print STDOUT $errString; |
|
128 } |
|
129 print STDOUT join("",@_); |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 ########################################################################### |
|
135 # Parses the command line parameters from ARGV |
|
136 # |
|
137 # Params: - |
|
138 # |
|
139 # Return: - |
|
140 # |
|
141 ########################################################################### |
|
142 sub parseCmdLine |
|
143 { |
|
144 my $incorrectParam = 0; |
|
145 my @extList; |
|
146 |
|
147 if( ! GetOptions('t=s' => \$resultFile, |
|
148 'd=s' => \@dirList, |
|
149 'e=s' => \@extList, |
|
150 'h' => \&okUsage, |
|
151 'help' => \&okUsage, |
|
152 '<>' => \&errorUsage)) |
|
153 { |
|
154 exit(-2); |
|
155 } |
|
156 |
|
157 if(scalar(@dirList) == 0) |
|
158 { |
|
159 print STDERR "\nERROR: At least one directory has to be specified with -d\n"; |
|
160 exit(-2); |
|
161 } |
|
162 |
|
163 foreach (@dirList) |
|
164 { |
|
165 if(/\s+/) |
|
166 { |
|
167 print STDERR "\nERROR: No spaces allowed in directory names\n"; |
|
168 exit(-2); |
|
169 } |
|
170 } |
|
171 |
|
172 # if no ext given => use the default values. |
|
173 if(scalar(@extList) == 0) |
|
174 { |
|
175 $extHash{"mmp"} = 1; |
|
176 $extHash{"mk"} = 1; |
|
177 } |
|
178 else |
|
179 { |
|
180 # handle the extensions given |
|
181 foreach my $param (@extList) |
|
182 { |
|
183 my @items = split(",",$param); |
|
184 foreach my $item (@items) |
|
185 { |
|
186 # remove spaces |
|
187 $item =~ s/\s//g; |
|
188 $item = convertPath($item); |
|
189 $extHash{$item} = 1; |
|
190 } |
|
191 } |
|
192 } |
|
193 } |
|
194 |
|
195 ########################################################################### |
|
196 ########################################################################### |
|
197 sub handleFileopenError |
|
198 { |
|
199 print STDERR "\nERROR: Unable to open $resultFile\n"; |
|
200 exit(-2); |
|
201 } |
|
202 |
|
203 |
|
204 ########################################### |
|
205 # This function is called for each file by |
|
206 # the "find" functionality. |
|
207 ########################################### |
|
208 # contains all the erronous file names, details in the |
|
209 # $refToFileHash |
|
210 my $refToErrHash; |
|
211 # content is: |
|
212 # {filenamewithExt => (foundInDir1,foundInDir2)} |
|
213 my $refToFileHash; |
|
214 |
|
215 #actual function |
|
216 sub handleFile |
|
217 { |
|
218 my $file = convertPath($_); |
|
219 my $fileDir = convertPath(File::Spec->catfile(File::Spec->splitdir($File::Find::dir))); |
|
220 |
|
221 # the find seems to change the current dir => checking if the item is a dir |
|
222 # should be done from curr Dir (we need to add the ./ so that the -d (testing if |
|
223 # item is directory works) |
|
224 if( -d "./$file") |
|
225 { |
|
226 return; |
|
227 } |
|
228 |
|
229 # its a file, test wether the extension is what we want |
|
230 my @tmpList = split(/\./,$file); |
|
231 my $ext = pop @tmpList; |
|
232 |
|
233 if(defined($extHash{$ext})) |
|
234 { |
|
235 # is there same name already => if yes => error |
|
236 if(defined($$refToFileHash{$file})) |
|
237 { |
|
238 $$refToErrHash{$file} = 1; |
|
239 } |
|
240 # 1st occurance. Add as new item into the refToFileHash |
|
241 else |
|
242 { |
|
243 my @list; |
|
244 $$refToFileHash{$file} = \@list; |
|
245 } |
|
246 push(@{$$refToFileHash{$file}},$fileDir); |
|
247 } |
|
248 } |
|
249 |
|
250 ########################################################################### |
|
251 # MAIN functionality |
|
252 ########################################################################### |
|
253 parseCmdLine; |
|
254 if(defined($resultFile)) |
|
255 { |
|
256 open(FILEOUT,">$resultFile") || handleFileopenError; |
|
257 } |
|
258 |
|
259 # handle each root dir as separate case. This way |
|
260 # we do not have to worry about stuff between dirs |
|
261 foreach my $dir (@dirList) |
|
262 { |
|
263 my %errFileHash; |
|
264 $refToErrHash = \%errFileHash; |
|
265 my %fileHash; |
|
266 $refToFileHash = \%fileHash; |
|
267 |
|
268 find(\&handleFile,($dir)); |
|
269 |
|
270 # After one base dir has been handled, then print the found |
|
271 # errors related to that one. |
|
272 |
|
273 if(scalar(keys(%errFileHash)) > 0) |
|
274 { |
|
275 printError "\nUnder: $dir\n"; |
|
276 foreach my $errFile (keys (%errFileHash)) |
|
277 { |
|
278 printError " $errFile found in:\n"; |
|
279 foreach my $fileLoc (@{$fileHash{$errFile}}) |
|
280 { |
|
281 printError " $fileLoc\n"; |
|
282 } |
|
283 } |
|
284 } |
|
285 else |
|
286 { |
|
287 printError "\nNo errors found under $dir\n"; |
|
288 } |
|
289 } |
|
290 |
|
291 if(defined($resultFile)) |
|
292 { |
|
293 close FILEOUT; |
|
294 } |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|