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 );
50 our ($verbose, $mail_logs, $list_order, $list_state,
51 $curr_date, $op_mode, $user, $real_user, $distribution,
52 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
54 $info_all_dists, $arch,
55 $category, %catval, %short_category,
56 $short_date, $list_min_age, $dbbase, @curr_time,
57 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
62 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
67 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
68 $short_date = strftime("%m/%d/%y",@curr_time);
71 # map program invocation names to operation modes
72 my %prognames = ( "uploaded-build" => "set-uploaded",
73 "failed-build" => "set-failed",
74 "no-build" => "set-not-for-us",
75 "give-back-build" => "set-needs-build",
76 "dep-wait-build" => "set-dep-wait",
77 "forget-build" => "forget",
78 "merge-quinn" => "merge-quinn",
79 "merge-packages" => "merge-packages",
80 "merge-sources" => "merge-sources",
81 "build-info" => "info" );
83 %short_category = ( u => "uploaded-fixed-pkg",
90 c => "compiler-error",
94 ($progname = $0) =~ s,.*/,,;
95 if ($prognames{$progname}) {
96 $op_mode = $prognames{$progname};
98 elsif ($progname =~ /^list-(.*)$/) {
100 $list_state = ($1 eq "all") ? "" : $1;
105 verbose => { short => "v", flag => \$verbose },
106 override => { short => "o", flag => \$opt_override },
107 "create-db" => { flag => \$opt_create_db },
108 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
109 # TODO: remove after buildds no longer pass to wanna-build
110 "no-propagation" => { short => "N" },
111 "no-down-propagation" => { short => "D" },
113 take => { mode => "set-building" },
114 failed => { short => "f", mode => "set-failed" },
115 uploaded => { short => "u", mode => "set-uploaded" },
116 "no-build" => { short => "n", mode => "set-not-for-us" },
117 built => { mode => "set-built" },
118 attempted => { mode => "set-attempted" },
119 "give-back" => { mode => "set-needs-build" },
120 "dep-wait" => { mode => "set-dep-wait" },
121 forget => { mode => "forget" },
122 'forget-user' => { mode => 'forget-user' },
123 "merge-quinn" => { mode => "merge-quinn" },
124 "merge-partial-quinn" => { mode => "merge-partial-quinn" },
125 "merge-packages" => { mode => "merge-packages" },
126 "merge-sources" => { mode => "merge-sources" },
127 "pretend-avail" => { short => "p", mode => "pretend-avail" },
128 "merge-all" => { mode => "merge-all" },
129 "merge-all-secondary" => { mode => "merge-all-secondary" },
130 info => { short => "i", mode => "info" },
131 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
132 code => sub { die "Invalid binNMU version: $binNMUver\n"
133 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
134 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
135 code => sub { die "Invalid build priority: $build_priority\n"
136 if $build_priority !~ /^-?[\d]+$/; } },
137 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
138 code => sub { die "Invalid build priority: $build_priority\n"
139 if $build_priority !~ /^-?[\d]+$/; } },
141 { short => "l", mode => "list", arg => \$list_state,
143 die "Unknown state to list: $list_state\n"
144 if !isin( $list_state, qw(needs-build building uploaded
145 built build-attempted failed installed dep-wait
146 not-for-us all failed-removed
147 install-wait reupload-wait bd-uninstallable));} },
150 { short => "d", arg => \$distribution,
152 if ($distribution eq "a" || $distribution eq "all") {
157 $distribution = "oldstable" if $distribution eq "o";
158 $distribution = "stable" if $distribution eq "s";
159 $distribution = "testing" if $distribution eq "t";
160 $distribution = "unstable" if $distribution eq "u";
164 { short => "O", arg => \$list_order,
166 die "Bad ordering character\n"
167 if $list_order !~ /^[PSpsncbCW]+$/;
169 message => { short => "m", arg => \$fail_reason },
170 # database is deprecated, use arch instead.
171 database => { short => "b", arg => \$conf::dbbase },
172 arch => { short => "A", arg => \$arch },
173 user => { short => "U", arg => \$user },
174 category => { short => "c", arg => \$category,
176 $category = $short_category{$category}
177 if exists $short_category{$category};
178 die "Unknown category: $category\n"
179 if !isin( $category, values %short_category );
181 "min-age" => { short => "a", arg => \$list_min_age,
183 die "Argument of --min-age must be a non-zero number\n"
184 if $list_min_age == 0;
186 "max-age" => { arg => \$list_min_age,
188 die "Argument of --max-age must be a non-zero number\n"
189 if $list_min_age == 0;
192 "format" => { arg => \$printformat },
194 export => { arg => \$export_to, mode => "export" },
195 import => { arg => \$import_from, mode => "import" },
196 "manual-edit" => { mode => "manual-edit" },
199 while( @ARGV && $ARGV[0] =~ /^-/ ) {
202 my($opt, $optname, $arg);
203 if (/^--([^=]+)(=|$)/) {
205 $opt = $options{$optname};
206 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
209 $optname = substr( $_, 1, 1 );
210 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
211 $arg = $1 if /^-$optname(.+)$/;
214 warn "Unknown option: --$1\n";
219 die "$optname option missing argument\n" if !@ARGV;
222 ${$opt->{arg}} = $arg;
224 elsif (defined $arg) {
225 die "Option $optname takes no argument\n";
229 die "Conflicting operation modes\n" if $op_mode;
230 $op_mode = $opt->{mode};
240 $op_mode = $category ? "set-failed" : "set-building"
241 if !$op_mode; # default operation
242 $list_order = $list_state eq "failed" ? 'fPcpsn' : 'PScpsn'
243 if !$list_order and $list_state;
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 ($user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
310 push ( @files, "$user.yaml");
311 foreach my $file (@files) {
312 if ($verbose >= 2) { print "Trying to read $file ...\n"; }
313 next unless -f $yamldir."/".$file;
314 if ($verbose >= 2) { print "Read $file ...\n"; }
315 my $m = YAML::Tiny->read( $yamldir."/".$file )->[0];
316 $yamlmap = merge($m, $yamlmap);
319 die "FATAL: no configuration found\n";
327 $dbh->disconnect or warn $dbh->errstr;
331 my $schema_suffix = '';
332 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !(not -t and $user =~ /-/)) {
333 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
334 die "FATAL: Cannot open database: $DBI::errstr\n";
335 $schema_suffix = '_public';
339 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
340 die "FATAL: Cannot open database: $DBI::errstr\n";
343 # TODO: This shouldn't be needed, file a bug.
344 $dbh->{pg_server_prepare} = 0;
346 $dbh->begin_work or die $dbh->errstr;
353 if ($mail_logs && $conf::log_mail) {
354 send_mail( $conf::log_mail,
355 "wanna-build $distribution state changes $curr_date",
356 "State changes at $curr_date for distribution ".
357 "$distribution:\n\n$mail_logs\n" );
365 SWITCH: foreach ($op_mode) {
367 add_packages( $1, @ARGV );
371 list_packages( $list_state );
375 info_packages( @ARGV );
378 /^forget-user/ && do {
379 die "This operation is restricted to admin users\n"
380 if (defined @conf::admin_users and
381 !isin( $real_user, @conf::admin_users));
382 forget_users( @ARGV );
386 forget_packages( @ARGV );
389 /^merge-partial-quinn/ && do {
390 die "This operation is restricted to admin users\n"
391 if (defined @conf::admin_users and
392 !isin( $real_user, @conf::admin_users));
397 /^merge-quinn/ && do {
398 die "This operation is restricted to admin users\n"
399 if (defined @conf::admin_users and
400 !isin( $real_user, @conf::admin_users));
405 /^merge-packages/ && do {
406 die "This operation is restricted to admin users\n"
407 if (defined @conf::admin_users and
408 !isin( $real_user, @conf::admin_users));
413 /^merge-sources/ && do {
414 die "This operation is restricted to admin users\n"
415 if (defined @conf::admin_users and
416 !isin( $real_user, @conf::admin_users));
421 /^pretend-avail/ && do {
422 pretend_avail( @ARGV );
425 /^merge-all$/ && do {
426 die "This operation is restricted to admin users\n"
427 if (defined @conf::admin_users and
428 !isin( $real_user, @conf::admin_users));
431 @ARGV = ( $ARGS[0] );
432 my $pkgs = parse_packages(0);
433 @ARGV = ( $ARGS[1] );
435 @ARGV = ( $ARGS[2] );
436 my $srcs = parse_sources(1);
437 call_edos_depcheck( $ARGS[0], $srcs );
440 /^merge-all-secondary/ && do {
441 die "This operation is restricted to admin users\n"
442 if (defined @conf::admin_users and
443 !isin( $real_user, @conf::admin_users));
444 # This is in case the chroot has multiple unrelated
445 # dist, for instance unstable and experimental.
446 # This is not for stable and proposed-updates.
447 # The second packages file contains a combination
448 # of all Packages files known to the buildd, the
449 # first only for the current dist.
452 @ARGV = ( $ARGS[0] );
453 my $pkgs = parse_packages(0);
454 @ARGV = ( $ARGS[3] );
455 my $pkgs = parse_packages(1);
456 @ARGV = ( $ARGS[1] );
458 @ARGV = ( $ARGS[2] );
459 my $srcs = parse_sources(1);
460 call_edos_depcheck( $ARGS[3], $srcs );
464 die "This operation is restricted to admin users\n"
465 if (defined @conf::admin_users and
466 !isin( $real_user, @conf::admin_users));
467 $dbh->do("DELETE from " . table_name() .
468 " WHERE distribution = ?", undef,
472 read_db( $import_from );
476 export_db( $export_to );
480 die "Unexpected operation mode $op_mode\n";
482 if (not -t and $user =~ /-/) {
483 my $userinfo = get_user_info($user);
484 if (!defined $userinfo)
486 add_user_info($user);
490 update_user_info($user);
496 my $newstate = shift;
497 my( $package, $name, $version, $ok, $reason );
499 foreach $package (@_) {
500 $package =~ s,^.*/,,; # strip path
501 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
502 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
503 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
504 ($name,$version) = ($1,$2);
507 warn "$package: can't extract package name and version ".
512 if ($op_mode eq "set-building") {
513 add_one_building( $name, $version );
515 elsif ($op_mode eq "set-built") {
516 add_one_built( $name, $version );
518 elsif ($op_mode eq "set-attempted") {
519 add_one_attempted( $name, $version );
521 elsif ($op_mode eq "set-uploaded") {
522 add_one_uploaded( $name, $version );
524 elsif ($op_mode eq "set-failed") {
525 add_one_failed( $name, $version );
527 elsif ($op_mode eq "set-not-for-us") {
528 add_one_notforus( $name, $version );
530 elsif ($op_mode eq "set-needs-build") {
531 add_one_needsbuild( $name, $version );
533 elsif ($op_mode eq "set-dep-wait") {
534 add_one_depwait( $name, $version );
536 elsif ($op_mode eq "set-build-priority") {
537 set_one_buildpri( $name, $version, 'buildpri' );
539 elsif ($op_mode eq "set-permanent-build-priority") {
540 set_one_buildpri( $name, $version, 'permbuildpri' );
542 elsif ($op_mode eq "set-binary-nmu") {
543 set_one_binnmu( $name, $version );
548 sub add_one_building {
554 my $pkg = get_source_info($name);
556 if ($pkg->{'state'} eq "Not-For-Us") {
558 $reason = "not suitable for this architecture";
560 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
562 $reason = "not all source dependencies available yet";
564 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
566 $reason = "source dependencies are not installable";
568 elsif ($pkg->{'state'} eq "Uploaded" &&
569 (version_lesseq($version, $pkg->{'version'}))) {
571 $reason = "already uploaded by $pkg->{'builder'}";
572 $reason .= " (in newer version $pkg->{'version'})"
573 if !version_eq($pkg, $version);
575 elsif ($pkg->{'state'} eq "Installed" &&
576 version_less($version,$pkg->{'version'})) {
578 print "$name: Warning: newer version $pkg->{'version'} ".
579 "already installed, but overridden.\n";
583 $reason = "newer version $pkg->{'version'} already in ".
584 "archive; doesn't need rebuilding";
585 print "$name: Note: If the following is due to an epoch ",
586 " change, use --override\n";
589 elsif ($pkg->{'state'} eq "Installed" &&
590 pkg_version_eq($pkg,$version)) {
592 $reason = "is up-to-date in the archive; doesn't need rebuilding";
594 elsif ($pkg->{'state'} eq "Needs-Build" &&
595 version_less($version,$pkg->{'version'})) {
597 print "$name: Warning: newer version $pkg->{'version'} ".
598 "needs building, but overridden.";
602 $reason = "newer version $pkg->{'version'} needs building, ".
606 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
607 if (version_less($pkg->{'version'},$version)) {
608 print "$name: Warning: Older version $pkg->{'version'} ",
609 "is being built by $pkg->{'builder'}\n";
610 if ($pkg->{'builder'} ne $user) {
611 send_mail( $pkg->{'builder'},
612 "package takeover in newer version",
613 "You are building package '$name' in ".
614 "version $version\n".
615 "(as far as I'm informed).\n".
616 "$user now has taken the newer ".
617 "version $version for building.".
618 "You can abort the build if you like.\n" );
623 print "User $pkg->{'builder'} had already ",
624 "taken the following package,\n",
625 "but overriding this as you request:\n";
626 send_mail( $pkg->{'builder'}, "package takeover",
627 "The package '$name' (version $version) that ".
628 "was taken by you\n".
629 "has been taken over by $user\n" );
631 elsif ($pkg->{'builder'} eq $user) {
632 print "$name: Note: already taken by you.\n";
633 print "$name: ok\n" if $verbose;
638 $reason = "already taken by $pkg->{'builder'}";
639 $reason .= " (in newer version $pkg->{'version'})"
640 if !version_eq($pkg->{'version'}, $version);
644 elsif ($pkg->{'state'} =~ /^Failed/ &&
645 pkg_version_eq($pkg, $version)) {
647 print "The following package previously failed ",
648 "(by $pkg->{'builder'})\n",
649 "but overriding this as you request:\n";
650 send_mail( $pkg->{'builder'}, "failed package takeover",
651 "The package '$name' (version $version) that ".
653 "and has failed previously has been taken over ".
655 if $pkg->{'builder'} ne $user;
659 $reason = "build of $version failed previously:\n ";
660 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
661 $reason .= "\nalso the package doesn't need builing"
662 if $pkg->{'state'} eq 'Failed-Removed';
668 if ($pkg->{'binary_nmu_version'}) {
669 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
670 "$pkg->{'binary_nmu_changelog'}\n";
673 print "$name: Warning: Previous version failed!\n"
674 if $pkg->{'previous_state'} =~ /^Failed/ ||
675 $pkg->{'state'} =~ /^Failed/;
677 change_state( \$pkg, 'Building' );
678 $pkg->{'package'} = $name;
679 $pkg->{'version'} = $version;
680 $pkg->{'builder'} = $user;
681 log_ta( $pkg, "--take" );
682 update_source_info($pkg);
683 print "$name: $ok\n" if $verbose;
686 print "$name: NOT OK!\n $reason\n";
690 sub add_one_attempted {
693 my $pkg = get_source_info($name);
695 if (!defined($pkg)) {
696 print "$name: not registered yet.\n";
700 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
701 print "$name: not taken for building (state is $pkg->{'state'}). ",
705 if ($pkg->{'builder'} ne $user) {
706 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
709 elsif ( !pkg_version_eq($pkg, $version) ) {
710 print "$name: version mismatch ".
711 "$(pkg->{'version'} ".
712 "by $pkg->{'builder'})\n";
716 change_state( \$pkg, 'Build-Attempted' );
717 log_ta( $pkg, "--attempted" );
718 update_source_info($pkg);
719 print "$name: registered as uploaded\n" if $verbose;
725 my $pkg = get_source_info($name);
727 if (!defined($pkg)) {
728 print "$name: not registered yet.\n";
732 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
733 print "$name: not taken for building (state is $pkg->{'state'}). ",
737 if ($pkg->{'builder'} ne $user) {
738 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
741 elsif ( !pkg_version_eq($pkg, $version) ) {
742 print "$name: version mismatch ".
743 "$(pkg->{'version'} ".
744 "by $pkg->{'builder'})\n";
747 change_state( \$pkg, 'Built' );
748 log_ta( $pkg, "--built" );
749 update_source_info($pkg);
750 print "$name: registered as built\n" if $verbose;
753 sub add_one_uploaded {
756 my $pkg = get_source_info($name);
758 if (!defined($pkg)) {
759 print "$name: not registered yet.\n";
763 if ($pkg->{'state'} eq "Uploaded" &&
764 pkg_version_eq($pkg,$version)) {
765 print "$name: already uploaded\n";
768 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
769 print "$name: not taken for building (state is $pkg->{'state'}). ",
773 if ($pkg->{'builder'} ne $user) {
774 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
777 # strip epoch -- buildd-uploader used to go based on the filename.
778 # (to remove at some point)
780 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
781 $version =~ s/^\d+://; # for command line use
782 if ($pkg->{'binary_nmu_version'} ) {
783 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
784 if (!version_eq( $nmuver, $version )) {
785 print "$name: version mismatch ($nmuver registered). ",
789 } elsif (!version_eq($pkgver, $version)) {
790 print "$name: version mismatch ($pkg->{'version'} registered). ",
795 change_state( \$pkg, 'Uploaded' );
796 log_ta( $pkg, "--uploaded" );
797 update_source_info($pkg);
798 print "$name: registered as uploaded\n" if $verbose;
805 my $pkg = get_source_info($name);
807 if (!defined($pkg)) {
808 print "$name: not registered yet.\n";
811 $state = $pkg->{'state'};
813 if ($state eq "Not-For-Us") {
814 print "$name: not suitable for this architecture anyway. Skipping.\n";
817 elsif ($state eq "Failed-Removed") {
818 print "$name: failed previously and doesn't need building. Skipping.\n";
821 elsif ($state eq "Installed") {
822 print "$name: Is already installed in archive. Skipping.\n";
825 elsif ($pkg->{'builder'} &&
826 (($user ne $pkg->{'builder'}) &&
827 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
828 print "$name: not taken by you, but by ".
829 "$pkg->{'builder'}. Skipping.\n";
832 elsif ( !pkg_version_eq($pkg, $version) ) {
833 print "$name: version mismatch ".
834 "$(pkg->{'version'} ".
835 "by $pkg->{'builder'})\n";
840 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
842 $cat = $short_category{$cat} if exists $short_category{$cat};
843 if (!isin( $cat, values %short_category )) {
844 print "$name: Warning: unknown category $cat; discarded\n";
847 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
850 if ($state eq "Needs-Build") {
851 print "$name: Warning: not registered for building previously, ".
852 "but processing anyway.\n";
854 elsif ($state eq "Uploaded") {
855 print "$name: Warning: marked as uploaded previously, ".
856 "but processing anyway.\n";
858 elsif ($state eq "Dep-Wait") {
859 print "$name: Warning: marked as waiting for dependencies, ".
860 "but processing anyway.\n";
862 elsif ($state eq "BD-Uninstallable") {
863 print "$name: Warning: marked as having uninstallable build-dependencies, ".
864 "but processing anyway.\n";
866 elsif ($state eq "Failed") {
867 print "$name: already registered as failed; will append new message\n"
869 print "$name: already registered as failed; changing category\n"
873 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
874 defined $pkg->{'failed_category'} &&
875 $pkg->{'failed_category'} ne $cat) {
876 (my $action = $cat) =~ s/-/ /;
877 $fail_reason .= "\n$short_date: $action";
880 change_state( \$pkg, 'Failed' );
881 $pkg->{'builder'} = $user;
882 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
883 $pkg->{'failed'} .= $fail_reason;
884 $pkg->{'failed_category'} = $cat if $cat;
885 if (defined $pkg->{'permbuildpri'}) {
886 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
888 delete $pkg->{'buildpri'};
890 log_ta( $pkg, "--failed" );
891 update_source_info($pkg);
892 print "$name: registered as failed\n" if $verbose;
895 sub add_one_notforus {
898 my $pkg = get_source_info($name);
900 if ($pkg->{'state'} eq 'Not-For-Us') {
901 # reset Not-For-Us state in case it's called twice; this is
902 # the only way to get a package out of this state...
903 # There is no really good state in which such packages should
904 # be put :-( So use Failed for now.
905 change_state( \$pkg, 'Failed' );
906 $pkg->{'package'} = $name;
907 $pkg->{'failed'} = "Was Not-For-Us previously";
908 delete $pkg->{'builder'};
909 delete $pkg->{'depends'};
910 log_ta( $pkg, "--no-build(rev)" );
911 print "$name: now not unsuitable anymore\n";
913 send_mail( $conf::notforus_maint,
914 "$name moved out of Not-For-Us state",
915 "The package '$name' has been moved out of the Not-For-Us ".
917 "It should probably also be removed from ".
918 "Packages-arch-specific or\n".
919 "the action was wrong.\n" )
920 if $conf::notforus_maint;
923 change_state( \$pkg, 'Not-For-Us' );
924 $pkg->{'package'} = $name;
925 delete $pkg->{'builder'};
926 delete $pkg->{'depends'};
927 delete $pkg->{'buildpri'};
928 delete $pkg->{'binary_nmu_version'};
929 delete $pkg->{'binary_nmu_changelog'};
930 log_ta( $pkg, "--no-build" );
931 print "$name: registered as unsuitable\n" if $verbose;
933 send_mail( $conf::notforus_maint,
934 "$name set to Not-For-Us",
935 "The package '$name' has been set to state Not-For-Us ".
937 "It should probably also be added to ".
938 "Packages-arch-specific or\n".
939 "the Not-For-Us state is wrong.\n" )
940 if $conf::notforus_maint;
942 update_source_info($pkg);
945 sub add_one_needsbuild {
949 my $pkg = get_source_info($name);
951 if (!defined($pkg)) {
952 print "$name: not registered; can't give back.\n";
955 $state = $pkg->{'state'};
957 if ($state eq "BD-Uninstallable") {
959 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
961 change_state( \$pkg, 'Needs-Build' );
962 delete $pkg->{'builder'};
963 delete $pkg->{'depends'};
964 log_ta( $pkg, "--give-back" );
965 update_source_info($pkg);
966 print "$name: given back\n" if $verbose;
970 print "$name: has uninstallable build-dependencies. Skipping\n",
971 " (use --override to clear dependency list and ",
972 "give back anyway)\n";
976 elsif ($state eq "Dep-Wait") {
978 print "$name: Forcing source dependency list to be cleared\n";
981 print "$name: waiting for source dependencies. Skipping\n",
982 " (use --override to clear dependency list and ",
983 "give back anyway)\n";
987 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
988 print "$name: not taken for building (state is $state).";
990 print "\n$name: Forcing give-back\n";
993 print " Skipping.\n";
997 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
998 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
1000 print "$name: not taken by you, but by ".
1001 "$pkg->{'builder'}. Skipping.\n";
1004 if (!pkg_version_eq($pkg, $version)) {
1005 print "$name: version mismatch ($pkg->{'version'} registered). ",
1009 if ($distribution eq "unstable") {
1010 change_state( \$pkg, 'BD-Uninstallable' );
1011 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1013 change_state( \$pkg, 'Needs-Build' );
1015 $pkg->{'builder'} = undef;
1016 $pkg->{'depends'} = undef;
1017 log_ta( $pkg, "--give-back" );
1018 update_source_info($pkg);
1019 print "$name: given back\n" if $verbose;
1022 sub set_one_binnmu {
1024 my $version = shift;
1025 my $pkg = get_source_info($name);
1028 if (!defined($pkg)) {
1029 print "$name: not registered; can't register for binNMU.\n";
1032 my $db_ver = $pkg->{'version'};
1034 if (!version_eq($db_ver, $version)) {
1035 print "$name: version mismatch ($db_ver registered). ",
1039 $state = $pkg->{'state'};
1041 if (defined $pkg->{'binary_nmu_version'}) {
1042 if ($binNMUver == 0) {
1043 change_state( \$pkg, 'Installed' );
1044 delete $pkg->{'builder'};
1045 delete $pkg->{'depends'};
1046 delete $pkg->{'binary_nmu_version'};
1047 delete $pkg->{'binary_nmu_changelog'};
1048 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1049 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1052 $pkg->{'binary_nmu_version'} = $binNMUver;
1053 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1054 $pkg->{'notes'} = 'out-of-date';
1055 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1056 if (defined $pkg->{'permbuildpri'});
1058 log_ta( $pkg, "--binNMU" );
1059 update_source_info($pkg);
1061 } elsif ($binNMUver == 0) {
1062 print "${name}_$version: no scheduled binNMU to cancel.\n";
1066 if ($state ne 'Installed') {
1067 print "${name}_$version: not installed; can't register for binNMU.\n";
1071 my $fullver = binNMU_version($version,$binNMUver);
1072 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1074 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1078 if ($distribution eq "unstable") {
1079 change_state( \$pkg, 'BD-Uninstallable' );
1080 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1084 change_state( \$pkg, 'Needs-Build' );
1086 delete $pkg->{'builder'};
1087 delete $pkg->{'depends'};
1088 $pkg->{'binary_nmu_version'} = $binNMUver;
1089 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1090 $pkg->{'notes'} = 'out-of-date';
1091 log_ta( $pkg, "--binNMU" );
1092 update_source_info($pkg);
1093 print "${name}: registered for binNMU $fullver\n" if $verbose;
1096 sub set_one_buildpri {
1098 my $version = shift;
1100 my $pkg = get_source_info($name);
1103 if (!defined($pkg)) {
1104 print "$name: not registered; can't set priority.\n";
1107 $state = $pkg->{'state'};
1109 if ($state eq "Not-For-Us") {
1110 print "$name: not suitable for this architecture. Skipping.\n";
1112 } elsif ($state eq "Failed-Removed") {
1113 print "$name: failed previously and doesn't need building. Skipping.\n";
1116 if (!pkg_version_eq($pkg, $version)) {
1117 print "$name: version mismatch ($pkg->{'version'} registered). ",
1121 if ( $build_priority == 0 ) {
1122 delete $pkg->{'buildpri'}
1123 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1124 and $pkg->{'buildpri'} == $pkg->{$key};
1125 delete $pkg->{$key};
1127 $pkg->{'buildpri'} = $build_priority
1128 if $key eq 'permbuildpri';
1129 $pkg->{$key} = $build_priority;
1131 update_source_info($pkg);
1132 print "$name: set to build priority $build_priority\n" if $verbose;
1135 sub add_one_depwait {
1137 my $version = shift;
1139 my $pkg = get_source_info($name);
1141 if (!defined($pkg)) {
1142 print "$name: not registered yet.\n";
1145 $state = $pkg->{'state'};
1147 if ($state eq "Dep-Wait") {
1148 print "$name: merging with previously registered dependencies\n";
1151 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1152 print "$name: Warning: not registered for building previously, ".
1153 "but processing anyway.\n";
1155 elsif ($state eq "Not-For-Us") {
1156 print "$name: not suitable for this architecture anyway. Skipping.\n";
1159 elsif ($state eq "Failed-Removed") {
1160 print "$name: failed previously and doesn't need building. Skipping.\n";
1163 elsif ($state eq "Installed") {
1164 print "$name: Is already installed in archive. Skipping.\n";
1167 elsif ($state eq "Uploaded") {
1168 print "$name: Is already uploaded. Skipping.\n";
1171 elsif ($pkg->{'builder'} &&
1172 $user ne $pkg->{'builder'}) {
1173 print "$name: not taken by you, but by ".
1174 "$pkg->{'builder'}. Skipping.\n";
1177 elsif ( !pkg_version_eq($pkg,$version)) {
1178 print "$name: version mismatch ".
1179 "($pkg->{'version'} ".
1180 "by $pkg->{'builder'})\n";
1183 elsif ($fail_reason =~ /^\s*$/ ||
1184 !parse_deplist( $fail_reason, 1 )) {
1185 print "$name: Bad dependency list\n";
1188 change_state( \$pkg, 'Dep-Wait' );
1189 $pkg->{'builder'} = $user;
1190 if (defined $pkg->{'permbuildpri'}) {
1191 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1193 delete $pkg->{'buildpri'};
1195 my $deplist = parse_deplist( $pkg->{'depends'} );
1196 my $new_deplist = parse_deplist( $fail_reason );
1197 # add new dependencies, maybe overwriting old entries
1198 foreach (keys %$new_deplist) {
1199 $deplist->{$_} = $new_deplist->{$_};
1201 $pkg->{'depends'} = build_deplist($deplist);
1202 log_ta( $pkg, "--dep-wait" );
1203 update_source_info($pkg);
1204 print "$name: registered as waiting for dependencies\n" if $verbose;
1214 my $db = get_all_source_info();
1216 local($/) = ""; # read in paragraph mode
1218 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1220 /^Package:\s*(\S+)$/mi and $name = $1;
1221 /^Version:\s*(\S+)$/mi and $version = $1;
1222 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1223 /^Section:\s*(\S+)$/mi and $section = $1;
1224 /^Priority:\s*(\S+)$/mi and $priority = $1;
1225 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1226 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1227 /^Binary:\s*(.*)$/mi and $binaries = $1;
1229 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1230 $srcver{$name} = $version;
1232 $pkgs{$name}{'ver'} = $version;
1233 $pkgs{$name}{'bin'} = $binaries;
1234 $pkgs{$name}{'dep'} = $builddep;
1235 $pkgs{$name}{'conf'} = $buildconf;
1236 my $pkg = $db->{$name};
1241 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1242 # package is now Arch: all, delete it from db
1243 change_state( \$pkg, 'deleted' );
1244 log_ta( $pkg, "--merge-sources" );
1245 print "$name ($pkg->{'version'}): deleted ".
1246 "from database, because now Arch: all\n"
1248 del_source_info($name);
1249 delete $db->{$name};
1253 # The "Version" should always be the source version --
1254 # not a possible binNMU version number.
1255 $pkg->{'version'} = $version, $change++
1256 if ($pkg->{'state'} eq 'Installed' and
1257 !version_eq( $pkg->{'version'}, $version));
1258 # Always update priority and section, if available
1259 $pkg->{'priority'} = $priority, $change++
1260 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1262 $pkg->{'section'} = $section, $change++
1263 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1265 update_source_info($pkg) if $change;
1268 # Now that we only have the latest source version, build the list
1269 # of binary packages from the Sources point of view
1270 foreach $name (keys %pkgs) {
1271 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1272 $merge_binsrc{$bin} = $name;
1275 # remove installed packages that no longer have source available
1276 # or binaries installed
1277 foreach $name (keys %$db) {
1278 next if $name =~ /^_/;
1279 my $pkg = $db->{$name};
1280 if (not defined($pkgs{$name})) {
1281 change_state( \$pkg, 'deleted' );
1282 log_ta( $pkg, "--merge-sources" );
1283 print "$name ($pkg->{'version'}): ".
1284 "deleted from database, because ".
1285 "not in Sources anymore\n"
1287 del_source_info($name);
1288 delete $db->{$name};
1290 next if !isin( $pkg->{'state'}, qw(Installed) );
1291 if ($full && not defined $merge_srcvers{$name}) {
1292 change_state( \$pkg, 'deleted' );
1293 log_ta( $pkg, "--merge-sources" );
1294 print "$name ($pkg->{'version'}): ".
1295 "deleted from database, because ".
1296 "binaries don't exist anymore\n"
1298 del_source_info($name);
1299 delete $db->{$name};
1300 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1301 print "$name ($pkg->{'version'}): ".
1302 "package is Installed but binaries are from ".
1303 $merge_srcvers{$name}. "\n"
1311 # This function looks through a Packages file and sets the state of
1312 # packages to 'Installed'
1313 sub parse_packages {
1314 my $depwait_only = shift;
1317 my $pkgs = get_all_source_info();
1318 local($/) = ""; # read in paragraph mode
1320 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1322 /^Package:\s*(\S+)$/mi and $name = $1;
1323 /^Version:\s*(\S+)$/mi and $version = $1;
1324 /^Depends:\s*(.*)$/mi and $depends = $1;
1325 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1326 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1327 /^Provides:\s*(.*)$/mi and $provides = $1;
1328 next if !$name || !$version;
1329 next if ($arch ne $architecture and $architecture ne "all");
1330 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1331 version_lesseq( $version, $installed->{$name}{'version'} ));
1332 $installed->{$name}{'version'} = $version;
1333 next if $depwait_only;
1334 $installed->{$name}{'depends'} = $depends;
1335 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1336 undef $installed->{$name}{'Provider'};
1337 $installed->{$name}{'Source'} = $source ? $source : $name;
1339 foreach (split( /\s*,\s*/, $provides )) {
1340 if (not defined ($installed->{$_})) {
1341 $installed->{$_}{'version'} = "";
1342 $installed->{$_}{'Provider'} = $name;
1346 if ( $version =~ /\+b(\d+)$/ ) {
1349 $version = $sourcev if $sourcev;
1350 $binaryv = $version;
1351 $binaryv =~ s/\+b\d+$//;
1352 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1353 $binaryv .= "+b$binnmu" if defined($binnmu);
1355 next if $architecture ne $arch;
1356 $name = $source if $source;
1357 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1358 $merge_srcvers{$name} = $version;
1360 my $pkg = $pkgs->{$name};
1363 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1364 (isin($pkg->{'state'}, qw(Installed)) &&
1365 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1366 print "Skipping $name because State == $pkg->{'state'}\n"
1370 if ($pkg->{'binary_nmu_version'} ) {
1371 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1372 if (version_less( $binaryv, $nmuver )) {
1373 print "Skipping $name ($version) because have newer ".
1374 "version ($nmuver) in db.\n"
1378 } elsif (version_less($version, $pkg->{'version'})) {
1379 print "Skipping $name ($version) because have newer ".
1380 "version ($pkg->{'version'}) in db.\n"
1385 if (!pkg_version_eq($pkg, $version) &&
1386 $pkg->{'state'} ne "Installed") {
1387 warn "Warning: $name: newer version than expected appeared ".
1388 "in archive ($version vs. $pkg->{'version'})\n";
1389 delete $pkg->{'builder'};
1392 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1393 warn "Warning: Package $name was not in uploaded state ".
1394 "before (but in '$pkg->{'state'}').\n";
1395 delete $pkg->{'builder'};
1396 delete $pkg->{'depends'};
1400 $pkg->{'version'} = $version;
1403 change_state( \$pkg, 'Installed' );
1404 $pkg->{'package'} = $name;
1405 $pkg->{'installed_version'} = $binaryv;
1406 if (defined $pkg->{'permbuildpri'}) {
1407 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1409 delete $pkg->{'buildpri'};
1411 $pkg->{'version'} = $version
1412 if version_less( $pkg->{'version'}, $version);
1413 delete $pkg->{'binary_nmu_version'};
1414 delete $pkg->{'binary_nmu_changelog'};
1415 log_ta( $pkg, "--merge-packages" );
1416 update_source_info($pkg);
1417 print "$name ($version) is up-to-date now.\n" if $verbose;
1420 check_dep_wait( "--merge-packages", $installed );
1425 my ($package, $name, $version, $installed);
1427 foreach $package (@_) {
1428 $package =~ s,^.*/,,; # strip path
1429 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1430 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1431 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1432 ($name,$version) = ($1,$2);
1435 warn "$package: can't extract package name and version ".
1439 $installed->{$name}{'version'} = $version;
1442 check_dep_wait( "--pretend-avail", $installed );
1445 sub check_dep_wait {
1447 my $installed = shift;
1449 # check all packages in state Dep-Wait if dependencies are all
1452 my $db = get_all_source_info();
1453 foreach $name (keys %$db) {
1454 next if $name =~ /^_/;
1455 my $pkg = $db->{$name};
1456 next if $pkg->{'state'} ne "Dep-Wait";
1457 my $deps = $pkg->{'depends'};
1459 print "$name: was in state Dep-Wait, but with empty ",
1461 goto make_needs_build;
1463 my $deplist = parse_deplist($deps);
1467 foreach (keys %$deplist) {
1468 if (!exists $installed->{$_} ||
1469 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1470 !version_compare( $installed->{$_}{'version'},
1471 $deplist->{$_}->{'rel'},
1472 $deplist->{$_}->{'version'}))) {
1474 $new_deplist->{$_} = $deplist->{$_};
1477 push( @removed_deps, $_ );
1482 change_state( \$pkg, 'Needs-Build' );
1483 log_ta( $pkg, $action );
1484 delete $pkg->{'builder'};
1485 delete $pkg->{'depends'};
1486 print "$name ($pkg->{'version'}) has all ",
1487 "dependencies available now\n" if $verbose;
1489 update_source_info($pkg);
1491 elsif (@removed_deps) {
1492 $pkg->{'depends'} = build_deplist( $new_deplist );
1493 print "$name ($pkg->{'version'}): some dependencies ",
1494 "(@removed_deps) available now, but not all yet\n"
1496 update_source_info($pkg);
1501 # This function accepts quinn-diff output (either from a file named on
1502 # the command line, or on stdin) and sets the packages named there to
1503 # state 'Needs-Build'.
1504 sub parse_quinn_diff {
1505 my $partial = shift;
1509 my $pkgs = get_all_source_info();
1513 next if !m,^([-\w\d/]*)/ # section
1514 ([-\w\d.+]+)_ # package name
1515 ([\w\d:.~+-]+)\.dsc\s* # version
1516 \[([^:]*): # priority
1517 ([^]]+)\]\s*$,x; # rest of notes
1518 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1519 $quinn_pkgs{$name}++;
1520 $section ||= "unknown";
1521 $priority ||= "unknown";
1522 $priority = "unknown" if $priority eq "-";
1523 $priority = "standard" if ($name eq "debian-installer");
1525 my $pkg = $pkgs->{$name};
1527 # Always update section and priority.
1528 if (defined($pkg)) {
1530 $pkg->{'section'} = $section, $change++ if not defined
1531 $pkg->{'section'} or $section ne "unknown";
1532 $pkg->{'priority'} = $priority, $change++ if not defined
1533 $pkg->{'priority'} or $priority ne "unknown";
1536 if (defined($pkg) &&
1537 $pkg->{'state'} =~ /^Dep-Wait/ &&
1538 version_less( $pkg->{'version'}, $version )) {
1539 change_state( \$pkg, 'Dep-Wait' );
1540 $pkg->{'version'} = $version;
1541 delete $pkg->{'binary_nmu_version'};
1542 delete $pkg->{'binary_nmu_changelog'};
1543 log_ta( $pkg, "--merge-quinn" );
1545 print "$name ($version) still waiting for dependencies.\n"
1548 elsif (defined($pkg) &&
1549 $pkg->{'state'} =~ /-Removed$/ &&
1550 version_eq($pkg->{'version'}, $version)) {
1551 # reinstantiate a package that has been removed earlier
1552 # (probably due to a quinn-diff malfunction...)
1553 my $newstate = $pkg->{'state'};
1554 $newstate =~ s/-Removed$//;
1555 change_state( \$pkg, $newstate );
1556 $pkg->{'version'} = $version;
1557 $pkg->{'notes'} = $notes;
1558 log_ta( $pkg, "--merge-quinn" );
1560 print "$name ($version) reinstantiated to $newstate.\n"
1563 elsif (defined($pkg) &&
1564 $pkg->{'state'} eq "Not-For-Us" &&
1565 version_less( $pkg->{'version'}, $version )) {
1566 # for Not-For-Us packages just update the version etc., but
1568 change_state( \$pkg, "Not-For-Us" );
1569 $pkg->{'package'} = $name;
1570 $pkg->{'version'} = $version;
1571 $pkg->{'notes'} = $notes;
1572 delete $pkg->{'builder'};
1573 log_ta( $pkg, "--merge-quinn" );
1575 print "$name ($version) still Not-For-Us.\n" if $verbose;
1577 elsif (!defined($pkg) ||
1578 $pkg->{'state'} ne "Not-For-Us" &&
1579 (version_less( $pkg->{'version'}, $version ) ||
1580 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1582 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1583 send_mail( $pkg->{'builder'},
1584 "new version of $name (dist=$distribution)",
1585 "As far as I'm informed, you're currently ".
1586 "building the package $name\n".
1587 "in version $pkg->{'version'}.\n\n".
1588 "Now there's a new source version $version. ".
1589 "If you haven't finished\n".
1590 "compiling $name yet, you can stop it to ".
1591 "save some work.\n".
1592 "Just to inform you...\n".
1593 "(This is an automated message)\n" );
1594 print "$name: new version ($version) while building ".
1595 "$pkg->{'version'} -- sending mail ".
1596 "to builder ($pkg->{'builder'})\n"
1599 change_state( \$pkg, 'Needs-Build' );
1600 $pkg->{'package'} = $name;
1601 $pkg->{'version'} = $version;
1602 $pkg->{'section'} = $section;
1603 $pkg->{'priority'} = $priority;
1604 $pkg->{'notes'} = $notes;
1605 delete $pkg->{'builder'};
1606 delete $pkg->{'binary_nmu_version'};
1607 delete $pkg->{'binary_nmu_changelog'};
1608 log_ta( $pkg, "--merge-quinn" );
1611 print "$name ($version) needs rebuilding now.\n" if $verbose;
1613 elsif (defined($pkg) &&
1614 !version_eq( $pkg->{'version'}, $version ) &&
1615 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1616 print "$name: skipping because version in db ".
1617 "($pkg->{'version'}) is >> than ".
1618 "what quinn-diff says ($version) ".
1619 "(state is $pkg->{'state'})\n"
1621 $dubious .= "$pkg->{'state'}: ".
1622 "db ${name}_$pkg->{'version'} >> ".
1623 "quinn $version\n" if !$partial;
1625 elsif ($verbose >= 2) {
1626 if ($pkg->{'state'} eq "Not-For-Us") {
1627 print "Skipping $name because State == ".
1628 "$pkg->{'state'}\n";
1630 elsif (!version_less($pkg->{'version'}, $version)) {
1631 print "Skipping $name because version in db ".
1632 "($pkg->{'version'}) is >= than ".
1633 "what quinn-diff says ($version)\n";
1636 update_source_info($pkg) if $change;
1640 send_mail( $conf::db_maint,
1641 "Dubious versions in " . table_name() . " "
1642 . $distribution . " table",
1643 "The following packages have a newer version in the ".
1644 "wanna-build database\n".
1645 "than what quinn-diff says, and this is strange for ".
1647 "It could be caused by a lame mirror, or the version ".
1648 "in the database\n".
1653 # Now re-check the DB for packages in states Needs-Build, Failed,
1654 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1655 # anymore by quinn-diff.
1658 my $db = get_all_source_info();
1659 foreach $name (keys %$db) {
1660 next if $name =~ /^_/;
1661 my $pkg = $db->{$name};
1662 next if defined $pkg->{'binary_nmu_version'};
1663 next if !isin( $pkg->{'state'},
1664 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1665 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1667 if (!$quinn_pkgs{$name}) {
1668 change_state( \$pkg, $virtual_delete ?
1669 $pkg->{'state'}."-Removed" :
1671 log_ta( $pkg, "--merge-quinn" );
1672 print "$name ($pkg->{'version'}): ".
1673 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1674 "from database, because not in quinn-diff anymore\n"
1676 if ($virtual_delete) {
1677 update_source_info($pkg);
1679 del_source_info($name);
1687 # for sorting priorities and sections
1689 %prioval = ( required => -5,
1697 'debian-installer' => -199,
1718 localizations => -178,
1719 interpreters => -177,
1744 electronics => -152,
1750 foreach my $i (keys %sectval) {
1751 $sectval{"contrib/$i"} = $sectval{$i}+40;
1752 $sectval{"non-free/$i"} = $sectval{$i}+80;
1754 $sectval{'unknown'} = -165;
1756 %catval = ( "none" => -20,
1757 "uploaded-fixed-pkg" => -19,
1758 "fix-expected" => -18,
1759 "reminder-sent" => -17,
1760 "nmu-offered" => -16,
1764 "compiler-error" => -12 );
1767 sub sort_list_func {
1768 my( $letter, $x, $ax, $bx );
1770 foreach $letter (split( "", $list_order )) {
1771 SWITCH: foreach ($letter) {
1773 $x = $b->{'calprio'} <=> $a->{'calprio'};
1774 return $x if $x != 0;
1778 $x = $b->{'state_days'} <=> $a->{'state_days'};
1779 return $x if $x != 0;
1783 $x = $b->{'buildpri'} <=> $a->{'buildpri'};
1784 return $x if $x != 0;
1788 $x = $prioval{$a->{'priority'}} <=> $prioval{$b->{'priority'}};
1789 return $x if $x != 0;
1793 $x = $sectval{$a->{'section'}} <=> $sectval{$b->{'section'}};
1794 return $x if $x != 0;
1798 $x = $a->{'package'} cmp $b->{'package'};
1799 return $x if $x != 0;
1803 $x = $a->{'builder'} cmp $b->{'builder'};
1804 return $x if $x != 0;
1808 $ax = ($a->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1809 ($a->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1810 $bx = ($b->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1811 ($b->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1813 return $x if $x != 0;
1817 my $ca = defined $a->{'failed_category'} ?
1818 $a->{'failed_category'} : "none";
1819 my $cb = defined $b->{'failed_category'} ?
1820 $b->{'failed_category'} : "none";
1821 $x = $catval{$ca} <=> $catval{$cb};
1822 return $x if $x != 0;
1826 my $pa = $prioval{$a->{'priority'}} >
1827 $prioval{'standard'};
1828 my $pb = $prioval{$b->{'priority'}} >
1829 $prioval{'standard'};
1831 return $x if $x != 0;
1839 sub calculate_prio {
1840 my $priomap = $yamlmap->{priority};
1842 $pkg->{'calprio'} = 0;
1843 foreach my $k (keys %{$priomap->{keys}}) {
1844 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1847 my $days = $pkg->{'state_days'};
1848 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1849 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1850 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1851 $pkg->{'calprio'} += $days * $scale;
1853 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1854 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1863 if (ref($_[0]) eq 'CODE') {
1873 return $r unless $t;
1877 if (substr($t,0,1) eq '!') {
1881 return "" unless $r;
1884 return print_format($t, $pkg, $var);
1888 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
1891 my $printfmt = shift;
1895 Within an format string, the following values are allowed (need to be preceded by %).
1896 This can be combined to e.g.
1897 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
1901 s Time in this state in full seconds since epoch
1904 u Builder (e.g. buildd_mipsel-rem)
1905 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
1906 c section (e.g. libs or utils)
1908 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
1909 D in case of BD-Uninstallable the reason for the uninstallability
1911 t time of state change
1913 %{Text}? print Text in case ? is not empty; ? is never printed
1914 %{!Text}? print Text in case ? is empty; ? is never printed
1915 Text could contain further %. To start with !, use %!
1918 return stringf($printfmt, (
1919 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
1920 'a' => make_fmt( $arch, $pkg, $var),
1921 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
1922 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
1923 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
1924 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
1925 'X' => make_fmt( sub {
1926 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
1927 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} =~ /^Failed/;
1928 $c .= ":bp{" . $pkg->{'buildpri'} . "}" if defined $pkg->{'buildpri'};
1929 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
1930 $c .= ":calprio{". $pkg->{'calprio'}."}";
1931 $c .= ":days{". $pkg->{'state_days'}."}";
1934 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
1935 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
1936 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
1937 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
1938 return ""; }, $pkg, $var),
1939 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
1940 return $pkg->{'package'}."#".$arch."-bd-problem\n".
1941 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
1942 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
1943 'd' => make_fmt( $distribution, $pkg, $var),
1944 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
1950 my( $name, $pkg, @list );
1955 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
1956 foreach $name (keys %$db) {
1957 next if $name =~ /^_/;
1958 push @list, calculate_prio($db->{$name});
1961 foreach $pkg (sort sort_list_func @list) {
1963 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
1965 $scnt{$pkg->{'state'}}++;
1968 print "$pkg->{'section'}/$pkg->{'package'}_$pkg->{'version'}";
1969 print ": $pkg->{'state'}"
1971 print " by $pkg->{'builder'}"
1972 if $pkg->{'state'} ne "Needs-Build" && $pkg->{'builder'};
1973 print " [$pkg->{'priority'}:$pkg->{'notes'}";
1974 print ":PREV-FAILED"
1975 if $pkg->{'previous_state'} =~ /^Failed/;
1976 print ":bp{" . $pkg->{'buildpri'} . "}"
1977 if defined $pkg->{'buildpri'};
1978 print ":binNMU{" . $pkg->{'binary_nmu_version'} . "}"
1979 if defined $pkg->{'binary_nmu_version'};
1980 print ":calprio{". $pkg->{'calprio'}."}";
1981 print ":days{". $pkg->{'state_days'}."}";
1983 print " Reasons for failing:\n",
1985 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
1987 join("\n ",split("\n",$pkg->{'failed'})), "\n"
1988 if $pkg->{'state'} =~ /^Failed/;
1989 print " Dependencies: $pkg->{'depends'}\n"
1990 if $pkg->{'state'} eq "Dep-Wait";
1991 print " Reasons for BD-Uninstallable:\n ",
1992 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
1993 if $pkg->{'state'} eq "BD-Uninstallable";
1994 print " Previous state was $pkg->{'previous_state'}\n"
1995 if $verbose && $pkg->{'previous_state'};
1996 print " No previous state recorded\n"
1997 if $verbose && !$pkg->{'previous_state'};
1998 print " State changed at $pkg->{'state_change'}\n"
1999 if $verbose && $pkg->{'state_change'};
2000 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
2001 if $verbose && $pkg->{'previous_state'};
2002 print " Previous failing reasons:\n ",
2003 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
2004 if $verbose && $pkg->{'old_failed'};
2006 $scnt{$pkg->{'state'}}++ if $state eq "all";
2008 if ($state eq "all" && !$printformat) {
2009 foreach (sort keys %scnt) {
2010 print "Total $scnt{$_} package(s) in state $_.\n";
2013 print "Total $cnt package(s)\n" unless $printformat;
2018 my( $name, $pkg, $key, $dist );
2019 my @firstkeys = qw(package version builder state section priority
2020 installed_version previous_state state_change);
2021 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
2022 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
2023 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
2024 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
2025 'state_change' => 'State-Change',
2026 'bd_problem' => 'BD-Problem',
2027 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
2028 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
2029 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
2030 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
2031 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
2032 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days'
2035 foreach $name (@_) {
2036 $name =~ s/_.*$//; # strip version
2037 foreach $dist (@dists) {
2038 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
2040 $pkg = get_readonly_source_info($name);
2041 if (!defined( $pkg )) {
2042 print "$pname: not registered\n";
2045 $pkg = calculate_prio($pkg);
2048 foreach $key (@firstkeys) {
2049 next if !defined $pkg->{$key};
2050 my $val = $pkg->{$key};
2052 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2054 my $print_key = $key;
2055 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2056 printf " %-20s: %s\n", $print_key, $val;
2058 foreach $key (sort keys %$pkg) {
2059 next if isin( $key, @firstkeys );
2060 my $val = $pkg->{$key};
2061 next if !defined($val);
2063 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2065 my $print_key = $key;
2066 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2067 printf " %-20s: %s\n", $print_key, $val;
2073 sub forget_packages {
2074 my( $name, $pkg, $key, $data );
2076 foreach $name (@_) {
2077 $name =~ s/_.*$//; # strip version
2078 $pkg = get_source_info($name);
2079 if (!defined( $pkg )) {
2080 print "$name: not registered\n";
2085 foreach $key (sort keys %$pkg) {
2086 my $val = $pkg->{$key};
2089 $data .= sprintf " %-20s: %s\n", $key, $val;
2091 send_mail( $conf::db_maint,
2092 "$name deleted from DB " . table_name() . " " . $distribution,
2093 "The package '$name' has been deleted from the database ".
2095 "Data registered about the deleted package:\n".
2096 "$data\n" ) if $conf::db_maint;
2097 change_state( \$pkg, 'deleted' );
2098 log_ta( $pkg, "--forget" );
2099 del_source_info($name);
2100 print "$name: deleted from database\n" if $verbose;
2105 $dbh->do("DELETE from " . user_table_name() .
2106 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
2112 print "Reading ASCII database from $file..." if $verbose >= 1;
2113 open( F, "<$file" ) or
2114 die "Can't open database $file: $!\n";
2116 local($/) = ""; # read in paragraph mode
2118 my( %thispkg, $name );
2120 s/\n[ \t]+/\376\377/g; # fix continuation lines
2121 s/\376\377\s*\376\377/\376\377/og;
2123 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2124 my ($key, $val) = ($1, $2);
2126 $key =~ tr/A-Z/a-z/;
2127 $val =~ s/\376\377/\n/g;
2128 $thispkg{$key} = $val;
2130 check_entry( \%thispkg );
2132 if (exists($thispkg{'package'})) {
2133 update_source_info(\%thispkg);
2135 elsif(exists($thispkg{'user'})) {
2136 # user in import, username in database.
2137 $dbh->do('INSERT INTO ' . user_table_name() .
2138 ' (username, distribution, last_seen)' .
2139 ' values (?, ?, ?)',
2140 undef, $thispkg{'user'}, $distribution,
2141 $thispkg{'last_seen'})
2142 or die $dbh->errstr;
2146 print "done\n" if $verbose >= 1;
2153 return if $op_mode eq "manual-edit"; # no checks then
2155 # check for required fields
2156 if (exists $pkg->{'user'}) {
2159 if (!exists $pkg->{'package'}) {
2160 print STDERR "Bad entry: ",
2161 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2162 die "Database entry lacks package or username field\n";
2164 # if no State: field, generate one (for old db compat)
2165 if (!exists($pkg->{'state'})) {
2167 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2169 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2170 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2173 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2174 if !isin( $pkg->{'state'},
2175 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2176 Failed Failed-Removed Not-For-Us BD-Uninstallable
2182 my($name,$pkg,$key);
2184 print "Writing ASCII database to $file..." if $verbose >= 1;
2185 open( F, ">$file" ) or
2186 die "Can't open export $file: $!\n";
2188 my $db = get_all_source_info();
2189 foreach $name (keys %$db) {
2190 next if $name =~ /^_/;
2191 my $pkg = $db->{$name};
2192 foreach $key (keys %{$pkg}) {
2193 my $val = $pkg->{$key};
2194 next if !defined($val);
2197 $val =~ s/^ +$/ ./mg;
2198 print F "$key: $val\n";
2203 print "done\n" if $verbose >= 1;
2209 my $newstate = shift;
2210 my $state = \$pkg->{'state'};
2212 return if defined($$state) and $$state eq $newstate;
2213 $pkg->{'previous_state'} = $$state if defined($$state);
2214 $pkg->{'state_change'} = $curr_date;
2215 $pkg->{'do_state_change'} = 1;
2217 if (defined($$state) and $$state eq 'Failed') {
2218 $pkg->{'old_failed'} =
2219 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2220 $pkg->{'failed'} . "\n" .
2221 $pkg->{'old_failed'};
2222 delete $pkg->{'failed'};
2223 delete $pkg->{'failed_category'};
2225 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2226 delete $pkg->{'bd_problem'};
2228 $$state = $newstate;
2234 my $dist = $distribution;
2238 $prevstate = $pkg->{'previous_state'};
2239 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2240 "changed from $prevstate to $pkg->{'state'} ".
2241 "by $real_user as $user";
2243 $dbh->do('INSERT INTO ' . transactions_table_name() .
2244 ' (package, distribution, version, action, ' .
2245 ' prevstate, state, real_user, set_user, time) ' .
2246 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2247 undef, $pkg->{'package'}, $distribution,
2248 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2249 $real_user, $user, 'now()') or die $dbh->errstr;
2251 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2252 $str .= " (with --override)"
2254 $mail_logs .= "$str\n";
2261 my $subject = shift;
2264 my $from = $conf::db_maint;
2265 my $domain = $conf::buildd_domain;
2267 $from .= "\@$domain" if $from !~ /\@/;
2269 $to .= '@' . $domain if $to !~ /\@/;
2270 $text =~ s/^\.$/../mg;
2271 local $SIG{'PIPE'} = 'IGNORE';
2272 open( PIPE, "| $conf::mailprog -oem $to" )
2273 or die "Can't open pipe to $conf::mailprog: $!\n";
2275 print PIPE "From: $from\n";
2276 print PIPE "Subject: $subject\n\n";
2277 print PIPE "$text\n";
2281 # for parsing input to dep-wait
2287 foreach (split( /\s*,\s*/, $deps )) {
2289 # verification requires > starting prompts, no | crap
2290 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2295 my @alts = split( /\s*\|\s*/, $_ );
2296 # Anything with an | is ignored, as it can be configured on a
2297 # per-buildd basis what will be installed
2298 next if $#alts != 0;
2301 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2302 warn( "parse_deplist: bad dependency $_\n" );
2305 my($dep, $rel, $relv) = ($1, $3, $4);
2306 $rel = ">>" if defined($rel) and $rel eq ">";
2307 $result{$dep}->{'package'} = $dep;
2308 if ($rel && $relv) {
2309 $result{$dep}->{'rel'} = $rel;
2310 $result{$dep}->{'version'} = $relv;
2313 return 1 if $verify;
2321 foreach $key (keys %$list) {
2322 $result .= ", " if $result;
2324 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2325 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2330 sub call_edos_depcheck {
2331 my $packagesfile = shift;
2335 return if defined ($conf::distributions{$distribution}{noadw});
2337 # We need to check all of needs-build, as any new upload could make
2338 # something in needs-build have uninstallable deps
2339 # We also check everything in bd-uninstallable, as any new upload could
2340 # make that work again
2341 my %interesting_packages;
2342 my $db = get_all_source_info();
2343 foreach $key (keys %$db) {
2344 my $pkg = $db->{$key};
2345 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/)) {
2346 $interesting_packages{$key} = undef;
2350 #print "I would look at these sources with edos-depcheck:\n";
2351 #print join " ", keys %interesting_packages,"\n";
2353 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2355 for( $i = 0;; ++$i ) {
2356 $tmpfile = $tmpfile_pattern . $i;
2357 last if ! -e $tmpfile;
2360 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2361 for my $key (keys %interesting_packages) {
2362 my $pkg = $db->{$key};
2363 print SOURCES "Package: $key\n";
2364 print SOURCES "Version: $pkg->{'version'}\n";
2365 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2366 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2367 print SOURCES "Architecture: all\n";
2372 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2374 local($/) = ""; # read in paragraph mode
2376 my( $key, $reason ) ;
2378 /^Package:\s*(\S+)$/mi and $key = $1;
2379 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2380 $reason =~ s/^\s*//mg;
2381 $reason ||= 'No reason given by edos-debcheck';
2383 if (exists $interesting_packages{$key}) {
2384 $interesting_packages{$key} = $reason;
2386 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2391 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2392 "all packages have installable build-dependencies."
2397 for my $key (keys %interesting_packages) {
2398 my $pkg = $db->{$key};
2400 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2401 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2402 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2404 if (defined $interesting_packages{$key}) {
2405 change_state( \$pkg, 'BD-Uninstallable' );
2406 $pkg->{'bd_problem'} = $interesting_packages{$key};
2408 change_state( \$pkg, 'Needs-Build' );
2411 if ($problemchange) {
2412 if (defined $interesting_packages{$key}) {
2413 $pkg->{'bd_problem'} = $interesting_packages{$key};
2417 log_ta( $pkg, "--merge-all" );
2418 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} to $pkg->{'state'}\n" if $verbose;
2420 if ($change || $problemchange) {
2421 update_source_info($pkg);
2428 ($prgname = $0) =~ s,^.*/,,;
2430 Usage: $prgname <options...> <package_version...>
2432 -v, --verbose: Verbose execution.
2433 -A arch: Architecture this operation is for.
2434 --take: Take package for building [default operation]
2435 -f, --failed: Record in database that a build failed due to
2436 deficiencies in the package (that aren't fixable without a new
2438 -u, --uploaded: Record in the database that the packages build
2439 correctly and were uploaded.
2440 -n, --no-build: Record in the database that the packages aren't
2441 desired for this architecture and shouldn't appear in listings even
2442 if they're out of date.
2443 --dep-wait: Record in the database that the packages are waiting
2444 for some source dependencies to become available
2445 --binNMU num: Schedule a re-build of the package with unchanged source, but
2446 a new version number (source-version + "+b<num>")
2447 --give-back: Mark a package as ready to build that is in state Building,
2448 Built or Build-Attempted. To give back a package in state Failed, use
2449 --override. This command will actually put the package in state
2450 BD-Uninstallable, until the installability of its Build-Dependencies
2451 were verified. This happens at each call of --merge-all, usually
2453 --merge-quinn: Merge quinn-diff output into database.
2454 --merge-packages: Merge Packages files into database.
2455 --pretend-avail: Pretend that given packages are available now and give
2456 free packages waiting for them
2457 -i SRC_PKG, --info SRC_PKG: Show information for source package
2458 -l STATE, --list=STATE: List all packages in state STATE; can be
2459 combined with -U to restrict to a specific user; STATE can
2461 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2462 source dependency list
2463 (used with -f, --dep-wait, and --binNMU)
2464 -o, --override: Override another user's lock on a package, i.e.
2465 take it over; a notice mail will be sent to the other user
2466 -U USER, --user=USER: select user name for which listings should
2467 apply, if not given all users are listed.
2468 if -l is missing, set user name to be entered in db; usually
2469 automatically choosen
2470 --import FILE: Import database from a ASCII file FILE
2471 --export FILE: Export database to a ASCII file FILE
2473 The remaining arguments (depending on operation) usually start with
2474 "name_version", the trailer is ignored. This allows to pass the names
2475 of .dsc files, for which file name completion can be used.
2476 --merge-packages and --merge-quinn take Package/quin--diff file names
2477 on the command line or read stdin. --list needs nothing more on the
2478 command line. --info takes source package names (without version).
2483 sub pkg_version_eq {
2485 my $version = shift;
2488 if (defined $pkg->{'binary_nmu_version'}) and
2489 version_compare(binNMU_version($pkg->{'version'},
2490 $pkg->{'binary_nmu_version'}),'=', $version);
2491 return version_compare( $pkg->{'version'}, "=", $version );
2495 return '"' . $arch . $schema_suffix . '".packages';
2498 sub user_table_name {
2499 return '"' . $arch . $schema_suffix . '".users';
2502 sub transactions_table_name {
2503 return '"' . $arch . $schema_suffix . '".transactions';
2506 sub get_readonly_source_info {
2508 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2509 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as state_days FROM ' .
2510 table_name() . ' WHERE package = ? AND distribution = ?',
2511 undef, $name, $distribution);
2515 sub get_source_info {
2517 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as state_days FROM ' .
2518 table_name() . ' WHERE package = ? AND distribution = ?' .
2520 undef, $name, $distribution);
2524 sub get_all_source_info {
2527 my $q = 'SELECT *, '.
2528 'extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as state_days, '.
2529 'date_trunc(\'seconds\', now() - state_change::timestamp) as state_time'.
2530 ' FROM ' . table_name()
2531 . ' WHERE distribution = ? ';
2532 my @args = ($distribution);
2533 if ($options{state} && uc($options{state}) ne "ALL") {
2534 $q .= ' AND upper(state) = ? ';
2535 push @args, uc($options{state});
2538 if ($options{user}) {
2539 #this basically means "this user, or no user at all":
2540 $q .= ' AND (builder = ? OR upper(state) = ?)';
2541 push @args, $options{user};
2542 push @args, "NEEDS-BUILD";
2545 if ($options{category}) {
2546 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2547 push @args, $options{category};
2548 push @args, "FAILED";
2551 if ($options{list_min_age} > 0) {
2552 $q .= ' AND age(state_change::timestamp) > ? ';
2553 push @args, $options{list_min_age} . " days";
2556 if ($options{list_min_age} < 0) {
2557 $q .= ' AND age(state_change::timestamp) < ? ';
2558 push @args, -$options{list_min_age} . " days";
2561 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2565 sub update_source_info {
2568 my $pkg2 = get_source_info($pkg->{'package'});
2569 if (! defined $pkg2)
2571 add_source_info($pkg);
2574 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2579 'installed_version = ?, ' .
2580 'previous_state = ?, ' .
2581 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2585 'old_failed = ?, ' .
2586 'binary_nmu_version = ?, ' .
2587 'binary_nmu_changelog = ?, ' .
2588 'failed_category = ?, ' .
2589 'permbuildpri = ?, ' .
2594 'WHERE package = ? AND distribution = ?',
2600 $pkg->{'installed_version'},
2601 $pkg->{'previous_state'},
2605 $pkg->{'old_failed'},
2606 $pkg->{'binary_nmu_version'},
2607 $pkg->{'binary_nmu_changelog'},
2608 $pkg->{'failed_category'},
2609 $pkg->{'permbuildpri'},
2613 $pkg->{'bd_problem'},
2615 $distribution) or die $dbh->errstr;
2618 sub add_source_info {
2620 $dbh->do('INSERT INTO ' . table_name() .
2621 ' (package, distribution) values (?, ?)',
2622 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2625 sub del_source_info {
2627 $dbh->do('DELETE FROM ' . table_name() .
2628 ' WHERE package = ? AND distribution = ?',
2629 undef, $name, $distribution) or die $dbh->errstr;
2634 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2635 user_table_name() . ' WHERE username = ? AND distribution = ?',
2636 undef, $name, $distribution);
2640 sub update_user_info {
2642 $dbh->do('UPDATE ' . user_table_name() .
2643 ' SET last_seen = now() WHERE username = ?' .
2644 ' AND distribution = ?',
2645 undef, $user, $distribution)
2646 or die $dbh->errstr;
2652 $dbh->do('INSERT INTO ' . user_table_name() .
2653 ' (username, distribution, last_seen)' .
2654 ' values (?, ?, now())',
2655 undef, $user, $distribution)
2656 or die $dbh->errstr;
2661 $dbh->do('LOCK TABLE ' . table_name() .
2662 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;