build_package.pl
author darios@symbian.org
Thu, 28 May 2009 15:03:22 +0100
changeset 15 45ed0efeb8a4
parent 14 0c4d71ffa649
child 16 e1b9f78cef38
permissions -rw-r--r--
Added copyright header to build_package.pl
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
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    21
my $sBOOTSTRAP_DIR="D:\\Helium\\hlm-apps\\bootstrap";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    22
my $sJOB_BASE_DIR="D:\\fbf_project";
14
0c4d71ffa649 Changed location of pkgbuild config to take account of the new structure of the Mercurial repos
darios@symbian.org
parents: 13
diff changeset
    23
my $sCONFIG_REPO="\\\\lon-engbuild87\\d\$\\mercurial_development\\oss\\FCL\\interim\\fbf\\configs\\pkgbuild";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    24
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
    25
my $nLOCK_FILE_MAX_ATTEMPTS = 5;
12
2eaa774ddc63 Changed location of package build config and numbers.txt
darios@symbian.org
parents: 11
diff changeset
    26
my $sNUMBERS_FILE="\\\\sym-build01\\f\$\\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
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    30
my $sProjectRepo = '';
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    31
my $sJobLabel = '';
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    32
my $nCmdLineNumber;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    33
GetOptions(('label:s' => \$sJobLabel, 'project:s' => \$sProjectRepo, 'number:s' => \$nCmdLineNumber));
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    34
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    35
if (!$sJobLabel or !$sProjectRepo)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    36
{
12
2eaa774ddc63 Changed location of package build config and numbers.txt
darios@symbian.org
parents: 11
diff changeset
    37
	print "Usage: build_package.pl --label=<label> --project=<project_repo>\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    38
	exit(0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    39
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    40
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    41
my $sJobDir = mkdir_unique("$sJOB_BASE_DIR\\$sJobLabel");
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
print("cd $sBOOTSTRAP_DIR\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    44
chdir("$sBOOTSTRAP_DIR");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    45
print "###### BOOTSTRAP ######\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    46
print("hlm -f bootstrap.xml -Dsf.config.repo=$sCONFIG_REPO -Dsf.project.repo=$sProjectRepo -Dsf.target.dir=$sJobDir\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    47
system("hlm -f bootstrap.xml -Dsf.config.repo=$sCONFIG_REPO -Dsf.project.repo=$sProjectRepo -Dsf.target.dir=$sJobDir");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    48
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    49
# 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
    50
if (!-f $sNUMBERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    51
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    52
	open FILE, ">$sNUMBERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    53
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    54
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    55
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    56
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    57
my $nUnformattedNumber = ( $nCmdLineNumber ? $nCmdLineNumber : get_job_number($sProjectRepo));
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    58
my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    59
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    60
# 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
    61
if (!-f $sLETTERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    62
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    63
	open FILE, ">$sLETTERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    64
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    65
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    66
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    67
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    68
# acquire drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    69
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
    70
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
    71
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
    72
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    73
print("cd $sJobDir\\sf-config\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    74
chdir("$sJobDir\\sf-config");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    75
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
    76
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
    77
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
    78
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    79
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
    80
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
    81
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
    82
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    83
# release the drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    84
release_drive_letter($sDriveLetter);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    85
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
    86
print "drive letter $sDriveLetter released (and drive unsubsted)\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    87
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    88
sub mkdir_unique
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    89
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    90
	my ($sBaseDir) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    91
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    92
	# 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
    93
	$sBaseDir =~ m,(.*[\\/])?(.*),;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    94
	mkpath($1) if ($1 && !-d $1);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    95
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    96
	my $nI = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    97
	my $sNewDirName = "$sBaseDir";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    98
	while(!mkdir($sNewDirName))
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    99
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   100
		$nI++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   101
		$sNewDirName = "$sBaseDir.$nI";
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
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   104
	return $sNewDirName;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   105
}
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
sub get_job_number
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   108
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   109
	my ($sKey) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   110
	
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   111
	$sKey=lc($sKey);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   112
	
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   113
	my %hnNumbers = ();
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   114
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   115
	my $nAttempts = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   116
	my $bGotNumber = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   117
	do
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   118
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   119
		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
   120
		if ( flock(FILE, 6) )
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 $sLine;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   123
			while ($sLine = <FILE>)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   124
			{
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   125
				$hnNumbers{lc($1)} = $2 if ($sLine =~ m%(.*),(.*)%);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   126
			}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   127
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   128
			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   129
			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   130
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   131
			seek(FILE, 0, 0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   132
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   133
			for my $sStr ( keys(%hnNumbers) )
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
				print FILE "$sStr,$hnNumbers{$sStr}\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   136
			}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   137
			truncate(FILE,tell(FILE));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   138
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   139
			$bGotNumber = 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   140
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   141
		else
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   142
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   143
			$nAttempts ++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   144
			sleep(3);
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
		close(FILE);
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
	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
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
	return $hnNumbers{$sKey};
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   151
}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   152
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   153
sub acquire_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   154
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   155
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   156
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   157
	my $sLetterToRelease = '';
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   158
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   159
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   160
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   161
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   162
	{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   163
		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
   164
		if ( flock(FILE, 6) )
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 $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   167
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   168
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   169
				if ($sLine =~ m%([^,]*),(.*)%)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   170
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   171
					my $sLetter=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   172
					my $sString=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   173
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   174
					$sString=~m%([^,]*),(.*)%;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   175
					my $nPid=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   176
					my $nTimestamp=$2;
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
					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
   179
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   180
						$hsPidsAndTimestamps{$sLetter} = $sString;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   181
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   182
					else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   183
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   184
						# do nothing
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   185
						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
   186
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   187
				}
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
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   190
			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
   191
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   192
				if (! $hsPidsAndTimestamps{$sNewLetter})
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
					my $sTimestamp = time();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   195
					$hsPidsAndTimestamps{$sNewLetter} = "$$,$sTimestamp";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   196
					$sLetterToRelease = $sNewLetter;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   197
					last;
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
			}
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
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   202
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   203
			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
   204
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   205
				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
   206
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   207
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   208
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   209
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   210
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   211
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   212
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   213
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   214
			sleep(3);
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
		close(FILE);
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
	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
   219
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   220
	return $sLetterToRelease;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   221
}
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
sub release_drive_letter
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
	my ($sLetterToRelease) = @_;
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
	my %hsPidsAndTimestamps = ();
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
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   230
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   231
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   232
	{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   233
		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
   234
		if ( flock(FILE, 6) )
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 $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   237
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   238
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   239
				$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
   240
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   241
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   242
			delete $hsPidsAndTimestamps{$sLetterToRelease};
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   243
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   244
			seek(FILE, 0, 0);
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
			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
   247
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   248
				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
   249
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   250
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   251
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   252
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   253
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   254
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   255
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   256
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   257
			sleep(3);
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
		close(FILE);
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
	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
   262
}