build_package.pl
author Dario Sestito <darios@symbian.org>
Thu, 30 Jul 2009 18:00:18 +0100
changeset 32 11821242bc3e
parent 31 7d05cbb136ad
child 33 4d7642508510
permissions -rw-r--r--
Make G: the working drive (unless not ready) and D: the second option
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";
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    22
my $sJOB_BASE_DIR="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";
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    26
my $sLETTERS_FILE="letters.txt";
13
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";
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    65
	print "\t--nopublish Use 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
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    81
my $sWORKING_DRIVE = "G:";
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    82
my $output = `G: 2>&1`;
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    83
$sWORKING_DRIVE = "D:" if ($output =~ /The device is not ready./);
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    84
print "Will use drive $sWORKING_DRIVE as working drive for this build\n";
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    85
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    86
my $sFbfProjectRev = '';
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    87
if ($sFbfProjectRepo =~ m,(.*)#(.*),)
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    88
{
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    89
	$sFbfProjectRepo = $1;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    90
	$sFbfProjectRev = $2;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    91
}
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    92
my $sFbfConfigRev = '';
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    93
if ($sFbfConfigRepo =~ m,(.*)#(.*),)
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    94
{
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    95
	$sFbfConfigRepo = $1;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    96
	$sFbfConfigRev = $2;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    97
}
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    98
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    99
my $sTestBuildOpt = "";
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
   100
$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
   101
my $sNoPublishOpt = "";
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
   102
$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
   103
$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
   104
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   105
my $sJobLabel = 'job';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   106
if ($sSubProject)
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
	$sSubProject =~ 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 ($sFbfProjectRepo)
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
	$sFbfProjectRepo =~ 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 ($sFbfProjectDir)
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
	$sFbfProjectDir =~ m,(.*[\\/])?([^\\^/]+),;
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
}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   121
#elsif ($sSourcesFile)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   122
#{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   123
#	$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
   124
#	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   125
#	$sSourcesFile =~ m,(.*[\\/])?([^\\^/]+),;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   126
#	$sJobLabel = $2 if (!$sJobLabel);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   127
#}
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   128
mkdir("$sWORKING_DRIVE\\$sJOB_BASE_DIR") if (!-d "$sWORKING_DRIVE\\$sJOB_BASE_DIR");
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   129
my $sJobDir = mkdir_unique("$sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel");
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   130
print "Created project dir $sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   131
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   132
print("cd $sBOOTSTRAP_DIR\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   133
chdir("$sBOOTSTRAP_DIR");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   134
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
   135
my $sConfigArg = "-Dsf.config.repo=$sFbfConfigRepo";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   136
$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
   137
$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
   138
my $sProjectArg = "-Dsf.project.repo=$sFbfProjectRepo";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   139
$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
   140
$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
   141
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
   142
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
   143
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   144
# 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
   145
if (!-f $sNUMBERS_FILE)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   146
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   147
	open FILE, ">$sNUMBERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   148
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   149
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   150
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   151
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
   152
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
   153
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
   154
{
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
   155
	$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
   156
}
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
   157
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
   158
{
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   159
	my $sJobNumberKey = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   160
	if ($sSubProject)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   161
	{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   162
		# 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
   163
		$sSubProject =~ m,^([^/]+)/[^/]+/([^/]+)$,;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   164
		$sJobNumberKey = "$2_$1";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   165
	}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   166
	else
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   167
	{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   168
		# 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
   169
		my $sRevZeroHash = get_rev_zero_hash($sFbfProjectRepo);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   170
		$sJobNumberKey = $sRevZeroHash;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   171
	}
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
   172
	$sJobNumberKey .= ".T" if (!$bProduction);
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
   173
	$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
   174
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   175
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
   176
$nJobNumber = "T$nJobNumber" if (!$bProduction);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   177
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   178
# check that $sLETTERS_FILE exists, otherwise create it
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   179
if (!-f "$sWORKING_DRIVE\\$sLETTERS_FILE")
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   180
{
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   181
	open FILE, ">$sWORKING_DRIVE\\$sLETTERS_FILE";
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   182
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   183
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   184
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   185
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   186
# acquire drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   187
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
   188
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
   189
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
   190
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   191
my $sSubProjArg = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   192
$sSubProjArg = "-Dsf.subproject.path=$sSubProject" if ($sSubProject);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   193
print("cd $sJobDir\\sf-config\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   194
chdir("$sJobDir\\sf-config");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   195
print "###### BUILD PREPARATION ######\n";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   196
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
   197
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
   198
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   199
print "###### EXECUTE BUILD ######\n";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   200
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
   201
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
   202
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   203
# release the drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   204
release_drive_letter($sDriveLetter);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   205
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
   206
print "drive letter $sDriveLetter released (and drive unsubsted)\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   207
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   208
sub mkdir_unique
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   209
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   210
	my ($sBaseDir) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   211
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   212
	# 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
   213
	$sBaseDir =~ m,(.*[\\/])?(.*),;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   214
	mkpath($1) if ($1 && !-d $1);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   215
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   216
	my $nI = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   217
	my $sNewDirName = "$sBaseDir";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   218
	while(!mkdir($sNewDirName))
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   219
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   220
		$nI++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   221
		$sNewDirName = "$sBaseDir.$nI";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   222
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   223
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   224
	return $sNewDirName;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   225
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   226
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
   227
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
   228
{
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
	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
   230
	
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
	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
   232
	
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
	# 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
   234
	$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
   235
	$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
   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
	# 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
   238
	$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
   239
	
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
   240
	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
   241
}
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
   242
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   243
sub get_job_number
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   244
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   245
	my ($sKey) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   246
	
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   247
	$sKey=lc($sKey);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   248
	
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   249
	my %hnNumbers = ();
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   250
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   251
	my $nAttempts = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   252
	my $bGotNumber = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   253
	do
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   254
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   255
		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
   256
		if ( flock(FILE, 6) )
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
			my $sLine;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   259
			while ($sLine = <FILE>)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   260
			{
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   261
				$hnNumbers{lc($1)} = $2 if ($sLine =~ m%(.*),(.*)%);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   262
			}
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
			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   265
			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   266
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   267
			seek(FILE, 0, 0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   268
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   269
			for my $sStr ( keys(%hnNumbers) )
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   270
			{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   271
				print FILE "$sStr,$hnNumbers{$sStr}\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   272
			}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   273
			truncate(FILE,tell(FILE));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   274
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   275
			$bGotNumber = 1;
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
		else
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
			$nAttempts ++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   280
			sleep(3);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   281
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   282
		close(FILE);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   283
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   284
	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   285
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   286
	return $hnNumbers{$sKey};
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   287
}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   288
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   289
sub acquire_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   290
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   291
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   292
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   293
	my $sLetterToRelease = '';
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   294
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   295
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   296
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   297
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   298
	{
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   299
		open(FILE, "+<$sWORKING_DRIVE\\$sLETTERS_FILE") or die("Can't open $sWORKING_DRIVE\\$sLETTERS_FILE");
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   300
		if ( flock(FILE, 6) )
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 $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   303
			while ($sLine = <FILE>)
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
				if ($sLine =~ m%([^,]*),(.*)%)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   306
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   307
					my $sLetter=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   308
					my $sString=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   309
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   310
					$sString=~m%([^,]*),(.*)%;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   311
					my $nPid=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   312
					my $nTimestamp=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   313
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   314
					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
   315
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   316
						$hsPidsAndTimestamps{$sLetter} = $sString;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   317
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   318
					else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   319
					{
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
   320
						# 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
   321
						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
   322
						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
   323
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   324
				}
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
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   327
			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
   328
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   329
				if (! $hsPidsAndTimestamps{$sNewLetter})
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
					my $sTimestamp = time();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   332
					$hsPidsAndTimestamps{$sNewLetter} = "$$,$sTimestamp";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   333
					$sLetterToRelease = $sNewLetter;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   334
					last;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   335
				}
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
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   338
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   339
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   340
			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
   341
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   342
				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
   343
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   344
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   345
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   346
			$bAcquired = 1;
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
		else
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
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   351
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   352
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   353
		close(FILE);
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
	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
   356
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   357
	return $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
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   360
sub release_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   361
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   362
	my ($sLetterToRelease) = @_;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   363
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   364
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   365
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   366
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   367
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   368
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   369
	{
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   370
		open(FILE, "+<$sWORKING_DRIVE\\$sLETTERS_FILE") or die("Can't open $sWORKING_DRIVE\\$sLETTERS_FILE");
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   371
		if ( flock(FILE, 6) )
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
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   374
			while ($sLine = <FILE>)
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
				$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
   377
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   378
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   379
			delete $hsPidsAndTimestamps{$sLetterToRelease};
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   380
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   381
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   382
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   383
			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
   384
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   385
				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
   386
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   387
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   388
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   389
			$bAcquired = 1;
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
		else
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
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   394
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   395
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   396
		close(FILE);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   397
	}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   398
	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
   399
}