Mozilla/mozilla/webtools/buildbot-try/processchanges.pl
bhearsum%mozilla.com 217d33d991 bug 437143: try servers need to support building from a mercurial repository with a patch. r=rhelmer, patch=vlad,me
git-svn-id: svn://10.0.0.236/trunk@253025 18797224-902f-48f8-a5cc-f745e15eee43
2008-07-14 12:01:38 +00:00

167 lines
4.9 KiB
Perl
Executable File

#!/usr/bin/perl
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Try server patch downloader script.
#
# The Initial Developer of the Original Code is
# Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Hearsum <bhearsum@mozilla.com>
# ***** END LICENSE BLOCK *****
# Description:
# TODO
#
use strict;
use warnings;
use File::Spec::Functions;
use MozBuild::Util qw(RunShellCommand MkdirWithPath);
# for readability
my $ST_INODE = 1;
# where to retrieve files from -- make sure this has a trailing slash
my $PATCHURL = "https://build.mozilla.org/patches/";
# where the patches go
my $PATCHDIR = "patches/";
# where to log errors
my $LOGFILE = "downloader.log";
my $PYTHON_PATH = "/tools/python/bin/python";
my $BUILDBOT_PATH = "/tools/buildbot/bin/buildbot";
my $MASTER_HOST = "localhost:9982";
my $CVS_BRANCH = "PATCH_TRY";
my $HG_BRANCH = "HG_TRY";
# if multiple patches are being this controls the delay between them
# this value should be more than the treeStableTimer on the Scheduler
my $DELAY = 5;
# set up the patch directory
if (-e $PATCHDIR) {
if (! -d $PATCHDIR) {
print STDERR "Patch directory is a file\n";
exit 1;
}
}
else {
if (! MkdirWithPath(dir => $PATCHDIR)) {
print STDERR "Could not create patch directory\n";
exit 1;
}
}
RunShellCommand(command => "wget",
args => ['--no-check-certificate', '-q', '-r', '-l1',
'-np', '-nd', '-Rindex.html*,.1',
'-P', $PATCHDIR, $PATCHURL],
logfile => $LOGFILE,
appendLogfile => 1,
redirectStderr => 1);
# set-up the logfile
open(LOGFILE, ">>$LOGFILE") ||
die("Could not open logfile\nFailure message: $!\n");
opendir(DIR, $PATCHDIR) ||
die("Could not read patch directory\nFailure message: $!\n");
my @files = grep { /^[\w.-]+\.info$/ } readdir(DIR);
closedir(DIR) || die("Could not close directory\nFailure message: $!\n");
if (0 == scalar(@files)) {
print LOGFILE scalar(localtime()) . " - No Patches, exiting...\n";
exit 0;
}
# any changes left still need a sendchange generated
foreach my $file (@files) {
my (%info, $key, $value, $rv);
my $infoFilename = catfile($PATCHDIR, $file);
open(INFOFILE, $infoFilename) ||
die("Could not open info file: $file\nFailure message: $!\n");
while (<INFOFILE>) {
if ($_ !~ /^\s*$/) {
($key, $value) = split(/: ?/, $_, 2);
chomp($value);
$info{$key} = $value;
}
}
close(INFOFILE) ||
die("Could not close info file: $file\nFailure message: $!\n");
if (! exists $info{'processed'} || ! scalar($info{'processed'})) {
my $args = [$BUILDBOT_PATH, "sendchange",
"--username", $info{'submitter'},
"--master", $MASTER_HOST,
"--comments", "$info{'description'}"];
my $required = [];
my $optional = [];
if ($info{'type'} eq "patch") {
push @$args, "--branch", $CVS_BRANCH;
push @$required, "mozconfig", "identifier", "branch", "patchLevel", "patchFile";
}
elsif ($info{'type'} eq "hg") {
push @$args, "--branch", $HG_BRANCH;
push @$required, "mozconfig", "identifier", "mozillaRepoPath";
push @$optional, "tamarinRepoPath", "patchLevel", "patchFile";
}
else {
print LOGFILE "Bad info file\n";
die;
}
foreach my $arg (@$required) {
if (!exists($info{$arg})) {
print LOGFILE "Missing arg '$arg' in info file\n";
die;
}
push @$args, "$arg: $info{$arg}";
}
foreach my $arg (@$optional) {
if (exists($info{$arg})) {
push @$args, "$arg: $info{$arg}";
}
}
$rv = RunShellCommand(command => $PYTHON_PATH,
args => $args);
if (0 == $rv->{'exitValue'} && -1 == index($rv->{'output'}, "NOT")) {
# sendchange succeeded
open(INFO, ">>$infoFilename") ||
die("Could not open info file: $file\nFailure message: $!\n");
print INFO "\nprocessed: 1\n";
close(INFO) ||
die("Coould not close info file: $file\nFailure message: $!\n");
sleep($DELAY);
}
else {
# sendchange failed
print LOGFILE "Could not send change: $file\n";
}
}
}
close(LOGFILE) || die("Could not close logfile\nFailure message: $!\n");