3 # wanna-build: coordination script for Debian buildds
4 # Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 # Copyright (C) 2005-2008 Ryan Murray <rmurray@debian.org>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 $basedir ||= "/var/lib/debbuild";
25 $dbbase ||= "build-db";
26 $transactlog ||= "transactions.log";
27 $mailprog ||= "/usr/sbin/sendmail";
28 require "/etc/wanna-build.conf";
29 die "$conf::basedir is not a directory\n" if ! -d $conf::basedir;
30 die "dbbase is empty\n" if ! $dbbase;
31 die "transactlog is empty\n" if ! $transactlog;
32 die "mailprog binary $conf::mailprog does not exist or isn't executable\n"
33 if !-x $conf::mailprog;
34 die "no distributions defined\n" if ! %distributions;
42 use MLDBM qw(GDBM_File Storable);
45 our ($verbose, $mail_logs, $list_order, $list_state,
46 $curr_date, $op_mode, $user, $real_user, $distribution,
47 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
48 %db, %otherdb, %otherdb_lock, %prioval, %sectval,
49 $info_all_dists, $arch,
50 $category, %catval, %short_category,
51 $short_date, $list_min_age, $dbbase, @curr_time,
52 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
53 $lock_for_pid, $transactional);
56 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
60 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
61 $short_date = strftime("%m/%d/%y",@curr_time);
63 $lock_for_pid = -1; # -1 means normal procedure
64 $transactional = 0; # 0 means: work on main copy
66 # map program invocation names to operation modes
67 my %prognames = ( "uploaded-build" => "set-uploaded",
68 "failed-build" => "set-failed",
69 "no-build" => "set-not-for-us",
70 "give-back-build" => "set-needs-build",
71 "dep-wait-build" => "set-dep-wait",
72 "forget-build" => "forget",
73 "merge-quinn" => "merge-quinn",
74 "merge-packages" => "merge-packages",
75 "merge-sources" => "merge-sources",
76 "build-info" => "info" );
78 %short_category = ( u => "uploaded-fixed-pkg",
85 c => "compiler-error",
89 ($progname = $0) =~ s,.*/,,;
90 if ($prognames{$progname}) {
91 $op_mode = $prognames{$progname};
93 elsif ($progname =~ /^list-(.*)$/) {
95 $list_state = ($1 eq "all") ? "" : $1;
100 verbose => { short => "v", flag => \$verbose },
101 override => { short => "o", flag => \$opt_override },
102 "create-db" => { flag => \$opt_create_db },
103 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
104 # TODO: remove after buildds no longer pass to wanna-build
105 "no-propagation" => { short => "N" },
106 "no-down-propagation" => { short => "D" },
108 take => { mode => "set-building" },
109 failed => { short => "f", mode => "set-failed" },
110 uploaded => { short => "u", mode => "set-uploaded" },
111 "no-build" => { short => "n", mode => "set-not-for-us" },
112 built => { mode => "set-built" },
113 attempted => { mode => "set-attempted" },
114 "give-back" => { mode => "set-needs-build" },
115 "dep-wait" => { mode => "set-dep-wait" },
116 forget => { mode => "forget" },
117 'forget-user' => { mode => 'forget-user' },
118 "merge-quinn" => { mode => "merge-quinn" },
119 "merge-partial-quinn" => { mode => "merge-partial-quinn" },
120 "merge-packages" => { mode => "merge-packages" },
121 "merge-sources" => { mode => "merge-sources" },
122 "pretend-avail" => { short => "p", mode => "pretend-avail" },
123 "merge-all" => { mode => "merge-all" },
124 info => { short => "i", mode => "info" },
125 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
126 code => sub { die "Invalid binNMU version: $binNMUver\n"
127 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
128 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
129 code => sub { die "Invalid build priority: $build_priority\n"
130 if $build_priority !~ /^-?[\d]+$/; } },
131 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
132 code => sub { die "Invalid build priority: $build_priority\n"
133 if $build_priority !~ /^-?[\d]+$/; } },
135 { short => "l", mode => "list", arg => \$list_state,
137 die "Unknown state to list: $list_state\n"
138 if !isin( $list_state, qw(needs-build building uploaded
139 built build-attempted failed installed dep-wait
140 not-for-us all failed-removed
141 install-wait reupload-wait bd-uninstallable));} },
144 { short => "d", arg => \$distribution,
146 if ($distribution eq "a" || $distribution eq "all") {
151 $distribution = "oldstable" if $distribution eq "o";
152 $distribution = "stable" if $distribution eq "s";
153 $distribution = "testing" if $distribution eq "t";
154 $distribution = "unstable" if $distribution eq "u";
158 { short => "O", arg => \$list_order,
160 die "Bad ordering character\n"
161 if $list_order !~ /^[PSpsncb]+$/;
163 message => { short => "m", arg => \$fail_reason },
164 database => { short => "b", arg => \$conf::dbbase },
165 arch => { short => "A", arg => \$arch },
166 user => { short => "U", arg => \$user },
167 category => { short => "c", arg => \$category,
169 $category = $short_category{$category}
170 if exists $short_category{$category};
171 die "Unknown category: $category\n"
172 if !isin( $category, values %short_category );
174 "min-age" => { short => "a", arg => \$list_min_age,
176 die "Argument of --min-age must be a non-zero number\n"
177 if $list_min_age == 0;
178 $list_min_age *= 24*60*60;
180 "max-age" => { arg => \$list_min_age,
182 die "Argument of --max-age must be a non-zero number\n"
183 if $list_min_age == 0;
184 $list_min_age *= -24*60*60;
187 import => { arg => \$import_from, mode => "import" },
188 export => { arg => \$export_to, mode => "export" },
189 "lock-for" => { arg => \$lock_for_pid, mode => "lock-for" },
190 "unlock-for" => { arg => \$lock_for_pid, mode => "unlock-for" },
191 "act-on-behalf-of" => { arg => \$lock_for_pid },
192 "start-transaction" => { mode => "start-transaction" },
193 "commit-transaction" => { mode => "commit-transaction" },
194 "transactional" => { flag => \$transactional },
195 "manual-edit" => { mode => "manual-edit" },
196 "create-maintenance-lock" => { mode => "maintlock-create" },
197 "remove-maintenance-lock" => { mode => "maintlock-remove" },
198 "clean-db" => { mode => "clean-db" },
201 while( @ARGV && $ARGV[0] =~ /^-/ ) {
204 my($opt, $optname, $arg);
205 if (/^--([^=]+)(=|$)/) {
207 $opt = $options{$optname};
208 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
211 $optname = substr( $_, 1, 1 );
212 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
213 $arg = $1 if /^-$optname(.+)$/;
216 warn "Unknown option: --$1\n";
221 die "$optname option missing argument\n" if !@ARGV;
224 ${$opt->{arg}} = $arg;
226 elsif (defined $arg) {
227 die "Option $optname takes no argument\n";
231 die "Conflicting operation modes\n" if $op_mode;
232 $op_mode = $opt->{mode};
242 $op_mode = $category ? "set-failed" : "set-building"
243 if !$op_mode; # default operation
244 $list_order = $list_state eq "failed" ? 'fPcpsn' : 'PScpsn'
245 if !$list_order and $list_state;
246 $distribution ||= "unstable";
247 die "Bad distribution '$distribution'\n"
248 if !isin($distribution, keys %conf::distributions);
251 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
252 $version =~ s/(^\$| \$ .*$)//g;
253 print "wanna-build $version for $distribution on $conf::dbbase\n";
256 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
257 merge-packages manual-edit maintlock-create lock-for unlock-for
258 start-transaction commit-transaction
259 merge-sources maintlock-remove clean-db))) {
260 warn "No packages given.\n";
264 $real_user = (getpwuid($<))[0];
265 die "Can't determine your user name\n"
266 if $op_mode ne "list" && !$user &&
267 !($user = $real_user);
270 if ($op_mode eq "set-failed" && !$category) {
271 print "Enter reason for failing (end with '.' alone on ".
276 last if $line eq ".\n";
277 $fail_reason .= $line;
279 chomp( $fail_reason );
280 } elsif ($op_mode eq "set-dep-wait") {
281 print "Enter dependencies (one line):\n";
283 while( !$line && !eof(STDIN) ) {
284 chomp( $line = <STDIN> );
286 die "No dependencies given\n" if !$line;
287 $fail_reason = $line;
288 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
289 print "Enter changelog entry (one line):\n";
291 while( !$line && !eof(STDIN) ) {
292 chomp( $line = <STDIN> );
294 die "No changelog entry given\n" if !$line;
295 $fail_reason = $line;
298 if ($op_mode eq "maintlock-create") {
302 if ($op_mode eq "maintlock-remove") {
306 waitfor_maintlock() if $op_mode !~ /^(?:merge-|clean-db$)/;
308 if (!-f db_filename( $distribution ) && !$opt_create_db) {
309 if ($transactional) {
310 die "No running transaction for $distribution\n";
312 die "Database for $distribution doesn't exist\n";
316 # Locking for another process means that a longer running process (most likely
317 # wb) wants to do several steps at once, and manages the locks.
318 if ($op_mode eq "lock-for") {
319 lock_db( $distribution );
322 if ($op_mode eq "unlock-for") {
323 unlock_db( $distribution );
327 lock_db( $distribution );
329 if ($op_mode eq "start-transaction") {
330 copy ( db_filename_master( $distribution ), db_filename_transaction( $distribution ))
331 or die "Copy failed: $!";
332 open LOG, ">", db_transactlog_transaction( $distribution )
333 or die "Could not create logfile for transaction: $!";
338 if ($op_mode eq "commit-transaction") {
339 # we need to copy here to preserve the owner and group of the file
340 copy ( db_filename_transaction( $distribution ), db_filename_master( $distribution ))
341 or die "Copy failed: $!";
342 unlink db_filename_transaction( $distribution );
343 open TLOG, "<", db_transactlog_transaction( $distribution )
344 or die "Could not open logfile from transaction: $!";
345 open LOG, ">>", db_transactlog_master( $distribution )
346 or die "Could not open logfile: $!";
347 while (<TLOG>) { print LOG $_ };
350 unlink db_transactlog_transaction( $distribution );
356 if ($lock_for_pid == -1) {
357 unlock_db( $distribution );
359 foreach (keys %conf::distributions) {
360 untie %{$otherdb{$_}} if tied(%{$otherdb{$_}});
361 unlock_db( $_ ) if $otherdb_lock{$_};
365 tie %db, 'MLDBM', db_filename( $distribution ), GDBM_WRCREAT, 0664
366 or die "FATAL: Cannot open database\n";
370 if ($mail_logs && $conf::log_mail) {
371 send_mail( $conf::log_mail,
372 "wanna-build $distribution state changes $curr_date",
373 "State changes at $curr_date for distribution ".
374 "$distribution:\n\n$mail_logs\n" );
382 SWITCH: foreach ($op_mode) {
384 add_packages( $1, @ARGV );
388 list_packages( $list_state );
392 info_packages( @ARGV );
395 /^forget-user/ && do {
396 die "This operation is restricted to admin users\n"
397 if (defined @conf::admin_users and
398 !isin( $real_user, @conf::admin_users));
399 forget_users( @ARGV );
403 forget_packages( @ARGV );
406 /^merge-partial-quinn/ && do {
407 die "This operation is restricted to admin users\n"
408 if (defined @conf::admin_users and
409 !isin( $real_user, @conf::admin_users));
413 /^merge-quinn/ && do {
414 die "This operation is restricted to admin users\n"
415 if (defined @conf::admin_users and
416 !isin( $real_user, @conf::admin_users));
420 /^merge-packages/ && do {
421 die "This operation is restricted to admin users\n"
422 if (defined @conf::admin_users and
423 !isin( $real_user, @conf::admin_users));
427 /^merge-sources/ && do {
428 die "This operation is restricted to admin users\n"
429 if (defined @conf::admin_users and
430 !isin( $real_user, @conf::admin_users));
434 /^pretend-avail/ && do {
435 pretend_avail( @ARGV );
439 die "This operation is restricted to admin users\n"
440 if (defined @conf::admin_users and
441 !isin( $real_user, @conf::admin_users));
443 @ARGV = ( $ARGS[0] );
444 my $pkgs = parse_packages();
445 @ARGV = ( $ARGS[1] );
447 @ARGV = ( $ARGS[2] );
448 my $srcs = parse_sources(1);
449 call_edos_depcheck( $ARGS[0], $srcs );
454 die "This operation is restricted to admin users\n"
455 if (defined @conf::admin_users and
456 !isin( $real_user, @conf::admin_users));
457 %db = (); # clear all current contents
458 read_db( $import_from );
462 write_db( $export_to );
465 /^manual-edit/ && do {
466 die "This operation is restricted to admin users\n"
467 if (defined @conf::admin_users and
468 !isin( $real_user, @conf::admin_users));
469 my $tmpfile_pattern = "/tmp/wanna-build-$distribution.$$-";
471 for( $i = 0;; ++$i ) {
472 $tmpfile = $tmpfile_pattern . $i;
473 last if ! -e $tmpfile;
475 write_db( $tmpfile );
476 my $editor = $ENV{'VISUAL'} ||
477 "/usr/bin/sensible-editor";
478 system "$editor $tmpfile";
479 %db = (); # clear all current contents
485 die "This operation is restricted to admin users\n"
486 if (defined @conf::admin_users and
487 !isin( $real_user, @conf::admin_users));
492 die "Unexpected operation mode $op_mode\n";
494 if (not -t and $user =~ /-/) {
495 my $userinfo = $db{'_userinfo'};
496 $userinfo = {} if (!defined($userinfo));
498 my $ui = $userinfo->{$user};
499 $ui = {} if (!defined($ui));
501 $ui->{'Last-Seen'} = $curr_date;
502 $ui->{'User'} = $user;
504 $userinfo->{$user} = $ui;
505 $db{'_userinfo'} = $userinfo;
510 my $newstate = shift;
511 my( $package, $name, $version, $ok, $reason );
513 foreach $package (@_) {
514 $package =~ s,^.*/,,; # strip path
515 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
516 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
517 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
518 ($name,$version) = ($1,$2);
521 warn "$package: can't extract package name and version ".
526 if ($op_mode eq "set-building") {
527 add_one_building( $name, $version );
529 elsif ($op_mode eq "set-built") {
530 add_one_built( $name, $version );
532 elsif ($op_mode eq "set-attempted") {
533 add_one_attempted( $name, $version );
535 elsif ($op_mode eq "set-uploaded") {
536 add_one_uploaded( $name, $version );
538 elsif ($op_mode eq "set-failed") {
539 add_one_failed( $name, $version );
541 elsif ($op_mode eq "set-not-for-us") {
542 add_one_notforus( $name, $version );
544 elsif ($op_mode eq "set-needs-build") {
545 add_one_needsbuild( $name, $version );
547 elsif ($op_mode eq "set-dep-wait") {
548 add_one_depwait( $name, $version );
550 elsif ($op_mode eq "set-build-priority") {
551 set_one_buildpri( $name, $version, 'BuildPri' );
553 elsif ($op_mode eq "set-permanent-build-priority") {
554 set_one_buildpri( $name, $version, 'PermBuildPri' );
556 elsif ($op_mode eq "set-binary-nmu") {
557 set_one_binnmu( $name, $version );
562 sub add_one_building {
568 my $pkg = $db{$name};
570 if ($pkg->{'State'} eq "Not-For-Us") {
572 $reason = "not suitable for this architecture";
574 elsif ($pkg->{'State'} =~ /^Dep-Wait/) {
576 $reason = "not all source dependencies available yet";
578 elsif ($pkg->{'State'} =~ /^BD-Uninstallable/) {
580 $reason = "source dependencies are not installable";
582 elsif ($pkg->{'State'} eq "Uploaded" &&
583 (version_lesseq($version, $pkg->{'Version'}))) {
585 $reason = "already uploaded by $pkg->{'Builder'}";
586 $reason .= " (in newer version $pkg->{'Version'})"
587 if !version_eq($pkg, $version);
589 elsif ($pkg->{'State'} eq "Installed" &&
590 version_less($version,$pkg->{'Version'})) {
592 print "$name: Warning: newer version $pkg->{'Version'} ".
593 "already installed, but overridden.\n";
597 $reason = "newer version $pkg->{'Version'} already in ".
598 "archive; doesn't need rebuilding";
599 print "$name: Note: If the following is due to an epoch ",
600 " change, use --override\n";
603 elsif ($pkg->{'State'} eq "Installed" &&
604 pkg_version_eq($pkg,$version)) {
606 $reason = "is up-to-date in the archive; doesn't need rebuilding";
608 elsif ($pkg->{'State'} eq "Needs-Build" &&
609 version_less($version,$pkg->{'Version'})) {
611 print "$name: Warning: newer version $pkg->{'Version'} ".
612 "needs building, but overridden.";
616 $reason = "newer version $pkg->{'Version'} needs building, ".
620 elsif (isin($pkg->{'State'},qw(Building Built Build-Attempted))) {
621 if (version_less($pkg->{'Version'},$version)) {
622 print "$name: Warning: Older version $pkg->{'Version'} ",
623 "is being built by $pkg->{'Builder'}\n";
624 if ($pkg->{'Builder'} ne $user) {
625 send_mail( $pkg->{'Builder'},
626 "package takeover in newer version",
627 "You are building package '$name' in ".
628 "version $version\n".
629 "(as far as I'm informed).\n".
630 "$user now has taken the newer ".
631 "version $version for building.".
632 "You can abort the build if you like.\n" );
637 print "User $pkg->{'Builder'} had already ",
638 "taken the following package,\n",
639 "but overriding this as you request:\n";
640 send_mail( $pkg->{'Builder'}, "package takeover",
641 "The package '$name' (version $version) that ".
642 "was locked by you\n".
643 "has been taken over by $user\n" );
645 elsif ($pkg->{'Builder'} eq $user) {
646 print "$name: Note: already taken by you.\n";
647 print "$name: ok\n" if $verbose;
652 $reason = "already taken by $pkg->{'Builder'}";
653 $reason .= " (in newer version $pkg->{'Version'})"
654 if !version_eq($pkg->{'Version'}, $version);
658 elsif ($pkg->{'State'} =~ /^Failed/ &&
659 pkg_version_eq($pkg, $version)) {
661 print "The following package previously failed ",
662 "(by $pkg->{'Builder'})\n",
663 "but overriding this as you request:\n";
664 send_mail( $pkg->{'Builder'}, "failed package takeover",
665 "The package '$name' (version $version) that ".
666 "is locked by you\n".
667 "and has failed previously has been taken over ".
669 if $pkg->{'Builder'} ne $user;
673 $reason = "build of $version failed previously:\n ";
674 $reason .= join( "\n ", split( "\n", $pkg->{'Failed'} ));
675 $reason .= "\nalso the package doesn't need builing"
676 if $pkg->{'State'} eq 'Failed-Removed';
682 if ($pkg->{'Binary-NMU-Version'}) {
683 print "$name: Warning: needs binary NMU $pkg->{'Binary-NMU-Version'}\n" .
684 "$pkg->{'Binary-NMU-Changelog'}\n";
687 print "$name: Warning: Previous version failed!\n"
688 if $pkg->{'Previous-State'} =~ /^Failed/ ||
689 $pkg->{'State'} =~ /^Failed/;
691 change_state( \$pkg, 'Building' );
692 $pkg->{'Package'} = $name;
693 $pkg->{'Version'} = $version;
694 $pkg->{'Builder'} = $user;
695 log_ta( $pkg, "--take" );
697 print "$name: $ok\n" if $verbose;
700 print "$name: NOT OK!\n $reason\n";
704 sub add_one_attempted {
707 my $pkg = $db{$name};
709 if (!defined($pkg)) {
710 print "$name: not registered yet.\n";
714 if ($pkg->{'State'} ne "Building" ) {
715 print "$name: not taken for building (state is $pkg->{'State'}). ",
719 if ($pkg->{'Builder'} ne $user) {
720 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
723 elsif ( !pkg_version_eq($pkg, $version) ) {
724 print "$name: version mismatch ".
725 "$(pkg->{'Version'} ".
726 "by $pkg->{'Builder'})\n";
730 change_state( \$pkg, 'Build-Attempted' );
731 log_ta( $pkg, "--attempted" );
733 print "$name: registered as uploaded\n" if $verbose;
739 my $pkg = $db{$name};
741 if (!defined($pkg)) {
742 print "$name: not registered yet.\n";
746 if ($pkg->{'State'} ne "Building" ) {
747 print "$name: not taken for building (state is $pkg->{'State'}). ",
751 if ($pkg->{'Builder'} ne $user) {
752 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
755 elsif ( !pkg_version_eq($pkg, $version) ) {
756 print "$name: version mismatch ".
757 "$(pkg->{'Version'} ".
758 "by $pkg->{'Builder'})\n";
761 change_state( \$pkg, 'Built' );
762 log_ta( $pkg, "--built" );
764 print "$name: registered as built\n" if $verbose;
767 sub add_one_uploaded {
770 my $pkg = $db{$name};
772 if (!defined($pkg)) {
773 print "$name: not registered yet.\n";
777 if ($pkg->{'State'} eq "Uploaded" &&
778 pkg_version_eq($pkg,$version)) {
779 print "$name: already uploaded\n";
782 if (!isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
783 print "$name: not taken for building (state is $pkg->{'State'}). ",
787 if ($pkg->{'Builder'} ne $user) {
788 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
791 # strip epoch -- buildd-uploader used to go based on the filename.
792 # (to remove at some point)
794 ($pkgver = $pkg->{'Version'}) =~ s/^\d+://;
795 $version =~ s/^\d+://; # for command line use
796 if ($pkg->{'Binary-NMU-Version'} ) {
797 my $nmuver = binNMU_version($pkgver, $pkg->{'Binary-NMU-Version'});
798 if (!version_eq( $nmuver, $version )) {
799 print "$name: version mismatch ($nmuver registered). ",
803 } elsif (!version_eq($pkgver, $version)) {
804 print "$name: version mismatch ($pkg->{'Version'} registered). ",
809 change_state( \$pkg, 'Uploaded' );
810 log_ta( $pkg, "--uploaded" );
812 print "$name: registered as uploaded\n" if $verbose;
819 my $pkg = $db{$name};
821 if (!defined($pkg)) {
822 print "$name: not registered yet.\n";
825 $state = $pkg->{'State'};
827 if ($state eq "Not-For-Us") {
828 print "$name: not suitable for this architecture anyway. Skipping.\n";
831 elsif ($state eq "Failed-Removed") {
832 print "$name: failed previously and doesn't need building. Skipping.\n";
835 elsif ($state eq "Installed") {
836 print "$name: Is already installed in archive. Skipping.\n";
839 elsif ($pkg->{'Builder'} &&
840 (($user ne $pkg->{'Builder'}) &&
841 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
842 print "$name: not taken by you, but by ".
843 "$pkg->{'Builder'}. Skipping.\n";
846 elsif ( !pkg_version_eq($pkg, $version) ) {
847 print "$name: version mismatch ".
848 "$(pkg->{'Version'} ".
849 "by $pkg->{'Builder'})\n";
854 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
856 $cat = $short_category{$cat} if exists $short_category{$cat};
857 if (!isin( $cat, values %short_category )) {
858 print "$name: Warning: unknown category $cat; discarded\n";
861 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
864 if ($state eq "Needs-Build") {
865 print "$name: Warning: not registered for building previously, ".
866 "but processing anyway.\n";
868 elsif ($state eq "Uploaded") {
869 print "$name: Warning: marked as uploaded previously, ".
870 "but processing anyway.\n";
872 elsif ($state eq "Dep-Wait") {
873 print "$name: Warning: marked as waiting for dependencies, ".
874 "but processing anyway.\n";
876 elsif ($state eq "BD-Uninstallable") {
877 print "$name: Warning: marked as having uninstallable build-dependencies, ".
878 "but processing anyway.\n";
880 elsif ($state eq "Failed") {
881 print "$name: already registered as failed; will append new message\n"
883 print "$name: already registered as failed; changing category\n"
887 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
888 exists $pkg->{'Failed-Category'} &&
889 $pkg->{'Failed-Category'} ne $cat) {
890 (my $action = $cat) =~ s/-/ /;
891 $fail_reason .= "\n$short_date: $action";
894 change_state( \$pkg, 'Failed' );
895 $pkg->{'Builder'} = $user;
896 $pkg->{'Failed'} .= "\n" if $pkg->{'Failed'};
897 $pkg->{'Failed'} .= $fail_reason;
898 $pkg->{'Failed-Category'} = $cat if $cat;
899 if (defined $pkg->{'PermBuildPri'}) {
900 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
902 delete $pkg->{'BuildPri'};
904 log_ta( $pkg, "--failed" );
906 print "$name: registered as failed\n" if $verbose;
909 sub add_one_notforus {
912 my $pkg = $db{$name};
914 if ($pkg->{'State'} eq 'Not-For-Us') {
915 # reset Not-For-Us state in case it's called twice; this is
916 # the only way to get a package out of this state...
917 # There is no really good state in which such packages should
918 # be put :-( So use Failed for now.
919 change_state( \$pkg, 'Failed' );
920 $pkg->{'Package'} = $name;
921 $pkg->{'Failed'} = "Was Not-For-Us previously";
922 delete $pkg->{'Builder'};
923 delete $pkg->{'Depends'};
924 log_ta( $pkg, "--no-build(rev)" );
925 print "$name: now not unsuitable anymore\n";
927 send_mail( $conf::notforus_maint,
928 "$name moved out of Not-For-Us state",
929 "The package '$name' has been moved out of the Not-For-Us ".
931 "It should probably also be removed from ".
932 "Packages-arch-specific or\n".
933 "the action was wrong.\n" )
934 if $conf::notforus_maint;
937 change_state( \$pkg, 'Not-For-Us' );
938 $pkg->{'Package'} = $name;
939 delete $pkg->{'Builder'};
940 delete $pkg->{'Depends'};
941 delete $pkg->{'BuildPri'};
942 delete $pkg->{'Binary-NMU-Version'};
943 delete $pkg->{'Binary-NMU-Changelog'};
944 log_ta( $pkg, "--no-build" );
945 print "$name: registered as unsuitable\n" if $verbose;
947 send_mail( $conf::notforus_maint,
948 "$name set to Not-For-Us",
949 "The package '$name' has been set to state Not-For-Us ".
951 "It should probably also be added to ".
952 "Packages-arch-specific or\n".
953 "the Not-For-Us state is wrong.\n" )
954 if $conf::notforus_maint;
959 sub add_one_needsbuild {
963 my $pkg = $db{$name};
965 if (!defined($pkg)) {
966 print "$name: not registered; can't give back.\n";
969 $state = $pkg->{'State'};
971 if ($state eq "BD-Uninstallable") {
973 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
975 change_state( \$pkg, 'Needs-Build' );
976 delete $pkg->{'Builder'};
977 delete $pkg->{'Depends'};
978 log_ta( $pkg, "--give-back" );
980 print "$name: given back\n" if $verbose;
984 print "$name: has uninstallable build-dependencies. Skipping\n",
985 " (use --override to clear dependency list and ",
986 "give back anyway)\n";
990 elsif ($state eq "Dep-Wait") {
992 print "$name: Forcing source dependency list to be cleared\n";
995 print "$name: waiting for source dependencies. Skipping\n",
996 " (use --override to clear dependency list and ",
997 "give back anyway)\n";
1001 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1002 print "$name: not taken for building (state is $state).";
1003 if ($opt_override) {
1004 print "\n$name: Forcing give-back\n";
1007 print " Skipping.\n";
1011 if (defined ($pkg->{'Builder'}) && $user ne $pkg->{'Builder'} &&
1012 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user)) {
1013 print "$name: not taken by you, but by ".
1014 "$pkg->{'Builder'}. Skipping.\n";
1017 if (!pkg_version_eq($pkg, $version)) {
1018 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1022 change_state( \$pkg, 'BD-Uninstallable' );
1023 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1024 delete $pkg->{'Builder'};
1025 delete $pkg->{'Depends'};
1026 log_ta( $pkg, "--give-back" );
1028 print "$name: given back\n" if $verbose;
1031 sub set_one_binnmu {
1033 my $version = shift;
1034 my $pkg = $db{$name};
1037 if (!defined($pkg)) {
1038 print "$name: not registered; can't register for binNMU.\n";
1041 my $db_ver = $pkg->{'Version'};
1043 if (!version_eq($db_ver, $version)) {
1044 print "$name: version mismatch ($db_ver registered). ",
1048 $state = $pkg->{'State'};
1050 if (defined $pkg->{'Binary-NMU-Version'}) {
1051 if ($binNMUver == 0) {
1052 change_state( \$pkg, 'Installed' );
1053 delete $pkg->{'Builder'};
1054 delete $pkg->{'Depends'};
1055 delete $pkg->{'Binary-NMU-Version'};
1056 delete $pkg->{'Binary-NMU-Changelog'};
1057 } elsif ($binNMUver <= $pkg->{'Binary-NMU-Version'}) {
1058 print "$name: already building binNMU $pkg->{'Binary-NMU-Version'}\n";
1061 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1062 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1063 $pkg->{'Notes'} = 'out-of-date';
1064 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'}
1065 if (defined $pkg->{'PermBuildPri'});
1067 log_ta( $pkg, "--binNMU" );
1070 } elsif ($binNMUver == 0) {
1071 print "${name}_$version: no scheduled binNMU to cancel.\n";
1075 if ($state ne 'Installed') {
1076 print "${name}_$version: not installed; can't register for binNMU.\n";
1080 my $fullver = binNMU_version($version,$binNMUver);
1081 if ( version_lesseq( $fullver, $pkg->{'Installed-Version'} ) )
1083 print "$name: binNMU $fullver is not newer than current version $pkg->{'Installed-Version'}\n";
1087 change_state( \$pkg, 'BD-Uninstallable' );
1088 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1089 delete $pkg->{'Builder'};
1090 delete $pkg->{'Depends'};
1091 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1092 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1093 $pkg->{'Notes'} = 'out-of-date';
1094 log_ta( $pkg, "--binNMU" );
1096 print "${name}: registered for binNMU $fullver\n" if $verbose;
1099 sub set_one_buildpri {
1101 my $version = shift;
1103 my $pkg = $db{$name};
1106 if (!defined($pkg)) {
1107 print "$name: not registered; can't set priority.\n";
1110 $state = $pkg->{'State'};
1112 if ($state eq "Not-For-Us") {
1113 print "$name: not suitable for this architecture. Skipping.\n";
1115 } elsif ($state eq "Failed-Removed") {
1116 print "$name: failed previously and doesn't need building. Skipping.\n";
1119 if (!pkg_version_eq($pkg, $version)) {
1120 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1124 if ( $build_priority == 0 ) {
1125 delete $pkg->{'BuildPri'}
1126 if $key eq 'PermBuildPri' and defined $pkg->{'BuildPri'}
1127 and $pkg->{'BuildPri'} == $pkg->{$key};
1128 delete $pkg->{$key};
1130 $pkg->{'BuildPri'} = $build_priority
1131 if $key eq 'PermBuildPri';
1132 $pkg->{$key} = $build_priority;
1135 print "$name: set to build priority $build_priority\n" if $verbose;
1138 sub add_one_depwait {
1140 my $version = shift;
1142 my $pkg = $db{$name};
1144 if (!defined($pkg)) {
1145 print "$name: not registered yet.\n";
1148 $state = $pkg->{'State'};
1150 if ($state eq "Dep-Wait") {
1151 print "$name: merging with previously registered dependencies\n";
1154 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1155 print "$name: Warning: not registered for building previously, ".
1156 "but processing anyway.\n";
1158 elsif ($state eq "Not-For-Us") {
1159 print "$name: not suitable for this architecture anyway. Skipping.\n";
1162 elsif ($state eq "Failed-Removed") {
1163 print "$name: failed previously and doesn't need building. Skipping.\n";
1166 elsif ($state eq "Installed") {
1167 print "$name: Is already installed in archive. Skipping.\n";
1170 elsif ($state eq "Uploaded") {
1171 print "$name: Is already uploaded. Skipping.\n";
1174 elsif ($pkg->{'Builder'} &&
1175 $user ne $pkg->{'Builder'}) {
1176 print "$name: not taken by you, but by ".
1177 "$pkg->{'Builder'}. Skipping.\n";
1180 elsif ( !pkg_version_eq($pkg,$version)) {
1181 print "$name: version mismatch ".
1182 "($pkg->{'Version'} ".
1183 "by $pkg->{'Builder'})\n";
1186 elsif ($fail_reason =~ /^\s*$/ ||
1187 !parse_deplist( $fail_reason, 1 )) {
1188 print "$name: Bad dependency list\n";
1191 change_state( \$pkg, 'Dep-Wait' );
1192 $pkg->{'Builder'} = $user;
1193 if (defined $pkg->{'PermBuildPri'}) {
1194 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1196 delete $pkg->{'BuildPri'};
1198 my $deplist = parse_deplist( $pkg->{'Depends'} );
1199 my $new_deplist = parse_deplist( $fail_reason );
1200 # add new dependencies, maybe overwriting old entries
1201 foreach (keys %$new_deplist) {
1202 $deplist->{$_} = $new_deplist->{$_};
1204 $pkg->{'Depends'} = build_deplist($deplist);
1205 log_ta( $pkg, "--dep-wait" );
1207 print "$name: registered as waiting for dependencies\n" if $verbose;
1217 local($/) = ""; # read in paragraph mode
1219 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1221 /^Package:\s*(\S+)$/mi and $name = $1;
1222 /^Version:\s*(\S+)$/mi and $version = $1;
1223 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1224 /^Section:\s*(\S+)$/mi and $section = $1;
1225 /^Priority:\s*(\S+)$/mi and $priority = $1;
1226 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1227 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1228 /^Binary:\s*(.*)$/mi and $binaries = $1;
1230 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1231 $srcver{$name} = $version;
1233 $pkgs{$name}{'ver'} = $version;
1234 $pkgs{$name}{'bin'} = $binaries;
1235 $pkgs{$name}{'dep'} = $builddep;
1236 $pkgs{$name}{'conf'} = $buildconf;
1237 my $pkg = $db{$name};
1242 if ($arch eq "all" && !version_less( $version, $pkg->{'Version'} )) {
1243 # package is now Arch: all, delete it from db
1244 change_state( \$pkg, 'deleted' );
1245 log_ta( $pkg, "--merge-sources" );
1246 print "$name ($pkg->{'Version'}): deleted ".
1247 "from database, because now Arch: all\n"
1253 # The "Version" should always be the source version --
1254 # not a possible binNMU version number.
1255 $pkg->{'Version'} = $version, $change++
1256 if ($pkg->{'State'} eq 'Installed' and
1257 !version_eq( $pkg->{'Version'}, $version));
1258 # Always update priority and section, if available
1259 $pkg->{'Priority'} = $priority, $change++
1260 if defined $priority and (not defined($pkg->{'Priority'}) or $pkg->{'Priority'} ne $priority);
1262 $pkg->{'Section'} = $section, $change++
1263 if defined $section and (not defined($pkg->{'Section'}) or $pkg->{'Section'} ne $section);
1265 # Remove field from previous wanna-build versions
1266 for (qw/Reason Build-Depends Build-Conflicts/) {
1267 if (exists $pkg->{$_}) {
1273 $db{$name} = $pkg if $change;
1276 # Now that we only have the latest source version, build the list
1277 # of binary packages from the Sources point of view
1278 foreach $name (keys %pkgs) {
1279 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1280 $merge_binsrc{$bin} = $name;
1283 # remove installed packages that no longer have source available
1284 # or binaries installed
1285 foreach $name (keys %db) {
1286 next if $name =~ /^_/;
1287 my $pkg = $db{$name};
1288 if (not defined($pkgs{$name})) {
1289 change_state( \$pkg, 'deleted' );
1290 log_ta( $pkg, "--merge-sources" );
1291 print "$name ($pkg->{'Version'}): ".
1292 "deleted from database, because ".
1293 "not in Sources anymore\n"
1297 next if !isin( $pkg->{'State'}, qw(Installed) );
1298 if ($full && not defined $merge_srcvers{$name}) {
1299 change_state( \$pkg, 'deleted' );
1300 log_ta( $pkg, "--merge-sources" );
1301 print "$name ($pkg->{'Version'}): ".
1302 "deleted from database, because ".
1303 "binaries don't exist anymore\n"
1306 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'Version'})) {
1307 print "$name ($pkg->{'Version'}): ".
1308 "package is Installed but binaries are from ".
1309 $merge_srcvers{$name}. "\n"
1317 # This function looks through a Packages file and sets the state of
1318 # packages to 'Installed'
1319 sub parse_packages {
1322 local($/) = ""; # read in paragraph mode
1324 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1326 /^Package:\s*(\S+)$/mi and $name = $1;
1327 /^Version:\s*(\S+)$/mi and $version = $1;
1328 /^Depends:\s*(.*)$/mi and $depends = $1;
1329 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1330 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1331 /^Provides:\s*(.*)$/mi and $provides = $1;
1332 next if !$name || !$version;
1333 next if ($arch ne $architecture and $architecture ne "all");
1334 next if (defined ($installed->{$name}) and $installed->{$name}{'Version'} ne "" and
1335 version_lesseq( $version, $installed->{$name}{'Version'} ));
1336 $installed->{$name}{'Version'} = $version;
1337 $installed->{$name}{'Depends'} = $depends;
1338 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1339 undef $installed->{$name}{'Provider'};
1340 $installed->{$name}{'Source'} = $source ? $source : $name;
1342 foreach (split( /\s*,\s*/, $provides )) {
1343 if (not defined ($installed->{$_})) {
1344 $installed->{$_}{'Version'} = "";
1345 $installed->{$_}{'Provider'} = $name;
1349 if ( $version =~ /\+b(\d+)$/ ) {
1352 $version = $sourcev if $sourcev;
1353 $binaryv = $version;
1354 $binaryv =~ s/\+b\d+$//;
1355 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1356 $binaryv .= "+b$binnmu" if defined($binnmu);
1358 next if $architecture ne $arch;
1359 $name = $source if $source;
1360 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1361 $merge_srcvers{$name} = $version;
1363 my $pkg = $db{$name};
1366 if (isin( $pkg->{'State'}, qw(Not-For-Us)) ||
1367 (isin($pkg->{'State'}, qw(Installed)) &&
1368 version_lesseq($binaryv, $pkg->{'Installed-Version'}))) {
1369 print "Skipping $name because State == $pkg->{'State'}\n"
1373 if ($pkg->{'Binary-NMU-Version'} ) {
1374 my $nmuver = binNMU_version($pkg->{'Version'}, $pkg->{'Binary-NMU-Version'});
1375 if (version_less( $binaryv, $nmuver )) {
1376 print "Skipping $name ($version) because have newer ".
1377 "version ($nmuver) in db.\n"
1381 } elsif (version_less($version, $pkg->{'Version'})) {
1382 print "Skipping $name ($version) because have newer ".
1383 "version ($pkg->{'Version'}) in db.\n"
1388 if (!pkg_version_eq($pkg, $version) &&
1389 $pkg->{'State'} ne "Installed") {
1390 warn "Warning: $name: newer version than expected appeared ".
1391 "in archive ($version vs. $pkg->{'Version'})\n";
1392 delete $pkg->{'Builder'};
1395 if (!isin( $pkg->{'State'}, qw(Uploaded) )) {
1396 warn "Warning: Package $name was not in uploaded state ".
1397 "before (but in '$pkg->{'State'}').\n";
1398 delete $pkg->{'Builder'};
1399 delete $pkg->{'Depends'};
1403 $pkg->{'Version'} = $version;
1406 change_state( \$pkg, 'Installed' );
1407 $pkg->{'Package'} = $name;
1408 $pkg->{'Installed-Version'} = $binaryv;
1409 if (defined $pkg->{'PermBuildPri'}) {
1410 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1412 delete $pkg->{'BuildPri'};
1414 $pkg->{'Version'} = $version
1415 if version_less( $pkg->{'Version'}, $version);
1416 delete $pkg->{'Binary-NMU-Version'};
1417 delete $pkg->{'Binary-NMU-Changelog'};
1418 log_ta( $pkg, "--merge-packages" );
1420 print "$name ($version) is up-to-date now.\n" if $verbose;
1423 check_dep_wait( "--merge-packages", $installed );
1428 my ($package, $name, $version, $installed);
1430 foreach $package (@_) {
1431 $package =~ s,^.*/,,; # strip path
1432 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1433 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1434 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1435 ($name,$version) = ($1,$2);
1438 warn "$package: can't extract package name and version ".
1442 $installed->{$name}{'Version'} = $version;
1445 check_dep_wait( "--pretend-avail", $installed );
1448 sub check_dep_wait {
1450 my $installed = shift;
1452 # check all packages in state Dep-Wait if dependencies are all
1455 foreach $name (keys %db) {
1456 next if $name =~ /^_/;
1457 my $pkg = $db{$name};
1458 next if $pkg->{'State'} ne "Dep-Wait";
1459 my $deps = $pkg->{'Depends'};
1461 print "$name: was in state Dep-Wait, but with empty ",
1463 goto make_needs_build;
1465 my $deplist = parse_deplist($deps);
1469 foreach (keys %$deplist) {
1470 if (!exists $installed->{$_} ||
1471 ($deplist->{$_}->{'Rel'} && $deplist->{$_}->{'Version'} &&
1472 !version_compare( $installed->{$_}{'Version'},
1473 $deplist->{$_}->{'Rel'},
1474 $deplist->{$_}->{'Version'}))) {
1476 $new_deplist->{$_} = $deplist->{$_};
1479 push( @removed_deps, $_ );
1484 change_state( \$pkg, 'Needs-Build' );
1485 log_ta( $pkg, $action );
1486 delete $pkg->{'Builder'};
1487 delete $pkg->{'Depends'};
1488 print "$name ($pkg->{'Version'}) has all ",
1489 "dependencies available now\n" if $verbose;
1493 elsif (@removed_deps) {
1494 $pkg->{'Depends'} = build_deplist( $new_deplist );
1495 print "$name ($pkg->{'Version'}): some dependencies ",
1496 "(@removed_deps) available now, but not all yet\n"
1503 # This function accepts quinn-diff output (either from a file named on
1504 # the command line, or on stdin) and sets the packages named there to
1505 # state 'Needs-Build'.
1506 sub parse_quinn_diff {
1507 my $partial = shift;
1513 next if !m,^([-\w\d/]*)/ # section
1514 ([-\w\d.+]+)_ # package name
1515 ([\w\d:.~+-]+)\.dsc\s* # version
1516 \[([^:]*): # priority
1517 ([^]]+)\]\s*$,x; # rest of notes
1518 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1519 $quinn_pkgs{$name}++;
1520 $section ||= "unknown";
1521 $priority ||= "unknown";
1522 $priority = "unknown" if $priority eq "-";
1523 $priority = "standard" if ($name eq "debian-installer");
1525 my $pkg = $db{$name};
1527 # Always update section and priority.
1528 if (defined($pkg)) {
1530 $pkg->{'Section'} = $section, $change++ if not defined
1531 $pkg->{'Section'} or $section ne "unknown";
1532 $pkg->{'Priority'} = $priority, $change++ if not defined
1533 $pkg->{'Priority'} or $priority ne "unknown";
1536 if (defined($pkg) &&
1537 $pkg->{'State'} =~ /^Dep-Wait/ &&
1538 version_less( $pkg->{'Version'}, $version )) {
1539 change_state( \$pkg, 'Dep-Wait' );
1540 $pkg->{'Version'} = $version;
1541 delete $pkg->{'Binary-NMU-Version'};
1542 delete $pkg->{'Binary-NMU-Changelog'};
1543 log_ta( $pkg, "--merge-quinn" );
1545 print "$name ($version) still waiting for dependencies.\n"
1548 elsif (defined($pkg) &&
1549 $pkg->{'State'} =~ /-Removed$/ &&
1550 version_eq($pkg->{'Version'}, $version)) {
1551 # reinstantiate a package that has been removed earlier
1552 # (probably due to a quinn-diff malfunction...)
1553 my $newstate = $pkg->{'State'};
1554 $newstate =~ s/-Removed$//;
1555 change_state( \$pkg, $newstate );
1556 $pkg->{'Version'} = $version;
1557 $pkg->{'Notes'} = $notes;
1558 log_ta( $pkg, "--merge-quinn" );
1560 print "$name ($version) reinstantiated to $newstate.\n"
1563 elsif (defined($pkg) &&
1564 $pkg->{'State'} eq "Not-For-Us" &&
1565 version_less( $pkg->{'Version'}, $version )) {
1566 # for Not-For-Us packages just update the version etc., but
1568 change_state( \$pkg, "Not-For-Us" );
1569 $pkg->{'Package'} = $name;
1570 $pkg->{'Version'} = $version;
1571 $pkg->{'Notes'} = $notes;
1572 delete $pkg->{'Builder'};
1573 log_ta( $pkg, "--merge-quinn" );
1575 print "$name ($version) still Not-For-Us.\n" if $verbose;
1577 elsif (!defined($pkg) ||
1578 $pkg->{'State'} ne "Not-For-Us" &&
1579 (version_less( $pkg->{'Version'}, $version ) ||
1580 ($pkg->{'State'} eq "Installed" && version_less($pkg->{'Installed-Version'}, $version)))) {
1582 if (defined( $pkg->{'State'} ) && isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
1583 send_mail( $pkg->{'Builder'},
1584 "new version of $name (dist=$distribution)",
1585 "As far as I'm informed, you're currently ".
1586 "building the package $name\n".
1587 "in version $pkg->{'Version'}.\n\n".
1588 "Now there's a new source version $version. ".
1589 "If you haven't finished\n".
1590 "compiling $name yet, you can stop it to ".
1591 "save some work.\n".
1592 "Just to inform you...\n".
1593 "(This is an automated message)\n" );
1594 print "$name: new version ($version) while building ".
1595 "$pkg->{'Version'} -- sending mail ".
1596 "to builder ($pkg->{'Builder'})\n"
1599 change_state( \$pkg, 'Needs-Build' );
1600 $pkg->{'Package'} = $name;
1601 $pkg->{'Version'} = $version;
1602 $pkg->{'Section'} = $section;
1603 $pkg->{'Priority'} = $priority;
1604 $pkg->{'Notes'} = $notes;
1605 delete $pkg->{'Builder'};
1606 delete $pkg->{'Binary-NMU-Version'};
1607 delete $pkg->{'Binary-NMU-Changelog'};
1608 log_ta( $pkg, "--merge-quinn" );
1611 print "$name ($version) needs rebuilding now.\n" if $verbose;
1613 elsif (defined($pkg) &&
1614 !version_eq( $pkg->{'Version'}, $version ) &&
1615 isin( $pkg->{'State'}, qw(Installed Not-For-Us) )) {
1616 print "$name: skipping because version in db ".
1617 "($pkg->{'Version'}) is >> than ".
1618 "what quinn-diff says ($version) ".
1619 "(state is $pkg->{'State'})\n"
1621 $dubious .= "$pkg->{'State'}: ".
1622 "db ${name}_$pkg->{'Version'} >> ".
1623 "quinn $version\n" if !$partial;
1625 elsif ($verbose >= 2) {
1626 if ($pkg->{'State'} eq "Not-For-Us") {
1627 print "Skipping $name because State == ".
1628 "$pkg->{'State'}\n";
1630 elsif (!version_less($pkg->{'Version'}, $version)) {
1631 print "Skipping $name because version in db ".
1632 "($pkg->{'Version'}) is >= than ".
1633 "what quinn-diff says ($version)\n";
1636 $db{$name} = $pkg if $change;
1640 send_mail( $conf::db_maint,
1641 "Dubious versions in $distribution $conf::dbbase database",
1642 "The following packages have a newer version in the ".
1643 "wanna-build database\n".
1644 "than what quinn-diff says, and this is strange for ".
1646 "It could be caused by a lame mirror, or the version ".
1647 "in the database\n".
1652 # Now re-check the DB for packages in states Needs-Build, Failed,
1653 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1654 # anymore by quinn-diff.
1657 foreach $name (keys %db) {
1658 next if $name =~ /^_/;
1659 my $pkg = $db{$name};
1660 next if defined $pkg->{'Binary-NMU-Version'};
1661 next if !isin( $pkg->{'State'},
1662 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1663 my $virtual_delete = $pkg->{'State'} eq 'Failed';
1665 if (!$quinn_pkgs{$name}) {
1666 change_state( \$pkg, $virtual_delete ?
1667 $pkg->{'State'}."-Removed" :
1669 log_ta( $pkg, "--merge-quinn" );
1670 print "$name ($pkg->{'Version'}): ".
1671 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1672 "from database, because not in quinn-diff anymore\n"
1674 if ($virtual_delete) {
1684 sub send_reupload_mail {
1687 my $version = shift;
1689 my $other_dist = shift;
1692 "Please reupload ${pkg}_${'Version'} for $dist",
1693 "You have recently built (or are currently building)\n".
1694 "${pkg}_${'Version'} for $other_dist.\n".
1695 "This version is now also needed in the $dist distribution.\n".
1696 "Please reupload the files now present in the Debian archive\n".
1697 "(best with buildd-reupload).\n" );
1701 # for sorting priorities and sections
1703 %prioval = ( required => -5,
1711 'debian-installer' => -199,
1732 localizations => -178,
1733 interpreters => -177,
1758 electronics => -152,
1764 foreach my $i (keys %sectval) {
1765 $sectval{"contrib/$i"} = $sectval{$i}+40;
1766 $sectval{"non-free/$i"} = $sectval{$i}+80;
1768 $sectval{'unknown'} = -165;
1770 %catval = ( "none" => -20,
1771 "uploaded-fixed-pkg" => -19,
1772 "fix-expected" => -18,
1773 "reminder-sent" => -17,
1774 "nmu-offered" => -16,
1778 "compiler-error" => -12 );
1781 sub sort_list_func {
1782 my( $letter, $x, $ax, $bx );
1784 foreach $letter (split( "", $list_order )) {
1785 SWITCH: foreach ($letter) {
1787 $x = $b->{'BuildPri'} <=> $a->{'BuildPri'};
1788 return $x if $x != 0;
1792 $x = $prioval{$a->{'Priority'}} <=> $prioval{$b->{'Priority'}};
1793 return $x if $x != 0;
1797 $x = $sectval{$a->{'Section'}} <=> $sectval{$b->{'Section'}};
1798 return $x if $x != 0;
1802 $x = $a->{'Package'} cmp $b->{'Package'};
1803 return $x if $x != 0;
1807 $x = $a->{'Builder'} cmp $b->{'Builder'};
1808 return $x if $x != 0;
1812 $ax = ($a->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1813 ($a->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1814 $bx = ($b->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1815 ($b->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1817 return $x if $x != 0;
1821 my $ca = exists $a->{'Failed-Category'} ?
1822 $a->{'Failed-Category'} : "none";
1823 my $cb = exists $b->{'Failed-Category'} ?
1824 $b->{'Failed-Category'} : "none";
1825 $x = $catval{$ca} <=> $catval{$cb};
1826 return $x if $x != 0;
1830 my $pa = $prioval{$a->{'Priority'}} >
1831 $prioval{'standard'};
1832 my $pb = $prioval{$b->{'Priority'}} >
1833 $prioval{'standard'};
1835 return $x if $x != 0;
1845 my( $name, $pkg, @list );
1850 foreach $name (keys %db) {
1851 next if $name =~ /^_/;
1853 next if $state ne "all" && $pkg->{'State'} !~ /^\Q$state\E$/i;
1854 next if $user && (lc($state) ne 'needs-build' and $pkg->{'Builder'} ne $user);
1855 next if $category && $pkg->{'State'} eq "Failed" &&
1856 $pkg->{'Failed-Category'} ne $category;
1857 next if ($list_min_age > 0 &&
1858 ($ctime-parse_date($pkg->{'State-Change'})) < $list_min_age)||
1859 ($list_min_age < 0 &&
1860 ($ctime-parse_date($pkg->{'State-Change'})) > -$list_min_age);
1861 push( @list, $pkg );
1864 foreach $pkg (sort sort_list_func @list) {
1865 print "$pkg->{'Section'}/$pkg->{'Package'}_$pkg->{'Version'}";
1866 print ": $pkg->{'State'}"
1868 print " by $pkg->{'Builder'}"
1869 if $pkg->{'State'} ne "Needs-Build" && $pkg->{'Builder'};
1870 print " [$pkg->{'Priority'}:$pkg->{'Notes'}";
1871 print ":PREV-FAILED"
1872 if $pkg->{'Previous-State'} =~ /^Failed/;
1873 print ":bp{" . $pkg->{'BuildPri'} . "}"
1874 if exists $pkg->{'BuildPri'};
1875 print ":binNMU{" . $pkg->{'Binary-NMU-Version'} . "}"
1876 if exists $pkg->{'Binary-NMU-Version'};
1878 print " Reasons for failing:\n",
1880 exists $pkg->{'Failed-Category'} ? $pkg->{'Failed-Category'} : "none",
1882 join("\n ",split("\n",$pkg->{'Failed'})), "\n"
1883 if $pkg->{'State'} =~ /^Failed/;
1884 print " Dependencies: $pkg->{'Depends'}\n"
1885 if $pkg->{'State'} eq "Dep-Wait";
1886 print " Reasons for BD-Uninstallable:\n ",
1887 join("\n ",split("\n",$pkg->{'BD-Problem'})), "\n"
1888 if $pkg->{'State'} eq "BD-Uninstallable";
1889 print " Previous state was $pkg->{'Previous-State'} until ",
1890 "$pkg->{'State-Change'}\n"
1891 if $verbose && $pkg->{'Previous-State'};
1892 print " No previous state recorded\n"
1893 if $verbose && !$pkg->{'Previous-State'};
1894 print " Previous failing reasons:\n ",
1895 join("\n ",split("\n",$pkg->{'Old-Failed'})), "\n"
1896 if $verbose && $pkg->{'Old-Failed'};
1898 $scnt{$pkg->{'State'}}++ if $state eq "all";
1900 if ($state eq "all") {
1901 foreach (sort keys %scnt) {
1902 print "Total $scnt{$_} package(s) in state $_.\n";
1905 print "Total $cnt package(s)\n";
1910 my( $name, $pkg, $key, $dist );
1911 my @firstkeys = qw(Package Version Builder State Section Priority
1912 Installed-Version Previous-State State-Change);
1913 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1915 foreach $dist (@dists) {
1916 if ($dist ne $distribution) {
1917 if (!-f db_filename( $dist ) || !open_other_db( $dist )) {
1918 warn "Cannot open database for $dist!\n";
1919 @dists = grep { $_ ne $dist } @dists;
1924 foreach $name (@_) {
1925 $name =~ s/_.*$//; # strip version
1926 foreach $dist (@dists) {
1927 my $db = $dist ne $distribution ? $otherdb{$dist} : \%db;
1928 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1930 $pkg = $db->{$name};
1931 if (!defined( $pkg )) {
1932 print "$pname: not registered\n";
1937 foreach $key (@firstkeys) {
1938 next if !exists $pkg->{$key};
1939 my $val = $pkg->{$key};
1941 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1943 printf " %-20s: %s\n", $key, $val;
1945 foreach $key (sort keys %$pkg) {
1946 next if isin( $key, @firstkeys );
1947 my $val = $pkg->{$key};
1949 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1951 printf " %-20s: %s\n", $key, $val;
1957 sub forget_packages {
1958 my( $name, $pkg, $key, $data );
1960 foreach $name (@_) {
1961 $name =~ s/_.*$//; # strip version
1963 if (!defined( $pkg )) {
1964 print "$name: not registered\n";
1969 foreach $key (sort keys %$pkg) {
1970 my $val = $pkg->{$key};
1973 $data .= sprintf " %-20s: %s\n", $key, $val;
1975 send_mail( $conf::db_maint,
1976 "$name deleted from DB $conf::dbbase",
1977 "The package '$name' has been deleted from the database ".
1979 "Data registered about the deleted package:\n".
1980 "$data\n" ) if $conf::db_maint;
1981 change_state( \$pkg, 'deleted' );
1982 log_ta( $pkg, "--forget" );
1984 print "$name: deleted from database\n" if $verbose;
1992 $ui = $db{'_userinfo'};
1993 foreach $name (@_) {
1994 if (!defined( $ui->{$name} )) {
1995 print "$name: not registered\n";
1999 delete $ui->{$name};
2001 print "$name: deleted from database\n" if $verbose;
2003 $db{'_userinfo'} = $ui if $change;
2009 my $lockfile = db_lockfilename($dist);
2012 print "Locking $dist database\n" if $verbose >= 2;
2014 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2016 # lock file exists, wait
2017 goto repeat if !open( F, "<$lockfile" );
2020 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2021 warn "Bad lock file contents -- still trying\n";
2024 my($pid, $usr) = ($1, $2);
2025 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2026 # process doesn't exist anymore, remove stale lock
2027 print "Removing stale lock file (pid $pid, user $usr)\n";
2028 unlink( $lockfile );
2031 if ($pid == $lock_for_pid) {
2032 # We are allowed to use this lock.
2035 warn "Database locked by $usr -- please wait\n" if $try == 0;
2038 # avoid the END routine removes the lock
2039 $main::keep_lock{$dist} = 1;
2040 die "Lock still present after 200 * 5 seconds.\n";
2045 die "Can't create lock file $lockfile: $!\n";
2047 my $pid = $lock_for_pid == -1 ? $$ : $lock_for_pid;
2048 F->print("$pid $real_user\n");
2054 my $lockfile = db_lockfilename($dist);
2056 if (!$main::keep_lock{$dist}) {
2057 print "Unlocking $dist database\n" if $verbose >= 2;
2062 sub create_maintlock {
2063 my $lockfile = db_lockfilename("maintenance");
2067 print "Creating maintenance lock\n" if $verbose >= 2;
2069 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2071 # lock file exists, wait
2072 goto repeat if !open( F, "<$lockfile" );
2075 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2076 warn "Bad maintenance lock file contents -- still trying\n";
2079 my($pid, $usr) = ($1, $2);
2080 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2081 # process doesn't exist anymore, remove stale lock
2082 print "Removing stale lock file (pid $pid, user $usr)\n";
2083 unlink( $lockfile );
2086 warn "Maintenance lock already exists by $usr -- ".
2087 "please wait\n" if $try == 0;
2090 die "Lock still present after 120 * 60 seconds.\n";
2095 die "Can't create maintenance lock $lockfile: $!\n";
2097 F->print(getppid(), " $real_user\n");
2101 sub remove_maintlock {
2102 my $lockfile = db_lockfilename("maintenance");
2104 print "Removing maintenance lock\n" if $verbose >= 2;
2108 sub waitfor_maintlock {
2109 my $lockfile = db_lockfilename("maintenance");
2113 print "Checking for maintenance lock\n" if $verbose >= 2;
2115 if (open( F, "<$lockfile" )) {
2118 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2119 warn "Bad maintenance lock file contents -- still trying\n";
2122 my($pid, $usr) = ($1, $2);
2123 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2124 # process doesn't exist anymore, remove stale lock
2125 print "Removing stale maintenance lock (pid $pid, user $usr)\n";
2126 unlink( $lockfile );
2129 warn "Databases locked for general maintenance by $usr -- ".
2130 "please wait\n" if $try == 0;
2133 die "Lock still present after 120 * 60 seconds.\n";
2144 print "Reading ASCII database from $file..." if $verbose >= 1;
2145 open( F, "<$file" ) or
2146 die "Can't open database $file: $!\n";
2148 local($/) = ""; # read in paragraph mode
2150 my( %thispkg, $name );
2152 s/\n[ \t]+/\376\377/g; # fix continuation lines
2153 s/\376\377\s*\376\377/\376\377/og;
2155 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2156 my ($key, $val) = ($1, $2);
2157 $val =~ s/\376\377/\n/g;
2158 $thispkg{$key} = $val;
2160 check_entry( \%thispkg );
2162 if (exists($thispkg{'Package'})) {
2163 $name = $thispkg{'Package'};
2164 $db{$name} = \%thispkg;
2166 elsif(exists($thispkg{'User'})) {
2167 my $userinfo = $db{'_userinfo'};
2168 $userinfo = {} if (!defined($userinfo));
2170 $name = $thispkg{'User'};
2171 $userinfo->{$name} = \%thispkg;
2173 $db{'_userinfo'} = $userinfo;
2177 print "done\n" if $verbose >= 1;
2184 return if $op_mode eq "manual-edit"; # no checks then
2186 # check for required fields
2187 if (exists $pkg->{'User'}) {
2190 if (!exists $pkg->{'Package'}) {
2191 print STDERR "Bad entry: ",
2192 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2193 die "Database entry lacks Package or User: field\n";
2195 if (!exists $pkg->{'Version'}) {
2196 die "Database entry for $pkg->{'Package'} lacks Version: field\n";
2198 # if no State: field, generate one (for old db compat)
2199 if (!exists($pkg->{'State'})) {
2201 exists $pkg->{'Failed'} ? 'Failed' : 'Building';
2204 die "Bad state $pkg->{'State'} of package $pkg->{Package}\n"
2205 if !isin( $pkg->{'State'},
2206 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait
2207 Failed Failed-Removed Not-For-Us BD-Uninstallable
2213 my($name,$pkg,$key);
2215 print "Writing ASCII database to $file..." if $verbose >= 1;
2216 open( F, ">$file" ) or
2217 die "Can't open database $file: $!\n";
2219 foreach $name (sort keys %db) {
2220 my $pkg = $db{$name};
2221 if ($name eq '_userinfo') {
2222 foreach $user (sort keys %{$pkg}) {
2223 my $ui = $pkg->{$user};
2224 print F "User: $user\n"
2225 if (!defined($ui->{'User'}));
2226 foreach $key (keys %{$ui}) {
2227 my $val = $ui->{$key};
2230 $val =~ s/^ +$/ ./mg;
2231 print F "$key: $val\n";
2237 foreach $key (keys %{$pkg}) {
2238 my $val = $pkg->{$key};
2241 $val =~ s/^ +$/ ./mg;
2242 print F "$key: $val\n";
2248 print "done\n" if $verbose >= 1;
2254 my $newstate = shift;
2255 my $for_dist = shift;
2258 return if !open_other_db( $for_dist );
2259 $db = $otherdb{$for_dist};
2260 $pkg = \$db{$pkg->{'Package'}};
2265 my $state = \$pkg->{'State'};
2267 return if defined($$state) and $$state eq $newstate;
2268 $pkg->{'Previous-State'} = $$state if defined($$state);
2269 $pkg->{'State-Change'} = $curr_date;
2271 if (defined($$state) and $$state eq 'Failed') {
2272 $pkg->{'Old-Failed'} =
2273 "-"x20 . " $pkg->{'Version'} " . "-"x20 . "\n" .
2274 $pkg->{'Failed'} . "\n" .
2275 $pkg->{'Old-Failed'};
2276 delete $pkg->{'Failed'};
2277 delete $pkg->{'Failed-Category'};
2279 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2280 delete $pkg->{'BD-Problem'};
2282 $$state = $newstate;
2288 if (!tied(%{$otherdb{$dist}})) {
2290 $otherdb_lock{$dist} = 1;
2291 if (!(tie %{$otherdb{$dist}}, 'MLDBM', db_filename($dist), 0, 0664)){
2292 warn "Serious warning: Cannot open database for $dist\n";
2294 $otherdb_lock{$dist} = 0;
2305 my $dist = $distribution;
2309 $prevstate = $pkg->{'Previous-State'};
2310 $str = "$action($dist): $pkg->{'Package'}_$pkg->{'Version'} ".
2311 "changed from $prevstate to $pkg->{'State'} ".
2312 "by $real_user as $user";
2314 my $transactlog = db_transactlog( $distribution );
2315 if (!open( LOG, ">>$transactlog" )) {
2316 warn "Can't open log file $transactlog: $!\n";
2319 print LOG "$curr_date: $str\n";
2322 if (!($prevstate eq 'Failed' && $pkg->{'State'} eq 'Failed')) {
2323 $str .= " (with --override)"
2325 $mail_logs .= "$str\n";
2332 my $subject = shift;
2335 my $from = $conf::db_maint;
2336 my $domain = $conf::buildd_domain;
2338 $from .= "\@$domain" if $from !~ /\@/;
2340 $to .= '@' . $domain if $to !~ /\@/;
2341 $text =~ s/^\.$/../mg;
2342 local $SIG{'PIPE'} = 'IGNORE';
2343 open( PIPE, "| $conf::mailprog -oem $to" )
2344 or die "Can't open pipe to $conf::mailprog: $!\n";
2346 print PIPE "From: $from\n";
2347 print PIPE "Subject: $subject\n\n";
2348 print PIPE "$text\n";
2354 return $transactional ? db_filename_transaction($dist) : db_filename_master($dist);
2356 sub db_filename_master {
2358 return "$conf::basedir/$conf::dbbase-$dist";
2360 sub db_filename_transaction {
2362 return "$conf::basedir/$conf::dbbase-$dist-transaction";
2365 sub db_lockfilename {
2367 return db_filename_master($dist) . ".lock";
2371 sub db_transactlog {
2373 return $transactional ? db_transactlog_transaction($dist) : db_transactlog_master($dist);
2375 sub db_transactlog_master {
2377 $conf::dbbase =~ m#^([^/]+/)#;
2378 return "$conf::basedir/$1$conf::transactlog";
2380 sub db_transactlog_transaction {
2382 $conf::dbbase =~ m#^([^/]+/)#;
2383 return "$conf::basedir/$1$conf::transactlog-$dist-transaction";
2386 # for parsing input to dep-wait
2392 foreach (split( /\s*,\s*/, $deps )) {
2394 # verification requires > starting prompts, no | crap
2395 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2400 my @alts = split( /\s*\|\s*/, $_ );
2401 # Anything with an | is ignored, as it can be configured on a
2402 # per-buildd basis what will be installed
2403 next if $#alts != 0;
2406 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2407 warn( "parse_deplist: bad dependency $_\n" );
2410 my($dep, $rel, $relv) = ($1, $3, $4);
2411 $rel = ">>" if defined($rel) and $rel eq ">";
2412 $result{$dep}->{'Package'} = $dep;
2413 if ($rel && $relv) {
2414 $result{$dep}->{'Rel'} = $rel;
2415 $result{$dep}->{'Version'} = $relv;
2418 return 1 if $verify;
2422 # for parsing Build-Depends from Sources
2423 sub parse_srcdeplist {
2430 foreach $dep (split( /\s*,\s*/, $deps )) {
2431 my @alts = split( /\s*\|\s*/, $dep );
2432 # Anything with an | is ignored, as it can be configured on a
2433 # per-buildd basis what will be installed
2434 next if $#alts != 0;
2436 if (!/^([^\s([]+)\s*(\(\s*([<=>]+)\s*(\S+)\s*\))?(\s*\[([^]]+)\])?/) {
2437 warn( "parse_srcdeplist: bad dependency $_\n" );
2440 my($dep, $rel, $relv, $archlist) = ($1, $3, $4, $6);
2442 $archlist =~ s/^\s*(.*)\s*$/$1/;
2443 my @archs = split( /\s+/, $archlist );
2444 my ($use_it, $ignore_it, $include) = (0, 0, 0);
2447 $ignore_it = 1 if substr($_, 1) eq $arch;
2449 $use_it = 1 if $_ eq $arch;
2453 warn "Warning: inconsistent arch restriction on ",
2454 "$pkg: $dep depedency\n"
2455 if $ignore_it && $use_it;
2456 next if $ignore_it || ($include && !$use_it);
2464 $result->{'Package'} = $dep;
2465 $result->{'Neg'} = $neg;
2466 if ($rel && $relv) {
2467 $result->{'Rel'} = $rel;
2468 $result->{'Version'} = $relv;
2470 push @results, $result;
2479 foreach $key (keys %$list) {
2480 $result .= ", " if $result;
2482 $result .= " ($list->{$key}->{'Rel'} $list->{$key}->{'Version'})"
2483 if $list->{$key}->{'Rel'} && $list->{$key}->{'Version'};
2490 tie %new_db, 'MLDBM', db_filename( $distribution ) . ".new", GDBM_WRCREAT, 0664
2491 or die "FATAL: Cannot create new database\n";
2493 untie %db or die "FATAL: Cannot untie old database\n";
2494 system ("cp " . db_filename( $distribution ) . ".new " .
2495 db_filename( $distribution ) ) == 0
2496 or die "FATAL: Cannot overwrite old database";
2497 unlink db_filename( $distribution ) . ".new";
2502 sub get_unsatisfied_dep {
2506 my $savedep = shift;
2508 my $pkgname = $dep->{'Package'};
2510 if (defined $pkgs->{$pkgname}{'Provider'}) {
2511 # provides. leave them for buildd/sbuild.
2516 return $pkgs->{$pkgname}{'Unsatisfied'} if $savedep and defined($pkgs->{$pkgname}{'Unsatisfied'});
2518 # Return unsatisfied deps to a higher caller to process
2519 if ((!defined($pkgs->{$pkgname})) or
2520 (defined($dep->{'Rel'}) and !version_compare( $pkgs->{$pkgname}{'Version'}, $dep->{'Rel'}, $dep->{'Version'} ) ) ) {
2522 $deplist{$pkgname} = $dep;
2523 my $deps = build_deplist(\%deplist);
2524 $pkgs->{$pkgname}{'Unsatisfied'} = $deps if $savedep;
2528 # set cache to "" to avoid infinite recursion
2529 $pkgs->{$pkgname}{'Unsatisfied'} = "" if $savedep;
2531 if (defined $pkgs->{$dep->{'Package'}}{'Depends'}) {
2532 my $deps = parse_deplist( $pkgs->{$dep->{'Package'}}{'Depends'} );
2533 foreach (keys %$deps) {
2536 my $ret = get_unsatisfied_dep($bd,$pkgs,$dep,1);
2538 my $retdep = parse_deplist( $ret );
2539 foreach (keys %$retdep) {
2540 $dep = $$retdep{$_};
2542 $dep->{'Rel'} = '>=' if defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^=';
2544 if (defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>' and defined ($pkgs->{$dep->{'Package'}}) and
2545 version_compare($bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'ver'},'>>',$pkgs->{$dep->{'Package'}}{'Sourcev'})) {
2546 if (not defined($merge_binsrc{$dep->{'Package'}})) {
2547 # the uninstallable package doesn't exist in the new source; look for something else that does.
2548 delete $$retdep{$dep->{'Package'}};
2549 foreach (sort (split( /\s*,\s*/, $bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'bin'}))) {
2550 next if ($pkgs->{$_}{'all'} or not defined $pkgs->{$_}{'Version'});
2551 $dep->{'Package'} = $_;
2552 $dep->{'Rel'} = '>>';
2553 $dep->{'Version'} = $pkgs->{$_}{'Version'};
2554 $$retdep{$_} = $dep;
2559 # sanity check to make sure the depending binary still exists, and the depended binary exists and dep-wait on a new version of it
2560 if ( defined($merge_binsrc{$pkgname}) and defined($pkgs->{$dep->{'Package'}}{'Version'}) ) {
2561 delete $$retdep{$dep->{'Package'}};
2562 $dep->{'Package'} = $pkgname;
2563 $dep->{'Rel'} = '>>';
2564 $dep->{'Version'} = $pkgs->{$pkgname}{'Version'};
2565 $$retdep{$pkgname} = $dep;
2567 delete $$retdep{$dep->{'Package'}} if (defined ($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>');
2570 $ret = build_deplist($retdep);
2571 $pkgs->{$pkgname}{'Unsatisfied'} = $ret if $savedep;
2579 sub call_edos_depcheck {
2580 my $packagesfile = shift;
2584 return if defined ($conf::distributions{$distribution}{noadw});
2586 # We need to check all of needs-build, as any new upload could make
2587 # something in needs-build have uninstallable deps
2588 # We also check everything in bd-uninstallable, as any new upload could
2589 # make that work again
2590 my %interesting_packages;
2591 foreach $key (keys %db) {
2592 my $pkg = $db{$key};
2593 if (defined $pkg and isin($pkg->{'State'}, qw/Needs-Build BD-Uninstallable/)) {
2594 $interesting_packages{$key} = undef;
2598 #print "I would look at these sources with edos-depcheck:\n";
2599 #print join " ", keys %interesting_packages,"\n";
2601 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2603 for( $i = 0;; ++$i ) {
2604 $tmpfile = $tmpfile_pattern . $i;
2605 last if ! -e $tmpfile;
2608 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2609 for my $key (keys %interesting_packages) {
2610 my $pkg = $db{$key};
2611 print SOURCES "Package: $key\n";
2612 print SOURCES "Version: $pkg->{'Version'}\n";
2613 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2614 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2615 print SOURCES "Architecture: all\n";
2620 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2622 local($/) = ""; # read in paragraph mode
2624 my( $key, $reason ) ;
2626 /^Package:\s*(\S+)$/mi and $key = $1;
2627 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2628 $reason =~ s/^\s*//mg;
2629 $reason ||= 'No reason given by edos-debcheck';
2631 if (exists $interesting_packages{$key}) {
2632 $interesting_packages{$key} = $reason;
2634 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2639 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2640 "all packages have installable build-dependencies."
2645 for my $key (keys %interesting_packages) {
2646 my $pkg = $db{$key};
2648 (defined $interesting_packages{$key} and $pkg->{'State'} eq 'Needs-Build') ||
2649 (not defined $interesting_packages{$key} and $pkg->{'State'} eq 'BD-Uninstallable');
2650 my $problemchange = $interesting_packages{$key} ne $pkg->{'BD-Problem'};
2652 if (defined $interesting_packages{$key}) {
2653 change_state( \$pkg, 'BD-Uninstallable' );
2654 $pkg->{'BD-Problem'} = $interesting_packages{$key};
2656 change_state( \$pkg, 'Needs-Build' );
2659 if ($problemchange) {
2660 if (defined $interesting_packages{$key}) {
2661 $pkg->{'BD-Problem'} = $interesting_packages{$key};
2665 log_ta( $pkg, "--merge-all" );
2666 print "edos-builddebchange changed state of ${key}_$pkg->{'Version'} to $pkg->{'State'}\n" if $verbose;
2668 if ($change || $problemchange) {
2676 ($prgname = $0) =~ s,^.*/,,;
2678 Usage: $prgname <options...> <package_version...>
2680 -v, --verbose: Verbose execution.
2681 --take: Take package for building [default operation]
2682 -f, --failed: Record in database that a build failed due to
2683 deficiencies in the package (that aren't fixable without a new
2685 -u, --uploaded: Record in the database that the packages build
2686 correctly and were uploaded.
2687 -n, --no-build: Record in the database that the packages aren't
2688 desired for this architecture and shouldn't appear in listings even
2689 if they're out of date.
2690 --dep-wait: Record in the database that the packages are waiting
2691 for some source dependencies to become available
2692 --binNMU num: Schedule a re-build of the package with unchanged source, but
2693 a new version number (source-version + "+b<num>")
2694 --give-back: Mark a package as ready to build that is in state Building,
2695 Built or Build-Attempted. To give back a package in state Failed, use
2696 --override. This command will actually put the package in state
2697 BD-Uninstallable, until the installability of its Build-Dependencies
2698 were verified. This happens at each call of --merge-all, usually
2700 --merge-quinn: Merge quinn-diff output into database.
2701 --merge-packages: Merge Packages files into database.
2702 --pretend-avail: Pretend that given packages are available now and give
2703 free packages waiting for them
2704 -i SRC_PKG, --info SRC_PKG: Show information for source package
2705 -l STATE, --list=STATE: List all packages in state STATE; can be
2706 combined with -U to restrict to a specific user; STATE can
2708 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2709 source dependency list
2710 (used with -f, --dep-wait, and --binNMU)
2711 -o, --override: Override another user's lock on a package, i.e.
2712 take it over; a notice mail will be sent to the other user
2713 -U USER, --user=USER: select user name for which listings should
2714 apply, if not given all users are listed.
2715 if -l is missing, set user name to be entered in db; usually
2716 automatically choosen
2717 --import FILE: Import database from a ASCII file FILE
2718 --export FILE: Export database to a ASCII file FILE
2719 --lock-for PID: Locks the database for the process with this pid
2720 --unlock-for PID: Unlocks the database for the process with this pid
2721 --act-on-behalf-of PID: Ignores the lock (if it is held by this pid)
2722 --start-transaction: Creates a copy of the state of the database, for
2723 use with --transactional. This overrides any previous uncommited
2724 transaction. Should only be used after --lock-for
2725 --commit-transaction: Atomically moves the copy back to the main, thus
2726 commiting the changes
2727 --transactional: Flag to indicate that we want to work on the copy
2729 The remaining arguments (depending on operation) usually start with
2730 "name_version", the trailer is ignored. This allows to pass the names
2731 of .dsc files, for which file name completion can be used.
2732 --merge-packages and --merge-quinn take Package/quin--diff file names
2733 on the command line or read stdin. --list needs nothing more on the
2734 command line. --info takes source package names (without version).
2739 sub pkg_version_eq {
2741 my $version = shift;
2744 if (defined $pkg->{'Binary-NMU-Version'}) and
2745 version_compare(binNMU_version($pkg->{'Version'},
2746 $pkg->{'Binary-NMU-Version'}),'=', $version);
2747 return version_compare( $pkg->{'Version'}, "=", $version );