1 # |
|
2 # Copyright (c) 2009 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: |
|
15 # |
|
16 #!perl -w |
|
17 # |
|
18 # StartBuild.pl |
|
19 # |
|
20 # Script to bootstrap the starting of Daily and Test builds |
|
21 # Uses a config file containing details of which test source is needed. |
|
22 # Performs a delta sync to the baseline changelist number, copies only the |
|
23 # necessary files to clean-src, then syncs down any other files specified |
|
24 # in the config file into clean-src. |
|
25 |
|
26 use strict; |
|
27 use File::Copy; |
|
28 use Getopt::Long; |
|
29 use FindBin; |
|
30 use Sys::Hostname; |
|
31 use lib "$FindBin::Bin/.."; |
|
32 use BxCopy; |
|
33 use PreBldChecks; |
|
34 use BuildLaunchChecks; |
|
35 |
|
36 use PC_P4Table; |
|
37 my $gXMLEnvRef; # Reference to hash containing environment data read from the XML file |
|
38 my %gBuildSpec; |
|
39 |
|
40 # default opts are daily manual |
|
41 my $CFG_BUILD_SUBTYPE = "Daily"; |
|
42 |
|
43 # Process the commandline |
|
44 my ($iBuildSubTypeOpt) = ProcessCommandLine(); |
|
45 |
|
46 my $hostname = &GetHostName(); |
|
47 |
|
48 my $PUBLISH_LOCATION_DAILY = "\\\\builds01\\devbuilds"; |
|
49 my $PUBLISH_LOCATION_TEST = "\\\\builds01\\devbuilds\\test_builds"; |
|
50 my $BUILDS_LOCAL_DIR = "d:\\builds"; |
|
51 |
|
52 # Define the source root directory (assumes it's 3 levels up) |
|
53 my $sourcedir = Cwd::abs_path("$FindBin::Bin\\..\\..\\..\\.."); |
|
54 |
|
55 # Define the pathnames for the XML files |
|
56 my $BuildLaunchXML = "$sourcedir\\os\\buildtools\\bldsystemtools\\commonbldutils\\BuildLaunch.xml"; |
|
57 my $PostBuildXML = "$sourcedir\\os\\buildtools\\bldsystemtools\\commonbldutils\\PostBuild.xml"; |
|
58 |
|
59 sub main() { |
|
60 |
|
61 print "Starting\n "; |
|
62 |
|
63 prepBuildLaunch(); |
|
64 doLoadEnv(); # populate gBuildEnv with ENV |
|
65 doSubstDrive(); |
|
66 doLogsDirCreate(); |
|
67 doManualBuild(); # spawn build clients and do build |
|
68 } |
|
69 |
|
70 # load the env from BuildLaunch.xml |
|
71 sub doLoadEnv() { |
|
72 |
|
73 # User may have edited environment variables above (see call to Notepad) |
|
74 # So re-read the XML file and store current values in %$gXMLEnvRef |
|
75 $gXMLEnvRef = PreBldChecks::XMLEnvironment($BuildLaunchXML); |
|
76 |
|
77 $gBuildSpec{'Product'} = $gXMLEnvRef->{'Product'}; |
|
78 $gBuildSpec{'SnapshotNumber'} = $gXMLEnvRef->{'SnapshotNumber'}; |
|
79 $gBuildSpec{'ChangelistNumber'} = $gXMLEnvRef->{'ChangelistNumber'}; |
|
80 $gBuildSpec{'BuildsDirect'} = $gXMLEnvRef->{'BuildsDirect'}; |
|
81 $gBuildSpec{'Platform'} = $gXMLEnvRef->{'Platform'}; |
|
82 $gBuildSpec{'BuildBaseName'} = 'Symbian_OS_v'.$gBuildSpec{'Product'}; |
|
83 $gBuildSpec{'ThisBuild'} = $gBuildSpec{'SnapshotNumber'}."_".$gBuildSpec{'BuildBaseName'}; |
|
84 $gBuildSpec{'LogsDir'} = $gXMLEnvRef->{'LogsDir'}; |
|
85 $gBuildSpec{'BuildDir'} = $gXMLEnvRef->{'BuildDir'}; # substed drive letter |
|
86 $gBuildSpec{'BuildsDirect'} = $gXMLEnvRef->{'BuildsDirect'}; # build dir |
|
87 $gBuildSpec{'ThisBuildDir'} = $gBuildSpec{'BuildsDirect'} . $gBuildSpec{'ThisBuild'}; |
|
88 $gBuildSpec{'Type'} = $gXMLEnvRef->{'Type'}; |
|
89 $gBuildSpec{'CurrentCodeline'} = $gXMLEnvRef->{'CurrentCodeline'}; |
|
90 $gBuildSpec{'BuildSubType'} = $gXMLEnvRef->{'BuildSubType'}; |
|
91 $gBuildSpec{'SubstDir'} = $gXMLEnvRef->{'SubstDir'}; |
|
92 $gBuildSpec{'CleanSourceDir'} = $gXMLEnvRef->{'CleanSourceDir'}; |
|
93 |
|
94 doValidate(); |
|
95 } |
|
96 |
|
97 # |
|
98 # Output warnings for any missing attributes. If any |
|
99 # are missing, the output a RealTimeBuild ERROR to halt the build |
|
100 # |
|
101 sub doValidate() { |
|
102 |
|
103 # 1. validate all env vars are set |
|
104 # Note: Validate of TestBuild.cfg, not done here |
|
105 my $iWarnCount = 0; |
|
106 my $key; |
|
107 my $value; |
|
108 |
|
109 while(($key, $value) = each(%gBuildSpec)) { |
|
110 |
|
111 # do something with $key and $value |
|
112 if ($value eq "") { |
|
113 print "\nWARNING: Attribute $key is missing from Specification "; |
|
114 $iWarnCount++; |
|
115 } |
|
116 } |
|
117 |
|
118 die "\nERROR: RealTimeBuild: Attributes missing from BuildLaunch.xml" if $iWarnCount > 0; |
|
119 } |
|
120 |
|
121 # Create Logs dir |
|
122 sub doLogsDirCreate() { |
|
123 |
|
124 if (!(-e $gBuildSpec{'LogsDir'})) { |
|
125 |
|
126 print "=== CREATING LOGS DIRECTORY ===\n"; |
|
127 |
|
128 my $cmd = "mkdir $gBuildSpec{'LogsDir'}"; |
|
129 system($cmd); |
|
130 |
|
131 } else { |
|
132 print "REMARK: Logs dir " .$gBuildSpec{'LogsDir'}."already exists!\n"; |
|
133 } |
|
134 } |
|
135 |
|
136 # |
|
137 sub doSubstDrive() { |
|
138 |
|
139 # Ensure trailing backslashes are removed |
|
140 my $iSubstDrv = $gBuildSpec{'BuildDir'}; |
|
141 |
|
142 $iSubstDrv =~ s/\\{1}$//; |
|
143 |
|
144 print "=== CREATING BUILD DIRECTORY ===\n"; |
|
145 |
|
146 mkdir($gBuildSpec{'SubstDir'}, 0666) or die "ERROR: Could not create \"$gBuildSpec{'SubstDir'}\": $!"; |
|
147 |
|
148 print "=== SUBST'ING BUILD DIRECTORY ===\n"; |
|
149 `subst $iSubstDrv /d 2>&1`; |
|
150 system "subst $iSubstDrv $gBuildSpec{'SubstDir'} 2>&1" and die "ERROR: Could not subst \"$gBuildSpec{'SubstDir'}\" to \"substdrive\" : $!"; |
|
151 |
|
152 |
|
153 } |
|
154 |
|
155 # Perform the manual build by running |
|
156 # 1. BuildLaunch.xml |
|
157 # 2. Core/Glue xml |
|
158 # 3. PostBuild.xml |
|
159 # |
|
160 sub doManualBuild() { |
|
161 |
|
162 # Start the BuildClients |
|
163 print "Starting the BuildClients\n"; |
|
164 my $profile = 1;#($gProfile ? "-p" : ""); |
|
165 system "start \"Launch BuildClient\" cmd /k perl $sourcedir\\os\\buildtools\\bldsystemtools\\buildsystemtools\\BuildClient.pl -d localhost:15000 -d localhost:15001 -d localhost:15002 -w 5 -c Launch $profile"; |
|
166 |
|
167 # |
|
168 # BUILDING |
|
169 # |
|
170 print "=== Build started ===\n"; |
|
171 |
|
172 # Start the BuildServer for the main build |
|
173 print "Starting the Launch BuildServer\n"; |
|
174 my $command = "perl $sourcedir\\os\\buildtools\\bldsystemtools\\buildsystemtools\\buildserver.pl -p 15000 -p 15001 -p 15002 -t 5 -c 5 -d $BuildLaunchXML -l $gBuildSpec{'LogsDir'}\\".$gBuildSpec{'ThisBuild'}.".log"; |
|
175 system ($command) and die "Error: $!"; |
|
176 |
|
177 print "Starting the Glue BuildServer\n"; |
|
178 my $gGlueXMLFile = $gBuildSpec{'BuildDir'} . '\\clean-src' . '\\os\\deviceplatformrelease\\symbianosbld\\cedarutils\\Symbian_OS_v' . $gBuildSpec{'Product'} . '.xml'; |
|
179 $command = "perl $sourcedir\\os\\buildtools\\bldsystemtools\\buildsystemtools\\buildserver.pl -p 15000 -p 15001 -p 15002 -t 5 -c 5 -d $gGlueXMLFile -e $BuildLaunchXML -l $gBuildSpec{'LogsDir'}\\".$gBuildSpec{'BuildBaseName'}.".log"; |
|
180 system ($command) and die "Error: $!"; |
|
181 |
|
182 print "Starting the Postbuild BuildServer\n"; |
|
183 $PostBuildXML = $gBuildSpec{'CleanSourceDir'} . '\\os\\buildtools\\bldsystemtools\\commonbldutils\\PostBuild.xml'; |
|
184 $command = "perl $sourcedir\\os\\buildtools\\bldsystemtools\\buildsystemtools\\buildserver.pl -p 15000 -p 15001 -p 15002 -t 5 -c 5 -d $PostBuildXML -e $BuildLaunchXML -l $gBuildSpec{'LogsDir'}\\postbuild.log"; |
|
185 system ($command) and die "Error: $!"; |
|
186 |
|
187 print "=== Build finished ===\n"; |
|
188 |
|
189 exit 0; |
|
190 } |
|
191 |
|
192 # |
|
193 sub prepBuildLaunch() { |
|
194 |
|
195 my %BuildLaunchCheckData; |
|
196 |
|
197 # |
|
198 # PREPARATION |
|
199 # |
|
200 |
|
201 # Make XML file writable |
|
202 print "Making BuildLaunch XML file writable\n"; |
|
203 chmod(0666, $BuildLaunchXML) || warn "Warning: Couldn't make \"$BuildLaunchXML\" writable: $!"; |
|
204 |
|
205 ($BuildLaunchCheckData{'Product'}, |
|
206 $BuildLaunchCheckData{'SnapshotNumber'}, |
|
207 $BuildLaunchCheckData{'PreviousSnapshotNumber'}, |
|
208 $BuildLaunchCheckData{'ChangelistNumber'}, |
|
209 $BuildLaunchCheckData{'CurrentCodeline'}, |
|
210 $BuildLaunchCheckData{'Platform'}, |
|
211 $BuildLaunchCheckData{'Type'}) = BuildLaunchChecks::GetUserInput(); |
|
212 |
|
213 $BuildLaunchCheckData{'BCToolsBaseBuildNo'} = BuildLaunchChecks::GetBCValue(\%BuildLaunchCheckData); |
|
214 |
|
215 $BuildLaunchCheckData{'BuildsDirect'} = $BUILDS_LOCAL_DIR; |
|
216 $BuildLaunchCheckData{'BuildSubType'} = $CFG_BUILD_SUBTYPE; |
|
217 $BuildLaunchCheckData{'PreviousBuildPublishLocation'} = $PUBLISH_LOCATION_DAILY; |
|
218 |
|
219 # set publish location according to Build SubType |
|
220 if ($CFG_BUILD_SUBTYPE eq "Test") { |
|
221 $BuildLaunchCheckData{'PublishLocation'} = $PUBLISH_LOCATION_TEST; |
|
222 } else { |
|
223 $BuildLaunchCheckData{'PublishLocation'} = $PUBLISH_LOCATION_DAILY; |
|
224 } |
|
225 |
|
226 # validate and write any updates |
|
227 my($Warnings) = BuildLaunchChecks::CheckData(\%BuildLaunchCheckData); |
|
228 BuildLaunchChecks::UpdateXML($BuildLaunchXML, \%BuildLaunchCheckData, ""); |
|
229 |
|
230 # Open XML file for verification |
|
231 print "Opening XML file(s) for verification\n"; |
|
232 my $command = "start /wait notepad.exe ".$BuildLaunchXML; |
|
233 system($command) and die "Error: $!"; |
|
234 } |
|
235 |
|
236 # Return hostname of this machine |
|
237 sub GetHostName |
|
238 { |
|
239 my ($iHost) = &hostname() =~ /(\S+?)\./; |
|
240 if (!defined($iHost)) |
|
241 { |
|
242 # Not a fully qualified Hostname, use use raw name |
|
243 $iHost = &hostname(); |
|
244 } |
|
245 return ($iHost); |
|
246 } |
|
247 |
|
248 |
|
249 # new process command line |
|
250 sub ProcessCommandLine { |
|
251 my ($iHelp); |
|
252 |
|
253 GetOptions('h' => \$iHelp, |
|
254 't:s' => \$iBuildSubTypeOpt); |
|
255 |
|
256 if (($iHelp)) { |
|
257 Usage(); |
|
258 } else { |
|
259 |
|
260 if ((defined $iBuildSubTypeOpt)) { |
|
261 $CFG_BUILD_SUBTYPE= "Test"; |
|
262 } |
|
263 } |
|
264 |
|
265 return ($iBuildSubTypeOpt); |
|
266 } |
|
267 |
|
268 |
|
269 sub Usage { |
|
270 print <<USAGE_EOF; |
|
271 |
|
272 Usage: startbuild.pl [option] |
|
273 |
|
274 options: |
|
275 |
|
276 -h -- help |
|
277 -t [optional] Perform a TestBuild. |
|
278 |
|
279 - Additional source based upon testbuild.cfg will be |
|
280 obtained from Perforce. If testbuild.cfg is not correctly filled out |
|
281 it will fail during the syncsource stage. |
|
282 - TestBuild will be published to TestBuild area on devbuilds and to Test CBR Archive |
|
283 |
|
284 |
|
285 |
|
286 USAGE_EOF |
|
287 exit 1; |
|
288 } |
|
289 |
|
290 |
|
291 ######################################### |
|
292 # s t a r t |
|
293 ######################################### |
|
294 main(); |
|
295 |
|