blob: 5a1c31a5bd8c1a08416d86c1750fd7999f53d278 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#!/usr/bin/perl
2#
3# Copyright Statement:
4# --------------------
5# This software is protected by Copyright and the information contained
6# herein is confidential. The software may not be copied and the information
7# contained herein may not be used or disclosed except with the written
8# permission of MediaTek Inc. (C) 2005
9#
10# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
11# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
12# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
13# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
16# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
17# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
18# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
19# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
20# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
21# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
22#
23# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
24# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
25# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
26# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
27# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
28#
29# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
30# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
31# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
32# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
33# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
34#
35#
36#*****************************************************************************
37#
38# Filename:
39# ---------
40# mmi_res_check.pl
41#
42# Description:
43# ------------
44# this script is used to do mmi resource check.
45#
46# Auther:
47# -------
48# Shinn Lin
49#
50# Note:
51# -----
52# none.
53#
54# Log:
55# -----
56# 2010/02/09 Create.
57#
58
59BEGIN { push @INC, "pcore/" , 'pcore\\tools\\', '.\\'} # add additional library path
60#package XXX;
61use strict;
62use File::stat;
63use IO::Handle;
64use MauiInfo;
65
66use DataManipulation; # for debug usage
67
68#******************************************************************************
69# Global Data
70#******************************************************************************
71my $f_useTempRes = 1;
72my $f_stdOutToLog = 1;
73my $f_parseIncludeInc = 0;
74my $f_onlyGenDefaultMacro = 1; # only gen for @defaultIncList
75my $f_onlyParseMemoryRes = 1; # only parse xml w/ <MEMORY/> tag
76
77my $resRangeDefPath = "plutommi\\mmi\\inc";
78my $resRangeDefFile = "mmi_res_range_def.h";
79my $mcuPath = ".";
80my $prjName = "";
81
82my $outputPath = "";
83my $logFilename = "";
84
85my $compiler = "armcc";
86my $viaOption = "--via";
87
88my @defaultIncList = ("GlobalConstants.h", "lcd_sw_inc.h");
89
90my %resHash = ();
91my %incHash = (); # hash for all inc
92
93my $idx_dir = 0; # %resHash index for res file dir
94my $idx_inc = 1; # %resHash index for inc files used in that res file
95
96my $totalExecuteTime = 0;
97
98#******************************************************************************
99# Export Function
100#******************************************************************************
101
102#******************************************************************************
103# Internal Data
104#******************************************************************************
105my $oriStdout;
106
107#******************************************************************************
108# Program Start
109#******************************************************************************
110
111#die getHelp() if (@ARGV == 0);
112
113($outputPath) = @ARGV;
114
115$prjName = &getPrjName();
116
117$outputPath = ".\\build\\$prjName\\xml\\macro" if ($outputPath eq "");
118$logFilename = ".\\build\\$prjName\\log\\mmi_res_check.log";
119
120print "\n[mmi_res_check.pl] start ...\n\n";
121# redirect output to log file
122if ($f_stdOutToLog)
123{
124 open($oriStdout, ">&STDOUT"); # save original STDOUT
125 open(STDOUT, ">$logFilename") or die "can't open $logFilename\n";
126}
127
128# 1st time stamp
129$totalExecuteTime += &DataManipulation::timeCheck();
130
131&MauiInfo::setInfo($mcuPath, $prjName);
132&MauiInfo::setIncMods(qw{"plutommi" "venusmmi"});
133
134# prepare output path
135system("mkdir $outputPath") if (!(-e $outputPath));
136
137# get all res files
138&getResFileList("$mcuPath\\$resRangeDefPath\\$resRangeDefFile") if (!$f_onlyGenDefaultMacro);
139
140# get inc path for default inc files
141foreach my $inc (@defaultIncList)
142{
143 $inc = lc $inc;
144 my $path = lc &MauiInfo::getIncPath($inc);
145 if (!(defined $incHash{"$path\\$inc"}))
146 {
147 $incHash{"$path\\$inc"} = 1;
148 }
149}
150$totalExecuteTime += &DataManipulation::timeCheck("", "\t(get default inc path)");
151
152# get inc for all res files
153if (!$f_onlyGenDefaultMacro)
154{
155 # getResInc will only keep res file w/ <MEMORY/> tag
156 &getResInc(\%resHash, \%incHash);
157 $totalExecuteTime += &DataManipulation::timeCheck("", "\t(getResInc\(\))");
158}
159
160# skip mmi_features.h
161my $skipFile = lc &MauiInfo::getIncPath("mmi_features.h")."\\mmi_features.h";
162delete $incHash{$skipFile};
163
164# time diff.
165$totalExecuteTime += &DataManipulation::timeCheck("", "\t(mmi_res_check pre-processing)");
166
167foreach my $inc (keys %incHash)
168{
169 # TODO: if we wanna check timestamp to see whether re-gen log or not,
170 # we should check its .res and all *.h dependencies
171
172 system("perl $mcuPath\\pcore\\tools\\mmi_feature_check.pl $prjName $compiler $viaOption $inc $inc FALSE 0 $outputPath");
173
174 # time diff.
175 $totalExecuteTime += &DataManipulation::timeCheck("", "\t(".&splitPathName($inc).")");
176}
177
178#&DataManipulation::printObject(\%resHash);
179
180if (!$f_onlyGenDefaultMacro)
181{
182 foreach my $file (keys %resHash)
183 {
184 my $resFile = $resHash{$file}[$idx_dir]."\\".$file;
185 #print "resFile : ".$resFile."\n";
186 system("pcore\\tools\\python25\\python.exe pcore\\tools\\py\\prexml.py $resFile $resFile");
187 }
188 $totalExecuteTime += &DataManipulation::timeCheck("", "\t(prexml for <MEMORY/> tag)");
189}
190
191print "\n[Time: total = $totalExecuteTime sec.]\n";
192if ($f_stdOutToLog)
193{
194 close(STDOUT);
195 open(STDOUT, ">&", $oriStdout); # restore STDOUT
196}
197
198print "\n[mmi_res_check.pl] end (execution time: $totalExecuteTime sec., see mmi_res_check.log for detail)\n";
199
200exit 0;
201
202#******************************************************************************
203# Internal Function
204#******************************************************************************
205
206#******************************************************************************
207# FUNCTION
208# getMacroPreprocessResult
209# DESCRIPTION
210# xxx
211# PARAMETERS
212# xxx
213# RETURNS
214# none
215#******************************************************************************
216
217sub getPrjName()
218{
219 my $prjName = "";
220 if ((defined $ENV{"CUSTOMER"}) && ($ENV{"CUSTOMER"} ne "PLUTO"))
221 {
222 $prjName = $ENV{"CUSTOMER"};
223 }
224 elsif (-e "make.ini")
225 {
226 open (hFile, "<make.ini") or die "can't open make.ini\n";
227 if (join('', <hFile>) =~ /\n\s*custom\s+\=\s+([\w]+)\n/i)
228 {
229 $prjName = $1;
230 }
231 close(hFile);
232 }
233 return $prjName;
234}
235
236sub getResInc()
237{
238 my ($resHash_ref, $incHash_ref) = @_;
239
240 foreach my $file (keys(%{$resHash_ref}))
241 {
242 my $dir = ${$resHash_ref}{$file}[$idx_dir];
243
244 print "==> $file\n";
245
246 open(hFile, "<$dir\\$file") or die "can't open $dir\\$file!\n";
247 my $fileDataStr = join('', <hFile>);
248 close(hFile);
249
250 # only keep res file w/ <MEMORY/> tag
251 if ($f_onlyParseMemoryRes && ($fileDataStr !~ /\s+<MEMORY\s+/i))
252 {
253 delete ${$resHash_ref}{$file};
254 next;
255 }
256
257 while ($fileDataStr =~ /<INCLUDE4XML\s+file\s*\=\s*([\"\'])([^\1]+?)\1\s*\/>/g)
258 #while ($fileDataStr =~ /<INCLUDE\s+file\s*\=\s*([\"\'])([^\1]+?)\1\s*\/>/g)
259 {
260 my @incFiles = split(',', lc $2);
261 foreach my $incFile (@incFiles)
262 {
263 my $incPath = "";
264 ${$resHash_ref}{$file}[$idx_inc]{$incFile} = "";
265 if ($incFile =~ /\\/)
266 {
267 ${$incHash_ref}{$incFile} = 1 if ($incHash_ref);
268 }
269 else
270 {
271 $incPath = lc &MauiInfo::getIncPath($incFile);
272 ${$incHash_ref}{$incPath."\\".$incFile} = 1 if ($incHash_ref);
273 }
274 print "\t\t$incFile\t($incPath)\n";
275 }
276 }
277
278 if ($f_parseIncludeInc)
279 {
280 while ($fileDataStr =~ /(^|\n)\#include\s+\"([^\"]+)\"/g)
281 {
282 my $incFile = lc &trim($2);
283 my $incPath = "";
284 ${$resHash_ref}{$file}[$idx_inc]{$incFile} = "";
285 if ($incFile =~ /\\/)
286 {
287 ${$incHash_ref}{$incFile} = 1 if ($incHash_ref);
288 }
289 else
290 {
291 $incPath = lc &MauiInfo::getIncPath($incFile);
292 ${$incHash_ref}{$incPath."\\".$incFile} = 1 if ($incHash_ref);
293 }
294 print "\t\t$incFile\t($incPath)\n";
295 }
296 }
297 }
298}
299
300
301sub getResFileList()
302{
303 my ($defFilename) = @_;
304
305 my $pathListStr;
306
307 if (!$f_useTempRes)
308 {
309 open(hFile, "<$defFilename") or die "can't open $defFilename!\n";
310 my @fileData = <hFile>;
311 close(hFile);
312
313 my @pathList = ();
314
315 foreach my $line (@fileData)
316 {
317 if ($line =~ /^\s*RESOURCE_BASE_TABLE_ITEM_PATH\s*\([\w]+\s*,\s*\"([^\"]+)\"\s*\)/)
318 {
319 my $path = &trim($1);
320 $path =~ s/\\\\/\\/g;
321 push @pathList, "$mcuPath\\plutommi\\".$path."\\*.res";
322 }
323 }
324 $pathListStr = join(' ', @pathList);
325 }
326 else
327 {
328 $pathListStr = "$mcuPath\\plutommi\\Customer\\ResGenerator\\temp\\res\\*.c";
329 }
330 print "\$pathListStr = ".$pathListStr."\n";
331
332 my @list = ();
333 &getFileList($pathListStr, \@list);
334
335 foreach my $pathName (@list)
336 {
337 my $dir;
338 my $file = splitPathName($pathName, \$dir);
339 $resHash{$file}[$idx_dir] = $dir;
340 }
341}
342
343
344#******************************************************************************
345# FUNCTION
346# getFileList
347# DESCRIPTION
348# get file/path list for given search string
349# PARAMETERS
350# xxx
351# RETURNS
352# xxx
353#******************************************************************************
354sub getFileList()
355{
356 my $dirStr;
357 my $fileList_ref;
358
359 ($dirStr, $fileList_ref) = @_;
360
361 my @fileData = ();
362
363 # get file list
364 my $tmpFilename = "~tmpFile.lst";
365
366 system("dir ".$dirStr." > $tmpFilename");
367 open(hFile, "<$tmpFilename") or die "[ERROR] can't open $tmpFilename\n";
368 @fileData = <hFile>;
369 close(hFile);
370 system("del $tmpFilename");
371
372 my $currDir = "";
373 foreach my $line (@fileData)
374 {
375 if ($line =~ /^[\s]*Directory of[\s]+([^\n]+)/i)
376 {
377 $currDir = $1;
378 #print "[dir] $currDir\n";
379 }
380 elsif ($line =~ /[\s]+File\(s\)[\s]+/)
381 {
382 $currDir = "";
383 }
384 elsif ($currDir ne "")
385 {
386 # [time] [size] [filename] <= dir result
387 if ($line =~ /\d\d:\d\d[\s]+([\d,]+)[\s]+([^\n]+)/)
388 {
389 my $size = $1;
390 my $name = $2;
391 #print "[size] $size\t[name] $name\n";
392 push @{$fileList_ref}, "$currDir\\$name";
393 }
394 }
395 }
396 return scalar(@{$fileList_ref});
397}
398
399sub trim()
400{
401 my ($str) = @_;
402 $str =~ s/(^\s*)|(\s*$)//g;
403 return $str;
404}
405
406
407#******************************************************************************
408# FUNCTION
409# splitPathName
410# DESCRIPTION
411# split given filename to filename and path
412# PARAMETERS
413# $filename [IN] - filename
414# $refSubFilename [OUT] - reference to path, may be NULL
415# RETURNS
416# filename
417#******************************************************************************
418sub splitPathName()
419{
420 my $pathname;
421 my $path_ref;
422
423 ($pathname, $path_ref) = @_;
424
425 if ($pathname =~ /(^.*)[\\\/]([^\\\/]+$)/)
426 {
427 #print "path [$1] filename[$2]\n";
428 $$path_ref = $1 if ($path_ref != 0);
429 return $2;
430 }
431 else
432 {
433 $$path_ref = '.' if ($path_ref != 0); # current dir
434 return $pathname;
435 }
436}
437
438
439sub getHelp()
440{
441 my $help = << "__HELP";
442
443Usage: mmi_res_check.pl <output path>
444__HELP
445 return $help;
446}
447
448
449#******************************************************************************
450# FUNCTION
451# splitFilename
452# DESCRIPTION
453# split given filename to main and sub
454# PARAMETERS
455# $filename [IN] - filename
456# $refSubFilename [OUT] - reference to sub filename, may be NULL
457# RETURNS
458# main filename
459#******************************************************************************
460sub splitFilename()
461{
462 my $filename;
463 my $refSubFilename = "";
464 my $mainFilename = "";
465
466 ($filename, $refSubFilename) = @_;
467
468 if ($filename =~ /([^\s]*)(\.)([^\.]*$)/)
469 {
470 #print "$filename [$1][$3]\n";
471 $mainFilename = "$1";
472 $$refSubFilename = "$3" if ($refSubFilename != 0);
473 }
474 return $mainFilename;
475}