63
my $current_job = undef;
68
my $dist = $conf->get('DISTRIBUTION');
69
if (!defined($dist) || !$dist) {
70
print STDERR "No distribution defined\n";
74
print "Selected distribution " . $conf->get('DISTRIBUTION') . "\n"
75
if $conf->get('DEBUG');
76
print "Selected chroot " . $conf->get('CHROOT') . "\n"
77
if $conf->get('DEBUG') and defined $conf->get('CHROOT');
78
print "Selected architecture " . $conf->get('ARCH') . "\n"
79
if $conf->get('DEBUG' && defined($conf->get('ARCH')));
83
68
$SIG{'INT'} = \&main::shutdown;
84
69
$SIG{'TERM'} = \&main::shutdown;
85
70
$SIG{'ALRM'} = \&main::shutdown;
88
73
# If no arguments are supplied, assume we want to process the current dir.
89
74
push @ARGV, '.' unless (@ARGV);
93
foreach my $job (@ARGV) {
94
$jobs{$job} = Sbuild::Build->new($job, $conf);
95
$jobs{$job}->set('Pkg Status Trigger', \&status_trigger)
76
die "Only one build is permitted\n"
81
my $jobname = $ARGV[0];
85
$jobname = create_source_package($jobname);
89
# Check after source package build (which might set dist)
90
my $dist = $conf->get('DISTRIBUTION');
91
if (!defined($dist) || !$dist) {
92
print STDERR "No distribution defined\n";
96
print "Selected distribution " . $conf->get('DISTRIBUTION') . "\n"
97
if $conf->get('DEBUG');
98
print "Selected chroot " . $conf->get('CHROOT') . "\n"
99
if $conf->get('DEBUG') and defined $conf->get('CHROOT');
100
print "Selected architecture " . $conf->get('ARCH') . "\n"
101
if $conf->get('DEBUG' && defined($conf->get('ARCH')));
103
$job = Sbuild::Build->new($jobname, $conf);
104
$job->set('Pkg Status Trigger', \&status_trigger);
97
105
write_jobs_file(); # Will now update on trigger.
99
# Run each job. Potential for parallelising this step.
100
foreach (keys %jobs) {
103
my $job = $jobs{$jobname};
104
$current_job = $jobname;
109
dump_main_state() if $conf->get('DEBUG');
110
dump_main_state() if $conf->get('DEBUG');
119
119
dump_main_state();
120
120
print STDERR $e->trace->as_string, "\n";
122
} elsif (!defined($e)) {
123
print STDERR "E: $@\n" if $@;
125
126
unlink($conf->get('JOB_FILE'))
126
127
if $conf->get('BATCH_MODE');
127
unlink("SBUILD-FINISHED") if $conf->get('BATCH_MODE');
129
129
# Until buildd parses status info from sbuild output, skipped must
130
130
# be treated as a failure.
131
if (defined($current_job) && defined($jobs{$current_job})) {
132
if ($jobs{$current_job}->get_status() eq "successful" ||
132
if ($job->get_status() eq "successful" ||
133
133
($conf->get('SBUILD_MODE') ne "buildd" &&
134
$jobs{$current_job}->get_status() eq "skipped")) {
134
$job->get_status() eq "skipped")) {
136
} elsif ($jobs{$current_job}->get_status() eq "attempted") {
136
} elsif ($job->get_status() eq "attempted") {
138
} elsif ($jobs{$current_job}->get_status() eq "given-back") {
138
} elsif ($job->get_status() eq "given-back") {
139
139
#Probably needs a give back:
143
143
# reported to the admin as failure:
149
sub create_source_package ($) {
151
$dsc = abs_path($dsc);
153
open(my $pipe, '-|', 'dpkg-parsechangelog',
154
'-l' . $dsc . '/debian/changelog')
155
or Sbuild::Exception::Build->throw(
156
error => "Could not parse $dsc/debian/changelog: $!",
157
failstage => "pack-source");
159
my $pclog = Dpkg::Control->new(type => CTRL_CHANGELOG);
160
if (!$pclog->parse($pipe, 'dpkg-parsechangelog')) {
161
Sbuild::Exception::Build->throw(
162
error => "Could not parse $dsc/debian/changelog: $!",
163
failstage => "pack-source");
166
$pipe->close or Sbuild::Exception::Build->throw(
167
error => "dpkg-parsechangelog failed (exit status $?)",
168
failstage => "pack-source");
170
my $package = $pclog->{'Source'};
171
my $version = $pclog->{'Version'};
173
if (!defined($package) || !defined($version)) {
174
Sbuild::Exception::Build->throw(
175
error => "Missing Source or Version in $dsc/debian/changelog",
176
failstage => "pack-source");
179
my $dist = $pclog->{'Distribution'};
180
my $pver = Dpkg::Version->new($version, check => 1);
182
Sbuild::Exception::Build->throw(
183
error => "Bad version $version in $dsc/debian/changelog",
184
failstage => "pack-source");
187
my ($epoch, $uversion, $dversion);
188
$epoch = $pver->epoch();
189
$uversion = $pver->version();
190
$dversion = $pver->revision();
192
if (!defined($conf->get('DISTRIBUTION')) ||
193
!$conf->get('DISTRIBUTION')) {
194
$conf->set('DISTRIBUTION', $dist);
199
# Note: need to support cases when invoked from a subdirectory
200
# of the build directory, i.e. $dsc/foo -> $dsc/.. in addition
201
# to $dsc -> $dsc/.. as below.
202
if ($dir eq abs_path($dsc) &&
203
$dir eq $conf->get('BUILD_DIR')) {
204
# We won't attempt to build the source package from the source
205
# directory so the source package files will go to the parent dir.
206
$dir = abs_path("$dir/..");
207
$conf->set('BUILD_DIR', $dir);
210
$dsc = "${dir}/${package}_${uversion}-${dversion}.dsc";
212
system($conf->get('FAKEROOT'), 'debian/rules', 'clean');
214
Sbuild::Exception::Build->throw(
215
error => "Failed to clean source directory",
216
failstage => "pack-source");
218
chdir($dir) or Sbuild::Exception::Build->throw(
219
error => "Failed to change directory",
220
failstage => "pack-source");
221
my @dpkg_source_command = ($conf->get('DPKG_SOURCE'), '-b');
222
push @dpkg_source_command, @{$conf->get('DPKG_SOURCE_OPTIONS')}
223
if ($conf->get('DPKG_SOURCE_OPTIONS'));
224
push @dpkg_source_command, "${package}-${uversion}";
225
system(@dpkg_source_command);
227
Sbuild::Exception::Build->throw(
228
error => "Failed to package source directory",
229
failstage => "pack-source");
231
chdir($origdir) or Sbuild::Exception::Build->throw(
232
error => "Failed to change directory",
233
failstage => "pack-source");
148
238
# only called from main loop, but depends on job state.