|
1 # Copyright (c) 2003-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 # Script to send commands to 1 or more Build Clients to perform parallel builds |
|
15 # |
|
16 # |
|
17 |
|
18 use strict; |
|
19 use FindBin; # for FindBin::Bin |
|
20 use Getopt::Long; |
|
21 use File::Copy; |
|
22 |
|
23 # Add the directory contain this perl script into the path to find modules |
|
24 use lib $FindBin::Bin; |
|
25 |
|
26 use BuildServer; |
|
27 use ParseXML; |
|
28 |
|
29 # Turn on per command Buffering of STDOUT, so the log files are not so far behind what is actually happening |
|
30 $| = 1; |
|
31 |
|
32 # Process the commandline |
|
33 my ($iDataSource, $iPort, $iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections) = ProcessCommandLine(); |
|
34 |
|
35 # Create socket to server |
|
36 &BuildServer::Start($iDataSource, $iPort, $iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections); |
|
37 |
|
38 |
|
39 # ProcessCommandLine |
|
40 # |
|
41 # Inputs |
|
42 # |
|
43 # Outputs |
|
44 # $iPort (Port to listen on for Build Clients) |
|
45 # |
|
46 # Description |
|
47 # This function processes the commandline |
|
48 |
|
49 sub ProcessCommandLine { |
|
50 my ($iHelp, @iPort, $iDataSource, $iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections); |
|
51 GetOptions('h' => \$iHelp, 'd=s' =>\$iDataSource, 'p=i' => \@iPort, 'l=s' => \$iLogFile, 'e=s' =>\$iEnvSource, 't=s' =>\$iConnectionTimeout, 'c=s' =>\$iSocketConnections); |
|
52 |
|
53 if (($iHelp) || (scalar(@iPort) < 0) || (!defined $iDataSource) || (!defined $iLogFile)) |
|
54 { |
|
55 Usage(); |
|
56 } elsif (! -e $iDataSource) { |
|
57 die "Cannot open $iDataSource"; |
|
58 } |
|
59 if ((defined $iEnvSource) && (! -e $iEnvSource)) |
|
60 { |
|
61 die "Cannot open $iEnvSource"; |
|
62 } |
|
63 |
|
64 &backupFile($iLogFile) if (-e $iLogFile); |
|
65 |
|
66 return($iDataSource,\@iPort,$iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections); |
|
67 } |
|
68 |
|
69 # backupFile |
|
70 # |
|
71 # Inputs |
|
72 # $iFile - filename to backup |
|
73 # |
|
74 # Outputs |
|
75 # |
|
76 # Description |
|
77 # This function renames a file with the .baknn extension |
|
78 sub backupFile |
|
79 { |
|
80 my ($iFile) = @_; |
|
81 |
|
82 my ($iBak) = $iFile.".bak"; |
|
83 my ($i, $freefilename); |
|
84 # Loop until you find a free file name by increamenting the number on the end of the .bak extension |
|
85 while (!$freefilename) |
|
86 { |
|
87 if (-e $iBak.$i) |
|
88 { |
|
89 $i++; |
|
90 } else { |
|
91 $iBak .= $i; |
|
92 $freefilename = 1; |
|
93 } |
|
94 } |
|
95 print "WARNING: $iFile already exists, creating backup of orignal with new name of $iBak\n"; |
|
96 move($iFile,$iBak) or die "Could not backup $iFile to $iBak because of: $!\n"; |
|
97 } |
|
98 |
|
99 # Usage |
|
100 # |
|
101 # Output Usage Information. |
|
102 # |
|
103 |
|
104 sub Usage { |
|
105 print <<USAGE_EOF; |
|
106 |
|
107 Usage: BuildServer.pl [options] |
|
108 |
|
109 USAGE_EOF |
|
110 print " Version: ".&BuildServer::GetServerVersion()."\n"; |
|
111 print <<USAGE_EOF; |
|
112 |
|
113 options: |
|
114 |
|
115 -h help |
|
116 -p Port number to listen on for Build Clients [Multiple allowed] |
|
117 -t Time between connection attempts [Optional - default 0 seconds] |
|
118 -c Number of connection attempts per port [Optional - default infinite] |
|
119 -d Data Source (XML command file) |
|
120 -l Log file for output from commands run on the Build Client |
|
121 -e Use Environment of this data source (XML command file) |
|
122 The Environment in the main data source takes precedence |
|
123 USAGE_EOF |
|
124 exit 1; |
|
125 } |