1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 #!/usr/bin/perl -w |
|
17 use strict; |
|
18 use Getopt::Long; |
|
19 use HTTP::Date; |
|
20 |
|
21 my $JOBS_PATH = "autobfc\\"; |
|
22 my $JOB_QUEUE = 'jobqueue.lst'; |
|
23 my $CURR_JOB = 'currentjob.bat'; |
|
24 my $QUIT_BFC = 'quit.txt'; |
|
25 |
|
26 my $ENV_BFCPOOL = "AutoBFCServerPool"; |
|
27 |
|
28 |
|
29 SendBFC( ProcessCommandLine() ); |
|
30 |
|
31 # SendBFC |
|
32 # Send a BFC test request to an active Auto BFC server |
|
33 # |
|
34 # Return 0 if request was successfully added to the BFC queue. |
|
35 # |
|
36 # N.B: Since this script is invoked during the system build, WARNING/ERROR |
|
37 # messages must NOT be printed out in order to avoid affecting the BRAG status. |
|
38 # |
|
39 |
|
40 sub SendBFC |
|
41 { |
|
42 my ($iProduct, $iBuild, $iCodeline, $iServerPool, $iARMVer, $iMWVer, $iWait, $iExtraArg, $iQuit, $iSubType) = @_; |
|
43 |
|
44 # Get server list from ENV or from command line |
|
45 $iServerPool = $ENV{$ENV_BFCPOOL} if (!defined($iServerPool)); |
|
46 |
|
47 my $server = FindAvailableServer(split /\#/, $iServerPool); |
|
48 |
|
49 if (!$server) |
|
50 { |
|
51 print "Could not find BFC server \n"; |
|
52 return 1; |
|
53 } |
|
54 |
|
55 my $jobQueue = "\\\\$server\\".$JOBS_PATH.$JOB_QUEUE; |
|
56 |
|
57 # Set basic release info |
|
58 my $request = "Product=$iProduct,SnapshotNumber=$iBuild,CurrentCodeline=$iCodeline"; |
|
59 |
|
60 # Set timeout |
|
61 if (defined($iWait) && !($iExtraArg =~ /-o/)) |
|
62 { |
|
63 my $nowStr = HTTP::Date::time2isoz(time() + $iWait*60*60); |
|
64 $request .= ",BFCTimeout=$nowStr"; |
|
65 } |
|
66 |
|
67 $request .= ",ARMRVCTBLD=$iARMVer" if ($iARMVer); |
|
68 $request .= ",MWVER=$iMWVer" if ($iMWVer); |
|
69 |
|
70 $request .= ",QMAction=$iQuit" if ($iQuit); |
|
71 |
|
72 # Get BuildSubType from ENV or from command line, if specified. |
|
73 $iSubType = $ENV{'BuildSubType'} unless ($iSubType); |
|
74 $request .= ",BuildSubType=$iSubType" if ($iSubType); |
|
75 |
|
76 # Add extra arguments at the end |
|
77 $request .= ",BFCCommand=$iExtraArg" if ($iExtraArg); |
|
78 |
|
79 # Add the request to the server queue |
|
80 open FILE, ">> $jobQueue" or die "Can't open $jobQueue\n$!\n"; |
|
81 print FILE "$request \n"; |
|
82 close FILE; |
|
83 |
|
84 print "Added request: $request\nto $server\n"; |
|
85 return 0; |
|
86 } |
|
87 |
|
88 # FindAvailableServer |
|
89 # Scan the server list and find an available AutoBFC server. |
|
90 # |
|
91 # Return the first bfc server with no jobs or the bfc server with |
|
92 # the least jobs on the queue. |
|
93 # |
|
94 sub FindAvailableServer |
|
95 { |
|
96 my @servers = @_; |
|
97 |
|
98 my %bestServer; |
|
99 foreach my $server (@servers) |
|
100 { |
|
101 # Check autobfc shared dir. |
|
102 my $jobsPath = "\\\\$server\\".$JOBS_PATH; |
|
103 next if !(-d $jobsPath); |
|
104 |
|
105 # This is a valid server. |
|
106 # Check the job list. |
|
107 my $jobQueue = $jobsPath.$JOB_QUEUE; |
|
108 my $currentJob = $jobsPath.$CURR_JOB; |
|
109 push my @jobs, "current" if (-e $currentJob); |
|
110 if (open (FH1, $jobQueue)) |
|
111 { |
|
112 push @jobs, <FH1>; |
|
113 close FH1; |
|
114 } |
|
115 %bestServer = ('Server' => $server, 'Jobs' => scalar @jobs) if (!exists($bestServer{'Server'}) || (scalar @jobs < $bestServer{'Jobs'})); |
|
116 last if ($bestServer{'Jobs'} == 0); |
|
117 } |
|
118 |
|
119 return $bestServer{'Server'}; |
|
120 } |
|
121 |
|
122 |
|
123 # ProcessCommandLine |
|
124 # |
|
125 |
|
126 sub ProcessCommandLine |
|
127 { |
|
128 my ($iHelp); |
|
129 my ($iProduct, $iBuild, $iCodeline, $iServerPool, $iARMVer, $iMWVer, $iWait, $iExtraArg, $iQuit, $iSubType); |
|
130 |
|
131 my $ret = GetOptions('h' => \$iHelp, |
|
132 "product=s" => \$iProduct, |
|
133 "build=s" => \$iBuild, |
|
134 "codeline=s" => \$iCodeline, |
|
135 "server=s" => \$iServerPool, |
|
136 "arm=s" => \$iARMVer, |
|
137 "mw=s" => \$iMWVer, |
|
138 "wait=i" => \$iWait, |
|
139 "reboot" => \$iQuit, |
|
140 "type=s" => \$iSubType); |
|
141 |
|
142 $iExtraArg = join(' ', @ARGV); |
|
143 |
|
144 if ((!$ret) || ($iHelp) || (!defined $iProduct) || (!defined $iBuild) || (!defined $iCodeline)) |
|
145 { |
|
146 Usage(); |
|
147 } |
|
148 |
|
149 if (defined($iQuit)) |
|
150 { |
|
151 $iQuit = "reboot"; |
|
152 } |
|
153 |
|
154 return ($iProduct, $iBuild, $iCodeline, $iServerPool, $iARMVer, $iMWVer, $iWait, $iExtraArg, $iQuit, $iSubType); |
|
155 } |
|
156 |
|
157 # Usage |
|
158 # |
|
159 # Output Usage Information. |
|
160 # |
|
161 |
|
162 sub Usage |
|
163 { |
|
164 print <<USAGE_EOF; |
|
165 |
|
166 Request a BFC |
|
167 Usage: bfcClient.pl -p <Ver> -b <BuildNo> -c <Codeline> -s <ServerPool> [options] -- [bfc extra arg] |
|
168 |
|
169 --product Specify OS product (e.g. 9.1). |
|
170 --build Specify Build Number (e.g. M04191). |
|
171 --codeline Specify Codeline (e.g. Master, Symbian_OS_v9.4) |
|
172 --server Hash separated BFC server list (e.g lon-engbuild20\#lon-engbuild21). |
|
173 Alternatively, set $ENV_BFCPOOL. |
|
174 |
|
175 [Options] |
|
176 -h This help |
|
177 --arm Specify ARM version to be used (435 or 559 or 616). |
|
178 --mw Specify Metrowerk version to be used (3.0 or 3.1.1 or 3.1.2). |
|
179 --wait 0..n Force the bfc process to wait no more than n hours from now. |
|
180 --reboot Force the bfc process to reboot before this task. |
|
181 --type Specify BuildSubType (e.g. Daily, Test). |
|
182 |
|
183 [bfc extra arg] |
|
184 Any other switches will be passed to the bfc process tools |
|
185 |
|
186 USAGE_EOF |
|
187 exit 0; |
|
188 } |
|
189 |
|
190 |
|