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