#!/usr/bin/perl
#
#Copyright (c) 2009, Perforce Software, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#*******************************************************************************
#
# A sample change content trigger which creates an executable using a makefile
# If it succeeds, the change is accepted. If it does not succeeds, it change
# is rejected. May not feasible for a large build since that can lock up
# the database for an extended period.
#
#*******************************************************************************
use warnings;
use strict;
use File::Basename;
#use File::chdir;
use Cwd;
my @files = qw/err.log std.log/;
my $p4 = "p4 -plocalhost:20092 -u bruno -c test_ws";
my ($makePath,$depotPath,$path,$d1,$d2) = "";
foreach(`$p4 describe $ARGV[0]`) {
chomp;
if(/^\.\.\.\s+\/\/(\w+\/.*\#[0-9]+) (\w+)$/) {
print "\ndepot path: //" . dirname($1) . "/...";
$depotPath = "//" . dirname($1) . "/...";
system("$p4 sync $depotPath");
($d1,$d2,$path) = split(/\s+/,`$p4 where $depotPath`);
$makePath = dirname($path) . "/Makefile";
print "makepath: " . $makePath . "\n";
print "\nCurrent Dir: " . getcwd;
chdir(dirname($path)) or die "Can't change dir\n";
print "\nCurrent Dir: " . getcwd . "\n";
system(`make -f $makePath 2> /tmp/$files[0] 1> /tmp/$files[1]`);
if(-s "/tmp/" . $files[0]) {
print "build was unsuccessful!\n";
exit 1;
} else {
print "build was successful!\n";
exit 0;
}
}
}