tools/release/release
author dbaron@dbaron.org
Wed, 15 Aug 2007 17:03:29 -0700
changeset 4701 5c27a0fafb0f6720de04309a79b80a0b0d81796c
parent 3322 d457d32a705be2503eb5e2e0368addbdcd77f5b2
child 5156 a1d9d1fd879298834b1a867280acdca7263e7848
permissions -rwxr-xr-x
Enable Linux stack walking code on Mac OS X. b=336517 r+a=bsmedberg

#!/usr/bin/perl -w
use strict;

use Getopt::Long;

use MozBuild::Util qw(Email);

use Bootstrap::Step::Tag;
use Bootstrap::Step::TinderConfig;
use Bootstrap::Step::Build;
use Bootstrap::Step::Source;
use Bootstrap::Step::Repack;
use Bootstrap::Step::PatcherConfig;
use Bootstrap::Step::Updates;
use Bootstrap::Step::Stage;
use Bootstrap::Step::Sign;

my @allSteps = (
    'Tag',
    'TinderConfig',
    'Build',
    'Source',
    'Repack',
    'PatcherConfig',
    'Updates',
    'Stage',
    'Sign',
);

my %config;

sub main {
    ProcessArgs();
    DetermineSteps();
}

sub ProcessArgs {
    GetOptions(
        \%config,
        "step|s=s", "only|o=s", "list|l", "help|h", "execute|e", "verify|v",
        "push|p", "announce|a"
    );

    if ($config{'list'}) {
        print "Bootstrap listing all steps.\n";
        for my $step (@allSteps) {
            print "$step\n";
        }
        exit(0);
    }

    if ($config{'help'}) {
        print "Usage: release [-l] [-s Step] [-o Step] [-e | -v | -p | -a] [-h]\n";
        print "    -l list all Steps\n";
        print "    -s start at Step\n";
        print "    -o only run one Step\n";
        print "    -e only run Execute\n";
        print "    -v only run Verify\n";
        print "    -p only run Push\n";
        print "    -a only run Announce\n";
        print "    -h this usage message\n";
        exit(0);
    }
}

sub DetermineSteps() {
    my $desiredStep;

    if (defined($config{'step'})) {
        $desiredStep = $config{'step'};
        print "Bootstrap skip to step: $desiredStep\n";
    }
    if (defined($config{'only'})) {
        $desiredStep = $config{'only'};
        print "Bootstrap only run step: $desiredStep\n";
    }

    my $currentStep = -1;
    if (defined($desiredStep)) {
        if (not grep(/^$desiredStep$/, @allSteps)) {
            die("ASSERT: $desiredStep is not a valid step name.");
        }
        for (my $i=0; $i < scalar(@allSteps); $i++) {
            if ($allSteps[$i] eq "$desiredStep") {
                $currentStep = $i;
            }
        }
        if ($currentStep == -1) {
            die("Step $desiredStep not found!\n");
        }
    } else {
        print "Bootstrap running default steps.\n";
        $currentStep = 0;
    }

    while ($currentStep < scalar(@allSteps)) {
        my $stepName = $allSteps[$currentStep];
        PerformStep( stepName => $stepName );
        $currentStep += 1;
        if (defined($config{'only'})) {
            if ($config{'only'} eq $stepName) {
                 exit(0);
            }
        }
    }

    print "Bootstrap finished all steps.\n";
}


sub PerformStep {
    my %args = @_;
    my $stepName = $args{'stepName'};
    print "Bootstrap running $stepName\n";
    my $step = "Bootstrap::Step::$stepName"->new();
    eval {
        if (defined($config{'execute'})) {
            print "Bootstrap only running Execute\n";
            $step->Execute();
        } elsif (defined($config{'verify'})) {
            print "Bootstrap only running Verify\n";
            $step->Verify();
        } elsif (defined($config{'push'})) {
            print "Bootstrap only running Push\n";
            $step->Push();
        } elsif (defined($config{'announce'})) {
            print "Bootstrap only running Announce\n";
            $step->Announce();
        } else {
            $step->Execute();
            $step->Verify();
            $step->Push();
            $step->Announce();
        }
    };
    if ($@) {
        my $error = $@;
        print "Step $stepName died: $error";
        my $conf = new Bootstrap::Config();
        my $from = $conf->Get(var => 'from');
        my $to = $conf->Get(var => 'to');
        my @ccList = $conf->Exists(var => 'cc') ? split(/[,\s]+/, 
          $conf->Get(var => 'cc')) : ();
        my $blat = $conf->Get(var => 'blat');
        my $sendmail = $conf->Get(var => 'sendmail');
        my $hostname = $conf->SystemInfo(var => 'hostname');

        eval {
            Email(
              blat => $blat,
              sendmail => $sendmail,
              from => $from,
              to => $to,
              cc => \@ccList,
              subject => "$hostname - Step $stepName died: $error",
              message => "$hostname - Step $stepName died: $error",
            );
            exit(1);
        };
        if ($@) {
            print "Unable to email failure message to $to: $@";
            exit(1);
        }
    }
}

main();