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 "/org/wanna-build/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 lib '/org/wanna-build/bin';
46 use Hash::Merge qw ( merge );
49 use List::Util qw[max];
51 our ($verbose, $mail_logs, $list_order, $list_state,
52 $curr_date, $op_mode, $user, $real_user, $distribution,
53 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
55 $info_all_dists, $arch,
56 $category, %catval, %short_category,
57 $short_date, $list_min_age, $dbbase, @curr_time,
58 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
59 $printformat, $ownprintformat
63 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
68 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
69 $short_date = strftime("%m/%d/%y",@curr_time);
72 # map program invocation names to operation modes
73 my %prognames = ( "uploaded-build" => "set-uploaded",
74 "failed-build" => "set-failed",
75 "no-build" => "set-not-for-us",
76 "give-back-build" => "set-needs-build",
77 "dep-wait-build" => "set-dep-wait",
78 "forget-build" => "forget",
79 "merge-quinn" => "merge-quinn",
80 "merge-packages" => "merge-packages",
81 "merge-sources" => "merge-sources",
82 "build-info" => "info" );
84 %short_category = ( u => "uploaded-fixed-pkg",
91 c => "compiler-error",
95 ($progname = $0) =~ s,.*/,,;
96 if ($prognames{$progname}) {
97 $op_mode = $prognames{$progname};
99 elsif ($progname =~ /^list-(.*)$/) {
101 $list_state = ($1 eq "all") ? "" : $1;
106 verbose => { short => "v", flag => \$verbose },
107 override => { short => "o", flag => \$opt_override },
108 "create-db" => { flag => \$opt_create_db },
109 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
110 # TODO: remove after buildds no longer pass to wanna-build
111 "no-propagation" => { short => "N" },
112 "no-down-propagation" => { short => "D" },
114 take => { mode => "set-building" },
115 failed => { short => "f", mode => "set-failed" },
116 uploaded => { short => "u", mode => "set-uploaded" },
117 "no-build" => { short => "n", mode => "set-not-for-us" },
118 built => { mode => "set-built" },
119 attempted => { mode => "set-attempted" },
120 "give-back" => { mode => "set-needs-build" },
121 "dep-wait" => { mode => "set-dep-wait" },
122 forget => { mode => "forget" },
123 'forget-user' => { mode => 'forget-user' },
124 "merge-quinn" => { mode => "merge-quinn" },
125 "merge-partial-quinn" => { mode => "merge-partial-quinn" },
126 "merge-packages" => { mode => "merge-packages" },
127 "merge-sources" => { mode => "merge-sources" },
128 "pretend-avail" => { short => "p", mode => "pretend-avail" },
129 "merge-all" => { mode => "merge-all" },
130 "merge-all-secondary" => { mode => "merge-all-secondary" },
131 info => { short => "i", mode => "info" },
132 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
133 code => sub { die "Invalid binNMU version: $binNMUver\n"
134 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
135 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
136 code => sub { die "Invalid build priority: $build_priority\n"
137 if $build_priority !~ /^-?[\d]+$/; } },
138 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
139 code => sub { die "Invalid build priority: $build_priority\n"
140 if $build_priority !~ /^-?[\d]+$/; } },
142 { short => "l", mode => "list", arg => \$list_state,
144 die "Unknown state to list: $list_state\n"
145 if !isin( $list_state, qw(needs-build building uploaded
146 built build-attempted failed installed dep-wait
147 not-for-us all failed-removed
148 install-wait reupload-wait bd-uninstallable));} },
151 { short => "d", arg => \$distribution,
153 if ($distribution eq "a" || $distribution eq "all") {
158 $distribution = "oldstable" if $distribution eq "o";
159 $distribution = "stable" if $distribution eq "s";
160 $distribution = "testing" if $distribution eq "t";
161 $distribution = "unstable" if $distribution eq "u";
165 { short => "O", arg => \$list_order,
167 die "Bad ordering character\n"
168 if $list_order !~ /^[PSpsncbCW]+$/;
170 message => { short => "m", arg => \$fail_reason },
171 # database is deprecated, use arch instead.
172 database => { short => "b", arg => \$conf::dbbase },
173 arch => { short => "A", arg => \$arch },
174 user => { short => "U", arg => \$user },
175 category => { short => "c", arg => \$category,
177 $category = $short_category{$category}
178 if exists $short_category{$category};
179 die "Unknown category: $category\n"
180 if !isin( $category, values %short_category );
182 "min-age" => { short => "a", arg => \$list_min_age,
184 die "Argument of --min-age must be a non-zero number\n"
185 if $list_min_age == 0;
187 "max-age" => { arg => \$list_min_age,
189 die "Argument of --max-age must be a non-zero number\n"
190 if $list_min_age == 0;
193 "format" => { arg => \$printformat },
194 "own-format" => { arg => \$ownprintformat },
196 export => { arg => \$export_to, mode => "export" },
197 import => { arg => \$import_from, mode => "import" },
198 "manual-edit" => { mode => "manual-edit" },
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 $distribution ||= "unstable";
245 die "Bad distribution '$distribution'\n"
246 if !isin($distribution, keys %conf::distributions);
248 # If they didn't specify an arch, try to get it from database name which
249 # is in the form of $arch/build-db
250 # This is for backwards compatibity with older versions that didn't
251 # specify the arch yet.
252 $conf::dbbase =~ m#^([^/]+)#;
255 # TODO: Check that it's an known arch (for that dist), and give
259 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
260 $version =~ s/(^\$| \$ .*$)//g;
261 print "wanna-build $version for $distribution on $arch\n";
264 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
265 merge-packages manual-edit
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;
307 my $yamldir = "/org/wanna-build/etc/yaml";
308 my @files = ('wanna-build.yaml');
309 if ((getpwuid($>))[7]) { push (@files, ((getpwuid($>))[7])."/.wanna-build.yaml"); }
310 if ($user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
311 if ($user) { push ( @files, "$user.yaml"); }
312 foreach my $file (@files) {
313 my $cfile = File::Spec->rel2abs( $file, $yamldir );
314 if ($verbose >= 2) { print "Trying to read $file ($cfile) ...\n"; }
315 next unless -f $cfile;
316 if ($verbose >= 2) { print "Read $file ($cfile) ...\n"; }
317 my $m = YAML::Tiny->read( $cfile )->[0];
318 $yamlmap = merge($m, $yamlmap);
321 die "FATAL: no configuration found\n";
323 $list_order = $yamlmap->{"list-order"}{$list_state} if !$list_order and $list_state;
324 $list_order ||= $yamlmap->{"list-order"}{'default'};
331 $dbh->disconnect or warn $dbh->errstr;
335 my $schema_suffix = '';
336 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !(not -t and $user =~ /-/)) {
337 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
338 die "FATAL: Cannot open database: $DBI::errstr\n";
339 $schema_suffix = '_public';
343 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
344 die "FATAL: Cannot open database: $DBI::errstr\n";
347 # TODO: This shouldn't be needed, file a bug.
348 $dbh->{pg_server_prepare} = 0;
350 $dbh->begin_work or die $dbh->errstr;
357 if ($mail_logs && $conf::log_mail) {
358 send_mail( $conf::log_mail,
359 "wanna-build $distribution state changes $curr_date",
360 "State changes at $curr_date for distribution ".
361 "$distribution:\n\n$mail_logs\n" );
369 SWITCH: foreach ($op_mode) {
371 add_packages( $1, @ARGV );
375 list_packages( $list_state );
379 info_packages( @ARGV );
382 /^forget-user/ && do {
383 die "This operation is restricted to admin users\n"
384 if (defined @conf::admin_users and
385 !isin( $real_user, @conf::admin_users));
386 forget_users( @ARGV );
390 forget_packages( @ARGV );
393 /^merge-partial-quinn/ && do {
394 die "This operation is restricted to admin users\n"
395 if (defined @conf::admin_users and
396 !isin( $real_user, @conf::admin_users));
401 /^merge-quinn/ && do {
402 die "This operation is restricted to admin users\n"
403 if (defined @conf::admin_users and
404 !isin( $real_user, @conf::admin_users));
409 /^merge-packages/ && do {
410 die "This operation is restricted to admin users\n"
411 if (defined @conf::admin_users and
412 !isin( $real_user, @conf::admin_users));
417 /^merge-sources/ && 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));
425 /^pretend-avail/ && do {
426 pretend_avail( @ARGV );
429 /^merge-all$/ && do {
430 die "This operation is restricted to admin users\n"
431 if (defined @conf::admin_users and
432 !isin( $real_user, @conf::admin_users));
435 @ARGV = ( $ARGS[0] );
436 my $pkgs = parse_packages(0);
437 @ARGV = ( $ARGS[1] );
439 @ARGV = ( $ARGS[2] );
440 my $srcs = parse_sources(1);
441 call_edos_depcheck( $ARGS[0], $srcs );
444 /^merge-all-secondary/ && do {
445 die "This operation is restricted to admin users\n"
446 if (defined @conf::admin_users and
447 !isin( $real_user, @conf::admin_users));
448 # This is in case the chroot has multiple unrelated
449 # dist, for instance unstable and experimental.
450 # This is not for stable and proposed-updates.
451 # The second packages file contains a combination
452 # of all Packages files known to the buildd, the
453 # first only for the current dist.
456 @ARGV = ( $ARGS[0] );
457 my $pkgs = parse_packages(0);
458 @ARGV = ( $ARGS[3] );
459 my $pkgs = parse_packages(1);
460 @ARGV = ( $ARGS[1] );
462 @ARGV = ( $ARGS[2] );
463 my $srcs = parse_sources(1);
464 call_edos_depcheck( $ARGS[3], $srcs );
468 die "This operation is restricted to admin users\n"
469 if (defined @conf::admin_users and
470 !isin( $real_user, @conf::admin_users));
471 $dbh->do("DELETE from " . table_name() .
472 " WHERE distribution = ?", undef,
476 read_db( $import_from );
480 export_db( $export_to );
484 die "Unexpected operation mode $op_mode\n";
486 if (not -t and $user =~ /-/) {
487 my $userinfo = get_user_info($user);
488 if (!defined $userinfo)
490 add_user_info($user);
494 update_user_info($user);
500 my $newstate = shift;
501 my( $package, $name, $version, $ok, $reason );
503 foreach $package (@_) {
504 $package =~ s,^.*/,,; # strip path
505 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
506 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
507 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
508 ($name,$version) = ($1,$2);
511 warn "$package: can't extract package name and version ".
516 if ($op_mode eq "set-building") {
517 add_one_building( $name, $version );
519 elsif ($op_mode eq "set-built") {
520 add_one_built( $name, $version );
522 elsif ($op_mode eq "set-attempted") {
523 add_one_attempted( $name, $version );
525 elsif ($op_mode eq "set-uploaded") {
526 add_one_uploaded( $name, $version );
528 elsif ($op_mode eq "set-failed") {
529 add_one_failed( $name, $version );
531 elsif ($op_mode eq "set-not-for-us") {
532 add_one_notforus( $name, $version );
534 elsif ($op_mode eq "set-needs-build") {
535 add_one_needsbuild( $name, $version );
537 elsif ($op_mode eq "set-dep-wait") {
538 add_one_depwait( $name, $version );
540 elsif ($op_mode eq "set-build-priority") {
541 set_one_buildpri( $name, $version, 'buildpri' );
543 elsif ($op_mode eq "set-permanent-build-priority") {
544 set_one_buildpri( $name, $version, 'permbuildpri' );
546 elsif ($op_mode eq "set-binary-nmu") {
547 set_one_binnmu( $name, $version );
552 sub add_one_building {
558 my $pkg = get_source_info($name);
560 if ($pkg->{'state'} eq "Not-For-Us") {
562 $reason = "not suitable for this architecture";
564 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
566 $reason = "not all source dependencies available yet";
568 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
570 $reason = "source dependencies are not installable";
572 elsif ($pkg->{'state'} eq "Uploaded" &&
573 (version_lesseq($version, $pkg->{'version'}))) {
575 $reason = "already uploaded by $pkg->{'builder'}";
576 $reason .= " (in newer version $pkg->{'version'})"
577 if !version_eq($pkg, $version);
579 elsif ($pkg->{'state'} eq "Installed" &&
580 version_less($version,$pkg->{'version'})) {
582 print "$name: Warning: newer version $pkg->{'version'} ".
583 "already installed, but overridden.\n";
587 $reason = "newer version $pkg->{'version'} already in ".
588 "archive; doesn't need rebuilding";
589 print "$name: Note: If the following is due to an epoch ",
590 " change, use --override\n";
593 elsif ($pkg->{'state'} eq "Installed" &&
594 pkg_version_eq($pkg,$version)) {
596 $reason = "is up-to-date in the archive; doesn't need rebuilding";
598 elsif ($pkg->{'state'} eq "Needs-Build" &&
599 version_less($version,$pkg->{'version'})) {
601 print "$name: Warning: newer version $pkg->{'version'} ".
602 "needs building, but overridden.";
606 $reason = "newer version $pkg->{'version'} needs building, ".
610 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
611 if (version_less($pkg->{'version'},$version)) {
612 print "$name: Warning: Older version $pkg->{'version'} ",
613 "is being built by $pkg->{'builder'}\n";
614 if ($pkg->{'builder'} ne $user) {
615 send_mail( $pkg->{'builder'},
616 "package takeover in newer version",
617 "You are building package '$name' in ".
618 "version $version\n".
619 "(as far as I'm informed).\n".
620 "$user now has taken the newer ".
621 "version $version for building.".
622 "You can abort the build if you like.\n" );
627 print "User $pkg->{'builder'} had already ",
628 "taken the following package,\n",
629 "but overriding this as you request:\n";
630 send_mail( $pkg->{'builder'}, "package takeover",
631 "The package '$name' (version $version) that ".
632 "was taken by you\n".
633 "has been taken over by $user\n" );
635 elsif ($pkg->{'builder'} eq $user) {
636 print "$name: Note: already taken by you.\n";
637 print "$name: ok\n" if $verbose;
642 $reason = "already taken by $pkg->{'builder'}";
643 $reason .= " (in newer version $pkg->{'version'})"
644 if !version_eq($pkg->{'version'}, $version);
648 elsif ($pkg->{'state'} =~ /^Failed/ &&
649 pkg_version_eq($pkg, $version)) {
651 print "The following package previously failed ",
652 "(by $pkg->{'builder'})\n",
653 "but overriding this as you request:\n";
654 send_mail( $pkg->{'builder'}, "failed package takeover",
655 "The package '$name' (version $version) that ".
657 "and has failed previously has been taken over ".
659 if $pkg->{'builder'} ne $user;
663 $reason = "build of $version failed previously:\n ";
664 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
665 $reason .= "\nalso the package doesn't need builing"
666 if $pkg->{'state'} eq 'Failed-Removed';
672 if ($pkg->{'binary_nmu_version'}) {
673 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
674 "$pkg->{'binary_nmu_changelog'}\n";
677 print "$name: Warning: Previous version failed!\n"
678 if $pkg->{'previous_state'} =~ /^Failed/ ||
679 $pkg->{'state'} =~ /^Failed/;
681 change_state( \$pkg, 'Building' );
682 $pkg->{'package'} = $name;
683 $pkg->{'version'} = $version;
684 $pkg->{'builder'} = $user;
685 log_ta( $pkg, "--take" );
686 update_source_info($pkg);
687 print "$name: $ok\n" if $verbose;
690 print "$name: NOT OK!\n $reason\n";
694 sub add_one_attempted {
697 my $pkg = get_source_info($name);
699 if (!defined($pkg)) {
700 print "$name: not registered yet.\n";
704 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
705 print "$name: not taken for building (state is $pkg->{'state'}). ",
709 if ($pkg->{'builder'} ne $user) {
710 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
713 elsif ( !pkg_version_eq($pkg, $version) ) {
714 print "$name: version mismatch ".
715 "$(pkg->{'version'} ".
716 "by $pkg->{'builder'})\n";
720 change_state( \$pkg, 'Build-Attempted' );
721 log_ta( $pkg, "--attempted" );
722 update_source_info($pkg);
723 print "$name: registered as uploaded\n" if $verbose;
729 my $pkg = get_source_info($name);
731 if (!defined($pkg)) {
732 print "$name: not registered yet.\n";
736 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
737 print "$name: not taken for building (state is $pkg->{'state'}). ",
741 if ($pkg->{'builder'} ne $user) {
742 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
745 elsif ( !pkg_version_eq($pkg, $version) ) {
746 print "$name: version mismatch ".
747 "$(pkg->{'version'} ".
748 "by $pkg->{'builder'})\n";
751 change_state( \$pkg, 'Built' );
752 log_ta( $pkg, "--built" );
753 update_source_info($pkg);
754 print "$name: registered as built\n" if $verbose;
757 sub add_one_uploaded {
760 my $pkg = get_source_info($name);
762 if (!defined($pkg)) {
763 print "$name: not registered yet.\n";
767 if ($pkg->{'state'} eq "Uploaded" &&
768 pkg_version_eq($pkg,$version)) {
769 print "$name: already uploaded\n";
772 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
773 print "$name: not taken for building (state is $pkg->{'state'}). ",
777 if ($pkg->{'builder'} ne $user) {
778 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
781 # strip epoch -- buildd-uploader used to go based on the filename.
782 # (to remove at some point)
784 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
785 $version =~ s/^\d+://; # for command line use
786 if ($pkg->{'binary_nmu_version'} ) {
787 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
788 if (!version_eq( $nmuver, $version )) {
789 print "$name: version mismatch ($nmuver registered). ",
793 } elsif (!version_eq($pkgver, $version)) {
794 print "$name: version mismatch ($pkg->{'version'} registered). ",
799 change_state( \$pkg, 'Uploaded' );
800 log_ta( $pkg, "--uploaded" );
801 update_source_info($pkg);
802 print "$name: registered as uploaded\n" if $verbose;
809 my $pkg = get_source_info($name);
811 if (!defined($pkg)) {
812 print "$name: not registered yet.\n";
815 $state = $pkg->{'state'};
817 if ($state eq "Not-For-Us") {
818 print "$name: not suitable for this architecture anyway. Skipping.\n";
821 elsif ($state eq "Failed-Removed") {
822 print "$name: failed previously and doesn't need building. Skipping.\n";
825 elsif ($state eq "Installed") {
826 print "$name: Is already installed in archive. Skipping.\n";
829 elsif ($pkg->{'builder'} &&
830 (($user ne $pkg->{'builder'}) &&
831 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
832 print "$name: not taken by you, but by ".
833 "$pkg->{'builder'}. Skipping.\n";
836 elsif ( !pkg_version_eq($pkg, $version) ) {
837 print "$name: version mismatch ".
838 "$(pkg->{'version'} ".
839 "by $pkg->{'builder'})\n";
844 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
846 $cat = $short_category{$cat} if exists $short_category{$cat};
847 if (!isin( $cat, values %short_category )) {
848 print "$name: Warning: unknown category $cat; discarded\n";
851 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
854 if ($state eq "Needs-Build") {
855 print "$name: Warning: not registered for building previously, ".
856 "but processing anyway.\n";
858 elsif ($state eq "Uploaded") {
859 print "$name: Warning: marked as uploaded previously, ".
860 "but processing anyway.\n";
862 elsif ($state eq "Dep-Wait") {
863 print "$name: Warning: marked as waiting for dependencies, ".
864 "but processing anyway.\n";
866 elsif ($state eq "BD-Uninstallable") {
867 print "$name: Warning: marked as having uninstallable build-dependencies, ".
868 "but processing anyway.\n";
870 elsif ($state eq "Failed") {
871 print "$name: already registered as failed; will append new message\n"
873 print "$name: already registered as failed; changing category\n"
877 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
878 defined $pkg->{'failed_category'} &&
879 $pkg->{'failed_category'} ne $cat) {
880 (my $action = $cat) =~ s/-/ /;
881 $fail_reason .= "\n$short_date: $action";
884 change_state( \$pkg, 'Failed' );
885 $pkg->{'builder'} = $user;
886 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
887 $pkg->{'failed'} .= $fail_reason;
888 $pkg->{'failed_category'} = $cat if $cat;
889 if (defined $pkg->{'permbuildpri'}) {
890 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
892 delete $pkg->{'buildpri'};
894 log_ta( $pkg, "--failed" );
895 update_source_info($pkg);
896 print "$name: registered as failed\n" if $verbose;
899 sub add_one_notforus {
902 my $pkg = get_source_info($name);
904 if ($pkg->{'state'} eq 'Not-For-Us') {
905 # reset Not-For-Us state in case it's called twice; this is
906 # the only way to get a package out of this state...
907 # There is no really good state in which such packages should
908 # be put :-( So use Failed for now.
909 change_state( \$pkg, 'Failed' );
910 $pkg->{'package'} = $name;
911 $pkg->{'failed'} = "Was Not-For-Us previously";
912 delete $pkg->{'builder'};
913 delete $pkg->{'depends'};
914 log_ta( $pkg, "--no-build(rev)" );
915 print "$name: now not unsuitable anymore\n";
917 send_mail( $conf::notforus_maint,
918 "$name moved out of Not-For-Us state",
919 "The package '$name' has been moved out of the Not-For-Us ".
921 "It should probably also be removed from ".
922 "Packages-arch-specific or\n".
923 "the action was wrong.\n" )
924 if $conf::notforus_maint;
927 change_state( \$pkg, 'Not-For-Us' );
928 $pkg->{'package'} = $name;
929 delete $pkg->{'builder'};
930 delete $pkg->{'depends'};
931 delete $pkg->{'buildpri'};
932 delete $pkg->{'binary_nmu_version'};
933 delete $pkg->{'binary_nmu_changelog'};
934 log_ta( $pkg, "--no-build" );
935 print "$name: registered as unsuitable\n" if $verbose;
937 send_mail( $conf::notforus_maint,
938 "$name set to Not-For-Us",
939 "The package '$name' has been set to state Not-For-Us ".
941 "It should probably also be added to ".
942 "Packages-arch-specific or\n".
943 "the Not-For-Us state is wrong.\n" )
944 if $conf::notforus_maint;
946 update_source_info($pkg);
949 sub add_one_needsbuild {
953 my $pkg = get_source_info($name);
955 if (!defined($pkg)) {
956 print "$name: not registered; can't give back.\n";
959 $state = $pkg->{'state'};
961 if ($state eq "BD-Uninstallable") {
963 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
965 change_state( \$pkg, 'Needs-Build' );
966 delete $pkg->{'builder'};
967 delete $pkg->{'depends'};
968 log_ta( $pkg, "--give-back" );
969 update_source_info($pkg);
970 print "$name: given back\n" if $verbose;
974 print "$name: has uninstallable build-dependencies. Skipping\n",
975 " (use --override to clear dependency list and ",
976 "give back anyway)\n";
980 elsif ($state eq "Dep-Wait") {
982 print "$name: Forcing source dependency list to be cleared\n";
985 print "$name: waiting for source dependencies. Skipping\n",
986 " (use --override to clear dependency list and ",
987 "give back anyway)\n";
991 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
992 print "$name: not taken for building (state is $state).";
994 print "\n$name: Forcing give-back\n";
997 print " Skipping.\n";
1001 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
1002 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
1004 print "$name: not taken by you, but by ".
1005 "$pkg->{'builder'}. Skipping.\n";
1008 if (!pkg_version_eq($pkg, $version)) {
1009 print "$name: version mismatch ($pkg->{'version'} registered). ",
1013 if ($distribution eq "unstable") {
1014 change_state( \$pkg, 'BD-Uninstallable' );
1015 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1017 change_state( \$pkg, 'Needs-Build' );
1019 $pkg->{'builder'} = undef;
1020 $pkg->{'depends'} = undef;
1021 log_ta( $pkg, "--give-back" );
1022 update_source_info($pkg);
1023 print "$name: given back\n" if $verbose;
1026 sub set_one_binnmu {
1028 my $version = shift;
1029 my $pkg = get_source_info($name);
1032 if (!defined($pkg)) {
1033 print "$name: not registered; can't register for binNMU.\n";
1036 my $db_ver = $pkg->{'version'};
1038 if (!version_eq($db_ver, $version)) {
1039 print "$name: version mismatch ($db_ver registered). ",
1043 $state = $pkg->{'state'};
1045 if (defined $pkg->{'binary_nmu_version'}) {
1046 if ($binNMUver == 0) {
1047 change_state( \$pkg, 'Installed' );
1048 delete $pkg->{'builder'};
1049 delete $pkg->{'depends'};
1050 delete $pkg->{'binary_nmu_version'};
1051 delete $pkg->{'binary_nmu_changelog'};
1052 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1053 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1056 $pkg->{'binary_nmu_version'} = $binNMUver;
1057 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1058 $pkg->{'notes'} = 'out-of-date';
1059 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1060 if (defined $pkg->{'permbuildpri'});
1062 log_ta( $pkg, "--binNMU" );
1063 update_source_info($pkg);
1065 } elsif ($binNMUver == 0) {
1066 print "${name}_$version: no scheduled binNMU to cancel.\n";
1070 if ($state ne 'Installed') {
1071 print "${name}_$version: not installed; can't register for binNMU.\n";
1075 my $fullver = binNMU_version($version,$binNMUver);
1076 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1078 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1082 if ($distribution eq "unstable") {
1083 change_state( \$pkg, 'BD-Uninstallable' );
1084 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1088 change_state( \$pkg, 'Needs-Build' );
1090 delete $pkg->{'builder'};
1091 delete $pkg->{'depends'};
1092 $pkg->{'binary_nmu_version'} = $binNMUver;
1093 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1094 $pkg->{'notes'} = 'out-of-date';
1095 log_ta( $pkg, "--binNMU" );
1096 update_source_info($pkg);
1097 print "${name}: registered for binNMU $fullver\n" if $verbose;
1100 sub set_one_buildpri {
1102 my $version = shift;
1104 my $pkg = get_source_info($name);
1107 if (!defined($pkg)) {
1108 print "$name: not registered; can't set priority.\n";
1111 $state = $pkg->{'state'};
1113 if ($state eq "Not-For-Us") {
1114 print "$name: not suitable for this architecture. Skipping.\n";
1116 } elsif ($state eq "Failed-Removed") {
1117 print "$name: failed previously and doesn't need building. Skipping.\n";
1120 if (!pkg_version_eq($pkg, $version)) {
1121 print "$name: version mismatch ($pkg->{'version'} registered). ",
1125 if ( $build_priority == 0 ) {
1126 delete $pkg->{'buildpri'}
1127 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1128 and $pkg->{'buildpri'} == $pkg->{$key};
1129 delete $pkg->{$key};
1131 $pkg->{'buildpri'} = $build_priority
1132 if $key eq 'permbuildpri';
1133 $pkg->{$key} = $build_priority;
1135 update_source_info($pkg);
1136 print "$name: set to build priority $build_priority\n" if $verbose;
1139 sub add_one_depwait {
1141 my $version = shift;
1143 my $pkg = get_source_info($name);
1145 if (!defined($pkg)) {
1146 print "$name: not registered yet.\n";
1149 $state = $pkg->{'state'};
1151 if ($state eq "Dep-Wait") {
1152 print "$name: merging with previously registered dependencies\n";
1155 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1156 print "$name: Warning: not registered for building previously, ".
1157 "but processing anyway.\n";
1159 elsif ($state eq "Not-For-Us") {
1160 print "$name: not suitable for this architecture anyway. Skipping.\n";
1163 elsif ($state eq "Failed-Removed") {
1164 print "$name: failed previously and doesn't need building. Skipping.\n";
1167 elsif ($state eq "Installed") {
1168 print "$name: Is already installed in archive. Skipping.\n";
1171 elsif ($state eq "Uploaded") {
1172 print "$name: Is already uploaded. Skipping.\n";
1175 elsif ($pkg->{'builder'} &&
1176 $user ne $pkg->{'builder'}) {
1177 print "$name: not taken by you, but by ".
1178 "$pkg->{'builder'}. Skipping.\n";
1181 elsif ( !pkg_version_eq($pkg,$version)) {
1182 print "$name: version mismatch ".
1183 "($pkg->{'version'} ".
1184 "by $pkg->{'builder'})\n";
1187 elsif ($fail_reason =~ /^\s*$/ ||
1188 !parse_deplist( $fail_reason, 1 )) {
1189 print "$name: Bad dependency list\n";
1192 change_state( \$pkg, 'Dep-Wait' );
1193 $pkg->{'builder'} = $user;
1194 if (defined $pkg->{'permbuildpri'}) {
1195 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1197 delete $pkg->{'buildpri'};
1199 my $deplist = parse_deplist( $pkg->{'depends'} );
1200 my $new_deplist = parse_deplist( $fail_reason );
1201 # add new dependencies, maybe overwriting old entries
1202 foreach (keys %$new_deplist) {
1203 $deplist->{$_} = $new_deplist->{$_};
1205 $pkg->{'depends'} = build_deplist($deplist);
1206 log_ta( $pkg, "--dep-wait" );
1207 update_source_info($pkg);
1208 print "$name: registered as waiting for dependencies\n" if $verbose;
1218 my $db = get_all_source_info();
1220 local($/) = ""; # read in paragraph mode
1222 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1224 /^Package:\s*(\S+)$/mi and $name = $1;
1225 /^Version:\s*(\S+)$/mi and $version = $1;
1226 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1227 /^Section:\s*(\S+)$/mi and $section = $1;
1228 /^Priority:\s*(\S+)$/mi and $priority = $1;
1229 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1230 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1231 /^Binary:\s*(.*)$/mi and $binaries = $1;
1233 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1234 $srcver{$name} = $version;
1236 $pkgs{$name}{'ver'} = $version;
1237 $pkgs{$name}{'bin'} = $binaries;
1238 $pkgs{$name}{'dep'} = $builddep;
1239 $pkgs{$name}{'conf'} = $buildconf;
1240 my $pkg = $db->{$name};
1245 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1246 # package is now Arch: all, delete it from db
1247 change_state( \$pkg, 'deleted' );
1248 log_ta( $pkg, "--merge-sources" );
1249 print "$name ($pkg->{'version'}): deleted ".
1250 "from database, because now Arch: all\n"
1252 del_source_info($name);
1253 delete $db->{$name};
1257 # The "Version" should always be the source version --
1258 # not a possible binNMU version number.
1259 $pkg->{'version'} = $version, $change++
1260 if ($pkg->{'state'} eq 'Installed' and
1261 !version_eq( $pkg->{'version'}, $version));
1262 # Always update priority and section, if available
1263 $pkg->{'priority'} = $priority, $change++
1264 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1266 $pkg->{'section'} = $section, $change++
1267 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1269 update_source_info($pkg) if $change;
1272 # Now that we only have the latest source version, build the list
1273 # of binary packages from the Sources point of view
1274 foreach $name (keys %pkgs) {
1275 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1276 $merge_binsrc{$bin} = $name;
1279 # remove installed packages that no longer have source available
1280 # or binaries installed
1281 foreach $name (keys %$db) {
1282 next if $name =~ /^_/;
1283 my $pkg = $db->{$name};
1284 if (not defined($pkgs{$name})) {
1285 change_state( \$pkg, 'deleted' );
1286 log_ta( $pkg, "--merge-sources" );
1287 print "$name ($pkg->{'version'}): ".
1288 "deleted from database, because ".
1289 "not in Sources anymore\n"
1291 del_source_info($name);
1292 delete $db->{$name};
1294 next if !isin( $pkg->{'state'}, qw(Installed) );
1295 if ($full && not defined $merge_srcvers{$name}) {
1296 change_state( \$pkg, 'deleted' );
1297 log_ta( $pkg, "--merge-sources" );
1298 print "$name ($pkg->{'version'}): ".
1299 "deleted from database, because ".
1300 "binaries don't exist anymore\n"
1302 del_source_info($name);
1303 delete $db->{$name};
1304 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1305 print "$name ($pkg->{'version'}): ".
1306 "package is Installed but binaries are from ".
1307 $merge_srcvers{$name}. "\n"
1315 # This function looks through a Packages file and sets the state of
1316 # packages to 'Installed'
1317 sub parse_packages {
1318 my $depwait_only = shift;
1321 my $pkgs = get_all_source_info();
1322 local($/) = ""; # read in paragraph mode
1324 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1326 /^Package:\s*(\S+)$/mi and $name = $1;
1327 /^Version:\s*(\S+)$/mi and $version = $1;
1328 /^Depends:\s*(.*)$/mi and $depends = $1;
1329 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1330 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1331 /^Provides:\s*(.*)$/mi and $provides = $1;
1332 next if !$name || !$version;
1333 next if ($arch ne $architecture and $architecture ne "all");
1334 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1335 version_lesseq( $version, $installed->{$name}{'version'} ));
1336 $installed->{$name}{'version'} = $version;
1337 next if $depwait_only;
1338 $installed->{$name}{'depends'} = $depends;
1339 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1340 undef $installed->{$name}{'Provider'};
1341 $installed->{$name}{'Source'} = $source ? $source : $name;
1343 foreach (split( /\s*,\s*/, $provides )) {
1344 if (not defined ($installed->{$_})) {
1345 $installed->{$_}{'version'} = "";
1346 $installed->{$_}{'Provider'} = $name;
1350 if ( $version =~ /\+b(\d+)$/ ) {
1353 $version = $sourcev if $sourcev;
1354 $binaryv = $version;
1355 $binaryv =~ s/\+b\d+$//;
1356 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1357 $binaryv .= "+b$binnmu" if defined($binnmu);
1359 next if $architecture ne $arch;
1360 $name = $source if $source;
1361 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1362 $merge_srcvers{$name} = $version;
1364 my $pkg = $pkgs->{$name};
1367 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1368 (isin($pkg->{'state'}, qw(Installed)) &&
1369 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1370 print "Skipping $name because State == $pkg->{'state'}\n"
1374 if ($pkg->{'binary_nmu_version'} ) {
1375 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1376 if (version_less( $binaryv, $nmuver )) {
1377 print "Skipping $name ($version) because have newer ".
1378 "version ($nmuver) in db.\n"
1382 } elsif (version_less($version, $pkg->{'version'})) {
1383 print "Skipping $name ($version) because have newer ".
1384 "version ($pkg->{'version'}) in db.\n"
1389 if (!pkg_version_eq($pkg, $version) &&
1390 $pkg->{'state'} ne "Installed") {
1391 warn "Warning: $name: newer version than expected appeared ".
1392 "in archive ($version vs. $pkg->{'version'})\n";
1393 delete $pkg->{'builder'};
1396 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1397 warn "Warning: Package $name was not in uploaded state ".
1398 "before (but in '$pkg->{'state'}').\n";
1399 delete $pkg->{'builder'};
1400 delete $pkg->{'depends'};
1404 $pkg->{'version'} = $version;
1407 change_state( \$pkg, 'Installed' );
1408 $pkg->{'package'} = $name;
1409 $pkg->{'installed_version'} = $binaryv;
1410 if (defined $pkg->{'permbuildpri'}) {
1411 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1413 delete $pkg->{'buildpri'};
1415 $pkg->{'version'} = $version
1416 if version_less( $pkg->{'version'}, $version);
1417 delete $pkg->{'binary_nmu_version'};
1418 delete $pkg->{'binary_nmu_changelog'};
1419 log_ta( $pkg, "--merge-packages" );
1420 update_source_info($pkg);
1421 print "$name ($version) is up-to-date now.\n" if $verbose;
1424 check_dep_wait( "--merge-packages", $installed );
1429 my ($package, $name, $version, $installed);
1431 foreach $package (@_) {
1432 $package =~ s,^.*/,,; # strip path
1433 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1434 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1435 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1436 ($name,$version) = ($1,$2);
1439 warn "$package: can't extract package name and version ".
1443 $installed->{$name}{'version'} = $version;
1446 check_dep_wait( "--pretend-avail", $installed );
1449 sub check_dep_wait {
1451 my $installed = shift;
1453 # check all packages in state Dep-Wait if dependencies are all
1456 my $db = get_all_source_info();
1457 foreach $name (keys %$db) {
1458 next if $name =~ /^_/;
1459 my $pkg = $db->{$name};
1460 next if $pkg->{'state'} ne "Dep-Wait";
1461 my $deps = $pkg->{'depends'};
1463 print "$name: was in state Dep-Wait, but with empty ",
1465 goto make_needs_build;
1467 my $deplist = parse_deplist($deps);
1471 foreach (keys %$deplist) {
1472 if (!exists $installed->{$_} ||
1473 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1474 !version_compare( $installed->{$_}{'version'},
1475 $deplist->{$_}->{'rel'},
1476 $deplist->{$_}->{'version'}))) {
1478 $new_deplist->{$_} = $deplist->{$_};
1481 push( @removed_deps, $_ );
1486 change_state( \$pkg, 'Needs-Build' );
1487 log_ta( $pkg, $action );
1488 delete $pkg->{'builder'};
1489 delete $pkg->{'depends'};
1490 print "$name ($pkg->{'version'}) has all ",
1491 "dependencies available now\n" if $verbose;
1493 update_source_info($pkg);
1495 elsif (@removed_deps) {
1496 $pkg->{'depends'} = build_deplist( $new_deplist );
1497 print "$name ($pkg->{'version'}): some dependencies ",
1498 "(@removed_deps) available now, but not all yet\n"
1500 update_source_info($pkg);
1505 # This function accepts quinn-diff output (either from a file named on
1506 # the command line, or on stdin) and sets the packages named there to
1507 # state 'Needs-Build'.
1508 sub parse_quinn_diff {
1509 my $partial = shift;
1513 my $pkgs = get_all_source_info();
1517 next if !m,^([-\w\d/]*)/ # section
1518 ([-\w\d.+]+)_ # package name
1519 ([\w\d:.~+-]+)\.dsc\s* # version
1520 \[([^:]*): # priority
1521 ([^]]+)\]\s*$,x; # rest of notes
1522 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1523 $quinn_pkgs{$name}++;
1524 $section ||= "unknown";
1525 $priority ||= "unknown";
1526 $priority = "unknown" if $priority eq "-";
1527 $priority = "standard" if ($name eq "debian-installer");
1529 my $pkg = $pkgs->{$name};
1531 # Always update section and priority.
1532 if (defined($pkg)) {
1534 $pkg->{'section'} = $section, $change++ if not defined
1535 $pkg->{'section'} or $section ne "unknown";
1536 $pkg->{'priority'} = $priority, $change++ if not defined
1537 $pkg->{'priority'} or $priority ne "unknown";
1540 if (defined($pkg) &&
1541 $pkg->{'state'} =~ /^Dep-Wait/ &&
1542 version_less( $pkg->{'version'}, $version )) {
1543 change_state( \$pkg, 'Dep-Wait' );
1544 $pkg->{'version'} = $version;
1545 delete $pkg->{'binary_nmu_version'};
1546 delete $pkg->{'binary_nmu_changelog'};
1547 log_ta( $pkg, "--merge-quinn" );
1549 print "$name ($version) still waiting for dependencies.\n"
1552 elsif (defined($pkg) &&
1553 $pkg->{'state'} =~ /-Removed$/ &&
1554 version_eq($pkg->{'version'}, $version)) {
1555 # reinstantiate a package that has been removed earlier
1556 # (probably due to a quinn-diff malfunction...)
1557 my $newstate = $pkg->{'state'};
1558 $newstate =~ s/-Removed$//;
1559 change_state( \$pkg, $newstate );
1560 $pkg->{'version'} = $version;
1561 $pkg->{'notes'} = $notes;
1562 log_ta( $pkg, "--merge-quinn" );
1564 print "$name ($version) reinstantiated to $newstate.\n"
1567 elsif (defined($pkg) &&
1568 $pkg->{'state'} eq "Not-For-Us" &&
1569 version_less( $pkg->{'version'}, $version )) {
1570 # for Not-For-Us packages just update the version etc., but
1572 change_state( \$pkg, "Not-For-Us" );
1573 $pkg->{'package'} = $name;
1574 $pkg->{'version'} = $version;
1575 $pkg->{'notes'} = $notes;
1576 delete $pkg->{'builder'};
1577 log_ta( $pkg, "--merge-quinn" );
1579 print "$name ($version) still Not-For-Us.\n" if $verbose;
1581 elsif (!defined($pkg) ||
1582 $pkg->{'state'} ne "Not-For-Us" &&
1583 (version_less( $pkg->{'version'}, $version ) ||
1584 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1586 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1587 send_mail( $pkg->{'builder'},
1588 "new version of $name (dist=$distribution)",
1589 "As far as I'm informed, you're currently ".
1590 "building the package $name\n".
1591 "in version $pkg->{'version'}.\n\n".
1592 "Now there's a new source version $version. ".
1593 "If you haven't finished\n".
1594 "compiling $name yet, you can stop it to ".
1595 "save some work.\n".
1596 "Just to inform you...\n".
1597 "(This is an automated message)\n" );
1598 print "$name: new version ($version) while building ".
1599 "$pkg->{'version'} -- sending mail ".
1600 "to builder ($pkg->{'builder'})\n"
1603 change_state( \$pkg, 'Needs-Build' );
1604 $pkg->{'package'} = $name;
1605 $pkg->{'version'} = $version;
1606 $pkg->{'section'} = $section;
1607 $pkg->{'priority'} = $priority;
1608 $pkg->{'notes'} = $notes;
1609 delete $pkg->{'builder'};
1610 delete $pkg->{'binary_nmu_version'};
1611 delete $pkg->{'binary_nmu_changelog'};
1612 log_ta( $pkg, "--merge-quinn" );
1615 print "$name ($version) needs rebuilding now.\n" if $verbose;
1617 elsif (defined($pkg) &&
1618 !version_eq( $pkg->{'version'}, $version ) &&
1619 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1620 print "$name: skipping because version in db ".
1621 "($pkg->{'version'}) is >> than ".
1622 "what quinn-diff says ($version) ".
1623 "(state is $pkg->{'state'})\n"
1625 $dubious .= "$pkg->{'state'}: ".
1626 "db ${name}_$pkg->{'version'} >> ".
1627 "quinn $version\n" if !$partial;
1629 elsif ($verbose >= 2) {
1630 if ($pkg->{'state'} eq "Not-For-Us") {
1631 print "Skipping $name because State == ".
1632 "$pkg->{'state'}\n";
1634 elsif (!version_less($pkg->{'version'}, $version)) {
1635 print "Skipping $name because version in db ".
1636 "($pkg->{'version'}) is >= than ".
1637 "what quinn-diff says ($version)\n";
1640 update_source_info($pkg) if $change;
1644 send_mail( $conf::db_maint,
1645 "Dubious versions in " . table_name() . " "
1646 . $distribution . " table",
1647 "The following packages have a newer version in the ".
1648 "wanna-build database\n".
1649 "than what quinn-diff says, and this is strange for ".
1651 "It could be caused by a lame mirror, or the version ".
1652 "in the database\n".
1657 # Now re-check the DB for packages in states Needs-Build, Failed,
1658 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1659 # anymore by quinn-diff.
1662 my $db = get_all_source_info();
1663 foreach $name (keys %$db) {
1664 next if $name =~ /^_/;
1665 my $pkg = $db->{$name};
1666 next if defined $pkg->{'binary_nmu_version'};
1667 next if !isin( $pkg->{'state'},
1668 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1669 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1671 if (!$quinn_pkgs{$name}) {
1672 change_state( \$pkg, $virtual_delete ?
1673 $pkg->{'state'}."-Removed" :
1675 log_ta( $pkg, "--merge-quinn" );
1676 print "$name ($pkg->{'version'}): ".
1677 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1678 "from database, because not in quinn-diff anymore\n"
1680 if ($virtual_delete) {
1681 update_source_info($pkg);
1683 del_source_info($name);
1691 # for sorting priorities and sections
1693 %prioval = ( required => -5,
1701 'debian-installer' => -199,
1722 localizations => -178,
1723 interpreters => -177,
1748 electronics => -152,
1754 foreach my $i (keys %sectval) {
1755 $sectval{"contrib/$i"} = $sectval{$i}+40;
1756 $sectval{"non-free/$i"} = $sectval{$i}+80;
1758 $sectval{'unknown'} = -165;
1760 %catval = ( "none" => -20,
1761 "uploaded-fixed-pkg" => -19,
1762 "fix-expected" => -18,
1763 "reminder-sent" => -17,
1764 "nmu-offered" => -16,
1768 "compiler-error" => -12 );
1771 sub sort_list_func {
1773 'C' => ['<=>', sub { return (-1) * $_[0]->{'calprio'}; }],
1774 'W' => ['<=>', sub { return (-1) * $_[0]->{'state_days'}; }],
1775 'P' => ['<=>', sub { return (-1) * $_[0]->{'buildpri'}; }],
1776 'p' => ['<=>', sub { return $prioval{$_[0]->{'priority'}}; }],
1777 's' => ['<=>', sub { return $sectval{$_[0]->{'section'}}; }],
1778 'n' => ['cmp', sub { return $_[0]->{'package'}; }],
1779 'b' => ['cmp', sub { return $_[0]->{'builder'}; }],
1780 'c' => ['<=>', sub { return ($_[0]->{'notes'} =~ /^(out-of-date|partial)/) ? 0: ($_[0]->{'notes'} =~ /^uncompiled/) ? 2 : 1; }],
1781 'f' => ['<=>', sub { return $catval{ $_[0]->{'failed_category'} ? $_[0]->{'failed_category'}: "none" }; }],
1782 'S' => ['<=>', sub { return $prioval{$_[0]->{'priority'}} > $prioval{'standard'}; }],
1785 foreach my $letter (split( //, $list_order )) {
1787 $r = &{$map_funcs->{$letter}[1]}($a) <=> &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq '<=>';
1788 $r = &{$map_funcs->{$letter}[1]}($a) cmp &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq 'cmp';
1789 return $r if $r != 0;
1794 sub calculate_prio {
1795 my $priomap = $yamlmap->{priority};
1797 my @s=split("/", $pkg->{'section'});
1798 $pkg->{'component'} = $s[0] if $s[1];
1799 $pkg->{'component'} ||= 'main';
1800 $pkg->{'calprio'} = 0;
1801 foreach my $k (keys %{$priomap->{keys}}) {
1802 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1805 my $days = $pkg->{'state_days'};
1806 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1807 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1808 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1809 $pkg->{'calprio'} += $days * $scale;
1811 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1812 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1820 return "" unless $t;
1822 my $min = int($t/60) % 60;
1823 my $hours = int($t / 3600);
1824 return sprintf("%d:%02d:%02d", $hours, $min, $sec) if $hours;
1825 return sprintf("%d:%02d", $min, $sec);
1832 if (ref($_[0]) eq 'CODE') {
1842 return $r unless $t;
1846 if (substr($t,0,1) eq '!') {
1850 return "" unless $r;
1853 return print_format($t, $pkg, $var);
1857 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
1860 my $printfmt = shift;
1864 Within an format string, the following values are allowed (need to be preceded by %).
1865 This can be combined to e.g.
1866 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
1869 c section (e.g. libs or utils)
1870 D in case of BD-Uninstallable the reason for the uninstallability
1872 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
1873 F in case of Failed the fail reason
1875 o time of last successful build (seconds)
1876 O time of last successful build (formated)
1879 q time of last build (seconds)
1880 Q time of last build (formated)
1881 r max time of last (successful) build (seconds)
1882 R max time of last (successful) build (formated)
1884 s Time in this state in full seconds since epoch
1885 t time of state change
1886 u Builder (e.g. buildd_mipsel-rem)
1888 V full Package version (i.e. with +b.., = %v%{+b}B%B
1889 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
1891 %{Text}? print Text in case ? is not empty; ? is never printed
1892 %{!Text}? print Text in case ? is empty; ? is never printed
1893 Text could contain further %. To start with !, use %!
1896 return stringf($printfmt, (
1897 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
1898 'a' => make_fmt( $arch, $pkg, $var),
1899 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
1900 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
1901 'V' => make_fmt( sub { $pkg->{'binary_nmu_version'} ? $pkg->{'version'}."+b".$pkg->{'binary_nmu_version'} : $pkg->{'version'} }, $pkg, $var),
1902 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
1903 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
1904 'X' => make_fmt( sub {
1905 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
1906 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} =~ /^Failed/;
1907 $c .= ":bp{" . $pkg->{'buildpri'} . "}" if defined $pkg->{'buildpri'};
1908 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
1909 $c .= ":calprio{". $pkg->{'calprio'}."}";
1910 $c .= ":days{". $pkg->{'state_days'}."}";
1913 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
1914 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
1915 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
1916 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
1917 return ""; }, $pkg, $var),
1918 'F' => make_fmt( sub { return "" unless $pkg->{'failed'};
1919 my $failed = $pkg->{'failed'};
1920 $failed =~ s/\\/\\\\/g;
1921 return $pkg->{'package'}."#".$arch."-failure\n ".
1922 join("\\0a",split("\n",$failed))."\\0a\n"; }, $pkg, $var),
1923 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
1924 return $pkg->{'package'}."#".$arch."-bd-problem\n".
1925 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
1926 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
1927 'd' => make_fmt( $distribution, $pkg, $var),
1928 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
1929 'o' => make_fmt( $pkg->{'successtime'}, $pkg, $var),
1930 'O' => make_fmt( sub { return seconds2time ( $pkg->{'successtime'}); }, $pkg, $var),
1931 'q' => make_fmt( $pkg->{'anytime'}, $pkg, $var),
1932 'Q' => make_fmt( sub { return seconds2time ( $pkg->{'anytime'}); }, $pkg, $var),
1933 'r' => make_fmt( sub { return max($pkg->{'successtime'}, $pkg->{'anytime'}); }, $pkg, $var),
1934 'R' => make_fmt( sub { return seconds2time ( max($pkg->{'successtime'}, $pkg->{'anytime'})); }, $pkg, $var),
1940 my( $name, $pkg, @list );
1945 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
1946 foreach $name (keys %$db) {
1947 next if $name =~ /^_/;
1948 push @list, calculate_prio($db->{$name});
1952 @list = grep { my $i = $_->{'component'}; grep { $i eq $_ } split /[, ]+/, $yamlmap->{"restrict"}{'component'} } @list;
1954 # first adjust ownprintformat, then set printformat accordingly
1955 $printformat ||= $yamlmap->{"format"}{$ownprintformat};
1956 $printformat ||= $yamlmap->{"format"}{"default"}{$state};
1957 $printformat ||= $yamlmap->{"format"}{"default"}{"default"};
1958 undef $printformat if ($ownprintformat eq 'none');
1960 foreach $pkg (sort sort_list_func @list) {
1962 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
1964 $scnt{$pkg->{'state'}}++;
1967 print print_format("%c/%p_%v", $pkg, {});
1968 print print_format(": %S", $pkg, {})
1970 print print_format("%{ by }u%u", $pkg, {})
1971 if $pkg->{'state'} ne "Needs-Build";
1972 print print_format(" [%X]\n", $pkg, {});
1973 print " Reasons for failing:\n",
1975 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
1977 join("\n ",split("\n",$pkg->{'failed'})), "\n"
1978 if $pkg->{'state'} =~ /^Failed/;
1979 print " Dependencies: $pkg->{'depends'}\n"
1980 if $pkg->{'state'} eq "Dep-Wait";
1981 print " Reasons for BD-Uninstallable:\n ",
1982 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
1983 if $pkg->{'state'} eq "BD-Uninstallable";
1984 print " Previous state was $pkg->{'previous_state'}\n"
1985 if $verbose && $pkg->{'previous_state'};
1986 print " No previous state recorded\n"
1987 if $verbose && !$pkg->{'previous_state'};
1988 print " State changed at $pkg->{'state_change'}\n"
1989 if $verbose && $pkg->{'state_change'};
1990 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
1991 if $verbose && $pkg->{'previous_state'};
1992 print " Previous failing reasons:\n ",
1993 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
1994 if $verbose && $pkg->{'old_failed'};
1996 $scnt{$pkg->{'state'}}++ if $state eq "all";
1998 if ($state eq "all" && !$printformat) {
1999 foreach (sort keys %scnt) {
2000 print "Total $scnt{$_} package(s) in state $_.\n";
2003 print "Total $cnt package(s)\n" unless $printformat;
2008 my( $name, $pkg, $key, $dist );
2009 my @firstkeys = qw(package version builder state section priority
2010 installed_version previous_state state_change);
2011 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
2012 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
2013 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
2014 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
2015 'state_change' => 'State-Change',
2016 'bd_problem' => 'BD-Problem',
2017 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
2018 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
2019 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
2020 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
2021 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
2022 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days',
2023 'successtime' => 'Success-build-time',
2024 'anytime' => 'Build-time'
2027 foreach $name (@_) {
2028 $name =~ s/_.*$//; # strip version
2029 foreach $dist (@dists) {
2030 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
2032 $pkg = get_readonly_source_info($name);
2033 if (!defined( $pkg )) {
2034 print "$pname: not registered\n";
2037 $pkg = calculate_prio($pkg);
2040 foreach $key (@firstkeys) {
2041 next if !defined $pkg->{$key};
2042 my $val = $pkg->{$key};
2044 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2046 my $print_key = $key;
2047 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2048 printf " %-20s: %s\n", $print_key, $val;
2050 foreach $key (sort keys %$pkg) {
2051 next if isin( $key, @firstkeys );
2052 my $val = $pkg->{$key};
2053 next if !defined($val);
2055 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2057 my $print_key = $key;
2058 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2059 printf " %-20s: %s\n", $print_key, $val;
2065 sub forget_packages {
2066 my( $name, $pkg, $key, $data );
2068 foreach $name (@_) {
2069 $name =~ s/_.*$//; # strip version
2070 $pkg = get_source_info($name);
2071 if (!defined( $pkg )) {
2072 print "$name: not registered\n";
2077 foreach $key (sort keys %$pkg) {
2078 my $val = $pkg->{$key};
2081 $data .= sprintf " %-20s: %s\n", $key, $val;
2083 send_mail( $conf::db_maint,
2084 "$name deleted from DB " . table_name() . " " . $distribution,
2085 "The package '$name' has been deleted from the database ".
2087 "Data registered about the deleted package:\n".
2088 "$data\n" ) if $conf::db_maint;
2089 change_state( \$pkg, 'deleted' );
2090 log_ta( $pkg, "--forget" );
2091 del_source_info($name);
2092 print "$name: deleted from database\n" if $verbose;
2097 $dbh->do("DELETE from " . user_table_name() .
2098 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
2104 print "Reading ASCII database from $file..." if $verbose >= 1;
2105 open( F, "<$file" ) or
2106 die "Can't open database $file: $!\n";
2108 local($/) = ""; # read in paragraph mode
2110 my( %thispkg, $name );
2112 s/\n[ \t]+/\376\377/g; # fix continuation lines
2113 s/\376\377\s*\376\377/\376\377/og;
2115 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2116 my ($key, $val) = ($1, $2);
2118 $key =~ tr/A-Z/a-z/;
2119 $val =~ s/\376\377/\n/g;
2120 $thispkg{$key} = $val;
2122 check_entry( \%thispkg );
2124 if (exists($thispkg{'package'})) {
2125 update_source_info(\%thispkg);
2127 elsif(exists($thispkg{'user'})) {
2128 # user in import, username in database.
2129 $dbh->do('INSERT INTO ' . user_table_name() .
2130 ' (username, distribution, last_seen)' .
2131 ' values (?, ?, ?)',
2132 undef, $thispkg{'user'}, $distribution,
2133 $thispkg{'last_seen'})
2134 or die $dbh->errstr;
2138 print "done\n" if $verbose >= 1;
2145 return if $op_mode eq "manual-edit"; # no checks then
2147 # check for required fields
2148 if (exists $pkg->{'user'}) {
2151 if (!exists $pkg->{'package'}) {
2152 print STDERR "Bad entry: ",
2153 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2154 die "Database entry lacks package or username field\n";
2156 # if no State: field, generate one (for old db compat)
2157 if (!exists($pkg->{'state'})) {
2159 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2161 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2162 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2165 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2166 if !isin( $pkg->{'state'},
2167 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2168 Failed Failed-Removed Not-For-Us BD-Uninstallable
2174 my($name,$pkg,$key);
2176 print "Writing ASCII database to $file..." if $verbose >= 1;
2177 open( F, ">$file" ) or
2178 die "Can't open export $file: $!\n";
2180 my $db = get_all_source_info();
2181 foreach $name (keys %$db) {
2182 next if $name =~ /^_/;
2183 my $pkg = $db->{$name};
2184 foreach $key (keys %{$pkg}) {
2185 my $val = $pkg->{$key};
2186 next if !defined($val);
2189 $val =~ s/^ +$/ ./mg;
2190 print F "$key: $val\n";
2195 print "done\n" if $verbose >= 1;
2201 my $newstate = shift;
2202 my $state = \$pkg->{'state'};
2204 return if defined($$state) and $$state eq $newstate;
2205 $pkg->{'previous_state'} = $$state if defined($$state);
2206 $pkg->{'state_change'} = $curr_date;
2207 $pkg->{'do_state_change'} = 1;
2209 if (defined($$state) and $$state eq 'Failed') {
2210 $pkg->{'old_failed'} =
2211 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2212 $pkg->{'failed'} . "\n" .
2213 $pkg->{'old_failed'};
2214 delete $pkg->{'failed'};
2215 delete $pkg->{'failed_category'};
2217 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2218 delete $pkg->{'bd_problem'};
2220 $$state = $newstate;
2226 my $dist = $distribution;
2230 $prevstate = $pkg->{'previous_state'};
2231 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2232 "changed from $prevstate to $pkg->{'state'} ".
2233 "by $real_user as $user";
2235 $dbh->do('INSERT INTO ' . transactions_table_name() .
2236 ' (package, distribution, version, action, ' .
2237 ' prevstate, state, real_user, set_user, time) ' .
2238 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2239 undef, $pkg->{'package'}, $distribution,
2240 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2241 $real_user, $user, 'now()') or die $dbh->errstr;
2243 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2244 $str .= " (with --override)"
2246 $mail_logs .= "$str\n";
2253 my $subject = shift;
2256 my $from = $conf::db_maint;
2257 my $domain = $conf::buildd_domain;
2259 $from .= "\@$domain" if $from !~ /\@/;
2261 $to .= '@' . $domain if $to !~ /\@/;
2262 $text =~ s/^\.$/../mg;
2263 local $SIG{'PIPE'} = 'IGNORE';
2264 open( PIPE, "| $conf::mailprog -oem $to" )
2265 or die "Can't open pipe to $conf::mailprog: $!\n";
2267 print PIPE "From: $from\n";
2268 print PIPE "Subject: $subject\n\n";
2269 print PIPE "$text\n";
2273 # for parsing input to dep-wait
2279 foreach (split( /\s*,\s*/, $deps )) {
2281 # verification requires > starting prompts, no | crap
2282 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2287 my @alts = split( /\s*\|\s*/, $_ );
2288 # Anything with an | is ignored, as it can be configured on a
2289 # per-buildd basis what will be installed
2290 next if $#alts != 0;
2293 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2294 warn( "parse_deplist: bad dependency $_\n" );
2297 my($dep, $rel, $relv) = ($1, $3, $4);
2298 $rel = ">>" if defined($rel) and $rel eq ">";
2299 $result{$dep}->{'package'} = $dep;
2300 if ($rel && $relv) {
2301 $result{$dep}->{'rel'} = $rel;
2302 $result{$dep}->{'version'} = $relv;
2305 return 1 if $verify;
2313 foreach $key (keys %$list) {
2314 $result .= ", " if $result;
2316 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2317 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2322 sub call_edos_depcheck {
2323 my $packagesfile = shift;
2327 return if defined ($conf::distributions{$distribution}{noadw});
2329 # We need to check all of needs-build, as any new upload could make
2330 # something in needs-build have uninstallable deps
2331 # We also check everything in bd-uninstallable, as any new upload could
2332 # make that work again
2333 my %interesting_packages;
2334 my $db = get_all_source_info();
2335 foreach $key (keys %$db) {
2336 my $pkg = $db->{$key};
2337 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/)) {
2338 $interesting_packages{$key} = undef;
2342 #print "I would look at these sources with edos-depcheck:\n";
2343 #print join " ", keys %interesting_packages,"\n";
2345 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2347 for( $i = 0;; ++$i ) {
2348 $tmpfile = $tmpfile_pattern . $i;
2349 last if ! -e $tmpfile;
2352 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2353 for my $key (keys %interesting_packages) {
2354 my $pkg = $db->{$key};
2355 print SOURCES "Package: $key\n";
2356 print SOURCES "Version: $pkg->{'version'}\n";
2357 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2358 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2359 print SOURCES "Architecture: all\n";
2364 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2366 local($/) = ""; # read in paragraph mode
2368 my( $key, $reason ) ;
2370 /^Package:\s*(\S+)$/mi and $key = $1;
2371 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2372 $reason =~ s/^\s*//mg;
2373 $reason ||= 'No reason given by edos-debcheck';
2375 if (exists $interesting_packages{$key}) {
2376 $interesting_packages{$key} = $reason;
2378 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2383 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2384 "all packages have installable build-dependencies."
2389 for my $key (keys %interesting_packages) {
2390 my $pkg = $db->{$key};
2392 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2393 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2394 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2396 if (defined $interesting_packages{$key}) {
2397 change_state( \$pkg, 'BD-Uninstallable' );
2398 $pkg->{'bd_problem'} = $interesting_packages{$key};
2400 change_state( \$pkg, 'Needs-Build' );
2403 if ($problemchange) {
2404 if (defined $interesting_packages{$key}) {
2405 $pkg->{'bd_problem'} = $interesting_packages{$key};
2409 log_ta( $pkg, "--merge-all" );
2410 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} to $pkg->{'state'}\n" if $verbose;
2412 if ($change || $problemchange) {
2413 update_source_info($pkg);
2420 ($prgname = $0) =~ s,^.*/,,;
2422 Usage: $prgname <options...> <package_version...>
2424 -v, --verbose: Verbose execution.
2425 -A arch: Architecture this operation is for.
2426 --take: Take package for building [default operation]
2427 -f, --failed: Record in database that a build failed due to
2428 deficiencies in the package (that aren't fixable without a new
2430 -u, --uploaded: Record in the database that the packages build
2431 correctly and were uploaded.
2432 -n, --no-build: Record in the database that the packages aren't
2433 desired for this architecture and shouldn't appear in listings even
2434 if they're out of date.
2435 --dep-wait: Record in the database that the packages are waiting
2436 for some source dependencies to become available
2437 --binNMU num: Schedule a re-build of the package with unchanged source, but
2438 a new version number (source-version + "+b<num>")
2439 --give-back: Mark a package as ready to build that is in state Building,
2440 Built or Build-Attempted. To give back a package in state Failed, use
2441 --override. This command will actually put the package in state
2442 BD-Uninstallable, until the installability of its Build-Dependencies
2443 were verified. This happens at each call of --merge-all, usually
2445 --merge-quinn: Merge quinn-diff output into database.
2446 --merge-packages: Merge Packages files into database.
2447 --pretend-avail: Pretend that given packages are available now and give
2448 free packages waiting for them
2449 -i SRC_PKG, --info SRC_PKG: Show information for source package
2450 -l STATE, --list=STATE: List all packages in state STATE; can be
2451 combined with -U to restrict to a specific user; STATE can
2453 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2454 source dependency list
2455 (used with -f, --dep-wait, and --binNMU)
2456 -o, --override: Override another user's lock on a package, i.e.
2457 take it over; a notice mail will be sent to the other user
2458 -U USER, --user=USER: select user name for which listings should
2459 apply, if not given all users are listed.
2460 if -l is missing, set user name to be entered in db; usually
2461 automatically choosen
2462 --import FILE: Import database from a ASCII file FILE
2463 --export FILE: Export database to a ASCII file FILE
2465 The remaining arguments (depending on operation) usually start with
2466 "name_version", the trailer is ignored. This allows to pass the names
2467 of .dsc files, for which file name completion can be used.
2468 --merge-packages and --merge-quinn take Package/quin--diff file names
2469 on the command line or read stdin. --list needs nothing more on the
2470 command line. --info takes source package names (without version).
2475 sub pkg_version_eq {
2477 my $version = shift;
2480 if (defined $pkg->{'binary_nmu_version'}) and
2481 version_compare(binNMU_version($pkg->{'version'},
2482 $pkg->{'binary_nmu_version'}),'=', $version);
2483 return version_compare( $pkg->{'version'}, "=", $version );
2487 return '"' . $arch . $schema_suffix . '".packages';
2490 sub user_table_name {
2491 return '"' . $arch . $schema_suffix . '".users';
2494 sub transactions_table_name {
2495 return '"' . $arch . $schema_suffix . '".transactions';
2498 sub pkg_history_table_name {
2499 return '"' . $arch . $schema_suffix . '".pkg_history';
2502 sub get_readonly_source_info {
2504 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2505 my $q = 'SELECT rel, priority, state_change, permbuildpri, section, buildpri, failed, state, binary_nmu_changelog, bd_problem, version, package, distribution, installed_version, notes, failed_category, builder, old_failed, previous_state, binary_nmu_version, depends, extract(days from date_trunc(\'days\', now() - state_change)) as state_days, successtime.build_time as successtime, anytime.build_time as anytime FROM ' .
2508 'select distinct on (package, distribution) build_time, package, distribution from '.pkg_history_table_name().' where result = \'successful\' order by package, distribution, timestamp desc '.
2509 ' ) as successtime using (package, distribution) '.
2511 'select distinct on (package, distribution) build_time, package, distribution from '.pkg_history_table_name().' order by package, distribution, timestamp desc'.
2512 ' ) as anytime using (package, distribution) '.
2513 ' WHERE package = ? AND distribution = ?';
2514 my $pkg = $dbh->selectrow_hashref( $q,
2515 undef, $name, $distribution);
2519 sub get_source_info {
2521 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change)) as state_days FROM ' .
2522 table_name() . ' WHERE package = ? AND distribution = ?' .
2524 undef, $name, $distribution);
2528 sub get_all_source_info {
2531 my $q = 'SELECT rel, priority, state_change, permbuildpri, section, buildpri, failed, state, binary_nmu_changelog, bd_problem, version, package, distribution, installed_version, notes, failed_category, builder, old_failed, previous_state, binary_nmu_version, depends, extract(days from date_trunc(\'days\', now() - state_change)) as state_days, successtime.build_time as successtime, anytime.build_time as anytime FROM ' .
2534 'select distinct on (package, distribution) build_time, package, distribution from '.pkg_history_table_name().' where result = \'successful\' order by package, distribution, timestamp desc '.
2535 ' ) as successtime using (package, distribution) '.
2537 'select distinct on (package, distribution) build_time, package, distribution from '.pkg_history_table_name().' order by package, distribution, timestamp desc'.
2538 ' ) as anytime using (package, distribution) '
2539 . ' WHERE distribution = ? ';
2540 my @args = ($distribution);
2541 if ($options{state} && uc($options{state}) ne "ALL") {
2542 $q .= ' AND upper(state) = ? ';
2543 push @args, uc($options{state});
2546 if ($options{user}) {
2547 #this basically means "this user, or no user at all":
2548 $q .= ' AND (builder = ? OR upper(state) = ?)';
2549 push @args, $options{user};
2550 push @args, "NEEDS-BUILD";
2553 if ($options{category}) {
2554 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2555 push @args, $options{category};
2556 push @args, "FAILED";
2559 if ($options{list_min_age} > 0) {
2560 $q .= ' AND age(state_change) > ? ';
2561 push @args, $options{list_min_age} . " days";
2564 if ($options{list_min_age} < 0) {
2565 $q .= ' AND age(state_change) < ? ';
2566 push @args, -$options{list_min_age} . " days";
2569 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2573 sub update_source_info {
2576 my $pkg2 = get_source_info($pkg->{'package'});
2577 if (! defined $pkg2)
2579 add_source_info($pkg);
2582 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2587 'installed_version = ?, ' .
2588 'previous_state = ?, ' .
2589 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2593 'old_failed = ?, ' .
2594 'binary_nmu_version = ?, ' .
2595 'binary_nmu_changelog = ?, ' .
2596 'failed_category = ?, ' .
2597 'permbuildpri = ?, ' .
2602 'WHERE package = ? AND distribution = ?',
2608 $pkg->{'installed_version'},
2609 $pkg->{'previous_state'},
2613 $pkg->{'old_failed'},
2614 $pkg->{'binary_nmu_version'},
2615 $pkg->{'binary_nmu_changelog'},
2616 $pkg->{'failed_category'},
2617 $pkg->{'permbuildpri'},
2621 $pkg->{'bd_problem'},
2623 $distribution) or die $dbh->errstr;
2626 sub add_source_info {
2628 $dbh->do('INSERT INTO ' . table_name() .
2629 ' (package, distribution) values (?, ?)',
2630 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2633 sub del_source_info {
2635 $dbh->do('DELETE FROM ' . table_name() .
2636 ' WHERE package = ? AND distribution = ?',
2637 undef, $name, $distribution) or die $dbh->errstr;
2642 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2643 user_table_name() . ' WHERE username = ? AND distribution = ?',
2644 undef, $name, $distribution);
2648 sub update_user_info {
2650 $dbh->do('UPDATE ' . user_table_name() .
2651 ' SET last_seen = now() WHERE username = ?' .
2652 ' AND distribution = ?',
2653 undef, $user, $distribution)
2654 or die $dbh->errstr;
2660 $dbh->do('INSERT INTO ' . user_table_name() .
2661 ' (username, distribution, last_seen)' .
2662 ' values (?, ?, now())',
2663 undef, $user, $distribution)
2664 or die $dbh->errstr;
2669 $dbh->do('LOCK TABLE ' . table_name() .
2670 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;