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;
983 print "$name: has uninstallable build-dependencies. Skipping\n",
984 " (use --override to clear dependency list and ",
985 "give back anyway)\n";
989 elsif ($state eq "Dep-Wait") {
991 print "$name: Forcing source dependency list to be cleared\n";
994 print "$name: waiting for source dependencies. Skipping\n",
995 " (use --override to clear dependency list and ",
996 "give back anyway)\n";
1000 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1001 print "$name: not taken for building (state is $state).";
1002 if ($opt_override) {
1003 print "\n$name: Forcing give-back\n";
1006 print " Skipping.\n";
1010 if (defined ($pkg->{'Builder'}) && $user ne $pkg->{'Builder'} &&
1011 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user)) {
1012 print "$name: not taken by you, but by ".
1013 "$pkg->{'Builder'}. Skipping.\n";
1016 if (!pkg_version_eq($pkg, $version)) {
1017 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1021 change_state( \$pkg, 'BD-Uninstallable' );
1022 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1023 delete $pkg->{'Builder'};
1024 delete $pkg->{'Depends'};
1025 log_ta( $pkg, "--give-back" );
1027 print "$name: given back\n" if $verbose;
1030 sub set_one_binnmu {
1032 my $version = shift;
1033 my $pkg = $db{$name};
1036 if (!defined($pkg)) {
1037 print "$name: not registered; can't register for binNMU.\n";
1040 my $db_ver = $pkg->{'Version'};
1042 if (!version_eq($db_ver, $version)) {
1043 print "$name: version mismatch ($db_ver registered). ",
1047 $state = $pkg->{'State'};
1049 if (defined $pkg->{'Binary-NMU-Version'}) {
1050 if ($binNMUver == 0) {
1051 change_state( \$pkg, 'Installed' );
1052 delete $pkg->{'Builder'};
1053 delete $pkg->{'Depends'};
1054 delete $pkg->{'Binary-NMU-Version'};
1055 delete $pkg->{'Binary-NMU-Changelog'};
1056 } elsif ($binNMUver <= $pkg->{'Binary-NMU-Version'}) {
1057 print "$name: already building binNMU $pkg->{'Binary-NMU-Version'}\n";
1060 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1061 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1062 $pkg->{'Notes'} = 'out-of-date';
1063 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'}
1064 if (defined $pkg->{'PermBuildPri'});
1066 log_ta( $pkg, "--binNMU" );
1069 } elsif ($binNMUver == 0) {
1070 print "${name}_$version: no scheduled binNMU to cancel.\n";
1074 if ($state ne 'Installed') {
1075 print "${name}_$version: not installed; can't register for binNMU.\n";
1079 my $fullver = binNMU_version($version,$binNMUver);
1080 if ( version_lesseq( $fullver, $pkg->{'Installed-Version'} ) )
1082 print "$name: binNMU $fullver is not newer than current version $pkg->{'Installed-Version'}\n";
1086 change_state( \$pkg, 'BD-Uninstallable' );
1087 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1088 delete $pkg->{'Builder'};
1089 delete $pkg->{'Depends'};
1090 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1091 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1092 $pkg->{'Notes'} = 'out-of-date';
1093 log_ta( $pkg, "--binNMU" );
1095 print "${name}: registered for binNMU $fullver\n" if $verbose;
1098 sub set_one_buildpri {
1100 my $version = shift;
1102 my $pkg = $db{$name};
1105 if (!defined($pkg)) {
1106 print "$name: not registered; can't set priority.\n";
1109 $state = $pkg->{'State'};
1111 if ($state eq "Not-For-Us") {
1112 print "$name: not suitable for this architecture. Skipping.\n";
1114 } elsif ($state eq "Failed-Removed") {
1115 print "$name: failed previously and doesn't need building. Skipping.\n";
1118 if (!pkg_version_eq($pkg, $version)) {
1119 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1123 if ( $build_priority == 0 ) {
1124 delete $pkg->{'BuildPri'}
1125 if $key eq 'PermBuildPri' and defined $pkg->{'BuildPri'}
1126 and $pkg->{'BuildPri'} == $pkg->{$key};
1127 delete $pkg->{$key};
1129 $pkg->{'BuildPri'} = $build_priority
1130 if $key eq 'PermBuildPri';
1131 $pkg->{$key} = $build_priority;
1134 print "$name: set to build priority $build_priority\n" if $verbose;
1137 sub add_one_depwait {
1139 my $version = shift;
1141 my $pkg = $db{$name};
1143 if (!defined($pkg)) {
1144 print "$name: not registered yet.\n";
1147 $state = $pkg->{'State'};
1149 if ($state eq "Dep-Wait") {
1150 print "$name: merging with previously registered dependencies\n";
1153 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1154 print "$name: Warning: not registered for building previously, ".
1155 "but processing anyway.\n";
1157 elsif ($state eq "Not-For-Us") {
1158 print "$name: not suitable for this architecture anyway. Skipping.\n";
1161 elsif ($state eq "Failed-Removed") {
1162 print "$name: failed previously and doesn't need building. Skipping.\n";
1165 elsif ($state eq "Installed") {
1166 print "$name: Is already installed in archive. Skipping.\n";
1169 elsif ($state eq "Uploaded") {
1170 print "$name: Is already uploaded. Skipping.\n";
1173 elsif ($pkg->{'Builder'} &&
1174 $user ne $pkg->{'Builder'}) {
1175 print "$name: not taken by you, but by ".
1176 "$pkg->{'Builder'}. Skipping.\n";
1179 elsif ( !pkg_version_eq($pkg,$version)) {
1180 print "$name: version mismatch ".
1181 "($pkg->{'Version'} ".
1182 "by $pkg->{'Builder'})\n";
1185 elsif ($fail_reason =~ /^\s*$/ ||
1186 !parse_deplist( $fail_reason, 1 )) {
1187 print "$name: Bad dependency list\n";
1190 change_state( \$pkg, 'Dep-Wait' );
1191 $pkg->{'Builder'} = $user;
1192 if (defined $pkg->{'PermBuildPri'}) {
1193 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1195 delete $pkg->{'BuildPri'};
1197 my $deplist = parse_deplist( $pkg->{'Depends'} );
1198 my $new_deplist = parse_deplist( $fail_reason );
1199 # add new dependencies, maybe overwriting old entries
1200 foreach (keys %$new_deplist) {
1201 $deplist->{$_} = $new_deplist->{$_};
1203 $pkg->{'Depends'} = build_deplist($deplist);
1204 log_ta( $pkg, "--dep-wait" );
1206 print "$name: registered as waiting for dependencies\n" if $verbose;
1216 local($/) = ""; # read in paragraph mode
1218 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1220 /^Package:\s*(\S+)$/mi and $name = $1;
1221 /^Version:\s*(\S+)$/mi and $version = $1;
1222 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1223 /^Section:\s*(\S+)$/mi and $section = $1;
1224 /^Priority:\s*(\S+)$/mi and $priority = $1;
1225 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1226 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1227 /^Binary:\s*(.*)$/mi and $binaries = $1;
1229 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1230 $srcver{$name} = $version;
1232 $pkgs{$name}{'ver'} = $version;
1233 $pkgs{$name}{'bin'} = $binaries;
1234 $pkgs{$name}{'dep'} = $builddep;
1235 $pkgs{$name}{'conf'} = $buildconf;
1236 my $pkg = $db{$name};
1241 if ($arch eq "all" && !version_less( $version, $pkg->{'Version'} )) {
1242 # package is now Arch: all, delete it from db
1243 change_state( \$pkg, 'deleted' );
1244 log_ta( $pkg, "--merge-sources" );
1245 print "$name ($pkg->{'Version'}): deleted ".
1246 "from database, because now Arch: all\n"
1252 # The "Version" should always be the source version --
1253 # not a possible binNMU version number.
1254 $pkg->{'Version'} = $version, $change++
1255 if ($pkg->{'State'} eq 'Installed' and
1256 !version_eq( $pkg->{'Version'}, $version));
1257 # Always update priority and section, if available
1258 $pkg->{'Priority'} = $priority, $change++
1259 if defined $priority and (not defined($pkg->{'Priority'}) or $pkg->{'Priority'} ne $priority);
1261 $pkg->{'Section'} = $section, $change++
1262 if defined $section and (not defined($pkg->{'Section'}) or $pkg->{'Section'} ne $section);
1264 # Remove field from previous wanna-build versions
1265 for (qw/Reason Build-Depends Build-Conflicts/) {
1266 if (exists $pkg->{$_}) {
1272 $db{$name} = $pkg if $change;
1275 # Now that we only have the latest source version, build the list
1276 # of binary packages from the Sources point of view
1277 foreach $name (keys %pkgs) {
1278 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1279 $merge_binsrc{$bin} = $name;
1282 # remove installed packages that no longer have source available
1283 # or binaries installed
1284 foreach $name (keys %db) {
1285 next if $name =~ /^_/;
1286 my $pkg = $db{$name};
1287 if (not defined($pkgs{$name})) {
1288 change_state( \$pkg, 'deleted' );
1289 log_ta( $pkg, "--merge-sources" );
1290 print "$name ($pkg->{'Version'}): ".
1291 "deleted from database, because ".
1292 "not in Sources anymore\n"
1296 next if !isin( $pkg->{'State'}, qw(Installed) );
1297 if ($full && not defined $merge_srcvers{$name}) {
1298 change_state( \$pkg, 'deleted' );
1299 log_ta( $pkg, "--merge-sources" );
1300 print "$name ($pkg->{'Version'}): ".
1301 "deleted from database, because ".
1302 "binaries don't exist anymore\n"
1305 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'Version'})) {
1306 print "$name ($pkg->{'Version'}): ".
1307 "package is Installed but binaries are from ".
1308 $merge_srcvers{$name}. "\n"
1316 # This function looks through a Packages file and sets the state of
1317 # packages to 'Installed'
1318 sub parse_packages {
1321 local($/) = ""; # read in paragraph mode
1323 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1325 /^Package:\s*(\S+)$/mi and $name = $1;
1326 /^Version:\s*(\S+)$/mi and $version = $1;
1327 /^Depends:\s*(.*)$/mi and $depends = $1;
1328 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1329 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1330 /^Provides:\s*(.*)$/mi and $provides = $1;
1331 next if !$name || !$version;
1332 next if ($arch ne $architecture and $architecture ne "all");
1333 next if (defined ($installed->{$name}) and $installed->{$name}{'Version'} ne "" and
1334 version_lesseq( $version, $installed->{$name}{'Version'} ));
1335 $installed->{$name}{'Version'} = $version;
1336 $installed->{$name}{'Depends'} = $depends;
1337 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1338 undef $installed->{$name}{'Provider'};
1339 $installed->{$name}{'Source'} = $source ? $source : $name;
1341 foreach (split( /\s*,\s*/, $provides )) {
1342 if (not defined ($installed->{$_})) {
1343 $installed->{$_}{'Version'} = "";
1344 $installed->{$_}{'Provider'} = $name;
1348 if ( $version =~ /\+b(\d+)$/ ) {
1351 $version = $sourcev if $sourcev;
1352 $binaryv = $version;
1353 $binaryv =~ s/\+b\d+$//;
1354 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1355 $binaryv .= "+b$binnmu" if defined($binnmu);
1357 next if $architecture ne $arch;
1358 $name = $source if $source;
1359 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1360 $merge_srcvers{$name} = $version;
1362 my $pkg = $db{$name};
1365 if (isin( $pkg->{'State'}, qw(Not-For-Us)) ||
1366 (isin($pkg->{'State'}, qw(Installed)) &&
1367 version_lesseq($binaryv, $pkg->{'Installed-Version'}))) {
1368 print "Skipping $name because State == $pkg->{'State'}\n"
1372 if ($pkg->{'Binary-NMU-Version'} ) {
1373 my $nmuver = binNMU_version($pkg->{'Version'}, $pkg->{'Binary-NMU-Version'});
1374 if (version_less( $binaryv, $nmuver )) {
1375 print "Skipping $name ($version) because have newer ".
1376 "version ($nmuver) in db.\n"
1380 } elsif (version_less($version, $pkg->{'Version'})) {
1381 print "Skipping $name ($version) because have newer ".
1382 "version ($pkg->{'Version'}) in db.\n"
1387 if (!pkg_version_eq($pkg, $version) &&
1388 $pkg->{'State'} ne "Installed") {
1389 warn "Warning: $name: newer version than expected appeared ".
1390 "in archive ($version vs. $pkg->{'Version'})\n";
1391 delete $pkg->{'Builder'};
1394 if (!isin( $pkg->{'State'}, qw(Uploaded) )) {
1395 warn "Warning: Package $name was not in uploaded state ".
1396 "before (but in '$pkg->{'State'}').\n";
1397 delete $pkg->{'Builder'};
1398 delete $pkg->{'Depends'};
1402 $pkg->{'Version'} = $version;
1405 change_state( \$pkg, 'Installed' );
1406 $pkg->{'Package'} = $name;
1407 $pkg->{'Installed-Version'} = $binaryv;
1408 if (defined $pkg->{'PermBuildPri'}) {
1409 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1411 delete $pkg->{'BuildPri'};
1413 $pkg->{'Version'} = $version
1414 if version_less( $pkg->{'Version'}, $version);
1415 delete $pkg->{'Binary-NMU-Version'};
1416 delete $pkg->{'Binary-NMU-Changelog'};
1417 log_ta( $pkg, "--merge-packages" );
1419 print "$name ($version) is up-to-date now.\n" if $verbose;
1422 check_dep_wait( "--merge-packages", $installed );
1427 my ($package, $name, $version, $installed);
1429 foreach $package (@_) {
1430 $package =~ s,^.*/,,; # strip path
1431 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1432 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1433 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1434 ($name,$version) = ($1,$2);
1437 warn "$package: can't extract package name and version ".
1441 $installed->{$name}{'Version'} = $version;
1444 check_dep_wait( "--pretend-avail", $installed );
1447 sub check_dep_wait {
1449 my $installed = shift;
1451 # check all packages in state Dep-Wait if dependencies are all
1454 foreach $name (keys %db) {
1455 next if $name =~ /^_/;
1456 my $pkg = $db{$name};
1457 next if $pkg->{'State'} ne "Dep-Wait";
1458 my $deps = $pkg->{'Depends'};
1460 print "$name: was in state Dep-Wait, but with empty ",
1462 goto make_needs_build;
1464 my $deplist = parse_deplist($deps);
1468 foreach (keys %$deplist) {
1469 if (!exists $installed->{$_} ||
1470 ($deplist->{$_}->{'Rel'} && $deplist->{$_}->{'Version'} &&
1471 !version_compare( $installed->{$_}{'Version'},
1472 $deplist->{$_}->{'Rel'},
1473 $deplist->{$_}->{'Version'}))) {
1475 $new_deplist->{$_} = $deplist->{$_};
1478 push( @removed_deps, $_ );
1483 change_state( \$pkg, 'Needs-Build' );
1484 log_ta( $pkg, $action );
1485 delete $pkg->{'Builder'};
1486 delete $pkg->{'Depends'};
1487 print "$name ($pkg->{'Version'}) has all ",
1488 "dependencies available now\n" if $verbose;
1492 elsif (@removed_deps) {
1493 $pkg->{'Depends'} = build_deplist( $new_deplist );
1494 print "$name ($pkg->{'Version'}): some dependencies ",
1495 "(@removed_deps) available now, but not all yet\n"
1502 # This function accepts quinn-diff output (either from a file named on
1503 # the command line, or on stdin) and sets the packages named there to
1504 # state 'Needs-Build'.
1505 sub parse_quinn_diff {
1506 my $partial = shift;
1512 next if !m,^([-\w\d/]*)/ # section
1513 ([-\w\d.+]+)_ # package name
1514 ([\w\d:.~+-]+)\.dsc\s* # version
1515 \[([^:]*): # priority
1516 ([^]]+)\]\s*$,x; # rest of notes
1517 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1518 $quinn_pkgs{$name}++;
1519 $section ||= "unknown";
1520 $priority ||= "unknown";
1521 $priority = "unknown" if $priority eq "-";
1522 $priority = "standard" if ($name eq "debian-installer");
1524 my $pkg = $db{$name};
1526 # Always update section and priority.
1527 if (defined($pkg)) {
1529 $pkg->{'Section'} = $section, $change++ if not defined
1530 $pkg->{'Section'} or $section ne "unknown";
1531 $pkg->{'Priority'} = $priority, $change++ if not defined
1532 $pkg->{'Priority'} or $priority ne "unknown";
1535 if (defined($pkg) &&
1536 $pkg->{'State'} =~ /^Dep-Wait/ &&
1537 version_less( $pkg->{'Version'}, $version )) {
1538 change_state( \$pkg, 'Dep-Wait' );
1539 $pkg->{'Version'} = $version;
1540 delete $pkg->{'Binary-NMU-Version'};
1541 delete $pkg->{'Binary-NMU-Changelog'};
1542 log_ta( $pkg, "--merge-quinn" );
1544 print "$name ($version) still waiting for dependencies.\n"
1547 elsif (defined($pkg) &&
1548 $pkg->{'State'} =~ /-Removed$/ &&
1549 version_eq($pkg->{'Version'}, $version)) {
1550 # reinstantiate a package that has been removed earlier
1551 # (probably due to a quinn-diff malfunction...)
1552 my $newstate = $pkg->{'State'};
1553 $newstate =~ s/-Removed$//;
1554 change_state( \$pkg, $newstate );
1555 $pkg->{'Version'} = $version;
1556 $pkg->{'Notes'} = $notes;
1557 log_ta( $pkg, "--merge-quinn" );
1559 print "$name ($version) reinstantiated to $newstate.\n"
1562 elsif (defined($pkg) &&
1563 $pkg->{'State'} eq "Not-For-Us" &&
1564 version_less( $pkg->{'Version'}, $version )) {
1565 # for Not-For-Us packages just update the version etc., but
1567 change_state( \$pkg, "Not-For-Us" );
1568 $pkg->{'Package'} = $name;
1569 $pkg->{'Version'} = $version;
1570 $pkg->{'Notes'} = $notes;
1571 delete $pkg->{'Builder'};
1572 log_ta( $pkg, "--merge-quinn" );
1574 print "$name ($version) still Not-For-Us.\n" if $verbose;
1576 elsif (!defined($pkg) ||
1577 $pkg->{'State'} ne "Not-For-Us" &&
1578 (version_less( $pkg->{'Version'}, $version ) ||
1579 ($pkg->{'State'} eq "Installed" && version_less($pkg->{'Installed-Version'}, $version)))) {
1581 if (defined( $pkg->{'State'} ) && isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
1582 send_mail( $pkg->{'Builder'},
1583 "new version of $name (dist=$distribution)",
1584 "As far as I'm informed, you're currently ".
1585 "building the package $name\n".
1586 "in version $pkg->{'Version'}.\n\n".
1587 "Now there's a new source version $version. ".
1588 "If you haven't finished\n".
1589 "compiling $name yet, you can stop it to ".
1590 "save some work.\n".
1591 "Just to inform you...\n".
1592 "(This is an automated message)\n" );
1593 print "$name: new version ($version) while building ".
1594 "$pkg->{'Version'} -- sending mail ".
1595 "to builder ($pkg->{'Builder'})\n"
1598 change_state( \$pkg, 'Needs-Build' );
1599 $pkg->{'Package'} = $name;
1600 $pkg->{'Version'} = $version;
1601 $pkg->{'Section'} = $section;
1602 $pkg->{'Priority'} = $priority;
1603 $pkg->{'Notes'} = $notes;
1604 delete $pkg->{'Builder'};
1605 delete $pkg->{'Binary-NMU-Version'};
1606 delete $pkg->{'Binary-NMU-Changelog'};
1607 log_ta( $pkg, "--merge-quinn" );
1610 print "$name ($version) needs rebuilding now.\n" if $verbose;
1612 elsif (defined($pkg) &&
1613 !version_eq( $pkg->{'Version'}, $version ) &&
1614 isin( $pkg->{'State'}, qw(Installed Not-For-Us) )) {
1615 print "$name: skipping because version in db ".
1616 "($pkg->{'Version'}) is >> than ".
1617 "what quinn-diff says ($version) ".
1618 "(state is $pkg->{'State'})\n"
1620 $dubious .= "$pkg->{'State'}: ".
1621 "db ${name}_$pkg->{'Version'} >> ".
1622 "quinn $version\n" if !$partial;
1624 elsif ($verbose >= 2) {
1625 if ($pkg->{'State'} eq "Not-For-Us") {
1626 print "Skipping $name because State == ".
1627 "$pkg->{'State'}\n";
1629 elsif (!version_less($pkg->{'Version'}, $version)) {
1630 print "Skipping $name because version in db ".
1631 "($pkg->{'Version'}) is >= than ".
1632 "what quinn-diff says ($version)\n";
1635 $db{$name} = $pkg if $change;
1639 send_mail( $conf::db_maint,
1640 "Dubious versions in $distribution $conf::dbbase database",
1641 "The following packages have a newer version in the ".
1642 "wanna-build database\n".
1643 "than what quinn-diff says, and this is strange for ".
1645 "It could be caused by a lame mirror, or the version ".
1646 "in the database\n".
1651 # Now re-check the DB for packages in states Needs-Build, Failed,
1652 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1653 # anymore by quinn-diff.
1656 foreach $name (keys %db) {
1657 next if $name =~ /^_/;
1658 my $pkg = $db{$name};
1659 next if defined $pkg->{'Binary-NMU-Version'};
1660 next if !isin( $pkg->{'State'},
1661 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1662 my $virtual_delete = $pkg->{'State'} eq 'Failed';
1664 if (!$quinn_pkgs{$name}) {
1665 change_state( \$pkg, $virtual_delete ?
1666 $pkg->{'State'}."-Removed" :
1668 log_ta( $pkg, "--merge-quinn" );
1669 print "$name ($pkg->{'Version'}): ".
1670 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1671 "from database, because not in quinn-diff anymore\n"
1673 if ($virtual_delete) {
1683 sub send_reupload_mail {
1686 my $version = shift;
1688 my $other_dist = shift;
1691 "Please reupload ${pkg}_${'Version'} for $dist",
1692 "You have recently built (or are currently building)\n".
1693 "${pkg}_${'Version'} for $other_dist.\n".
1694 "This version is now also needed in the $dist distribution.\n".
1695 "Please reupload the files now present in the Debian archive\n".
1696 "(best with buildd-reupload).\n" );
1700 # for sorting priorities and sections
1702 %prioval = ( required => -5,
1710 'debian-installer' => -199,
1731 localizations => -178,
1732 interpreters => -177,
1757 electronics => -152,
1763 foreach my $i (keys %sectval) {
1764 $sectval{"contrib/$i"} = $sectval{$i}+40;
1765 $sectval{"non-free/$i"} = $sectval{$i}+80;
1767 $sectval{'unknown'} = -165;
1769 %catval = ( "none" => -20,
1770 "uploaded-fixed-pkg" => -19,
1771 "fix-expected" => -18,
1772 "reminder-sent" => -17,
1773 "nmu-offered" => -16,
1777 "compiler-error" => -12 );
1780 sub sort_list_func {
1781 my( $letter, $x, $ax, $bx );
1783 foreach $letter (split( "", $list_order )) {
1784 SWITCH: foreach ($letter) {
1786 $x = $b->{'BuildPri'} <=> $a->{'BuildPri'};
1787 return $x if $x != 0;
1791 $x = $prioval{$a->{'Priority'}} <=> $prioval{$b->{'Priority'}};
1792 return $x if $x != 0;
1796 $x = $sectval{$a->{'Section'}} <=> $sectval{$b->{'Section'}};
1797 return $x if $x != 0;
1801 $x = $a->{'Package'} cmp $b->{'Package'};
1802 return $x if $x != 0;
1806 $x = $a->{'Builder'} cmp $b->{'Builder'};
1807 return $x if $x != 0;
1811 $ax = ($a->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1812 ($a->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1813 $bx = ($b->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1814 ($b->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1816 return $x if $x != 0;
1820 my $ca = exists $a->{'Failed-Category'} ?
1821 $a->{'Failed-Category'} : "none";
1822 my $cb = exists $b->{'Failed-Category'} ?
1823 $b->{'Failed-Category'} : "none";
1824 $x = $catval{$ca} <=> $catval{$cb};
1825 return $x if $x != 0;
1829 my $pa = $prioval{$a->{'Priority'}} >
1830 $prioval{'standard'};
1831 my $pb = $prioval{$b->{'Priority'}} >
1832 $prioval{'standard'};
1834 return $x if $x != 0;
1844 my( $name, $pkg, @list );
1849 foreach $name (keys %db) {
1850 next if $name =~ /^_/;
1852 next if $state ne "all" && $pkg->{'State'} !~ /^\Q$state\E$/i;
1853 next if $user && (lc($state) ne 'needs-build' and $pkg->{'Builder'} ne $user);
1854 next if $category && $pkg->{'State'} eq "Failed" &&
1855 $pkg->{'Failed-Category'} ne $category;
1856 next if ($list_min_age > 0 &&
1857 ($ctime-parse_date($pkg->{'State-Change'})) < $list_min_age)||
1858 ($list_min_age < 0 &&
1859 ($ctime-parse_date($pkg->{'State-Change'})) > -$list_min_age);
1860 push( @list, $pkg );
1863 foreach $pkg (sort sort_list_func @list) {
1864 print "$pkg->{'Section'}/$pkg->{'Package'}_$pkg->{'Version'}";
1865 print ": $pkg->{'State'}"
1867 print " by $pkg->{'Builder'}"
1868 if $pkg->{'State'} ne "Needs-Build" && $pkg->{'Builder'};
1869 print " [$pkg->{'Priority'}:$pkg->{'Notes'}";
1870 print ":PREV-FAILED"
1871 if $pkg->{'Previous-State'} =~ /^Failed/;
1872 print ":bp{" . $pkg->{'BuildPri'} . "}"
1873 if exists $pkg->{'BuildPri'};
1874 print ":binNMU{" . $pkg->{'Binary-NMU-Version'} . "}"
1875 if exists $pkg->{'Binary-NMU-Version'};
1877 print " Reasons for failing:\n",
1879 exists $pkg->{'Failed-Category'} ? $pkg->{'Failed-Category'} : "none",
1881 join("\n ",split("\n",$pkg->{'Failed'})), "\n"
1882 if $pkg->{'State'} =~ /^Failed/;
1883 print " Dependencies: $pkg->{'Depends'}\n"
1884 if $pkg->{'State'} eq "Dep-Wait";
1885 print " Reason: $pkg->{'BD-Problem'}\n"
1886 if $pkg->{'State'} eq "BD-Uninstallable";
1887 print " Previous state was $pkg->{'Previous-State'} until ",
1888 "$pkg->{'State-Change'}\n"
1889 if $verbose && $pkg->{'Previous-State'};
1890 print " Previous failing reasons:\n ",
1891 join("\n ",split("\n",$pkg->{'Old-Failed'})), "\n"
1892 if $verbose && $pkg->{'Old-Failed'};
1894 $scnt{$pkg->{'State'}}++ if $state eq "all";
1896 if ($state eq "all") {
1897 foreach (sort keys %scnt) {
1898 print "Total $scnt{$_} package(s) in state $_.\n";
1901 print "Total $cnt package(s)\n";
1906 my( $name, $pkg, $key, $dist );
1907 my @firstkeys = qw(Package Version Builder State Section Priority
1908 Installed-Version Previous-State State-Change);
1909 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1911 foreach $dist (@dists) {
1912 if ($dist ne $distribution) {
1913 if (!-f db_filename( $dist ) || !open_other_db( $dist )) {
1914 warn "Cannot open database for $dist!\n";
1915 @dists = grep { $_ ne $dist } @dists;
1920 foreach $name (@_) {
1921 $name =~ s/_.*$//; # strip version
1922 foreach $dist (@dists) {
1923 my $db = $dist ne $distribution ? $otherdb{$dist} : \%db;
1924 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1926 $pkg = $db->{$name};
1927 if (!defined( $pkg )) {
1928 print "$pname: not registered\n";
1933 foreach $key (@firstkeys) {
1934 next if !exists $pkg->{$key};
1935 my $val = $pkg->{$key};
1937 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1939 printf " %-20s: %s\n", $key, $val;
1941 foreach $key (sort keys %$pkg) {
1942 next if isin( $key, @firstkeys );
1943 my $val = $pkg->{$key};
1945 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1947 printf " %-20s: %s\n", $key, $val;
1953 sub forget_packages {
1954 my( $name, $pkg, $key, $data );
1956 foreach $name (@_) {
1957 $name =~ s/_.*$//; # strip version
1959 if (!defined( $pkg )) {
1960 print "$name: not registered\n";
1965 foreach $key (sort keys %$pkg) {
1966 my $val = $pkg->{$key};
1969 $data .= sprintf " %-20s: %s\n", $key, $val;
1971 send_mail( $conf::db_maint,
1972 "$name deleted from DB $conf::dbbase",
1973 "The package '$name' has been deleted from the database ".
1975 "Data registered about the deleted package:\n".
1976 "$data\n" ) if $conf::db_maint;
1977 change_state( \$pkg, 'deleted' );
1978 log_ta( $pkg, "--forget" );
1980 print "$name: deleted from database\n" if $verbose;
1988 $ui = $db{'_userinfo'};
1989 foreach $name (@_) {
1990 if (!defined( $ui->{$name} )) {
1991 print "$name: not registered\n";
1995 delete $ui->{$name};
1997 print "$name: deleted from database\n" if $verbose;
1999 $db{'_userinfo'} = $ui if $change;
2005 my $lockfile = db_lockfilename($dist);
2008 print "Locking $dist database\n" if $verbose >= 2;
2010 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2012 # lock file exists, wait
2013 goto repeat if !open( F, "<$lockfile" );
2016 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2017 warn "Bad lock file contents -- still trying\n";
2020 my($pid, $usr) = ($1, $2);
2021 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2022 # process doesn't exist anymore, remove stale lock
2023 print "Removing stale lock file (pid $pid, user $usr)\n";
2024 unlink( $lockfile );
2027 if ($pid == $lock_for_pid) {
2028 # We are allowed to use this lock.
2031 warn "Database locked by $usr -- please wait\n" if $try == 0;
2034 # avoid the END routine removes the lock
2035 $main::keep_lock{$dist} = 1;
2036 die "Lock still present after 200 * 5 seconds.\n";
2041 die "Can't create lock file $lockfile: $!\n";
2043 my $pid = $lock_for_pid == -1 ? $$ : $lock_for_pid;
2044 F->print("$pid $real_user\n");
2050 my $lockfile = db_lockfilename($dist);
2052 if (!$main::keep_lock{$dist}) {
2053 print "Unlocking $dist database\n" if $verbose >= 2;
2058 sub create_maintlock {
2059 my $lockfile = db_lockfilename("maintenance");
2063 print "Creating maintenance lock\n" if $verbose >= 2;
2065 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2067 # lock file exists, wait
2068 goto repeat if !open( F, "<$lockfile" );
2071 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2072 warn "Bad maintenance lock file contents -- still trying\n";
2075 my($pid, $usr) = ($1, $2);
2076 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2077 # process doesn't exist anymore, remove stale lock
2078 print "Removing stale lock file (pid $pid, user $usr)\n";
2079 unlink( $lockfile );
2082 warn "Maintenance lock already exists by $usr -- ".
2083 "please wait\n" if $try == 0;
2086 die "Lock still present after 120 * 60 seconds.\n";
2091 die "Can't create maintenance lock $lockfile: $!\n";
2093 F->print(getppid(), " $real_user\n");
2097 sub remove_maintlock {
2098 my $lockfile = db_lockfilename("maintenance");
2100 print "Removing maintenance lock\n" if $verbose >= 2;
2104 sub waitfor_maintlock {
2105 my $lockfile = db_lockfilename("maintenance");
2109 print "Checking for maintenance lock\n" if $verbose >= 2;
2111 if (open( F, "<$lockfile" )) {
2114 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2115 warn "Bad maintenance lock file contents -- still trying\n";
2118 my($pid, $usr) = ($1, $2);
2119 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2120 # process doesn't exist anymore, remove stale lock
2121 print "Removing stale maintenance lock (pid $pid, user $usr)\n";
2122 unlink( $lockfile );
2125 warn "Databases locked for general maintenance by $usr -- ".
2126 "please wait\n" if $try == 0;
2129 die "Lock still present after 120 * 60 seconds.\n";
2140 print "Reading ASCII database from $file..." if $verbose >= 1;
2141 open( F, "<$file" ) or
2142 die "Can't open database $file: $!\n";
2144 local($/) = ""; # read in paragraph mode
2146 my( %thispkg, $name );
2148 s/\n[ \t]+/\376\377/g; # fix continuation lines
2149 s/\376\377\s*\376\377/\376\377/og;
2151 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2152 my ($key, $val) = ($1, $2);
2153 $val =~ s/\376\377/\n/g;
2154 $thispkg{$key} = $val;
2156 check_entry( \%thispkg );
2158 if (exists($thispkg{'Package'})) {
2159 $name = $thispkg{'Package'};
2160 $db{$name} = \%thispkg;
2162 elsif(exists($thispkg{'User'})) {
2163 my $userinfo = $db{'_userinfo'};
2164 $userinfo = {} if (!defined($userinfo));
2166 $name = $thispkg{'User'};
2167 $userinfo->{$name} = \%thispkg;
2169 $db{'_userinfo'} = $userinfo;
2173 print "done\n" if $verbose >= 1;
2180 return if $op_mode eq "manual-edit"; # no checks then
2182 # check for required fields
2183 if (exists $pkg->{'User'}) {
2186 if (!exists $pkg->{'Package'}) {
2187 print STDERR "Bad entry: ",
2188 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2189 die "Database entry lacks Package or User: field\n";
2191 if (!exists $pkg->{'Version'}) {
2192 die "Database entry for $pkg->{'Package'} lacks Version: field\n";
2194 # if no State: field, generate one (for old db compat)
2195 if (!exists($pkg->{'State'})) {
2197 exists $pkg->{'Failed'} ? 'Failed' : 'Building';
2200 die "Bad state $pkg->{'State'} of package $pkg->{Package}\n"
2201 if !isin( $pkg->{'State'},
2202 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait
2203 Failed Failed-Removed Not-For-Us BD-Uninstallable
2209 my($name,$pkg,$key);
2211 print "Writing ASCII database to $file..." if $verbose >= 1;
2212 open( F, ">$file" ) or
2213 die "Can't open database $file: $!\n";
2215 foreach $name (sort keys %db) {
2216 my $pkg = $db{$name};
2217 if ($name eq '_userinfo') {
2218 foreach $user (sort keys %{$pkg}) {
2219 my $ui = $pkg->{$user};
2220 print F "User: $user\n"
2221 if (!defined($ui->{'User'}));
2222 foreach $key (keys %{$ui}) {
2223 my $val = $ui->{$key};
2226 $val =~ s/^ $/ ./mg;
2227 print F "$key: $val\n";
2233 foreach $key (keys %{$pkg}) {
2234 my $val = $pkg->{$key};
2237 $val =~ s/^ $/ ./mg;
2238 print F "$key: $val\n";
2244 print "done\n" if $verbose >= 1;
2250 my $newstate = shift;
2251 my $for_dist = shift;
2254 return if !open_other_db( $for_dist );
2255 $db = $otherdb{$for_dist};
2256 $pkg = \$db{$pkg->{'Package'}};
2261 my $state = \$pkg->{'State'};
2263 return if defined($$state) and $$state eq $newstate;
2264 $pkg->{'Previous-State'} = $$state if defined($$state);
2265 $pkg->{'State-Change'} = $curr_date;
2267 if (defined($$state) and $$state eq 'Failed') {
2268 $pkg->{'Old-Failed'} =
2269 "-"x20 . " $pkg->{'Version'} " . "-"x20 . "\n" .
2270 $pkg->{'Failed'} . "\n" .
2271 $pkg->{'Old-Failed'};
2272 delete $pkg->{'Failed'};
2273 delete $pkg->{'Failed-Category'};
2275 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2276 delete $pkg->{'BD-Problem'};
2278 $$state = $newstate;
2284 if (!tied(%{$otherdb{$dist}})) {
2286 $otherdb_lock{$dist} = 1;
2287 if (!(tie %{$otherdb{$dist}}, 'MLDBM', db_filename($dist), 0, 0664)){
2288 warn "Serious warning: Cannot open database for $dist\n";
2290 $otherdb_lock{$dist} = 0;
2301 my $dist = $distribution;
2305 $prevstate = $pkg->{'Previous-State'};
2306 $str = "$action($dist): $pkg->{'Package'}_$pkg->{'Version'} ".
2307 "changed from $prevstate to $pkg->{'State'} ".
2308 "by $real_user as $user";
2310 my $transactlog = db_transactlog( $distribution );
2311 if (!open( LOG, ">>$transactlog" )) {
2312 warn "Can't open log file $transactlog: $!\n";
2315 print LOG "$curr_date: $str\n";
2318 if (!($prevstate eq 'Failed' && $pkg->{'State'} eq 'Failed')) {
2319 $str .= " (with --override)"
2321 $mail_logs .= "$str\n";
2328 my $subject = shift;
2331 my $from = $conf::db_maint;
2332 my $domain = $conf::buildd_domain;
2334 $from .= "\@$domain" if $from !~ /\@/;
2336 $to .= '@' . $domain if $to !~ /\@/;
2337 $text =~ s/^\.$/../mg;
2338 local $SIG{'PIPE'} = 'IGNORE';
2339 open( PIPE, "| $conf::mailprog -oem $to" )
2340 or die "Can't open pipe to $conf::mailprog: $!\n";
2342 print PIPE "From: $from\n";
2343 print PIPE "Subject: $subject\n\n";
2344 print PIPE "$text\n";
2350 return $transactional ? db_filename_transaction($dist) : db_filename_master($dist);
2352 sub db_filename_master {
2354 return "$conf::basedir/$conf::dbbase-$dist";
2356 sub db_filename_transaction {
2358 return "$conf::basedir/$conf::dbbase-$dist-transaction";
2361 sub db_lockfilename {
2363 return db_filename_master($dist) . ".lock";
2367 sub db_transactlog {
2369 return $transactional ? db_transactlog_transaction($dist) : db_transactlog_master($dist);
2371 sub db_transactlog_master {
2373 $conf::dbbase =~ m#^([^/]+/)#;
2374 return "$conf::basedir/$1$conf::transactlog";
2376 sub db_transactlog_transaction {
2378 $conf::dbbase =~ m#^([^/]+/)#;
2379 return "$conf::basedir/$1$conf::transactlog-$dist-transaction";
2382 # for parsing input to dep-wait
2388 foreach (split( /\s*,\s*/, $deps )) {
2390 # verification requires > starting prompts, no | crap
2391 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2396 my @alts = split( /\s*\|\s*/, $_ );
2397 # Anything with an | is ignored, as it can be configured on a
2398 # per-buildd basis what will be installed
2399 next if $#alts != 0;
2402 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2403 warn( "parse_deplist: bad dependency $_\n" );
2406 my($dep, $rel, $relv) = ($1, $3, $4);
2407 $rel = ">>" if defined($rel) and $rel eq ">";
2408 $result{$dep}->{'Package'} = $dep;
2409 if ($rel && $relv) {
2410 $result{$dep}->{'Rel'} = $rel;
2411 $result{$dep}->{'Version'} = $relv;
2414 return 1 if $verify;
2418 # for parsing Build-Depends from Sources
2419 sub parse_srcdeplist {
2426 foreach $dep (split( /\s*,\s*/, $deps )) {
2427 my @alts = split( /\s*\|\s*/, $dep );
2428 # Anything with an | is ignored, as it can be configured on a
2429 # per-buildd basis what will be installed
2430 next if $#alts != 0;
2432 if (!/^([^\s([]+)\s*(\(\s*([<=>]+)\s*(\S+)\s*\))?(\s*\[([^]]+)\])?/) {
2433 warn( "parse_srcdeplist: bad dependency $_\n" );
2436 my($dep, $rel, $relv, $archlist) = ($1, $3, $4, $6);
2438 $archlist =~ s/^\s*(.*)\s*$/$1/;
2439 my @archs = split( /\s+/, $archlist );
2440 my ($use_it, $ignore_it, $include) = (0, 0, 0);
2443 $ignore_it = 1 if substr($_, 1) eq $arch;
2445 $use_it = 1 if $_ eq $arch;
2449 warn "Warning: inconsistent arch restriction on ",
2450 "$pkg: $dep depedency\n"
2451 if $ignore_it && $use_it;
2452 next if $ignore_it || ($include && !$use_it);
2460 $result->{'Package'} = $dep;
2461 $result->{'Neg'} = $neg;
2462 if ($rel && $relv) {
2463 $result->{'Rel'} = $rel;
2464 $result->{'Version'} = $relv;
2466 push @results, $result;
2475 foreach $key (keys %$list) {
2476 $result .= ", " if $result;
2478 $result .= " ($list->{$key}->{'Rel'} $list->{$key}->{'Version'})"
2479 if $list->{$key}->{'Rel'} && $list->{$key}->{'Version'};
2486 tie %new_db, 'MLDBM', db_filename( $distribution ) . ".new", GDBM_WRCREAT, 0664
2487 or die "FATAL: Cannot create new database\n";
2489 untie %db or die "FATAL: Cannot untie old database\n";
2490 system ("cp " . db_filename( $distribution ) . ".new " .
2491 db_filename( $distribution ) ) == 0
2492 or die "FATAL: Cannot overwrite old database";
2493 unlink db_filename( $distribution ) . ".new";
2498 sub get_unsatisfied_dep {
2502 my $savedep = shift;
2504 my $pkgname = $dep->{'Package'};
2506 if (defined $pkgs->{$pkgname}{'Provider'}) {
2507 # provides. leave them for buildd/sbuild.
2512 return $pkgs->{$pkgname}{'Unsatisfied'} if $savedep and defined($pkgs->{$pkgname}{'Unsatisfied'});
2514 # Return unsatisfied deps to a higher caller to process
2515 if ((!defined($pkgs->{$pkgname})) or
2516 (defined($dep->{'Rel'}) and !version_compare( $pkgs->{$pkgname}{'Version'}, $dep->{'Rel'}, $dep->{'Version'} ) ) ) {
2518 $deplist{$pkgname} = $dep;
2519 my $deps = build_deplist(\%deplist);
2520 $pkgs->{$pkgname}{'Unsatisfied'} = $deps if $savedep;
2524 # set cache to "" to avoid infinite recursion
2525 $pkgs->{$pkgname}{'Unsatisfied'} = "" if $savedep;
2527 if (defined $pkgs->{$dep->{'Package'}}{'Depends'}) {
2528 my $deps = parse_deplist( $pkgs->{$dep->{'Package'}}{'Depends'} );
2529 foreach (keys %$deps) {
2532 my $ret = get_unsatisfied_dep($bd,$pkgs,$dep,1);
2534 my $retdep = parse_deplist( $ret );
2535 foreach (keys %$retdep) {
2536 $dep = $$retdep{$_};
2538 $dep->{'Rel'} = '>=' if defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^=';
2540 if (defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>' and defined ($pkgs->{$dep->{'Package'}}) and
2541 version_compare($bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'ver'},'>>',$pkgs->{$dep->{'Package'}}{'Sourcev'})) {
2542 if (not defined($merge_binsrc{$dep->{'Package'}})) {
2543 # the uninstallable package doesn't exist in the new source; look for something else that does.
2544 delete $$retdep{$dep->{'Package'}};
2545 foreach (sort (split( /\s*,\s*/, $bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'bin'}))) {
2546 next if ($pkgs->{$_}{'all'} or not defined $pkgs->{$_}{'Version'});
2547 $dep->{'Package'} = $_;
2548 $dep->{'Rel'} = '>>';
2549 $dep->{'Version'} = $pkgs->{$_}{'Version'};
2550 $$retdep{$_} = $dep;
2555 # sanity check to make sure the depending binary still exists, and the depended binary exists and dep-wait on a new version of it
2556 if ( defined($merge_binsrc{$pkgname}) and defined($pkgs->{$dep->{'Package'}}{'Version'}) ) {
2557 delete $$retdep{$dep->{'Package'}};
2558 $dep->{'Package'} = $pkgname;
2559 $dep->{'Rel'} = '>>';
2560 $dep->{'Version'} = $pkgs->{$pkgname}{'Version'};
2561 $$retdep{$pkgname} = $dep;
2563 delete $$retdep{$dep->{'Package'}} if (defined ($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>');
2566 $ret = build_deplist($retdep);
2567 $pkgs->{$pkgname}{'Unsatisfied'} = $ret if $savedep;
2575 sub call_edos_depcheck {
2576 my $packagesfile = shift;
2580 return if defined ($conf::distributions{$distribution}{noadw});
2582 # We need to check all of needs-build, as any new upload could make
2583 # something in needs-build have uninstallable deps
2584 # We also check everything in bd-uninstallable, as any new upload could
2585 # make that work again
2586 my %interesting_packages;
2587 foreach $key (keys %db) {
2588 my $pkg = $db{$key};
2589 if (defined $pkg and isin($pkg->{'State'}, qw/Needs-Build BD-Uninstallable/)) {
2590 $interesting_packages{$key} = undef;
2594 #print "I would look at these sources with edos-depcheck:\n";
2595 #print join " ", keys %interesting_packages,"\n";
2597 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2599 for( $i = 0;; ++$i ) {
2600 $tmpfile = $tmpfile_pattern . $i;
2601 last if ! -e $tmpfile;
2604 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2605 for my $key (keys %interesting_packages) {
2606 my $pkg = $db{$key};
2607 print SOURCES "Package: $key\n";
2608 print SOURCES "Version: $pkg->{'Version'}\n";
2609 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2610 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2611 print SOURCES "Architecture: all\n";
2616 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2618 local($/) = ""; # read in paragraph mode
2620 my( $key, $reason ) ;
2622 /^Package:\s*(\S+)$/mi and $key = $1;
2623 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2624 $reason =~ s/^\s*//mg;
2625 $reason ||= 'No reason given by edos-debcheck';
2627 if (exists $interesting_packages{$key}) {
2628 $interesting_packages{$key} = $reason;
2630 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2635 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2636 "all packages have installable build-dependencies."
2641 for my $key (keys %interesting_packages) {
2642 my $pkg = $db{$key};
2644 (defined $interesting_packages{$key} and $pkg->{'State'} eq 'Needs-Build') ||
2645 (not defined $interesting_packages{$key} and $pkg->{'State'} eq 'BD-Uninstallable');
2647 if (defined $interesting_packages{$key}) {
2648 change_state( \$pkg, 'BD-Uninstallable' );
2649 $pkg->{'BD-Problem'} = $interesting_packages{$key};
2651 change_state( \$pkg, 'Needs-Build' );
2653 log_ta( $pkg, "--merge-all" );
2655 print "edos-builddebchange changed state of ${key}_$pkg->{'Version'} to $pkg->{'State'}\n" if $verbose;
2662 ($prgname = $0) =~ s,^.*/,,;
2664 Usage: $prgname <options...> <package_version...>
2666 -v, --verbose: Verbose execution.
2667 --take: Take package for building [default operation]
2668 -f, --failed: Record in database that a build failed due to
2669 deficiencies in the package (that aren't fixable without a new
2671 -u, --uploaded: Record in the database that the packages build
2672 correctly and were uploaded.
2673 -n, --no-build: Record in the database that the packages aren't
2674 desired for this architecture and shouldn't appear in listings even
2675 if they're out of date.
2676 --dep-wait: Record in the database that the packages are waiting
2677 for some source dependencies to become available
2678 --binNMU num: Schedule a re-build of the package with unchanged source, but
2679 a new version number (source-version + "+b<num>")
2680 --give-back: Mark a package as ready to build that is in state Building,
2681 Built or Build-Attempted. To give back a package in state Failed, use
2683 --merge-quinn: Merge quinn-diff output into database.
2684 --merge-packages: Merge Packages files into database.
2685 --pretend-avail: Pretend that given packages are available now and give
2686 free packages waiting for them
2687 -i SRC_PKG, --info SRC_PKG: Show information for source package
2688 -l STATE, --list=STATE: List all packages in state STATE; can be
2689 combined with -U to restrict to a specific user; STATE can
2691 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2692 source dependency list
2693 (used with -f, --dep-wait, and --binNMU)
2694 -o, --override: Override another user's lock on a package, i.e.
2695 take it over; a notice mail will be sent to the other user
2696 -U USER, --user=USER: select user name for which listings should
2697 apply, if not given all users are listed.
2698 if -l is missing, set user name to be entered in db; usually
2699 automatically choosen
2700 --import FILE: Import database from a ASCII file FILE
2701 --export FILE: Export database to a ASCII file FILE
2702 --lock-for PID: Locks the database for the process with this pid
2703 --unlock-for PID: Unlocks the database for the process with this pid
2704 --act-on-behalf-of PID: Ignores the log (if it is held by this pid)
2705 --start-transaction: Creates a copy of the state of the database, for
2706 use with --transactional. This overrides any previous uncommited
2707 transaction. Should only be used after --lock-for
2708 --commit-transaction: Atomically moves the copy back to the main, thus
2709 commiting the changes
2710 --transactional: Flag to indicate that we want to work on the copy
2712 The remaining arguments (depending on operation) usually start with
2713 "name_version", the trailer is ignored. This allows to pass the names
2714 of .dsc files, for which file name completion can be used.
2715 --merge-packages and --merge-quinn take Package/quin--diff file names
2716 on the command line or read stdin. --list needs nothing more on the
2717 command line. --info takes source package names (without version).
2722 sub pkg_version_eq {
2724 my $version = shift;
2727 if (defined $pkg->{'Binary-NMU-Version'}) and
2728 version_compare(binNMU_version($pkg->{'Version'},
2729 $pkg->{'Binary-NMU-Version'}),'=', $version);
2730 return version_compare( $pkg->{'Version'}, "=", $version );