head	1.2;
access;
symbols
	import-20090318:1.1.1.9
	import-20081205:1.1.1.9
	rel-8-1-2-sv:1.1.1.9
	import-20080404:1.1.1.9
	import-20071105:1.1.1.8
	import-20070116:1.1.1.7
	import-20061124:1.1.1.6
	rel-6-2-2-sv:1.1.1.5
	rel-6-2-1-sv:1.1.1.5
	import-20060615:1.1.1.5
	import-20060530:1.1.1.5
	import-20060516:1.1.1.5
	import-20060421:1.1.1.4
	import-20060406:1.1.1.3
	import-29mar06:1.1.1.2
	import-14mar06:1.1.1.1
	import-13mar06:1.1.1.1
	fixed-post-import-14feb06:1.1.1.1
	import-14feb06:1.1.1.1
	fixed-post-import-6feb06:1.1.1.1
	import-6feb06:1.1.1.1
	import-6sep05:1.1.1.1
	start:1.1.1.1
	freescale:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2009.05.18.14.01.23;	author seh;	state Exp;
branches;
next	1.1;
commitid	Yb65nkgrmYQEmmOt;

1.1
date	2005.08.23.08.54.15;	author seh;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2005.08.23.08.54.15;	author seh;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2006.03.29.14.43.13;	author seh;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2006.04.06.14.36.27;	author seh;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	2006.04.21.10.02.33;	author seh;	state Exp;
branches;
next	1.1.1.5;

1.1.1.5
date	2006.05.16.14.20.55;	author seh;	state Exp;
branches;
next	1.1.1.6;

1.1.1.6
date	2006.11.27.11.19.19;	author seh;	state Exp;
branches;
next	1.1.1.7;

1.1.1.7
date	2007.01.17.10.48.15;	author seh;	state Exp;
branches;
next	1.1.1.8;

1.1.1.8
date	2007.11.06.15.44.45;	author seh;	state Exp;
branches;
next	1.1.1.9;
commitid	AdKoH3Xx8FxdUwEs;

1.1.1.9
date	2008.04.04.10.51.55;	author seh;	state Exp;
branches;
next	;
commitid	GVikqE6sLnKPsMXs;


desc
@@


1.2
log
@Fix auth order for email in autobuild_ltib.  Fix naming.
@
text
@#!/usr/bin/perl -w
eval 'LANG=C exec perl -w -S $0 ${1+"$@@"}'
    if $running_under_some_shell;
$running_under_some_shell = 0;

######################################################################
# 
# Copyright  Freescale Semiconductor, Inc. 2004-2007. All rights reserved.
#
# Stuart Hughes, stuarth@@freescale.com,  20th April 2005
# 
# This file is part of LTIB.
#
# LTIB is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LTIB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LTIB; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

# autobuild ltib bsps and mail the results
#
# To use this:
#  1/ Create a directory that will hold your ltib projects
#  2/ In that directory unpack and configure ltib a number of times
#     once for each BSP you want to test
#  3/ Copy this script into the top level directory containing the 
#     ltib BSPs
#  4/ Edit the values in the section: EDIT THESE
#  2/ Add an entry in your crontab to run the script, for instance,
#     I run a build at 10 minutes past 9pm Mon-Fri:
#     10 21 * * 1-5 (cd /home/seh/ltib_bsps ; ./autobuild_ltib 2>&1 )
#
#
######################################################################
use Getopt::Std;

($day, $month, $year) = (gmtime)[3,4,5];
$yyyymmdd = sprintf("%04d%02d%02d", $year+1900, $month+1, $day);
$stime = time();
$sdate = scalar(gmtime());

####### EDIT THESE ######
$from = 'fromname@@somedomain.org';
$fpw  = 'plain_auth_password';
$to   = 'toname@@somedomain.org';
$cc   = '';
$subject = 'Build results for ' . $yyyymmdd;
$smtp = 'server.somedomain.org';
$tag  = '';
####### END OF EDIT THESE ######

$opt_d = ".";
$opt_P = "";
$opt_h = 0;
$opt_f = 0;
$opt_c = 0;

$usage = <<TXT;

Usage: autobuild_ltib [ -d <dir> -f -h -P profile ]
  where:
    -d <dir>  : base ltib directory containing bsps (default is $opt_d)
    -f        : full force build
    -c        : continue on error
    -P <pf>   : profile
    -h        : help
TXT
getopts("d:P:hfc") or die $usage;
die "$opt_d is not a directory" unless -d $opt_d;
die $usage if $opt_h;

$ltib_cmd  = "./ltib -b ";
$ltib_cmd .= "--profile $opt_P " if $opt_P;
$ltib_cmd .= "-f " if $opt_f;
$ltib_cmd .= "-C " if $opt_c;

# before we get started, wait for any unfinished earlier autobuilds
wait_until_ready('autobuilder.lock', 6, 60 * 60, "$$\n$sdate GMT\n");

foreach $dir ( glob("$opt_d/*") ) {
    next unless -d $dir;
    next unless -f "$dir/.config";
    next if $dir eq 'noautobuild';
    $log  = "Processing directory $dir\n";
    $log .= "$ltib_cmd \n";
    system_nb(<<TXT) == 0 or die "autobuild died: $?";
cd $dir
rm -rf rpm/BUILD/*
cvs -q up $tag -dP -A &> /dev/null
rm -f build.log  build.log.end.txt
$ltib_cmd &> build.log 
tail -30 build.log > build.log.end.txt
# delete the pax_global_header stuff (from git tarballs)
rm -f rpm/BUILD/* 2>/dev/null
cd - >/dev/null
TXT
}
# build failure summary
system_nb(<<TXT) == 0 or die "autobuild died: $?";
./mk_pkg_results -s $stime -d > build_res.html
#scp build_res.html hostname:/path/
./mk_pkg_results -s $stime > pkg_build_list.html
#scp pkg_build_list.html hostname:/path/
TXT

open(RES, "build_res.html") or die "open build_res.html: $!\n";
while(<RES>) { $res .= $_; }
close RES;
email(from    => $from, 
      fpw     => $fpw,
      do_auth => $fpw ? 1 : 0,
      to      => $to, 
      cc      => $cc,
      subject => $subject, 
      body    => $res, 
      smtp_server => $smtp);

# run autotest
system_nb(<<TXT);

# run local BSP autotest
#./run_autotest

# run kernel autotest
#ssh autotest_host 'echo "cd; ./run_autotest_pb01" | at now+1min' 2>&1 >/dev/null
TXT

exit 0;


# send an email message (extracted from twikicopytogppstage)
sub email
{
    require Net::SMTP;
    my $a = {
        from_name    => 'autobuilder',
        from         => 'automail@@bitshrine.org',
        to_name      => 'ltib-users',
        to           => 'ltib@@nongnu.org',
        cc           => '',
        subject      => 'no subject',
        body         => '',
        do_auth      => 0,
        fpw          => '',
        smtp_server  => 'localhost',
        content_type => 'text/html', 
        @@_
    };
    my $smtp = Net::SMTP->new($a->{smtp_server},
                              Debug => 0) or die "Net::SMTP->new";
    $smtp->auth($a->{from}, $a->{fpw}) if $a->{do_auth};
    $smtp->mail($a->{from});
    $smtp->to($a->{to});
    $smtp->cc($a->{cc});
    $smtp->data();
    $smtp->datasend("From: $a->{from_name} <$a->{from}>\n");
    $smtp->datasend("To: $a->{to_name} <$a->{to}>\n");
    $smtp->datasend("Subject: $a->{subject}\n");
    $smtp->datasend("MIME-Version: 1.0\n");
    $smtp->datasend("Content-type: $a->{content_type}\n");
    $smtp->datasend("Content-Transfer-Encoding: 7bit\n");
    $smtp->datasend("\n");
    $smtp->datasend($a->{body});
    $smtp->quit;
    return 1;
}

# Normally system will block SIGINT and SIGQUIT
# We don't want to do this, or we can't properly CNTRL-C
sub system_nb
{
    my (@@cmd) = @@_;
    if(my $pid = fork) {
        waitpid($pid, 0);
        return $?;
    } else {
        die "cannot fork: $!\n" unless defined $pid;
        exec(@@cmd) or die "exec: @@cmd: $!";
    }
}

# we use this to make sure we don't overlap jobs
# the file will unlock when this process exits
use Fcntl qw(:DEFAULT :flock);
sub wait_until_ready
{
    my ($lf, $tries, $sec, $lockinfo) = @@_;
    my ($i, $msg) = (0, '');

    sysopen(LF, $lf, O_RDWR|O_CREAT) or die("can't open $lf: $!\n");
    while(1) {
        last if flock(LF, LOCK_EX|LOCK_NB);
        $i++ if $tries > 0;
        $msg = $i > $tries ? "Can't get lock after $tries tries, giving up\n"
                           :  scalar gmtime() . " GMT: $lf locked, attempt "
                            . "$i of $tries.\nWill retry in $sec seconds\n";
        email(from    => $from,
              fpw     => $fpw,
              do_auth => $fpw ? 1 : 0,
              to      => $to,
              subject => 'autobuilder waiting for lock',
              body    => $msg,
              smtp_server => $smtp);
        warn($msg);
        die if $i > $tries;
        sleep($sec);
    }
    flock(LF, LOCK_EX) or die("can't lock $lf: $!\n");
    seek(LF, 0, 0)     or die("can't seek to start of $lf: $!\n");
    truncate(LF, 0)    or die("can't truncate $lf $!\n");
    my $ofh = select(LF); $| = 1; select($ofh);
    print LF $lockinfo;
}


@


1.1
log
@Initial revision
@
text
@d1 1
d8 1
a8 1
# Copyright  Freescale Semicondutor, Inc. 2004-2005. All rights reserved.
d11 1
a11 1
#   
d18 1
a18 1
# 
d28 1
a28 1
# 
a43 2
use MIME::Lite;
use Cwd 'abs_path';
d46 14
a59 5
# EDIT THESE
$to   = 'stuarth@@freescale.com';  # who to email
$cc   = ''                        # who to copy (comma separated list)
$from = 'autobuilder@@AusLXPB02';  # who it came from 
# END EDIT THESE
d62 1
d69 1
a69 1
Usage: autobuild_ltib [ -d <dir> -f -h ]
d74 1
d77 1
a77 2

getopts("d:hfc") or die $usage;
d81 2
a82 1
$ltib_cmd  = "./ltib ";
d86 2
a87 15

($day, $month, $year) = (gmtime)[3,4,5];
$date = sprintf("%04d%02d%02d", $year+1900, $month+1, $day);

$msg = MIME::Lite->new(
             From     => $from,
             To       => $to,
             Cc       => $cc,
             Subject  =>"Build results for $date",
             Type     =>'multipart/mixed',
                      );
        
$msg->attach(Type     =>'TEXT',
             Data     =>"Build results attached\n",
            );
d91 5
a95 3
    $apath = abs_path($dir);
    print "Processing directory $dir\n";
    system(<<TXT);
d97 2
a98 1
cvs -q up -dP &> /dev/null
d102 3
a104 1
cd -
a105 11
    $log  = "Results for build in directory: $dir\n";
    $log .= "This is the last 30 lines of $dir/build.log\n";
    $log .= "-------------------------------------------\n";
    $log .= `cat $dir/build.log.end.txt`;
    $log .= "-------------------------------------------\n";
    $log .= "\n\n";
    $msg->attach(Type     =>'TEXT',
                 Disposition => 'attachment',
                 Filename => "$apath.txt",
                 Data     => $log,
                 );
d107 30
a136 1
$msg->send("sendmail");
d138 87
@


1.1.1.1
log
@LTIB external initial import
@
text
@@


1.1.1.2
log
@Import from fsl 29mar06
@
text
@d10 1
a10 1
# 
d17 1
a17 1
#
d27 1
a27 1

d49 1
a49 1
$cc   = '';   # who to CC (comma separated list)
a53 1
$opt_P = "";
d60 1
a60 1
Usage: autobuild_ltib [ -d <dir> -f -h -P profile ]
a64 1
    -P <pf>   : profile
d68 1
a68 1
getopts("d:P:hfc") or die $usage;
d72 1
a72 2
$ltib_cmd  = "./ltib -b ";
$ltib_cmd .= "--profile $opt_P " if $opt_P;
d76 1
d95 2
a96 3
    $log  = "Processing directory $dir\n";
    $log .= "$ltib_cmd \n";
    system_nb(<<TXT);
d104 1
a104 1
    $log .= "Results for build in directory: $dir\n";
a117 15

# Normally system will block SIGINT and SIGQUIT
# We don't want to do this, or we can't properly CNTRL-C
sub system_nb
{
    my (@@cmd) = @@_;
    if(my $pid = fork) {
        waitpid($pid, 0);
        return $?;
    } else {
        die "cannot fork: $!\n" unless defined $pid;
        exec(@@cmd) or die "exec: @@cmd: $!";
    }
}

@


1.1.1.3
log
@Import from fsl 20060406
@
text
@d7 1
a7 1
# Copyright  Freescale Semicondutor, Inc. 2004-2006. All rights reserved.
a100 1
rm -rf rpm/BUILD/*
a119 6

# build failure summary
system_nb(<<TXT);
./mk_pkg_results > build_res.html
scp build_res.html auslxsc01:/opt/freescale/var/www/html/ltib/
TXT
@


1.1.1.4
log
@Import from fsl 20060421
@
text
@d47 5
a51 8
####### EDIT THESE ######
# who to email
$to   = 'Ltib-users@@sourceforge.freescale.net';
# who to CC (comma separated list)
$cc   = '';
# who it came from
$from = 'autobuilder@@auslxpb02.mtwk.freescale.net';
####### END OF EDIT THESE ######
d89 5
d96 1
a96 1
    #$apath = abs_path($dir);
d108 11
d120 1
a126 12

$msg->attach(Type     =>'TEXT',
             Data     => "Here are todays build results\n",
             );

$msg->attach(Type     =>'text/html',
             Path     => "build_res.html",
             Filename => "build_res.html",
             Disposition => 'attachment',
             );

$msg->send("sendmail");
@


1.1.1.5
log
@Import from fsl 20060516
@
text
@d7 1
a7 1
# Copyright  Freescale Semiconductor, Inc. 2004-2006. All rights reserved.
@


1.1.1.6
log
@Import from fsl 20061124
@
text
@d43 2
a46 3
($day, $month, $year) = (gmtime)[3,4,5];
$date = sprintf("%04d%02d%02d", $year+1900, $month+1, $day);

d48 3
a50 2
$from = 'autobuilder@@hostname';
$to   = 'Ltib-users@@hostname';
d52 2
a53 2
$subject = 'Build results for ' . $date;
$smtp = 'remotesmtp.freescale.net';
d72 1
d82 10
d94 1
a94 1
    next if $dir eq 'noautobuild';
a103 2
# delete the pax_global_header stuff (from git tarballs)
rm -f rpm/BUILD/* 2>/dev/null
d107 1
d111 1
a111 1
scp build_res.html hostname:/opt/freescale/var/www/html/ltib/
d114 11
a124 8
open(RES, "build_res.html") or die "open build_res.html: $!\n";
while(<RES>) { $res .= $_; }
close RES;
email(from    => $from, 
      to      => $to, 
      subject => $subject, 
      body    => $res, 
      smtp    => $smtp);
a126 37

# send an email message (extracted from twikicopytogppstage)
sub email
{
    require Net::SMTP;
    my $a = {
        from         => 'twikicopytogppstage <stuarth@@freescale.com>',
        to           => 'stuarth@@freescale.com',
        cc           => '',
        subject      => 'no subject',
        body         => '',
        do_auth      => 0,
        fpw          => '',
        smtp_server  => 'localhost',
        content_type => 'text/html', 
        @@_
    };
    my $date = gmtime();
    my $smtp = Net::SMTP->new($a->{smtp_server},
                              Debug => 0) or die "Net::SMTP->new";
    $smtp->mail($a->{from});
    $smtp->auth($a->{from}, $a->{fpw}) if $a->{do_auth};
    $smtp->to($a->{to});
    $smtp->cc($a->{cc});
    $smtp->data();
    $smtp->datasend("From: $a->{from}\n");
    $smtp->datasend("To: $a->{to}\n");
    $smtp->datasend("Subject: $a->{subject}\n");
    $smtp->datasend("MIME-Version: 1.0\n");
    $smtp->datasend("Content-type: $a->{content_type}\n");
    $smtp->datasend("Content-Transfer-Encoding: 7bit\n");
    $smtp->datasend("\n");
    $smtp->datasend($a->{body});
    $smtp->quit;
    return 1;
}

@


1.1.1.7
log
@Import from fsl 20070116
@
text
@a101 2
./mk_pkg_build_list > pkg_build_list.html
scp pkg_build_list.html hostname:/opt/freescale/var/www/html/ltib/
@


1.1.1.8
log
@Import from fsl 20071105
@
text
@a0 1
#!/usr/bin/perl -w
d7 1
a7 1
# Copyright  Freescale Semiconductor, Inc. 2004-2007. All rights reserved.
d46 1
a46 3
$yyyymmdd = sprintf("%04d%02d%02d", $year+1900, $month+1, $day);
$stime = time();
$sdate = scalar(gmtime());
d52 1
a52 1
$subject = 'Build results for ' . $yyyymmdd;
a80 3
# before we get started, wait for any unfinished earlier autobuilds
wait_until_ready('autobuilder.lock', 6, 60 * 60, "$$\n$sdate GMT\n");

d86 1
a86 1
    system_nb(<<TXT) == 0 or die "autobuild died: $?";
d95 1
a95 1
cd - >/dev/null
d99 2
a100 2
system_nb(<<TXT) == 0 or die "autobuild died: $?";
./mk_pkg_results -s $stime -d > build_res.html
d102 1
a102 1
./mk_pkg_results -s $stime > pkg_build_list.html
a110 1
      cc      => $cc,
a113 11

# run autotest
system_nb(<<TXT);

# run local BSP autotest
./run_autotest

# run kernel autotest
ssh autotest_host 'echo "cd; ./run_autotest_pb01" | at now+1min' 2>&1 >/dev/null
TXT

d133 1
a166 32
# we use this to make sure we don't overlap jobs
# the file will unlock when this process exits
use Fcntl qw(:DEFAULT :flock);
sub wait_until_ready
{
    my ($lf, $tries, $sec, $lockinfo) = @@_;
    my ($i, $msg) = (0, '');

    sysopen(LF, $lf, O_RDWR|O_CREAT) or die("can't open $lf: $!\n");
    while(1) {
        last if flock(LF, LOCK_EX|LOCK_NB);
        $i++ if $tries > 0;
        $msg = $i > $tries ? "Can't get lock after $tries tries, giving up\n"
                           :  scalar gmtime() . " GMT: $lf locked, attempt "
                            . "$i of $tries.\nWill retry in $sec seconds\n";
        email(from    => $from,
              to      => 'stuarth@@freescale.com',
              subject => 'autobuilder waiting for lock',
              body    => $msg,
              smtp    => $smtp);
        warn($msg);
        die if $i > $tries;
        sleep($sec);
    }
    flock(LF, LOCK_EX) or die("can't lock $lf: $!\n");
    seek(LF, 0, 0)     or die("can't seek to start of $lf: $!\n");
    truncate(LF, 0)    or die("can't truncate $lf $!\n");
    my $ofh = select(LF); $| = 1; select($ofh);
    print LF $lockinfo;
}


@


1.1.1.9
log
@Import from fsl 20080404
@
text
@a56 1
$tag  = '';
d95 1
a95 1
cvs -q up $tag -dP -A &> /dev/null
@


