build_package.pl
author darios@symbian.org
Fri, 29 May 2009 16:03:16 +0100
changeset 16 e1b9f78cef38
parent 15 45ed0efeb8a4
child 17 d75feffe620f
permissions -rw-r--r--
Project spec and config to be taken from a dir instead of from a repo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     1
# Copyright (c) 2009 Symbian Foundation Ltd
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     2
# This component and the accompanying materials are made available
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     3
# under the terms of the License "Eclipse Public License v1.0"
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     4
# which accompanies this distribution, and is available
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     5
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     6
#
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     7
# Initial Contributors:
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     8
# Symbian Foundation Ltd - initial contribution.
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     9
#
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    10
# Contributors:
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    11
#
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    12
# Description:
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    13
# This is a helper script which allocates unique drive letter and build number
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    14
# then starts a package build by running FBF bootstrap and build targets
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    15
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    16
use strict;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    17
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    18
use Getopt::Long;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    19
use File::Path;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    20
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    21
my $sBOOTSTRAP_DIR="C:\\Apps\\FBF\\bootstrap";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    22
my $sJOB_BASE_DIR="D:\\fbf_project";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    23
my $nMAX_JOBDIR_AGE_SECONDS = 86400; # max number of seconds after which the letter is forcibly released
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    24
my $nLOCK_FILE_MAX_ATTEMPTS = 5;
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    25
#my $sNUMBERS_FILE="\\\\sym-build01\\f\$\\numbers.txt";
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    26
my $sNUMBERS_FILE="d:\\numbers.txt";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    27
my $sLETTERS_FILE="D:\\letters.txt";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    28
my $nMAX_LETTER_AGE_SECONDS = 86400; # max number of seconds after which the letter is forcibly released
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    29
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    30
my $sFbfProjectRepo = '';
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    31
my $sFbfProjectDir = '';
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    32
my $sFbfConfigRepo="\\\\lon-engbuild87\\d\$\\mercurial_development\\oss\\FCL\\interim\\fbf\\configs\\pkgbuild";
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    33
my $sFbfConfigDir = '';
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    34
my $sJobLabel = '';
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    35
my $nCmdLineNumber;
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    36
GetOptions(('label:s' => \$sJobLabel, 'configrepo:s' => \$sFbfConfigRepo, 'configdir:s' => \$sFbfConfigDir, 'projectrepo:s' => \$sFbfProjectRepo, 'projectdir:s' => \$sFbfProjectDir, 'number:s' => \$nCmdLineNumber));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    37
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    38
if (!$sJobLabel or !$sFbfProjectRepo)
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    39
{
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    40
	print "Usage: build_package.pl --label=<label> --projectrepo=<project repo> | --projectdir=<project dir>\n\t[--configrepo=<config repo> | --configdir=<config dir>]\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    41
	exit(0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    42
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    43
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    44
my $sJobDir = mkdir_unique("$sJOB_BASE_DIR\\$sJobLabel");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    45
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    46
print("cd $sBOOTSTRAP_DIR\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    47
chdir("$sBOOTSTRAP_DIR");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    48
print "###### BOOTSTRAP ######\n";
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    49
my $sConfigArg = "-Dsf.config.repo=$sFbfConfigRepo";
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    50
$sConfigArg = "-Dsf.config.dir=$sFbfConfigDir" if ($sFbfConfigDir);
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    51
my $sProjectArg = "-Dsf.project.repo=$sFbfProjectRepo";
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    52
$sProjectArg = "-Dsf.project.dir=$sFbfProjectDir" if ($sFbfProjectDir);
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    53
print("hlm -f bootstrap.xml $sConfigArg $sProjectArg -Dsf.target.dir=$sJobDir\n");
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    54
system("hlm -f bootstrap.xml $sConfigArg $sProjectArg -Dsf.target.dir=$sJobDir");
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    55
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    56
# check that $sNUMBERS_FILE exists, otherwise create it
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    57
if (!-f $sNUMBERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    58
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    59
	open FILE, ">$sNUMBERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    60
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    61
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    62
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    63
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    64
my $nUnformattedNumber = ( $nCmdLineNumber ? $nCmdLineNumber : get_job_number($sFbfProjectRepo));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    65
my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    66
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    67
# check that $sLETTERS_FILE exists, otherwise create it
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    68
if (!-f $sLETTERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    69
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    70
	open FILE, ">$sLETTERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    71
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    72
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    73
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    74
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    75
# acquire drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    76
my $sDriveLetter = acquire_drive_letter();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    77
print "acquired drive letter: $sDriveLetter\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    78
die "Could not acquire drive letter" if (! $sDriveLetter);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    79
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    80
print("cd $sJobDir\\sf-config\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    81
chdir("$sJobDir\\sf-config");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    82
print "###### BUILD PREPARATION ######\n";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    83
print("hlm sf-prep -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter:\n");
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    84
system("hlm sf-prep -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter:");
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    85
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    86
print "###### EXECUTE BUILD ######\n";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    87
print("hlm sf-build-all -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter:\n");
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    88
system("hlm sf-build-all -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter:");
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    89
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    90
# release the drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    91
release_drive_letter($sDriveLetter);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    92
system("subst $sDriveLetter: /d"); # this is not required, but it's a good idea to keep things in order
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    93
print "drive letter $sDriveLetter released (and drive unsubsted)\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    94
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    95
sub mkdir_unique
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    96
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    97
	my ($sBaseDir) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    98
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    99
	# check that the path where the new dir must be created exists.
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   100
	$sBaseDir =~ m,(.*[\\/])?(.*),;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   101
	mkpath($1) if ($1 && !-d $1);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   102
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   103
	my $nI = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   104
	my $sNewDirName = "$sBaseDir";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   105
	while(!mkdir($sNewDirName))
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   106
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   107
		$nI++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   108
		$sNewDirName = "$sBaseDir.$nI";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   109
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   110
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   111
	return $sNewDirName;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   112
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   113
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   114
sub get_job_number
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   115
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   116
	my ($sKey) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   117
	
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   118
	$sKey=lc($sKey);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   119
	
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   120
	my %hnNumbers = ();
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   121
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   122
	my $nAttempts = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   123
	my $bGotNumber = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   124
	do
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   125
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   126
		open(FILE, "+<$sNUMBERS_FILE") or die("Can't open $sNUMBERS_FILE");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   127
		if ( flock(FILE, 6) )
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   128
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   129
			my $sLine;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   130
			while ($sLine = <FILE>)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   131
			{
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   132
				$hnNumbers{lc($1)} = $2 if ($sLine =~ m%(.*),(.*)%);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   133
			}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   134
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   135
			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   136
			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   137
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   138
			seek(FILE, 0, 0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   139
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   140
			for my $sStr ( keys(%hnNumbers) )
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   141
			{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   142
				print FILE "$sStr,$hnNumbers{$sStr}\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   143
			}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   144
			truncate(FILE,tell(FILE));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   145
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   146
			$bGotNumber = 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   147
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   148
		else
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   149
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   150
			$nAttempts ++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   151
			sleep(3);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   152
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   153
		close(FILE);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   154
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   155
	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   156
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   157
	return $hnNumbers{$sKey};
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   158
}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   159
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   160
sub acquire_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   161
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   162
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   163
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   164
	my $sLetterToRelease = '';
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   165
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   166
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   167
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   168
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   169
	{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   170
		open(FILE, "+<$sLETTERS_FILE") or die("Can't open $sLETTERS_FILE");
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   171
		if ( flock(FILE, 6) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   172
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   173
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   174
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   175
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   176
				if ($sLine =~ m%([^,]*),(.*)%)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   177
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   178
					my $sLetter=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   179
					my $sString=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   180
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   181
					$sString=~m%([^,]*),(.*)%;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   182
					my $nPid=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   183
					my $nTimestamp=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   184
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   185
					if (time()-$nTimestamp<=$nMAX_LETTER_AGE_SECONDS)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   186
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   187
						$hsPidsAndTimestamps{$sLetter} = $sString;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   188
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   189
					else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   190
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   191
						# do nothing
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   192
						print "forced release of letter: $sLetter\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   193
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   194
				}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   195
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   196
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   197
			for my $sNewLetter ('H'..'Y')
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   198
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   199
				if (! $hsPidsAndTimestamps{$sNewLetter})
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   200
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   201
					my $sTimestamp = time();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   202
					$hsPidsAndTimestamps{$sNewLetter} = "$$,$sTimestamp";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   203
					$sLetterToRelease = $sNewLetter;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   204
					last;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   205
				}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   206
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   207
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   208
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   209
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   210
			for my $sLetter ( keys(%hsPidsAndTimestamps) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   211
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   212
				print FILE "$sLetter,$hsPidsAndTimestamps{$sLetter}\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   213
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   214
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   215
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   216
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   217
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   218
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   219
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   220
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   221
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   222
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   223
		close(FILE);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   224
	}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   225
	until ( $bAcquired or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   226
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   227
	return $sLetterToRelease;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   228
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   229
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   230
sub release_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   231
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   232
	my ($sLetterToRelease) = @_;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   233
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   234
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   235
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   236
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   237
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   238
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   239
	{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   240
		open(FILE, "+<$sLETTERS_FILE") or die("Can't open $sLETTERS_FILE");
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   241
		if ( flock(FILE, 6) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   242
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   243
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   244
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   245
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   246
				$hsPidsAndTimestamps{$1} = $2 if ($sLine =~ m%([^,]*),(.*)%);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   247
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   248
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   249
			delete $hsPidsAndTimestamps{$sLetterToRelease};
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   250
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   251
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   252
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   253
			for my $sLetter ( keys(%hsPidsAndTimestamps) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   254
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   255
				print FILE "$sLetter,$hsPidsAndTimestamps{$sLetter}\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   256
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   257
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   258
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   259
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   260
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   261
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   262
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   263
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   264
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   265
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   266
		close(FILE);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   267
	}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   268
	until ( $bAcquired or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   269
}