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 $build_deps = parse_sources(1);
449 call_edos_depcheck( $ARGS[0], $ARGS[2] );
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 "Dep-Wait") {
973 print "$name: Forcing source dependency list to be cleared\n";
976 print "$name: waiting for source dependencies. Skipping\n",
977 " (use --override to clear dependency list and ",
978 "give back anyway)\n";
982 if ($state eq "BD-Uninstallable") {
984 print "$name: Forcing uninstallability mark to be removed\n";
987 print "$name: has uninstallable build-dependencies. Skipping\n",
988 " (use --override to clear dependency list and ",
989 "give back anyway)\n";
993 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
994 print "$name: not taken for building (state is $state).";
996 print "\n$name: Forcing give-back\n";
999 print " Skipping.\n";
1003 if (defined ($pkg->{'Builder'}) && $user ne $pkg->{'Builder'} &&
1004 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user)) {
1005 print "$name: not taken by you, but by ".
1006 "$pkg->{'Builder'}. Skipping.\n";
1009 if (!pkg_version_eq($pkg, $version)) {
1010 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1014 change_state( \$pkg, 'Needs-Build' );
1015 delete $pkg->{'Builder'};
1016 delete $pkg->{'Depends'};
1017 log_ta( $pkg, "--give-back" );
1019 print "$name: given back\n" if $verbose;
1022 sub set_one_binnmu {
1024 my $version = shift;
1025 my $pkg = $db{$name};
1028 if (!defined($pkg)) {
1029 print "$name: not registered; can't register for binNMU.\n";
1032 my $db_ver = $pkg->{'Version'};
1034 if (!version_eq($db_ver, $version)) {
1035 print "$name: version mismatch ($db_ver registered). ",
1039 $state = $pkg->{'State'};
1041 if (defined $pkg->{'Binary-NMU-Version'}) {
1042 if ($binNMUver == 0) {
1043 change_state( \$pkg, 'Installed' );
1044 delete $pkg->{'Builder'};
1045 delete $pkg->{'Depends'};
1046 delete $pkg->{'Binary-NMU-Version'};
1047 delete $pkg->{'Binary-NMU-Changelog'};
1048 } elsif ($binNMUver <= $pkg->{'Binary-NMU-Version'}) {
1049 print "$name: already building binNMU $pkg->{'Binary-NMU-Version'}\n";
1052 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1053 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1054 $pkg->{'Notes'} = 'out-of-date';
1055 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'}
1056 if (defined $pkg->{'PermBuildPri'});
1058 log_ta( $pkg, "--binNMU" );
1061 } elsif ($binNMUver == 0) {
1062 print "${name}_$version: no scheduled binNMU to cancel.\n";
1066 if ($state ne 'Installed') {
1067 print "${name}_$version: not installed; can't register for binNMU.\n";
1071 my $fullver = binNMU_version($version,$binNMUver);
1072 if ( version_lesseq( $fullver, $pkg->{'Installed-Version'} ) )
1074 print "$name: binNMU $fullver is not newer than current version $pkg->{'Installed-Version'}\n";
1078 change_state( \$pkg, 'Needs-Build' );
1079 delete $pkg->{'Builder'};
1080 delete $pkg->{'Depends'};
1081 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1082 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1083 $pkg->{'Notes'} = 'out-of-date';
1084 log_ta( $pkg, "--binNMU" );
1086 print "${name}: registered for binNMU $fullver\n" if $verbose;
1089 sub set_one_buildpri {
1091 my $version = shift;
1093 my $pkg = $db{$name};
1096 if (!defined($pkg)) {
1097 print "$name: not registered; can't set priority.\n";
1100 $state = $pkg->{'State'};
1102 if ($state eq "Not-For-Us") {
1103 print "$name: not suitable for this architecture. Skipping.\n";
1105 } elsif ($state eq "Failed-Removed") {
1106 print "$name: failed previously and doesn't need building. Skipping.\n";
1109 if (!pkg_version_eq($pkg, $version)) {
1110 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1114 if ( $build_priority == 0 ) {
1115 delete $pkg->{'BuildPri'}
1116 if $key eq 'PermBuildPri' and defined $pkg->{'BuildPri'}
1117 and $pkg->{'BuildPri'} == $pkg->{$key};
1118 delete $pkg->{$key};
1120 $pkg->{'BuildPri'} = $build_priority
1121 if $key eq 'PermBuildPri';
1122 $pkg->{$key} = $build_priority;
1125 print "$name: set to build priority $build_priority\n" if $verbose;
1128 sub add_one_depwait {
1130 my $version = shift;
1132 my $pkg = $db{$name};
1134 if (!defined($pkg)) {
1135 print "$name: not registered yet.\n";
1138 $state = $pkg->{'State'};
1140 if ($state eq "Dep-Wait") {
1141 print "$name: merging with previously registered dependencies\n";
1144 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1145 print "$name: Warning: not registered for building previously, ".
1146 "but processing anyway.\n";
1148 elsif ($state eq "Not-For-Us") {
1149 print "$name: not suitable for this architecture anyway. Skipping.\n";
1152 elsif ($state eq "Failed-Removed") {
1153 print "$name: failed previously and doesn't need building. Skipping.\n";
1156 elsif ($state eq "Installed") {
1157 print "$name: Is already installed in archive. Skipping.\n";
1160 elsif ($state eq "Uploaded") {
1161 print "$name: Is already uploaded. Skipping.\n";
1164 elsif ($pkg->{'Builder'} &&
1165 $user ne $pkg->{'Builder'}) {
1166 print "$name: not taken by you, but by ".
1167 "$pkg->{'Builder'}. Skipping.\n";
1170 elsif ( !pkg_version_eq($pkg,$version)) {
1171 print "$name: version mismatch ".
1172 "($pkg->{'Version'} ".
1173 "by $pkg->{'Builder'})\n";
1176 elsif ($fail_reason =~ /^\s*$/ ||
1177 !parse_deplist( $fail_reason, 1 )) {
1178 print "$name: Bad dependency list\n";
1181 change_state( \$pkg, 'Dep-Wait' );
1182 $pkg->{'Builder'} = $user;
1183 if (defined $pkg->{'PermBuildPri'}) {
1184 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1186 delete $pkg->{'BuildPri'};
1188 my $deplist = parse_deplist( $pkg->{'Depends'} );
1189 my $new_deplist = parse_deplist( $fail_reason );
1190 # add new dependencies, maybe overwriting old entries
1191 foreach (keys %$new_deplist) {
1192 $deplist->{$_} = $new_deplist->{$_};
1194 $pkg->{'Depends'} = build_deplist($deplist);
1195 log_ta( $pkg, "--dep-wait" );
1197 print "$name: registered as waiting for dependencies\n" if $verbose;
1207 local($/) = ""; # read in paragraph mode
1209 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1211 /^Package:\s*(\S+)$/mi and $name = $1;
1212 /^Version:\s*(\S+)$/mi and $version = $1;
1213 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1214 /^Section:\s*(\S+)$/mi and $section = $1;
1215 /^Priority:\s*(\S+)$/mi and $priority = $1;
1216 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1217 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1218 /^Binary:\s*(.*)$/mi and $binaries = $1;
1220 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1221 $srcver{$name} = $version;
1223 $pkgs{$name}{'ver'} = $version;
1224 $pkgs{$name}{'bin'} = $binaries;
1225 my $pkg = $db{$name};
1230 if ($arch eq "all" && !version_less( $version, $pkg->{'Version'} )) {
1231 # package is now Arch: all, delete it from db
1232 change_state( \$pkg, 'deleted' );
1233 log_ta( $pkg, "--merge-sources" );
1234 print "$name ($pkg->{'Version'}): deleted ".
1235 "from database, because now Arch: all\n"
1241 # The "Version" should always be the source version --
1242 # not a possible binNMU version number.
1243 $pkg->{'Version'} = $version, $change++
1244 if ($pkg->{'State'} eq 'Installed' and
1245 !version_eq( $pkg->{'Version'}, $version));
1246 # Always update priority and section, if available
1247 $pkg->{'Priority'} = $priority, $change++
1248 if defined $priority and (not defined($pkg->{'Priority'}) or $pkg->{'Priority'} ne $priority);
1250 $pkg->{'Section'} = $section, $change++
1251 if defined $section and (not defined($pkg->{'Section'}) or $pkg->{'Section'} ne $section);
1253 # Store Build-Deps and Build-Conflicts for edos-debcheck later
1254 $pkg->{'Build-Depends'} = $builddep, $change++
1255 if ($pkg->{'Build-Depends'} ne $builddep);
1256 $pkg->{'Build-Conflicts'} = $buildconf, $change++
1257 if ($pkg->{'Build-Conflicts'} ne $buildconf);
1259 $db{$name} = $pkg if $change;
1262 # Now that we only have the latest source version, build the list
1263 # of binary packages from the Sources point of view
1264 foreach $name (keys %pkgs) {
1265 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1266 $merge_binsrc{$bin} = $name;
1269 # remove installed packages that no longer have source available
1270 # or binaries installed
1271 foreach $name (keys %db) {
1272 next if $name =~ /^_/;
1273 my $pkg = $db{$name};
1274 if (not defined($pkgs{$name})) {
1275 change_state( \$pkg, 'deleted' );
1276 log_ta( $pkg, "--merge-sources" );
1277 print "$name ($pkg->{'Version'}): ".
1278 "deleted from database, because ".
1279 "not in Sources anymore\n"
1283 next if !isin( $pkg->{'State'}, qw(Installed) );
1284 if ($full && not defined $merge_srcvers{$name}) {
1285 change_state( \$pkg, 'deleted' );
1286 log_ta( $pkg, "--merge-sources" );
1287 print "$name ($pkg->{'Version'}): ".
1288 "deleted from database, because ".
1289 "binaries don't exist anymore\n"
1292 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'Version'})) {
1293 print "$name ($pkg->{'Version'}): ".
1294 "package is Installed but binaries are from ".
1295 $merge_srcvers{$name}. "\n"
1303 # This function looks through a Packages file and sets the state of
1304 # packages to 'Installed'
1305 sub parse_packages {
1308 local($/) = ""; # read in paragraph mode
1310 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1312 /^Package:\s*(\S+)$/mi and $name = $1;
1313 /^Version:\s*(\S+)$/mi and $version = $1;
1314 /^Depends:\s*(.*)$/mi and $depends = $1;
1315 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1316 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1317 /^Provides:\s*(.*)$/mi and $provides = $1;
1318 next if !$name || !$version;
1319 next if ($arch ne $architecture and $architecture ne "all");
1320 next if (defined ($installed->{$name}) and $installed->{$name}{'Version'} ne "" and
1321 version_lesseq( $version, $installed->{$name}{'Version'} ));
1322 $installed->{$name}{'Version'} = $version;
1323 $installed->{$name}{'Depends'} = $depends;
1324 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1325 undef $installed->{$name}{'Provider'};
1326 $installed->{$name}{'Source'} = $source ? $source : $name;
1328 foreach (split( /\s*,\s*/, $provides )) {
1329 if (not defined ($installed->{$_})) {
1330 $installed->{$_}{'Version'} = "";
1331 $installed->{$_}{'Provider'} = $name;
1335 if ( $version =~ /\+b(\d+)$/ ) {
1338 $version = $sourcev if $sourcev;
1339 $binaryv = $version;
1340 $binaryv =~ s/\+b\d+$//;
1341 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1342 $binaryv .= "+b$binnmu" if defined($binnmu);
1344 next if $architecture ne $arch;
1345 $name = $source if $source;
1346 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1347 $merge_srcvers{$name} = $version;
1349 my $pkg = $db{$name};
1352 if (isin( $pkg->{'State'}, qw(Not-For-Us)) ||
1353 (isin($pkg->{'State'}, qw(Installed)) &&
1354 version_lesseq($binaryv, $pkg->{'Installed-Version'}))) {
1355 print "Skipping $name because State == $pkg->{'State'}\n"
1359 if ($pkg->{'Binary-NMU-Version'} ) {
1360 my $nmuver = binNMU_version($pkg->{'Version'}, $pkg->{'Binary-NMU-Version'});
1361 if (version_less( $binaryv, $nmuver )) {
1362 print "Skipping $name ($version) because have newer ".
1363 "version ($nmuver) in db.\n"
1367 } elsif (version_less($version, $pkg->{'Version'})) {
1368 print "Skipping $name ($version) because have newer ".
1369 "version ($pkg->{'Version'}) in db.\n"
1374 if (!pkg_version_eq($pkg, $version) &&
1375 $pkg->{'State'} ne "Installed") {
1376 warn "Warning: $name: newer version than expected appeared ".
1377 "in archive ($version vs. $pkg->{'Version'})\n";
1378 delete $pkg->{'Builder'};
1381 if (!isin( $pkg->{'State'}, qw(Uploaded) )) {
1382 warn "Warning: Package $name was not in uploaded state ".
1383 "before (but in '$pkg->{'State'}').\n";
1384 delete $pkg->{'Builder'};
1385 delete $pkg->{'Depends'};
1389 $pkg->{'Version'} = $version;
1392 change_state( \$pkg, 'Installed' );
1393 $pkg->{'Package'} = $name;
1394 $pkg->{'Installed-Version'} = $binaryv;
1395 if (defined $pkg->{'PermBuildPri'}) {
1396 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1398 delete $pkg->{'BuildPri'};
1400 $pkg->{'Version'} = $version
1401 if version_less( $pkg->{'Version'}, $version);
1402 delete $pkg->{'Binary-NMU-Version'};
1403 delete $pkg->{'Binary-NMU-Changelog'};
1404 log_ta( $pkg, "--merge-packages" );
1406 print "$name ($version) is up-to-date now.\n" if $verbose;
1409 check_dep_wait( "--merge-packages", $installed );
1414 my ($package, $name, $version, $installed);
1416 foreach $package (@_) {
1417 $package =~ s,^.*/,,; # strip path
1418 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1419 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1420 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1421 ($name,$version) = ($1,$2);
1424 warn "$package: can't extract package name and version ".
1428 $installed->{$name}{'Version'} = $version;
1431 check_dep_wait( "--pretend-avail", $installed );
1434 sub check_dep_wait {
1436 my $installed = shift;
1438 # check all packages in state Dep-Wait if dependencies are all
1441 foreach $name (keys %db) {
1442 next if $name =~ /^_/;
1443 my $pkg = $db{$name};
1444 next if $pkg->{'State'} ne "Dep-Wait";
1445 my $deps = $pkg->{'Depends'};
1447 print "$name: was in state Dep-Wait, but with empty ",
1449 goto make_needs_build;
1451 my $deplist = parse_deplist($deps);
1455 foreach (keys %$deplist) {
1456 if (!exists $installed->{$_} ||
1457 ($deplist->{$_}->{'Rel'} && $deplist->{$_}->{'Version'} &&
1458 !version_compare( $installed->{$_}{'Version'},
1459 $deplist->{$_}->{'Rel'},
1460 $deplist->{$_}->{'Version'}))) {
1462 $new_deplist->{$_} = $deplist->{$_};
1465 push( @removed_deps, $_ );
1470 change_state( \$pkg, 'Needs-Build' );
1471 log_ta( $pkg, $action );
1472 delete $pkg->{'Builder'};
1473 delete $pkg->{'Depends'};
1474 print "$name ($pkg->{'Version'}) has all ",
1475 "dependencies available now\n" if $verbose;
1479 elsif (@removed_deps) {
1480 $pkg->{'Depends'} = build_deplist( $new_deplist );
1481 print "$name ($pkg->{'Version'}): some dependencies ",
1482 "(@removed_deps) available now, but not all yet\n"
1489 # This function accepts quinn-diff output (either from a file named on
1490 # the command line, or on stdin) and sets the packages named there to
1491 # state 'Needs-Build'.
1492 sub parse_quinn_diff {
1493 my $partial = shift;
1499 next if !m,^([-\w\d/]*)/ # section
1500 ([-\w\d.+]+)_ # package name
1501 ([\w\d:.~+-]+)\.dsc\s* # version
1502 \[([^:]*): # priority
1503 ([^]]+)\]\s*$,x; # rest of notes
1504 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1505 $quinn_pkgs{$name}++;
1506 $section ||= "unknown";
1507 $priority ||= "unknown";
1508 $priority = "unknown" if $priority eq "-";
1509 $priority = "standard" if ($name eq "debian-installer");
1511 my $pkg = $db{$name};
1513 # Always update section and priority.
1514 if (defined($pkg)) {
1516 $pkg->{'Section'} = $section, $change++ if not defined
1517 $pkg->{'Section'} or $section ne "unknown";
1518 $pkg->{'Priority'} = $priority, $change++ if not defined
1519 $pkg->{'Priority'} or $priority ne "unknown";
1522 if (defined($pkg) &&
1523 $pkg->{'State'} =~ /^Dep-Wait/ &&
1524 version_less( $pkg->{'Version'}, $version )) {
1525 change_state( \$pkg, 'Dep-Wait' );
1526 $pkg->{'Version'} = $version;
1527 delete $pkg->{'Binary-NMU-Version'};
1528 delete $pkg->{'Binary-NMU-Changelog'};
1529 log_ta( $pkg, "--merge-quinn" );
1531 print "$name ($version) still waiting for dependencies.\n"
1534 elsif (defined($pkg) &&
1535 $pkg->{'State'} =~ /-Removed$/ &&
1536 version_eq($pkg->{'Version'}, $version)) {
1537 # reinstantiate a package that has been removed earlier
1538 # (probably due to a quinn-diff malfunction...)
1539 my $newstate = $pkg->{'State'};
1540 $newstate =~ s/-Removed$//;
1541 change_state( \$pkg, $newstate );
1542 $pkg->{'Version'} = $version;
1543 $pkg->{'Notes'} = $notes;
1544 log_ta( $pkg, "--merge-quinn" );
1546 print "$name ($version) reinstantiated to $newstate.\n"
1549 elsif (defined($pkg) &&
1550 $pkg->{'State'} eq "Not-For-Us" &&
1551 version_less( $pkg->{'Version'}, $version )) {
1552 # for Not-For-Us packages just update the version etc., but
1554 change_state( \$pkg, "Not-For-Us" );
1555 $pkg->{'Package'} = $name;
1556 $pkg->{'Version'} = $version;
1557 $pkg->{'Notes'} = $notes;
1558 delete $pkg->{'Builder'};
1559 log_ta( $pkg, "--merge-quinn" );
1561 print "$name ($version) still Not-For-Us.\n" if $verbose;
1563 elsif (!defined($pkg) ||
1564 $pkg->{'State'} ne "Not-For-Us" &&
1565 (version_less( $pkg->{'Version'}, $version ) ||
1566 ($pkg->{'State'} eq "Installed" && version_less($pkg->{'Installed-Version'}, $version)))) {
1568 if (defined( $pkg->{'State'} ) && isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
1569 send_mail( $pkg->{'Builder'},
1570 "new version of $name (dist=$distribution)",
1571 "As far as I'm informed, you're currently ".
1572 "building the package $name\n".
1573 "in version $pkg->{'Version'}.\n\n".
1574 "Now there's a new source version $version. ".
1575 "If you haven't finished\n".
1576 "compiling $name yet, you can stop it to ".
1577 "save some work.\n".
1578 "Just to inform you...\n".
1579 "(This is an automated message)\n" );
1580 print "$name: new version ($version) while building ".
1581 "$pkg->{'Version'} -- sending mail ".
1582 "to builder ($pkg->{'Builder'})\n"
1585 change_state( \$pkg, 'Needs-Build' );
1586 $pkg->{'Package'} = $name;
1587 $pkg->{'Version'} = $version;
1588 $pkg->{'Section'} = $section;
1589 $pkg->{'Priority'} = $priority;
1590 $pkg->{'Notes'} = $notes;
1591 delete $pkg->{'Builder'};
1592 delete $pkg->{'Binary-NMU-Version'};
1593 delete $pkg->{'Binary-NMU-Changelog'};
1594 log_ta( $pkg, "--merge-quinn" );
1597 print "$name ($version) needs rebuilding now.\n" if $verbose;
1599 elsif (defined($pkg) &&
1600 !version_eq( $pkg->{'Version'}, $version ) &&
1601 isin( $pkg->{'State'}, qw(Installed Not-For-Us) )) {
1602 print "$name: skipping because version in db ".
1603 "($pkg->{'Version'}) is >> than ".
1604 "what quinn-diff says ($version) ".
1605 "(state is $pkg->{'State'})\n"
1607 $dubious .= "$pkg->{'State'}: ".
1608 "db ${name}_$pkg->{'Version'} >> ".
1609 "quinn $version\n" if !$partial;
1611 elsif ($verbose >= 2) {
1612 if ($pkg->{'State'} eq "Not-For-Us") {
1613 print "Skipping $name because State == ".
1614 "$pkg->{'State'}\n";
1616 elsif (!version_less($pkg->{'Version'}, $version)) {
1617 print "Skipping $name because version in db ".
1618 "($pkg->{'Version'}) is >= than ".
1619 "what quinn-diff says ($version)\n";
1622 $db{$name} = $pkg if $change;
1626 send_mail( $conf::db_maint,
1627 "Dubious versions in $distribution $conf::dbbase database",
1628 "The following packages have a newer version in the ".
1629 "wanna-build database\n".
1630 "than what quinn-diff says, and this is strange for ".
1632 "It could be caused by a lame mirror, or the version ".
1633 "in the database\n".
1638 # Now re-check the DB for packages in states Needs-Build, Failed,
1639 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1640 # anymore by quinn-diff.
1643 foreach $name (keys %db) {
1644 next if $name =~ /^_/;
1645 my $pkg = $db{$name};
1646 next if defined $pkg->{'Binary-NMU-Version'};
1647 next if !isin( $pkg->{'State'},
1648 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1649 my $virtual_delete = $pkg->{'State'} eq 'Failed';
1651 if (!$quinn_pkgs{$name}) {
1652 change_state( \$pkg, $virtual_delete ?
1653 $pkg->{'State'}."-Removed" :
1655 log_ta( $pkg, "--merge-quinn" );
1656 print "$name ($pkg->{'Version'}): ".
1657 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1658 "from database, because not in quinn-diff anymore\n"
1660 if ($virtual_delete) {
1670 sub send_reupload_mail {
1673 my $version = shift;
1675 my $other_dist = shift;
1678 "Please reupload ${pkg}_${'Version'} for $dist",
1679 "You have recently built (or are currently building)\n".
1680 "${pkg}_${'Version'} for $other_dist.\n".
1681 "This version is now also needed in the $dist distribution.\n".
1682 "Please reupload the files now present in the Debian archive\n".
1683 "(best with buildd-reupload).\n" );
1687 # for sorting priorities and sections
1689 %prioval = ( required => -5,
1697 'debian-installer' => -199,
1718 localizations => -178,
1719 interpreters => -177,
1744 electronics => -152,
1750 foreach my $i (keys %sectval) {
1751 $sectval{"contrib/$i"} = $sectval{$i}+40;
1752 $sectval{"non-free/$i"} = $sectval{$i}+80;
1754 $sectval{'unknown'} = -165;
1756 %catval = ( "none" => -20,
1757 "uploaded-fixed-pkg" => -19,
1758 "fix-expected" => -18,
1759 "reminder-sent" => -17,
1760 "nmu-offered" => -16,
1764 "compiler-error" => -12 );
1767 sub sort_list_func {
1768 my( $letter, $x, $ax, $bx );
1770 foreach $letter (split( "", $list_order )) {
1771 SWITCH: foreach ($letter) {
1773 $x = $b->{'BuildPri'} <=> $a->{'BuildPri'};
1774 return $x if $x != 0;
1778 $x = $prioval{$a->{'Priority'}} <=> $prioval{$b->{'Priority'}};
1779 return $x if $x != 0;
1783 $x = $sectval{$a->{'Section'}} <=> $sectval{$b->{'Section'}};
1784 return $x if $x != 0;
1788 $x = $a->{'Package'} cmp $b->{'Package'};
1789 return $x if $x != 0;
1793 $x = $a->{'Builder'} cmp $b->{'Builder'};
1794 return $x if $x != 0;
1798 $ax = ($a->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1799 ($a->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1800 $bx = ($b->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1801 ($b->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1803 return $x if $x != 0;
1807 my $ca = exists $a->{'Failed-Category'} ?
1808 $a->{'Failed-Category'} : "none";
1809 my $cb = exists $b->{'Failed-Category'} ?
1810 $b->{'Failed-Category'} : "none";
1811 $x = $catval{$ca} <=> $catval{$cb};
1812 return $x if $x != 0;
1816 my $pa = $prioval{$a->{'Priority'}} >
1817 $prioval{'standard'};
1818 my $pb = $prioval{$b->{'Priority'}} >
1819 $prioval{'standard'};
1821 return $x if $x != 0;
1831 my( $name, $pkg, @list );
1836 foreach $name (keys %db) {
1837 next if $name =~ /^_/;
1839 next if $state ne "all" && $pkg->{'State'} !~ /^\Q$state\E$/i;
1840 next if $user && (lc($state) ne 'needs-build' and $pkg->{'Builder'} ne $user);
1841 next if $category && $pkg->{'State'} eq "Failed" &&
1842 $pkg->{'Failed-Category'} ne $category;
1843 next if ($list_min_age > 0 &&
1844 ($ctime-parse_date($pkg->{'State-Change'})) < $list_min_age)||
1845 ($list_min_age < 0 &&
1846 ($ctime-parse_date($pkg->{'State-Change'})) > -$list_min_age);
1847 push( @list, $pkg );
1850 foreach $pkg (sort sort_list_func @list) {
1851 print "$pkg->{'Section'}/$pkg->{'Package'}_$pkg->{'Version'}";
1852 print ": $pkg->{'State'}"
1854 print " by $pkg->{'Builder'}"
1855 if $pkg->{'State'} ne "Needs-Build" && $pkg->{'Builder'};
1856 print " [$pkg->{'Priority'}:$pkg->{'Notes'}";
1857 print ":PREV-FAILED"
1858 if $pkg->{'Previous-State'} =~ /^Failed/;
1859 print ":bp{" . $pkg->{'BuildPri'} . "}"
1860 if exists $pkg->{'BuildPri'};
1861 print ":binNMU{" . $pkg->{'Binary-NMU-Version'} . "}"
1862 if exists $pkg->{'Binary-NMU-Version'};
1864 print " Reasons for failing:\n",
1866 exists $pkg->{'Failed-Category'} ? $pkg->{'Failed-Category'} : "none",
1868 join("\n ",split("\n",$pkg->{'Failed'})), "\n"
1869 if $pkg->{'State'} =~ /^Failed/;
1870 print " Dependencies: $pkg->{'Depends'}\n"
1871 if $pkg->{'State'} eq "Dep-Wait";
1872 print " Reason: $pkg->{'Reason'}\n"
1873 if $pkg->{'State'} eq "BD-Uninstallable";
1874 print " Previous state was $pkg->{'Previous-State'} until ",
1875 "$pkg->{'State-Change'}\n"
1876 if $verbose && $pkg->{'Previous-State'};
1877 print " Previous failing reasons:\n ",
1878 join("\n ",split("\n",$pkg->{'Old-Failed'})), "\n"
1879 if $verbose && $pkg->{'Old-Failed'};
1881 $scnt{$pkg->{'State'}}++ if $state eq "all";
1883 if ($state eq "all") {
1884 foreach (sort keys %scnt) {
1885 print "Total $scnt{$_} package(s) in state $_.\n";
1888 print "Total $cnt package(s)\n";
1893 my( $name, $pkg, $key, $dist );
1894 my @firstkeys = qw(Package Version Builder State Section Priority
1895 Installed-Version Previous-State State-Change);
1896 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1898 foreach $dist (@dists) {
1899 if ($dist ne $distribution) {
1900 if (!-f db_filename( $dist ) || !open_other_db( $dist )) {
1901 warn "Cannot open database for $dist!\n";
1902 @dists = grep { $_ ne $dist } @dists;
1907 foreach $name (@_) {
1908 $name =~ s/_.*$//; # strip version
1909 foreach $dist (@dists) {
1910 my $db = $dist ne $distribution ? $otherdb{$dist} : \%db;
1911 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1913 $pkg = $db->{$name};
1914 if (!defined( $pkg )) {
1915 print "$pname: not registered\n";
1920 foreach $key (@firstkeys) {
1921 next if !exists $pkg->{$key};
1922 my $val = $pkg->{$key};
1924 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1926 printf " %-20s: %s\n", $key, $val;
1928 foreach $key (sort keys %$pkg) {
1929 next if isin( $key, @firstkeys );
1930 my $val = $pkg->{$key};
1932 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1934 printf " %-20s: %s\n", $key, $val;
1940 sub forget_packages {
1941 my( $name, $pkg, $key, $data );
1943 foreach $name (@_) {
1944 $name =~ s/_.*$//; # strip version
1946 if (!defined( $pkg )) {
1947 print "$name: not registered\n";
1952 foreach $key (sort keys %$pkg) {
1953 my $val = $pkg->{$key};
1956 $data .= sprintf " %-20s: %s\n", $key, $val;
1958 send_mail( $conf::db_maint,
1959 "$name deleted from DB $conf::dbbase",
1960 "The package '$name' has been deleted from the database ".
1962 "Data registered about the deleted package:\n".
1963 "$data\n" ) if $conf::db_maint;
1964 change_state( \$pkg, 'deleted' );
1965 log_ta( $pkg, "--forget" );
1967 print "$name: deleted from database\n" if $verbose;
1975 $ui = $db{'_userinfo'};
1976 foreach $name (@_) {
1977 if (!defined( $ui->{$name} )) {
1978 print "$name: not registered\n";
1982 delete $ui->{$name};
1984 print "$name: deleted from database\n" if $verbose;
1986 $db{'_userinfo'} = $ui if $change;
1992 my $lockfile = db_lockfilename($dist);
1995 print "Locking $dist database\n" if $verbose >= 2;
1997 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
1999 # lock file exists, wait
2000 goto repeat if !open( F, "<$lockfile" );
2003 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2004 warn "Bad lock file contents -- still trying\n";
2007 my($pid, $usr) = ($1, $2);
2008 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2009 # process doesn't exist anymore, remove stale lock
2010 print "Removing stale lock file (pid $pid, user $usr)\n";
2011 unlink( $lockfile );
2014 if ($pid == $lock_for_pid) {
2015 # We are allowed to use this lock.
2018 warn "Database locked by $usr -- please wait\n" if $try == 0;
2021 # avoid the END routine removes the lock
2022 $main::keep_lock{$dist} = 1;
2023 die "Lock still present after 200 * 5 seconds.\n";
2028 die "Can't create lock file $lockfile: $!\n";
2030 my $pid = $lock_for_pid == -1 ? $$ : $lock_for_pid;
2031 F->print("$pid $real_user\n");
2037 my $lockfile = db_lockfilename($dist);
2039 if (!$main::keep_lock{$dist}) {
2040 print "Unlocking $dist database\n" if $verbose >= 2;
2045 sub create_maintlock {
2046 my $lockfile = db_lockfilename("maintenance");
2050 print "Creating maintenance lock\n" if $verbose >= 2;
2052 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2054 # lock file exists, wait
2055 goto repeat if !open( F, "<$lockfile" );
2058 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2059 warn "Bad maintenance lock file contents -- still trying\n";
2062 my($pid, $usr) = ($1, $2);
2063 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2064 # process doesn't exist anymore, remove stale lock
2065 print "Removing stale lock file (pid $pid, user $usr)\n";
2066 unlink( $lockfile );
2069 warn "Maintenance lock already exists by $usr -- ".
2070 "please wait\n" if $try == 0;
2073 die "Lock still present after 120 * 60 seconds.\n";
2078 die "Can't create maintenance lock $lockfile: $!\n";
2080 F->print(getppid(), " $real_user\n");
2084 sub remove_maintlock {
2085 my $lockfile = db_lockfilename("maintenance");
2087 print "Removing maintenance lock\n" if $verbose >= 2;
2091 sub waitfor_maintlock {
2092 my $lockfile = db_lockfilename("maintenance");
2096 print "Checking for maintenance lock\n" if $verbose >= 2;
2098 if (open( F, "<$lockfile" )) {
2101 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2102 warn "Bad maintenance lock file contents -- still trying\n";
2105 my($pid, $usr) = ($1, $2);
2106 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2107 # process doesn't exist anymore, remove stale lock
2108 print "Removing stale maintenance lock (pid $pid, user $usr)\n";
2109 unlink( $lockfile );
2112 warn "Databases locked for general maintenance by $usr -- ".
2113 "please wait\n" if $try == 0;
2116 die "Lock still present after 120 * 60 seconds.\n";
2127 print "Reading ASCII database from $file..." if $verbose >= 1;
2128 open( F, "<$file" ) or
2129 die "Can't open database $file: $!\n";
2131 local($/) = ""; # read in paragraph mode
2133 my( %thispkg, $name );
2135 s/\n[ \t]+/\376\377/g; # fix continuation lines
2136 s/\376\377\s*\376\377/\376\377/og;
2138 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2139 my ($key, $val) = ($1, $2);
2140 $val =~ s/\376\377/\n/g;
2141 $thispkg{$key} = $val;
2143 check_entry( \%thispkg );
2145 if (exists($thispkg{'Package'})) {
2146 $name = $thispkg{'Package'};
2147 $db{$name} = \%thispkg;
2149 elsif(exists($thispkg{'User'})) {
2150 my $userinfo = $db{'_userinfo'};
2151 $userinfo = {} if (!defined($userinfo));
2153 $name = $thispkg{'User'};
2154 $userinfo->{$name} = \%thispkg;
2156 $db{'_userinfo'} = $userinfo;
2160 print "done\n" if $verbose >= 1;
2167 return if $op_mode eq "manual-edit"; # no checks then
2169 # check for required fields
2170 if (exists $pkg->{'User'}) {
2173 if (!exists $pkg->{'Package'}) {
2174 print STDERR "Bad entry: ",
2175 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2176 die "Database entry lacks Package or User: field\n";
2178 if (!exists $pkg->{'Version'}) {
2179 die "Database entry for $pkg->{'Package'} lacks Version: field\n";
2181 # if no State: field, generate one (for old db compat)
2182 if (!exists($pkg->{'State'})) {
2184 exists $pkg->{'Failed'} ? 'Failed' : 'Building';
2187 die "Bad state $pkg->{'State'} of package $pkg->{Package}\n"
2188 if !isin( $pkg->{'State'},
2189 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait
2190 Failed Failed-Removed Not-For-Us BD-Uninstallable
2196 my($name,$pkg,$key);
2198 print "Writing ASCII database to $file..." if $verbose >= 1;
2199 open( F, ">$file" ) or
2200 die "Can't open database $file: $!\n";
2202 foreach $name (sort keys %db) {
2203 my $pkg = $db{$name};
2204 if ($name eq '_userinfo') {
2205 foreach $user (sort keys %{$pkg}) {
2206 my $ui = $pkg->{$user};
2207 print F "User: $user\n"
2208 if (!defined($ui->{'User'}));
2209 foreach $key (keys %{$ui}) {
2210 my $val = $ui->{$key};
2213 $val =~ s/^ $/ ./mg;
2214 print F "$key: $val\n";
2220 foreach $key (keys %{$pkg}) {
2221 my $val = $pkg->{$key};
2224 $val =~ s/^ $/ ./mg;
2225 print F "$key: $val\n";
2231 print "done\n" if $verbose >= 1;
2237 my $newstate = shift;
2238 my $for_dist = shift;
2241 return if !open_other_db( $for_dist );
2242 $db = $otherdb{$for_dist};
2243 $pkg = \$db{$pkg->{'Package'}};
2248 my $state = \$pkg->{'State'};
2250 return if defined($$state) and $$state eq $newstate;
2251 $pkg->{'Previous-State'} = $$state if defined($$state);
2252 $pkg->{'State-Change'} = $curr_date;
2254 if (defined($$state) and $$state eq 'Failed') {
2255 $pkg->{'Old-Failed'} =
2256 "-"x20 . " $pkg->{'Version'} " . "-"x20 . "\n" .
2257 $pkg->{'Failed'} . "\n" .
2258 $pkg->{'Old-Failed'};
2259 delete $pkg->{'Failed'};
2260 delete $pkg->{'Failed-Category'};
2262 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2263 delete $pkg->{'Reason'};
2265 $$state = $newstate;
2271 if (!tied(%{$otherdb{$dist}})) {
2273 $otherdb_lock{$dist} = 1;
2274 if (!(tie %{$otherdb{$dist}}, 'MLDBM', db_filename($dist), 0, 0664)){
2275 warn "Serious warning: Cannot open database for $dist\n";
2277 $otherdb_lock{$dist} = 0;
2288 my $dist = $distribution;
2292 $prevstate = $pkg->{'Previous-State'};
2293 $str = "$action($dist): $pkg->{'Package'}_$pkg->{'Version'} ".
2294 "changed from $prevstate to $pkg->{'State'} ".
2295 "by $real_user as $user";
2297 my $transactlog = db_transactlog( $distribution );
2298 if (!open( LOG, ">>$transactlog" )) {
2299 warn "Can't open log file $transactlog: $!\n";
2302 print LOG "$curr_date: $str\n";
2305 if (!($prevstate eq 'Failed' && $pkg->{'State'} eq 'Failed')) {
2306 $str .= " (with --override)"
2308 $mail_logs .= "$str\n";
2315 my $subject = shift;
2318 my $from = $conf::db_maint;
2319 my $domain = $conf::buildd_domain;
2321 $from .= "\@$domain" if $from !~ /\@/;
2323 $to .= '@' . $domain if $to !~ /\@/;
2324 $text =~ s/^\.$/../mg;
2325 local $SIG{'PIPE'} = 'IGNORE';
2326 open( PIPE, "| $conf::mailprog -oem $to" )
2327 or die "Can't open pipe to $conf::mailprog: $!\n";
2329 print PIPE "From: $from\n";
2330 print PIPE "Subject: $subject\n\n";
2331 print PIPE "$text\n";
2337 return $transactional ? db_filename_transaction($dist) : db_filename_master($dist);
2339 sub db_filename_master {
2341 return "$conf::basedir/$conf::dbbase-$dist";
2343 sub db_filename_transaction {
2345 return "$conf::basedir/$conf::dbbase-$dist-transaction";
2348 sub db_lockfilename {
2350 return db_filename_master($dist) . ".lock";
2354 sub db_transactlog {
2356 return $transactional ? db_transactlog_transaction($dist) : db_transactlog_master($dist);
2358 sub db_transactlog_master {
2360 $conf::dbbase =~ m#^([^/]+/)#;
2361 return "$conf::basedir/$1$conf::transactlog";
2363 sub db_transactlog_transaction {
2365 $conf::dbbase =~ m#^([^/]+/)#;
2366 return "$conf::basedir/$1$conf::transactlog-$dist-transaction";
2369 # for parsing input to dep-wait
2375 foreach (split( /\s*,\s*/, $deps )) {
2377 # verification requires > starting prompts, no | crap
2378 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2383 my @alts = split( /\s*\|\s*/, $_ );
2384 # Anything with an | is ignored, as it can be configured on a
2385 # per-buildd basis what will be installed
2386 next if $#alts != 0;
2389 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2390 warn( "parse_deplist: bad dependency $_\n" );
2393 my($dep, $rel, $relv) = ($1, $3, $4);
2394 $rel = ">>" if defined($rel) and $rel eq ">";
2395 $result{$dep}->{'Package'} = $dep;
2396 if ($rel && $relv) {
2397 $result{$dep}->{'Rel'} = $rel;
2398 $result{$dep}->{'Version'} = $relv;
2401 return 1 if $verify;
2405 # for parsing Build-Depends from Sources
2406 sub parse_srcdeplist {
2413 foreach $dep (split( /\s*,\s*/, $deps )) {
2414 my @alts = split( /\s*\|\s*/, $dep );
2415 # Anything with an | is ignored, as it can be configured on a
2416 # per-buildd basis what will be installed
2417 next if $#alts != 0;
2419 if (!/^([^\s([]+)\s*(\(\s*([<=>]+)\s*(\S+)\s*\))?(\s*\[([^]]+)\])?/) {
2420 warn( "parse_srcdeplist: bad dependency $_\n" );
2423 my($dep, $rel, $relv, $archlist) = ($1, $3, $4, $6);
2425 $archlist =~ s/^\s*(.*)\s*$/$1/;
2426 my @archs = split( /\s+/, $archlist );
2427 my ($use_it, $ignore_it, $include) = (0, 0, 0);
2430 $ignore_it = 1 if substr($_, 1) eq $arch;
2432 $use_it = 1 if $_ eq $arch;
2436 warn "Warning: inconsistent arch restriction on ",
2437 "$pkg: $dep depedency\n"
2438 if $ignore_it && $use_it;
2439 next if $ignore_it || ($include && !$use_it);
2447 $result->{'Package'} = $dep;
2448 $result->{'Neg'} = $neg;
2449 if ($rel && $relv) {
2450 $result->{'Rel'} = $rel;
2451 $result->{'Version'} = $relv;
2453 push @results, $result;
2462 foreach $key (keys %$list) {
2463 $result .= ", " if $result;
2465 $result .= " ($list->{$key}->{'Rel'} $list->{$key}->{'Version'})"
2466 if $list->{$key}->{'Rel'} && $list->{$key}->{'Version'};
2473 tie %new_db, 'MLDBM', db_filename( $distribution ) . ".new", GDBM_WRCREAT, 0664
2474 or die "FATAL: Cannot create new database\n";
2476 untie %db or die "FATAL: Cannot untie old database\n";
2477 system ("cp " . db_filename( $distribution ) . ".new " .
2478 db_filename( $distribution ) ) == 0
2479 or die "FATAL: Cannot overwrite old database";
2480 unlink db_filename( $distribution ) . ".new";
2485 sub get_unsatisfied_dep {
2489 my $savedep = shift;
2491 my $pkgname = $dep->{'Package'};
2493 if (defined $pkgs->{$pkgname}{'Provider'}) {
2494 # provides. leave them for buildd/sbuild.
2499 return $pkgs->{$pkgname}{'Unsatisfied'} if $savedep and defined($pkgs->{$pkgname}{'Unsatisfied'});
2501 # Return unsatisfied deps to a higher caller to process
2502 if ((!defined($pkgs->{$pkgname})) or
2503 (defined($dep->{'Rel'}) and !version_compare( $pkgs->{$pkgname}{'Version'}, $dep->{'Rel'}, $dep->{'Version'} ) ) ) {
2505 $deplist{$pkgname} = $dep;
2506 my $deps = build_deplist(\%deplist);
2507 $pkgs->{$pkgname}{'Unsatisfied'} = $deps if $savedep;
2511 # set cache to "" to avoid infinite recursion
2512 $pkgs->{$pkgname}{'Unsatisfied'} = "" if $savedep;
2514 if (defined $pkgs->{$dep->{'Package'}}{'Depends'}) {
2515 my $deps = parse_deplist( $pkgs->{$dep->{'Package'}}{'Depends'} );
2516 foreach (keys %$deps) {
2519 my $ret = get_unsatisfied_dep($bd,$pkgs,$dep,1);
2521 my $retdep = parse_deplist( $ret );
2522 foreach (keys %$retdep) {
2523 $dep = $$retdep{$_};
2525 $dep->{'Rel'} = '>=' if defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^=';
2527 if (defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>' and defined ($pkgs->{$dep->{'Package'}}) and
2528 version_compare($bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'ver'},'>>',$pkgs->{$dep->{'Package'}}{'Sourcev'})) {
2529 if (not defined($merge_binsrc{$dep->{'Package'}})) {
2530 # the uninstallable package doesn't exist in the new source; look for something else that does.
2531 delete $$retdep{$dep->{'Package'}};
2532 foreach (sort (split( /\s*,\s*/, $bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'bin'}))) {
2533 next if ($pkgs->{$_}{'all'} or not defined $pkgs->{$_}{'Version'});
2534 $dep->{'Package'} = $_;
2535 $dep->{'Rel'} = '>>';
2536 $dep->{'Version'} = $pkgs->{$_}{'Version'};
2537 $$retdep{$_} = $dep;
2542 # sanity check to make sure the depending binary still exists, and the depended binary exists and dep-wait on a new version of it
2543 if ( defined($merge_binsrc{$pkgname}) and defined($pkgs->{$dep->{'Package'}}{'Version'}) ) {
2544 delete $$retdep{$dep->{'Package'}};
2545 $dep->{'Package'} = $pkgname;
2546 $dep->{'Rel'} = '>>';
2547 $dep->{'Version'} = $pkgs->{$pkgname}{'Version'};
2548 $$retdep{$pkgname} = $dep;
2550 delete $$retdep{$dep->{'Package'}} if (defined ($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>');
2553 $ret = build_deplist($retdep);
2554 $pkgs->{$pkgname}{'Unsatisfied'} = $ret if $savedep;
2562 sub call_edos_depcheck {
2563 my $packagesfile = shift;
2564 my $sourcesfile = shift;
2567 return if defined ($conf::distributions{$distribution}{noadw});
2569 # We need to check all of needs-build, as any new upload could make
2570 # something in needs-build have uninstallable deps
2571 # We also check everything in bd-uninstallable, as any new upload could
2572 # make that work again
2573 my %interesting_packages;
2574 foreach $key (keys %db) {
2575 my $pkg = $db{$key};
2576 if (defined $pkg and isin($pkg->{'State'}, qw/Needs-Build BD-Uninstallable/)) {
2577 $interesting_packages{$key} = undef;
2581 #print "I would look at these sources with edos-depcheck:\n";
2582 #print join " ", keys %interesting_packages,"\n";
2584 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2586 for( $i = 0;; ++$i ) {
2587 $tmpfile = $tmpfile_pattern . $i;
2588 last if ! -e $tmpfile;
2591 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2592 for my $key (keys %interesting_packages) {
2593 my $pkg = $db{$key};
2594 print SOURCES "Package: $key\n";
2595 print SOURCES "Version: $pkg->{'Version'}\n";
2596 print SOURCES "Build-Depends: $pkg->{'Build-Depends'}\n" if $pkg->{'Build-Depends'};
2597 print SOURCES "Build-Conflicts: $pkg->{'Build-Conflicts'}\n" if $pkg->{'Build-Conflicts'};
2598 print SOURCES "Architecture: all\n";
2603 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2605 local($/) = ""; # read in paragraph mode
2607 my( $key, $reason ) ;
2609 /^Package:\s*(\S+)$/mi and $key = $1;
2610 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2611 $reason =~ s/^\s*//mg;
2612 $reason ||= 'No reason given by edos-debcheck';
2614 if (exists $interesting_packages{$key}) {
2615 $interesting_packages{$key} = $reason;
2617 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2622 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2623 "all packages have installable build-dependencies."
2628 for my $key (keys %interesting_packages) {
2629 my $pkg = $db{$key};
2631 (defined $interesting_packages{$key} and $pkg->{'State'} eq 'Needs-Build') ||
2632 (not defined $interesting_packages{$key} and $pkg->{'State'} eq 'BD-Uninstallable');
2634 if (defined $interesting_packages{$key}) {
2635 change_state( \$pkg, 'BD-Uninstallable' );
2636 $pkg->{'Reason'} = $interesting_packages{$key};
2638 change_state( \$pkg, 'Needs-Build' );
2640 log_ta( $pkg, "--merge-all" );
2642 print "edos-builddebchange changed state of ${key}_$pkg->{'Version'} to $pkg->{'State'}\n" if $verbose;
2649 ($prgname = $0) =~ s,^.*/,,;
2651 Usage: $prgname <options...> <package_version...>
2653 -v, --verbose: Verbose execution.
2654 --take: Take package for building [default operation]
2655 -f, --failed: Record in database that a build failed due to
2656 deficiencies in the package (that aren't fixable without a new
2658 -u, --uploaded: Record in the database that the packages build
2659 correctly and were uploaded.
2660 -n, --no-build: Record in the database that the packages aren't
2661 desired for this architecture and shouldn't appear in listings even
2662 if they're out of date.
2663 --dep-wait: Record in the database that the packages are waiting
2664 for some source dependencies to become available
2665 --binNMU num: Schedule a re-build of the package with unchanged source, but
2666 a new version number (source-version + "+b<num>")
2667 --give-back: Mark a package as ready to build that is in state Building,
2668 Built or Build-Attempted. To give back a package in state Failed, use
2670 --merge-quinn: Merge quinn-diff output into database.
2671 --merge-packages: Merge Packages files into database.
2672 --pretend-avail: Pretend that given packages are available now and give
2673 free packages waiting for them
2674 -i SRC_PKG, --info SRC_PKG: Show information for source package
2675 -l STATE, --list=STATE: List all packages in state STATE; can be
2676 combined with -U to restrict to a specific user; STATE can
2678 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2679 source dependency list
2680 (used with -f, --dep-wait, and --binNMU)
2681 -o, --override: Override another user's lock on a package, i.e.
2682 take it over; a notice mail will be sent to the other user
2683 -U USER, --user=USER: select user name for which listings should
2684 apply, if not given all users are listed.
2685 if -l is missing, set user name to be entered in db; usually
2686 automatically choosen
2687 --import FILE: Import database from a ASCII file FILE
2688 --export FILE: Export database to a ASCII file FILE
2689 --lock-for PID: Locks the database for the process with this pid
2690 --unlock-for PID: Unlocks the database for the process with this pid
2691 --act-on-behalf-of PID: Ignores the log (if it is held by this pid)
2692 --start-transaction: Creates a copy of the state of the database, for
2693 use with --transactional. This overrides any previous uncommited
2694 transaction. Should only be used after --lock-for
2695 --commit-transaction: Atomically moves the copy back to the main, thus
2696 commiting the changes
2697 --transactional: Flag to indicate that we want to work on the copy
2699 The remaining arguments (depending on operation) usually start with
2700 "name_version", the trailer is ignored. This allows to pass the names
2701 of .dsc files, for which file name completion can be used.
2702 --merge-packages and --merge-quinn take Package/quin--diff file names
2703 on the command line or read stdin. --list needs nothing more on the
2704 command line. --info takes source package names (without version).
2709 sub pkg_version_eq {
2711 my $version = shift;
2714 if (defined $pkg->{'Binary-NMU-Version'}) and
2715 version_compare(binNMU_version($pkg->{'Version'},
2716 $pkg->{'Binary-NMU-Version'}),'=', $version);
2717 return version_compare( $pkg->{'Version'}, "=", $version );