3 # wanna-build: coordination script for Debian buildds
4 # Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 # Copyright (C) 2005-2008 Ryan Murray <rmurray@debian.org>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 $basedir ||= "/var/lib/debbuild";
25 $dbbase ||= "build-db";
26 $transactlog ||= "transactions.log";
27 $mailprog ||= "/usr/sbin/sendmail";
28 require "/etc/wanna-build.conf";
29 die "$conf::basedir is not a directory\n" if ! -d $conf::basedir;
30 die "dbbase is empty\n" if ! $dbbase;
31 die "transactlog is empty\n" if ! $transactlog;
32 die "mailprog binary $conf::mailprog does not exist or isn't executable\n"
33 if !-x $conf::mailprog;
34 die "no distributions defined\n" if ! %distributions;
42 use MLDBM qw(GDBM_File Storable);
45 our ($verbose, $mail_logs, $list_order, $list_state,
46 $curr_date, $op_mode, $user, $real_user, $distribution,
47 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
48 %db, %otherdb, %otherdb_lock, %prioval, %sectval,
49 $info_all_dists, $arch,
50 $category, %catval, %short_category,
51 $short_date, $list_min_age, $dbbase, @curr_time,
52 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
53 $lock_for_pid, $transactional, $read_only);
56 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
60 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
61 $short_date = strftime("%m/%d/%y",@curr_time);
63 $lock_for_pid = -1; # -1 means normal procedure
64 $transactional = 0; # 0 means: work on main copy
65 $read_only = 0; # 1 means: do not set or check lock, do never write
67 # map program invocation names to operation modes
68 my %prognames = ( "uploaded-build" => "set-uploaded",
69 "failed-build" => "set-failed",
70 "no-build" => "set-not-for-us",
71 "give-back-build" => "set-needs-build",
72 "dep-wait-build" => "set-dep-wait",
73 "forget-build" => "forget",
74 "merge-quinn" => "merge-quinn",
75 "merge-packages" => "merge-packages",
76 "merge-sources" => "merge-sources",
77 "build-info" => "info" );
79 %short_category = ( u => "uploaded-fixed-pkg",
86 c => "compiler-error",
90 ($progname = $0) =~ s,.*/,,;
91 if ($prognames{$progname}) {
92 $op_mode = $prognames{$progname};
94 elsif ($progname =~ /^list-(.*)$/) {
96 $list_state = ($1 eq "all") ? "" : $1;
101 verbose => { short => "v", flag => \$verbose },
102 override => { short => "o", flag => \$opt_override },
103 "create-db" => { flag => \$opt_create_db },
104 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
105 # TODO: remove after buildds no longer pass to wanna-build
106 "no-propagation" => { short => "N" },
107 "no-down-propagation" => { short => "D" },
109 take => { mode => "set-building" },
110 failed => { short => "f", mode => "set-failed" },
111 uploaded => { short => "u", mode => "set-uploaded" },
112 "no-build" => { short => "n", mode => "set-not-for-us" },
113 built => { mode => "set-built" },
114 attempted => { mode => "set-attempted" },
115 "give-back" => { mode => "set-needs-build" },
116 "dep-wait" => { mode => "set-dep-wait" },
117 forget => { mode => "forget" },
118 'forget-user' => { mode => 'forget-user' },
119 "merge-quinn" => { mode => "merge-quinn" },
120 "merge-partial-quinn" => { mode => "merge-partial-quinn" },
121 "merge-packages" => { mode => "merge-packages" },
122 "merge-sources" => { mode => "merge-sources" },
123 "pretend-avail" => { short => "p", mode => "pretend-avail" },
124 "merge-all" => { mode => "merge-all" },
125 info => { short => "i", mode => "info" },
126 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
127 code => sub { die "Invalid binNMU version: $binNMUver\n"
128 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
129 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
130 code => sub { die "Invalid build priority: $build_priority\n"
131 if $build_priority !~ /^-?[\d]+$/; } },
132 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
133 code => sub { die "Invalid build priority: $build_priority\n"
134 if $build_priority !~ /^-?[\d]+$/; } },
136 { short => "l", mode => "list", arg => \$list_state,
138 die "Unknown state to list: $list_state\n"
139 if !isin( $list_state, qw(needs-build building uploaded
140 built build-attempted failed installed dep-wait
141 not-for-us all failed-removed
142 install-wait reupload-wait bd-uninstallable));} },
145 { short => "d", arg => \$distribution,
147 if ($distribution eq "a" || $distribution eq "all") {
152 $distribution = "oldstable" if $distribution eq "o";
153 $distribution = "stable" if $distribution eq "s";
154 $distribution = "testing" if $distribution eq "t";
155 $distribution = "unstable" if $distribution eq "u";
159 { short => "O", arg => \$list_order,
161 die "Bad ordering character\n"
162 if $list_order !~ /^[PSpsncb]+$/;
164 message => { short => "m", arg => \$fail_reason },
165 database => { short => "b", arg => \$conf::dbbase },
166 arch => { short => "A", arg => \$arch },
167 user => { short => "U", arg => \$user },
168 category => { short => "c", arg => \$category,
170 $category = $short_category{$category}
171 if exists $short_category{$category};
172 die "Unknown category: $category\n"
173 if !isin( $category, values %short_category );
175 "min-age" => { short => "a", arg => \$list_min_age,
177 die "Argument of --min-age must be a non-zero number\n"
178 if $list_min_age == 0;
179 $list_min_age *= 24*60*60;
181 "max-age" => { arg => \$list_min_age,
183 die "Argument of --max-age must be a non-zero number\n"
184 if $list_min_age == 0;
185 $list_min_age *= -24*60*60;
188 import => { arg => \$import_from, mode => "import" },
189 export => { arg => \$export_to, mode => "export" },
190 "lock-for" => { arg => \$lock_for_pid, mode => "lock-for" },
191 "unlock-for" => { arg => \$lock_for_pid, mode => "unlock-for" },
192 "act-on-behalf-of" => { arg => \$lock_for_pid },
193 "start-transaction" => { mode => "start-transaction" },
194 "commit-transaction" => { mode => "commit-transaction" },
195 "transactional" => { flag => \$transactional },
196 "read-only" => { flag => \$read_only },
197 "manual-edit" => { mode => "manual-edit" },
198 "create-maintenance-lock" => { mode => "maintlock-create" },
199 "remove-maintenance-lock" => { mode => "maintlock-remove" },
200 "clean-db" => { mode => "clean-db" },
203 while( @ARGV && $ARGV[0] =~ /^-/ ) {
206 my($opt, $optname, $arg);
207 if (/^--([^=]+)(=|$)/) {
209 $opt = $options{$optname};
210 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
213 $optname = substr( $_, 1, 1 );
214 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
215 $arg = $1 if /^-$optname(.+)$/;
218 warn "Unknown option: --$1\n";
223 die "$optname option missing argument\n" if !@ARGV;
226 ${$opt->{arg}} = $arg;
228 elsif (defined $arg) {
229 die "Option $optname takes no argument\n";
233 die "Conflicting operation modes\n" if $op_mode;
234 $op_mode = $opt->{mode};
244 $op_mode = $category ? "set-failed" : "set-building"
245 if !$op_mode; # default operation
246 $list_order = $list_state eq "failed" ? 'fPcpsn' : 'PScpsn'
247 if !$list_order and $list_state;
248 $distribution ||= "unstable";
249 die "Bad distribution '$distribution'\n"
250 if !isin($distribution, keys %conf::distributions);
253 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
254 $version =~ s/(^\$| \$ .*$)//g;
255 print "wanna-build $version for $distribution on $conf::dbbase\n";
258 if ($read_only && !isin( $op_mode, qw(list export info))) {
259 warn "Invalid operation with --read-only. You can only use --list, --export or --info.\n";
263 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
264 merge-packages manual-edit maintlock-create lock-for unlock-for
265 start-transaction commit-transaction
266 merge-sources maintlock-remove clean-db))) {
267 warn "No packages given.\n";
271 $real_user = (getpwuid($<))[0];
272 die "Can't determine your user name\n"
273 if $op_mode ne "list" && !$user &&
274 !($user = $real_user);
277 if ($op_mode eq "set-failed" && !$category) {
278 print "Enter reason for failing (end with '.' alone on ".
283 last if $line eq ".\n";
284 $fail_reason .= $line;
286 chomp( $fail_reason );
287 } elsif ($op_mode eq "set-dep-wait") {
288 print "Enter dependencies (one line):\n";
290 while( !$line && !eof(STDIN) ) {
291 chomp( $line = <STDIN> );
293 die "No dependencies given\n" if !$line;
294 $fail_reason = $line;
295 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
296 print "Enter changelog entry (one line):\n";
298 while( !$line && !eof(STDIN) ) {
299 chomp( $line = <STDIN> );
301 die "No changelog entry given\n" if !$line;
302 $fail_reason = $line;
305 if ($op_mode eq "maintlock-create") {
309 if ($op_mode eq "maintlock-remove") {
313 waitfor_maintlock() if $op_mode !~ /^(?:merge-|clean-db$)/;
315 if (!-f db_filename( $distribution ) && !$opt_create_db) {
316 if ($transactional) {
317 die "No running transaction for $distribution\n";
319 die "Database for $distribution doesn't exist\n";
323 # Locking for another process means that a longer running process (most likely
324 # wb) wants to do several steps at once, and manages the locks.
325 if ($op_mode eq "lock-for") {
326 lock_db( $distribution );
329 if ($op_mode eq "unlock-for") {
330 unlock_db( $distribution );
335 lock_db( $distribution );
338 if ($op_mode eq "start-transaction") {
339 copy ( db_filename_master( $distribution ), db_filename_transaction( $distribution ))
340 or die "Copy failed: $!";
341 open LOG, ">", db_transactlog_transaction( $distribution )
342 or die "Could not create logfile for transaction: $!";
347 if ($op_mode eq "commit-transaction") {
348 # we need to copy here to preserve the owner and group of the file
349 copy ( db_filename_transaction( $distribution ), db_filename_master( $distribution ))
350 or die "Copy failed: $!";
351 unlink db_filename_transaction( $distribution );
352 open TLOG, "<", db_transactlog_transaction( $distribution )
353 or die "Could not open logfile from transaction: $!";
354 open LOG, ">>", db_transactlog_master( $distribution )
355 or die "Could not open logfile: $!";
356 while (<TLOG>) { print LOG $_ };
359 unlink db_transactlog_transaction( $distribution );
366 if ($lock_for_pid == -1) {
367 unlock_db( $distribution );
369 foreach (keys %conf::distributions) {
370 untie %{$otherdb{$_}} if tied(%{$otherdb{$_}});
371 unlock_db( $_ ) if $otherdb_lock{$_};
376 tie %db, 'MLDBM', db_filename( $distribution ), $read_only ? GDBM_READER : GDBM_WRCREAT, 0664
377 or die "FATAL: Cannot open database\n";
381 if ($mail_logs && $conf::log_mail) {
382 send_mail( $conf::log_mail,
383 "wanna-build $distribution state changes $curr_date",
384 "State changes at $curr_date for distribution ".
385 "$distribution:\n\n$mail_logs\n" );
393 SWITCH: foreach ($op_mode) {
395 add_packages( $1, @ARGV );
399 list_packages( $list_state );
403 info_packages( @ARGV );
406 /^forget-user/ && do {
407 die "This operation is restricted to admin users\n"
408 if (defined @conf::admin_users and
409 !isin( $real_user, @conf::admin_users));
410 forget_users( @ARGV );
414 forget_packages( @ARGV );
417 /^merge-partial-quinn/ && do {
418 die "This operation is restricted to admin users\n"
419 if (defined @conf::admin_users and
420 !isin( $real_user, @conf::admin_users));
424 /^merge-quinn/ && do {
425 die "This operation is restricted to admin users\n"
426 if (defined @conf::admin_users and
427 !isin( $real_user, @conf::admin_users));
431 /^merge-packages/ && do {
432 die "This operation is restricted to admin users\n"
433 if (defined @conf::admin_users and
434 !isin( $real_user, @conf::admin_users));
438 /^merge-sources/ && do {
439 die "This operation is restricted to admin users\n"
440 if (defined @conf::admin_users and
441 !isin( $real_user, @conf::admin_users));
445 /^pretend-avail/ && do {
446 pretend_avail( @ARGV );
450 die "This operation is restricted to admin users\n"
451 if (defined @conf::admin_users and
452 !isin( $real_user, @conf::admin_users));
454 @ARGV = ( $ARGS[0] );
455 my $pkgs = parse_packages();
456 @ARGV = ( $ARGS[1] );
458 @ARGV = ( $ARGS[2] );
459 my $srcs = parse_sources(1);
460 call_edos_depcheck( $ARGS[0], $srcs );
465 die "This operation is restricted to admin users\n"
466 if (defined @conf::admin_users and
467 !isin( $real_user, @conf::admin_users));
468 %db = (); # clear all current contents
469 read_db( $import_from );
473 write_db( $export_to );
476 /^manual-edit/ && do {
477 die "This operation is restricted to admin users\n"
478 if (defined @conf::admin_users and
479 !isin( $real_user, @conf::admin_users));
480 my $tmpfile_pattern = "/tmp/wanna-build-$distribution.$$-";
482 for( $i = 0;; ++$i ) {
483 $tmpfile = $tmpfile_pattern . $i;
484 last if ! -e $tmpfile;
486 write_db( $tmpfile );
487 my $editor = $ENV{'VISUAL'} ||
488 "/usr/bin/sensible-editor";
489 system "$editor $tmpfile";
490 %db = (); # clear all current contents
496 die "This operation is restricted to admin users\n"
497 if (defined @conf::admin_users and
498 !isin( $real_user, @conf::admin_users));
503 die "Unexpected operation mode $op_mode\n";
505 if (not -t and $user =~ /-/) {
506 my $userinfo = $db{'_userinfo'};
507 $userinfo = {} if (!defined($userinfo));
509 my $ui = $userinfo->{$user};
510 $ui = {} if (!defined($ui));
512 $ui->{'Last-Seen'} = $curr_date;
513 $ui->{'User'} = $user;
515 $userinfo->{$user} = $ui;
516 $db{'_userinfo'} = $userinfo;
521 my $newstate = shift;
522 my( $package, $name, $version, $ok, $reason );
524 foreach $package (@_) {
525 $package =~ s,^.*/,,; # strip path
526 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
527 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
528 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
529 ($name,$version) = ($1,$2);
532 warn "$package: can't extract package name and version ".
537 if ($op_mode eq "set-building") {
538 add_one_building( $name, $version );
540 elsif ($op_mode eq "set-built") {
541 add_one_built( $name, $version );
543 elsif ($op_mode eq "set-attempted") {
544 add_one_attempted( $name, $version );
546 elsif ($op_mode eq "set-uploaded") {
547 add_one_uploaded( $name, $version );
549 elsif ($op_mode eq "set-failed") {
550 add_one_failed( $name, $version );
552 elsif ($op_mode eq "set-not-for-us") {
553 add_one_notforus( $name, $version );
555 elsif ($op_mode eq "set-needs-build") {
556 add_one_needsbuild( $name, $version );
558 elsif ($op_mode eq "set-dep-wait") {
559 add_one_depwait( $name, $version );
561 elsif ($op_mode eq "set-build-priority") {
562 set_one_buildpri( $name, $version, 'BuildPri' );
564 elsif ($op_mode eq "set-permanent-build-priority") {
565 set_one_buildpri( $name, $version, 'PermBuildPri' );
567 elsif ($op_mode eq "set-binary-nmu") {
568 set_one_binnmu( $name, $version );
573 sub add_one_building {
579 my $pkg = $db{$name};
581 if ($pkg->{'State'} eq "Not-For-Us") {
583 $reason = "not suitable for this architecture";
585 elsif ($pkg->{'State'} =~ /^Dep-Wait/) {
587 $reason = "not all source dependencies available yet";
589 elsif ($pkg->{'State'} =~ /^BD-Uninstallable/) {
591 $reason = "source dependencies are not installable";
593 elsif ($pkg->{'State'} eq "Uploaded" &&
594 (version_lesseq($version, $pkg->{'Version'}))) {
596 $reason = "already uploaded by $pkg->{'Builder'}";
597 $reason .= " (in newer version $pkg->{'Version'})"
598 if !version_eq($pkg, $version);
600 elsif ($pkg->{'State'} eq "Installed" &&
601 version_less($version,$pkg->{'Version'})) {
603 print "$name: Warning: newer version $pkg->{'Version'} ".
604 "already installed, but overridden.\n";
608 $reason = "newer version $pkg->{'Version'} already in ".
609 "archive; doesn't need rebuilding";
610 print "$name: Note: If the following is due to an epoch ",
611 " change, use --override\n";
614 elsif ($pkg->{'State'} eq "Installed" &&
615 pkg_version_eq($pkg,$version)) {
617 $reason = "is up-to-date in the archive; doesn't need rebuilding";
619 elsif ($pkg->{'State'} eq "Needs-Build" &&
620 version_less($version,$pkg->{'Version'})) {
622 print "$name: Warning: newer version $pkg->{'Version'} ".
623 "needs building, but overridden.";
627 $reason = "newer version $pkg->{'Version'} needs building, ".
631 elsif (isin($pkg->{'State'},qw(Building Built Build-Attempted))) {
632 if (version_less($pkg->{'Version'},$version)) {
633 print "$name: Warning: Older version $pkg->{'Version'} ",
634 "is being built by $pkg->{'Builder'}\n";
635 if ($pkg->{'Builder'} ne $user) {
636 send_mail( $pkg->{'Builder'},
637 "package takeover in newer version",
638 "You are building package '$name' in ".
639 "version $version\n".
640 "(as far as I'm informed).\n".
641 "$user now has taken the newer ".
642 "version $version for building.".
643 "You can abort the build if you like.\n" );
648 print "User $pkg->{'Builder'} had already ",
649 "taken the following package,\n",
650 "but overriding this as you request:\n";
651 send_mail( $pkg->{'Builder'}, "package takeover",
652 "The package '$name' (version $version) that ".
653 "was locked by you\n".
654 "has been taken over by $user\n" );
656 elsif ($pkg->{'Builder'} eq $user) {
657 print "$name: Note: already taken by you.\n";
658 print "$name: ok\n" if $verbose;
663 $reason = "already taken by $pkg->{'Builder'}";
664 $reason .= " (in newer version $pkg->{'Version'})"
665 if !version_eq($pkg->{'Version'}, $version);
669 elsif ($pkg->{'State'} =~ /^Failed/ &&
670 pkg_version_eq($pkg, $version)) {
672 print "The following package previously failed ",
673 "(by $pkg->{'Builder'})\n",
674 "but overriding this as you request:\n";
675 send_mail( $pkg->{'Builder'}, "failed package takeover",
676 "The package '$name' (version $version) that ".
677 "is locked by you\n".
678 "and has failed previously has been taken over ".
680 if $pkg->{'Builder'} ne $user;
684 $reason = "build of $version failed previously:\n ";
685 $reason .= join( "\n ", split( "\n", $pkg->{'Failed'} ));
686 $reason .= "\nalso the package doesn't need builing"
687 if $pkg->{'State'} eq 'Failed-Removed';
693 if ($pkg->{'Binary-NMU-Version'}) {
694 print "$name: Warning: needs binary NMU $pkg->{'Binary-NMU-Version'}\n" .
695 "$pkg->{'Binary-NMU-Changelog'}\n";
698 print "$name: Warning: Previous version failed!\n"
699 if $pkg->{'Previous-State'} =~ /^Failed/ ||
700 $pkg->{'State'} =~ /^Failed/;
702 change_state( \$pkg, 'Building' );
703 $pkg->{'Package'} = $name;
704 $pkg->{'Version'} = $version;
705 $pkg->{'Builder'} = $user;
706 log_ta( $pkg, "--take" );
708 print "$name: $ok\n" if $verbose;
711 print "$name: NOT OK!\n $reason\n";
715 sub add_one_attempted {
718 my $pkg = $db{$name};
720 if (!defined($pkg)) {
721 print "$name: not registered yet.\n";
725 if ($pkg->{'State'} ne "Building" ) {
726 print "$name: not taken for building (state is $pkg->{'State'}). ",
730 if ($pkg->{'Builder'} ne $user) {
731 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
734 elsif ( !pkg_version_eq($pkg, $version) ) {
735 print "$name: version mismatch ".
736 "$(pkg->{'Version'} ".
737 "by $pkg->{'Builder'})\n";
741 change_state( \$pkg, 'Build-Attempted' );
742 log_ta( $pkg, "--attempted" );
744 print "$name: registered as uploaded\n" if $verbose;
750 my $pkg = $db{$name};
752 if (!defined($pkg)) {
753 print "$name: not registered yet.\n";
757 if ($pkg->{'State'} ne "Building" ) {
758 print "$name: not taken for building (state is $pkg->{'State'}). ",
762 if ($pkg->{'Builder'} ne $user) {
763 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
766 elsif ( !pkg_version_eq($pkg, $version) ) {
767 print "$name: version mismatch ".
768 "$(pkg->{'Version'} ".
769 "by $pkg->{'Builder'})\n";
772 change_state( \$pkg, 'Built' );
773 log_ta( $pkg, "--built" );
775 print "$name: registered as built\n" if $verbose;
778 sub add_one_uploaded {
781 my $pkg = $db{$name};
783 if (!defined($pkg)) {
784 print "$name: not registered yet.\n";
788 if ($pkg->{'State'} eq "Uploaded" &&
789 pkg_version_eq($pkg,$version)) {
790 print "$name: already uploaded\n";
793 if (!isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
794 print "$name: not taken for building (state is $pkg->{'State'}). ",
798 if ($pkg->{'Builder'} ne $user) {
799 print "$name: not taken by you, but by $pkg->{'Builder'}. Skipping.\n";
802 # strip epoch -- buildd-uploader used to go based on the filename.
803 # (to remove at some point)
805 ($pkgver = $pkg->{'Version'}) =~ s/^\d+://;
806 $version =~ s/^\d+://; # for command line use
807 if ($pkg->{'Binary-NMU-Version'} ) {
808 my $nmuver = binNMU_version($pkgver, $pkg->{'Binary-NMU-Version'});
809 if (!version_eq( $nmuver, $version )) {
810 print "$name: version mismatch ($nmuver registered). ",
814 } elsif (!version_eq($pkgver, $version)) {
815 print "$name: version mismatch ($pkg->{'Version'} registered). ",
820 change_state( \$pkg, 'Uploaded' );
821 log_ta( $pkg, "--uploaded" );
823 print "$name: registered as uploaded\n" if $verbose;
830 my $pkg = $db{$name};
832 if (!defined($pkg)) {
833 print "$name: not registered yet.\n";
836 $state = $pkg->{'State'};
838 if ($state eq "Not-For-Us") {
839 print "$name: not suitable for this architecture anyway. Skipping.\n";
842 elsif ($state eq "Failed-Removed") {
843 print "$name: failed previously and doesn't need building. Skipping.\n";
846 elsif ($state eq "Installed") {
847 print "$name: Is already installed in archive. Skipping.\n";
850 elsif ($pkg->{'Builder'} &&
851 (($user ne $pkg->{'Builder'}) &&
852 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
853 print "$name: not taken by you, but by ".
854 "$pkg->{'Builder'}. Skipping.\n";
857 elsif ( !pkg_version_eq($pkg, $version) ) {
858 print "$name: version mismatch ".
859 "$(pkg->{'Version'} ".
860 "by $pkg->{'Builder'})\n";
865 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
867 $cat = $short_category{$cat} if exists $short_category{$cat};
868 if (!isin( $cat, values %short_category )) {
869 print "$name: Warning: unknown category $cat; discarded\n";
872 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
875 if ($state eq "Needs-Build") {
876 print "$name: Warning: not registered for building previously, ".
877 "but processing anyway.\n";
879 elsif ($state eq "Uploaded") {
880 print "$name: Warning: marked as uploaded previously, ".
881 "but processing anyway.\n";
883 elsif ($state eq "Dep-Wait") {
884 print "$name: Warning: marked as waiting for dependencies, ".
885 "but processing anyway.\n";
887 elsif ($state eq "BD-Uninstallable") {
888 print "$name: Warning: marked as having uninstallable build-dependencies, ".
889 "but processing anyway.\n";
891 elsif ($state eq "Failed") {
892 print "$name: already registered as failed; will append new message\n"
894 print "$name: already registered as failed; changing category\n"
898 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
899 exists $pkg->{'Failed-Category'} &&
900 $pkg->{'Failed-Category'} ne $cat) {
901 (my $action = $cat) =~ s/-/ /;
902 $fail_reason .= "\n$short_date: $action";
905 change_state( \$pkg, 'Failed' );
906 $pkg->{'Builder'} = $user;
907 $pkg->{'Failed'} .= "\n" if $pkg->{'Failed'};
908 $pkg->{'Failed'} .= $fail_reason;
909 $pkg->{'Failed-Category'} = $cat if $cat;
910 if (defined $pkg->{'PermBuildPri'}) {
911 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
913 delete $pkg->{'BuildPri'};
915 log_ta( $pkg, "--failed" );
917 print "$name: registered as failed\n" if $verbose;
920 sub add_one_notforus {
923 my $pkg = $db{$name};
925 if ($pkg->{'State'} eq 'Not-For-Us') {
926 # reset Not-For-Us state in case it's called twice; this is
927 # the only way to get a package out of this state...
928 # There is no really good state in which such packages should
929 # be put :-( So use Failed for now.
930 change_state( \$pkg, 'Failed' );
931 $pkg->{'Package'} = $name;
932 $pkg->{'Failed'} = "Was Not-For-Us previously";
933 delete $pkg->{'Builder'};
934 delete $pkg->{'Depends'};
935 log_ta( $pkg, "--no-build(rev)" );
936 print "$name: now not unsuitable anymore\n";
938 send_mail( $conf::notforus_maint,
939 "$name moved out of Not-For-Us state",
940 "The package '$name' has been moved out of the Not-For-Us ".
942 "It should probably also be removed from ".
943 "Packages-arch-specific or\n".
944 "the action was wrong.\n" )
945 if $conf::notforus_maint;
948 change_state( \$pkg, 'Not-For-Us' );
949 $pkg->{'Package'} = $name;
950 delete $pkg->{'Builder'};
951 delete $pkg->{'Depends'};
952 delete $pkg->{'BuildPri'};
953 delete $pkg->{'Binary-NMU-Version'};
954 delete $pkg->{'Binary-NMU-Changelog'};
955 log_ta( $pkg, "--no-build" );
956 print "$name: registered as unsuitable\n" if $verbose;
958 send_mail( $conf::notforus_maint,
959 "$name set to Not-For-Us",
960 "The package '$name' has been set to state Not-For-Us ".
962 "It should probably also be added to ".
963 "Packages-arch-specific or\n".
964 "the Not-For-Us state is wrong.\n" )
965 if $conf::notforus_maint;
970 sub add_one_needsbuild {
974 my $pkg = $db{$name};
976 if (!defined($pkg)) {
977 print "$name: not registered; can't give back.\n";
980 $state = $pkg->{'State'};
982 if ($state eq "BD-Uninstallable") {
984 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
986 change_state( \$pkg, 'Needs-Build' );
987 delete $pkg->{'Builder'};
988 delete $pkg->{'Depends'};
989 log_ta( $pkg, "--give-back" );
991 print "$name: given back\n" if $verbose;
995 print "$name: has uninstallable build-dependencies. Skipping\n",
996 " (use --override to clear dependency list and ",
997 "give back anyway)\n";
1001 elsif ($state eq "Dep-Wait") {
1002 if ($opt_override) {
1003 print "$name: Forcing source dependency list to be cleared\n";
1006 print "$name: waiting for source dependencies. Skipping\n",
1007 " (use --override to clear dependency list and ",
1008 "give back anyway)\n";
1012 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1013 print "$name: not taken for building (state is $state).";
1014 if ($opt_override) {
1015 print "\n$name: Forcing give-back\n";
1018 print " Skipping.\n";
1022 if (defined ($pkg->{'Builder'}) && $user ne $pkg->{'Builder'} &&
1023 !($pkg->{'Builder'} =~ /^(\w+)-\w+/ && $1 eq $user)) {
1024 print "$name: not taken by you, but by ".
1025 "$pkg->{'Builder'}. Skipping.\n";
1028 if (!pkg_version_eq($pkg, $version)) {
1029 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1033 change_state( \$pkg, 'BD-Uninstallable' );
1034 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1035 delete $pkg->{'Builder'};
1036 delete $pkg->{'Depends'};
1037 log_ta( $pkg, "--give-back" );
1039 print "$name: given back\n" if $verbose;
1042 sub set_one_binnmu {
1044 my $version = shift;
1045 my $pkg = $db{$name};
1048 if (!defined($pkg)) {
1049 print "$name: not registered; can't register for binNMU.\n";
1052 my $db_ver = $pkg->{'Version'};
1054 if (!version_eq($db_ver, $version)) {
1055 print "$name: version mismatch ($db_ver registered). ",
1059 $state = $pkg->{'State'};
1061 if (defined $pkg->{'Binary-NMU-Version'}) {
1062 if ($binNMUver == 0) {
1063 change_state( \$pkg, 'Installed' );
1064 delete $pkg->{'Builder'};
1065 delete $pkg->{'Depends'};
1066 delete $pkg->{'Binary-NMU-Version'};
1067 delete $pkg->{'Binary-NMU-Changelog'};
1068 } elsif ($binNMUver <= $pkg->{'Binary-NMU-Version'}) {
1069 print "$name: already building binNMU $pkg->{'Binary-NMU-Version'}\n";
1072 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1073 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1074 $pkg->{'Notes'} = 'out-of-date';
1075 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'}
1076 if (defined $pkg->{'PermBuildPri'});
1078 log_ta( $pkg, "--binNMU" );
1081 } elsif ($binNMUver == 0) {
1082 print "${name}_$version: no scheduled binNMU to cancel.\n";
1086 if ($state ne 'Installed') {
1087 print "${name}_$version: not installed; can't register for binNMU.\n";
1091 my $fullver = binNMU_version($version,$binNMUver);
1092 if ( version_lesseq( $fullver, $pkg->{'Installed-Version'} ) )
1094 print "$name: binNMU $fullver is not newer than current version $pkg->{'Installed-Version'}\n";
1098 change_state( \$pkg, 'BD-Uninstallable' );
1099 $pkg->{'BD-Problem'} = "Installability of build dependencies not tested yet";
1100 delete $pkg->{'Builder'};
1101 delete $pkg->{'Depends'};
1102 $pkg->{'Binary-NMU-Version'} = $binNMUver;
1103 $pkg->{'Binary-NMU-Changelog'} = $fail_reason;
1104 $pkg->{'Notes'} = 'out-of-date';
1105 log_ta( $pkg, "--binNMU" );
1107 print "${name}: registered for binNMU $fullver\n" if $verbose;
1110 sub set_one_buildpri {
1112 my $version = shift;
1114 my $pkg = $db{$name};
1117 if (!defined($pkg)) {
1118 print "$name: not registered; can't set priority.\n";
1121 $state = $pkg->{'State'};
1123 if ($state eq "Not-For-Us") {
1124 print "$name: not suitable for this architecture. Skipping.\n";
1126 } elsif ($state eq "Failed-Removed") {
1127 print "$name: failed previously and doesn't need building. Skipping.\n";
1130 if (!pkg_version_eq($pkg, $version)) {
1131 print "$name: version mismatch ($pkg->{'Version'} registered). ",
1135 if ( $build_priority == 0 ) {
1136 delete $pkg->{'BuildPri'}
1137 if $key eq 'PermBuildPri' and defined $pkg->{'BuildPri'}
1138 and $pkg->{'BuildPri'} == $pkg->{$key};
1139 delete $pkg->{$key};
1141 $pkg->{'BuildPri'} = $build_priority
1142 if $key eq 'PermBuildPri';
1143 $pkg->{$key} = $build_priority;
1146 print "$name: set to build priority $build_priority\n" if $verbose;
1149 sub add_one_depwait {
1151 my $version = shift;
1153 my $pkg = $db{$name};
1155 if (!defined($pkg)) {
1156 print "$name: not registered yet.\n";
1159 $state = $pkg->{'State'};
1161 if ($state eq "Dep-Wait") {
1162 print "$name: merging with previously registered dependencies\n";
1165 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1166 print "$name: Warning: not registered for building previously, ".
1167 "but processing anyway.\n";
1169 elsif ($state eq "Not-For-Us") {
1170 print "$name: not suitable for this architecture anyway. Skipping.\n";
1173 elsif ($state eq "Failed-Removed") {
1174 print "$name: failed previously and doesn't need building. Skipping.\n";
1177 elsif ($state eq "Installed") {
1178 print "$name: Is already installed in archive. Skipping.\n";
1181 elsif ($state eq "Uploaded") {
1182 print "$name: Is already uploaded. Skipping.\n";
1185 elsif ($pkg->{'Builder'} &&
1186 $user ne $pkg->{'Builder'}) {
1187 print "$name: not taken by you, but by ".
1188 "$pkg->{'Builder'}. Skipping.\n";
1191 elsif ( !pkg_version_eq($pkg,$version)) {
1192 print "$name: version mismatch ".
1193 "($pkg->{'Version'} ".
1194 "by $pkg->{'Builder'})\n";
1197 elsif ($fail_reason =~ /^\s*$/ ||
1198 !parse_deplist( $fail_reason, 1 )) {
1199 print "$name: Bad dependency list\n";
1202 change_state( \$pkg, 'Dep-Wait' );
1203 $pkg->{'Builder'} = $user;
1204 if (defined $pkg->{'PermBuildPri'}) {
1205 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1207 delete $pkg->{'BuildPri'};
1209 my $deplist = parse_deplist( $pkg->{'Depends'} );
1210 my $new_deplist = parse_deplist( $fail_reason );
1211 # add new dependencies, maybe overwriting old entries
1212 foreach (keys %$new_deplist) {
1213 $deplist->{$_} = $new_deplist->{$_};
1215 $pkg->{'Depends'} = build_deplist($deplist);
1216 log_ta( $pkg, "--dep-wait" );
1218 print "$name: registered as waiting for dependencies\n" if $verbose;
1228 local($/) = ""; # read in paragraph mode
1230 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1232 /^Package:\s*(\S+)$/mi and $name = $1;
1233 /^Version:\s*(\S+)$/mi and $version = $1;
1234 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1235 /^Section:\s*(\S+)$/mi and $section = $1;
1236 /^Priority:\s*(\S+)$/mi and $priority = $1;
1237 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1238 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1239 /^Binary:\s*(.*)$/mi and $binaries = $1;
1241 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1242 $srcver{$name} = $version;
1244 $pkgs{$name}{'ver'} = $version;
1245 $pkgs{$name}{'bin'} = $binaries;
1246 $pkgs{$name}{'dep'} = $builddep;
1247 $pkgs{$name}{'conf'} = $buildconf;
1248 my $pkg = $db{$name};
1253 if ($arch eq "all" && !version_less( $version, $pkg->{'Version'} )) {
1254 # package is now Arch: all, delete it from db
1255 change_state( \$pkg, 'deleted' );
1256 log_ta( $pkg, "--merge-sources" );
1257 print "$name ($pkg->{'Version'}): deleted ".
1258 "from database, because now Arch: all\n"
1264 # The "Version" should always be the source version --
1265 # not a possible binNMU version number.
1266 $pkg->{'Version'} = $version, $change++
1267 if ($pkg->{'State'} eq 'Installed' and
1268 !version_eq( $pkg->{'Version'}, $version));
1269 # Always update priority and section, if available
1270 $pkg->{'Priority'} = $priority, $change++
1271 if defined $priority and (not defined($pkg->{'Priority'}) or $pkg->{'Priority'} ne $priority);
1273 $pkg->{'Section'} = $section, $change++
1274 if defined $section and (not defined($pkg->{'Section'}) or $pkg->{'Section'} ne $section);
1276 # Remove field from previous wanna-build versions
1277 for (qw/Reason Build-Depends Build-Conflicts/) {
1278 if (exists $pkg->{$_}) {
1284 $db{$name} = $pkg if $change;
1287 # Now that we only have the latest source version, build the list
1288 # of binary packages from the Sources point of view
1289 foreach $name (keys %pkgs) {
1290 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1291 $merge_binsrc{$bin} = $name;
1294 # remove installed packages that no longer have source available
1295 # or binaries installed
1296 foreach $name (keys %db) {
1297 next if $name =~ /^_/;
1298 my $pkg = $db{$name};
1299 if (not defined($pkgs{$name})) {
1300 change_state( \$pkg, 'deleted' );
1301 log_ta( $pkg, "--merge-sources" );
1302 print "$name ($pkg->{'Version'}): ".
1303 "deleted from database, because ".
1304 "not in Sources anymore\n"
1308 next if !isin( $pkg->{'State'}, qw(Installed) );
1309 if ($full && not defined $merge_srcvers{$name}) {
1310 change_state( \$pkg, 'deleted' );
1311 log_ta( $pkg, "--merge-sources" );
1312 print "$name ($pkg->{'Version'}): ".
1313 "deleted from database, because ".
1314 "binaries don't exist anymore\n"
1317 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'Version'})) {
1318 print "$name ($pkg->{'Version'}): ".
1319 "package is Installed but binaries are from ".
1320 $merge_srcvers{$name}. "\n"
1328 # This function looks through a Packages file and sets the state of
1329 # packages to 'Installed'
1330 sub parse_packages {
1333 local($/) = ""; # read in paragraph mode
1335 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1337 /^Package:\s*(\S+)$/mi and $name = $1;
1338 /^Version:\s*(\S+)$/mi and $version = $1;
1339 /^Depends:\s*(.*)$/mi and $depends = $1;
1340 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1341 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1342 /^Provides:\s*(.*)$/mi and $provides = $1;
1343 next if !$name || !$version;
1344 next if ($arch ne $architecture and $architecture ne "all");
1345 next if (defined ($installed->{$name}) and $installed->{$name}{'Version'} ne "" and
1346 version_lesseq( $version, $installed->{$name}{'Version'} ));
1347 $installed->{$name}{'Version'} = $version;
1348 $installed->{$name}{'Depends'} = $depends;
1349 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1350 undef $installed->{$name}{'Provider'};
1351 $installed->{$name}{'Source'} = $source ? $source : $name;
1353 foreach (split( /\s*,\s*/, $provides )) {
1354 if (not defined ($installed->{$_})) {
1355 $installed->{$_}{'Version'} = "";
1356 $installed->{$_}{'Provider'} = $name;
1360 if ( $version =~ /\+b(\d+)$/ ) {
1363 $version = $sourcev if $sourcev;
1364 $binaryv = $version;
1365 $binaryv =~ s/\+b\d+$//;
1366 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1367 $binaryv .= "+b$binnmu" if defined($binnmu);
1369 next if $architecture ne $arch;
1370 $name = $source if $source;
1371 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1372 $merge_srcvers{$name} = $version;
1374 my $pkg = $db{$name};
1377 if (isin( $pkg->{'State'}, qw(Not-For-Us)) ||
1378 (isin($pkg->{'State'}, qw(Installed)) &&
1379 version_lesseq($binaryv, $pkg->{'Installed-Version'}))) {
1380 print "Skipping $name because State == $pkg->{'State'}\n"
1384 if ($pkg->{'Binary-NMU-Version'} ) {
1385 my $nmuver = binNMU_version($pkg->{'Version'}, $pkg->{'Binary-NMU-Version'});
1386 if (version_less( $binaryv, $nmuver )) {
1387 print "Skipping $name ($version) because have newer ".
1388 "version ($nmuver) in db.\n"
1392 } elsif (version_less($version, $pkg->{'Version'})) {
1393 print "Skipping $name ($version) because have newer ".
1394 "version ($pkg->{'Version'}) in db.\n"
1399 if (!pkg_version_eq($pkg, $version) &&
1400 $pkg->{'State'} ne "Installed") {
1401 warn "Warning: $name: newer version than expected appeared ".
1402 "in archive ($version vs. $pkg->{'Version'})\n";
1403 delete $pkg->{'Builder'};
1406 if (!isin( $pkg->{'State'}, qw(Uploaded) )) {
1407 warn "Warning: Package $name was not in uploaded state ".
1408 "before (but in '$pkg->{'State'}').\n";
1409 delete $pkg->{'Builder'};
1410 delete $pkg->{'Depends'};
1414 $pkg->{'Version'} = $version;
1417 change_state( \$pkg, 'Installed' );
1418 $pkg->{'Package'} = $name;
1419 $pkg->{'Installed-Version'} = $binaryv;
1420 if (defined $pkg->{'PermBuildPri'}) {
1421 $pkg->{'BuildPri'} = $pkg->{'PermBuildPri'};
1423 delete $pkg->{'BuildPri'};
1425 $pkg->{'Version'} = $version
1426 if version_less( $pkg->{'Version'}, $version);
1427 delete $pkg->{'Binary-NMU-Version'};
1428 delete $pkg->{'Binary-NMU-Changelog'};
1429 log_ta( $pkg, "--merge-packages" );
1431 print "$name ($version) is up-to-date now.\n" if $verbose;
1434 check_dep_wait( "--merge-packages", $installed );
1439 my ($package, $name, $version, $installed);
1441 foreach $package (@_) {
1442 $package =~ s,^.*/,,; # strip path
1443 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1444 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1445 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1446 ($name,$version) = ($1,$2);
1449 warn "$package: can't extract package name and version ".
1453 $installed->{$name}{'Version'} = $version;
1456 check_dep_wait( "--pretend-avail", $installed );
1459 sub check_dep_wait {
1461 my $installed = shift;
1463 # check all packages in state Dep-Wait if dependencies are all
1466 foreach $name (keys %db) {
1467 next if $name =~ /^_/;
1468 my $pkg = $db{$name};
1469 next if $pkg->{'State'} ne "Dep-Wait";
1470 my $deps = $pkg->{'Depends'};
1472 print "$name: was in state Dep-Wait, but with empty ",
1474 goto make_needs_build;
1476 my $deplist = parse_deplist($deps);
1480 foreach (keys %$deplist) {
1481 if (!exists $installed->{$_} ||
1482 ($deplist->{$_}->{'Rel'} && $deplist->{$_}->{'Version'} &&
1483 !version_compare( $installed->{$_}{'Version'},
1484 $deplist->{$_}->{'Rel'},
1485 $deplist->{$_}->{'Version'}))) {
1487 $new_deplist->{$_} = $deplist->{$_};
1490 push( @removed_deps, $_ );
1495 change_state( \$pkg, 'Needs-Build' );
1496 log_ta( $pkg, $action );
1497 delete $pkg->{'Builder'};
1498 delete $pkg->{'Depends'};
1499 print "$name ($pkg->{'Version'}) has all ",
1500 "dependencies available now\n" if $verbose;
1504 elsif (@removed_deps) {
1505 $pkg->{'Depends'} = build_deplist( $new_deplist );
1506 print "$name ($pkg->{'Version'}): some dependencies ",
1507 "(@removed_deps) available now, but not all yet\n"
1514 # This function accepts quinn-diff output (either from a file named on
1515 # the command line, or on stdin) and sets the packages named there to
1516 # state 'Needs-Build'.
1517 sub parse_quinn_diff {
1518 my $partial = shift;
1524 next if !m,^([-\w\d/]*)/ # section
1525 ([-\w\d.+]+)_ # package name
1526 ([\w\d:.~+-]+)\.dsc\s* # version
1527 \[([^:]*): # priority
1528 ([^]]+)\]\s*$,x; # rest of notes
1529 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1530 $quinn_pkgs{$name}++;
1531 $section ||= "unknown";
1532 $priority ||= "unknown";
1533 $priority = "unknown" if $priority eq "-";
1534 $priority = "standard" if ($name eq "debian-installer");
1536 my $pkg = $db{$name};
1538 # Always update section and priority.
1539 if (defined($pkg)) {
1541 $pkg->{'Section'} = $section, $change++ if not defined
1542 $pkg->{'Section'} or $section ne "unknown";
1543 $pkg->{'Priority'} = $priority, $change++ if not defined
1544 $pkg->{'Priority'} or $priority ne "unknown";
1547 if (defined($pkg) &&
1548 $pkg->{'State'} =~ /^Dep-Wait/ &&
1549 version_less( $pkg->{'Version'}, $version )) {
1550 change_state( \$pkg, 'Dep-Wait' );
1551 $pkg->{'Version'} = $version;
1552 delete $pkg->{'Binary-NMU-Version'};
1553 delete $pkg->{'Binary-NMU-Changelog'};
1554 log_ta( $pkg, "--merge-quinn" );
1556 print "$name ($version) still waiting for dependencies.\n"
1559 elsif (defined($pkg) &&
1560 $pkg->{'State'} =~ /-Removed$/ &&
1561 version_eq($pkg->{'Version'}, $version)) {
1562 # reinstantiate a package that has been removed earlier
1563 # (probably due to a quinn-diff malfunction...)
1564 my $newstate = $pkg->{'State'};
1565 $newstate =~ s/-Removed$//;
1566 change_state( \$pkg, $newstate );
1567 $pkg->{'Version'} = $version;
1568 $pkg->{'Notes'} = $notes;
1569 log_ta( $pkg, "--merge-quinn" );
1571 print "$name ($version) reinstantiated to $newstate.\n"
1574 elsif (defined($pkg) &&
1575 $pkg->{'State'} eq "Not-For-Us" &&
1576 version_less( $pkg->{'Version'}, $version )) {
1577 # for Not-For-Us packages just update the version etc., but
1579 change_state( \$pkg, "Not-For-Us" );
1580 $pkg->{'Package'} = $name;
1581 $pkg->{'Version'} = $version;
1582 $pkg->{'Notes'} = $notes;
1583 delete $pkg->{'Builder'};
1584 log_ta( $pkg, "--merge-quinn" );
1586 print "$name ($version) still Not-For-Us.\n" if $verbose;
1588 elsif (!defined($pkg) ||
1589 $pkg->{'State'} ne "Not-For-Us" &&
1590 (version_less( $pkg->{'Version'}, $version ) ||
1591 ($pkg->{'State'} eq "Installed" && version_less($pkg->{'Installed-Version'}, $version)))) {
1593 if (defined( $pkg->{'State'} ) && isin( $pkg->{'State'}, qw(Building Built Build-Attempted))) {
1594 send_mail( $pkg->{'Builder'},
1595 "new version of $name (dist=$distribution)",
1596 "As far as I'm informed, you're currently ".
1597 "building the package $name\n".
1598 "in version $pkg->{'Version'}.\n\n".
1599 "Now there's a new source version $version. ".
1600 "If you haven't finished\n".
1601 "compiling $name yet, you can stop it to ".
1602 "save some work.\n".
1603 "Just to inform you...\n".
1604 "(This is an automated message)\n" );
1605 print "$name: new version ($version) while building ".
1606 "$pkg->{'Version'} -- sending mail ".
1607 "to builder ($pkg->{'Builder'})\n"
1610 change_state( \$pkg, 'Needs-Build' );
1611 $pkg->{'Package'} = $name;
1612 $pkg->{'Version'} = $version;
1613 $pkg->{'Section'} = $section;
1614 $pkg->{'Priority'} = $priority;
1615 $pkg->{'Notes'} = $notes;
1616 delete $pkg->{'Builder'};
1617 delete $pkg->{'Binary-NMU-Version'};
1618 delete $pkg->{'Binary-NMU-Changelog'};
1619 log_ta( $pkg, "--merge-quinn" );
1622 print "$name ($version) needs rebuilding now.\n" if $verbose;
1624 elsif (defined($pkg) &&
1625 !version_eq( $pkg->{'Version'}, $version ) &&
1626 isin( $pkg->{'State'}, qw(Installed Not-For-Us) )) {
1627 print "$name: skipping because version in db ".
1628 "($pkg->{'Version'}) is >> than ".
1629 "what quinn-diff says ($version) ".
1630 "(state is $pkg->{'State'})\n"
1632 $dubious .= "$pkg->{'State'}: ".
1633 "db ${name}_$pkg->{'Version'} >> ".
1634 "quinn $version\n" if !$partial;
1636 elsif ($verbose >= 2) {
1637 if ($pkg->{'State'} eq "Not-For-Us") {
1638 print "Skipping $name because State == ".
1639 "$pkg->{'State'}\n";
1641 elsif (!version_less($pkg->{'Version'}, $version)) {
1642 print "Skipping $name because version in db ".
1643 "($pkg->{'Version'}) is >= than ".
1644 "what quinn-diff says ($version)\n";
1647 $db{$name} = $pkg if $change;
1651 send_mail( $conf::db_maint,
1652 "Dubious versions in $distribution $conf::dbbase database",
1653 "The following packages have a newer version in the ".
1654 "wanna-build database\n".
1655 "than what quinn-diff says, and this is strange for ".
1657 "It could be caused by a lame mirror, or the version ".
1658 "in the database\n".
1663 # Now re-check the DB for packages in states Needs-Build, Failed,
1664 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1665 # anymore by quinn-diff.
1668 foreach $name (keys %db) {
1669 next if $name =~ /^_/;
1670 my $pkg = $db{$name};
1671 next if defined $pkg->{'Binary-NMU-Version'};
1672 next if !isin( $pkg->{'State'},
1673 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1674 my $virtual_delete = $pkg->{'State'} eq 'Failed';
1676 if (!$quinn_pkgs{$name}) {
1677 change_state( \$pkg, $virtual_delete ?
1678 $pkg->{'State'}."-Removed" :
1680 log_ta( $pkg, "--merge-quinn" );
1681 print "$name ($pkg->{'Version'}): ".
1682 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1683 "from database, because not in quinn-diff anymore\n"
1685 if ($virtual_delete) {
1695 sub send_reupload_mail {
1698 my $version = shift;
1700 my $other_dist = shift;
1703 "Please reupload ${pkg}_${'Version'} for $dist",
1704 "You have recently built (or are currently building)\n".
1705 "${pkg}_${'Version'} for $other_dist.\n".
1706 "This version is now also needed in the $dist distribution.\n".
1707 "Please reupload the files now present in the Debian archive\n".
1708 "(best with buildd-reupload).\n" );
1712 # for sorting priorities and sections
1714 %prioval = ( required => -5,
1722 'debian-installer' => -199,
1743 localizations => -178,
1744 interpreters => -177,
1769 electronics => -152,
1775 foreach my $i (keys %sectval) {
1776 $sectval{"contrib/$i"} = $sectval{$i}+40;
1777 $sectval{"non-free/$i"} = $sectval{$i}+80;
1779 $sectval{'unknown'} = -165;
1781 %catval = ( "none" => -20,
1782 "uploaded-fixed-pkg" => -19,
1783 "fix-expected" => -18,
1784 "reminder-sent" => -17,
1785 "nmu-offered" => -16,
1789 "compiler-error" => -12 );
1792 sub sort_list_func {
1793 my( $letter, $x, $ax, $bx );
1795 foreach $letter (split( "", $list_order )) {
1796 SWITCH: foreach ($letter) {
1798 $x = $b->{'BuildPri'} <=> $a->{'BuildPri'};
1799 return $x if $x != 0;
1803 $x = $prioval{$a->{'Priority'}} <=> $prioval{$b->{'Priority'}};
1804 return $x if $x != 0;
1808 $x = $sectval{$a->{'Section'}} <=> $sectval{$b->{'Section'}};
1809 return $x if $x != 0;
1813 $x = $a->{'Package'} cmp $b->{'Package'};
1814 return $x if $x != 0;
1818 $x = $a->{'Builder'} cmp $b->{'Builder'};
1819 return $x if $x != 0;
1823 $ax = ($a->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1824 ($a->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1825 $bx = ($b->{'Notes'} =~ /^(out-of-date|partial)/) ? 0 :
1826 ($b->{'Notes'} =~ /^uncompiled/) ? 2 : 1;
1828 return $x if $x != 0;
1832 my $ca = exists $a->{'Failed-Category'} ?
1833 $a->{'Failed-Category'} : "none";
1834 my $cb = exists $b->{'Failed-Category'} ?
1835 $b->{'Failed-Category'} : "none";
1836 $x = $catval{$ca} <=> $catval{$cb};
1837 return $x if $x != 0;
1841 my $pa = $prioval{$a->{'Priority'}} >
1842 $prioval{'standard'};
1843 my $pb = $prioval{$b->{'Priority'}} >
1844 $prioval{'standard'};
1846 return $x if $x != 0;
1856 my( $name, $pkg, @list );
1861 foreach $name (keys %db) {
1862 next if $name =~ /^_/;
1864 next if $state ne "all" && $pkg->{'State'} !~ /^\Q$state\E$/i;
1865 next if $user && (lc($state) ne 'needs-build' and $pkg->{'Builder'} ne $user);
1866 next if $category && $pkg->{'State'} eq "Failed" &&
1867 $pkg->{'Failed-Category'} ne $category;
1868 next if ($list_min_age > 0 &&
1869 ($ctime-parse_date($pkg->{'State-Change'})) < $list_min_age)||
1870 ($list_min_age < 0 &&
1871 ($ctime-parse_date($pkg->{'State-Change'})) > -$list_min_age);
1872 push( @list, $pkg );
1875 foreach $pkg (sort sort_list_func @list) {
1876 print "$pkg->{'Section'}/$pkg->{'Package'}_$pkg->{'Version'}";
1877 print ": $pkg->{'State'}"
1879 print " by $pkg->{'Builder'}"
1880 if $pkg->{'State'} ne "Needs-Build" && $pkg->{'Builder'};
1881 print " [$pkg->{'Priority'}:$pkg->{'Notes'}";
1882 print ":PREV-FAILED"
1883 if $pkg->{'Previous-State'} =~ /^Failed/;
1884 print ":bp{" . $pkg->{'BuildPri'} . "}"
1885 if exists $pkg->{'BuildPri'};
1886 print ":binNMU{" . $pkg->{'Binary-NMU-Version'} . "}"
1887 if exists $pkg->{'Binary-NMU-Version'};
1889 print " Reasons for failing:\n",
1891 exists $pkg->{'Failed-Category'} ? $pkg->{'Failed-Category'} : "none",
1893 join("\n ",split("\n",$pkg->{'Failed'})), "\n"
1894 if $pkg->{'State'} =~ /^Failed/;
1895 print " Dependencies: $pkg->{'Depends'}\n"
1896 if $pkg->{'State'} eq "Dep-Wait";
1897 print " Reasons for BD-Uninstallable:\n ",
1898 join("\n ",split("\n",$pkg->{'BD-Problem'})), "\n"
1899 if $pkg->{'State'} eq "BD-Uninstallable";
1900 print " Previous state was $pkg->{'Previous-State'} until ",
1901 "$pkg->{'State-Change'}\n"
1902 if $verbose && $pkg->{'Previous-State'};
1903 print " No previous state recorded\n"
1904 if $verbose && !$pkg->{'Previous-State'};
1905 print " Previous failing reasons:\n ",
1906 join("\n ",split("\n",$pkg->{'Old-Failed'})), "\n"
1907 if $verbose && $pkg->{'Old-Failed'};
1909 $scnt{$pkg->{'State'}}++ if $state eq "all";
1911 if ($state eq "all") {
1912 foreach (sort keys %scnt) {
1913 print "Total $scnt{$_} package(s) in state $_.\n";
1916 print "Total $cnt package(s)\n";
1921 my( $name, $pkg, $key, $dist );
1922 my @firstkeys = qw(Package Version Builder State Section Priority
1923 Installed-Version Previous-State State-Change);
1924 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1926 foreach $dist (@dists) {
1927 if ($dist ne $distribution) {
1928 if (!-f db_filename( $dist ) || !open_other_db( $dist )) {
1929 warn "Cannot open database for $dist!\n";
1930 @dists = grep { $_ ne $dist } @dists;
1935 foreach $name (@_) {
1936 $name =~ s/_.*$//; # strip version
1937 foreach $dist (@dists) {
1938 my $db = $dist ne $distribution ? $otherdb{$dist} : \%db;
1939 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1941 $pkg = $db->{$name};
1942 if (!defined( $pkg )) {
1943 print "$pname: not registered\n";
1948 foreach $key (@firstkeys) {
1949 next if !exists $pkg->{$key};
1950 my $val = $pkg->{$key};
1952 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1954 printf " %-20s: %s\n", $key, $val;
1956 foreach $key (sort keys %$pkg) {
1957 next if isin( $key, @firstkeys );
1958 my $val = $pkg->{$key};
1960 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1962 printf " %-20s: %s\n", $key, $val;
1968 sub forget_packages {
1969 my( $name, $pkg, $key, $data );
1971 foreach $name (@_) {
1972 $name =~ s/_.*$//; # strip version
1974 if (!defined( $pkg )) {
1975 print "$name: not registered\n";
1980 foreach $key (sort keys %$pkg) {
1981 my $val = $pkg->{$key};
1984 $data .= sprintf " %-20s: %s\n", $key, $val;
1986 send_mail( $conf::db_maint,
1987 "$name deleted from DB $conf::dbbase",
1988 "The package '$name' has been deleted from the database ".
1990 "Data registered about the deleted package:\n".
1991 "$data\n" ) if $conf::db_maint;
1992 change_state( \$pkg, 'deleted' );
1993 log_ta( $pkg, "--forget" );
1995 print "$name: deleted from database\n" if $verbose;
2003 $ui = $db{'_userinfo'};
2004 foreach $name (@_) {
2005 if (!defined( $ui->{$name} )) {
2006 print "$name: not registered\n";
2010 delete $ui->{$name};
2012 print "$name: deleted from database\n" if $verbose;
2014 $db{'_userinfo'} = $ui if $change;
2020 my $lockfile = db_lockfilename($dist);
2023 print "Locking $dist database\n" if $verbose >= 2;
2025 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2027 # lock file exists, wait
2028 goto repeat if !open( F, "<$lockfile" );
2031 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2032 warn "Bad lock file contents -- still trying\n";
2035 my($pid, $usr) = ($1, $2);
2036 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2037 # process doesn't exist anymore, remove stale lock
2038 print "Removing stale lock file (pid $pid, user $usr)\n";
2039 unlink( $lockfile );
2042 if ($pid == $lock_for_pid) {
2043 # We are allowed to use this lock.
2046 warn "Database locked by $usr -- please wait\n" if $try == 0;
2049 # avoid the END routine removes the lock
2050 $main::keep_lock{$dist} = 1;
2051 die "Lock still present after 200 * 5 seconds.\n";
2056 die "Can't create lock file $lockfile: $!\n";
2058 my $pid = $lock_for_pid == -1 ? $$ : $lock_for_pid;
2059 F->print("$pid $real_user\n");
2065 my $lockfile = db_lockfilename($dist);
2067 if (!$main::keep_lock{$dist}) {
2068 print "Unlocking $dist database\n" if $verbose >= 2;
2073 sub create_maintlock {
2074 my $lockfile = db_lockfilename("maintenance");
2078 print "Creating maintenance lock\n" if $verbose >= 2;
2080 if (!sysopen( F, $lockfile, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644 )){
2082 # lock file exists, wait
2083 goto repeat if !open( F, "<$lockfile" );
2086 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2087 warn "Bad maintenance lock file contents -- still trying\n";
2090 my($pid, $usr) = ($1, $2);
2091 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2092 # process doesn't exist anymore, remove stale lock
2093 print "Removing stale lock file (pid $pid, user $usr)\n";
2094 unlink( $lockfile );
2097 warn "Maintenance lock already exists by $usr -- ".
2098 "please wait\n" if $try == 0;
2101 die "Lock still present after 120 * 60 seconds.\n";
2106 die "Can't create maintenance lock $lockfile: $!\n";
2108 F->print(getppid(), " $real_user\n");
2112 sub remove_maintlock {
2113 my $lockfile = db_lockfilename("maintenance");
2115 print "Removing maintenance lock\n" if $verbose >= 2;
2119 sub waitfor_maintlock {
2120 my $lockfile = db_lockfilename("maintenance");
2124 print "Checking for maintenance lock\n" if $verbose >= 2;
2126 if (open( F, "<$lockfile" )) {
2129 if ($line !~ /^(\d+)\s+([\w\d.-]+)$/) {
2130 warn "Bad maintenance lock file contents -- still trying\n";
2133 my($pid, $usr) = ($1, $2);
2134 if (kill( 0, $pid ) == 0 && $! == ESRCH) {
2135 # process doesn't exist anymore, remove stale lock
2136 print "Removing stale maintenance lock (pid $pid, user $usr)\n";
2137 unlink( $lockfile );
2140 warn "Databases locked for general maintenance by $usr -- ".
2141 "please wait\n" if $try == 0;
2144 die "Lock still present after 120 * 60 seconds.\n";
2155 print "Reading ASCII database from $file..." if $verbose >= 1;
2156 open( F, "<$file" ) or
2157 die "Can't open database $file: $!\n";
2159 local($/) = ""; # read in paragraph mode
2161 my( %thispkg, $name );
2163 s/\n[ \t]+/\376\377/g; # fix continuation lines
2164 s/\376\377\s*\376\377/\376\377/og;
2166 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2167 my ($key, $val) = ($1, $2);
2168 $val =~ s/\376\377/\n/g;
2169 $thispkg{$key} = $val;
2171 check_entry( \%thispkg );
2173 if (exists($thispkg{'Package'})) {
2174 $name = $thispkg{'Package'};
2175 $db{$name} = \%thispkg;
2177 elsif(exists($thispkg{'User'})) {
2178 my $userinfo = $db{'_userinfo'};
2179 $userinfo = {} if (!defined($userinfo));
2181 $name = $thispkg{'User'};
2182 $userinfo->{$name} = \%thispkg;
2184 $db{'_userinfo'} = $userinfo;
2188 print "done\n" if $verbose >= 1;
2195 return if $op_mode eq "manual-edit"; # no checks then
2197 # check for required fields
2198 if (exists $pkg->{'User'}) {
2201 if (!exists $pkg->{'Package'}) {
2202 print STDERR "Bad entry: ",
2203 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2204 die "Database entry lacks Package or User: field\n";
2206 if (!exists $pkg->{'Version'}) {
2207 die "Database entry for $pkg->{'Package'} lacks Version: field\n";
2209 # if no State: field, generate one (for old db compat)
2210 if (!exists($pkg->{'State'})) {
2212 exists $pkg->{'Failed'} ? 'Failed' : 'Building';
2215 die "Bad state $pkg->{'State'} of package $pkg->{Package}\n"
2216 if !isin( $pkg->{'State'},
2217 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait
2218 Failed Failed-Removed Not-For-Us BD-Uninstallable
2224 my($name,$pkg,$key);
2226 print "Writing ASCII database to $file..." if $verbose >= 1;
2227 open( F, ">$file" ) or
2228 die "Can't open database $file: $!\n";
2230 foreach $name (sort keys %db) {
2231 my $pkg = $db{$name};
2232 if ($name eq '_userinfo') {
2233 foreach $user (sort keys %{$pkg}) {
2234 my $ui = $pkg->{$user};
2235 print F "User: $user\n"
2236 if (!defined($ui->{'User'}));
2237 foreach $key (keys %{$ui}) {
2238 my $val = $ui->{$key};
2241 $val =~ s/^ +$/ ./mg;
2242 print F "$key: $val\n";
2248 foreach $key (keys %{$pkg}) {
2249 my $val = $pkg->{$key};
2252 $val =~ s/^ +$/ ./mg;
2253 print F "$key: $val\n";
2259 print "done\n" if $verbose >= 1;
2265 my $newstate = shift;
2266 my $for_dist = shift;
2269 return if !open_other_db( $for_dist );
2270 $db = $otherdb{$for_dist};
2271 $pkg = \$db{$pkg->{'Package'}};
2276 my $state = \$pkg->{'State'};
2278 return if defined($$state) and $$state eq $newstate;
2279 $pkg->{'Previous-State'} = $$state if defined($$state);
2280 $pkg->{'State-Change'} = $curr_date;
2282 if (defined($$state) and $$state eq 'Failed') {
2283 $pkg->{'Old-Failed'} =
2284 "-"x20 . " $pkg->{'Version'} " . "-"x20 . "\n" .
2285 $pkg->{'Failed'} . "\n" .
2286 $pkg->{'Old-Failed'};
2287 delete $pkg->{'Failed'};
2288 delete $pkg->{'Failed-Category'};
2290 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2291 delete $pkg->{'BD-Problem'};
2293 $$state = $newstate;
2299 if (!tied(%{$otherdb{$dist}})) {
2301 $otherdb_lock{$dist} = 1;
2302 if (!(tie %{$otherdb{$dist}}, 'MLDBM', db_filename($dist), 0, 0664)){
2303 warn "Serious warning: Cannot open database for $dist\n";
2305 $otherdb_lock{$dist} = 0;
2316 my $dist = $distribution;
2320 $prevstate = $pkg->{'Previous-State'};
2321 $str = "$action($dist): $pkg->{'Package'}_$pkg->{'Version'} ".
2322 "changed from $prevstate to $pkg->{'State'} ".
2323 "by $real_user as $user";
2325 my $transactlog = db_transactlog( $distribution );
2326 if (!open( LOG, ">>$transactlog" )) {
2327 warn "Can't open log file $transactlog: $!\n";
2330 print LOG "$curr_date: $str\n";
2333 if (!($prevstate eq 'Failed' && $pkg->{'State'} eq 'Failed')) {
2334 $str .= " (with --override)"
2336 $mail_logs .= "$str\n";
2343 my $subject = shift;
2346 my $from = $conf::db_maint;
2347 my $domain = $conf::buildd_domain;
2349 $from .= "\@$domain" if $from !~ /\@/;
2351 $to .= '@' . $domain if $to !~ /\@/;
2352 $text =~ s/^\.$/../mg;
2353 local $SIG{'PIPE'} = 'IGNORE';
2354 open( PIPE, "| $conf::mailprog -oem $to" )
2355 or die "Can't open pipe to $conf::mailprog: $!\n";
2357 print PIPE "From: $from\n";
2358 print PIPE "Subject: $subject\n\n";
2359 print PIPE "$text\n";
2365 return $transactional ? db_filename_transaction($dist) : db_filename_master($dist);
2367 sub db_filename_master {
2369 return "$conf::basedir/$conf::dbbase-$dist";
2371 sub db_filename_transaction {
2373 return "$conf::basedir/$conf::dbbase-$dist-transaction";
2376 sub db_lockfilename {
2378 return db_filename_master($dist) . ".lock";
2382 sub db_transactlog {
2384 return $transactional ? db_transactlog_transaction($dist) : db_transactlog_master($dist);
2386 sub db_transactlog_master {
2388 $conf::dbbase =~ m#^([^/]+/)#;
2389 return "$conf::basedir/$1$conf::transactlog";
2391 sub db_transactlog_transaction {
2393 $conf::dbbase =~ m#^([^/]+/)#;
2394 return "$conf::basedir/$1$conf::transactlog-$dist-transaction";
2397 # for parsing input to dep-wait
2403 foreach (split( /\s*,\s*/, $deps )) {
2405 # verification requires > starting prompts, no | crap
2406 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2411 my @alts = split( /\s*\|\s*/, $_ );
2412 # Anything with an | is ignored, as it can be configured on a
2413 # per-buildd basis what will be installed
2414 next if $#alts != 0;
2417 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2418 warn( "parse_deplist: bad dependency $_\n" );
2421 my($dep, $rel, $relv) = ($1, $3, $4);
2422 $rel = ">>" if defined($rel) and $rel eq ">";
2423 $result{$dep}->{'Package'} = $dep;
2424 if ($rel && $relv) {
2425 $result{$dep}->{'Rel'} = $rel;
2426 $result{$dep}->{'Version'} = $relv;
2429 return 1 if $verify;
2433 # for parsing Build-Depends from Sources
2434 sub parse_srcdeplist {
2441 foreach $dep (split( /\s*,\s*/, $deps )) {
2442 my @alts = split( /\s*\|\s*/, $dep );
2443 # Anything with an | is ignored, as it can be configured on a
2444 # per-buildd basis what will be installed
2445 next if $#alts != 0;
2447 if (!/^([^\s([]+)\s*(\(\s*([<=>]+)\s*(\S+)\s*\))?(\s*\[([^]]+)\])?/) {
2448 warn( "parse_srcdeplist: bad dependency $_\n" );
2451 my($dep, $rel, $relv, $archlist) = ($1, $3, $4, $6);
2453 $archlist =~ s/^\s*(.*)\s*$/$1/;
2454 my @archs = split( /\s+/, $archlist );
2455 my ($use_it, $ignore_it, $include) = (0, 0, 0);
2458 $ignore_it = 1 if substr($_, 1) eq $arch;
2460 $use_it = 1 if $_ eq $arch;
2464 warn "Warning: inconsistent arch restriction on ",
2465 "$pkg: $dep depedency\n"
2466 if $ignore_it && $use_it;
2467 next if $ignore_it || ($include && !$use_it);
2475 $result->{'Package'} = $dep;
2476 $result->{'Neg'} = $neg;
2477 if ($rel && $relv) {
2478 $result->{'Rel'} = $rel;
2479 $result->{'Version'} = $relv;
2481 push @results, $result;
2490 foreach $key (keys %$list) {
2491 $result .= ", " if $result;
2493 $result .= " ($list->{$key}->{'Rel'} $list->{$key}->{'Version'})"
2494 if $list->{$key}->{'Rel'} && $list->{$key}->{'Version'};
2501 tie %new_db, 'MLDBM', db_filename( $distribution ) . ".new", GDBM_WRCREAT, 0664
2502 or die "FATAL: Cannot create new database\n";
2504 untie %db or die "FATAL: Cannot untie old database\n";
2505 system ("cp " . db_filename( $distribution ) . ".new " .
2506 db_filename( $distribution ) ) == 0
2507 or die "FATAL: Cannot overwrite old database";
2508 unlink db_filename( $distribution ) . ".new";
2513 sub get_unsatisfied_dep {
2517 my $savedep = shift;
2519 my $pkgname = $dep->{'Package'};
2521 if (defined $pkgs->{$pkgname}{'Provider'}) {
2522 # provides. leave them for buildd/sbuild.
2527 return $pkgs->{$pkgname}{'Unsatisfied'} if $savedep and defined($pkgs->{$pkgname}{'Unsatisfied'});
2529 # Return unsatisfied deps to a higher caller to process
2530 if ((!defined($pkgs->{$pkgname})) or
2531 (defined($dep->{'Rel'}) and !version_compare( $pkgs->{$pkgname}{'Version'}, $dep->{'Rel'}, $dep->{'Version'} ) ) ) {
2533 $deplist{$pkgname} = $dep;
2534 my $deps = build_deplist(\%deplist);
2535 $pkgs->{$pkgname}{'Unsatisfied'} = $deps if $savedep;
2539 # set cache to "" to avoid infinite recursion
2540 $pkgs->{$pkgname}{'Unsatisfied'} = "" if $savedep;
2542 if (defined $pkgs->{$dep->{'Package'}}{'Depends'}) {
2543 my $deps = parse_deplist( $pkgs->{$dep->{'Package'}}{'Depends'} );
2544 foreach (keys %$deps) {
2547 my $ret = get_unsatisfied_dep($bd,$pkgs,$dep,1);
2549 my $retdep = parse_deplist( $ret );
2550 foreach (keys %$retdep) {
2551 $dep = $$retdep{$_};
2553 $dep->{'Rel'} = '>=' if defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^=';
2555 if (defined($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>' and defined ($pkgs->{$dep->{'Package'}}) and
2556 version_compare($bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'ver'},'>>',$pkgs->{$dep->{'Package'}}{'Sourcev'})) {
2557 if (not defined($merge_binsrc{$dep->{'Package'}})) {
2558 # the uninstallable package doesn't exist in the new source; look for something else that does.
2559 delete $$retdep{$dep->{'Package'}};
2560 foreach (sort (split( /\s*,\s*/, $bd->{$pkgs->{$dep->{'Package'}}{'Source'}}{'bin'}))) {
2561 next if ($pkgs->{$_}{'all'} or not defined $pkgs->{$_}{'Version'});
2562 $dep->{'Package'} = $_;
2563 $dep->{'Rel'} = '>>';
2564 $dep->{'Version'} = $pkgs->{$_}{'Version'};
2565 $$retdep{$_} = $dep;
2570 # sanity check to make sure the depending binary still exists, and the depended binary exists and dep-wait on a new version of it
2571 if ( defined($merge_binsrc{$pkgname}) and defined($pkgs->{$dep->{'Package'}}{'Version'}) ) {
2572 delete $$retdep{$dep->{'Package'}};
2573 $dep->{'Package'} = $pkgname;
2574 $dep->{'Rel'} = '>>';
2575 $dep->{'Version'} = $pkgs->{$pkgname}{'Version'};
2576 $$retdep{$pkgname} = $dep;
2578 delete $$retdep{$dep->{'Package'}} if (defined ($dep->{'Rel'}) and $dep->{'Rel'} =~ '^>');
2581 $ret = build_deplist($retdep);
2582 $pkgs->{$pkgname}{'Unsatisfied'} = $ret if $savedep;
2590 sub call_edos_depcheck {
2591 my $packagesfile = shift;
2595 return if defined ($conf::distributions{$distribution}{noadw});
2597 # We need to check all of needs-build, as any new upload could make
2598 # something in needs-build have uninstallable deps
2599 # We also check everything in bd-uninstallable, as any new upload could
2600 # make that work again
2601 my %interesting_packages;
2602 foreach $key (keys %db) {
2603 my $pkg = $db{$key};
2604 if (defined $pkg and isin($pkg->{'State'}, qw/Needs-Build BD-Uninstallable/)) {
2605 $interesting_packages{$key} = undef;
2609 #print "I would look at these sources with edos-depcheck:\n";
2610 #print join " ", keys %interesting_packages,"\n";
2612 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2614 for( $i = 0;; ++$i ) {
2615 $tmpfile = $tmpfile_pattern . $i;
2616 last if ! -e $tmpfile;
2619 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2620 for my $key (keys %interesting_packages) {
2621 my $pkg = $db{$key};
2622 print SOURCES "Package: $key\n";
2623 print SOURCES "Version: $pkg->{'Version'}\n";
2624 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2625 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2626 print SOURCES "Architecture: all\n";
2631 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2633 local($/) = ""; # read in paragraph mode
2635 my( $key, $reason ) ;
2637 /^Package:\s*(\S+)$/mi and $key = $1;
2638 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2639 $reason =~ s/^\s*//mg;
2640 $reason ||= 'No reason given by edos-debcheck';
2642 if (exists $interesting_packages{$key}) {
2643 $interesting_packages{$key} = $reason;
2645 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2650 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2651 "all packages have installable build-dependencies."
2656 for my $key (keys %interesting_packages) {
2657 my $pkg = $db{$key};
2659 (defined $interesting_packages{$key} and $pkg->{'State'} eq 'Needs-Build') ||
2660 (not defined $interesting_packages{$key} and $pkg->{'State'} eq 'BD-Uninstallable');
2661 my $problemchange = $interesting_packages{$key} ne $pkg->{'BD-Problem'};
2663 if (defined $interesting_packages{$key}) {
2664 change_state( \$pkg, 'BD-Uninstallable' );
2665 $pkg->{'BD-Problem'} = $interesting_packages{$key};
2667 change_state( \$pkg, 'Needs-Build' );
2670 if ($problemchange) {
2671 if (defined $interesting_packages{$key}) {
2672 $pkg->{'BD-Problem'} = $interesting_packages{$key};
2676 log_ta( $pkg, "--merge-all" );
2677 print "edos-builddebchange changed state of ${key}_$pkg->{'Version'} to $pkg->{'State'}\n" if $verbose;
2679 if ($change || $problemchange) {
2687 ($prgname = $0) =~ s,^.*/,,;
2689 Usage: $prgname <options...> <package_version...>
2691 -v, --verbose: Verbose execution.
2692 --take: Take package for building [default operation]
2693 -f, --failed: Record in database that a build failed due to
2694 deficiencies in the package (that aren't fixable without a new
2696 -u, --uploaded: Record in the database that the packages build
2697 correctly and were uploaded.
2698 -n, --no-build: Record in the database that the packages aren't
2699 desired for this architecture and shouldn't appear in listings even
2700 if they're out of date.
2701 --dep-wait: Record in the database that the packages are waiting
2702 for some source dependencies to become available
2703 --binNMU num: Schedule a re-build of the package with unchanged source, but
2704 a new version number (source-version + "+b<num>")
2705 --give-back: Mark a package as ready to build that is in state Building,
2706 Built or Build-Attempted. To give back a package in state Failed, use
2707 --override. This command will actually put the package in state
2708 BD-Uninstallable, until the installability of its Build-Dependencies
2709 were verified. This happens at each call of --merge-all, usually
2711 --merge-quinn: Merge quinn-diff output into database.
2712 --merge-packages: Merge Packages files into database.
2713 --pretend-avail: Pretend that given packages are available now and give
2714 free packages waiting for them
2715 -i SRC_PKG, --info SRC_PKG: Show information for source package
2716 -l STATE, --list=STATE: List all packages in state STATE; can be
2717 combined with -U to restrict to a specific user; STATE can
2719 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2720 source dependency list
2721 (used with -f, --dep-wait, and --binNMU)
2722 -o, --override: Override another user's lock on a package, i.e.
2723 take it over; a notice mail will be sent to the other user
2724 -U USER, --user=USER: select user name for which listings should
2725 apply, if not given all users are listed.
2726 if -l is missing, set user name to be entered in db; usually
2727 automatically choosen
2728 --import FILE: Import database from a ASCII file FILE
2729 --export FILE: Export database to a ASCII file FILE
2730 --lock-for PID: Locks the database for the process with this pid
2731 --unlock-for PID: Unlocks the database for the process with this pid
2732 --act-on-behalf-of PID: Ignores the lock (if it is held by this pid)
2733 --start-transaction: Creates a copy of the state of the database, for
2734 use with --transactional. This overrides any previous uncommited
2735 transaction. Should only be used after --lock-for
2736 --commit-transaction: Atomically moves the copy back to the main, thus
2737 commiting the changes
2738 --transactional: Flag to indicate that we want to work on the copy
2740 The remaining arguments (depending on operation) usually start with
2741 "name_version", the trailer is ignored. This allows to pass the names
2742 of .dsc files, for which file name completion can be used.
2743 --merge-packages and --merge-quinn take Package/quin--diff file names
2744 on the command line or read stdin. --list needs nothing more on the
2745 command line. --info takes source package names (without version).
2750 sub pkg_version_eq {
2752 my $version = shift;
2755 if (defined $pkg->{'Binary-NMU-Version'}) and
2756 version_compare(binNMU_version($pkg->{'Version'},
2757 $pkg->{'Binary-NMU-Version'}),'=', $version);
2758 return version_compare( $pkg->{'Version'}, "=", $version );