blob: 34cb8a82090b925410fa44393985b6800919e0b7 [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) 2007
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# Filename:
38# ---------
39# operator_check.pl
40#
41# Description:
42# ------------
43# To call operator_feature_check.pl to pre-process operator header files for
44# generating warning messages when customer macros were modified by operator
45# header files.
46#
47# Auther:
48# -------
49# Frank Wu
50#
51# Note:
52# -----
53# none.
54#
55# Log:
56# -----
57# 2007/04/01 Create.
58#
59#use strict;
60use Fcntl;
61use File::Basename;
62
63#Open operator_checklist.txt
64open(optr_check,"$ARGV[2]") || die "Cannot open $ARGV[2]. Error:$!";
65
66my $CUSTOMER = $ARGV[0];
67my $PROJECT = $ARGV[1];
68my $theMF = "make\\$CUSTOMER\_$PROJECT.mak";
69my $CC = "$ARGV[3]";
70my $VIA = "$ARGV[4]";
71my $operator_path = "";
72my $DoCheck = 0;
73my $flag = 0;
74my $operator_macro = "";
75my @logname = ();
76my @macroname = ();
77my $logs = "";
78my $macro = "";
79my @extlist = qw(.log);
80my $base = "";
81my $MMI_switch_path = "";
82my $seg_name = "";
83
84# remove temp file or not
85my $removeTempFile = 1;
86
87open (FILE_HANDLE, "<$theMF") or die "Cannot open $theMF\n";
88while (<FILE_HANDLE>) {
89 if (/^(\S+)\s*=\s*(\S+)/) {
90 my $keyname = lc($1);
91 defined($${keyname});
92 $${keyname} = uc($2);
93 }
94}
95close FILE_HANDLE;
96
97$ARGV[2] =~ /(.+)\\operator_checklist/;
98my $operator_path = $1;
99
100$operator_path =~ /.+\\.+\\(.+?)\\(.+?)\\.+/;
101my $operator_name = uc($1);
102my $spec_version = $2;
103
104if ($optr_spec =~ /.+_TECH/)
105{
106 $optr_spec =~ /.+_.+_(.+)_TECH/;
107 $seg_name = $1;
108}
109else
110{
111 $optr_spec =~ /.+_.+_(.+)/;
112 $seg_name = $1;
113}
114
115if (-e "$operator_path\\operator_check.log"){
116 system("del /F /Q $operator_path\\operator_check.log");
117}
118sysopen(log_file,"$operator_path\\operator_check.log",O_CREAT|O_RDWR|O_APPEND) || die "Error:$!";
119print log_file "[Messages from operator header files]\n";
120while(<optr_check>){
121 if (index($_,"OPERATOR RELATED FILES")>=0 || index($_,"OPERATOR MACRO")>=0){
122 next;
123 }
124 $_ =~ s/{BOARD_VER}/$board_ver/;
125 $_ =~ s/{OpName}/$operator_name/;
126 $_ =~ s/{VerNum}/$spec_version/;
127 $_ =~ s/{SegName}/$seg_name/;
128 $DoCheck = $_ =~ /(.+?)[\s]+(.+?)[\s]+(.+?)[\s]+([\S]+)/;
129 if ($DoCheck){
130 if(index($2,"MMI_features_switch")>=0){
131 $MMI_switch_path = "$1\\$2";
132 } elsif (index($2,"MMI_features.h")>=0) {
133 $MMI_switch_path = "$1\\$2";
134 $MMI_switch_path =~ s/.h/_switch.h/;
135 }
136 my $dummyHeaderFile = splitFilename($3, 0)."_dummy".".h";
137 CreateDummyHeaderFile($3, $dummyHeaderFile, $4, $1, $2, 1);
138 CreateDummyHeaderFile($3, "original_".$dummyHeaderFile, $4, $1, $2, 0);
139 system("perl .\\pcore\\tools\\operator_feature_check.pl $CUSTOMER . $dummyHeaderFile $3 $1 $4 1 $CC $VIA");
140 system("perl .\\pcore\\tools\\operator_feature_check.pl $CUSTOMER . original_$dummyHeaderFile $3 $1 $4 0 $CC $VIA");
141 push @logname, ".\\".splitFilename($3, 0)."_dummy"."_$CUSTOMER".".log";
142 if ($removeTempFile)
143 {
144 system("del /F /Q $4\\*_dummy.h");
145 }
146 } elsif ($_ =~ /([\w]+?)[\s]?/) {
147 $operator_macro = $_;
148 chomp($operator_macro);
149 push @macroname, $operator_macro;
150 }
151}
152close(optr_check);
153
154
155#*******************************************************************
156# Start to parse the log files.
157#*******************************************************************
158
159foreach $logs (@logname){
160 open(read_log,"$logs") || die "Cannot open $logs. Error:$!";
161 $base = basename($logs, @extlist);
162 $base =~ s/_dummy_$CUSTOMER/.h/;
163 while(<read_log>){
164 $line = $_;
165 chomp($line);
166 $line =~ /([\w]+)\'s/;
167 my $macro = $1;
168 my $originalValue = getValue($macro, $base, 0);
169 my $resultValue = getValue($macro, $base, 1);
170
171 if ($originalValue eq ""){
172 $originalValue = "Undefined or NULL";
173 } elsif ($resultValue eq "") {
174 $resultValue = "Undefined or NULL";
175 }
176
177 #To get __ON__, __OFF__ and __DEFAULT__ definitions from MMI_features_switch.h
178 if ($base eq "operator_mmi.h") {
179 open(mmi_switch,"$MMI_switch_path") || die "Cannot open $MMI_switch_path. Error:$!\n";
180 while(<mmi_switch>){
181 $_ =~ /^([\s]*)(#define[\s]+)([\w_]+)([\s]*)(.+)/;
182 if($3 eq "__ON__"){
183 if (index("\($originalValue\)",$5)>=0){
184 $originalValue = "__ON__";
185 } elsif (index("\($resultValue\)",$5)>=0) {
186 $resultValue = "__ON__";
187 }
188 } elsif ($3 eq "__OFF__") {
189 if (index("\($originalValue\)",$5)>=0){
190 $originalValue = "__OFF__";
191 } elsif (index("\($resultValue\)",$5)>=0) {
192 $resultValue = "__OFF__";
193 }
194 } elsif ($3 eq "__DEFAULT__") {
195 if (index("\($originalValue\)",$5)>=0){
196 $originalValue = "__DEFAULT__";
197 } elsif (index("\($resultValue\)",$5)>=0) {
198 $resultValue = "__DEFAULT__";
199 }
200 } elsif ($3 eq "__AUTO__") {
201 if (index("\($originalValue\)",$5)>=0){
202 $originalValue = "__AUTO__";
203 } elsif (index("\($resultValue\)",$5)>=0) {
204 $resultValue = "__AUTO__";
205 }
206 }
207 }
208 close(mmi_switch);
209 }
210
211 print log_file ($line," from \"",$originalValue,"\" to \"",$resultValue,"\" according to"," $operator_name"," Specification Version ","$spec_version"," by File"," \"$base\"",".\n");
212 }
213 close(read_log);
214}
215print log_file "\n";
216close(log_file);
217#*******************************************************************
218#To merge makefile warning messages from make\~warning.tmp
219#*******************************************************************
220if(-e "make\\\~warning.tmp"){
221 system("echo [Messages from operator.mak]>>$operator_path\\operator_check.log");
222 system("type make\\\~warning.tmp >>$operator_path\\operator_check.log");
223}
224
225print "\nPlease check the Operator Log: $operator_path\\operator_check.log\n";
226
227if ($removeTempFile)
228{
229 system("del /F /Q .\\*_dummy_$CUSTOMER.log");
230 system("del /F /Q .\\*_OriginalValue.log");
231 system("del /F /Q .\\*_ResultValue.log");
232}
233
234#*******************************************************************
235sub splitFilename()
236{
237 my $filename;
238 my $refSubFilename = "";
239 my $mainFilename = "";
240
241 ($filename, $refSubFilename) = @_;
242
243 if ($filename =~ /([^\s]*)(\.)([^\.]*$)/)
244 {
245 $mainFilename = "$1";
246 if ($refSubFilename != 0)
247 {
248 $$refSubFilename = "$3";
249 }
250 }
251 return $mainFilename;
252}
253
254sub CreateDummyHeaderFile()
255{
256 my $operatorHeaderFile;
257 my $outputFile = "";
258 my $operatorPath = "";
259 my $filePath = "";
260 my $customerHeaderFile = "";
261 my $IfCreateOpMacro;
262
263 ($operatorHeaderFile, $outputFile, $operatorPath, $filePath, $customerHeaderFile, $IfCreateOpMacro) = @_;
264
265 open(readfile,"$operatorPath\\$operatorHeaderFile") || die "Cannot open $operatorPath\\$operatorHeaderFile. Error:$!";
266 if (-e "$operatorPath\\$outputFile"){
267 system("del $operatorPath\\$outputFile");
268 }
269 sysopen(writefile,"$operatorPath\\$outputFile",O_CREAT|O_RDWR|O_APPEND) || die "Error:$!";
270
271 if ($IfCreateOpMacro){
272 print writefile "#include \"$customerHeaderFile\"";
273 print writefile "\n";
274 while(<readfile>){
275 print writefile $_;
276 }
277 close(writefile);
278 close(readfile);
279 } else {
280 open(readCustH,"$filePath\\$customerHeaderFile") || die "Cannot open $filePath\\$customerHeaderFile. Error:$!";
281 $customerHeaderFile =~ /(.+?)\.h/;
282 my $dummyCustomerHeaderFile = $1."_dummy.h";
283
284 open(writeCustDummyH,">$operatorPath\\$dummyCustomerHeaderFile") || die "Error:$!";
285 while(<readCustH>){
286 if(index($_,"$operatorHeaderFile")>=0){
287 print writeCustDummyH "";
288 } else {
289 print writeCustDummyH $_;
290 }
291 }
292 close(writeCustDummyH);
293 close(readCustH);
294
295 print writefile "#include \"$dummyCustomerHeaderFile\"";
296 print writefile "\n";
297
298 while(<readfile>){
299 if ($_ =~ /^([\s]*)(#define[\s]+)([\w_]+)([\s]*)/){
300 print writefile "//{",$3,"}","\n";
301 }
302 }
303 close(writefile);
304 close(readfile);
305 }
306}
307
308sub getValue() {
309 my $macroN = "";
310 my $OpHeadF = "";
311 my $IfReuslt = "";
312 my $result = "";
313 ($macroN, $OpHeadF, $IfResult) = @_;
314 $OpHeadF =~ /(.+)\./;
315 $OpHeadBase = $1;
316
317 if ($IfResult){
318 open(FH, "$OpHeadBase\_ResultValue.log") || die "Error:$!";
319 while(<FH>){
320 if (index($_, $macroN)==0){
321 $_ =~ /.+=[\s](.+)/;
322 $result = $1;
323 }
324 }
325 close(FH);
326 } else {
327 open(FH, "$OpHeadBase\_OriginalValue.log") || die "Error:$!";
328 while(<FH>){
329 if (index($_, $macroN)==0){
330 $_ =~ /.+=[\s](.+)/;
331 $result = $1;
332 }
333 }
334 close(FH);
335 }
336 return $result;
337}