#!/usr/bin/perl -w
# $Id: //guest/daniel_kionka/bootstrap/sample1/build/top-level-build.pl#1 $
#
# Copyright (c) 2006 Daniel P. Kionka; all rights reserved
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#
# top-level-build.pl - sample top-level build script
#
# This script would normally run make or a solution file, but here it simply
# generates a text file with the build version.
use strict;
use warnings;
#
# variables
#
# constants
my $outFile = "build-out.txt";
my $logP4Change = "log/p4change.txt";
#
# functions
#
#
# A developer should be able to run the same start-up script,
# so set the ENV variables bootstrap would normally set.
#
sub checkENV()
{
# need last p4 changelist number in BBS_CHANGE
if (! defined($ENV{BBS_CHANGE})) {
my $change;
# first check the log file
my $err = open(LOG, "<", $logP4Change) ||
warn "cannot read file: $logP4Change";
if (! $err) {
$change = <LOG>;
close(LOG);
chomp($change);
}
if (! $change) {
# run p4 changes to find last one
delete($ENV{PWD}); # PWD confuses p4
$change = `p4 changes -m 1 #have`;
chomp($change);
print STDERR "parsing line: $change\n";
$change =~ s/Change (\d+) .*/$1/;
die "No p4 change" if (! $change);
$ENV{BBS_CHANGE} = $change;
}
}
}
#
# mainline
#
checkENV();
open(OUT, ">", $outFile) || die;
print OUT "This is a simple output file...\n\n";
print OUT "Build version: $ENV{BBS_CHANGE}\n";
close(OUT);