build_package.pl
changeset 11 f3475510d60c
child 12 2eaa774ddc63
equal deleted inserted replaced
10:c1cbd33e46c0 11:f3475510d60c
       
     1 #!/usr/bin/perl -w
       
     2 
       
     3 use strict;
       
     4 
       
     5 use Getopt::Long;
       
     6 use File::Path;
       
     7 
       
     8 my $sBOOTSTRAP_DIR="D:\\Helium\\hlm-apps\\bootstrap";
       
     9 my $sJOB_BASE_DIR="D:\\fbf_project";
       
    10 my $sCONFIG_REPO="\\\\lon-engbuild87\\d\$\\mercurial\\fbf\\configs\\dario_dev";
       
    11 my $nLOCK_FILE_MAX_ATTEMPTS = 5;
       
    12 my $sNUMBERS_FILE="\\\\lon-engbuild87\\d\$\\numbers.txt";
       
    13 
       
    14 my $sProjectRepo = '';
       
    15 my $sJobLabel = '';
       
    16 my $nCmdLineNumber;
       
    17 GetOptions(('label:s' => \$sJobLabel, 'project:s' => \$sProjectRepo, 'number:s' => \$nCmdLineNumber));
       
    18 
       
    19 if (!$sJobLabel or !$sProjectRepo)
       
    20 {
       
    21 	print "Usage: build_package.pl <label> <project_repo>\n";
       
    22 	exit(0);
       
    23 }
       
    24 
       
    25 my $sJobDir = mkdir_unique("$sJOB_BASE_DIR\\$sJobLabel");
       
    26 
       
    27 print("cd $sBOOTSTRAP_DIR\n");
       
    28 chdir("$sBOOTSTRAP_DIR");
       
    29 print "###### BOOTSTRAP ######\n";
       
    30 print("hlm -f bootstrap.xml -Dsf.config.repo=$sCONFIG_REPO -Dsf.project.repo=$sProjectRepo -Dsf.target.dir=$sJobDir\n");
       
    31 system("hlm -f bootstrap.xml -Dsf.config.repo=$sCONFIG_REPO -Dsf.project.repo=$sProjectRepo -Dsf.target.dir=$sJobDir");
       
    32 
       
    33 
       
    34 my $nUnformattedNumber = ( $nCmdLineNumber ? $nCmdLineNumber : get_job_number($sProjectRepo));
       
    35 my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
       
    36 
       
    37 print("cd $sJobDir\\sf-config\n");
       
    38 chdir("$sJobDir\\sf-config");
       
    39 print "###### BUILD PREPARATION ######\n";
       
    40 print("hlm sf-prep -Dsf.spec.job.number=$nJobNumber\n");
       
    41 system("hlm sf-prep -Dsf.spec.job.number=$nJobNumber");
       
    42 
       
    43 print "###### EXECUTE BUILD ######\n";
       
    44 print("hlm sf-build-all -Dsf.spec.job.number=$nJobNumber\n");
       
    45 system("hlm sf-build-all -Dsf.spec.job.number=$nJobNumber");
       
    46 
       
    47 sub mkdir_unique
       
    48 {
       
    49 	my ($sBaseDir) = @_;
       
    50 	
       
    51 	# check that the path where the new dir must be created exists.
       
    52 	$sBaseDir =~ m,(.*[\\/])?(.*),;
       
    53 	mkpath($1) if ($1 && !-d $1);
       
    54 	
       
    55 	my $nI = 0;
       
    56 	my $sNewDirName = "$sBaseDir";
       
    57 	while(!mkdir($sNewDirName))
       
    58 	{
       
    59 		$nI++;
       
    60 		$sNewDirName = "$sBaseDir.$nI";
       
    61 	}
       
    62 	
       
    63 	return $sNewDirName;
       
    64 }
       
    65 
       
    66 sub get_job_number
       
    67 {
       
    68 	my ($sKey) = @_;
       
    69 	
       
    70 	my %hnNumbers = ();
       
    71 	
       
    72 	my $nAttempts = 0;
       
    73 	my $bGotNumber = 0;
       
    74 	do
       
    75 	{
       
    76 		open(FILE, "+<$sNUMBERS_FILE") or die("Can't open $sNUMBERS_FILE");
       
    77 		if ( flock(FILE, 6) )
       
    78 		{
       
    79 			my $sLine;
       
    80 			while ($sLine = <FILE>)
       
    81 			{
       
    82 				$hnNumbers{$1} = $2 if ($sLine =~ m%(.*),(.*)%);
       
    83 			}
       
    84 			
       
    85 			$hnNumbers{$sKey} = 0 if (! $hnNumbers{$sKey} );
       
    86 			$hnNumbers{$sKey} = $hnNumbers{$sKey} + 1;
       
    87 			
       
    88 			seek(FILE, 0, 0);
       
    89 
       
    90 			for my $sStr ( keys(%hnNumbers) )
       
    91 			{
       
    92 				print FILE "$sStr,$hnNumbers{$sStr}\n";
       
    93 			}
       
    94 			
       
    95 			$bGotNumber = 1;
       
    96 		}
       
    97 		else
       
    98 		{
       
    99 			$nAttempts ++;
       
   100 			sleep(3);
       
   101 		}
       
   102 		close(FILE);
       
   103 	}
       
   104 	until ( $bGotNumber or $nAttempts == $nLOCK_FILE_MAX_ATTEMPTS );
       
   105 	
       
   106 	return $hnNumbers{$sKey};
       
   107 }