deprecated/buildtools/buildsystemtools/BuildServer.pl
author jascui
Wed, 17 Nov 2010 13:39:51 +0800
changeset 688 27f7c5c966fc
parent 655 3f65fd25dfd4
permissions -rw-r--r--
delete orig.txt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
# Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
# All rights reserved.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
# This component and the accompanying materials are made available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
# which accompanies this distribution, and is available
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
# Initial Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
# Contributors:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
# Description:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
# Script to send commands to 1 or more Build Clients to perform parallel builds
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
# 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
use FindBin;    # for FindBin::Bin
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
use Getopt::Long;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
use File::Copy;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
# Add the directory contain this perl script into the path to find modules
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
use lib $FindBin::Bin;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
use BuildServer;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
use ParseXML;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
# Turn on per command Buffering of STDOUT, so the log files are not so far behind what is actually happening
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
$| = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
# Process the commandline
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
my ($iDataSource, $iPort, $iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections) = ProcessCommandLine();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
# Create socket to server
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
&BuildServer::Start($iDataSource, $iPort, $iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
# ProcessCommandLine
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
# $iPort (Port to listen on for Build Clients)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
# This function processes the commandline
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
sub ProcessCommandLine {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
  my ($iHelp, @iPort, $iDataSource, $iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
  GetOptions('h' => \$iHelp, 'd=s' =>\$iDataSource, 'p=i' => \@iPort, 'l=s' => \$iLogFile, 'e=s' =>\$iEnvSource, 't=s' =>\$iConnectionTimeout, 'c=s' =>\$iSocketConnections);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
  if (($iHelp) || (scalar(@iPort) < 0) || (!defined $iDataSource) || (!defined $iLogFile))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
    Usage();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
  } elsif (! -e $iDataSource) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
    die "Cannot open $iDataSource";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
  if ((defined $iEnvSource) && (! -e $iEnvSource))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
    die "Cannot open $iEnvSource";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
  &backupFile($iLogFile) if (-e $iLogFile);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
  return($iDataSource,\@iPort,$iLogFile, $iEnvSource, $iConnectionTimeout, $iSocketConnections);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
# backupFile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
# Inputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
# $iFile - filename to backup
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
# Outputs
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
# Description
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
# This function renames a file with the .baknn extension
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
sub backupFile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
  my ($iFile) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
  
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
  my ($iBak) = $iFile.".bak";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
  my ($i, $freefilename);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
  # Loop until you find a free file name by increamenting the number on the end of the .bak extension
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
  while (!$freefilename)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
  {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
    if (-e $iBak.$i)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
      $i++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
    } else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
      $iBak .= $i;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
      $freefilename = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
  }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
  print "WARNING: $iFile already exists, creating backup of orignal with new name of $iBak\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
  move($iFile,$iBak) or die "Could not backup $iFile to $iBak because of: $!\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
# Usage
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
# Output Usage Information.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
sub Usage {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
  print <<USAGE_EOF;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
  Usage: BuildServer.pl [options]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
USAGE_EOF
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
print "  Version: ".&BuildServer::GetServerVersion()."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
print <<USAGE_EOF;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
  options:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
  -h  help
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
  -p  Port number to listen on for Build Clients [Multiple allowed]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
  -t  Time between connection attempts [Optional - default 0 seconds]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
  -c  Number of connection attempts per port [Optional - default infinite]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
  -d  Data Source (XML command file)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
  -l  Log file for output from commands run on the Build Client
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
  -e  Use Environment of this data source (XML command file)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
      The Environment in the main data source takes precedence
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
USAGE_EOF
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
  exit 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
}