build_package.pl
author Dario Sestito <darios@symbian.org>
Mon, 10 Aug 2009 14:24:35 +0100
changeset 40 6661369591af
parent 39 d6975a94a893
child 41 177164b3c155
permissions -rw-r--r--
Build console output must be redirected to file but must also go to console
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;
39
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
    25
my $sREMOTE_LOG_ARCHIVE="\\\\bishare\SF_builds";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    26
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
    27
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
    28
my $nMAX_LETTER_AGE_SECONDS = 86400; # max number of seconds after which the letter is forcibly released
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    29
38
6da50515cbeb Fix start package build with no --subproj option, pointed defaults to mercurial_development
Dario Sestito <darios@symbian.org>
parents: 37
diff changeset
    30
my $sFbfProjectRepo = "\\\\bishare\\mercurial_development\\oss\\FCL\\interim\\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
    31
my $sFbfProjectDir = '';
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    32
my $sSubProject = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    33
#my $sSourcesFile = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    34
#my $sModelFile = '';
38
6da50515cbeb Fix start package build with no --subproj option, pointed defaults to mercurial_development
Dario Sestito <darios@symbian.org>
parents: 37
diff changeset
    35
my $sFbfConfigRepo="\\\\bishare\\mercurial_development\\oss\\FCL\\interim\\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
    36
my $sFbfConfigDir = '';
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    37
my $nCmdLineNumber;
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
    38
my $bProduction = 0;
34
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    39
my $sDiamondsTag = '';
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    40
my $bHudson = 0;
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    41
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
    42
GetOptions((
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    43
	'configrepo=s' => \$sFbfConfigRepo,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    44
	'configdir=s' => \$sFbfConfigDir,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    45
	'projectrepo=s' => \$sFbfProjectRepo,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    46
	'projectdir=s' => \$sFbfProjectDir,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    47
	'subproj=s' => \$sSubProject,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    48
	#'sources=s' => \$sSourcesFile,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    49
	#'model=s' => \$sModelFile,
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    50
	'number=s' => \$nCmdLineNumber,
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
    51
	'production!' => \$bProduction,
34
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    52
	'tag=s' => \$sDiamondsTag,
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    53
	'hudson!' => \$bHudson,
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
    54
	'publish!' => \$bPublish
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
    55
));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    56
38
6da50515cbeb Fix start package build with no --subproj option, pointed defaults to mercurial_development
Dario Sestito <darios@symbian.org>
parents: 37
diff changeset
    57
if (!($sSubProject or $sFbfProjectRepo or $sFbfProjectDir))
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    58
{
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    59
	print "Usage: build_package.pl --subproj=RELPATH [OPTIONS]\n";
38
6da50515cbeb Fix start package build with no --subproj option, pointed defaults to mercurial_development
Dario Sestito <darios@symbian.org>
parents: 37
diff changeset
    60
	print "       build_package.pl --projectrepo=REPO [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
    61
	print "where OPTIONS are:\n";
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    62
	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
    63
	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
    64
	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
    65
	#print "\t--sources=FILE ...\n";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    66
	#print "\t--model=FILE ...\n";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
    67
	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
    68
	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
    69
	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
    70
	print "\t--production Tag this build as 'production' (default: 'test') and use nnn numbering (default: Tnnn)\n";
34
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    71
	print "\t--tag=TAG Apply Diamonds tag TAG to this build (exclusive with --production)\n";
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    72
	print "\t--hudson Checks that there is at least NUMBER_OF_PROCESSORS X 10 GB available on the working drive\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
    73
	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
    74
	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
    75
}
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
    76
38
6da50515cbeb Fix start package build with no --subproj option, pointed defaults to mercurial_development
Dario Sestito <darios@symbian.org>
parents: 37
diff changeset
    77
if ($sSubProject and $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
    78
{
34
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    79
	print "ERROR: Option --subproj must be in the format codeline/layer/package (e.g. MCL/os/boardsupport)\n";
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    80
	exit(0);
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    81
}
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    82
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    83
if ($bProduction and $sDiamondsTag)
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    84
{
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
    85
	print "ERROR: Options --production and --tag are mutually exclusive.\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
    86
	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
    87
}
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
    88
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    89
#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
    90
#{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    91
#	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
    92
#	exit(0);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
    93
#}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
    94
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
    95
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
    96
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
    97
$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
    98
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
    99
34
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   100
if ($bHudson)
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   101
{
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   102
	my $nProcessors = $ENV{'NUMBER_OF_PROCESSORS'};
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   103
	my $diroutput = `dir /-C $sWORKING_DRIVE`;
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   104
	my $nBytesFree = 0;
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   105
	$nBytesFree = $1 if ($diroutput =~ /(\d+) bytes free/);
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   106
	my $nNeededSpace = 10*$nProcessors*1073741824;
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   107
	#print "Needed space is $nNeededSpace\n";
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   108
	if ($nBytesFree < $nNeededSpace)
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   109
	{
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   110
		print "ERROR: Available disk space on working drive ($nBytesFree bytes) is not enough to run a package build with Hudson.\n";
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   111
		exit(1);
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   112
	}
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   113
}
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   114
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   115
my $sFbfProjectRev = '';
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   116
if ($sFbfProjectRepo =~ m,(.*)#(.*),)
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   117
{
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   118
	$sFbfProjectRepo = $1;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   119
	$sFbfProjectRev = $2;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   120
}
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   121
my $sFbfConfigRev = '';
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   122
if ($sFbfConfigRepo =~ m,(.*)#(.*),)
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   123
{
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   124
	$sFbfConfigRepo = $1;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   125
	$sFbfConfigRev = $2;
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   126
}
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   127
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
   128
my $sTestBuildOpt = "";
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
   129
$sTestBuildOpt = "-Dsf.spec.publish.diamonds.tag=production" if ( $bProduction );
34
d156d56b00c2 Add --hudson option to check availability of space on working drive. Add --tag option to allow arbitrary Diamonds tags
Dario Sestito <darios@symbian.org>
parents: 33
diff changeset
   130
$sTestBuildOpt = "-Dsf.spec.publish.diamonds.tag=$sDiamondsTag" if ( $sDiamondsTag );
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
   131
my $sNoPublishOpt = "";
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
   132
$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
   133
$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
   134
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   135
my $sJobLabel = 'job';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   136
if ($sSubProject)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   137
{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   138
	$sSubProject =~ m,^([^/]+)/[^/]+/([^/]+)$,;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   139
	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   140
}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   141
elsif ($sFbfProjectRepo)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   142
{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   143
	$sFbfProjectRepo =~ m,(.*[\\/])?([^\\^/]+),;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   144
	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   145
}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   146
elsif ($sFbfProjectDir)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   147
{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   148
	$sFbfProjectDir =~ m,(.*[\\/])?([^\\^/]+),;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   149
	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   150
}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   151
#elsif ($sSourcesFile)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   152
#{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   153
#	$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
   154
#	$sJobLabel = $2;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   155
#	$sSourcesFile =~ m,(.*[\\/])?([^\\^/]+),;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   156
#	$sJobLabel = $2 if (!$sJobLabel);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   157
#}
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   158
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
   159
my $sJobDir = mkdir_unique("$sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel");
35
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   160
print "Created project dir $sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobDir\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   161
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   162
print("cd $sBOOTSTRAP_DIR\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   163
chdir("$sBOOTSTRAP_DIR");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   164
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
   165
my $sConfigArg = "-Dsf.config.repo=$sFbfConfigRepo";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   166
$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
   167
$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
   168
my $sProjectArg = "-Dsf.project.repo=$sFbfProjectRepo";
24
ed4e68942437 Allow revisions for projects and configs
Dario Sestito <darios@symbian.org>
parents: 22
diff changeset
   169
$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
   170
$sProjectArg = "-Dsf.project.dir=$sFbfProjectDir" if ($sFbfProjectDir);
40
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   171
my $sBootstrapCmd = "hlm -f bootstrap.xml $sConfigArg $sProjectArg -Dsf.target.dir=$sJobDir";
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   172
print("$sBootstrapCmd\n");
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   173
open(LOG, ">console_bootstrap_$$.txt")
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   174
open(PIPE, "$sBootstrapCmd 2>&1 |");
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   175
while(<PIPE>)
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   176
{
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   177
	print LOG $_;
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   178
	print $_;
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   179
}
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   180
close(PIPE);
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   181
close(LOG);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   182
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   183
# 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
   184
if (!-f $sNUMBERS_FILE)
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
	open FILE, ">$sNUMBERS_FILE";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   187
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   188
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   189
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   190
35
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   191
my $sJobNumberKey = '';
39
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   192
my $sPackage = '';
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   193
my $sPlatform = '';
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
   194
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
   195
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
   196
{
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
   197
	$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
   198
}
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
   199
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
   200
{
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   201
	if ($sSubProject)
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   202
	{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   203
		# 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
   204
		$sSubProject =~ m,^([^/]+)/[^/]+/([^/]+)$,;
39
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   205
		$sPackage = $2;
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   206
		$sPlatform = $1;
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   207
		$sJobNumberKey = "$2_$1";
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   208
	}
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   209
	else
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   210
	{
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   211
		# 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
   212
		my $sRevZeroHash = get_rev_zero_hash($sFbfProjectRepo);
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   213
		$sJobNumberKey = $sRevZeroHash;
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   214
	}
29
b9212509f335 Default to test build: removed --testbuild option and added --production
Dario Sestito <darios@symbian.org>
parents: 28
diff changeset
   215
	$sJobNumberKey .= ".T" if (!$bProduction);
28
bf45384632b0 Add support for --testbuild and --nopublish options
Dario Sestito <darios@symbian.org>
parents: 27
diff changeset
   216
	$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
   217
}
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   218
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
   219
$nJobNumber = "T$nJobNumber" if (!$bProduction);
35
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   220
print "For build key $sJobNumberKey got assigned number \"$nJobNumber\"\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   221
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   222
# 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
   223
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
   224
{
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   225
	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
   226
	print FILE "\n";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   227
	close FILE;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   228
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   229
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   230
# acquire drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   231
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
   232
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
   233
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
   234
33
4d7642508510 Pass the job rootdir as parameter to helium
Dario Sestito <darios@symbian.org>
parents: 32
diff changeset
   235
my $sJobRootDirArg = "-Dsf.spec.job.rootdir=$sWORKING_DRIVE\\fbf_job";
4d7642508510 Pass the job rootdir as parameter to helium
Dario Sestito <darios@symbian.org>
parents: 32
diff changeset
   236
31
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   237
my $sSubProjArg = '';
7d05cbb136ad Enable package builds from one common repository
Dario Sestito <darios@symbian.org>
parents: 29
diff changeset
   238
$sSubProjArg = "-Dsf.subproject.path=$sSubProject" if ($sSubProject);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   239
print("cd $sJobDir\\sf-config\n");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   240
chdir("$sJobDir\\sf-config");
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   241
print "###### BUILD PREPARATION ######\n";
40
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   242
my $sPreparationCmd = "hlm sf-prep -Dsf.project.type=package $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt $sJobRootDirArg";
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   243
print("$sPreparationCmd\n");
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   244
open(LOG, ">console_sfprep_$$.txt")
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   245
open(PIPE, "$sPreparationCmd 2>&1 |");
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   246
while(<PIPE>)
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   247
{
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   248
	print LOG $_;
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   249
	print $_;
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   250
}
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   251
close(PIPE);
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   252
close(LOG);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   253
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   254
print "###### EXECUTE BUILD ######\n";
40
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   255
my $sBuildallCmd = "hlm sf-build-all -Dsf.project.type=package $sSubProjArg -Dsf.spec.job.number=$nJobNumber -Dsf.spec.job.drive=$sDriveLetter: $sTestBuildOpt $sNoPublishOpt $sJobRootDirArg";
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   256
print("$sBuildallCmd\n");
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   257
open(LOG, ">console_sfbuildall_$$.txt")
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   258
open(PIPE, "$sBuildallCmd 2>&1 |");
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   259
while(<PIPE>)
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   260
{
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   261
	print LOG $_;
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   262
	print $_;
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   263
}
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   264
close(PIPE);
6661369591af Build console output must be redirected to file but must also go to console
Dario Sestito <darios@symbian.org>
parents: 39
diff changeset
   265
close(LOG);
39
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   266
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   267
# copy console outputs to remote log archive
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   268
if (-d "$sREMOTE_LOG_ARCHIVE\\$sPackage\\builds\\$sPlatform\\$sPackage\_$sPlatform.$nJobNumber\\logs")
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   269
{
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   270
	my $sTgtDir = "$sREMOTE_LOG_ARCHIVE\\$sPackage\\builds\\$sPlatform\\$sPackage\_$sPlatform.$nJobNumber\\logs\\console";
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   271
	system("mkdir $sTgtDir");
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   272
	system("copy /Y $sBOOTSTRAP_DIR\\console_bootstrap_$$.txt $sTgtDir");
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   273
	system("del $sBOOTSTRAP_DIR\\console_bootstrap_$$.txt");
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   274
	system("copy $sJobDir\\sf-config\\console_sfprep_$$.txt $sTgtDir");
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   275
	system("copy $sJobDir\\sf-config\\console_sfbuildall_$$.txt $sTgtDir");
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   276
}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   277
37
2e0ebeeeaf52 Change back to bootstrap dir after the build to allow removal of project dir
Dario Sestito <darios@symbian.org>
parents: 36
diff changeset
   278
print("cd $sBOOTSTRAP_DIR\n");
2e0ebeeeaf52 Change back to bootstrap dir after the build to allow removal of project dir
Dario Sestito <darios@symbian.org>
parents: 36
diff changeset
   279
chdir("$sBOOTSTRAP_DIR");
2e0ebeeeaf52 Change back to bootstrap dir after the build to allow removal of project dir
Dario Sestito <darios@symbian.org>
parents: 36
diff changeset
   280
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   281
# release the drive letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   282
release_drive_letter($sDriveLetter);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   283
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
   284
print "drive letter $sDriveLetter released (and drive unsubsted)\n";
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   285
35
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   286
if ($bHudson)
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   287
{
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   288
	print "cleaning job directories...\n";
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   289
	if (-d "$sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel") # project dir
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   290
	{
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   291
		print "rmdir /S $sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel\n";
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   292
		system("rmdir /S /Q $sWORKING_DRIVE\\$sJOB_BASE_DIR\\$sJobLabel");
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   293
	}
39
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   294
	if (-d "$sWORKING_DRIVE\\fbf_job\\$sPackage\_$sPlatform.$nJobNumber") # build drive
35
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   295
	{
39
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   296
		print "rmdir /S $sWORKING_DRIVE\\fbf_job\\$sPackage\_$sPlatform.$nJobNumber\n";
d6975a94a893 Dump console output to files and upload them to \\bishare
Dario Sestito <darios@symbian.org>
parents: 38
diff changeset
   297
		system("rmdir /S /Q $sWORKING_DRIVE\\fbf_job\\$sPackage\_$sPlatform.$nJobNumber");
35
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   298
	}
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   299
}
4d500511bf5a Add removal of job directories if build is run from build management system (i.e. --hudson is given)
Dario Sestito <darios@symbian.org>
parents: 34
diff changeset
   300
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   301
sub mkdir_unique
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   302
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   303
	my ($sBaseDir) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   304
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   305
	# 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
   306
	$sBaseDir =~ m,(.*[\\/])?(.*),;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   307
	mkpath($1) if ($1 && !-d $1);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   308
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   309
	my $nI = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   310
	my $sNewDirName = "$sBaseDir";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   311
	while(!mkdir($sNewDirName))
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   312
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   313
		$nI++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   314
		$sNewDirName = "$sBaseDir.$nI";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   315
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   316
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   317
	return $sNewDirName;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   318
}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   319
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
   320
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
   321
{
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
   322
	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
   323
	
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
   324
	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
   325
	
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
   326
	# 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
   327
	$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
   328
	$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
   329
	
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
   330
	# 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
   331
	$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
   332
	
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
   333
	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
   334
}
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
   335
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   336
sub get_job_number
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   337
{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   338
	my ($sKey) = @_;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   339
	
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   340
	$sKey=lc($sKey);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   341
	
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   342
	my %hnNumbers = ();
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   343
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   344
	my $nAttempts = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   345
	my $bGotNumber = 0;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   346
	do
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   347
	{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   348
		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
   349
		if ( flock(FILE, 6) )
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   350
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   351
			my $sLine;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   352
			while ($sLine = <FILE>)
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   353
			{
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   354
				$hnNumbers{lc($1)} = $2 if ($sLine =~ m%(.*),(.*)%);
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   355
			}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   356
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   357
			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   358
			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   359
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   360
			seek(FILE, 0, 0);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   361
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   362
			for my $sStr ( keys(%hnNumbers) )
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   363
			{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   364
				print FILE "$sStr,$hnNumbers{$sStr}\n";
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   365
			}
13
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   366
			truncate(FILE,tell(FILE));
11
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   367
			
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   368
			$bGotNumber = 1;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   369
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   370
		else
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   371
		{
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   372
			$nAttempts ++;
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   373
			sleep(3);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   374
		}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   375
		close(FILE);
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   376
	}
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   377
	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   378
	
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   379
	return $hnNumbers{$sKey};
f3475510d60c Added script to automate package build steps
BuildAdmin@LON-ENGBUILD89
parents:
diff changeset
   380
}
13
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
sub acquire_drive_letter
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
	my %hsPidsAndTimestamps = ();
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
	my $sLetterToRelease = '';
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
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   389
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   390
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   391
	{
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   392
		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
   393
		if ( flock(FILE, 6) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   394
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   395
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   396
			while ($sLine = <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
				if ($sLine =~ m%([^,]*),(.*)%)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   399
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   400
					my $sLetter=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   401
					my $sString=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   402
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   403
					$sString=~m%([^,]*),(.*)%;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   404
					my $nPid=$1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   405
					my $nTimestamp=$2;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   406
					
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   407
					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
   408
					{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   409
						$hsPidsAndTimestamps{$sLetter} = $sString;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   410
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   411
					else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   412
					{
19
472feb69d0c9 Changed location of default config repo, added --testbuild option, extended help
Dario Sestito <darios@symbian.org>
parents: 17
diff changeset
   413
						# 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
   414
						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
   415
						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
   416
					}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   417
				}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   418
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   419
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   420
			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
   421
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   422
				if (! $hsPidsAndTimestamps{$sNewLetter})
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   423
				{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   424
					my $sTimestamp = time();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   425
					$hsPidsAndTimestamps{$sNewLetter} = "$$,$sTimestamp";
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   426
					$sLetterToRelease = $sNewLetter;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   427
					last;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   428
				}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   429
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   430
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   431
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   432
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   433
			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
   434
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   435
				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
   436
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   437
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   438
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   439
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   440
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   441
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   442
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   443
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   444
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   445
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   446
		close(FILE);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   447
	}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   448
	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
   449
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   450
	return $sLetterToRelease;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   451
}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   452
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   453
sub release_drive_letter
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   454
{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   455
	my ($sLetterToRelease) = @_;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   456
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   457
	my %hsPidsAndTimestamps = ();
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   458
	
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   459
	my $nAttempts = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   460
	my $bAcquired = 0;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   461
	do
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   462
	{
32
11821242bc3e Make G: the working drive (unless not ready) and D: the second option
Dario Sestito <darios@symbian.org>
parents: 31
diff changeset
   463
		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
   464
		if ( flock(FILE, 6) )
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   465
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   466
			my $sLine;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   467
			while ($sLine = <FILE>)
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   468
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   469
				$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
   470
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   471
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   472
			delete $hsPidsAndTimestamps{$sLetterToRelease};
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   473
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   474
			seek(FILE, 0, 0);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   475
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   476
			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
   477
			{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   478
				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
   479
			}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   480
			truncate(FILE,tell(FILE));
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   481
			
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   482
			$bAcquired = 1;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   483
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   484
		else
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   485
		{
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   486
			$nAttempts ++;
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   487
			sleep(3);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   488
		}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   489
		close(FILE);
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   490
	}
85202f272e4a Changes to make build_package.pl allocate drive and build number automatically
darios@symbian.org
parents: 12
diff changeset
   491
	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
   492
}