~ubuntu-branches/ubuntu/karmic/sbuild/karmic

« back to all changes in this revision

Viewing changes to sbuild

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2005-04-01 21:23:30 UTC
  • mfrom: (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050401212330-lnjvuwrm9urpy54l
Tags: 0.35
Michael Banck:

* bin/abort-current-build: Remove the `-B' from the grep line as
  `sbuild -s' does not pass that option to dpkg-configure and abort-
  current-build fails in that case.
* sbuild: Set the locale to `POSIX' to make debconf and debhelper calls in
  the chroot not spew out locale warnings all the time.
  (closes: #287672)
* sbuild: Removed check for specific distributions. Instead, fail if
  build/chroot-$dist is not there.
* sbuild: Only override Distribution in .changes if specified as option on
  the command-line.
  (closes: #300145)
* sbuild: Specify full path for Dir::Etc::main and Dir::Etc::parts.
* example.sbuildrc: Clarify that $maintainer_name is not mandatory and
  overrides Maintainer: field, whereas $uploader_name overrides
  the Changed-By: field in changes.
* Applied patch by Santiago Vila:
  - Moves scripts from /usr/lib/sbuild to /usr/share/sbuild and modifies
    all callers accordingly.
  - Add -n option to tail to comply with POSIX.
  - Call /usr/sbin/sendmail instead of /usr/lib/sendmail.
  (closes: #292717)
* sbuild: Tolerate '0' as version number, thanks Santiago Vila.
  (closes: #300205)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
19
#
20
 
# $Id: sbuild,v 1.159 2001/06/18 09:57:55 rnhodek Exp $
21
 
#
22
 
# $Log: sbuild,v $
23
 
# Revision 1.159  2001/06/18 09:57:55  rnhodek
24
 
# Use --database option when wanna_build_dbbase set in config.
25
 
#
26
 
# Revision 1.158  2001/06/01 09:54:36  rnhodek
27
 
# Fix two typos.
28
 
#
29
 
# Revision 1.157  2001/05/31 08:08:08  rnhodek
30
 
# Fixed thinko in conflicts checking (tnx James)
31
 
#
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).
35
 
#
36
 
# Revision 1.155  2001/05/30 08:17:01  rnhodek
37
 
# Print also architecture at start of log.
38
 
#
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>)
42
 
#
43
 
# Revision 1.153  2001/03/13 08:45:17  rnhodek
44
 
# Run chmod -R on source tree only after unpacking.
45
 
#
46
 
# Revision 1.152  2001/02/19 09:23:24  rnhodek
47
 
# Fix typo.
48
 
#
49
 
# Revision 1.151  2001/02/19 08:43:22  rnhodek
50
 
# Fix wrong arch logic.
51
 
#
52
 
# Revision 1.150  2001/01/22 12:56:16  rnhodek
53
 
# Fix handling of arch-restricted build-deps (tnx to Ryan Murray).
54
 
#
55
 
# Revision 1.149  2001/01/15 11:17:36  rnhodek
56
 
# Fixed typo.
57
 
#
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.
61
 
#
62
 
# Revision 1.147  2001/01/10 16:16:48  rnhodek
63
 
# Move all built files from chroot dir, not only *.deb.
64
 
#
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.
67
 
#
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.
72
 
#
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.
77
 
#
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.
84
 
#
85
 
# Revision 1.142  2000/06/19 14:09:00  rnhodek
86
 
# Fix syntax error.
87
 
#
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
91
 
# environments).
92
 
#
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
97
 
# from pathname.
98
 
#
99
 
# Revision 1.139  2000/06/13 10:54:43  rnhodek
100
 
# Also execute special dependency scripts in chroot environment.
101
 
#
102
 
# Revision 1.138  2000/06/09 12:47:52  rnhodek
103
 
# File .dsc filename for rbuilder (with URL).
104
 
#
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.
108
 
#
109
 
# Revision 1.136  2000/06/09 08:20:52  rnhodek
110
 
# Fixed su usage in sub build.
111
 
#
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.
116
 
#
117
 
# Revision 1.134  2000/06/08 13:01:54  rnhodek
118
 
# apt-cache calls need sudo, too, when using chroot.
119
 
#
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.
127
 
#
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.
131
 
#
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.
135
 
#
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.
140
 
#
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.
144
 
#
145
 
# Revision 1.128  2000/02/16 15:21:33  rnhodek
146
 
# Fix a print message in merge_pkg_build_deps.
147
 
#
148
 
# Revision 1.127  2000/02/16 15:20:38  rnhodek
149
 
# Print version number of sbuild in package log.
150
 
#
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.
155
 
#
156
 
# Revision 1.125  2000/02/15 14:40:35  rnhodek
157
 
# Remove forgotten debugging code.
158
 
#
159
 
# Revision 1.124  2000/02/15 11:12:43  rnhodek
160
 
# Expand virtual packages in package build dependencies for comparing
161
 
# with central deps.
162
 
#
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
166
 
# by sbuild.)
167
 
# Also do not activate watches for dependencies of pkg build deps.
168
 
#
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.
172
 
#
173
 
# Revision 1.121  2000/02/04 14:04:18  rnhodek
174
 
# Use --no-down-propagation.
175
 
#
176
 
# Revision 1.120  2000/02/01 12:05:56  rnhodek
177
 
# In binNMU mode, a '_' was missing in the job name.
178
 
#
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.
185
 
#
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).
189
 
#
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.
196
 
#
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.
200
 
#
201
 
# Revision 1.115  1999/12/09 09:54:42  rnhodek
202
 
# Again fixed a fatal typo...
203
 
#
204
 
# Revision 1.114  1999/12/08 12:33:16  rnhodek
205
 
# merge_pkg_build_deps: Fix printing of overrides.
206
 
#
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.
210
 
#
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
213
 
# provided.
214
 
#
215
 
# Revision 1.111  1999/12/08 10:37:33  rnhodek
216
 
# Change parsing of .dsc file so that multi-line build dependencies are
217
 
# allowed.
218
 
# Make warning about missing central deps a bit bigger.
219
 
#
220
 
# Revision 1.110  1999/12/06 15:00:33  rnhodek
221
 
# Fix comparison with old deps (must copy them, not only the reference).
222
 
#
223
 
# Revision 1.109  1999/12/06 08:35:53  rnhodek
224
 
# Fixed typo.
225
 
#
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.
229
 
#
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.
236
 
#
237
 
# Revision 1.106  1999/11/15 12:30:15  rnhodek
238
 
# merge_pkg_build_deps: added missing if $main::debug.
239
 
#
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
243
 
# be opened.
244
 
#
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
249
 
# installed.
250
 
#
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.
254
 
#
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.
258
 
#
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.
264
 
#
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.
268
 
#
269
 
# Revision 1.99  1999/10/22 09:01:36  rnhodek
270
 
# Minor changes to output of check_inst_packages.
271
 
#
272
 
# Revision 1.98  1999/10/21 14:21:57  rnhodek
273
 
# Oops... call check_inst_packages only if build was successful.
274
 
#
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;
279
 
# replace by a-zA-Z.
280
 
# Read reverse sourcedeps of $main::store_built_packages.
281
 
# New sub check_inst_packages.
282
 
#
283
 
# Revision 1.96  1999/09/27 11:18:10  rnhodek
284
 
# Added a missing PLOG.
285
 
#
286
 
# Revision 1.95  1999/09/15 09:10:25  rnhodek
287
 
# Additionally print a warning if a special dep has a version relation.
288
 
#
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.
292
 
#
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.
296
 
#
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.
301
 
#
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
308
 
# (& prefix).
309
 
# Implemented abbrevs as kind of macros in src-deps.
310
 
# New option --add-depends (-a).
311
 
# New option --arch-all (-A).
312
 
#
313
 
# Revision 1.90  1999/08/11 15:28:11  rnhodek
314
 
# Insert missing wait call in run_script to get correct return value.
315
 
#
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
324
 
# to sbuild log.
325
 
# Same in run_apt for virtual package handling.
326
 
# Fix stdout/stderr redirecting when running scripts.
327
 
#
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
330
 
# DB_File anymore.
331
 
#
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.
335
 
#
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...
340
 
#
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 "**".
344
 
#
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.
350
 
#
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.
355
 
#
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
359
 
# package fail.
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.
364
 
#
365
 
# Revision 1.81  1999/05/31 12:59:41  rnhodek
366
 
# Run du after build under sudo, to avoid error messages about
367
 
# unreadable dirs.
368
 
#
369
 
# Revision 1.80  1999/05/27 13:28:04  rnhodek
370
 
# Oops, missed an epoch fix (when constructing the .changes file name).
371
 
#
372
 
# Revision 1.79  1999/05/26 11:34:11  rnhodek
373
 
# Ignore epochs for fetching files.
374
 
#
375
 
# Revision 1.78  1999/05/26 09:48:23  rnhodek
376
 
# If dpkg-source fails, remove .tmp-nest dir.
377
 
#
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 :-)
381
 
#
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
386
 
# database.
387
 
#
388
 
# Revision 1.75  1999/05/04 14:43:01  rnhodek
389
 
# Fix parsing of a single dependency: package name never should contain
390
 
# a '('.
391
 
#
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
396
 
# avg_time_db).
397
 
#
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.
403
 
#
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
406
 
# undefined then!
407
 
#
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.
411
 
#
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 $
414
21
#
415
22
 
416
23
BEGIN {
426
33
# defaults:
427
34
@dist_parts = qw(main contrib non-free);
428
35
$source_dependencies = "/etc/source-dependencies";
429
 
$mailprog = "/usr/lib/sendmail";
 
36
$mailprog = "/usr/sbin/sendmail";
430
37
$dpkg = "/usr/bin/dpkg";
431
38
$sudo = "/usr/bin/sudo";
432
39
$fakeroot = "/usr/bin/fakeroot";
437
44
$mailto = "";
438
45
$mailfrom = "Source Builder <sbuild>";
439
46
$purge_build_directory = "successful";
440
 
$hack_changes_for_frozen = 1;
441
47
$stalled_pkg_timeout = 90; # minutes
442
48
$srcdep_lock_wait = 1; # minutes
443
49
%individual_stalled_pkg_timeout = ();
464
70
use FileHandle;
465
71
use Cwd;
466
72
 
 
73
$ENV{'LC_ALL'} = "POSIX";
 
74
 
467
75
# avoid intermixing of stdout and stderr
468
76
$| = 1;
469
77
# in case the terminal disappears, the build should continue
471
79
 
472
80
$main::distribution = "unstable";
473
81
 
474
 
%main::dist_val = ( stable   => 0,
475
 
                                        frozen   => 1,
476
 
                                        unstable => 2 );
 
82
%main::dist_order = ( 'oldstable' => 0, 'oldstable-security' => 0, stable => 1, 'stable-security' => 1, testing => 2, 'testing-security' => 2, unstable => 3 );
477
83
 
478
84
chomp( $main::arch = `dpkg --print-installation-architecture` );
479
85
$main::username = (getpwuid($<))[0] || $ENV{'LOGNAME'} || $ENV{'USER'};
488
94
$main::max_lock_trys = 120;
489
95
$main::lock_interval = 5;
490
96
$main::cwd = cwd();
491
 
%main::dist_order = ( stable => 0, frozen => 1, unstable => 2 );
492
97
$main::ilock_file = "$conf::srcdep_lock_dir/install";
493
98
$main::srcdep_lock_cnt = 0;
494
99
$main::chroot_dir = "";
495
100
$main::chroot_build_dir = "";
496
101
$main::chroot_apt_options = "";
 
102
$main::override_distribution = 0;
497
103
 
498
104
$main::new_dpkg = 0;
499
105
check_dpkg_version();
517
123
        }
518
124
        elsif (/^-s$/ || /^--source$/) {
519
125
                $main::build_source++;
520
 
                $conf::purge_build_directory = "never";
521
126
        }
522
127
        elsif (/^-d/ || /^--dist/) {
523
128
                if (/^-d(.)/ || /^--dist=(.)/) {
529
134
                else {
530
135
                        $main::distribution = shift @ARGV;
531
136
                }
 
137
                $main::distribution = "oldstable" if $main::distribution eq "o";
532
138
                $main::distribution = "stable"   if $main::distribution eq "s";
533
 
                $main::distribution = "frozen"   if $main::distribution eq "f";
 
139
                $main::distribution = "testing"  if $main::distribution eq "t";
534
140
                $main::distribution = "unstable" if $main::distribution eq "u";
535
 
                die "Bad distribution\n"
536
 
                        if !isin($main::distribution, qw(stable frozen unstable));
 
141
                $main::override_distribution = 1;
537
142
        }
538
143
        elsif (/^-p/ || /^--purge/) {
539
144
                if (/^-p(.)/ || /^--purge=(.)/) {
559
164
                        $conf::maintainer_name = shift @ARGV;
560
165
                }
561
166
        }
 
167
        elsif (/^-k/ || /^--keyid/) {
 
168
                if (/^-k(.)/ || /^--keyid=(.)/) {
 
169
                        $conf::key_id = $1.$';
 
170
                }
 
171
                elsif (!@ARGV) {
 
172
                        die "$_ option missing argument\n";
 
173
                }
 
174
                else {
 
175
                        $conf::key_id = shift @ARGV;
 
176
                }
 
177
        }
 
178
        elsif (/^-e/ || /^--uploader/) {
 
179
                if (/^-e(.)/ || /^--uploader=(.)/) {
 
180
                        $conf::uploader_name = $1.$';
 
181
                }
 
182
                elsif (!@ARGV) {
 
183
                        die "$_ option missing argument\n";
 
184
                }
 
185
                else {
 
186
                        $conf::uploader_name = shift @ARGV;
 
187
                }
 
188
        }
562
189
        elsif (/^-f/ || /^--force-depends/) {
563
190
                if (/^-f(.)/ || /^--force-depends=(.)/) {
564
191
                        push( @main::manual_srcdeps, "f".$1.$' );
607
234
        }
608
235
}
609
236
 
 
237
$conf::mailto = $conf::mailto{$main::distribution}
 
238
        if $conf::mailto{$main::distribution};
 
239
 
 
240
# see debsign for priorities, we will follow the same order
 
241
$main::dpkg_buildpackage_signopt="-m'".$conf::maintainer_name."'";
 
242
$main::dpkg_buildpackage_signopt="-e'".$conf::uploader_name."'" if defined $conf::uploader_name; 
 
243
$main::dpkg_buildpackage_signopt="-k'".$conf::key_id."'" if defined $conf::key_id; 
 
244
$conf::maintainer_name=$conf::uploader_name if defined $conf::uploader_name;
 
245
$conf::maintainer_name=$conf::key_id if defined $conf::key_id;
 
246
 
 
247
# variables for scripts:
610
248
open_log();
611
249
$SIG{'INT'} = \&shutdown;
612
250
$SIG{'TERM'} = \&shutdown;
619
257
        $conf::srcdep_lock_dir = "$main::chroot_dir/$conf::srcdep_lock_dir";
620
258
        $main::ilock_file = "$conf::srcdep_lock_dir/install";
621
259
        my $absroot = "$main::cwd/$main::chroot_dir";
622
 
        # had a problem with base preferences being picked up, so set
623
 
        # Dir::Etc in the chroot and it should cover sources.list & preferences
624
260
        $main::chroot_apt_options =
625
261
                "-o Dir::State=$absroot/var/".
626
262
                        (-d "$absroot/var/lib/apt" ? "lib":"state")."/apt ".
627
263
                "-o Dir::State::status=$absroot/var/lib/dpkg/status ".
628
264
                "-o Dir::Cache=$absroot/var/cache/apt ".
629
265
                "-o Dir::Etc=$absroot/etc/apt ".
 
266
                "-o Dir::Etc::main=$absroot/etc/apt/apt.conf ".
 
267
                "-o Dir::Etc::parts=$absroot/etc/apt/apt.conf.d ".
630
268
                "-o DPkg::Options::=--root=$absroot ".
631
269
                "-o DPkg::Run-Directory=$absroot";
632
270
        $main::chroot_apt_op = '$CHROOT_OPTIONS';
 
271
} else {                                                                                                
 
272
        die "chroot-$main::distribution does not exist\n";
633
273
}
634
274
write_jobs_file();
635
275
 
649
289
                $main::pkg_status = "skipped";
650
290
                goto cleanup_close;
651
291
        }
 
292
        my $dscfile = $pkgv.".dsc";
652
293
        $main::pkg_fail_stage = "fetch-src";
653
 
        my @files_to_rm = fetch_source_files( $pkgv );
 
294
        my @files_to_rm = fetch_source_files( \$dscfile );
654
295
        if (@files_to_rm && $files_to_rm[0] eq "ERROR") {
655
296
                shift @files_to_rm;
656
297
                goto cleanup_symlinks;
662
303
                goto cleanup_packages;
663
304
        }
664
305
 
665
 
        $main::pkg_status = "successful" if build( "${pkgv}.dsc", $pkgv );
 
306
        my $dscbase = basename( $dscfile );
 
307
        $main::pkg_status = "successful" if build( $dscbase, $pkgv );
666
308
        chdir( $main::cwd );
667
309
        write_jobs_file( $main::pkg_status );
668
310
        append_to_FINISHED( $main::current_job );
686
328
unlink( "SBUILD-FINISHED" ) if $main::batchmode;
687
329
exit 0;
688
330
 
689
 
 
690
331
sub fetch_source_files {
691
 
        my $pkgv = shift;
692
 
        my ($pkg, $version);
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);
697
337
        local( *F );
698
338
 
699
 
        if (-f "${pkgv}.dsc") {
700
 
                print PLOG "${pkgv}.dsc exists in cwd\n";
701
 
        }
702
 
        else {
703
 
                $fetch = 1;
704
 
        }
705
 
 
706
 
        if ( $fetch ) {
707
 
        $pkgv =~ s/[^_]+://;
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";
712
 
                return ("ERROR");
713
 
        }
714
 
        $/ = "";
715
 
        while( <PIPE> ) {
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 );
720
 
        }
721
 
        $/ = "\n";
722
 
        close( PIPE );
723
 
        if ($?) {
724
 
                print PLOG "Apt-cache failed\n";
725
 
                return ("ERROR");
726
 
        }
727
 
 
728
 
        if (!defined($entries{$version})) {
729
 
                print PLOG "Can't find source for $pkgv\n";
730
 
                my $c = 0;
731
 
                foreach my $entry (keys %entries) {
732
 
                        if ($c == 0) {
733
 
                                print PLOG "(only different version(s)";
734
 
                        } elsif ($c >= 1) {
735
 
                                print PLOG ",";
736
 
                        }
737
 
                        print PLOG " $entry";
738
 
                        $c++;
739
 
                }
740
 
                print PLOG " found)\n" if $c;
741
 
                return ("ERROR");
742
 
        }
743
 
 
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);
750
 
        }
751
 
        if ($newest ne $version) {
752
 
                print PLOG "Version skew. Latest version is $newest, not $version.\n";
753
 
                return ("ERROR");
754
 
        }
755
 
 
756
 
        @made = @{$entries{$version}};
757
 
 
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);
763
 
        }
764
 
        while( <PIPE> ) {
765
 
                print PLOG $_;
766
 
        }
767
 
        close( PIPE );
768
 
        if ($?) {
769
 
                print PLOG "Apt-get of sources failed\n";
770
 
                return( "ERROR", @made );
771
 
        }
772
 
        push @made, "${pkgv}.dsc";
773
 
        } else {
774
 
                $pkgv =~ s/\.dsc$//;
775
 
        }
776
 
 
777
 
        if (!open( F, "<${pkgv}.dsc" )) {
778
 
                print PLOG "Can't open ${pkgv}.dsc: $!\n";
 
339
        $dscfile =~ m,^(.*)/([^/]+)$,;
 
340
        ($dir, $dscbase) = ($1, $2);
 
341
        my $urlbase;
 
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 = ();
 
346
 
 
347
        if (-d $dscfile) {
 
348
                if (-f "$dscfile/debian/.sbuild-build-deps") {
 
349
                        open( F, "<$dscfile/debian/.sbuild-build-deps" );
 
350
                        my $pkg;
 
351
                        while( <F> ) {
 
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;
 
357
                        }
 
358
                        close( F );
 
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 );
 
364
                        }
 
365
                }
 
366
                return;
 
367
        }
 
368
 
 
369
        if ($dir ne ".") {
 
370
                {
 
371
                        if (-f "${pkgv}.dsc") {
 
372
                                print PLOG "${pkgv}.dsc exists in cwd\n";
 
373
                        }
 
374
                        else {
 
375
                                my %entries;
 
376
                                my $retried = 0;
 
377
 
 
378
                          retry:
 
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";
 
383
                                        return ("ERROR");
 
384
                                }
 
385
                                { local($/) = "";
 
386
                                  while( <PIPE> ) {
 
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 );
 
391
                                  }
 
392
                            }
 
393
                                close( PIPE );
 
394
                                if ($?) {
 
395
                                        print PLOG "$conf::apt_cache failed\n";
 
396
                                        return ("ERROR");
 
397
                                }
 
398
                                
 
399
                                if (!defined($entries{$version})) {
 
400
                                        if (!$retried) {
 
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";
 
404
                                                $retried = 1;
 
405
                                                goto retry;
 
406
                                        }
 
407
                                        print PLOG "Can't find source for $pkgv\n";
 
408
                                        print PLOG "(only different version(s) ",
 
409
                                                           join( ", ", sort keys %entries), " found)\n"
 
410
                                                if %entries;
 
411
                                        return( "ERROR" );
 
412
                                }
 
413
 
 
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
 
417
                                # day.
 
418
                                my $newest = $version;
 
419
                                foreach my $entry (keys %entries) {
 
420
                                        $newest = $entry if version_cmp($entry, '>>', $newest);
 
421
                                }
 
422
                                if ($newest ne $version) {
 
423
                                        print PLOG "Version skew. Latest version is $newest, ".
 
424
                                                           "not $version.\n";
 
425
                                        return ("ERROR");
 
426
                                }
 
427
 
 
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);
 
434
                                }
 
435
                                while( <PIPE> ) {
 
436
                                        print PLOG $_;
 
437
                                }
 
438
                                close( PIPE );
 
439
                                if ($?) {
 
440
                                        print PLOG "$conf::apt_get for sources failed\n";
 
441
                                        return( "ERROR", @made );
 
442
                                }
 
443
                                $$dscfile_ref = $dscfile = (grep { /\.dsc$/ } @made)[0];
 
444
                        }
 
445
                }
 
446
        }
 
447
        
 
448
        if (!open( F, "<$dscfile" )) {
 
449
                print PLOG "Can't open $dscfile: $!\n";
779
450
                return( "ERROR", @made );
780
451
        }
781
452
        my $dsctext;
 
453
        my $orig;
782
454
        { local($/); $dsctext = <F>; }
783
455
        close( F );
784
 
        
785
 
        $dsctext =~ /^Files:\s*\n((\s+.*\s*\n)+)/mi and $files = $1;
786
 
        push @made, map { (split( /\s+/, $_ ))[3] } split( "\n", $files ) if $fetch;
 
456
 
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
799
469
 
800
470
        $dsctext =~ /^Architecture:\s*(.*)$/mi and $dscarchs = $1;
801
471
 
 
472
        $dsctext =~ /^Files:\s*\n((\s+.*\s*\n)+)/mi and $files = $1;
 
473
        @other_files = map { (split( /\s+/, $_ ))[3] } split( "\n", $files );
 
474
        $files =~ /(\Q$pkg\E.*orig.tar.gz)/mi and $orig = $1;
 
475
 
802
476
        if (!$dscarchs) {
803
 
                print PLOG "$pkgv.dsc has no Architecture: field -- skipping arch check!\n";
 
477
                print PLOG "$dscbase has no Architecture: field -- skipping arch check!\n";
804
478
        }
805
479
        else {
806
480
                if ($dscarchs ne "any" && $dscarchs ne "all" && $dscarchs !~ /\b$main::arch\b/) {
807
 
                        print PLOG "$pkgv.dsc: $main::arch not in arch list: $dscarchs -- ".
 
481
                        print PLOG "$dscbase: $main::arch not in arch list: $dscarchs -- ".
808
482
                                 "skipping\n";
809
483
                        $main::pkg_fail_stage = "arch-check";
810
484
                        return( "ERROR", @made );
820
494
                merge_pkg_build_deps( $pkg, $build_depends, $build_depends_indep,
821
495
                                                          $build_conflicts, $build_conflicts_indep );
822
496
        }
823
 
        
 
497
 
 
498
        if ($main::build_source) {
 
499
                @made = "";
 
500
                if ($orig && $main::chroot_build_dir) {
 
501
                        system ("cp $orig $main::chroot_build_dir") 
 
502
                                and print PLOG "ERROR: Could not copy $orig to $main::chroot_build_dir \n";
 
503
                        push(@made, "$main::chroot_build_dir$orig");
 
504
                }
 
505
        }
 
506
 
 
507
 
824
508
        return @made;
825
509
}
826
510
 
827
511
sub build {
828
512
        my $dsc = shift;
829
 
        $dsc =~ s/[^_]+://;
830
513
        my $pkgv = shift;
831
514
        my( $dir, $rv, $changes );
832
515
        my $do_apply_patches = 1;
837
520
        # count build time from now, ignoring the installation of source deps
838
521
        $main::pkg_start_time = time;
839
522
        $main::this_space = 0;
840
 
        $pkgv =~ /^([a-zA-Z\d.+-]+)_([a-zA-Z\d:.+-]+)/;
 
523
        $pkgv =~ /^([a-zA-Z\d.+-]+)_([a-zA-Z\d:.+-~]+)/;
841
524
        my ($pkg, $version) = ($1,$2);
842
525
        (my $sversion = $version) =~ s/^\d+://;
843
526
        my $tmpunpackdir = $dsc;
900
583
                        return 0;
901
584
                }
902
585
                
903
 
                if (@main::have_dsc_build_deps) {
 
586
                if (@main::have_dsc_build_deps && !defined $main::build_source) {
904
587
                        my ($d, $di, $c, $ci) = @main::have_dsc_build_deps;
905
588
                        open( F, ">$dir/debian/.sbuild-build-deps" );
906
589
                        print F "Package: $pkg\n";
970
653
                                           "(Source needs $current_usage KB, free are $free KB.)\n";
971
654
                        print PLOG "Purging $dir\n";
972
655
                        chdir( $main::cwd );
973
 
                        system "$conf::fakeroot rm -rf $dir";
 
656
                        system "$conf::sudo rm -rf $dir";
974
657
                        return 0;
975
658
                }
976
659
        }
992
675
                                return 0;
993
676
                        }
994
677
                        $dists = $main::distribution;
995
 
                        $dists .= " frozen unstable" if $dists eq "stable";
996
 
                        $dists .= " unstable" if $dists eq "frozen";
997
678
                        print F "$name ($NMUversion) $dists; urgency=low\n\n";
998
679
                        print F "  * Binary-only non-maintainer upload for $main::arch; ",
999
680
                                        "no source changes.\n";
1010
691
                }
1011
692
        }
1012
693
        
1013
 
        $main::pkg_fail_stage = "hack-frozen";
1014
 
        if ($conf::hack_changes_for_frozen && $main::distribution eq "frozen") {
1015
 
                if (open( F, "<debian/changelog" )) {
1016
 
                        my($firstline, $text);
1017
 
                        $firstline = <F> while $firstline =~ /^$/;
1018
 
                        { local($/); undef $/; $text = <F>; }
1019
 
                        close( F );
1020
 
                        $firstline =~ s/ unstable([ ;])/ frozen unstable$1/
1021
 
                                if $firstline !~ / frozen[ ;]/;
1022
 
                        if (!open( F, ">debian/changelog" )) {
1023
 
                                print PLOG "Can't open debian/changelog for frozen hack: $!\n";
1024
 
                                chdir( $main::cwd );
1025
 
                                return 0;
1026
 
                        }
1027
 
                        print F $firstline, $text;
1028
 
                        close( F );
1029
 
                }
1030
 
                else {
1031
 
                        print PLOG "Can't open debian/changelog -- no frozen hack!\n";
1032
 
                }
1033
 
        }
1034
 
 
1035
694
        if ($do_apply_patches) {
1036
695
                if (!apply_patches( $pkg )) {
1037
696
                        chdir( $main::cwd );
1078
737
        }
1079
738
        if ($main::sub_pid == 0) {
1080
739
                setpgrp( 0, $$ );
1081
 
                my $binopt = $main::build_source ? "" :
1082
 
                                         $main::build_arch_all ? "-b" : "-B";
 
740
                my $binopt = $main::build_source ? "" : $main::build_arch_all ? "-b" : "-B";
1083
741
                if ($main::chroot_dir) {
1084
742
                        my $bdir = $dir;
1085
743
                        $bdir =~ s/^\Q$main::chroot_dir\E//;
1088
746
                                system "$conf::sudo chmod a+r $main::chroot_dir/etc/ld.so.conf";
1089
747
                                print PLOG "ld.so.conf was not readable! Fixed.\n";
1090
748
                        }
 
749
                        print PLOG "$conf::sudo /usr/sbin/chroot $main::cwd/$main::chroot_diri ".
 
750
                                 "$conf::sudo -u $main::username -H /bin/sh -c cd $bdir && ".
 
751
                                 "exec dpkg-buildpackage $conf::pgp_options ".
 
752
                                 "$binopt $main::dpkg_buildpackage_signopt -r$conf::fakeroot 2>&1\n" if $main::debug;
 
753
 
1091
754
                        exec "$conf::sudo", "/usr/sbin/chroot", "$main::cwd/$main::chroot_dir",
1092
755
                                 "$conf::sudo", "-u", $main::username, "-H", "/bin/sh", "-c",
1093
756
                                 "cd $bdir && exec dpkg-buildpackage $conf::pgp_options ".
1094
 
                                 "$binopt -m'$conf::maintainer_name' -r$conf::fakeroot 2>&1";
 
757
                                 "$binopt $main::dpkg_buildpackage_signopt -r$conf::fakeroot 2>&1";
1095
758
                }
1096
759
                else {
1097
760
                        if (-f "/etc/ld.so.conf" && ! -r "/etc/ld.so.conf") {
1098
761
                                system "$conf::sudo chmod a+r /etc/ld.so.conf";
1099
762
                                print PLOG "ld.so.conf was not readable! Fixed.\n";
1100
763
                        }
 
764
                        print PLOG "dpkg-buildpackage $conf::pgp_options $binopt ".
 
765
                                "$main::dpkg_buildpackage_signopt -r$conf::fakeroot 2>&1\n" if $main::debug;
 
766
 
1101
767
                        exec "dpkg-buildpackage $conf::pgp_options $binopt ".
1102
 
                                "-m'$conf::maintainer_name' -r$conf::fakeroot 2>&1";
 
768
                                "$main::dpkg_buildpackage_signopt -r$conf::fakeroot 2>&1";
1103
769
                }
1104
770
        }
1105
771
        $main::sub_task = "dpkg-buildpackage";
1158
824
                        while( <F> ) {
1159
825
                                my $f = (split( /\s+/, $_ ))[0];
1160
826
                                push( @files, "$main::chroot_build_dir$f" );
1161
 
                                next if $f !~ /_$main::arch\.[a-z0-9.-]*$/;
 
827
                                next if $f !~ /$main::arch\.[\w\d.-]*$/;
1162
828
                                push( @debs, "$main::chroot_build_dir$f" );
1163
829
                                push( @space_files, $f );
1164
830
                                push( @checkinst_files, $f ) if $main::store_built_packages;
1185
851
                                        close( PIPE );
1186
852
                                }
1187
853
                        }
1188
 
                        if ($main::chroot_build_dir) {
1189
 
                                foreach (@files) {
1190
 
                                        system "mv", $_, "."
1191
 
                                                and print PLOG "ERROR: Could not move $_ to .\n";
1192
 
                                }
1193
 
                        }
1194
854
                }
1195
855
 
1196
856
                $changes = "${pkg}_".
1197
857
                        ($main::binNMU ? binNMU_version($sversion) : $sversion).
1198
858
                        "_$main::arch.changes";
 
859
                my @files;
1199
860
                if (-r "$main::chroot_build_dir$changes") {
1200
861
                        my(@do_dists, @saved_dists);
1201
862
                        print PLOG "\n$changes:\n";
1202
863
                        open( F, "<$main::chroot_build_dir$changes" );
1203
864
                        if (open( F2, ">$changes.new" )) {
1204
865
                                while( <F> ) {
1205
 
                                        if (/^Distribution:\s*(.*)\s*$/) {
1206
 
                                                my @dists = split( /\s+/, $1 );
1207
 
                                                foreach (@dists) {
1208
 
                                                        if (dist_cmp( $_, $main::distribution ) < 0) {
1209
 
                                                                push( @saved_dists, $_ );
1210
 
                                                        }
1211
 
                                                        else {
1212
 
                                                                push( @do_dists, $_ );
1213
 
                                                        }
1214
 
                                                }
1215
 
                                                print PLOG "Distribution: @do_dists\n";
1216
 
                                                print F2 "Distribution: @do_dists\n";
 
866
                                        if (/^Distribution:\s*(.*)\s*$/ and $main::override_distribution) {
 
867
                                                print PLOG "Distribution: $main::distribution\n";
 
868
                                                print F2 "Distribution: $main::distribution\n";
1217
869
                                        }
1218
870
                                        else {
1219
871
                                                print PLOG $_;
1220
872
                                                print F2 $_;
 
873
                                                if (/^ [a-z0-9]{32}/) {
 
874
                                                        push(@files, (split( /\s+/, $_ ))[5] );
 
875
                                                }
1221
876
                                        }
1222
877
                                }
1223
878
                                close( F2 );
1237
892
                        }
1238
893
                        close( F );
1239
894
                        print PLOG "\n";
1240
 
 
1241
 
                        if (@saved_dists) {
1242
 
                                mkdir( "SAVED-CHANGES", 0777 ) if !-d "SAVED-CHANGES";
1243
 
                                my $f = "SAVED-CHANGES/$changes";
1244
 
                                open( F, "<$changes" );
1245
 
                                if (open( F2, ">$f" )) {
1246
 
                                        while( <F> ) {
1247
 
                                                if (/^Distribution:/) {
1248
 
                                                        print F2 "Distribution: @saved_dists\n";
1249
 
                                                }
1250
 
                                                else {
1251
 
                                                        print F2 $_;
1252
 
                                                }
1253
 
                                        }
1254
 
                                        close( F2 );
1255
 
                                }
1256
 
                                else {
1257
 
                                        print PLOG "Cannot create $f: $!\n";
1258
 
                                }
1259
 
                                close( F );
1260
 
                                print PLOG <<EOF;
1261
 
Note:
1262
 
Deleted the distribution(s) @saved_dists from this .changes, because
1263
 
the package (probably) has not been accepted for them yet. Expect a reupload
1264
 
mail from wanna-build as soon as it is accepted. A modified .changes for
1265
 
@saved_dists has been stored in $f.
1266
 
 
1267
 
EOF
1268
 
                        }
1269
895
                }
1270
896
                else {
1271
897
                        print PLOG "Can't find $changes -- can't dump infos\n";
1272
898
                }
 
899
                foreach (@files) {
 
900
                        if ($main::chroot_build_dir) {
 
901
                                system "mv", "$main::chroot_build_dir$_", "."
 
902
                                        and print PLOG "ERROR: Could not move $_ to .\n";
 
903
                        }
 
904
                }
1273
905
 
1274
906
                print PLOG "*"x78, "\n";
1275
907
                print PLOG "Built successfully\n";
1281
913
        if ($conf::purge_build_directory eq "always" ||
1282
914
                ($conf::purge_build_directory eq "successful" && $rv == 0)) {
1283
915
                print PLOG "Purging $dir\n";
1284
 
                system "$conf::fakeroot rm -rf $dir";
 
916
                system "$conf::sudo rm -rf $dir";
1285
917
        }
1286
918
        check_inst_packages( @checkinst_files )
1287
919
                if $rv == 0 && $main::store_built_packages;
1340
972
        return if $main::pkg_status ne "failed";
1341
973
        return if !$main::auto_giveback;
1342
974
        if (isin( $main::pkg_fail_stage,
1343
 
                          qw(fetch-src unpack-check check-space))) {
 
975
                          qw(find-dsc fetch-src unpack-check check-space))) {
1344
976
                $main::pkg_status = "given-back";
1345
977
                print PLOG "Giving back package $pkgv after failure in ".
1346
978
                               "$main::pkg_fail_stage stage.\n";
1393
1025
        if ($main::debug) {
1394
1026
                print "Source dependencies of $pkg: ", format_deps(@$dep), "\n";
1395
1027
        }
1396
 
        
 
1028
 
1397
1029
  repeat:
1398
1030
        lock_file( "$main::ilock_file", 1 );
1399
 
 
 
1031
        
1400
1032
        print "Filtering dependencies\n" if $main::debug;
1401
1033
        if (!filter_dependencies( $dep, \@positive, \@negative, \@special )) {
1402
1034
                print PLOG "Package installation not possible\n";
1513
1145
        foreach my $s (@s) {
1514
1146
                my $dsc;
1515
1147
 
1516
 
        if (!open( PIPE, "$conf::apt_get $main::chroot_apt_options ".
1517
 
                        "--only-source -q -d source $s 2>&1 </dev/null |" )) {
1518
 
                print PLOG "Can't open pipe to apt-get: $!\n";
1519
 
                goto failed;
1520
 
        }
1521
 
        while( <PIPE> ) {
1522
 
                $dsc = "$1_$2.dsc" if /(\S+) (?:[^:]+:)?(\S+) \(dsc\)/;
1523
 
                print PLOG $_;
1524
 
        }
1525
 
        close( PIPE );
1526
 
        if ($?) {
1527
 
                print PLOG "Apt-get of special unpack sources failed\n";
1528
 
                goto failed;
1529
 
        }
1530
 
        push( @files, $dsc );
1531
 
        if (!open( F, "<$dsc" )) {
1532
 
                print PLOG "Can't open $dsc: $!\n";
1533
 
                goto failed;
1534
 
        }
1535
 
        my $dsctext;
1536
 
        { local($/); $dsctext = <F>; }
1537
 
        close( F );
1538
 
                my $files;
1539
 
                $dsctext =~ /^Files:\s*\n((\s+.*\s*\n)+)/mi and $files = $1;
1540
 
                push(@files, map { (split( /\s+/, $_ ))[3] } split( "\n", $files ));
 
1148
                {
 
1149
                        if (!open( PIPE, "$conf::apt_get $main::chroot_apt_options ".
 
1150
                       "--only-source -q -d source $s 2>&1 </dev/null |" )) {
 
1151
                                print PLOG "Can't open pipe to apt-get: $!\n";
 
1152
                                goto failed;
 
1153
                        }
 
1154
                        while( <PIPE> ) {
 
1155
                                $dsc = "$1_$2.dsc" if /(\S+) (?:[^:]+:)?(\S+) \(dsc\)/;
 
1156
                                print PLOG $_;
 
1157
                        }
 
1158
                        close( PIPE );
 
1159
                        if ($?) {
 
1160
                                print PLOG "Apt-get of special unpack sources failed\n";
 
1161
                                goto failed;
 
1162
                        }
 
1163
                        push( @files, $dsc );
 
1164
                        if (!open( F, "<$dsc" )) {
 
1165
                                print PLOG "Can't open $dsc: $!\n";
 
1166
                                goto failed;
 
1167
                        }
 
1168
                        my $dsctext;
 
1169
                        { local($/); $dsctext = <F>; }
 
1170
                        close( F );
 
1171
                        my $files;
 
1172
                        $dsctext =~ /^Files:\s*\n((\s+.*\s*\n)+)/mi and $files = $1;
 
1173
                        push(@files, map { (split( /\s+/, $_ ))[3] } split( "\n", $files ));
 
1174
                }
1541
1175
 
1542
1176
                my $pid = open( PIPE, "-|" );
1543
1177
                if (!defined $pid) {
1672
1306
        local (*PIPE);
1673
1307
        local (%ENV) = %ENV; # make local environment
1674
1308
        # hardwire frontent for debconf to non-interactive
1675
 
        $ENV{'DEBIAN_FRONTEND'} = "Noninteractive";
 
1309
        $ENV{'DEBIAN_FRONTEND'} = "noninteractive";
1676
1310
 
1677
1311
        @$inst_ret = ();
1678
1312
        @$rem_ret = ();
1679
1313
        return 1 if !@to_install;
1680
1314
  repeat:
1681
 
        print PLOG "  $conf::sudo $conf::apt_get $main::chroot_apt_op -q $mode install @to_install\n"
 
1315
        print PLOG "  $conf::sudo $conf::apt_get --purge $main::chroot_apt_op -q $mode install @to_install\n"
1682
1316
                if $mode ne "-s";
1683
1317
        $msgs = "";
1684
1318
        # redirection of stdin from /dev/null so that conffile question are
1685
1319
        # treated as if RETURN was pressed.
1686
1320
        # dpkg since 1.4.1.18 issues an error on the conffile question if it reads
1687
1321
        # EOF -- hardwire the new --force-confold option to avoid the questions.
1688
 
        if (!open( PIPE, "$conf::sudo $conf::apt_get $main::chroot_apt_options ".
 
1322
        if (!open( PIPE, "$conf::sudo $conf::apt_get --purge $main::chroot_apt_options ".
1689
1323
                           ($main::new_dpkg ? "-o DPkg::Options::=--force-confold " : "").
1690
1324
                           "-q $mode install @to_install 2>&1 </dev/null |" )) {
1691
1325
                print PLOG "Can't open pipe to apt-get: $!\n";
1751
1385
        }
1752
1386
        
1753
1387
        $pkgs = $rpkgs = "";
1754
 
        if ($msgs =~ /NEW packages will be installed:\n((^\s.*\n)*)/mi) {
1755
 
                ($pkgs = $1) =~ s/^\s*((.|\n)*)\s*$/$1/m;
 
1388
        if ($msgs =~ /NEW packages will be installed:\n((^[     ].*\n)*)/mi) {
 
1389
                ($pkgs = $1) =~ s/^[    ]*((.|\n)*)\s*$/$1/m;
1756
1390
        }
1757
 
        if ($msgs =~ /packages will be REMOVED:\n((^\s.*\n)*)/mi) {
1758
 
                ($rpkgs = $1) =~ s/^\s*((.|\n)*)\s*$/$1/m;
 
1391
        if ($msgs =~ /packages will be REMOVED:\n((^[   ].*\n)*)/mi) {
 
1392
                ($rpkgs = $1) =~ s/^[   ]*((.|\n)*)\s*$/$1/m;
1759
1393
        }
1760
1394
        @$inst_ret = split( /\s+/, $pkgs );
1761
1395
        @$rem_ret = split( /\s+/, $rpkgs );
1984
1618
                                         $result{$pkg}->{'Version'} eq '=*=PROVIDED=*=');
1985
1619
                        next;
1986
1620
                }
1987
 
                if (!$version) {
 
1621
                if ($version eq "") {
1988
1622
                        print PLOG "sbuild: parse error in $main::chroot_dir/var/lib/dpkg/status: ",
1989
1623
                                           "no Version: field for package $pkg\n";
1990
1624
                        next;
1994
1628
                if ($provides) {
1995
1629
                        foreach (split( /\s*,\s*/, $provides )) {
1996
1630
                                $result{$_} = { Installed => 1, Version => '=*=PROVIDED=*=' }
1997
 
                                        if isin( $_, @interest );
 
1631
                                        if !$result{$_}{Installed} && isin( $_, @interest );                                    
1998
1632
                        }
1999
1633
                }
2000
1634
        }
2011
1645
        return $? == 0;
2012
1646
}
2013
1647
 
2014
 
sub dist_cmp {
2015
 
        my $d1 = shift;
2016
 
        my $d2 = shift;
2017
 
 
2018
 
        return $main::dist_order{$d1} <=> $main::dist_order{$d2};
2019
 
}
2020
 
 
2021
 
 
2022
1648
sub run_script {
2023
1649
        my $e_mode = shift;
2024
1650
        my $x_mode = "";
2041
1667
                open( STDOUT, ">&PLOG" );
2042
1668
                open( STDERR, ">&PLOG" );
2043
1669
                if ($main::chroot_dir) {
2044
 
                        exec "$conf::sudo", "chroot", "$main::cwd/$main::chroot_dir",
2045
 
                                 "$conf::sudo", "-u", $main::username, "-H", "/bin/sh", "-c",
 
1670
                        exec "$conf::sudo", "/usr/sbin/chroot", "$main::cwd/$main::chroot_dir",
 
1671
                                 "$conf::sudo", "-u", $main::username, "/bin/sh", "-c",
2046
1672
                                 "cd /build/$main::username\nset $e_mode\n$x_mode$script";
2047
1673
                }
2048
1674
                else {
2234
1860
        $conflictsi = join( ", ", map { "!$_" } split( /\s*,\s*/, $conflictsi ));
2235
1861
        
2236
1862
        my $deps = $depends . ", " . $conflicts;
2237
 
        $deps .= $dependsi . ", " . $conflictsi if $main::build_arch_all;
 
1863
        $deps .= "," . $dependsi . ", " . $conflictsi if $main::build_arch_all;
2238
1864
        @{$main::deps{$pkg}} = @l;
2239
1865
        print "Merging pkg deps: $deps\n" if $main::debug;
2240
1866
        parse_one_srcdep( $pkg, $deps, \%main::deps );
2540
2166
                                        }
2541
2167
                                }
2542
2168
                                warn "Warning: inconsistent arch restriction on ",
2543
 
                                         "$pkg: $dep dependency\n"
 
2169
                                         "$pkg: $dep depedency\n"
2544
2170
                                                 if $ignore_it && $use_it;
2545
2171
                                next if $ignore_it || ($include && !$use_it);
2546
2172
                        }
2692
2318
 
2693
2319
sub open_pkg_log {
2694
2320
        my $date = `date +%Y%m%d-%H%M`;
 
2321
        chomp( $date );
2695
2322
        my $pkg = shift;
2696
2323
 
2697
2324
        if ($main::nolog) {
2706
2333
                        $pkg .= $3;
2707
2334
                }
2708
2335
                $main::pkg_logfile = "$conf::log_dir/${pkg}_$date";
 
2336
                system "ln -sf $main::pkg_logfile current";
2709
2337
                if ($main::verbose) {
2710
2338
                        my $pid;
2711
2339
                        ($pid = open( PLOG, "|-")) || exec "tee $main::pkg_logfile";
2725
2353
        }
2726
2354
        select( (select( PLOG ), $| = 1)[0] );
2727
2355
 
2728
 
        my $revision = '$Revision: 1.159 $';
 
2356
        my $revision = '$Revision: 1.7 $';
2729
2357
        $revision =~ /([\d.]+)/;
2730
2358
        $revision = $1;
2731
2359
 
2732
2360
        print PLOG "Automatic build of $pkg on $main::HOSTNAME by ".
2733
2361
                           "sbuild/$main::arch $revision\n";
2734
 
        print PLOG "Build started at $date";
 
2362
        print PLOG "Build started at $date\n";
2735
2363
        print PLOG "*"x78, "\n";
2736
2364
        return 1;
2737
2365
}
2918
2546
 
2919
2547
        my @chroots;
2920
2548
        if ($main::chroot_dir) {
2921
 
                foreach (qw(stable frozen unstable)) {
 
2549
                foreach (keys(%main::dist_order)) {
2922
2550
                        push( @chroots, "--chroot=$main::cwd/chroot-$_" )
2923
2551
                                  if !dist_gt( $_, $main::distribution ) &&
2924
2552
                                     -d "$main::cwd/chroot-$_";
3332
2960
sub df {
3333
2961
        my $dir = shift;
3334
2962
 
3335
 
        my $free = `/bin/df $dir | tail -1`;
 
2963
        my $free = `/bin/df $dir | tail -n 1`;
3336
2964
        my @free = split( /\s+/, $free );
3337
2965
        return $free[3];
3338
2966
}
3445
3073
 
3446
3074
sub dist_gt {
3447
3075
        my ($d1, $d2) = @_;
3448
 
        die "Unknown dist '$d1' in dist_gt\n" if !exists($main::dist_val{$d1});
3449
 
        die "Unknown dist '$d2' in dist_gt\n" if !exists($main::dist_val{$d2});
3450
 
        return $main::dist_val{$d1} > $main::dist_val{$d2};
 
3076
        die "Unknown dist '$d1' in dist_gt\n" if !exists($main::dist_order{$d1});
 
3077
        die "Unknown dist '$d2' in dist_gt\n" if !exists($main::dist_order{$d2});
 
3078
        return $main::dist_order{$d1} > $main::dist_order{$d2};
3451
3079
}
3452
3080
 
3453
3081
sub shutdown {