build_package.pl
changeset 22 7a9425957569
parent 21 4b02facbff8f
child 23 435ecee4ea5d
child 24 ed4e68942437
equal deleted inserted replaced
21:4b02facbff8f 22:7a9425957569
    28 
    28 
    29 my $sFbfProjectRepo = '';
    29 my $sFbfProjectRepo = '';
    30 my $sFbfProjectDir = '';
    30 my $sFbfProjectDir = '';
    31 my $sFbfConfigRepo="\\\\bishare\\mercurial_internal\\fbf\\configs\\pkgbuild";
    31 my $sFbfConfigRepo="\\\\bishare\\mercurial_internal\\fbf\\configs\\pkgbuild";
    32 my $sFbfConfigDir = '';
    32 my $sFbfConfigDir = '';
    33 my $sJobLabel = '';
       
    34 my $nCmdLineNumber;
    33 my $nCmdLineNumber;
    35 my $bTestBuild = 0;
    34 my $bTestBuild = 0;
    36 GetOptions((
    35 GetOptions((
    37 	'label:s' => \$sJobLabel,
       
    38 	'configrepo:s' => \$sFbfConfigRepo,
    36 	'configrepo:s' => \$sFbfConfigRepo,
    39 	'configdir:s' => \$sFbfConfigDir,
    37 	'configdir:s' => \$sFbfConfigDir,
    40 	'projectrepo:s' => \$sFbfProjectRepo,
    38 	'projectrepo:s' => \$sFbfProjectRepo,
    41 	'projectdir:s' => \$sFbfProjectDir,
    39 	'projectdir:s' => \$sFbfProjectDir,
    42 	'number:s' => \$nCmdLineNumber,
    40 	'number:s' => \$nCmdLineNumber,
    43 	'testbuild!' => \$bTestBuild
    41 	'testbuild!' => \$bTestBuild
    44 ));
    42 ));
    45 
    43 
    46 if (!$sJobLabel or !($sFbfProjectRepo or $sFbfProjectDir))
    44 if (!$sFbfProjectRepo and !$sFbfProjectDir)
    47 {
    45 {
    48 	print "Usage: build_package.pl --label=LABEL (--projectrepo=REPO | --projectdir=DIR) OPTIONS\n";
    46 	print "Usage: build_package.pl --projectrepo=REPO [OPTIONS]\n";
    49 	print "\tOPTIONS:\n";
    47 	print "where OPTIONS are:\n";
       
    48 	print "\t--projectrepo=REPO Use REPO location for the project.\n";
       
    49 	print "\t--projectdir=DIR Use DIR location for the project (exclusive with --projectrepo). Option --testbuild is required.\n";
    50 	print "\t--configrepo=REPO Use REPO location for the config instead of \\\\bishare\\mercurial_internal\\fbf\\config\\pkgbuild\n";
    50 	print "\t--configrepo=REPO Use REPO location for the config instead of \\\\bishare\\mercurial_internal\\fbf\\config\\pkgbuild\n";
    51 	print "\t--configdir=DIR Use DIR location for the config (exclusive with --configrepo)\n";
    51 	print "\t--configdir=DIR Use DIR location for the config (exclusive with --configrepo). Option --testbuild is required.\n";
    52 	print "\t--number=N Force build number to N\n";
    52 	print "\t--number=N Force build number to N\n";
    53 	print "\t--testbuild Use d:\\numbers_test.txt for numbers and d:\\SF_builds_test to publish results\n";
    53 	print "\t--testbuild Use d:\\numbers_test.txt for numbers and disable publishing\n";
    54 	exit(0);
    54 	exit(0);
    55 }
    55 }
    56 
    56 
       
    57 if ($sFbfProjectDir and !$bTestBuild)
       
    58 {
       
    59 	print "Error: Option --projectdir requires --testbuild\n";
       
    60 	exit(0);
       
    61 }
       
    62 
       
    63 if ($sFbfConfigDir and !$bTestBuild)
       
    64 {
       
    65 	print "Error: Option --configdir requires --testbuild\n";
       
    66 	exit(0);
       
    67 }
       
    68 
    57 my $sTestBuildOpts = "";
    69 my $sTestBuildOpts = "";
    58 $sTestBuildOpts = "-Dsf.spec.publish.networkdrive=d:\\SF_builds_test -Dsf.spec.publish.rootdir=d:\\SF_builds_test" if ( $bTestBuild );
    70 $sTestBuildOpts = "-Dsf.spec.publish.enable=false" if ( $bTestBuild );
    59 $sNUMBERS_FILE = "d:\\numbers_test.txt" if ( $bTestBuild );
    71 $sNUMBERS_FILE = "d:\\numbers_test.txt" if ( $bTestBuild );
    60 
    72 
       
    73 my $sLabelBaseString = $sFbfProjectRepo;
       
    74 $sLabelBaseString = $sFbfProjectDir if ($sFbfProjectDir);
       
    75 $sLabelBaseString =~ m,.*[\\/]([^\\^/]+),;
       
    76 my $sJobLabel = $1;
       
    77 $sJobLabel = $sLabelBaseString if (! $1);
    61 my $sJobDir = mkdir_unique("$sJOB_BASE_DIR\\$sJobLabel");
    78 my $sJobDir = mkdir_unique("$sJOB_BASE_DIR\\$sJobLabel");
       
    79 print "Created project dir $sJOB_BASE_DIR\\$sJobLabel\n";
    62 
    80 
    63 print("cd $sBOOTSTRAP_DIR\n");
    81 print("cd $sBOOTSTRAP_DIR\n");
    64 chdir("$sBOOTSTRAP_DIR");
    82 chdir("$sBOOTSTRAP_DIR");
    65 print "###### BOOTSTRAP ######\n";
    83 print "###### BOOTSTRAP ######\n";
    66 my $sConfigArg = "-Dsf.config.repo=$sFbfConfigRepo";
    84 my $sConfigArg = "-Dsf.config.repo=$sFbfConfigRepo";
    76 	open FILE, ">$sNUMBERS_FILE";
    94 	open FILE, ">$sNUMBERS_FILE";
    77 	print FILE "\n";
    95 	print FILE "\n";
    78 	close FILE;
    96 	close FILE;
    79 }
    97 }
    80 
    98 
    81 my $nUnformattedNumber = ( $nCmdLineNumber ? $nCmdLineNumber : get_job_number($sFbfProjectRepo));
    99 my $nUnformattedNumber = 0;
       
   100 if ($nCmdLineNumber)
       
   101 {
       
   102 	$nUnformattedNumber = $nCmdLineNumber;
       
   103 }
       
   104 elsif ($sFbfProjectRepo)
       
   105 {
       
   106 	my $sRevZeroHash = get_rev_zero_hash($sFbfProjectRepo);
       
   107 	$nUnformattedNumber = get_job_number($sRevZeroHash);
       
   108 }
    82 my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
   109 my $nJobNumber = sprintf("%.3d", $nUnformattedNumber);
    83 
   110 
    84 # check that $sLETTERS_FILE exists, otherwise create it
   111 # check that $sLETTERS_FILE exists, otherwise create it
    85 if (!-f $sLETTERS_FILE)
   112 if (!-f $sLETTERS_FILE)
    86 {
   113 {
   124 		$nI++;
   151 		$nI++;
   125 		$sNewDirName = "$sBaseDir.$nI";
   152 		$sNewDirName = "$sBaseDir.$nI";
   126 	}
   153 	}
   127 	
   154 	
   128 	return $sNewDirName;
   155 	return $sNewDirName;
       
   156 }
       
   157 
       
   158 sub get_rev_zero_hash
       
   159 {
       
   160 	my ($sFbfProjectRepo) = @_;
       
   161 	
       
   162 	my $sOutput = `hg -R $sFbfProjectRepo identify -r0`;
       
   163 	
       
   164 	# remove leading and trailing spaces
       
   165 	$sOutput =~ s,^\s+,,;
       
   166 	$sOutput =~ s,\s+$,,;
       
   167 	
       
   168 	# remove tags e.g. "1fc39a7e9d79 tip"
       
   169 	$sOutput =~ s,([0-9a-z]+)\s+.*,$1,;
       
   170 	
       
   171 	return $sOutput;
   129 }
   172 }
   130 
   173 
   131 sub get_job_number
   174 sub get_job_number
   132 {
   175 {
   133 	my ($sKey) = @_;
   176 	my ($sKey) = @_;