build_platform.pl
author Dario Sestito <darios@symbian.org>
Tue, 09 Mar 2010 12:57:02 +0000
changeset 71 f7ba24a607f8
parent 68 e41ebdf49dd5
permissions -rw-r--r--
Remove the correct job directory after the build, otherwise concurrent builds of the same package if run at the same time will have their jobdir removed and hence fail
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     1
# Copyright (c) 2009 Symbian Foundation Ltd
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     2
# This component and the accompanying materials are made available
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     3
# under the terms of the License "Eclipse Public License v1.0"
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     4
# which accompanies this distribution, and is available
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     5
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     6
#
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     7
# Initial Contributors:
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     8
# Symbian Foundation Ltd - initial contribution.
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     9
#
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    10
# Contributors:
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    11
#
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    12
# Description:
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    13
# This is a helper script which allocates unique drive letter and build number
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    14
# then starts a platform build by running FBF bootstrap and build targets
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    15
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    16
use strict;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    17
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    18
use Getopt::Long;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    19
use File::Path;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    20
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    21
my $sBOOTSTRAP_DIR="C:\\Apps\\FBF\\bootstrap";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    22
my $sJOB_BASE_DIR="fbf_project";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    23
my $nMAX_JOBDIR_AGE_SECONDS = 86400; # max number of seconds after which the letter is forcibly released
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    24
my $nLOCK_FILE_MAX_ATTEMPTS = 5;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    25
my $sNUMBERS_FILE="\\\\v800020\\Publish\\SF_builds\\numbers.txt";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    26
my $sLETTERS_FILE="letters.txt";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    27
my $nMAX_LETTER_AGE_SECONDS = 86400; # max number of seconds after which the letter is forcibly released
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    28
68
e41ebdf49dd5 s/bishare/v800020/
Dario Sestito <darios@symbian.org>
parents: 62
diff changeset
    29
my $sFbfProjectRepo = "\\\\v800020\\mercurial_development\\oss\\FCL\\interim\\fbf\\projects\\platforms";
54
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    30
my $sFbfProjectDir = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    31
my $sSubProject = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    32
#my $sSourcesFile = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    33
#my $sModelFile = '';
68
e41ebdf49dd5 s/bishare/v800020/
Dario Sestito <darios@symbian.org>
parents: 62
diff changeset
    34
my $sFbfConfigRepo="\\\\v800020\\mercurial_development\\oss\\FCL\\interim\\fbf\\configs\\default";
54
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    35
my $sFbfConfigDir = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    36
my $nCmdLineNumber;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    37
my $sDiamondsTag = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    38
my $bHudson = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    39
my $bPublish = 1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    40
my %hHlmDefines = ();
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    41
my $bHelp = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    42
GetOptions((
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    43
	'configrepo=s' => \$sFbfConfigRepo,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    44
	'configdir=s' => \$sFbfConfigDir,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    45
	'projectrepo=s' => \$sFbfProjectRepo,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    46
	'projectdir=s' => \$sFbfProjectDir,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    47
	'subproj=s' => \$sSubProject,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    48
	#'sources=s' => \$sSourcesFile,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    49
	#'model=s' => \$sModelFile,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    50
	'number=s' => \$nCmdLineNumber,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    51
	'tag=s' => \$sDiamondsTag,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    52
	'hudson!' => \$bHudson,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    53
	'publish!' => \$bPublish,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    54
	'define=s' => \%hHlmDefines,
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    55
	'help!' => \$bHelp
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    56
));
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    57
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    58
if ($bHelp or !($sSubProject or $sFbfProjectRepo or $sFbfProjectDir))
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    59
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    60
	print "Usage: build_platform.pl --subproj=RELPATH [OPTIONS]\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    61
	print "       build_platform.pl --projectrepo=REPO [OPTIONS]\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    62
	print "where OPTIONS are:\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    63
	print "\t--subproj=RELPATH Select subproject located at RELPATH (relative to the root of the project repository)\n";
68
e41ebdf49dd5 s/bishare/v800020/
Dario Sestito <darios@symbian.org>
parents: 62
diff changeset
    64
	print "\t--projectrepo=REPO[#REV] Use repository REPO at revision REV for the project (instead of \\\\v800020\\mercurial_internal\\fbf\\projects\\packages)\n";
54
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    65
	print "\t--projectdir=DIR Use DIR location for the project (exclusive with --projectrepo).\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    66
	#print "\t--sources=FILE ...\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    67
	#print "\t--model=FILE ...\n";
68
e41ebdf49dd5 s/bishare/v800020/
Dario Sestito <darios@symbian.org>
parents: 62
diff changeset
    68
	print "\t--configrepo=REPO[#REV] Use repository REPO at revision REV for the config (instead of \\\\v800020\\mercurial_internal\\fbf\\config\\default)\n";
54
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    69
	print "\t--configdir=DIR Use DIR location for the config (exclusive with --configrepo).\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    70
	print "\t--number=N Force build number to N\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    71
	print "\t--tag=TAG Apply Diamonds tag TAG to this build\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    72
	print "\t--hudson Checks that there is at least NUMBER_OF_PROCESSORS X 10 GB available on the working drive\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    73
	print "\t--nopublish Use \\numbers_test.txt for numbers and disable publishing\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    74
	print "\t--define ATTRIBUTE=VALUE Pass -D statements to the Helium Framework\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    75
	exit(0);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    76
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    77
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    78
if ($sSubProject and $sSubProject !~ m,^([^/]+)/([^/]+)$,)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    79
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    80
	print "ERROR: Option --subproj must be in the format codeline/platform (e.g. symbian3/micro)\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    81
	exit(0);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    82
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    83
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    84
#if (!$sFbfProjectRepo and !$sFbfProjectDir and (!$sSourcesFile or !$sModelFile))
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    85
#{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    86
#	print "Error: If you don't provide --projectrepo or --projectdir then you have to provide both --sources and --model\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    87
#	exit(0);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    88
#}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    89
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    90
my $sWORKING_DRIVE = find_working_drive();
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    91
print "Will use drive $sWORKING_DRIVE as working drive for this build\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    92
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    93
my $sFbfProjectRev = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    94
if ($sFbfProjectRepo =~ m,(.*)#(.*),)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    95
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    96
	$sFbfProjectRepo = $1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    97
	$sFbfProjectRev = $2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    98
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    99
my $sFbfConfigRev = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   100
if ($sFbfConfigRepo =~ m,(.*)#(.*),)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   101
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   102
	$sFbfConfigRepo = $1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   103
	$sFbfConfigRev = $2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   104
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   105
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   106
my $sHlmDefineOpt = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   107
for (keys %hHlmDefines)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   108
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   109
	$sHlmDefineOpt .= "-D$_=$hHlmDefines{$_} ";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   110
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   111
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   112
my $sTestBuildOpt = "";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   113
$sTestBuildOpt = "-Dsf.spec.publish.diamonds.tag=\"$sDiamondsTag\"" if ( $sDiamondsTag );
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   114
my $sNoPublishOpt = "";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   115
$sNoPublishOpt = "-Dsf.spec.publish.enable=false" if ( !$bPublish );
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   116
$sNUMBERS_FILE = "$sWORKING_DRIVE\\numbers_test.txt" if ( !$bPublish );
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   117
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   118
my $sJobLabel = 'job';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   119
if ($sSubProject)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   120
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   121
	$sSubProject =~ m,^([^/]+)/([^/]+)$,;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   122
	$sJobLabel = $2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   123
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   124
elsif ($sFbfProjectRepo)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   125
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   126
	$sFbfProjectRepo =~ m,(.*[\\/])?([^\\^/]+),;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   127
	$sJobLabel = $2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   128
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   129
elsif ($sFbfProjectDir)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   130
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   131
	$sFbfProjectDir =~ m,(.*[\\/])?([^\\^/]+),;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   132
	$sJobLabel = $2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   133
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   134
#elsif ($sSourcesFile)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   135
#{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   136
#	$sSourcesFile =~ m,/(adaptation|app|mw|os|ostools|tools)[\\/]([^\\^/]+),i;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   137
#	$sJobLabel = $2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   138
#	$sSourcesFile =~ m,(.*[\\/])?([^\\^/]+),;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   139
#	$sJobLabel = $2 if (!$sJobLabel);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   140
#}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   141
mkdir("$sWORKING_DRIVE\\$sJOB_BASE_DIR") if (!-d "$sWORKING_DRIVE\\$sJOB_BASE_DIR");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   142
my $sJobDir = mkdir_unique("$sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   143
print "Created project dir $sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobDir\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   144
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   145
print("cd $sBOOTSTRAP_DIR\n");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   146
chdir("$sBOOTSTRAP_DIR");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   147
print "###### BOOTSTRAP ######\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   148
my $sConfigArg = "-Dsf.config.repo=$sFbfConfigRepo";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   149
$sConfigArg .= " -Dsf.config.rev=$sFbfConfigRev" if ($sFbfConfigRev);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   150
$sConfigArg = "-Dsf.config.dir=$sFbfConfigDir" if ($sFbfConfigDir);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   151
my $sProjectArg = "-Dsf.project.repo=$sFbfProjectRepo";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   152
$sProjectArg .= " -Dsf.project.rev=$sFbfProjectRev" if ($sFbfProjectRev);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   153
$sProjectArg = "-Dsf.project.dir=$sFbfProjectDir" if ($sFbfProjectDir);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   154
my $sBootstrapCmd = "hlm -f bootstrap.xml $sConfigArg $sProjectArg -Dsf.target.dir=$sJobDir";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   155
print("$sBootstrapCmd\n");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   156
system($sBootstrapCmd);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   157
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   158
# check that $sNUMBERS_FILE exists, otherwise create it
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   159
if (!-f $sNUMBERS_FILE)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   160
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   161
	open FILE, ">$sNUMBERS_FILE";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   162
	print FILE "\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   163
	close FILE;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   164
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   165
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   166
my $sJobNumberKey = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   167
my $sPackage = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   168
my $sPlatform = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   169
my $nUnformattedNumber = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   170
if ($nCmdLineNumber)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   171
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   172
	$nUnformattedNumber = $nCmdLineNumber;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   173
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   174
elsif ($sFbfProjectRepo)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   175
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   176
	if ($sSubProject)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   177
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   178
		# key = <package>_<codeline>, e.g. for subproj=MCL/os/boardsupport -> key=boardsupport_MCL
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   179
		$sSubProject =~ m,^([^/]+)/([^/]+)$,;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   180
		$sPackage = $2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   181
		$sPlatform = $1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   182
		$sJobNumberKey = "$2_$1";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   183
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   184
	else
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   185
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   186
		# key = hash of the rev.0 of the package project repo
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   187
		my $sRevZeroHash = get_rev_zero_hash($sFbfProjectRepo);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   188
		$sJobNumberKey = $sRevZeroHash;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   189
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   190
	$nUnformattedNumber = get_job_number($sJobNumberKey);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   191
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   192
my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   193
print "For build key $sJobNumberKey got assigned number \"$nJobNumber\"\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   194
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   195
# check that $sLETTERS_FILE exists, otherwise create it
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   196
if (!-f "$sWORKING_DRIVE\\$sLETTERS_FILE")
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   197
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   198
	open FILE, ">$sWORKING_DRIVE\\$sLETTERS_FILE";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   199
	print FILE "\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   200
	close FILE;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   201
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   202
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   203
# acquire drive letter
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   204
my $sDriveLetter = acquire_drive_letter();
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   205
print "acquired drive letter: $sDriveLetter\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   206
die "Could not acquire drive letter" if (! $sDriveLetter);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   207
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   208
my $sJobRootDirArg = "-Dsf.spec.job.rootdir=$sWORKING_DRIVE\\fbf_job";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   209
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   210
my $sSubProjArg = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   211
$sSubProjArg = "-Dsf.subproject.path=$sSubProject" if ($sSubProject);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   212
print("cd $sJobDir\\sf-config\n");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   213
chdir("$sJobDir\\sf-config");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   214
print "###### BUILD PREPARATION ######\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   215
my $sPreparationCmd = "hlm sf-prep -Dsf.project.type=platform $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt $sJobRootDirArg $sHlmDefineOpt";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   216
print("$sPreparationCmd\n");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   217
system($sPreparationCmd);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   218
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   219
print "###### EXECUTE BUILD ######\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   220
my $sBuildallCmd = "hlm sf-build-all -Dsf.project.type=platform $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt $sJobRootDirArg $sHlmDefineOpt";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   221
print("$sBuildallCmd\n");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   222
system($sBuildallCmd);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   223
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   224
print("cd $sBOOTSTRAP_DIR\n");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   225
chdir("$sBOOTSTRAP_DIR");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   226
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   227
# release the drive letter
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   228
release_drive_letter($sDriveLetter);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   229
system("subst $sDriveLetter: /d"); # this is not required, but it's a good idea to keep things in order
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   230
print "drive letter $sDriveLetter released (and drive unsubsted)\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   231
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   232
if ($bHudson)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   233
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   234
	print "cleaning job directories...\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   235
	if (-d "$sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel") # project dir
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   236
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   237
		print "rmdir /S $sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   238
		system("rmdir /S /Q $sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   239
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   240
	if (-d "$sWORKING_DRIVE\\fbf_job\\$sPackage\_$sPlatform.$nJobNumber") # build drive
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   241
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   242
		print "rmdir /S $sWORKING_DRIVE\\fbf_job\\$sPackage\_$sPlatform.$nJobNumber\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   243
		system("rmdir /S /Q $sWORKING_DRIVE\\fbf_job\\$sPackage\_$sPlatform.$nJobNumber");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   244
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   245
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   246
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   247
sub find_working_drive
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   248
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   249
	my @drive_list = ('E', 'G', 'D', 'C');
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   250
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   251
	for my $drive (@drive_list)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   252
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   253
		return "$drive:" if (-d "$drive:/");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   254
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   255
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   256
	die "Could not find suitable working drive.";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   257
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   258
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   259
sub mkdir_unique
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   260
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   261
	my ($sBaseDir) = @_;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   262
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   263
	# check that the path where the new dir must be created exists.
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   264
	$sBaseDir =~ m,(.*[\\/])?(.*),;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   265
	mkpath($1) if ($1 && !-d $1);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   266
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   267
	my $nI = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   268
	my $sNewDirName = "$sBaseDir";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   269
	while(!mkdir($sNewDirName))
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   270
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   271
		$nI++;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   272
		$sNewDirName = "$sBaseDir.$nI";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   273
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   274
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   275
	return $sNewDirName;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   276
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   277
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   278
sub get_rev_zero_hash
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   279
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   280
	my ($sFbfProjectRepo) = @_;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   281
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   282
	my $sOutput = `hg -R $sFbfProjectRepo identify -r0`;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   283
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   284
	# remove leading and trailing spaces
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   285
	$sOutput =~ s,^\s+,,;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   286
	$sOutput =~ s,\s+$,,;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   287
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   288
	# remove tags e.g. "1fc39a7e9d79 tip"
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   289
	$sOutput =~ s,([0-9a-z]+)\s+.*,$1,;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   290
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   291
	return $sOutput;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   292
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   293
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   294
sub get_job_number
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   295
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   296
	my ($sKey) = @_;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   297
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   298
	$sKey=lc($sKey);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   299
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   300
	my %hnNumbers = ();
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   301
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   302
	my $nAttempts = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   303
	my $bGotNumber = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   304
	do
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   305
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   306
		open(FILE, "+<$sNUMBERS_FILE") or die("Can't open $sNUMBERS_FILE");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   307
		if ( flock(FILE, 6) )
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   308
		{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   309
			my $sLine;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   310
			while ($sLine = <FILE>)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   311
			{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   312
				$hnNumbers{lc($1)} = $2 if ($sLine =~ m%(.*),(.*)%);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   313
			}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   314
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   315
			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   316
			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   317
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   318
			seek(FILE, 0, 0);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   319
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   320
			for my $sStr ( keys(%hnNumbers) )
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   321
			{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   322
				print FILE "$sStr,$hnNumbers{$sStr}\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   323
			}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   324
			truncate(FILE,tell(FILE));
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   325
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   326
			$bGotNumber = 1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   327
		}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   328
		else
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   329
		{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   330
			$nAttempts ++;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   331
			sleep(3);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   332
		}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   333
		close(FILE);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   334
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   335
	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   336
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   337
	return $hnNumbers{$sKey};
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   338
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   339
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   340
sub acquire_drive_letter
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   341
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   342
	my %hsPidsAndTimestamps = ();
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   343
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   344
	my $sLetterToRelease = '';
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   345
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   346
	my $nAttempts = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   347
	my $bAcquired = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   348
	do
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   349
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   350
		open(FILE, "+<$sWORKING_DRIVE\\$sLETTERS_FILE") or die("Can't open $sWORKING_DRIVE\\$sLETTERS_FILE");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   351
		if ( flock(FILE, 6) )
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   352
		{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   353
			my $sLine;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   354
			while ($sLine = <FILE>)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   355
			{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   356
				if ($sLine =~ m%([^,]*),(.*)%)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   357
				{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   358
					my $sLetter=$1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   359
					my $sString=$2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   360
					
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   361
					$sString=~m%([^,]*),(.*)%;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   362
					my $nPid=$1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   363
					my $nTimestamp=$2;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   364
					
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   365
					if (time()-$nTimestamp<=$nMAX_LETTER_AGE_SECONDS)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   366
					{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   367
						$hsPidsAndTimestamps{$sLetter} = $sString;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   368
					}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   369
					else
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   370
					{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   371
						# lease has expired: unsubst drive letter and don't add to hash
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   372
						system("subst $sLetter: /d");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   373
						print "forced release of letter: $sLetter (and drive unsubsted)\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   374
					}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   375
				}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   376
			}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   377
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   378
			for my $sNewLetter ('H'..'Y')
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   379
			{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   380
				if (! $hsPidsAndTimestamps{$sNewLetter})
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   381
				{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   382
					my $sTimestamp = time();
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   383
					$hsPidsAndTimestamps{$sNewLetter} = "$$,$sTimestamp";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   384
					$sLetterToRelease = $sNewLetter;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   385
					last;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   386
				}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   387
			}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   388
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   389
			seek(FILE, 0, 0);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   390
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   391
			for my $sLetter ( keys(%hsPidsAndTimestamps) )
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   392
			{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   393
				print FILE "$sLetter,$hsPidsAndTimestamps{$sLetter}\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   394
			}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   395
			truncate(FILE,tell(FILE));
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   396
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   397
			$bAcquired = 1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   398
		}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   399
		else
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   400
		{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   401
			$nAttempts ++;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   402
			sleep(3);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   403
		}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   404
		close(FILE);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   405
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   406
	until ( $bAcquired or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   407
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   408
	return $sLetterToRelease;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   409
}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   410
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   411
sub release_drive_letter
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   412
{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   413
	my ($sLetterToRelease) = @_;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   414
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   415
	my %hsPidsAndTimestamps = ();
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   416
	
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   417
	my $nAttempts = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   418
	my $bAcquired = 0;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   419
	do
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   420
	{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   421
		open(FILE, "+<$sWORKING_DRIVE\\$sLETTERS_FILE") or die("Can't open $sWORKING_DRIVE\\$sLETTERS_FILE");
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   422
		if ( flock(FILE, 6) )
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   423
		{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   424
			my $sLine;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   425
			while ($sLine = <FILE>)
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   426
			{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   427
				$hsPidsAndTimestamps{$1} = $2 if ($sLine =~ m%([^,]*),(.*)%);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   428
			}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   429
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   430
			delete $hsPidsAndTimestamps{$sLetterToRelease};
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   431
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   432
			seek(FILE, 0, 0);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   433
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   434
			for my $sLetter ( keys(%hsPidsAndTimestamps) )
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   435
			{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   436
				print FILE "$sLetter,$hsPidsAndTimestamps{$sLetter}\n";
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   437
			}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   438
			truncate(FILE,tell(FILE));
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   439
			
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   440
			$bAcquired = 1;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   441
		}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   442
		else
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   443
		{
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   444
			$nAttempts ++;
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   445
			sleep(3);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   446
		}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   447
		close(FILE);
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   448
	}
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   449
	until ( $bAcquired or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
e643758258cb Add build_platform.pl script
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   450
}