2015-02-13 01:35:38 +03:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Getopt::Long;
|
|
|
|
use File::Temp qw/ tempfile tempdir /;
|
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
my $filename_arg;
|
|
|
|
my $coverity_token_arg;
|
|
|
|
my $dry_run_arg = 0;
|
|
|
|
my $verbose_arg = 0;
|
|
|
|
my $debug_arg = 0;
|
|
|
|
my $logfile_dir_arg;
|
|
|
|
my $configure_args = "";
|
|
|
|
my $make_args = "-j 32";
|
|
|
|
my $help_arg = 0;
|
|
|
|
|
|
|
|
&Getopt::Long::Configure("bundling");
|
|
|
|
my $ok = Getopt::Long::GetOptions("filename=s" => \$filename_arg,
|
|
|
|
"coverity-token=s" => \$coverity_token_arg,
|
|
|
|
"logfile-dir=s" => \$logfile_dir_arg,
|
|
|
|
"configure-args=s" => \$configure_args,
|
|
|
|
"make-args=s" => \$make_args,
|
|
|
|
"dry-run!" => \$dry_run_arg,
|
|
|
|
"verbose!" => \$verbose_arg,
|
|
|
|
"debug!" => \$debug_arg,
|
|
|
|
"help|h" => \$help_arg);
|
|
|
|
|
|
|
|
$ok = 0
|
|
|
|
if (!defined($filename_arg));
|
|
|
|
$ok = 0
|
|
|
|
if (!defined($coverity_token_arg));
|
|
|
|
if (!$ok || $help_arg) {
|
|
|
|
print "Usage: $0 --filename=FILENAME --coverity-token=TOKEN [--dry-run] [--verbose] [--help]\n";
|
|
|
|
exit($ok);
|
|
|
|
}
|
|
|
|
|
2015-02-13 01:54:45 +03:00
|
|
|
die "Cannot read $filename_arg"
|
|
|
|
if (! -r $filename_arg);
|
|
|
|
|
|
|
|
$verbose_arg = 1
|
|
|
|
if ($debug_arg);
|
|
|
|
|
2015-02-13 01:35:38 +03:00
|
|
|
######################################################################
|
|
|
|
|
|
|
|
sub verbose {
|
|
|
|
print @_
|
|
|
|
if ($verbose_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
# run a command and save the stdout / stderr
|
|
|
|
sub safe_system {
|
2015-02-14 18:10:49 +03:00
|
|
|
my $allowed_to_fail = shift;
|
|
|
|
my $cmd = shift;
|
|
|
|
my $stdout_file = shift;
|
|
|
|
|
|
|
|
# Redirect stdout if requested or not verbose
|
|
|
|
if (defined($stdout_file)) {
|
|
|
|
$stdout_file = "$logfile_dir_arg/$stdout_file";
|
|
|
|
unlink($stdout_file);
|
|
|
|
$cmd .= " >$stdout_file";
|
|
|
|
} elsif (!$debug_arg) {
|
|
|
|
$cmd .= " >/dev/null";
|
2015-02-13 01:35:38 +03:00
|
|
|
}
|
2015-02-14 18:10:49 +03:00
|
|
|
$cmd .= " 2>&1";
|
2015-02-13 01:35:38 +03:00
|
|
|
|
2015-02-14 18:10:49 +03:00
|
|
|
my $rc = system($cmd);
|
|
|
|
if (0 != $rc && !$allowed_to_fail) {
|
|
|
|
# If we die/fail, ensure to change out of the temp tree so
|
|
|
|
# that it can be removed upon exit.
|
2015-02-13 01:35:38 +03:00
|
|
|
chdir("/");
|
2015-02-14 18:10:49 +03:00
|
|
|
die "Command $cmd failed: exit status $rc";
|
2015-02-13 01:35:38 +03:00
|
|
|
}
|
2015-02-14 18:10:49 +03:00
|
|
|
system("cat $stdout_file")
|
|
|
|
if ($debug_arg && -f $stdout_file);
|
2015-02-13 01:35:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
# Make an area to work
|
|
|
|
|
|
|
|
my $dir = tempdir(CLEANUP => 1);
|
|
|
|
chdir($dir);
|
|
|
|
verbose "*** Working in $dir\n";
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
# Get the coverity tool, put it in our path
|
|
|
|
|
|
|
|
verbose "*** Downloading coverity tool\n";
|
2015-02-14 18:10:49 +03:00
|
|
|
safe_system(0, "wget https://scan.coverity.com/download/linux-64 --post-data \"token=$coverity_token_arg\&project=OpenMPI\" -O coverity_tool.tgz");
|
|
|
|
safe_system(0, "tar xf coverity_tool.tgz");
|
2015-02-13 01:35:38 +03:00
|
|
|
opendir(my $dh, ".") ||
|
|
|
|
die "Can't opendir .";
|
|
|
|
my @files = grep { /^cov/ && -d "./$_" } readdir($dh);
|
|
|
|
closedir($dh);
|
|
|
|
|
|
|
|
my $cov_dir = "$dir/$files[0]/bin";
|
|
|
|
$ENV{PATH} = "$cov_dir:$ENV{PATH}";
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
# Expand the OMPI tarball, build it
|
|
|
|
|
|
|
|
verbose "*** Extracting OMPI tarball\n";
|
2015-02-14 18:10:49 +03:00
|
|
|
safe_system(0, "tar xf $filename_arg");
|
2015-02-13 01:35:38 +03:00
|
|
|
my $tarball_filename = basename($filename_arg);
|
2015-02-14 18:10:49 +03:00
|
|
|
$tarball_filename =~ m/^openmpi-(.+)\.tar.+$/;
|
2015-02-13 01:35:38 +03:00
|
|
|
my $ompi_ver = $1;
|
2015-02-14 18:10:49 +03:00
|
|
|
chdir("openmpi-$ompi_ver");
|
2015-02-13 01:35:38 +03:00
|
|
|
|
|
|
|
verbose "*** Configuring OMPI tarball\n";
|
2015-02-14 18:10:49 +03:00
|
|
|
safe_system(0, "./configure $configure_args", "configure");
|
2015-02-13 01:35:38 +03:00
|
|
|
|
|
|
|
verbose "*** Building OMPI tarball\n";
|
2015-02-14 18:10:49 +03:00
|
|
|
safe_system(0, "cov-build --dir cov-int make $make_args", "cov-build");
|
2015-02-13 01:35:38 +03:00
|
|
|
|
|
|
|
# Tar up the Coverity results
|
|
|
|
verbose "*** Tarring up results\n";
|
2015-02-14 18:10:49 +03:00
|
|
|
safe_system(0, "tar jcf $ompi_ver-analyzed.tar.bz2 cov-int");
|
2015-02-13 01:35:38 +03:00
|
|
|
|
|
|
|
# If not dry-run, submit to Coverity
|
|
|
|
if ($dry_run_arg) {
|
|
|
|
verbose "*** Would have submitted, but this is a dry run\n";
|
|
|
|
} else {
|
|
|
|
verbose "*** Submitting results\n";
|
2015-02-14 18:10:49 +03:00
|
|
|
safe_system(0, "curl --form token=$coverity_token_arg " .
|
2015-02-13 01:35:38 +03:00
|
|
|
"--form email=jsquyres\@cisco.com " .
|
2015-02-13 15:08:51 +03:00
|
|
|
"--form file=\@$ompi_ver-analyzed.tar.bz2 " .
|
|
|
|
"--form version=$ompi_ver " .
|
|
|
|
"--form description=nightly-master " .
|
|
|
|
"https://scan.coverity.com/builds?project=OpenMPI",
|
2015-02-14 18:10:49 +03:00
|
|
|
"coverity-submit");
|
2015-02-13 01:35:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
verbose("*** All done\n");
|
2015-02-13 15:08:51 +03:00
|
|
|
|
|
|
|
# Chdir out of the tempdir so that it can be removed
|
2015-02-13 01:35:38 +03:00
|
|
|
chdir("/");
|
2015-02-13 15:08:51 +03:00
|
|
|
|
2015-02-13 01:35:38 +03:00
|
|
|
exit(0);
|