~ubuntu-branches/ubuntu/oneiric/sbuild/oneiric

« back to all changes in this revision

Viewing changes to bin/sbuild

  • Committer: Bazaar Package Importer
  • Author(s): Lorenzo De Liso
  • Date: 2011-05-01 16:55:16 UTC
  • mfrom: (8.1.19 upstream) (3.3.17 sid)
  • Revision ID: james.westby@ubuntu.com-20110501165516-8g3uwrnhv2bzjt8y
Tags: 0.62.2-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/patches/do-not-install-debfoster-into-chroots.patch: 
    do not install debfoster into the chroots because it is in universe and 
    not needed for package building itself.
  - debian/patches/run-pre-build-hooks-as-root.patch: 
    run pre-build hooks as root (Closes: #607228)
* Now that the package uses a patch system, don't modify the files directly;
  instead, put the changes in the respective patches and add the DEP-3
  patch tagging guidelines to them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
use POSIX;
32
32
use Data::Dumper;
33
 
use Sbuild qw(isin check_group_membership);
 
33
use Sbuild qw(isin check_group_membership $debug_level);
34
34
use Sbuild::Conf qw();
35
35
use Sbuild::Log qw(open_log close_log);
36
36
use Sbuild::Sysconfig qw(%programs);
37
37
use Sbuild::Options;
38
38
use Sbuild::Build;
 
39
use Sbuild::Exception;
39
40
 
40
41
sub main ();
41
42
sub write_jobs_file ();
50
51
exit 1 if !defined($options);
51
52
check_group_membership();
52
53
 
53
 
umask(022);
 
54
if (!$conf->get('MAINTAINER_NAME') &&
 
55
    ($conf->get('BIN_NMU') || $conf->get('APPEND_TO_VERSION'))) {
 
56
        die "A maintainer name, uploader name or key ID must be specified in .sbuildrc,\nor use -m, -e or -k, when performing a binNMU or appending a version suffix\n";
 
57
}
 
58
 
 
59
umask(002);
54
60
 
55
61
# Job state
56
62
my %jobs = ();
83
89
    push @ARGV, '.' unless (@ARGV);
84
90
 
85
91
    # Create jobs
86
 
    foreach my $job (@ARGV) {
87
 
        $jobs{$job} = Sbuild::Build->new($job, $conf);
88
 
        $jobs{$job}->set('Pkg Status Trigger', \&status_trigger)
89
 
    }
90
 
    write_jobs_file(); # Will now update on trigger.
91
 
 
92
 
    # Run each job.  Potential for parallelising this step.
93
 
    foreach (keys %jobs) {
94
 
        my $jobname = $_;
95
 
 
96
 
        my $job = $jobs{$jobname};
97
 
        $current_job = $jobname;
98
 
 
99
 
        # Do the build
100
 
        $job->run();
101
 
 
102
 
        dump_main_state() if $conf->get('DEBUG');
 
92
    eval {
 
93
        foreach my $job (@ARGV) {
 
94
            $jobs{$job} = Sbuild::Build->new($job, $conf);
 
95
            $jobs{$job}->set('Pkg Status Trigger', \&status_trigger)
 
96
        }
 
97
        write_jobs_file(); # Will now update on trigger.
 
98
 
 
99
        # Run each job.  Potential for parallelising this step.
 
100
        foreach (keys %jobs) {
 
101
            my $jobname = $_;
 
102
 
 
103
            my $job = $jobs{$jobname};
 
104
            $current_job = $jobname;
 
105
 
 
106
            # Do the build
 
107
            $job->run();
 
108
 
 
109
            dump_main_state() if $conf->get('DEBUG');
 
110
        }
 
111
    };
 
112
 
 
113
    my $e;
 
114
    if ($e = Exception::Class->caught('Sbuild::Exception::Build')) {
 
115
        print STDERR "E: $e\n";
 
116
        print STDERR "I: " . $e->info . "\n"
 
117
            if ($e->info);
 
118
        if ($debug_level) {
 
119
            dump_main_state();
 
120
            print STDERR $e->trace->as_string, "\n";
 
121
        }
103
122
    }
104
123
 
105
124
    close_log($conf);
182
201
sub shutdown ($) {
183
202
    my $job = undef;
184
203
    my $signame = shift;
185
 
    my(@npkgs,@pkgs);
186
 
    local( *F );
187
204
 
188
205
    $SIG{'INT'} = 'IGNORE';
189
206
    $SIG{'QUIT'} = 'IGNORE';
194
211
    $job = $jobs{$current_job} if (defined($current_job) &&
195
212
                                   defined($jobs{$current_job}));
196
213
 
197
 
    # TODO: Use main log
198
 
    if (defined($job)) {
199
 
        $job->log("sbuild received SIG$signame -- shutting down\n");
200
 
    }
201
 
 
202
 
    if (defined($job)) {
203
 
        my $session = $job->get('Session');
204
 
        my $resolver = $job->get('Dependency Resolver');
205
 
 
206
 
        # Kill currently running command (if any)
207
 
        if ($job->get('Sub PID')) {
208
 
            print "Killing " . $job->get('Sub Task') .
209
 
                " subprocess " . $job->get('Sub PID') . "\n";
210
 
            $job->get('Session')->run_command(
211
 
                { COMMAND => ['perl', '-e',
212
 
                              "\"kill( \\\"TERM\\\", " .
213
 
                              $job->get('Sub PID') .
214
 
                              " )\""],
215
 
                              USER => 'root',
216
 
                              PRIORITY => 0,
217
 
                              DIR => '/' });
218
 
        }
219
 
 
220
 
        if (defined($session) && $conf->get('BATCH_MODE') &&
221
 
            !$conf->get('SBUILD_MODE') eq "buildd") {
222
 
            # next: say which packages should be uninstalled
223
 
            if (defined ($session->get('Session Purged')) && $session->get('Session Purged') == 1) {
224
 
                print "Not removing build depends: cloned chroot in use\n";
225
 
            } else {
226
 
                @pkgs = keys %{$resolver->get('Changes')->{'installed'}};
227
 
                if (@pkgs) {
228
 
                    if (open( F, ">>NEED-TO-UNINSTALL" )) {
229
 
                        print F "@pkgs\n";
230
 
                        close( F );
231
 
                    }
232
 
                    print "The following packages still need to be uninstalled ",
233
 
                    "(--purge):\n@pkgs\n";
234
 
                }
235
 
            }
236
 
        }
237
 
 
238
 
        # Close logs and send mails
239
 
        if (defined($session) &&
240
 
            $conf->get('PURGE_BUILD_DIRECTORY') eq "always" &&
241
 
            defined($job->get('Chroot Build Dir'))) {
242
 
            $job->log("Purging " . $job->get('Chroot Build Dir') . "\n");
243
 
            my $bdir = $job->get('Session')->strip_chroot_path($job->get('Chroot Build Dir'));
244
 
            $job->get('Session')->run_command(
245
 
                { COMMAND => ['rm', '-rf', $bdir],
246
 
                  USER => 'root',
247
 
                  PRIORITY => 0,
248
 
                  DIR => '/' });
249
 
        }
250
 
 
251
 
        if (defined($resolver)) {
252
 
            $resolver->cleanup();
253
 
        }
254
 
 
255
 
        if (defined($session)) {
256
 
            $session->unlock_chroot();
257
 
            $session->end_session();
258
 
            $job->set('Session', undef);
259
 
        }
260
 
 
261
 
        $job->close_build_log();
262
 
        $job->set('binNMU Name', undef);
263
 
    }
264
 
 
265
 
    close_log($conf);
266
 
 
267
 
    # Restore the signal handler to let a self-kill result in the appropriate
268
 
    # exit code.
269
 
    $SIG{$signame} = 'DEFAULT';
270
 
    kill($signame, $$) or die("self-kill failed");
 
214
    if (defined($job)) {
 
215
        $job->request_abort("Received $signame signal");
 
216
    } else {
 
217
        exit(1);
 
218
    }
 
219
 
 
220
    $SIG{'INT'} = \&main::shutdown;
 
221
    $SIG{'TERM'} = \&main::shutdown;
 
222
    $SIG{'ALRM'} = \&main::shutdown;
 
223
    $SIG{'PIPE'} = \&main::shutdown;
271
224
}
272
225
 
273
226
sub dump_main_state () {