17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
# $Id: sbuild,v 1.159 2001/06/18 09:57:55 rnhodek Exp $
23
# Revision 1.159 2001/06/18 09:57:55 rnhodek
24
# Use --database option when wanna_build_dbbase set in config.
26
# Revision 1.158 2001/06/01 09:54:36 rnhodek
29
# Revision 1.157 2001/05/31 08:08:08 rnhodek
30
# Fixed thinko in conflicts checking (tnx James)
32
# Revision 1.156 2001/05/30 08:20:05 rnhodek
33
# Use /var/lib/apt as Dir::State if exists (newer apt versions use that)
34
# (tnx to Ryan Murray).
36
# Revision 1.155 2001/05/30 08:17:01 rnhodek
37
# Print also architecture at start of log.
39
# Revision 1.154 2001/05/29 07:33:54 rnhodek
40
# Also handle versioned Build-Conflicts.
41
# (Tnx to David Schleef <ds@schleef.org>)
43
# Revision 1.153 2001/03/13 08:45:17 rnhodek
44
# Run chmod -R on source tree only after unpacking.
46
# Revision 1.152 2001/02/19 09:23:24 rnhodek
49
# Revision 1.151 2001/02/19 08:43:22 rnhodek
50
# Fix wrong arch logic.
52
# Revision 1.150 2001/01/22 12:56:16 rnhodek
53
# Fix handling of arch-restricted build-deps (tnx to Ryan Murray).
55
# Revision 1.149 2001/01/15 11:17:36 rnhodek
58
# Revision 1.148 2001/01/15 10:59:18 rnhodek
59
# Shortcut when looking for non-dsc files: first try to fetch from same
60
# dir as .dsc and FF_search only if that fails.
62
# Revision 1.147 2001/01/10 16:16:48 rnhodek
63
# Move all built files from chroot dir, not only *.deb.
65
# Revision 1.146 2000/10/23 10:39:24 rnhodek
66
# Before doing chmod on /etc/ld.so.conf, test if it exists at all.
68
# Revision 1.145 2000/10/19 09:08:35 rnhodek
69
# A couple of little fixes from Ben.
70
# Checks and assures that /etc/ld.so.conf is readable.
71
# Support for local overrides with $conf::srcdep_over.
73
# Revision 1.144 2000/06/27 12:34:00 rnhodek
74
# Implemented new 'prepre' and 'unpack' sections for special targets;
75
# the first is a script run before package installation, and the latter
76
# can list source packages that should be unpacked in the build dir.
78
# Revision 1.143 2000/06/20 14:39:59 rnhodek
79
# Call apt-get with some options for relocating various files instead of
80
# chrooting it; this avoids that the archive must be available in chroot
81
# environment; same is true for dpkg and apt-cache calls.
82
# If chrooted, call dpkg with the chroot dir as cwd to avoid "cannot get
83
# current directory" errors; same for apt option DPkg::Run-Directory.
85
# Revision 1.142 2000/06/19 14:09:00 rnhodek
88
# Revision 1.141 2000/06/19 14:05:38 rnhodek
89
# Call buildd-addpkg with --chroot=DIR options for each dist that is >=
90
# the one building for (to run apt-get update in the chroot
93
# Revision 1.140 2000/06/19 09:10:24 rnhodek
94
# Obey new config var @ignore_watches_no_build_deps, i.e. don't flag
95
# watches that are listed there if the package doesn't have build deps.
96
# In check_watches(), strip $chroot_dir instead of $chroot_build_dir
99
# Revision 1.139 2000/06/13 10:54:43 rnhodek
100
# Also execute special dependency scripts in chroot environment.
102
# Revision 1.138 2000/06/09 12:47:52 rnhodek
103
# File .dsc filename for rbuilder (with URL).
105
# Revision 1.137 2000/06/09 09:15:21 rnhodek
106
# Always install built package (if already) when building chroot; i.e.
107
# the $system_level test is not necessary when chrooted.
109
# Revision 1.136 2000/06/09 08:20:52 rnhodek
110
# Fixed su usage in sub build.
112
# Revision 1.135 2000/06/08 14:02:11 rnhodek
113
# After changing to chroot dir, change back to be the normal user again
114
# and start dpkg-buildpackage with -rsudo again; some packages require
115
# that the build target is executed as non-root.
117
# Revision 1.134 2000/06/08 13:01:54 rnhodek
118
# apt-cache calls need sudo, too, when using chroot.
120
# Revision 1.133 2000/06/08 09:13:31 rnhodek
121
# Implemented chroot builds; there are a few new global variables
122
# $main::chroot_*; major changes are in build, where the source tree is
123
# unpacked somewhere else, dpkg-buildpackage called under chroot and
124
# built packages are moved back again; also all apt-get and dpkg calls
125
# are chroot-ed and /var/lib/dpkg/status is accessed from the chroot
126
# environment; also watches are checked under the new root dir.
128
# Revision 1.132 2000/06/06 14:37:05 rnhodek
129
# New option --source (-s): Also build source package, i.e. don't pass
130
# -b or -B to dpkg-buildpackage.
132
# Revision 1.131 2000/05/30 15:41:34 rnhodek
133
# Call buildd-addpkg with --dist option.
134
# Install freshly built packages only if $conf::system_level >= $dist.
136
# Revision 1.130 2000/05/16 12:34:20 rnhodek
137
# Insert a chmod -R go+rX on the build tree to make files readable; it
138
# happens sometimes that files in a .orig.tar.gz have restrictive
139
# permissions and this can be inconvenient.
141
# Revision 1.129 2000/03/01 14:43:34 rnhodek
142
# Also match error message "dpkg: status database area is locked" from
143
# apt and retry call later.
145
# Revision 1.128 2000/02/16 15:21:33 rnhodek
146
# Fix a print message in merge_pkg_build_deps.
148
# Revision 1.127 2000/02/16 15:20:38 rnhodek
149
# Print version number of sbuild in package log.
151
# Revision 1.126 2000/02/16 15:15:15 rnhodek
152
# Fix regexp for finding !needs-no-XXX packages.
153
# Move !needs-no-XXX from central deps to $main::additional_deps so that
154
# they can be found by prepare_watches later.
156
# Revision 1.125 2000/02/15 14:40:35 rnhodek
157
# Remove forgotten debugging code.
159
# Revision 1.124 2000/02/15 11:12:43 rnhodek
160
# Expand virtual packages in package build dependencies for comparing
163
# Revision 1.123 2000/02/11 11:17:07 rnhodek
164
# Do not activate watches for packages XXX if a negative dependency
165
# needs-no-XXX exists (used to be just a comment, now really processed
167
# Also do not activate watches for dependencies of pkg build deps.
169
# Revision 1.122 2000/02/09 15:57:25 rnhodek
170
# In merge_pkg_build_deps, do not show warnings about missing
171
# !this-package-does-not-exist or !needs-no-xxx dependencies.
173
# Revision 1.121 2000/02/04 14:04:18 rnhodek
174
# Use --no-down-propagation.
176
# Revision 1.120 2000/02/01 12:05:56 rnhodek
177
# In binNMU mode, a '_' was missing in the job name.
179
# Revision 1.119 2000/01/28 14:54:43 rnhodek
180
# Accept abbrevs for distribution options (-ds, -df, -du) here, too.
181
# New option --make-binNMU=entry.
182
# New binNMU hack to modify debian/changelog; it will add a new entry
183
# for the NMU version.
184
# New helper function binNMU_version to generate a new version number.
186
# Revision 1.118 2000/01/13 14:32:30 rnhodek
187
# For compiling on slink systems, pass the --force-confold option to
188
# dpkg only for versions < 1.4.1.18 (that don't understand it yet).
190
# Revision 1.117 1999/12/17 13:49:50 rnhodek
191
# Improved output about missing central deps: build-essential (act.
192
# policy) and dependencies of pkg build deps are filtered out and
193
# printed separately.
194
# New functions cmp_dep_lists, read_build_essential,
195
# expand_dependencies, and get_dependencies for the above.
197
# Revision 1.116 1999/12/17 11:04:43 rnhodek
198
# When pkg build-deps were read from debian/sbuild-build-deps, a wrong
199
# package name was used.
201
# Revision 1.115 1999/12/09 09:54:42 rnhodek
202
# Again fixed a fatal typo...
204
# Revision 1.114 1999/12/08 12:33:16 rnhodek
205
# merge_pkg_build_deps: Fix printing of overrides.
207
# Revision 1.113 1999/12/08 12:25:34 rnhodek
208
# Special dependencies are implicitly overrides, i.e. are added to the
209
# package-provided build deps.
211
# Revision 1.112 1999/12/08 11:31:38 rnhodek
212
# get_dpkg_status: don't reset $res{$pkg}->{Installed} to 0 if $pkg is
215
# Revision 1.111 1999/12/08 10:37:33 rnhodek
216
# Change parsing of .dsc file so that multi-line build dependencies are
218
# Make warning about missing central deps a bit bigger.
220
# Revision 1.110 1999/12/06 15:00:33 rnhodek
221
# Fix comparison with old deps (must copy them, not only the reference).
223
# Revision 1.109 1999/12/06 08:35:53 rnhodek
226
# Revision 1.108 1999/12/03 09:58:16 rnhodek
227
# If a pkg has its own build deps, compare them with the central ones
228
# and report missing ones.
230
# Revision 1.107 1999/11/30 13:54:38 rnhodek
231
# Print a message if build deps from the .dsc are used (to avoid confusion).
232
# If a pkg has build deps, store them in debian/.sbuild-build-deps to
233
# have them available when rebuilding later (no .dsc anymore); also
234
# check for this file and read deps from it if building without a .dsc
235
# in unpacked source.
237
# Revision 1.106 1999/11/15 12:30:15 rnhodek
238
# merge_pkg_build_deps: added missing if $main::debug.
240
# Revision 1.105 1999/11/03 14:56:32 rnhodek
241
# When running apt, set env var DEBIAN_FRONTEND to noninteractive to
242
# stop debconf from asking questions or complaining that /dev/tty can't
245
# Revision 1.104 1999/11/02 16:43:51 rnhodek
246
# check_inst_packages: also upgrade dependencies of src-deps (if they're
247
# already installed); some -dev packages fail to correctly require an
248
# identical versioned shlib pkg, so in some cases only the -dev pkg was
251
# Revision 1.103 1999/11/02 15:45:43 rnhodek
252
# build: Use epoch-stripped version number for the .changes file.
253
# check_inst_packages: forgot a if $main::debug.
255
# Revision 1.102 1999/10/29 13:07:49 rnhodek
256
# New option --stats-dir=DIR; if used, a "1" is appended to
257
# DIR/give-back each time a package is given back.
259
# Revision 1.101 1999/10/29 12:32:24 rnhodek
260
# If using an already unpacked source tree, check (with
261
# dpkg-parsechangelog) if it's really the requested version.
262
# Make apt-get run dpkg with --force-confold, as the </dev/null trick
263
# doesn't work anymore with dpkg >= 1.4.1.18.
265
# Revision 1.100 1999/10/25 12:12:21 rnhodek
266
# check_inst_packages: Add packages to @deps_inst only if they're not
267
# already to be installed.
269
# Revision 1.99 1999/10/22 09:01:36 rnhodek
270
# Minor changes to output of check_inst_packages.
272
# Revision 1.98 1999/10/21 14:21:57 rnhodek
273
# Oops... call check_inst_packages only if build was successful.
275
# Revision 1.97 1999/10/21 11:46:50 rnhodek
276
# Deleted RCS logs for < 1.50.
277
# New option --store-built-packages.
278
# Fix package name parsing: \w also matches '_' which is unwanted;
280
# Read reverse sourcedeps of $main::store_built_packages.
281
# New sub check_inst_packages.
283
# Revision 1.96 1999/09/27 11:18:10 rnhodek
284
# Added a missing PLOG.
286
# Revision 1.95 1999/09/15 09:10:25 rnhodek
287
# Additionally print a warning if a special dep has a version relation.
289
# Revision 1.94 1999/09/15 09:08:12 rnhodek
290
# Changed parsing of dependencies a bit so that special deps can have
291
# arch restrictions, too.
293
# Revision 1.93 1999/08/30 09:44:35 rnhodek
294
# get_dpkg_status: don't exit too early if a pkg isn't in the arg list,
295
# as it might be provided only.
297
# Revision 1.92 1999/08/27 13:32:04 rnhodek
298
# --auto-give-back has a new optional argument, the user and hostname
299
# where to call wanna-build (like $conf::sshcmd); this is needed that
300
# sbuild can do give-backs when there's no local wanna-build.
302
# Revision 1.91 1999/08/23 12:53:02 rnhodek
303
# Support for alternatives.
304
# Support for [ARCH1 !ARCH2] arch restriction on dependencies.
305
# Parses only src-deps which are needed for packages to be built.
306
# Reads Build-{Depends,Conflicts}{,-Indep}: fields from .dsc if present;
307
# those override the central src-deps, except those marked as override
309
# Implemented abbrevs as kind of macros in src-deps.
310
# New option --add-depends (-a).
311
# New option --arch-all (-A).
313
# Revision 1.90 1999/08/11 15:28:11 rnhodek
314
# Insert missing wait call in run_script to get correct return value.
316
# Revision 1.89 1999/08/10 14:01:49 rnhodek
317
# Virtual packages as dependencies didn't work really yet -- the
318
# consistency check didn't see them (dpkg --status doesn't know them)
319
# and thus aborted the build; solution: get_dpkg_status now directly
320
# reads the status file (which should be a bit faster, too) and extracts
321
# Provides: fields of all installed packages and considers those virtual
322
# packages installed, too.
323
# Print "Source-dependencies not satisfied" message to package log, not
325
# Same in run_apt for virtual package handling.
326
# Fix stdout/stderr redirecting when running scripts.
328
# Revision 1.88 1999/07/13 07:23:55 rnhodek
329
# Use GDBM for time/space databases, as perl-5.004 seems not to contain
332
# Revision 1.87 1999/06/21 12:52:00 rnhodek
333
# Seems apt has a new error message if a cached Packages file isn't
334
# up-to-date anymore -- recognize this msg, too, and reun apt-get update.
336
# Revision 1.86 1999/06/09 15:05:38 rnhodek
337
# Fix loop in apply_patches.
338
# Don't fail due to failed patch if a global patch.
339
# Global patches are no syntax error when parsing src-deps...
341
# Revision 1.85 1999/06/04 09:47:02 rnhodek
342
# Add support for global patches, which will be tried on any package;
343
# their names in source-dependencies start with "**".
345
# Revision 1.84 1999/06/04 08:17:17 rnhodek
346
# When calling wanna-build --give-back, don't forget the --dist argument!
347
# Added support for virtual packages as source dependencies: apt-get tells us
348
# which alternatives are possible, and one of these is selected either by
349
# %conf::alternatives or by random.
351
# Revision 1.83 1999/06/02 09:07:47 rnhodek
352
# With --batch, write each finished job to SBUILD-FINISHED; buildd can pick up
353
# this file if sbuild crashes and needs not rebuild already done stuff. The file
354
# is removed on normal exit and if sbuild dumps to REDO during a shutdown.
356
# Revision 1.82 1999/06/02 08:47:39 rnhodek
357
# Remove as many die's as possible -- the bad exit status can cause
358
# buildd to retry all packages of an sbuild run; better let this one
360
# Make sure that after build() we're in the correct directory: some
361
# chdir()s were missing; also don't chdir("..") because this can be
362
# wrong if we followed a symlink, use $main::cwd instead.
363
# If the package directory already exists as a symlink, abort the build.
365
# Revision 1.81 1999/05/31 12:59:41 rnhodek
366
# Run du after build under sudo, to avoid error messages about
369
# Revision 1.80 1999/05/27 13:28:04 rnhodek
370
# Oops, missed an epoch fix (when constructing the .changes file name).
372
# Revision 1.79 1999/05/26 11:34:11 rnhodek
373
# Ignore epochs for fetching files.
375
# Revision 1.78 1999/05/26 09:48:23 rnhodek
376
# If dpkg-source fails, remove .tmp-nest dir.
378
# Revision 1.77 1999/05/05 07:56:51 rnhodek
379
# Need to empty %main::this_watches before filling it for a new package;
380
# otherwise we have some spurious reports :-)
382
# Revision 1.76 1999/05/04 14:51:40 rnhodek
383
# Some more minor stuff for avg-build-space: Reset global
384
# $main::this_space to 0 before each build to avoid using the figure of
385
# the previous package in case of errors; don't write a 0 value into the
388
# Revision 1.75 1999/05/04 14:43:01 rnhodek
389
# Fix parsing of a single dependency: package name never should contain
392
# Revision 1.74 1999/05/04 14:29:51 rnhodek
393
# Determine how much space is required for a build (final build dir +
394
# generated .debs) after dpkg-buildpackage is finished; display figure
395
# in package log and also store it in $conf::avg_space_db (analogous to
398
# Revision 1.73 1999/05/03 12:53:25 rnhodek
399
# After unpacking src dir, run "chmod -R g-s ." on it; some
400
# .orig.tar.gz's are packed with the setgid bit, which causes the debian
401
# dir and all subdirs to be created setgid, too, and later dpkg-deb
402
# --build complains about this.
404
# Revision 1.72 1999/04/22 14:16:25 rnhodek
405
# Don't kill tee process if verbose but --nolog set -- $pkg_tee_pid
408
# Revision 1.71 1999/04/21 14:54:10 rnhodek
409
# Implemented watches if certain binaries have been used during a build
410
# without a source dependency.
412
# Revision 1.70 1999/03/12 10:29:32 rnhodek
413
# New option --force-depends (-f) to override src-deps of a package.
20
# $Id: sbuild,v 1.7 2005/03/31 16:42:48 mbanck Exp $
686
328
unlink( "SBUILD-FINISHED" ) if $main::batchmode;
690
331
sub fetch_source_files {
693
($pkg, $version) = split /_/, $pkgv;
694
my ($files, $dscarchs, @made, %entries, $fetch);
332
my $dscfile_ref = shift;
333
my $dscfile = $$dscfile_ref;
334
my ($dir, $dscbase, $files, @other_files, $dscarchs, @made);
695
335
my ($build_depends, $build_depends_indep, $build_conflicts,
696
336
$build_conflicts_indep);
699
if (-f "${pkgv}.dsc") {
700
print PLOG "${pkgv}.dsc exists in cwd\n";
708
print PLOG "Checking available source versions...\n";
709
if (!open( PIPE, "apt-cache $main::chroot_apt_options ".
710
"-q showsrc $pkg 2>&1 </dev/null |" )) {
711
print PLOG "Can't open pipe to apt-cache: $!\n";
716
my $ver = $1 if /Version:\s+(\S+)\s*$/mi;
717
my $tfile = $1 if /^Files:\s*\n((\s+.*\s*\n)+)/mi;
718
@{$entries{$ver}} = map { (split( /\s+/, $_ ))[3] }
719
split( "\n", $files );
724
print PLOG "Apt-cache failed\n";
728
if (!defined($entries{$version})) {
729
print PLOG "Can't find source for $pkgv\n";
731
foreach my $entry (keys %entries) {
733
print PLOG "(only different version(s)";
737
print PLOG " $entry";
740
print PLOG " found)\n" if $c;
744
# XXX: Apt-get always fetches the latest version. We need to make
745
# sure our version is the newest one and hope that apt-get
746
# supports versioned fetches one day.
747
my $newest = $version;
748
foreach my $entry (keys %entries) {
749
$newest = $entry if version_cmp($entry, '>>', $newest);
751
if ($newest ne $version) {
752
print PLOG "Version skew. Latest version is $newest, not $version.\n";
756
@made = @{$entries{$version}};
758
print PLOG "Fetching source files...\n";
759
if (!open( PIPE, "$conf::apt_get $main::chroot_apt_options ".
760
"--only-source -q -d source $pkg 2>&1 </dev/null |" )) {
761
print PLOG "Can't open pipe to apt-get: $!\n";
762
return ("ERROR", @made);
769
print PLOG "Apt-get of sources failed\n";
770
return( "ERROR", @made );
772
push @made, "${pkgv}.dsc";
777
if (!open( F, "<${pkgv}.dsc" )) {
778
print PLOG "Can't open ${pkgv}.dsc: $!\n";
339
$dscfile =~ m,^(.*)/([^/]+)$,;
340
($dir, $dscbase) = ($1, $2);
342
$urlbase = $1 if $dscfile =~ m,^(\w+://(\S+/)?)([^/]+)$,;
343
(my $pkgv = $dscfile) =~ s,^(.*/)?([^/]+)\.dsc$,$2,;
344
my ($pkg, $version) = split /_/, $pkgv;
345
@main::have_dsc_build_deps = ();
348
if (-f "$dscfile/debian/.sbuild-build-deps") {
349
open( F, "<$dscfile/debian/.sbuild-build-deps" );
352
/^Package:\s*(.*)\s*$/i and $pkg = $1;
353
/^Build-Depends:\s*(.*)\s*$/i and $build_depends = $1;
354
/^Build-Depends-Indep:\s*(.*)\s*$/i and $build_depends_indep = $1;
355
/^Build-Conflicts:\s*(.*)\s*$/i and $build_conflicts = $1;
356
/^Build-Conflicts-Indep:\s*(.*)\s*$/i and $build_conflicts_indep = $1;
359
if ($build_depends || $build_depends_indep || $build_conflicts ||
360
$build_conflicts_indep) {
361
merge_pkg_build_deps( $pkg, $build_depends,
362
$build_depends_indep, $build_conflicts,
363
$build_conflicts_indep );
371
if (-f "${pkgv}.dsc") {
372
print PLOG "${pkgv}.dsc exists in cwd\n";
379
print PLOG "Checking available source versions...\n";
380
if (!open( PIPE, "$conf::apt_cache $main::chroot_apt_options ".
381
"-q showsrc $pkg 2>&1 </dev/null |" )) {
382
print PLOG "Can't open pipe to apt-cache: $!\n";
387
my $ver = $1 if /^Version:\s+(\S+)\s*$/mi;
388
my $tfile = $1 if /^Files:\s*\n((\s+.*\s*\n)+)/mi;
389
@{$entries{$ver}} = map { (split( /\s+/, $_ ))[3] }
390
split( "\n", $tfile );
395
print PLOG "$conf::apt_cache failed\n";
399
if (!defined($entries{$version})) {
401
# try to update apt's cache if nothing found
402
system "$conf::sudo $conf::apt_get ".
403
"$main::chroot_apt_options update >/dev/null";
407
print PLOG "Can't find source for $pkgv\n";
408
print PLOG "(only different version(s) ",
409
join( ", ", sort keys %entries), " found)\n"
414
# XXX: Apt-get always fetches the latest version. We
415
# need to make sure our version is the newest one and
416
# hope that apt-get supports versioned fetches one
418
my $newest = $version;
419
foreach my $entry (keys %entries) {
420
$newest = $entry if version_cmp($entry, '>>', $newest);
422
if ($newest ne $version) {
423
print PLOG "Version skew. Latest version is $newest, ".
428
print PLOG "Fetching source files...\n";
429
@made = @{$entries{$version}};
430
if (!open( PIPE, "$conf::apt_get $main::chroot_apt_options ".
431
"--only-source -q -d source $pkg 2>&1 </dev/null |" )) {
432
print PLOG "Can't open pipe to $conf::apt_get: $!\n";
433
return ("ERROR", @made);
440
print PLOG "$conf::apt_get for sources failed\n";
441
return( "ERROR", @made );
443
$$dscfile_ref = $dscfile = (grep { /\.dsc$/ } @made)[0];
448
if (!open( F, "<$dscfile" )) {
449
print PLOG "Can't open $dscfile: $!\n";
779
450
return( "ERROR", @made );
782
454
{ local($/); $dsctext = <F>; }
785
$dsctext =~ /^Files:\s*\n((\s+.*\s*\n)+)/mi and $files = $1;
786
push @made, map { (split( /\s+/, $_ ))[3] } split( "\n", $files ) if $fetch;
787
457
$dsctext =~ /^Build-Depends:\s*((.|\n\s+)*)\s*$/mi
788
458
and $build_depends = $1;
789
459
$dsctext =~ /^Build-Depends-Indep:\s*((.|\n\s+)*)\s*$/mi