build_package.pl
author Dario Sestito <darios@symbian.org>
Tue, 28 Jul 2009 18:19:25 +0100
changeset 31 7d05cbb136ad
parent 29 b9212509f335
child 32 11821242bc3e
permissions -rw-r--r--
Enable package builds from one common repository
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     1
# Copyright (c) 2009 Symbian Foundation Ltd
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     2
# This component and the accompanying materials are made available
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     3
# under the terms of the License "Eclipse Public License v1.0"
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     4
# which accompanies this distribution, and is available
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     5
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     6
#
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     7
# Initial Contributors:
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     8
# Symbian Foundation Ltd - initial contribution.
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
     9
#
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    10
# Contributors:
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    11
#
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    12
# Description:
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    13
# This is a helper script which allocates unique drive letter and build number
45ed0efeb8a4 Added copyright header to build_package.pl
darios@symbian.org
parents: 14
diff changeset
    14
# then starts a package build by running FBF bootstrap and build targets
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    15
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    16
use strict;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    17
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    18
use Getopt::Long;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    19
use File::Path;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    20
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    21
my $sBOOTSTRAP_DIR="C:\\Apps\\FBF\\bootstrap";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    22
my $sJOB_BASE_DIR="D:\\fbf_project";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    23
my $nMAX_JOBDIR_AGE_SECONDS = 86400; # max number of seconds after which the letter is forcibly released
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    24
my $nLOCK_FILE_MAX_ATTEMPTS = 5;
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    25
my $sNUMBERS_FILE="\\\\bishare\\SF_builds\\numbers2.txt";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
    26
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
    27
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
    28
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    29
my $sFbfProjectRepo = "\\\\bishare\\mercurial_internal\\fbf\\projects\\packages";
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    30
my $sFbfProjectDir = '';
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    31
my $sSubProject = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    32
#my $sSourcesFile = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    33
#my $sModelFile = '';
21
4b02facbff8f Changed path to take account of new bishare alias
Dario Sestito <darios@symbian.org>
parents: 19
diff changeset
    34
my $sFbfConfigRepo="\\\\bishare\\mercurial_internal\\fbf\\configs\\pkgbuild";
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
    35
my $sFbfConfigDir = '';
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    36
my $nCmdLineNumber;
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
    37
my $bProduction = 0;
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    38
my $bPublish = 1;
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
    39
GetOptions((
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    40
	'configrepo=s' => \$sFbfConfigRepo,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    41
	'configdir=s' => \$sFbfConfigDir,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    42
	'projectrepo=s' => \$sFbfProjectRepo,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    43
	'projectdir=s' => \$sFbfProjectDir,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    44
	'subproj=s' => \$sSubProject,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    45
	#'sources=s' => \$sSourcesFile,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    46
	#'model=s' => \$sModelFile,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    47
	'number=s' => \$nCmdLineNumber,
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
    48
	'production!' => \$bProduction,
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    49
	'publish!' => \$bPublish
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
    50
));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    51
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    52
if (!$sSubProject)
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    53
{
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    54
	print "Usage: build_package.pl --subproj=RELPATH [OPTIONS]\n";
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    55
	print "where OPTIONS are:\n";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    56
	print "\t--subproj=RELPATH Select subproject located at RELPATH (relative to the root of the project repository)\n";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    57
	print "\t--projectrepo=REPO[#REV] Use repository REPO at revision REV for the project (instead of \\\\bishare\\mercurial_internal\\fbf\\projects\\packages)\n";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    58
	print "\t--projectdir=DIR Use DIR location for the project (exclusive with --projectrepo).\n";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    59
	#print "\t--sources=FILE ...\n";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    60
	#print "\t--model=FILE ...\n";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    61
	print "\t--configrepo=REPO[#REV] Use repository REPO at revision REV for the config (instead of \\\\bishare\\mercurial_internal\\fbf\\config\\pkgbuild)\n";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    62
	print "\t--configdir=DIR Use DIR location for the config (exclusive with --configrepo).\n";
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
    63
	print "\t--number=N Force build number to N\n";
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
    64
	print "\t--production Tag this build as 'production' (default: 'test') and use nnn numbering (default: Tnnn)\n";
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    65
	print "\t--nopublish Use d:\\numbers_test.txt for numbers and disable publishing\n";
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    66
	exit(0);
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    67
}
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    68
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    69
if ($sSubProject !~ m,^([^/]+)/[^/]+/([^/]+)$,)
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    70
{
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    71
	print "Error: Option --subproj must be in the format codeline/layer/package (e.g. MCL/os/boardsupport)\n";
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    72
	exit(0);
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    73
}
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
    74
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    75
#if (!$sFbfProjectRepo and !$sFbfProjectDir and (!$sSourcesFile or !$sModelFile))
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    76
#{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    77
#	print "Error: If you don't provide --projectrepo or --projectdir then you have to provide both --sources and --model\n";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    78
#	exit(0);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    79
#}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    80
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    81
my $sFbfProjectRev = '';
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    82
if ($sFbfProjectRepo =~ m,(.*)#(.*),)
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    83
{
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    84
	$sFbfProjectRepo = $1;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    85
	$sFbfProjectRev = $2;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    86
}
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    87
my $sFbfConfigRev = '';
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    88
if ($sFbfConfigRepo =~ m,(.*)#(.*),)
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    89
{
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    90
	$sFbfConfigRepo = $1;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    91
	$sFbfConfigRev = $2;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    92
}
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    93
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    94
my $sTestBuildOpt = "";
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
    95
$sTestBuildOpt = "-Dsf.spec.publish.diamonds.tag=production" if ( $bProduction );
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    96
my $sNoPublishOpt = "";
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    97
$sNoPublishOpt = "-Dsf.spec.publish.enable=false" if ( !$bPublish );
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    98
$sNUMBERS_FILE = "d:\\numbers_test.txt" if ( !$bPublish );
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
    99
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   100
my $sJobLabel = 'job';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   101
if ($sSubProject)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   102
{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   103
	$sSubProject =~ m,^([^/]+)/[^/]+/([^/]+)$,;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   104
	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   105
}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   106
elsif ($sFbfProjectRepo)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   107
{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   108
	$sFbfProjectRepo =~ m,(.*[\\/])?([^\\^/]+),;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   109
	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   110
}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   111
elsif ($sFbfProjectDir)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   112
{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   113
	$sFbfProjectDir =~ m,(.*[\\/])?([^\\^/]+),;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   114
	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   115
}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   116
#elsif ($sSourcesFile)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   117
#{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   118
#	$sSourcesFile =~ m,/(adaptation|app|mw|os|ostools|tools)[\\/]([^\\^/]+),i;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   119
#	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   120
#	$sSourcesFile =~ m,(.*[\\/])?([^\\^/]+),;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   121
#	$sJobLabel = $2 if (!$sJobLabel);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   122
#}
23
435ecee4ea5d Create sJOB_BASE_DIR if it doesn't exist
royt <tathagatar@symbian.org>
parents: 22
diff changeset
   123
mkdir($sJOB_BASE_DIR) if (!-d$sJOB_BASE_DIR);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   124
my $sJobDir = mkdir_unique("$sJOB_BASE_DIR\\$sJobLabel");
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   125
print "Created project dir $sJOB_BASE_DIR\\$sJobLabel\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   126
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   127
print("cd $sBOOTSTRAP_DIR\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   128
chdir("$sBOOTSTRAP_DIR");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   129
print "###### BOOTSTRAP ######\n";
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
   130
my $sConfigArg = "-Dsf.config.repo=$sFbfConfigRepo";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   131
$sConfigArg .= " -Dsf.config.rev=$sFbfConfigRev" if ($sFbfConfigRev);
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
   132
$sConfigArg = "-Dsf.config.dir=$sFbfConfigDir" if ($sFbfConfigDir);
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
   133
my $sProjectArg = "-Dsf.project.repo=$sFbfProjectRepo";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   134
$sProjectArg .= " -Dsf.project.rev=$sFbfProjectRev" if ($sFbfProjectRev);
16
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
   135
$sProjectArg = "-Dsf.project.dir=$sFbfProjectDir" if ($sFbfProjectDir);
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
   136
print("hlm -f bootstrap.xml $sConfigArg $sProjectArg -Dsf.target.dir=$sJobDir\n");
e1b9f78cef38 Project spec and config to be taken from a dir instead of from a repo
darios@symbian.org
parents: 15
diff changeset
   137
system("hlm -f bootstrap.xml $sConfigArg $sProjectArg -Dsf.target.dir=$sJobDir");
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   138
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   139
# 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
   140
if (!-f $sNUMBERS_FILE)
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
	open FILE, ">$sNUMBERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   143
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   144
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   145
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   146
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   147
my $nUnformattedNumber = 0;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   148
if ($nCmdLineNumber)
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   149
{
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   150
	$nUnformattedNumber = $nCmdLineNumber;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   151
}
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   152
elsif ($sFbfProjectRepo)
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   153
{
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   154
	my $sJobNumberKey = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   155
	if ($sSubProject)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   156
	{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   157
		# key = <package>_<codeline>, e.g. for subproj=MCL/os/boardsupport -> key=boardsupport_MCL
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   158
		$sSubProject =~ m,^([^/]+)/[^/]+/([^/]+)$,;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   159
		$sJobNumberKey = "$2_$1";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   160
	}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   161
	else
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   162
	{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   163
		# key = hash of the rev.0 of the package project repo
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   164
		my $sRevZeroHash = get_rev_zero_hash($sFbfProjectRepo);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   165
		$sJobNumberKey = $sRevZeroHash;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   166
	}
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
   167
	$sJobNumberKey .= ".T" if (!$bProduction);
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
   168
	$nUnformattedNumber = get_job_number($sJobNumberKey);
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   169
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   170
my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
   171
$nJobNumber = "T$nJobNumber" if (!$bProduction);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   172
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   173
# 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
   174
if (!-f $sLETTERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   175
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   176
	open FILE, ">$sLETTERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   177
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   178
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   179
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   180
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   181
# acquire drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   182
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
   183
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
   184
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
   185
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   186
my $sSubProjArg = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   187
$sSubProjArg = "-Dsf.subproject.path=$sSubProject" if ($sSubProject);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   188
print("cd $sJobDir\\sf-config\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   189
chdir("$sJobDir\\sf-config");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   190
print "###### BUILD PREPARATION ######\n";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   191
print("hlm sf-prep -Dsf.project.type=package $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt\n");
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   192
system("hlm sf-prep -Dsf.project.type=package $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt");
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   193
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   194
print "###### EXECUTE BUILD ######\n";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   195
print("hlm sf-build-all -Dsf.project.type=package $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt\n");
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   196
system("hlm sf-build-all -Dsf.project.type=package $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt");
13
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
# release the drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   199
release_drive_letter($sDriveLetter);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   200
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
   201
print "drive letter $sDriveLetter released (and drive unsubsted)\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   202
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   203
sub mkdir_unique
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   204
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   205
	my ($sBaseDir) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   206
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   207
	# 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
   208
	$sBaseDir =~ m,(.*[\\/])?(.*),;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   209
	mkpath($1) if ($1 && !-d $1);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   210
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   211
	my $nI = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   212
	my $sNewDirName = "$sBaseDir";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   213
	while(!mkdir($sNewDirName))
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   214
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   215
		$nI++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   216
		$sNewDirName = "$sBaseDir.$nI";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   217
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   218
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   219
	return $sNewDirName;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   220
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   221
22
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   222
sub get_rev_zero_hash
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   223
{
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   224
	my ($sFbfProjectRepo) = @_;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   225
	
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   226
	my $sOutput = `hg -R $sFbfProjectRepo identify -r0`;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   227
	
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   228
	# remove leading and trailing spaces
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   229
	$sOutput =~ s,^\s+,,;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   230
	$sOutput =~ s,\s+$,,;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   231
	
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   232
	# remove tags e.g. "1fc39a7e9d79 tip"
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   233
	$sOutput =~ s,([0-9a-z]+)\s+.*,$1,;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   234
	
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   235
	return $sOutput;
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   236
}
7a9425957569 Label to be retrieved automatically from project repo path, numbers file indexed by revision zero hash
Dario Sestito <darios@symbian.org>
parents: 21
diff changeset
   237
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   238
sub get_job_number
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   239
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   240
	my ($sKey) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   241
	
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   242
	$sKey=lc($sKey);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   243
	
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   244
	my %hnNumbers = ();
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   245
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   246
	my $nAttempts = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   247
	my $bGotNumber = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   248
	do
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   249
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   250
		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
   251
		if ( flock(FILE, 6) )
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   252
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   253
			my $sLine;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   254
			while ($sLine = <FILE>)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   255
			{
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   256
				$hnNumbers{lc($1)} = $2 if ($sLine =~ m%(.*),(.*)%);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   257
			}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   258
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   259
			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   260
			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   261
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   262
			seek(FILE, 0, 0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   263
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   264
			for my $sStr ( keys(%hnNumbers) )
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   265
			{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   266
				print FILE "$sStr,$hnNumbers{$sStr}\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   267
			}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   268
			truncate(FILE,tell(FILE));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   269
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   270
			$bGotNumber = 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   271
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   272
		else
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   273
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   274
			$nAttempts ++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   275
			sleep(3);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   276
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   277
		close(FILE);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   278
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   279
	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   280
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   281
	return $hnNumbers{$sKey};
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   282
}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   283
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   284
sub acquire_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   285
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   286
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   287
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   288
	my $sLetterToRelease = '';
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   289
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   290
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   291
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   292
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   293
	{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   294
		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
   295
		if ( flock(FILE, 6) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   296
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   297
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   298
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   299
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   300
				if ($sLine =~ m%([^,]*),(.*)%)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   301
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   302
					my $sLetter=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   303
					my $sString=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   304
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   305
					$sString=~m%([^,]*),(.*)%;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   306
					my $nPid=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   307
					my $nTimestamp=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   308
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   309
					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
   310
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   311
						$hsPidsAndTimestamps{$sLetter} = $sString;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   312
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   313
					else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   314
					{
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
   315
						# lease has expired: unsubst drive letter and don't add to hash
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
   316
						system("subst $sLetter: /d");
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
   317
						print "forced release of letter: $sLetter (and drive unsubsted)\n";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   318
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   319
				}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   320
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   321
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   322
			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
   323
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   324
				if (! $hsPidsAndTimestamps{$sNewLetter})
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   325
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   326
					my $sTimestamp = time();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   327
					$hsPidsAndTimestamps{$sNewLetter} = "$$,$sTimestamp";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   328
					$sLetterToRelease = $sNewLetter;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   329
					last;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   330
				}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   331
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   332
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   333
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   334
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   335
			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
   336
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   337
				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
   338
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   339
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   340
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   341
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   342
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   343
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   344
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   345
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   346
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   347
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   348
		close(FILE);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   349
	}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   350
	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
   351
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   352
	return $sLetterToRelease;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   353
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   354
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   355
sub release_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   356
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   357
	my ($sLetterToRelease) = @_;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   358
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   359
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   360
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   361
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   362
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   363
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   364
	{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   365
		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
   366
		if ( flock(FILE, 6) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   367
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   368
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   369
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   370
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   371
				$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
   372
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   373
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   374
			delete $hsPidsAndTimestamps{$sLetterToRelease};
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   375
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   376
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   377
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   378
			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
   379
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   380
				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
   381
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   382
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   383
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   384
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   385
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   386
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   387
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   388
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   389
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   390
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   391
		close(FILE);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   392
	}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   393
	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
   394
}