build_package.pl
author darios@symbian.org
Fri, 22 May 2009 16:54:57 +0100
changeset 14 0c4d71ffa649
parent 13 85202f272e4a
child 15 45ed0efeb8a4
permissions -rw-r--r--
Changed location of pkgbuild config to take account of the new structure of the Mercurial repos
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     1
#!/usr/bin/perl -w
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     2
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     3
use strict;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     4
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     5
use Getopt::Long;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     6
use File::Path;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     7
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     8
my $sBOOTSTRAP_DIR="D:\\Helium\\hlm-apps\\bootstrap";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
     9
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
    10
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
    11
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
    12
my $nLOCK_FILE_MAX_ATTEMPTS = 5;
12
2eaa774ddc63 Changed location of package build config and numbers.txt
darios@symbian.org
parents: 11
diff changeset
    13
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
    14
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
    15
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
    16
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    17
my $sProjectRepo = '';
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    18
my $sJobLabel = '';
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    19
my $nCmdLineNumber;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    20
GetOptions(('label:s' => \$sJobLabel, 'project:s' => \$sProjectRepo, 'number:s' => \$nCmdLineNumber));
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    21
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    22
if (!$sJobLabel or !$sProjectRepo)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    23
{
12
2eaa774ddc63 Changed location of package build config and numbers.txt
darios@symbian.org
parents: 11
diff changeset
    24
	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
    25
	exit(0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    26
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    27
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    28
my $sJobDir = mkdir_unique("$sJOB_BASE_DIR\\$sJobLabel");
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
print("cd $sBOOTSTRAP_DIR\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    31
chdir("$sBOOTSTRAP_DIR");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    32
print "###### BOOTSTRAP ######\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    33
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
    34
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
    35
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    36
# 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
    37
if (!-f $sNUMBERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    38
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    39
	open FILE, ">$sNUMBERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    40
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    41
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    42
}
11
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 $nUnformattedNumber = ( $nCmdLineNumber ? $nCmdLineNumber : get_job_number($sProjectRepo));
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    45
my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    46
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    47
# 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
    48
if (!-f $sLETTERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    49
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    50
	open FILE, ">$sLETTERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    51
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    52
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    53
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    54
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    55
# acquire drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    56
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
    57
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
    58
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
    59
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    60
print("cd $sJobDir\\sf-config\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    61
chdir("$sJobDir\\sf-config");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    62
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
    63
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
    64
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
    65
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    66
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
    67
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
    68
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
    69
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    70
# release the drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    71
release_drive_letter($sDriveLetter);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    72
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
    73
print "drive letter $sDriveLetter released (and drive unsubsted)\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    74
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    75
sub mkdir_unique
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    76
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    77
	my ($sBaseDir) = @_;
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
	# 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
    80
	$sBaseDir =~ m,(.*[\\/])?(.*),;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    81
	mkpath($1) if ($1 && !-d $1);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    82
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    83
	my $nI = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    84
	my $sNewDirName = "$sBaseDir";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    85
	while(!mkdir($sNewDirName))
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    86
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    87
		$nI++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    88
		$sNewDirName = "$sBaseDir.$nI";
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
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    91
	return $sNewDirName;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    92
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    93
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    94
sub get_job_number
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 ($sKey) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    97
	
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    98
	$sKey=lc($sKey);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    99
	
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   100
	my %hnNumbers = ();
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   101
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   102
	my $nAttempts = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   103
	my $bGotNumber = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   104
	do
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
		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
   107
		if ( flock(FILE, 6) )
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 $sLine;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   110
			while ($sLine = <FILE>)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   111
			{
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   112
				$hnNumbers{lc($1)} = $2 if ($sLine =~ m%(.*),(.*)%);
11
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
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   115
			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   116
			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   117
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   118
			seek(FILE, 0, 0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   119
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   120
			for my $sStr ( keys(%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
				print FILE "$sStr,$hnNumbers{$sStr}\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   123
			}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   124
			truncate(FILE,tell(FILE));
11
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
			$bGotNumber = 1;
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
		else
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   129
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   130
			$nAttempts ++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   131
			sleep(3);
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
		close(FILE);
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
	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   136
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   137
	return $hnNumbers{$sKey};
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   138
}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   139
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   140
sub acquire_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   141
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   142
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   143
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   144
	my $sLetterToRelease = '';
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   145
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   146
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   147
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   148
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   149
	{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   150
		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
   151
		if ( flock(FILE, 6) )
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
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   154
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   155
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   156
				if ($sLine =~ m%([^,]*),(.*)%)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   157
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   158
					my $sLetter=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   159
					my $sString=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   160
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   161
					$sString=~m%([^,]*),(.*)%;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   162
					my $nPid=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   163
					my $nTimestamp=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   164
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   165
					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
   166
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   167
						$hsPidsAndTimestamps{$sLetter} = $sString;
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
					else
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
						# do nothing
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   172
						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
   173
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   174
				}
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
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   177
			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
   178
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   179
				if (! $hsPidsAndTimestamps{$sNewLetter})
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
					my $sTimestamp = time();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   182
					$hsPidsAndTimestamps{$sNewLetter} = "$$,$sTimestamp";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   183
					$sLetterToRelease = $sNewLetter;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   184
					last;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   185
				}
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
			seek(FILE, 0, 0);
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 $sLetter ( keys(%hsPidsAndTimestamps) )
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
				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
   193
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   194
			truncate(FILE,tell(FILE));
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
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   197
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   198
		else
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
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   201
			sleep(3);
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
		close(FILE);
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
	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
   206
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   207
	return $sLetterToRelease;
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
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   210
sub release_drive_letter
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
	my ($sLetterToRelease) = @_;
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
	my %hsPidsAndTimestamps = ();
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
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   217
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   218
	do
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
		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
   221
		if ( flock(FILE, 6) )
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
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   224
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   225
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   226
				$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
   227
			}
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
			delete $hsPidsAndTimestamps{$sLetterToRelease};
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   230
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   231
			seek(FILE, 0, 0);
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
			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
   234
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   235
				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
   236
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   237
			truncate(FILE,tell(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
			$bAcquired = 1;
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
		else
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
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   244
			sleep(3);
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
		close(FILE);
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
	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
   249
}