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, $read_only);
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
65 $read_only = 0; # 1 means: do not set or check lock, do never write
67 # map program invocation names to operation modes
68 my %prognames = ( "uploaded-build" => "set-uploaded",
69 "failed-build" => "set-failed",
70 "no-build" => "set-not-for-us",
71 "give-back-build" => "set-needs-build",
72 "dep-wait-build" => "set-dep-wait",
73 "forget-build" => "forget",
74 "merge-quinn" => "merge-quinn",
75 "merge-packages" => "merge-packages",
76 "merge-sources" => "merge-sources",
77 "build-info" => "info" );
79 %short_category = ( u => "uploaded-fixed-pkg",
86 c => "compiler-error",
90 ($progname = $0) =~ s,.*/,,;
91 if ($prognames{$progname}) {
92 $op_mode = $prognames{$progname};
94 elsif ($progname =~ /^list-(.*)$/) {
96 $list_state = ($1 eq "all") ? "" : $1;
101 verbose => { short => "v", flag => \$verbose },
102 override => { short => "o", flag => \$opt_override },
103 "create-db" => { flag => \$opt_create_db },
104 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
105 # TODO: remove after buildds no longer pass to wanna-build
106 "no-propagation" => { short => "N" },
107 "no-down-propagation" => { short => "D" },
109 take => { mode => "set-building" },
110 failed => { short => "f", mode => "set-failed" },
111 uploaded => { short => "u", mode => "set-uploaded" },
112 "no-build" => { short => "n", mode => "set-not-for-us" },
113 built => { mode => "set-built" },
114 attempted => { mode => "set-attempted" },
115 "give-back" => { mode => "set-needs-build" },
116 "dep-wait" => { mode => "set-dep-wait" },
117 forget => { mode => "forget" },
118 'forget-user' => { mode => 'forget-user' },
119 "merge-quinn" => { mode => "merge-quinn" },
120 "merge-partial-quinn" => { mode => "merge-partial-quinn" },
121 "merge-packages" => { mode => "merge-packages" },
122 "merge-sources" => { mode => "merge-sources" },
123 "pretend-avail" => { short => "p", mode => "pretend-avail" },
124 "merge-all" => { mode => "merge-all" },
125 info => { short => "i", mode => "info" },
126 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
127 code => sub { die "Invalid binNMU version: $binNMUver\n"
128 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
129 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
130 code => sub { die "Invalid build priority: $build_priority\n"
131 if $build_priority !~ /^-?[\d]+$/; } },
132 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
133 code => sub { die "Invalid build priority: $build_priority\n"
134 if $build_priority !~ /^-?[\d]+$/; } },
136 { short => "l", mode => "list", arg => \$list_state,
138 die "Unknown state to list: $list_state\n"
139 if !isin( $list_state, qw(needs-build building uploaded
140 built build-attempted failed installed dep-wait
141 not-for-us all failed-removed
142 install-wait reupload-wait bd-uninstallable));} },
145 { short => "d", arg => \$distribution,
147 if ($distribution eq "a" || $distribution eq "all") {
152 $distribution = "oldstable" if $distribution eq "o";
153 $distribution = "stable" if $distribution eq "s";
154 $distribution = "testing" if $distribution eq "t";
155 $distribution = "unstable" if $distribution eq "u";
159 { short => "O", arg => \$list_order,
161 die "Bad ordering character\n"
162 if $list_order !~ /^[PSpsncb]+$/;
164 message => { short => "m", arg => \$fail_reason },
165 database => { short => "b", arg => \$conf::dbbase },
166 arch => { short => "A", arg => \$arch },
167 user => { short => "U", arg => \$user },
168 category => { short => "c", arg => \$category,
170 $category = $short_category{$category}
171 if exists $short_category{$category};
172 die "Unknown category: $category\n"
173 if !isin( $category, values %short_category );
175 "min-age" => { short => "a", arg => \$list_min_age,
177 die "Argument of --min-age must be a non-zero number\n"
178 if $list_min_age == 0;
179 $list_min_age *= 24*60*60;
181 "max-age" => { arg => \$list_min_age,
183 die "Argument of --max-age must be a non-zero number\n"
184 if $list_min_age == 0;
185 $list_min_age *= -24*60*60;
188 import => { arg => \$import_from, mode => "import" },
189 export => { arg => \$export_to, mode => "export" },
190 "lock-for" => { arg => \$lock_for_pid, mode => "lock-for" },
191 "unlock-for" => { arg => \$lock_for_pid, mode => "unlock-for" },
192 "act-on-behalf-of" => { arg => \$lock_for_pid },
193 "start-transaction" => { mode => "start-transaction" },
194 "commit-transaction" => { mode => "commit-transaction" },
195 "transactional" => { flag => \$transactional },
196 "read-only" => { flag => \$read_only },
197 "manual-edit" => { mode => "manual-edit" },
198 "create-maintenance-lock" => { mode => "maintlock-create" },
199 "remove-maintenance-lock" => { mode => "maintlock-remove" },
200 "clean-db" => { mode => "clean-db" },
203 while( @ARGV && $ARGV[0] =~ /^-/ ) {
206 my($opt, $optname, $arg);
207 if (/^--([^=]+)(=|$)/) {
209 $opt = $options{$optname};
210 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
213 $optname = substr( $_, 1, 1 );
214 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
215 $arg = $1 if /^-$optname(.+)$/;
218 warn "Unknown option: --$1\n";
223 die "$optname option missing argument\n" if !@ARGV;
226 ${$opt->{arg}} = $arg;
228 elsif (defined $arg) {
229 die "Option $optname takes no argument\n";
233 die "Conflicting operation modes\n" if $op_mode;
234 $op_mode = $opt->{mode};
244 $op_mode = $category ? "set-failed" : "set-building"
245 if !$op_mode; # default operation
246 $list_order = $list_state eq "failed" ? 'fPcpsn' : 'PScpsn'
247 if !$list_order and $list_state;
248 $distribution ||= "unstable";
249 die "Bad distribution '$distribution'\n"
250 if !isin($distribution, keys %conf::distributions);
253 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
254 $version =~ s/(^\$| \$ .*$)//g;
255 print "wanna-build $version for $distribution on $conf::dbbase\n";
258 if ($read_only && !isin( $op_mode, qw(list export info))) {
259 warn "Invalid operation with --read-only. You can only use --list, --export or --info.\n";
263 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
264 merge-packages manual-edit maintlock-create lock-for unlock-for
265 start-transaction commit-transaction
266 merge-sources maintlock-remove clean-db))) {
267 warn "No packages given.\n";
271 $real_user = (getpwuid($<))[0];
272 die "Can't determine your user name\n"
273 if $op_mode ne "list" && !$user &&
274 !($user = $real_user);
277 if ($op_mode eq "set-failed" && !$category) {
278 print "Enter reason for failing (end with '.' alone on ".
283 last if $line eq ".\n";
284 $fail_reason .= $line;
286 chomp( $fail_reason );
287 } elsif ($op_mode eq "set-dep-wait") {
288 print "Enter dependencies (one line):\n";
290 while( !$line && !eof(STDIN) ) {
291 chomp( $line = <STDIN> );
293 die "No dependencies given\n" if !$line;
294 $fail_reason = $line;
295 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
296 print "Enter changelog entry (one line):\n";
298 while( !$line && !eof(STDIN) ) {
299 chomp( $line = <STDIN> );
301 die "No changelog entry given\n" if !$line;
302 $fail_reason = $line;
305 if ($op_mode eq "maintlock-create") {
309 if ($op_mode eq "maintlock-remove") {
313 waitfor_maintlock() if $op_mode !~ /^(?:merge-|clean-db$)/;
315 if (!-f db_filename( $distribution ) && !$opt_create_db) {
316 if ($transactional) {
317 die "No running transaction for $distribution\n";
319 die "Database for $distribution doesn't exist\n";
323 # Locking for another process means that a longer running process (most likely
324 # wb) wants to do several steps at once, and manages the locks.
325 if ($op_mode eq "lock-for") {
326 lock_db( $distribution );
329 if ($op_mode eq "unlock-for") {
330 unlock_db( $distribution );
335 lock_db( $distribution );
338 if ($op_mode eq "start-transaction") {
339 copy ( db_filename_master( $distribution ), db_filename_transaction( $distribution ))
340 or die "Copy failed: $!";
341 open LOG, ">", db_transactlog_transaction( $distribution )
342 or die "Could not create logfile for transaction: $!";
347 if ($op_mode eq "commit-transaction") {
348 # we need to copy here to preserve the owner and group of the file
349 copy ( db_filename_transaction( $distribution ), db_filename_master( $distribution ))
350 or die "Copy failed: $!";
351 unlink db_filename_transaction( $distribution );
352 open TLOG, "<", db_transactlog_transaction( $distribution )
353 or die "Could not open logfile from transaction: $!";
354 open LOG, ">>", db_transactlog_master( $distribution )
355 or die "Could not open logfile: $!";
356 while (<TLOG>) { print LOG $_ };
359 unlink db_transactlog_transaction( $distribution );
366 if ($lock_for_pid == -1) {
367 unlock_db( $distribution );
369 foreach (keys %conf::distributions) {
370 untie %{$otherdb{$_}} if tied(%{$otherdb{$_}});
371 unlock_db( $_ ) if $otherdb_lock{$_};
376 tie %db, 'MLDBM', db_filename( $distribution ), $read_only ? GDBM_READER : GDBM_WRCREAT, 0664
377 or die "FATAL: Cannot open database\n";
381 if ($mail_logs && $conf::log_mail) {
382 send_mail( $conf::log_mail,
383 "wanna-build $distribution state changes $curr_date",
384 "State changes at $curr_date for distribution ".
385 "$distribution:\n\n$mail_logs\n" );
393 SWITCH: foreach ($op_mode) {
395 add_packages( $1, @ARGV );
399 list_packages( $list_state );
403 info_packages( @ARGV );
406 /^forget-user/ && 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));
410 forget_users( @ARGV );
414 forget_packages( @ARGV );
417 /^merge-partial-quinn/ && do {
418 die "This operation is restricted to admin users\n"
419 if (defined @conf::admin_users and
420 !isin( $real_user, @conf::admin_users));
424 /^merge-quinn/ && do {
425 die "This operation is restricted to admin users\n"
426 if (defined @conf::admin_users and
427 !isin( $real_user, @conf::admin_users));
431 /^merge-packages/ && do {
432 die "This operation is restricted to admin users\n"
433 if (defined @conf::admin_users and
434 !isin( $real_user, @conf::admin_users));
438 /^merge-sources/ && do {
439 die "This operation is restricted to admin users\n"
440 if (defined @conf::admin_users and
441 !isin( $real_user, @conf::admin_users));
445 /^pretend-avail/ && do {
446 pretend_avail( @ARGV );
450 die "This operation is restricted to admin users\n"
451 if (defined @conf::admin_users and
452 !isin( $real_user, @conf::admin_users));
454 @ARGV = ( $ARGS[0] );
455 my $pkgs = parse_packages();
456 @ARGV = ( $ARGS[1] );
458 @ARGV = ( $ARGS[2] );
459 my $srcs = parse_sources(1);
460 call_edos_depcheck( $ARGS[0], $srcs );
465 die "This operation is restricted to admin users\n"
466 if (defined @conf::admin_users and
467 !isin( $real_user, @conf::admin_users));
468 %db = (); # clear all current contents
469 read_db( $import_from );
473 write_db( $export_to );
476 /^manual-edit/ && do {
477 die "This operation is restricted to admin users\n"
478 if (defined @conf::admin_users and
479 !isin( $real_user, @conf::admin_users));
480 my $tmpfile_pattern = "/tmp/wanna-build-$distribution.$$-";
482 for( $i = 0;; ++$i ) {
483 $tmpfile = $tmpfile_pattern . $i;
484 last if ! -e $tmpfile;
486 write_db( $tmpfile );
487 my $editor = $ENV{'VISUAL'} ||
488 "/usr/bin/sensible-editor";
489 system "$editor $tmpfile";
490 %db = (); # clear all current contents
496 die "This operation is restricted to admin users\n"
497 if (defined @conf::admin_users and
498 !isin( $real_user, @conf::admin_users));
503 die "Unexpected operation mode $op_mode\n";
505 if (not -t and $user =~ /-/) {
506 my $userinfo = $db{'_userinfo'};
507 $userinfo = {} if (!defined($userinfo));
509 my $ui = $userinfo->{$user};
510 $ui = {} if (!defined($ui));
512 $ui->{'Last-Seen'} = $curr_date;
513 $ui->{'User'} = $user;
515 $userinfo->{$user} = $ui;
516 $db{'_userinfo'} = $userinfo;
521 my $newstate = shift;
522 my( $package, $name, $version, $ok, $reason );
524 foreach $package (@_) {
525 $package =~ s,^.*/,,; # strip path
526 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
527 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
528 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
529 ($name,$version) = ($1,$2);
532 warn "$package: can't extract package name and version ".
537 if ($op_mode eq "set-building") {
538 add_one_building( $name, $version );
540 elsif ($op_mode eq "set-built") {
541 add_one_built( $name, $version );
543 elsif ($op_mode eq "set-attempted") {
544 add_one_attempted( $name, $version );
546 elsif ($op_mode eq "set-uploaded") {
547 add_one_uploaded( $name, $version );
549 elsif ($op_mode eq "set-failed") {
550 add_one_failed( $name, $version );
552 elsif ($op_mode eq "set-not-for-us") {
553 add_one_notforus( $name, $version );
555 elsif ($op_mode eq "set-needs-build") {
556 add_one_needsbuild( $name, $version );
558 elsif ($op_mode eq "set-dep-wait") {
559 add_one_depwait( $name, $version );
561 elsif ($op_mode eq "set-build-priority") {
562 set_one_buildpri( $name, $version, 'BuildPri' );
564 elsif ($op_mode eq "set-permanent-build-priority") {
565 set_one_buildpri( $name, $version, 'PermBuildPri' );
567 elsif ($op_mode eq "set-binary-nmu") {
568 set_one_binnmu( $name, $version );
573 sub add_one_building {
579 my $pkg = $db{$name};
581 if ($pkg->{'State'} eq "Not-For-Us") {
583 $reason = "not suitable for this architecture";
585 elsif ($pkg->{'State'} =~ /^Dep-Wait/) {
587 $reason = "not all source dependencies available yet";
589 elsif ($pkg->{'State'} =~ /^BD-Uninstallable/) {
591 $reason = "source dependencies are not installable";
593 elsif ($pkg->{'State'} eq "Uploaded" &&
594 (version_lesseq($version, $pkg->{'Version'}))) {
596 $reason = "already uploaded by $pkg->{'Builder'}";
597 $reason .= " (in newer version $pkg->{'Version'})"
598 if !version_eq($pkg, $version);
600 elsif ($pkg->{'State'} eq "Installed" &&
601 version_less($version,$pkg->{'Version'})) {
603 print "$name: Warning: newer version $pkg->{'Version'} ".
604 "already installed, but overridden.\n";
608 $reason = "newer version $pkg->{'Version'} already in ".
609 "archive; doesn't need rebuilding";
610 print "$name: Note: If the following is due to an epoch ",
611 " change, use --override\n";
614 elsif ($pkg->{'State'} eq "Installed" &&
615 pkg_version_eq($pkg,$version)) {
617 $reason = "is up-to-date in the archive; doesn't need rebuilding";
619 elsif ($pkg->{'State'} eq "Needs-Build" &&
620 version_less($version,$pkg->{'Version'})) {
622 print "$name: Warning: newer version $pkg->{'Version'} ".
623 "needs building, but overridden.";
627 $reason = "newer version $pkg->{'Version'} needs building, ".
631 elsif (isin($pkg->{'State'},qw(Building Built Build-Attempted))) {
632 if (version_less($pkg->{'Version'},$version)) {
633 print "$name: Warning: Older version $pkg->{'Version'} ",
634 "is being built by $pkg->{'Builder'}\n";
635 if ($pkg->{'Builder'} ne $user) {
636 send_mail( $pkg->{'Builder'},
637 "package takeover in newer version",
638 "You are building package '$name' in ".
639 "version $version\n".
640 "(as far as I'm informed).\n".
641 "$user now has taken the newer ".
642 "version $version for building.".
643 "You can abort the build if you like.\n" );
648 print "User $pkg->{'Builder'} had already ",
649 "taken the following package,\n",
650 "but overriding this as you request:\n";
651 send_mail( $pkg->{'Builder'}, "package takeover",
652 "The package '$name' (version $version) that ".
653 "was locked by you\n".
654 "has been taken over by $user\n" );
656 elsif ($pkg->{'Builder'} eq $user) {
657 print "$name: Note: already taken by you.\n";
658 print "$name: ok\n" if $verbose;
663 $reason = "already taken by $pkg->{'Builder'}";
664 $reason .= " (in newer version $pkg->{'Version'})"
665 if !version_eq($pkg->{'Version'}, $version);
669 elsif ($pkg->{'State'} =~ /^Failed/ &&
670 pkg_version_eq($pkg, $version)) {
672 print "The following package previously failed ",
673 "(by $pkg->{'Builder'})\n",
674 "but overriding this as you request:\n";
675 send_mail( $pkg->{'Builder'}, "failed package takeover",
676 "The package '$name' (version $version) that ".
677 "is locked by you\n".
678 "and has failed previously has been taken over ".
680 if $pkg->{'Builder'} ne $user;
684 $reason = "build of $version failed previously:\n ";
685 $reason .= join( "\n ", split( "\n", $pkg->{'Failed'} ));
686 $reason .= "\nalso the package doesn't need builing"
687 if $pkg->{'State'} eq 'Failed-Removed';
693 if ($pkg->{'Binary-NMU-Version'}) {
694 print "$name: Warning: needs binary NMU $pkg->{'Binary-NMU-Version'}\n" .
695 "$pkg->{'Binary-NMU-Changelog'}\n";
698 print "$name: Warning: Previous version failed!\n"
699 if $pkg->{'Previous-State'} =~ /^Failed/ ||
700 $pkg->{'State'} =~ /^Failed/;
702 change_state( \$pkg, 'Building' );
703 $pkg->{'Package'} = $name;
704 $pkg->{'Version'} = $version;
705 $pkg->{'Builder'} = $user;
706 log_ta( $pkg, "--take" );
708 print "$name: $ok\n" if $verbose;
711 print "$name: NOT OK!\n $reason\n";
715 sub add_one_attempted {
718 my $pkg = $db{$name};
720 if (!defined($pkg)) {
721 print "$name: not registered yet.\n";
725 if ($pkg->{'State'} ne "Building" ) {
726 print "$name: not taken for building (state is $pkg->{'State'}). ",
730 if ($pkg->{'Builder'} ne $user) {
731 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
734 elsif ( !pkg_version_eq($pkg, $version) ) {
735 print "$name: version mismatch ".
736 "$(pkg->{'Version'} ".
737 "by $pkg->{'Builder'})\n";
741 change_state( \$pkg, 'Build-Attempted' );
742 log_ta( $pkg, "--attempted" );
744 print "$name: registered as uploaded\n" if $verbose;
750 my $pkg = $db{$name};
752 if (!defined($pkg)) {
753 print "$name: not registered yet.\n";
757 if ($pkg->{'State'} ne "Building" ) {
758 print "$name: not taken for building (state is $pkg->{'State'}). ",
762 if ($pkg->{'Builder'} ne $user) {
763 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
766 elsif ( !pkg_version_eq($pkg, $version) ) {
767 print "$name: version mismatch ".
768 "$(pkg->{'Version'} ".
769 "by $pkg->{'Builder'})\n";
772 change_state( \$pkg, 'Built' );
773 log_ta( $pkg, "--built" );
775 print "$name: registered as built\n" if $verbose;
778 sub add_one_uploaded {
781 my $pkg = $db{$name};
783 if (!defined($pkg)) {
784 print "$name: not registered yet.\n";
788 if ($pkg->{'State'} eq "Uploaded" &&
789 pkg_version_eq($pkg,$version)) {
790 print "$name: already uploaded\n";
793 if (!isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
794 print "$name: not taken for building (state is $pkg->{'State'}). ",
798 if ($pkg->{'Builder'} ne $user) {
799 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
802 # strip epoch -- buildd-uploader used to go based on the filename.
803 # (to remove at some point)
805 ($pkgver = $pkg->{'Version'}) =~ s/^\d+://;
806 $version =~ s/^\d+://; # for command line use
807 if ($pkg->{'Binary-NMU-Version'} ) {
808 my $nmuver = binNMU_version($pkgver, $pkg->{'Binary-NMU-Version'});
809 if (!version_eq( $nmuver, $version )) {
810 print "$name: version mismatch ($nmuver registered). ",
814 } elsif (!version_eq($pkgver, $version)) {
815 print "$name: version mismatch ($pkg->{'Version'} registered). ",
820 change_state( \$pkg, 'Uploaded' );
821 log_ta( $pkg, "--uploaded" );
823 print "$name: registered as uploaded\n" if $verbose;
830 my $pkg = $db{$name};
832 if (!defined($pkg)) {
833 print "$name: not registered yet.\n";
836 $state = $pkg->{'State'};
838 if ($state eq "Not-For-Us") {
839 print "$name: not suitable for this architecture anyway. Skipping.\n";
842 elsif ($state eq "Failed-Removed") {
843 print "$name: failed previously and doesn't need building. Skipping.\n";
846 elsif ($state eq "Installed") {
847 print "$name: Is already installed in archive. Skipping.\n";
850 elsif ($pkg->{'Builder'} &&
851 (($user ne $pkg->{'Builder'}) &&
852 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
853 print "$name: not taken by you, but by ".
854 "$pkg->{'Builder'}. Skipping.\n";
857 elsif ( !pkg_version_eq($pkg, $version) ) {
858 print "$name: version mismatch ".
859 "$(pkg->{'Version'} ".
860 "by $pkg->{'Builder'})\n";
865 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
867 $cat = $short_category{$cat} if exists $short_category{$cat};
868 if (!isin( $cat, values %short_category )) {
869 print "$name: Warning: unknown category $cat; discarded\n";
872 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
875 if ($state eq "Needs-Build") {
876 print "$name: Warning: not registered for building previously, ".
877 "but processing anyway.\n";
879 elsif ($state eq "Uploaded") {
880 print "$name: Warning: marked as uploaded previously, ".
881 "but processing anyway.\n";
883 elsif ($state eq "Dep-Wait") {
884 print "$name: Warning: marked as waiting for dependencies, ".
885 "but processing anyway.\n";
887 elsif ($state eq "BD-Uninstallable") {
888 print "$name: Warning: marked as having uninstallable build-dependencies, ".
889 "but processing anyway.\n";
891 elsif ($state eq "Failed") {
892 print "$name: already registered as failed; will append new message\n"
894 print "$name: already registered as failed; changing category\n"
898 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
899 exists $pkg->{'Failed-Category'} &&
900 $pkg->{'Failed-Category'} ne $cat) {
901 (my $action = $cat) =~ s/-/ /;
902 $fail_reason .= "\n$short_date: $action";
905 change_state( \$pkg, 'Failed' );
906 $pkg->{'Builder'} = $user;
907 $pkg->{'Failed'} .= "\n" if $pkg->{'Failed'};
908 $pkg->{'Failed'} .= $fail_reason;
909 $pkg->{'Failed-Category'} = $cat if $cat;
910 if (defined $pkg->{'PermBuildPri'}) {
911 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
913 delete $pkg->{'BuildPri'};
915 log_ta( $pkg, "--failed" );
917 print "$name: registered as failed\n" if $verbose;
920 sub add_one_notforus {
923 my $pkg = $db{$name};
925 if ($pkg->{'State'} eq 'Not-For-Us') {
926 # reset Not-For-Us state in case it's called twice; this is
927 # the only way to get a package out of this state...
928 # There is no really good state in which such packages should
929 # be put :-( So use Failed for now.
930 change_state( \$pkg, 'Failed' );
931 $pkg->{'Package'} = $name;
932 $pkg->{'Failed'} = "Was Not-For-Us previously";
933 delete $pkg->{'Builder'};
934 delete $pkg->{'Depends'};
935 log_ta( $pkg, "--no-build(rev)" );
936 print "$name: now not unsuitable anymore\n";
938 send_mail( $conf::notforus_maint,
939 "$name moved out of Not-For-Us state",
940 "The package '$name' has been moved out of the Not-For-Us ".
942 "It should probably also be removed from ".
943 "Packages-arch-specific or\n".
944 "the action was wrong.\n" )
945 if $conf::notforus_maint;
948 change_state( \$pkg, 'Not-For-Us' );
949 $pkg->{'Package'} = $name;
950 delete $pkg->{'Builder'};
951 delete $pkg->{'Depends'};
952 delete $pkg->{'BuildPri'};
953 delete $pkg->{'Binary-NMU-Version'};
954 delete $pkg->{'Binary-NMU-Changelog'};
955 log_ta( $pkg, "--no-build" );
956 print "$name: registered as unsuitable\n" if $verbose;
958 send_mail( $conf::notforus_maint,
959 "$name set to Not-For-Us",
960 "The package '$name' has been set to state Not-For-Us ".
962 "It should probably also be added to ".
963 "Packages-arch-specific or\n".
964 "the Not-For-Us state is wrong.\n" )
965 if $conf::notforus_maint;
970 sub add_one_needsbuild {
974 my $pkg = $db{$name};
976 if (!defined($pkg)) {
977 print "$name: not registered; can't give back.\n";
980 $state = $pkg->{'State'};
982 if ($state eq "BD-Uninstallable") {
984 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
986 change_state( \$pkg, 'Needs-Build' );
987 delete $pkg->{'Builder'};
988 delete $pkg->{'Depends'};
989 log_ta( $pkg, "--give-back" );
991 print "$name: given back\n" if $verbose;
995 print "$name: has uninstallable build-dependencies. Skipping\n",
996 " (use --override to clear dependency list and ",
997 "give back anyway)\n";
1001 elsif ($state eq "Dep-Wait") {
1002 if ($opt_override) {
1003 print "$name: Forcing source dependency list to be cleared\n";
1006 print "$name: waiting for source dependencies. Skipping\n",
1007 " (use --override to clear dependency list and ",
1008 "give back anyway)\n";
1012 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1013 print "$name: not taken for building (state is $state).";
1014 if ($opt_override) {
1015 print "\n$name: Forcing give-back\n";
1018 print " Skipping.\n";
1022 if (defined ($pkg->{'Builder'}) && $user ne $pkg->{'Builder'} &&
1023 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user)) {
1024 print "$name: not taken by you, but by ".
1025 "$pkg->{'Builder'}. Skipping.\n";
1028 if (!pkg_version_eq($pkg, $version)) {
1029 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1033 if ($distribution eq "unstable") {
1034 change_state( \$pkg, 'BD-Uninstallable' );
1035 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1037 change_state( \$pkg, 'Needs-Build' );
1039 delete $pkg->{'Builder'};
1040 delete $pkg->{'Depends'};
1041 log_ta( $pkg, "--give-back" );
1043 print "$name: given back\n" if $verbose;
1046 sub set_one_binnmu {
1048 my $version = shift;
1049 my $pkg = $db{$name};
1052 if (!defined($pkg)) {
1053 print "$name: not registered; can't register for binNMU.\n";
1056 my $db_ver = $pkg->{'Version'};
1058 if (!version_eq($db_ver, $version)) {
1059 print "$name: version mismatch ($db_ver registered). ",
1063 $state = $pkg->{'State'};
1065 if (defined $pkg->{'Binary-NMU-Version'}) {
1066 if ($binNMUver == 0) {
1067 change_state( \$pkg, 'Installed' );
1068 delete $pkg->{'Builder'};
1069 delete $pkg->{'Depends'};
1070 delete $pkg->{'Binary-NMU-Version'};
1071 delete $pkg->{'Binary-NMU-Changelog'};
1072 } elsif ($binNMUver <= $pkg->{'Binary-NMU-Version'}) {
1073 print "$name: already building binNMU $pkg->{'Binary-NMU-Version'}\n";
1076 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1077 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1078 $pkg->{'Notes'} = 'out-of-date';
1079 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'}
1080 if (defined $pkg->{'PermBuildPri'});
1082 log_ta( $pkg, "--binNMU" );
1085 } elsif ($binNMUver == 0) {
1086 print "${name}_$version: no scheduled binNMU to cancel.\n";
1090 if ($state ne 'Installed') {
1091 print "${name}_$version: not installed; can't register for binNMU.\n";
1095 my $fullver = binNMU_version($version,$binNMUver);
1096 if ( version_lesseq( $fullver, $pkg->{'Installed-Version'} ) )
1098 print "$name: binNMU $fullver is not newer than current version $pkg->{'Installed-Version'}\n";
1102 change_state( \$pkg, 'BD-Uninstallable' );
1103 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1104 delete $pkg->{'Builder'};
1105 delete $pkg->{'Depends'};
1106 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1107 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1108 $pkg->{'Notes'} = 'out-of-date';
1109 log_ta( $pkg, "--binNMU" );
1111 print "${name}: registered for binNMU $fullver\n" if $verbose;
1114 sub set_one_buildpri {
1116 my $version = shift;
1118 my $pkg = $db{$name};
1121 if (!defined($pkg)) {
1122 print "$name: not registered; can't set priority.\n";
1125 $state = $pkg->{'State'};
1127 if ($state eq "Not-For-Us") {
1128 print "$name: not suitable for this architecture. Skipping.\n";
1130 } elsif ($state eq "Failed-Removed") {
1131 print "$name: failed previously and doesn't need building. Skipping.\n";
1134 if (!pkg_version_eq($pkg, $version)) {
1135 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1139 if ( $build_priority == 0 ) {
1140 delete $pkg->{'BuildPri'}
1141 if $key eq 'PermBuildPri' and defined $pkg->{'BuildPri'}
1142 and $pkg->{'BuildPri'} == $pkg->{$key};
1143 delete $pkg->{$key};
1145 $pkg->{'BuildPri'} = $build_priority
1146 if $key eq 'PermBuildPri';
1147 $pkg->{$key} = $build_priority;
1150 print "$name: set to build priority $build_priority\n" if $verbose;
1153 sub add_one_depwait {
1155 my $version = shift;
1157 my $pkg = $db{$name};
1159 if (!defined($pkg)) {
1160 print "$name: not registered yet.\n";
1163 $state = $pkg->{'State'};
1165 if ($state eq "Dep-Wait") {
1166 print "$name: merging with previously registered dependencies\n";
1169 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1170 print "$name: Warning: not registered for building previously, ".
1171 "but processing anyway.\n";
1173 elsif ($state eq "Not-For-Us") {
1174 print "$name: not suitable for this architecture anyway. Skipping.\n";
1177 elsif ($state eq "Failed-Removed") {
1178 print "$name: failed previously and doesn't need building. Skipping.\n";
1181 elsif ($state eq "Installed") {
1182 print "$name: Is already installed in archive. Skipping.\n";
1185 elsif ($state eq "Uploaded") {
1186 print "$name: Is already uploaded. Skipping.\n";
1189 elsif ($pkg->{'Builder'} &&
1190 $user ne $pkg->{'Builder'}) {
1191 print "$name: not taken by you, but by ".
1192 "$pkg->{'Builder'}. Skipping.\n";
1195 elsif ( !pkg_version_eq($pkg,$version)) {
1196 print "$name: version mismatch ".
1197 "($pkg->{'Version'} ".
1198 "by $pkg->{'Builder'})\n";
1201 elsif ($fail_reason =~ /^\s*$/ ||
1202 !parse_deplist( $fail_reason, 1 )) {
1203 print "$name: Bad dependency list\n";
1206 change_state( \$pkg, 'Dep-Wait' );
1207 $pkg->{'Builder'} = $user;
1208 if (defined $pkg->{'PermBuildPri'}) {
1209 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1211 delete $pkg->{'BuildPri'};
1213 my $deplist = parse_deplist( $pkg->{'Depends'} );
1214 my $new_deplist = parse_deplist( $fail_reason );
1215 # add new dependencies, maybe overwriting old entries
1216 foreach (keys %$new_deplist) {
1217 $deplist->{$_} = $new_deplist->{$_};
1219 $pkg->{'Depends'} = build_deplist($deplist);
1220 log_ta( $pkg, "--dep-wait" );
1222 print "$name: registered as waiting for dependencies\n" if $verbose;
1232 local($/) = ""; # read in paragraph mode
1234 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1236 /^Package:\s*(\S+)$/mi and $name = $1;
1237 /^Version:\s*(\S+)$/mi and $version = $1;
1238 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1239 /^Section:\s*(\S+)$/mi and $section = $1;
1240 /^Priority:\s*(\S+)$/mi and $priority = $1;
1241 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1242 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1243 /^Binary:\s*(.*)$/mi and $binaries = $1;
1245 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1246 $srcver{$name} = $version;
1248 $pkgs{$name}{'ver'} = $version;
1249 $pkgs{$name}{'bin'} = $binaries;
1250 $pkgs{$name}{'dep'} = $builddep;
1251 $pkgs{$name}{'conf'} = $buildconf;
1252 my $pkg = $db{$name};
1257 if ($arch eq "all" && !version_less( $version, $pkg->{'Version'} )) {
1258 # package is now Arch: all, delete it from db
1259 change_state( \$pkg, 'deleted' );
1260 log_ta( $pkg, "--merge-sources" );
1261 print "$name ($pkg->{'Version'}): deleted ".
1262 "from database, because now Arch: all\n"
1268 # The "Version" should always be the source version --
1269 # not a possible binNMU version number.
1270 $pkg->{'Version'} = $version, $change++
1271 if ($pkg->{'State'} eq 'Installed' and
1272 !version_eq( $pkg->{'Version'}, $version));
1273 # Always update priority and section, if available
1274 $pkg->{'Priority'} = $priority, $change++
1275 if defined $priority and (not defined($pkg->{'Priority'}) or $pkg->{'Priority'} ne $priority);
1277 $pkg->{'Section'} = $section, $change++
1278 if defined $section and (not defined($pkg->{'Section'}) or $pkg->{'Section'} ne $section);
1280 # Remove field from previous wanna-build versions
1281 for (qw/Reason Build-Depends Build-Conflicts/) {
1282 if (exists $pkg->{$_}) {
1288 $db{$name} = $pkg if $change;
1291 # Now that we only have the latest source version, build the list
1292 # of binary packages from the Sources point of view
1293 foreach $name (keys %pkgs) {
1294 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1295 $merge_binsrc{$bin} = $name;
1298 # remove installed packages that no longer have source available
1299 # or binaries installed
1300 foreach $name (keys %db) {
1301 next if $name =~ /^_/;
1302 my $pkg = $db{$name};
1303 if (not defined($pkgs{$name})) {
1304 change_state( \$pkg, 'deleted' );
1305 log_ta( $pkg, "--merge-sources" );
1306 print "$name ($pkg->{'Version'}): ".
1307 "deleted from database, because ".
1308 "not in Sources anymore\n"
1312 next if !isin( $pkg->{'State'}, qw(Installed) );
1313 if ($full && not defined $merge_srcvers{$name}) {
1314 change_state( \$pkg, 'deleted' );
1315 log_ta( $pkg, "--merge-sources" );
1316 print "$name ($pkg->{'Version'}): ".
1317 "deleted from database, because ".
1318 "binaries don't exist anymore\n"
1321 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'Version'})) {
1322 print "$name ($pkg->{'Version'}): ".
1323 "package is Installed but binaries are from ".
1324 $merge_srcvers{$name}. "\n"
1332 # This function looks through a Packages file and sets the state of
1333 # packages to 'Installed'
1334 sub parse_packages {
1337 local($/) = ""; # read in paragraph mode
1339 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1341 /^Package:\s*(\S+)$/mi and $name = $1;
1342 /^Version:\s*(\S+)$/mi and $version = $1;
1343 /^Depends:\s*(.*)$/mi and $depends = $1;
1344 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1345 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1346 /^Provides:\s*(.*)$/mi and $provides = $1;
1347 next if !$name || !$version;
1348 next if ($arch ne $architecture and $architecture ne "all");
1349 next if (defined ($installed->{$name}) and $installed->{$name}{'Version'} ne "" and
1350 version_lesseq( $version, $installed->{$name}{'Version'} ));
1351 $installed->{$name}{'Version'} = $version;
1352 $installed->{$name}{'Depends'} = $depends;
1353 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1354 undef $installed->{$name}{'Provider'};
1355 $installed->{$name}{'Source'} = $source ? $source : $name;
1357 foreach (split( /\s*,\s*/, $provides )) {
1358 if (not defined ($installed->{$_})) {
1359 $installed->{$_}{'Version'} = "";
1360 $installed->{$_}{'Provider'} = $name;
1364 if ( $version =~ /\+b(\d+)$/ ) {
1367 $version = $sourcev if $sourcev;
1368 $binaryv = $version;
1369 $binaryv =~ s/\+b\d+$//;
1370 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1371 $binaryv .= "+b$binnmu" if defined($binnmu);
1373 next if $architecture ne $arch;
1374 $name = $source if $source;
1375 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1376 $merge_srcvers{$name} = $version;
1378 my $pkg = $db{$name};
1381 if (isin( $pkg->{'State'}, qw(Not-For-Us)) ||
1382 (isin($pkg->{'State'}, qw(Installed)) &&
1383 version_lesseq($binaryv, $pkg->{'Installed-Version'}))) {
1384 print "Skipping $name because State == $pkg->{'State'}\n"
1388 if ($pkg->{'Binary-NMU-Version'} ) {
1389 my $nmuver = binNMU_version($pkg->{'Version'}, $pkg->{'Binary-NMU-Version'});
1390 if (version_less( $binaryv, $nmuver )) {
1391 print "Skipping $name ($version) because have newer ".
1392 "version ($nmuver) in db.\n"
1396 } elsif (version_less($version, $pkg->{'Version'})) {
1397 print "Skipping $name ($version) because have newer ".
1398 "version ($pkg->{'Version'}) in db.\n"
1403 if (!pkg_version_eq($pkg, $version) &&
1404 $pkg->{'State'} ne "Installed") {
1405 warn "Warning: $name: newer version than expected appeared ".
1406 "in archive ($version vs. $pkg->{'Version'})\n";
1407 delete $pkg->{'Builder'};
1410 if (!isin( $pkg->{'State'}, qw(Uploaded) )) {
1411 warn "Warning: Package $name was not in uploaded state ".
1412 "before (but in '$pkg->{'State'}').\n";
1413 delete $pkg->{'Builder'};
1414 delete $pkg->{'Depends'};
1418 $pkg->{'Version'} = $version;
1421 change_state( \$pkg, 'Installed' );
1422 $pkg->{'Package'} = $name;
1423 $pkg->{'Installed-Version'} = $binaryv;
1424 if (defined $pkg->{'PermBuildPri'}) {
1425 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1427 delete $pkg->{'BuildPri'};
1429 $pkg->{'Version'} = $version
1430 if version_less( $pkg->{'Version'}, $version);
1431 delete $pkg->{'Binary-NMU-Version'};
1432 delete $pkg->{'Binary-NMU-Changelog'};
1433 log_ta( $pkg, "--merge-packages" );
1435 print "$name ($version) is up-to-date now.\n" if $verbose;
1438 check_dep_wait( "--merge-packages", $installed );
1443 my ($package, $name, $version, $installed);
1445 foreach $package (@_) {
1446 $package =~ s,^.*/,,; # strip path
1447 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1448 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1449 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1450 ($name,$version) = ($1,$2);
1453 warn "$package: can't extract package name and version ".
1457 $installed->{$name}{'Version'} = $version;
1460 check_dep_wait( "--pretend-avail", $installed );
1463 sub check_dep_wait {
1465 my $installed = shift;
1467 # check all packages in state Dep-Wait if dependencies are all
1470 foreach $name (keys %db) {
1471 next if $name =~ /^_/;
1472 my $pkg = $db{$name};
1473 next if $pkg->{'State'} ne "Dep-Wait";
1474 my $deps = $pkg->{'Depends'};
1476 print "$name: was in state Dep-Wait, but with empty ",
1478 goto make_needs_build;
1480 my $deplist = parse_deplist($deps);
1484 foreach (keys %$deplist) {
1485 if (!exists $installed->{$_} ||
1486 ($deplist->{$_}->{'Rel'} && $deplist->{$_}->{'Version'} &&
1487 !version_compare( $installed->{$_}{'Version'},
1488 $deplist->{$_}->{'Rel'},
1489 $deplist->{$_}->{'Version'}))) {
1491 $new_deplist->{$_} = $deplist->{$_};
1494 push( @removed_deps, $_ );
1499 change_state( \$pkg, 'Needs-Build' );
1500 log_ta( $pkg, $action );
1501 delete $pkg->{'Builder'};
1502 delete $pkg->{'Depends'};
1503 print "$name ($pkg->{'Version'}) has all ",
1504 "dependencies available now\n" if $verbose;
1508 elsif (@removed_deps) {
1509 $pkg->{'Depends'} = build_deplist( $new_deplist );
1510 print "$name ($pkg->{'Version'}): some dependencies ",
1511 "(@removed_deps) available now, but not all yet\n"
1518 # This function accepts quinn-diff output (either from a file named on
1519 # the command line, or on stdin) and sets the packages named there to
1520 # state 'Needs-Build'.
1521 sub parse_quinn_diff {
1522 my $partial = shift;
1528 next if !m,^([-\w\d/]*)/ # section
1529 ([-\w\d.+]+)_ # package name
1530 ([\w\d:.~+-]+)\.dsc\s* # version
1531 \[([^:]*): # priority
1532 ([^]]+)\]\s*$,x; # rest of notes
1533 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1534 $quinn_pkgs{$name}++;
1535 $section ||= "unknown";
1536 $priority ||= "unknown";
1537 $priority = "unknown" if $priority eq "-";
1538 $priority = "standard" if ($name eq "debian-installer");
1540 my $pkg = $db{$name};
1542 # Always update section and priority.
1543 if (defined($pkg)) {
1545 $pkg->{'Section'} = $section, $change++ if not defined
1546 $pkg->{'Section'} or $section ne "unknown";
1547 $pkg->{'Priority'} = $priority, $change++ if not defined
1548 $pkg->{'Priority'} or $priority ne "unknown";
1551 if (defined($pkg) &&
1552 $pkg->{'State'} =~ /^Dep-Wait/ &&
1553 version_less( $pkg->{'Version'}, $version )) {
1554 change_state( \$pkg, 'Dep-Wait' );
1555 $pkg->{'Version'} = $version;
1556 delete $pkg->{'Binary-NMU-Version'};
1557 delete $pkg->{'Binary-NMU-Changelog'};
1558 log_ta( $pkg, "--merge-quinn" );
1560 print "$name ($version) still waiting for dependencies.\n"
1563 elsif (defined($pkg) &&
1564 $pkg->{'State'} =~ /-Removed$/ &&
1565 version_eq($pkg->{'Version'}, $version)) {
1566 # reinstantiate a package that has been removed earlier
1567 # (probably due to a quinn-diff malfunction...)
1568 my $newstate = $pkg->{'State'};
1569 $newstate =~ s/-Removed$//;
1570 change_state( \$pkg, $newstate );
1571 $pkg->{'Version'} = $version;
1572 $pkg->{'Notes'} = $notes;
1573 log_ta( $pkg, "--merge-quinn" );
1575 print "$name ($version) reinstantiated to $newstate.\n"
1578 elsif (defined($pkg) &&
1579 $pkg->{'State'} eq "Not-For-Us" &&
1580 version_less( $pkg->{'Version'}, $version )) {
1581 # for Not-For-Us packages just update the version etc., but
1583 change_state( \$pkg, "Not-For-Us" );
1584 $pkg->{'Package'} = $name;
1585 $pkg->{'Version'} = $version;
1586 $pkg->{'Notes'} = $notes;
1587 delete $pkg->{'Builder'};
1588 log_ta( $pkg, "--merge-quinn" );
1590 print "$name ($version) still Not-For-Us.\n" if $verbose;
1592 elsif (!defined($pkg) ||
1593 $pkg->{'State'} ne "Not-For-Us" &&
1594 (version_less( $pkg->{'Version'}, $version ) ||
1595 ($pkg->{'State'} eq "Installed" && version_less($pkg->{'Installed-Version'}, $version)))) {
1597 if (defined( $pkg->{'State'} ) && isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
1598 send_mail( $pkg->{'Builder'},
1599 "new version of $name (dist=$distribution)",
1600 "As far as I'm informed, you're currently ".
1601 "building the package $name\n".
1602 "in version $pkg->{'Version'}.\n\n".
1603 "Now there's a new source version $version. ".
1604 "If you haven't finished\n".
1605 "compiling $name yet, you can stop it to ".
1606 "save some work.\n".
1607 "Just to inform you...\n".
1608 "(This is an automated message)\n" );
1609 print "$name: new version ($version) while building ".
1610 "$pkg->{'Version'} -- sending mail ".
1611 "to builder ($pkg->{'Builder'})\n"
1614 change_state( \$pkg, 'Needs-Build' );
1615 $pkg->{'Package'} = $name;
1616 $pkg->{'Version'} = $version;
1617 $pkg->{'Section'} = $section;
1618 $pkg->{'Priority'} = $priority;
1619 $pkg->{'Notes'} = $notes;
1620 delete $pkg->{'Builder'};
1621 delete $pkg->{'Binary-NMU-Version'};
1622 delete $pkg->{'Binary-NMU-Changelog'};
1623 log_ta( $pkg, "--merge-quinn" );
1626 print "$name ($version) needs rebuilding now.\n" if $verbose;
1628 elsif (defined($pkg) &&
1629 !version_eq( $pkg->{'Version'}, $version ) &&
1630 isin( $pkg->{'State'}, qw(Installed Not-For-Us) )) {
1631 print "$name: skipping because version in db ".
1632 "($pkg->{'Version'}) is >> than ".
1633 "what quinn-diff says ($version) ".
1634 "(state is $pkg->{'State'})\n"
1636 $dubious .= "$pkg->{'State'}: ".
1637 "db ${name}_$pkg->{'Version'} >> ".
1638 "quinn $version\n" if !$partial;
1640 elsif ($verbose >= 2) {
1641 if ($pkg->{'State'} eq "Not-For-Us") {
1642 print "Skipping $name because State == ".
1643 "$pkg->{'State'}\n";
1645 elsif (!version_less($pkg->{'Version'}, $version)) {
1646 print "Skipping $name because version in db ".
1647 "($pkg->{'Version'}) is >= than ".
1648 "what quinn-diff says ($version)\n";
1651 $db{$name} = $pkg if $change;
1655 send_mail( $conf::db_maint,
1656 "Dubious versions in $distribution $conf::dbbase database",
1657 "The following packages have a newer version in the ".
1658 "wanna-build database\n".
1659 "than what quinn-diff says, and this is strange for ".
1661 "It could be caused by a lame mirror, or the version ".
1662 "in the database\n".
1667 # Now re-check the DB for packages in states Needs-Build, Failed,
1668 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1669 # anymore by quinn-diff.
1672 foreach $name (keys %db) {
1673 next if $name =~ /^_/;
1674 my $pkg = $db{$name};
1675 next if defined $pkg->{'Binary-NMU-Version'};
1676 next if !isin( $pkg->{'State'},
1677 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1678 my $virtual_delete = $pkg->{'State'} eq 'Failed';
1680 if (!$quinn_pkgs{$name}) {
1681 change_state( \$pkg, $virtual_delete ?
1682 $pkg->{'State'}."-Removed" :
1684 log_ta( $pkg, "--merge-quinn" );
1685 print "$name ($pkg->{'Version'}): ".
1686 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1687 "from database, because not in quinn-diff anymore\n"
1689 if ($virtual_delete) {
1699 sub send_reupload_mail {
1702 my $version = shift;
1704 my $other_dist = shift;
1707 "Please reupload ${pkg}_${'Version'} for $dist",
1708 "You have recently built (or are currently building)\n".
1709 "${pkg}_${'Version'} for $other_dist.\n".
1710 "This version is now also needed in the $dist distribution.\n".
1711 "Please reupload the files now present in the Debian archive\n".
1712 "(best with buildd-reupload).\n" );
1716 # for sorting priorities and sections
1718 %prioval = ( required => -5,
1726 'debian-installer' => -199,
1747 localizations => -178,
1748 interpreters => -177,
1773 electronics => -152,
1779 foreach my $i (keys %sectval) {
1780 $sectval{"contrib/$i"} = $sectval{$i}+40;
1781 $sectval{"non-free/$i"} = $sectval{$i}+80;
1783 $sectval{'unknown'} = -165;
1785 %catval = ( "none" => -20,
1786 "uploaded-fixed-pkg" => -19,
1787 "fix-expected" => -18,
1788 "reminder-sent" => -17,
1789 "nmu-offered" => -16,
1793 "compiler-error" => -12 );
1796 sub sort_list_func {
1797 my( $letter, $x, $ax, $bx );
1799 foreach $letter (split( "", $list_order )) {
1800 SWITCH: foreach ($letter) {
1802 $x = $b->{'BuildPri'} <=> $a->{'BuildPri'};
1803 return $x if $x != 0;
1807 $x = $prioval{$a->{'Priority'}} <=> $prioval{$b->{'Priority'}};
1808 return $x if $x != 0;
1812 $x = $sectval{$a->{'Section'}} <=> $sectval{$b->{'Section'}};
1813 return $x if $x != 0;
1817 $x = $a->{'Package'} cmp $b->{'Package'};
1818 return $x if $x != 0;
1822 $x = $a->{'Builder'} cmp $b->{'Builder'};
1823 return $x if $x != 0;
1827 $ax = ($a->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1828 ($a->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1829 $bx = ($b->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1830 ($b->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1832 return $x if $x != 0;
1836 my $ca = exists $a->{'Failed-Category'} ?
1837 $a->{'Failed-Category'} : "none";
1838 my $cb = exists $b->{'Failed-Category'} ?
1839 $b->{'Failed-Category'} : "none";
1840 $x = $catval{$ca} <=> $catval{$cb};
1841 return $x if $x != 0;
1845 my $pa = $prioval{$a->{'Priority'}} >
1846 $prioval{'standard'};
1847 my $pb = $prioval{$b->{'Priority'}} >
1848 $prioval{'standard'};
1850 return $x if $x != 0;
1860 my( $name, $pkg, @list );
1865 foreach $name (keys %db) {
1866 next if $name =~ /^_/;
1868 next if $state ne "all" && $pkg->{'State'} !~ /^\Q$state\E$/i;
1869 next if $user && (lc($state) ne 'needs-build' and $pkg->{'Builder'} ne $user);
1870 next if $category && $pkg->{'State'} eq "Failed" &&
1871 $pkg->{'Failed-Category'} ne $category;
1872 next if ($list_min_age > 0 &&
1873 ($ctime-parse_date($pkg->{'State-Change'})) < $list_min_age)||
1874 ($list_min_age < 0 &&
1875 ($ctime-parse_date($pkg->{'State-Change'})) > -$list_min_age);
1876 push( @list, $pkg );
1879 foreach $pkg (sort sort_list_func @list) {
1880 print "$pkg->{'Section'}/$pkg->{'Package'}_$pkg->{'Version'}";
1881 print ": $pkg->{'State'}"
1883 print " by $pkg->{'Builder'}"
1884 if $pkg->{'State'} ne "Needs-Build" && $pkg->{'Builder'};
1885 print " [$pkg->{'Priority'}:$pkg->{'Notes'}";
1886 print ":PREV-FAILED"
1887 if $pkg->{'Previous-State'} =~ /^Failed/;
1888 print ":bp{" . $pkg->{'BuildPri'} . "}"
1889 if exists $pkg->{'BuildPri'};
1890 print ":binNMU{" . $pkg->{'Binary-NMU-Version'} . "}"
1891 if exists $pkg->{'Binary-NMU-Version'};
1893 print " Reasons for failing:\n",
1895 exists $pkg->{'Failed-Category'} ? $pkg->{'Failed-Category'} : "none",
1897 join("\n ",split("\n",$pkg->{'Failed'})), "\n"
1898 if $pkg->{'State'} =~ /^Failed/;
1899 print " Dependencies: $pkg->{'Depends'}\n"
1900 if $pkg->{'State'} eq "Dep-Wait";
1901 print " Reasons for BD-Uninstallable:\n ",
1902 join("\n ",split("\n",$pkg->{'BD-Problem'})), "\n"
1903 if $pkg->{'State'} eq "BD-Uninstallable";
1904 print " Previous state was $pkg->{'Previous-State'} until ",
1905 "$pkg->{'State-Change'}\n"
1906 if $verbose && $pkg->{'Previous-State'};
1907 print " No previous state recorded\n"
1908 if $verbose && !$pkg->{'Previous-State'};
1909 print " Previous failing reasons:\n ",
1910 join("\n ",split("\n",$pkg->{'Old-Failed'})), "\n"
1911 if $verbose && $pkg->{'Old-Failed'};
1913 $scnt{$pkg->{'State'}}++ if $state eq "all";
1915 if ($state eq "all") {
1916 foreach (sort keys %scnt) {
1917 print "Total $scnt{$_} package(s) in state $_.\n";
1920 print "Total $cnt package(s)\n";
1925 my( $name, $pkg, $key, $dist );
1926 my @firstkeys = qw(Package Version Builder State Section Priority
1927 Installed-Version Previous-State State-Change);
1928 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1930 foreach $dist (@dists) {
1931 if ($dist ne $distribution) {
1932 if (!-f db_filename( $dist ) || !open_other_db( $dist )) {
1933 warn "Cannot open database for $dist!\n";
1934 @dists = grep { $_ ne $dist } @dists;
1939 foreach $name (@_) {
1940 $name =~ s/_.*$//; # strip version
1941 foreach $dist (@dists) {
1942 my $db = $dist ne $distribution ? $otherdb{$dist} : \%db;
1943 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1945 $pkg = $db->{$name};
1946 if (!defined( $pkg )) {
1947 print "$pname: not registered\n";
1952 foreach $key (@firstkeys) {
1953 next if !exists $pkg->{$key};
1954 my $val = $pkg->{$key};
1956 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1958 printf " %-20s: %s\n", $key, $val;
1960 foreach $key (sort keys %$pkg) {
1961 next if isin( $key, @firstkeys );
1962 my $val = $pkg->{$key};
1964 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1966 printf " %-20s: %s\n", $key, $val;
1972 sub forget_packages {
1973 my( $name, $pkg, $key, $data );
1975 foreach $name (@_) {
1976 $name =~ s/_.*$//; # strip version
1978 if (!defined( $pkg )) {
1979 print "$name: not registered\n";
1984 foreach $key (sort keys %$pkg) {
1985 my $val = $pkg->{$key};
1988 $data .= sprintf " %-20s: %s\n", $key, $val;
1990 send_mail( $conf::db_maint,
1991 "$name deleted from DB $conf::dbbase",
1992 "The package '$name' has been deleted from the database ".
1994 "Data registered about the deleted package:\n".
1995 "$data\n" ) if $conf::db_maint;
1996 change_state( \$pkg, 'deleted' );
1997 log_ta( $pkg, "--forget" );
1999 print "$name: deleted from database\n" if $verbose;
2007 $ui = $db{'_userinfo'};
2008 foreach $name (@_) {
2009 if (!defined( $ui->{$name} )) {
2010 print "$name: not registered\n";
2014 delete $ui->{$name};
2016 print "$name: deleted from database\n" if $verbose;
2018 $db{'_userinfo'} = $ui if $change;
2024 my $lockfile = db_lockfilename($dist);
2027 print "Locking $dist database\n" if $verbose >= 2;
2029 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2031 # lock file exists, wait
2032 goto repeat if !open( F, "<$lockfile" );
2035 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2036 warn "Bad lock file contents -- still trying\n";
2039 my($pid, $usr) = ($1, $2);
2040 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2041 # process doesn't exist anymore, remove stale lock
2042 print "Removing stale lock file (pid $pid, user $usr)\n";
2043 unlink( $lockfile );
2046 if ($pid == $lock_for_pid) {
2047 # We are allowed to use this lock.
2050 warn "Database locked by $usr -- please wait\n" if $try == 0;
2053 # avoid the END routine removes the lock
2054 $main::keep_lock{$dist} = 1;
2055 die "Lock still present after 200 * 5 seconds.\n";
2060 die "Can't create lock file $lockfile: $!\n";
2062 my $pid = $lock_for_pid == -1 ? $$ : $lock_for_pid;
2063 F->print("$pid $real_user\n");
2069 my $lockfile = db_lockfilename($dist);
2071 if (!$main::keep_lock{$dist}) {
2072 print "Unlocking $dist database\n" if $verbose >= 2;
2077 sub create_maintlock {
2078 my $lockfile = db_lockfilename("maintenance");
2082 print "Creating maintenance lock\n" if $verbose >= 2;
2084 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2086 # lock file exists, wait
2087 goto repeat if !open( F, "<$lockfile" );
2090 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2091 warn "Bad maintenance lock file contents -- still trying\n";
2094 my($pid, $usr) = ($1, $2);
2095 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2096 # process doesn't exist anymore, remove stale lock
2097 print "Removing stale lock file (pid $pid, user $usr)\n";
2098 unlink( $lockfile );
2101 warn "Maintenance lock already exists by $usr -- ".
2102 "please wait\n" if $try == 0;
2105 die "Lock still present after 120 * 60 seconds.\n";
2110 die "Can't create maintenance lock $lockfile: $!\n";
2112 F->print(getppid(), " $real_user\n");
2116 sub remove_maintlock {
2117 my $lockfile = db_lockfilename("maintenance");
2119 print "Removing maintenance lock\n" if $verbose >= 2;
2123 sub waitfor_maintlock {
2124 my $lockfile = db_lockfilename("maintenance");
2128 print "Checking for maintenance lock\n" if $verbose >= 2;
2130 if (open( F, "<$lockfile" )) {
2133 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2134 warn "Bad maintenance lock file contents -- still trying\n";
2137 my($pid, $usr) = ($1, $2);
2138 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2139 # process doesn't exist anymore, remove stale lock
2140 print "Removing stale maintenance lock (pid $pid, user $usr)\n";
2141 unlink( $lockfile );
2144 warn "Databases in $conf::dbbase locked for general maintenance by $usr -- ".
2145 "please wait\n" if $try == 0;
2148 die "Lock still present after 120 * 60 seconds.\n";
2159 print "Reading ASCII database from $file..." if $verbose >= 1;
2160 open( F, "<$file" ) or
2161 die "Can't open database $file: $!\n";
2163 local($/) = ""; # read in paragraph mode
2165 my( %thispkg, $name );
2167 s/\n[ \t]+/\376\377/g; # fix continuation lines
2168 s/\376\377\s*\376\377/\376\377/og;
2170 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2171 my ($key, $val) = ($1, $2);
2172 $val =~ s/\376\377/\n/g;
2173 $thispkg{$key} = $val;
2175 check_entry( \%thispkg );
2177 if (exists($thispkg{'Package'})) {
2178 $name = $thispkg{'Package'};
2179 $db{$name} = \%thispkg;
2181 elsif(exists($thispkg{'User'})) {
2182 my $userinfo = $db{'_userinfo'};
2183 $userinfo = {} if (!defined($userinfo));
2185 $name = $thispkg{'User'};
2186 $userinfo->{$name} = \%thispkg;
2188 $db{'_userinfo'} = $userinfo;
2192 print "done\n" if $verbose >= 1;
2199 return if $op_mode eq "manual-edit"; # no checks then
2201 # check for required fields
2202 if (exists $pkg->{'User'}) {
2205 if (!exists $pkg->{'Package'}) {
2206 print STDERR "Bad entry: ",
2207 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2208 die "Database entry lacks Package or User: field\n";
2210 if (!exists $pkg->{'Version'}) {
2211 die "Database entry for $pkg->{'Package'} lacks Version: field\n";
2213 # if no State: field, generate one (for old db compat)
2214 if (!exists($pkg->{'State'})) {
2216 exists $pkg->{'Failed'} ? 'Failed' : 'Building';
2219 die "Bad state $pkg->{'State'} of package $pkg->{Package}\n"
2220 if !isin( $pkg->{'State'},
2221 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait
2222 Failed Failed-Removed Not-For-Us BD-Uninstallable
2228 my($name,$pkg,$key);
2230 print "Writing ASCII database to $file..." if $verbose >= 1;
2231 open( F, ">$file" ) or
2232 die "Can't open database $file: $!\n";
2234 foreach $name (sort keys %db) {
2235 my $pkg = $db{$name};
2236 if ($name eq '_userinfo') {
2237 foreach $user (sort keys %{$pkg}) {
2238 my $ui = $pkg->{$user};
2239 print F "User: $user\n"
2240 if (!defined($ui->{'User'}));
2241 foreach $key (keys %{$ui}) {
2242 my $val = $ui->{$key};
2245 $val =~ s/^ +$/ ./mg;
2246 print F "$key: $val\n";
2252 foreach $key (keys %{$pkg}) {
2253 my $val = $pkg->{$key};
2256 $val =~ s/^ +$/ ./mg;
2257 print F "$key: $val\n";
2263 print "done\n" if $verbose >= 1;
2269 my $newstate = shift;
2270 my $for_dist = shift;
2273 return if !open_other_db( $for_dist );
2274 $db = $otherdb{$for_dist};
2275 $pkg = \$db{$pkg->{'Package'}};
2280 my $state = \$pkg->{'State'};
2282 return if defined($$state) and $$state eq $newstate;
2283 $pkg->{'Previous-State'} = $$state if defined($$state);
2284 $pkg->{'State-Change'} = $curr_date;
2286 if (defined($$state) and $$state eq 'Failed') {
2287 $pkg->{'Old-Failed'} =
2288 "-"x20 . " $pkg->{'Version'} " . "-"x20 . "\n" .
2289 $pkg->{'Failed'} . "\n" .
2290 $pkg->{'Old-Failed'};
2291 delete $pkg->{'Failed'};
2292 delete $pkg->{'Failed-Category'};
2294 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2295 delete $pkg->{'BD-Problem'};
2297 $$state = $newstate;
2303 if (!tied(%{$otherdb{$dist}})) {
2305 $otherdb_lock{$dist} = 1;
2306 if (!(tie %{$otherdb{$dist}}, 'MLDBM', db_filename($dist), 0, 0664)){
2307 warn "Serious warning: Cannot open database for $dist\n";
2309 $otherdb_lock{$dist} = 0;
2320 my $dist = $distribution;
2324 $prevstate = $pkg->{'Previous-State'};
2325 $str = "$action($dist): $pkg->{'Package'}_$pkg->{'Version'} ".
2326 "changed from $prevstate to $pkg->{'State'} ".
2327 "by $real_user as $user";
2329 my $transactlog = db_transactlog( $distribution );
2330 if (!open( LOG, ">>$transactlog" )) {
2331 warn "Can't open log file $transactlog: $!\n";
2334 print LOG "$curr_date: $str\n";
2337 if (!($prevstate eq 'Failed' && $pkg->{'State'} eq 'Failed')) {
2338 $str .= " (with --override)"
2340 $mail_logs .= "$str\n";
2347 my $subject = shift;
2350 my $from = $conf::db_maint;
2351 my $domain = $conf::buildd_domain;
2353 $from .= "\@$domain" if $from !~ /\@/;
2355 $to .= '@' . $domain if $to !~ /\@/;
2356 $text =~ s/^\.$/../mg;
2357 local $SIG{'PIPE'} = 'IGNORE';
2358 open( PIPE, "| $conf::mailprog -oem $to" )
2359 or die "Can't open pipe to $conf::mailprog: $!\n";
2361 print PIPE "From: $from\n";
2362 print PIPE "Subject: $subject\n\n";
2363 print PIPE "$text\n";
2369 return $transactional ? db_filename_transaction($dist) : db_filename_master($dist);
2371 sub db_filename_master {
2373 return "$conf::basedir/$conf::dbbase-$dist";
2375 sub db_filename_transaction {
2377 return "$conf::basedir/$conf::dbbase-$dist-transaction";
2380 sub db_lockfilename {
2382 return db_filename_master($dist) . ".lock";
2386 sub db_transactlog {
2388 return $transactional ? db_transactlog_transaction($dist) : db_transactlog_master($dist);
2390 sub db_transactlog_master {
2392 $conf::dbbase =~ m#^([^/]+/)#;
2393 return "$conf::basedir/$1$conf::transactlog";
2395 sub db_transactlog_transaction {
2397 $conf::dbbase =~ m#^([^/]+/)#;
2398 return "$conf::basedir/$1$conf::transactlog-$dist-transaction";
2401 # for parsing input to dep-wait
2407 foreach (split( /\s*,\s*/, $deps )) {
2409 # verification requires > starting prompts, no | crap
2410 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2415 my @alts = split( /\s*\|\s*/, $_ );
2416 # Anything with an | is ignored, as it can be configured on a
2417 # per-buildd basis what will be installed
2418 next if $#alts != 0;
2421 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2422 warn( "parse_deplist: bad dependency $_\n" );
2425 my($dep, $rel, $relv) = ($1, $3, $4);
2426 $rel = ">>" if defined($rel) and $rel eq ">";
2427 $result{$dep}->{'Package'} = $dep;
2428 if ($rel && $relv) {
2429 $result{$dep}->{'Rel'} = $rel;
2430 $result{$dep}->{'Version'} = $relv;
2433 return 1 if $verify;
2437 # for parsing Build-Depends from Sources
2438 sub parse_srcdeplist {
2445 foreach $dep (split( /\s*,\s*/, $deps )) {
2446 my @alts = split( /\s*\|\s*/, $dep );
2447 # Anything with an | is ignored, as it can be configured on a
2448 # per-buildd basis what will be installed
2449 next if $#alts != 0;
2451 if (!/^([^\s([]+)\s*(\(\s*([<=>]+)\s*(\S+)\s*\))?(\s*\[([^]]+)\])?/) {
2452 warn( "parse_srcdeplist: bad dependency $_\n" );
2455 my($dep, $rel, $relv, $archlist) = ($1, $3, $4, $6);
2457 $archlist =~ s/^\s*(.*)\s*$/$1/;
2458 my @archs = split( /\s+/, $archlist );
2459 my ($use_it, $ignore_it, $include) = (0, 0, 0);
2462 $ignore_it = 1 if substr($_, 1) eq $arch;
2464 $use_it = 1 if $_ eq $arch;
2468 warn "Warning: inconsistent arch restriction on ",
2469 "$pkg: $dep depedency\n"
2470 if $ignore_it && $use_it;
2471 next if $ignore_it || ($include && !$use_it);
2479 $result->{'Package'} = $dep;
2480 $result->{'Neg'} = $neg;
2481 if ($rel && $relv) {
2482 $result->{'Rel'} = $rel;
2483 $result->{'Version'} = $relv;
2485 push @results, $result;
2494 foreach $key (keys %$list) {
2495 $result .= ", " if $result;
2497 $result .= " ($list->{$key}->{'Rel'} $list->{$key}->{'Version'})"
2498 if $list->{$key}->{'Rel'} && $list->{$key}->{'Version'};
2505 tie %new_db, 'MLDBM', db_filename( $distribution ) . ".new", GDBM_WRCREAT, 0664
2506 or die "FATAL: Cannot create new database\n";
2508 untie %db or die "FATAL: Cannot untie old database\n";
2509 system ("cp " . db_filename( $distribution ) . ".new " .
2510 db_filename( $distribution ) ) == 0
2511 or die "FATAL: Cannot overwrite old database";
2512 unlink db_filename( $distribution ) . ".new";
2517 sub get_unsatisfied_dep {
2521 my $savedep = shift;
2523 my $pkgname = $dep->{'Package'};
2525 if (defined $pkgs->{$pkgname}{'Provider'}) {
2526 # provides. leave them for buildd/sbuild.
2531 return $pkgs->{$pkgname}{'Unsatisfied'} if $savedep and defined($pkgs->{$pkgname}{'Unsatisfied'});
2533 # Return unsatisfied deps to a higher caller to process
2534 if ((!defined($pkgs->{$pkgname})) or
2535 (defined($dep->{'Rel'}) and !version_compare( $pkgs->{$pkgname}{'Version'}, $dep->{'Rel'}, $dep->{'Version'} ) ) ) {
2537 $deplist{$pkgname} = $dep;
2538 my $deps = build_deplist(\%deplist);
2539 $pkgs->{$pkgname}{'Unsatisfied'} = $deps if $savedep;
2543 # set cache to "" to avoid infinite recursion
2544 $pkgs->{$pkgname}{'Unsatisfied'} = "" if $savedep;
2546 if (defined $pkgs->{$dep->{'Package'}}{'Depends'}) {
2547 my $deps = parse_deplist( $pkgs->{$dep->{'Package'}}{'Depends'} );
2548 foreach (keys %$deps) {
2551 my $ret = get_unsatisfied_dep($bd,$pkgs,$dep,1);
2553 my $retdep = parse_deplist( $ret );
2554 foreach (keys %$retdep) {
2555 $dep = $$retdep{$_};
2557 $dep->{'Rel'} = '>=' if defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^=';
2559 if (defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>' and defined ($pkgs->{$dep->{'Package'}}) and
2560 version_compare($bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'ver'},'>>',$pkgs->{$dep->{'Package'}}{'Sourcev'})) {
2561 if (not defined($merge_binsrc{$dep->{'Package'}})) {
2562 # the uninstallable package doesn't exist in the new source; look for something else that does.
2563 delete $$retdep{$dep->{'Package'}};
2564 foreach (sort (split( /\s*,\s*/, $bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'bin'}))) {
2565 next if ($pkgs->{$_}{'all'} or not defined $pkgs->{$_}{'Version'});
2566 $dep->{'Package'} = $_;
2567 $dep->{'Rel'} = '>>';
2568 $dep->{'Version'} = $pkgs->{$_}{'Version'};
2569 $$retdep{$_} = $dep;
2574 # sanity check to make sure the depending binary still exists, and the depended binary exists and dep-wait on a new version of it
2575 if ( defined($merge_binsrc{$pkgname}) and defined($pkgs->{$dep->{'Package'}}{'Version'}) ) {
2576 delete $$retdep{$dep->{'Package'}};
2577 $dep->{'Package'} = $pkgname;
2578 $dep->{'Rel'} = '>>';
2579 $dep->{'Version'} = $pkgs->{$pkgname}{'Version'};
2580 $$retdep{$pkgname} = $dep;
2582 delete $$retdep{$dep->{'Package'}} if (defined ($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>');
2585 $ret = build_deplist($retdep);
2586 $pkgs->{$pkgname}{'Unsatisfied'} = $ret if $savedep;
2594 sub call_edos_depcheck {
2595 my $packagesfile = shift;
2599 return if defined ($conf::distributions{$distribution}{noadw});
2601 # We need to check all of needs-build, as any new upload could make
2602 # something in needs-build have uninstallable deps
2603 # We also check everything in bd-uninstallable, as any new upload could
2604 # make that work again
2605 my %interesting_packages;
2606 foreach $key (keys %db) {
2607 my $pkg = $db{$key};
2608 if (defined $pkg and isin($pkg->{'State'}, qw/Needs-Build BD-Uninstallable/)) {
2609 $interesting_packages{$key} = undef;
2613 #print "I would look at these sources with edos-depcheck:\n";
2614 #print join " ", keys %interesting_packages,"\n";
2616 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2618 for( $i = 0;; ++$i ) {
2619 $tmpfile = $tmpfile_pattern . $i;
2620 last if ! -e $tmpfile;
2623 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2624 for my $key (keys %interesting_packages) {
2625 my $pkg = $db{$key};
2626 print SOURCES "Package: $key\n";
2627 print SOURCES "Version: $pkg->{'Version'}\n";
2628 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2629 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2630 print SOURCES "Architecture: all\n";
2635 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2637 local($/) = ""; # read in paragraph mode
2639 my( $key, $reason ) ;
2641 /^Package:\s*(\S+)$/mi and $key = $1;
2642 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2643 $reason =~ s/^\s*//mg;
2644 $reason ||= 'No reason given by edos-debcheck';
2646 if (exists $interesting_packages{$key}) {
2647 $interesting_packages{$key} = $reason;
2649 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2654 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2655 "all packages have installable build-dependencies."
2660 for my $key (keys %interesting_packages) {
2661 my $pkg = $db{$key};
2663 (defined $interesting_packages{$key} and $pkg->{'State'} eq 'Needs-Build') ||
2664 (not defined $interesting_packages{$key} and $pkg->{'State'} eq 'BD-Uninstallable');
2665 my $problemchange = $interesting_packages{$key} ne $pkg->{'BD-Problem'};
2667 if (defined $interesting_packages{$key}) {
2668 change_state( \$pkg, 'BD-Uninstallable' );
2669 $pkg->{'BD-Problem'} = $interesting_packages{$key};
2671 change_state( \$pkg, 'Needs-Build' );
2674 if ($problemchange) {
2675 if (defined $interesting_packages{$key}) {
2676 $pkg->{'BD-Problem'} = $interesting_packages{$key};
2680 log_ta( $pkg, "--merge-all" );
2681 print "edos-builddebchange changed state of ${key}_$pkg->{'Version'} to $pkg->{'State'}\n" if $verbose;
2683 if ($change || $problemchange) {
2691 ($prgname = $0) =~ s,^.*/,,;
2693 Usage: $prgname <options...> <package_version...>
2695 -v, --verbose: Verbose execution.
2696 --take: Take package for building [default operation]
2697 -f, --failed: Record in database that a build failed due to
2698 deficiencies in the package (that aren't fixable without a new
2700 -u, --uploaded: Record in the database that the packages build
2701 correctly and were uploaded.
2702 -n, --no-build: Record in the database that the packages aren't
2703 desired for this architecture and shouldn't appear in listings even
2704 if they're out of date.
2705 --dep-wait: Record in the database that the packages are waiting
2706 for some source dependencies to become available
2707 --binNMU num: Schedule a re-build of the package with unchanged source, but
2708 a new version number (source-version + "+b<num>")
2709 --give-back: Mark a package as ready to build that is in state Building,
2710 Built or Build-Attempted. To give back a package in state Failed, use
2711 --override. This command will actually put the package in state
2712 BD-Uninstallable, until the installability of its Build-Dependencies
2713 were verified. This happens at each call of --merge-all, usually
2715 --merge-quinn: Merge quinn-diff output into database.
2716 --merge-packages: Merge Packages files into database.
2717 --pretend-avail: Pretend that given packages are available now and give
2718 free packages waiting for them
2719 -i SRC_PKG, --info SRC_PKG: Show information for source package
2720 -l STATE, --list=STATE: List all packages in state STATE; can be
2721 combined with -U to restrict to a specific user; STATE can
2723 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2724 source dependency list
2725 (used with -f, --dep-wait, and --binNMU)
2726 -o, --override: Override another user's lock on a package, i.e.
2727 take it over; a notice mail will be sent to the other user
2728 -U USER, --user=USER: select user name for which listings should
2729 apply, if not given all users are listed.
2730 if -l is missing, set user name to be entered in db; usually
2731 automatically choosen
2732 --import FILE: Import database from a ASCII file FILE
2733 --export FILE: Export database to a ASCII file FILE
2734 --lock-for PID: Locks the database for the process with this pid
2735 --unlock-for PID: Unlocks the database for the process with this pid
2736 --act-on-behalf-of PID: Ignores the lock (if it is held by this pid)
2737 --start-transaction: Creates a copy of the state of the database, for
2738 use with --transactional. This overrides any previous uncommited
2739 transaction. Should only be used after --lock-for
2740 --commit-transaction: Atomically moves the copy back to the main, thus
2741 commiting the changes
2742 --transactional: Flag to indicate that we want to work on the copy
2744 The remaining arguments (depending on operation) usually start with
2745 "name_version", the trailer is ignored. This allows to pass the names
2746 of .dsc files, for which file name completion can be used.
2747 --merge-packages and --merge-quinn take Package/quin--diff file names
2748 on the command line or read stdin. --list needs nothing more on the
2749 command line. --info takes source package names (without version).
2754 sub pkg_version_eq {
2756 my $version = shift;
2759 if (defined $pkg->{'Binary-NMU-Version'}) and
2760 version_compare(binNMU_version($pkg->{'Version'},
2761 $pkg->{'Binary-NMU-Version'}),'=', $version);
2762 return version_compare( $pkg->{'Version'}, "=", $version );