blob: d476936dc371041eae738444e9b5762289121804 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001#!/usr/local/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# process argument
37($project, $modem, $flavor) = @ARGV;
38die "Please specify the project name.\n" if ($project eq "");
39die "please specify the modem type.\n" if ($modem eq "");
40
41# get the conf file
42$daily_build_conf_file_path = "\\\\mtkrs12\\Software_Management_Material\\Script\\3rd_party\\Scripts";
43
44#check branch in verno file
45$verno_path = "make\\common";
46$verno_file = $verno_path."\\Verno_".$project.".bld";
47
48if (!-e $verno_file){
49 $verno_file = $verno_path."\\Verno.bld";
50}
51-e $verno_file or die "Verno file does NOT exist!\nPlease check.\n";
52
53# read the verno file
54open FILE, $verno_file;
55foreach $line (<FILE>){
56 if ($line =~ /BRANCH\s*=\s*(\S*)/){
57 $branch = $1;
58 break;
59 }
60}
61
62#get the daily build conf file according to the branch
63$daily_build_conf_file_name = "daily_build_".$branch."_conf.ini";
64$daily_build_conf_file = $daily_build_conf_file_path."\\".$daily_build_conf_file_name;
65
66-e $daily_build_conf_file or die "Config file: $daily_build_conf_file does NOT exist!\nPlease check.\n";
67
68# read the conf file
69open FILE, $daily_build_conf_file;
70
71foreach $line (<FILE>){
72 if ($line =~ /^OF_BUILD_PATH\s*=\s*(\S*)/){
73 $of_build_path = $1;
74 }
75 elsif ($line =~ /^CODE_BASE_WEEK\s*=\s*(\S*)/){
76 $code_base_week = $1;
77 # get the latest version if the week is not specified.
78 if ($code_base_week eq ""){
79 $code_base_week = &getLatestCodebaseWeek();
80 }
81 }
82 elsif ($line =~ /^DEFAULT_PROJECT_GSM\s*=\s*(\S*)/){
83 $default_project_gsm = $1;
84 }
85 elsif ($line =~ /^DEFAULT_PROJECT_GPRS\s*=\s*(\S*)/){
86 $default_project_gprs = $1;
87 }
88 elsif ($line =~ /^DEFAULT_PROJECT_UMTS\s*=\s*(\S*)/){
89 $default_project_umts = $1;
90 }
91 elsif ($line =~ /^DEFAULT_MODEM_GSM\s*=\s*(\S*)/){
92 $default_modem_gsm = $1;
93 }
94 elsif ($line =~ /^DEFAULT_MODEM_GPRS\s*=\s*(\S*)/){
95 $default_modem_gprs = $1;
96 }
97 elsif ($line =~ /^DEFAULT_MODEM_UMTS\s*=\s*(\S*)/){
98 $default_modem_umts = $1;
99 }
100 elsif ($line =~ /^DEFAULT_FLAVOR_GSM\s*=\s*(\S*)/){
101 $default_flavor_gsm = $1;
102 }
103 elsif ($line =~ /^DEFAULT_FLAVOR_GPRS\s*=\s*(\S*)/){
104 $default_flavor_gprs = $1;
105 }
106 elsif ($line =~ /^DEFAULT_FLAVOR_UMTS\s*=\s*(\S*)/){
107 $default_flavor_umts = $1;
108 }
109 elsif ($line =~ /^DEFAULT_STAGE_GSM\s*=\s*(\S*)/){
110 $default_stage_gsm = $1;
111 }
112 elsif ($line =~ /^DEFAULT_STAGE_GPRS\s*=\s*(\S*)/){
113 $default_stage_gprs = $1;
114 }
115 elsif ($line =~ /^DEFAULT_STAGE_UMTS\s*=\s*(\S*)/){
116 $default_stage_umts = $1;
117 }
118}
119
120
121# find the latest codebase in stage0/stage1/stage2 folders
122@stages = qw(Stage0 Stage1 Stage2);
123
124foreach $stage (@stages){
125 if ($flavor eq ""){
126 $codebase_path = $of_build_path ."\\".$code_base_week."_".$stage."\\".$project."_".$modem.".".$code_base_week."\\mcu";
127 }
128 else{
129 $codebase_path = $of_build_path ."\\".$code_base_week."_".$stage."\\".$project."(".$flavor.")_".$modem.".".$code_base_week."\\mcu";
130 }
131 #print "try to find the codebase : $codebase_path\n";
132 if (-d $codebase_path){
133 $codebase_found = 1;
134 print "codebase found: $codebase_path\n";
135 last;
136 }
137}
138
139# can not find the same project in latest official build, using the default project.
140if (!$codebase_found){
141 print "codebase not found, try to find the default project path.\n";
142 if ($modem =~ /gsm/i){
143 $project = $default_project_gsm;
144 $modem = $default_modem_gsm;
145 $flavor = $default_flavor_gsm;
146 $stage = $default_stage_gsm;
147 }
148 elsif ($modem =~ /gprs/i){
149 $project = $default_project_gprs;
150 $modem = $default_modem_gprs;
151 $flavor = $default_flavor_gprs;
152 $stage = $default_stage_gprs;
153 }
154 else{ #UMTS , HSPA
155 $project = $default_project_umts;
156 $modem = $default_modem_umts;
157 $flavor = $default_flavor_umts;
158 $stage = $default_stage_umts;
159 }
160
161 if ($flavor eq ""){
162 $codebase_path = $of_build_path ."\\".$code_base_week."_".$stage."\\".$project."_".$modem.".".$code_base_week."\\mcu";
163 }
164 else{
165 $codebase_path = $of_build_path ."\\".$code_base_week."_".$stage."\\".$project."(".$flavor.")_".$modem.".".$code_base_week."\\mcu";
166 }
167 #print "try to find the the default codebase : $codebase_path\n";
168 die "Can not find default $modem project path at $codebase_path." if (!-d $codebase_path);
169}
170
171
172# find codegen pstrace_db folder
173$codegen_path = "tst";
174@codegen_db_folders = qw(database database_classb database_classb_umts);
175$pstrace_db = "pstrace_db";
176
177foreach $folder (@codegen_db_folders){
178 if (-d $codebase_path."\\".$codegen_path."\\".$folder."\\".$pstrace_db){
179 $pstrace_path = $codebase_path."\\".$codegen_path."\\".$folder."\\".$pstrace_db;
180 $db_folder = $folder;
181 print "pstrace folder : $pstrace_path\n";
182 last;
183 }
184}
185
186die "pstrace folder does NOT exist in $codebase_path\\$codegen_path!\nPlease check.\n" if ($pstrace_path eq "");
187
188
189
190
191# identify local path
192chomp($current_path = `cd`);
193print "GET LOCAL PATH: $current_path\n";
194#$p = Win32::GetCwd();
195
196if ($current_path =~ /(.*)\\mcu(.*)/){
197 $local_root_path = $1."\\mcu";
198}
199#for LSF
200elsif($current_path =~ /E:\\temp\\(MAUI|10A|11A)/){
201 $local_root_path = $current_path;
202}
203
204#delete the log file generated before
205system("del -Q $local_root_path\\copy_latest_codegen.log");
206
207$local_pstrace_path = $local_root_path."\\".$codegen_path."\\".$db_folder."\\".$pstrace_db;
208
209#print "local pstrace path : $local_pstrace_path\n";
210
211# copy pstrace folder if do not have
212if (!-d $local_pstrace_path){
213 $need_to_copy = 1;
214}
215else{
216 opendir (DIR, $local_root_path."\\".$codegen_path."\\".$db_folder);
217 @files = readdir DIR;
218 close DIR;
219
220 $need_to_copy = 1;
221 foreach $file (@files){
222 if ($file =~ /BPLGUInfo(.*)/){
223 $need_to_copy = 0;
224 last;
225 }
226 }
227
228}
229if ($need_to_copy){
230 print ("Copy the latest codegen result.\n");
231 print ("xcopy /E /Y \"$pstrace_path\\\*\" \"$local_pstrace_path\\\*\"\n");
232 system("xcopy /E /Y \"$pstrace_path\\\*\" \"$local_pstrace_path\\\*\" >nul");
233
234 # write a file to identify do the copy latest codegen
235 open FILE, ">$local_root_path\\copy_latest_codegen.log";
236 close FILE;
237}
238else{
239 print ("Do codegen successfully. Do nothing.\n");
240}
241
242
243
244#########################################################################################
245
246sub getLatestCodebaseWeek{
247 #TODO: need to filter out files
248 opendir (DIR, $of_build_path);
249 @folders = reverse sort readdir DIR;
250 close DIR;
251 foreach $folder (@folders){
252 if ($folder =~ /W(\w*)\.(\w*)_(.*)/){
253 $code_base_week = "W".$1.".".$2;
254 last;
255 }
256 }
257 return $code_base_week;
258}