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';
45 our ($verbose, $mail_logs, $list_order, $list_state,
46 $curr_date, $op_mode, $user, $real_user, $distribution,
47 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
49 $info_all_dists, $arch,
50 $category, %catval, %short_category,
51 $short_date, $list_min_age, $dbbase, @curr_time,
52 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc);
55 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
59 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
60 $short_date = strftime("%m/%d/%y",@curr_time);
63 # map program invocation names to operation modes
64 my %prognames = ( "uploaded-build" => "set-uploaded",
65 "failed-build" => "set-failed",
66 "no-build" => "set-not-for-us",
67 "give-back-build" => "set-needs-build",
68 "dep-wait-build" => "set-dep-wait",
69 "forget-build" => "forget",
70 "merge-quinn" => "merge-quinn",
71 "merge-packages" => "merge-packages",
72 "merge-sources" => "merge-sources",
73 "build-info" => "info" );
75 %short_category = ( u => "uploaded-fixed-pkg",
82 c => "compiler-error",
86 ($progname = $0) =~ s,.*/,,;
87 if ($prognames{$progname}) {
88 $op_mode = $prognames{$progname};
90 elsif ($progname =~ /^list-(.*)$/) {
92 $list_state = ($1 eq "all") ? "" : $1;
97 verbose => { short => "v", flag => \$verbose },
98 override => { short => "o", flag => \$opt_override },
99 "create-db" => { flag => \$opt_create_db },
100 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
101 # TODO: remove after buildds no longer pass to wanna-build
102 "no-propagation" => { short => "N" },
103 "no-down-propagation" => { short => "D" },
105 take => { mode => "set-building" },
106 failed => { short => "f", mode => "set-failed" },
107 uploaded => { short => "u", mode => "set-uploaded" },
108 "no-build" => { short => "n", mode => "set-not-for-us" },
109 built => { mode => "set-built" },
110 attempted => { mode => "set-attempted" },
111 "give-back" => { mode => "set-needs-build" },
112 "dep-wait" => { mode => "set-dep-wait" },
113 forget => { mode => "forget" },
114 'forget-user' => { mode => 'forget-user' },
115 "merge-quinn" => { mode => "merge-quinn" },
116 "merge-partial-quinn" => { mode => "merge-partial-quinn" },
117 "merge-packages" => { mode => "merge-packages" },
118 "merge-sources" => { mode => "merge-sources" },
119 "pretend-avail" => { short => "p", mode => "pretend-avail" },
120 "merge-all" => { mode => "merge-all" },
121 "merge-all-secondary" => { mode => "merge-all-secondary" },
122 info => { short => "i", mode => "info" },
123 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
124 code => sub { die "Invalid binNMU version: $binNMUver\n"
125 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
126 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
127 code => sub { die "Invalid build priority: $build_priority\n"
128 if $build_priority !~ /^-?[\d]+$/; } },
129 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
130 code => sub { die "Invalid build priority: $build_priority\n"
131 if $build_priority !~ /^-?[\d]+$/; } },
133 { short => "l", mode => "list", arg => \$list_state,
135 die "Unknown state to list: $list_state\n"
136 if !isin( $list_state, qw(needs-build building uploaded
137 built build-attempted failed installed dep-wait
138 not-for-us all failed-removed
139 install-wait reupload-wait bd-uninstallable));} },
142 { short => "d", arg => \$distribution,
144 if ($distribution eq "a" || $distribution eq "all") {
149 $distribution = "oldstable" if $distribution eq "o";
150 $distribution = "stable" if $distribution eq "s";
151 $distribution = "testing" if $distribution eq "t";
152 $distribution = "unstable" if $distribution eq "u";
156 { short => "O", arg => \$list_order,
158 die "Bad ordering character\n"
159 if $list_order !~ /^[PSpsncb]+$/;
161 message => { short => "m", arg => \$fail_reason },
162 # database is deprecated, use arch instead.
163 database => { short => "b", arg => \$conf::dbbase },
164 arch => { short => "A", arg => \$arch },
165 user => { short => "U", arg => \$user },
166 category => { short => "c", arg => \$category,
168 $category = $short_category{$category}
169 if exists $short_category{$category};
170 die "Unknown category: $category\n"
171 if !isin( $category, values %short_category );
173 "min-age" => { short => "a", arg => \$list_min_age,
175 die "Argument of --min-age must be a non-zero number\n"
176 if $list_min_age == 0;
178 "max-age" => { arg => \$list_min_age,
180 die "Argument of --max-age must be a non-zero number\n"
181 if $list_min_age == 0;
185 export => { arg => \$export_to, mode => "export" },
186 import => { arg => \$import_from, mode => "import" },
187 "manual-edit" => { mode => "manual-edit" },
190 while( @ARGV && $ARGV[0] =~ /^-/ ) {
193 my($opt, $optname, $arg);
194 if (/^--([^=]+)(=|$)/) {
196 $opt = $options{$optname};
197 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
200 $optname = substr( $_, 1, 1 );
201 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
202 $arg = $1 if /^-$optname(.+)$/;
205 warn "Unknown option: --$1\n";
210 die "$optname option missing argument\n" if !@ARGV;
213 ${$opt->{arg}} = $arg;
215 elsif (defined $arg) {
216 die "Option $optname takes no argument\n";
220 die "Conflicting operation modes\n" if $op_mode;
221 $op_mode = $opt->{mode};
231 $op_mode = $category ? "set-failed" : "set-building"
232 if !$op_mode; # default operation
233 $list_order = $list_state eq "failed" ? 'fPcpsn' : 'PScpsn'
234 if !$list_order and $list_state;
235 $distribution ||= "unstable";
236 die "Bad distribution '$distribution'\n"
237 if !isin($distribution, keys %conf::distributions);
239 # If they didn't specify an arch, try to get it from database name which
240 # is in the form of $arch/build-db
241 # This is for backwards compatibity with older versions that didn't
242 # specify the arch yet.
243 $conf::dbbase =~ m#^([^/]+)#;
246 # TODO: Check that it's an known arch (for that dist), and give
250 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
251 $version =~ s/(^\$| \$ .*$)//g;
252 print "wanna-build $version for $distribution on $arch\n";
255 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
256 merge-packages manual-edit
258 warn "No packages given.\n";
262 $real_user = (getpwuid($<))[0];
263 die "Can't determine your user name\n"
264 if $op_mode ne "list" && !$user &&
265 !($user = $real_user);
268 if ($op_mode eq "set-failed" && !$category) {
269 print "Enter reason for failing (end with '.' alone on ".
274 last if $line eq ".\n";
275 $fail_reason .= $line;
277 chomp( $fail_reason );
278 } elsif ($op_mode eq "set-dep-wait") {
279 print "Enter dependencies (one line):\n";
281 while( !$line && !eof(STDIN) ) {
282 chomp( $line = <STDIN> );
284 die "No dependencies given\n" if !$line;
285 $fail_reason = $line;
286 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
287 print "Enter changelog entry (one line):\n";
289 while( !$line && !eof(STDIN) ) {
290 chomp( $line = <STDIN> );
292 die "No changelog entry given\n" if !$line;
293 $fail_reason = $line;
302 $dbh->disconnect or warn $dbh->errstr;
306 my $schema_suffix = '';
307 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !(not -t and $user =~ /-/)) {
308 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
309 die "FATAL: Cannot open database: $DBI::errstr\n";
310 $schema_suffix = '_public';
314 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
315 die "FATAL: Cannot open database: $DBI::errstr\n";
318 # TODO: This shouldn't be needed, file a bug.
319 $dbh->{pg_server_prepare} = 0;
321 $dbh->begin_work or die $dbh->errstr;
328 if ($mail_logs && $conf::log_mail) {
329 send_mail( $conf::log_mail,
330 "wanna-build $distribution state changes $curr_date",
331 "State changes at $curr_date for distribution ".
332 "$distribution:\n\n$mail_logs\n" );
340 SWITCH: foreach ($op_mode) {
342 add_packages( $1, @ARGV );
346 list_packages( $list_state );
350 info_packages( @ARGV );
353 /^forget-user/ && do {
354 die "This operation is restricted to admin users\n"
355 if (defined @conf::admin_users and
356 !isin( $real_user, @conf::admin_users));
357 forget_users( @ARGV );
361 forget_packages( @ARGV );
364 /^merge-partial-quinn/ && do {
365 die "This operation is restricted to admin users\n"
366 if (defined @conf::admin_users and
367 !isin( $real_user, @conf::admin_users));
372 /^merge-quinn/ && do {
373 die "This operation is restricted to admin users\n"
374 if (defined @conf::admin_users and
375 !isin( $real_user, @conf::admin_users));
380 /^merge-packages/ && do {
381 die "This operation is restricted to admin users\n"
382 if (defined @conf::admin_users and
383 !isin( $real_user, @conf::admin_users));
388 /^merge-sources/ && do {
389 die "This operation is restricted to admin users\n"
390 if (defined @conf::admin_users and
391 !isin( $real_user, @conf::admin_users));
396 /^pretend-avail/ && do {
397 pretend_avail( @ARGV );
400 /^merge-all$/ && do {
401 die "This operation is restricted to admin users\n"
402 if (defined @conf::admin_users and
403 !isin( $real_user, @conf::admin_users));
406 @ARGV = ( $ARGS[0] );
407 my $pkgs = parse_packages(0);
408 @ARGV = ( $ARGS[1] );
410 @ARGV = ( $ARGS[2] );
411 my $srcs = parse_sources(1);
412 call_edos_depcheck( $ARGS[0], $srcs );
415 /^merge-all-secondary/ && do {
416 die "This operation is restricted to admin users\n"
417 if (defined @conf::admin_users and
418 !isin( $real_user, @conf::admin_users));
419 # This is in case the chroot has multiple unrelated
420 # dist, for instance unstable and experimental.
421 # This is not for stable and proposed-updates.
422 # The second packages file contains a combination
423 # of all Packages files known to the buildd, the
424 # first only for the current dist.
427 @ARGV = ( $ARGS[0] );
428 my $pkgs = parse_packages(0);
429 @ARGV = ( $ARGS[3] );
430 my $pkgs = parse_packages(1);
431 @ARGV = ( $ARGS[1] );
433 @ARGV = ( $ARGS[2] );
434 my $srcs = parse_sources(1);
435 call_edos_depcheck( $ARGS[3], $srcs );
439 die "This operation is restricted to admin users\n"
440 if (defined @conf::admin_users and
441 !isin( $real_user, @conf::admin_users));
442 $dbh->do("DELETE from " . table_name() .
443 " WHERE distribution = ?", undef,
447 read_db( $import_from );
451 export_db( $export_to );
455 die "Unexpected operation mode $op_mode\n";
457 if (not -t and $user =~ /-/) {
458 my $userinfo = get_user_info($user);
459 if (!defined $userinfo)
461 add_user_info($user);
465 update_user_info($user);
471 my $newstate = shift;
472 my( $package, $name, $version, $ok, $reason );
474 foreach $package (@_) {
475 $package =~ s,^.*/,,; # strip path
476 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
477 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
478 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
479 ($name,$version) = ($1,$2);
482 warn "$package: can't extract package name and version ".
487 if ($op_mode eq "set-building") {
488 add_one_building( $name, $version );
490 elsif ($op_mode eq "set-built") {
491 add_one_built( $name, $version );
493 elsif ($op_mode eq "set-attempted") {
494 add_one_attempted( $name, $version );
496 elsif ($op_mode eq "set-uploaded") {
497 add_one_uploaded( $name, $version );
499 elsif ($op_mode eq "set-failed") {
500 add_one_failed( $name, $version );
502 elsif ($op_mode eq "set-not-for-us") {
503 add_one_notforus( $name, $version );
505 elsif ($op_mode eq "set-needs-build") {
506 add_one_needsbuild( $name, $version );
508 elsif ($op_mode eq "set-dep-wait") {
509 add_one_depwait( $name, $version );
511 elsif ($op_mode eq "set-build-priority") {
512 set_one_buildpri( $name, $version, 'buildpri' );
514 elsif ($op_mode eq "set-permanent-build-priority") {
515 set_one_buildpri( $name, $version, 'permbuildpri' );
517 elsif ($op_mode eq "set-binary-nmu") {
518 set_one_binnmu( $name, $version );
523 sub add_one_building {
529 my $pkg = get_source_info($name);
531 if ($pkg->{'state'} eq "Not-For-Us") {
533 $reason = "not suitable for this architecture";
535 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
537 $reason = "not all source dependencies available yet";
539 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
541 $reason = "source dependencies are not installable";
543 elsif ($pkg->{'state'} eq "Uploaded" &&
544 (version_lesseq($version, $pkg->{'version'}))) {
546 $reason = "already uploaded by $pkg->{'builder'}";
547 $reason .= " (in newer version $pkg->{'version'})"
548 if !version_eq($pkg, $version);
550 elsif ($pkg->{'state'} eq "Installed" &&
551 version_less($version,$pkg->{'version'})) {
553 print "$name: Warning: newer version $pkg->{'version'} ".
554 "already installed, but overridden.\n";
558 $reason = "newer version $pkg->{'version'} already in ".
559 "archive; doesn't need rebuilding";
560 print "$name: Note: If the following is due to an epoch ",
561 " change, use --override\n";
564 elsif ($pkg->{'state'} eq "Installed" &&
565 pkg_version_eq($pkg,$version)) {
567 $reason = "is up-to-date in the archive; doesn't need rebuilding";
569 elsif ($pkg->{'state'} eq "Needs-Build" &&
570 version_less($version,$pkg->{'version'})) {
572 print "$name: Warning: newer version $pkg->{'version'} ".
573 "needs building, but overridden.";
577 $reason = "newer version $pkg->{'version'} needs building, ".
581 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
582 if (version_less($pkg->{'version'},$version)) {
583 print "$name: Warning: Older version $pkg->{'version'} ",
584 "is being built by $pkg->{'builder'}\n";
585 if ($pkg->{'builder'} ne $user) {
586 send_mail( $pkg->{'builder'},
587 "package takeover in newer version",
588 "You are building package '$name' in ".
589 "version $version\n".
590 "(as far as I'm informed).\n".
591 "$user now has taken the newer ".
592 "version $version for building.".
593 "You can abort the build if you like.\n" );
598 print "User $pkg->{'builder'} had already ",
599 "taken the following package,\n",
600 "but overriding this as you request:\n";
601 send_mail( $pkg->{'builder'}, "package takeover",
602 "The package '$name' (version $version) that ".
603 "was taken by you\n".
604 "has been taken over by $user\n" );
606 elsif ($pkg->{'builder'} eq $user) {
607 print "$name: Note: already taken by you.\n";
608 print "$name: ok\n" if $verbose;
613 $reason = "already taken by $pkg->{'builder'}";
614 $reason .= " (in newer version $pkg->{'version'})"
615 if !version_eq($pkg->{'version'}, $version);
619 elsif ($pkg->{'state'} =~ /^Failed/ &&
620 pkg_version_eq($pkg, $version)) {
622 print "The following package previously failed ",
623 "(by $pkg->{'builder'})\n",
624 "but overriding this as you request:\n";
625 send_mail( $pkg->{'builder'}, "failed package takeover",
626 "The package '$name' (version $version) that ".
628 "and has failed previously has been taken over ".
630 if $pkg->{'builder'} ne $user;
634 $reason = "build of $version failed previously:\n ";
635 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
636 $reason .= "\nalso the package doesn't need builing"
637 if $pkg->{'state'} eq 'Failed-Removed';
643 if ($pkg->{'binary_nmu_version'}) {
644 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
645 "$pkg->{'binary_nmu_changelog'}\n";
648 print "$name: Warning: Previous version failed!\n"
649 if $pkg->{'previous_state'} =~ /^Failed/ ||
650 $pkg->{'state'} =~ /^Failed/;
652 change_state( \$pkg, 'Building' );
653 $pkg->{'package'} = $name;
654 $pkg->{'version'} = $version;
655 $pkg->{'builder'} = $user;
656 log_ta( $pkg, "--take" );
657 update_source_info($pkg);
658 print "$name: $ok\n" if $verbose;
661 print "$name: NOT OK!\n $reason\n";
665 sub add_one_attempted {
668 my $pkg = get_source_info($name);
670 if (!defined($pkg)) {
671 print "$name: not registered yet.\n";
675 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
676 print "$name: not taken for building (state is $pkg->{'state'}). ",
680 if ($pkg->{'builder'} ne $user) {
681 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
684 elsif ( !pkg_version_eq($pkg, $version) ) {
685 print "$name: version mismatch ".
686 "$(pkg->{'version'} ".
687 "by $pkg->{'builder'})\n";
691 change_state( \$pkg, 'Build-Attempted' );
692 log_ta( $pkg, "--attempted" );
693 update_source_info($pkg);
694 print "$name: registered as uploaded\n" if $verbose;
700 my $pkg = get_source_info($name);
702 if (!defined($pkg)) {
703 print "$name: not registered yet.\n";
707 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
708 print "$name: not taken for building (state is $pkg->{'state'}). ",
712 if ($pkg->{'builder'} ne $user) {
713 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
716 elsif ( !pkg_version_eq($pkg, $version) ) {
717 print "$name: version mismatch ".
718 "$(pkg->{'version'} ".
719 "by $pkg->{'builder'})\n";
722 change_state( \$pkg, 'Built' );
723 log_ta( $pkg, "--built" );
724 update_source_info($pkg);
725 print "$name: registered as built\n" if $verbose;
728 sub add_one_uploaded {
731 my $pkg = get_source_info($name);
733 if (!defined($pkg)) {
734 print "$name: not registered yet.\n";
738 if ($pkg->{'state'} eq "Uploaded" &&
739 pkg_version_eq($pkg,$version)) {
740 print "$name: already uploaded\n";
743 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
744 print "$name: not taken for building (state is $pkg->{'state'}). ",
748 if ($pkg->{'builder'} ne $user) {
749 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
752 # strip epoch -- buildd-uploader used to go based on the filename.
753 # (to remove at some point)
755 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
756 $version =~ s/^\d+://; # for command line use
757 if ($pkg->{'binary_nmu_version'} ) {
758 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
759 if (!version_eq( $nmuver, $version )) {
760 print "$name: version mismatch ($nmuver registered). ",
764 } elsif (!version_eq($pkgver, $version)) {
765 print "$name: version mismatch ($pkg->{'version'} registered). ",
770 change_state( \$pkg, 'Uploaded' );
771 log_ta( $pkg, "--uploaded" );
772 update_source_info($pkg);
773 print "$name: registered as uploaded\n" if $verbose;
780 my $pkg = get_source_info($name);
782 if (!defined($pkg)) {
783 print "$name: not registered yet.\n";
786 $state = $pkg->{'state'};
788 if ($state eq "Not-For-Us") {
789 print "$name: not suitable for this architecture anyway. Skipping.\n";
792 elsif ($state eq "Failed-Removed") {
793 print "$name: failed previously and doesn't need building. Skipping.\n";
796 elsif ($state eq "Installed") {
797 print "$name: Is already installed in archive. Skipping.\n";
800 elsif ($pkg->{'builder'} &&
801 (($user ne $pkg->{'builder'}) &&
802 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
803 print "$name: not taken by you, but by ".
804 "$pkg->{'builder'}. Skipping.\n";
807 elsif ( !pkg_version_eq($pkg, $version) ) {
808 print "$name: version mismatch ".
809 "$(pkg->{'version'} ".
810 "by $pkg->{'builder'})\n";
815 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
817 $cat = $short_category{$cat} if exists $short_category{$cat};
818 if (!isin( $cat, values %short_category )) {
819 print "$name: Warning: unknown category $cat; discarded\n";
822 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
825 if ($state eq "Needs-Build") {
826 print "$name: Warning: not registered for building previously, ".
827 "but processing anyway.\n";
829 elsif ($state eq "Uploaded") {
830 print "$name: Warning: marked as uploaded previously, ".
831 "but processing anyway.\n";
833 elsif ($state eq "Dep-Wait") {
834 print "$name: Warning: marked as waiting for dependencies, ".
835 "but processing anyway.\n";
837 elsif ($state eq "BD-Uninstallable") {
838 print "$name: Warning: marked as having uninstallable build-dependencies, ".
839 "but processing anyway.\n";
841 elsif ($state eq "Failed") {
842 print "$name: already registered as failed; will append new message\n"
844 print "$name: already registered as failed; changing category\n"
848 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
849 defined $pkg->{'failed_category'} &&
850 $pkg->{'failed_category'} ne $cat) {
851 (my $action = $cat) =~ s/-/ /;
852 $fail_reason .= "\n$short_date: $action";
855 change_state( \$pkg, 'Failed' );
856 $pkg->{'builder'} = $user;
857 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
858 $pkg->{'failed'} .= $fail_reason;
859 $pkg->{'failed_category'} = $cat if $cat;
860 if (defined $pkg->{'permbuildpri'}) {
861 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
863 delete $pkg->{'buildpri'};
865 log_ta( $pkg, "--failed" );
866 update_source_info($pkg);
867 print "$name: registered as failed\n" if $verbose;
870 sub add_one_notforus {
873 my $pkg = get_source_info($name);
875 if ($pkg->{'state'} eq 'Not-For-Us') {
876 # reset Not-For-Us state in case it's called twice; this is
877 # the only way to get a package out of this state...
878 # There is no really good state in which such packages should
879 # be put :-( So use Failed for now.
880 change_state( \$pkg, 'Failed' );
881 $pkg->{'package'} = $name;
882 $pkg->{'failed'} = "Was Not-For-Us previously";
883 delete $pkg->{'builder'};
884 delete $pkg->{'depends'};
885 log_ta( $pkg, "--no-build(rev)" );
886 print "$name: now not unsuitable anymore\n";
888 send_mail( $conf::notforus_maint,
889 "$name moved out of Not-For-Us state",
890 "The package '$name' has been moved out of the Not-For-Us ".
892 "It should probably also be removed from ".
893 "Packages-arch-specific or\n".
894 "the action was wrong.\n" )
895 if $conf::notforus_maint;
898 change_state( \$pkg, 'Not-For-Us' );
899 $pkg->{'package'} = $name;
900 delete $pkg->{'builder'};
901 delete $pkg->{'depends'};
902 delete $pkg->{'buildpri'};
903 delete $pkg->{'binary_nmu_version'};
904 delete $pkg->{'binary_nmu_changelog'};
905 log_ta( $pkg, "--no-build" );
906 print "$name: registered as unsuitable\n" if $verbose;
908 send_mail( $conf::notforus_maint,
909 "$name set to Not-For-Us",
910 "The package '$name' has been set to state Not-For-Us ".
912 "It should probably also be added to ".
913 "Packages-arch-specific or\n".
914 "the Not-For-Us state is wrong.\n" )
915 if $conf::notforus_maint;
917 update_source_info($pkg);
920 sub add_one_needsbuild {
924 my $pkg = get_source_info($name);
926 if (!defined($pkg)) {
927 print "$name: not registered; can't give back.\n";
930 $state = $pkg->{'state'};
932 if ($state eq "BD-Uninstallable") {
934 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
936 change_state( \$pkg, 'Needs-Build' );
937 delete $pkg->{'builder'};
938 delete $pkg->{'depends'};
939 log_ta( $pkg, "--give-back" );
940 update_source_info($pkg);
941 print "$name: given back\n" if $verbose;
945 print "$name: has uninstallable build-dependencies. Skipping\n",
946 " (use --override to clear dependency list and ",
947 "give back anyway)\n";
951 elsif ($state eq "Dep-Wait") {
953 print "$name: Forcing source dependency list to be cleared\n";
956 print "$name: waiting for source dependencies. Skipping\n",
957 " (use --override to clear dependency list and ",
958 "give back anyway)\n";
962 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
963 print "$name: not taken for building (state is $state).";
965 print "\n$name: Forcing give-back\n";
968 print " Skipping.\n";
972 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
973 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
975 print "$name: not taken by you, but by ".
976 "$pkg->{'builder'}. Skipping.\n";
979 if (!pkg_version_eq($pkg, $version)) {
980 print "$name: version mismatch ($pkg->{'version'} registered). ",
984 if ($distribution eq "unstable") {
985 change_state( \$pkg, 'BD-Uninstallable' );
986 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
988 change_state( \$pkg, 'Needs-Build' );
990 $pkg->{'builder'} = undef;
991 $pkg->{'depends'} = undef;
992 log_ta( $pkg, "--give-back" );
993 update_source_info($pkg);
994 print "$name: given back\n" if $verbose;
1000 my $pkg = get_source_info($name);
1003 if (!defined($pkg)) {
1004 print "$name: not registered; can't register for binNMU.\n";
1007 my $db_ver = $pkg->{'version'};
1009 if (!version_eq($db_ver, $version)) {
1010 print "$name: version mismatch ($db_ver registered). ",
1014 $state = $pkg->{'state'};
1016 if (defined $pkg->{'binary_nmu_version'}) {
1017 if ($binNMUver == 0) {
1018 change_state( \$pkg, 'Installed' );
1019 delete $pkg->{'builder'};
1020 delete $pkg->{'depends'};
1021 delete $pkg->{'binary_nmu_version'};
1022 delete $pkg->{'binary_nmu_changelog'};
1023 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1024 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1027 $pkg->{'binary_nmu_version'} = $binNMUver;
1028 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1029 $pkg->{'notes'} = 'out-of-date';
1030 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1031 if (defined $pkg->{'permbuildpri'});
1033 log_ta( $pkg, "--binNMU" );
1034 update_source_info($pkg);
1036 } elsif ($binNMUver == 0) {
1037 print "${name}_$version: no scheduled binNMU to cancel.\n";
1041 if ($state ne 'Installed') {
1042 print "${name}_$version: not installed; can't register for binNMU.\n";
1046 my $fullver = binNMU_version($version,$binNMUver);
1047 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1049 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1053 if ($distribution eq "unstable") {
1054 change_state( \$pkg, 'BD-Uninstallable' );
1055 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1059 change_state( \$pkg, 'Needs-Build' );
1061 delete $pkg->{'builder'};
1062 delete $pkg->{'depends'};
1063 $pkg->{'binary_nmu_version'} = $binNMUver;
1064 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1065 $pkg->{'notes'} = 'out-of-date';
1066 log_ta( $pkg, "--binNMU" );
1067 update_source_info($pkg);
1068 print "${name}: registered for binNMU $fullver\n" if $verbose;
1071 sub set_one_buildpri {
1073 my $version = shift;
1075 my $pkg = get_source_info($name);
1078 if (!defined($pkg)) {
1079 print "$name: not registered; can't set priority.\n";
1082 $state = $pkg->{'state'};
1084 if ($state eq "Not-For-Us") {
1085 print "$name: not suitable for this architecture. Skipping.\n";
1087 } elsif ($state eq "Failed-Removed") {
1088 print "$name: failed previously and doesn't need building. Skipping.\n";
1091 if (!pkg_version_eq($pkg, $version)) {
1092 print "$name: version mismatch ($pkg->{'version'} registered). ",
1096 if ( $build_priority == 0 ) {
1097 delete $pkg->{'buildpri'}
1098 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1099 and $pkg->{'buildpri'} == $pkg->{$key};
1100 delete $pkg->{$key};
1102 $pkg->{'buildpri'} = $build_priority
1103 if $key eq 'permbuildpri';
1104 $pkg->{$key} = $build_priority;
1106 update_source_info($pkg);
1107 print "$name: set to build priority $build_priority\n" if $verbose;
1110 sub add_one_depwait {
1112 my $version = shift;
1114 my $pkg = get_source_info($name);
1116 if (!defined($pkg)) {
1117 print "$name: not registered yet.\n";
1120 $state = $pkg->{'state'};
1122 if ($state eq "Dep-Wait") {
1123 print "$name: merging with previously registered dependencies\n";
1126 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1127 print "$name: Warning: not registered for building previously, ".
1128 "but processing anyway.\n";
1130 elsif ($state eq "Not-For-Us") {
1131 print "$name: not suitable for this architecture anyway. Skipping.\n";
1134 elsif ($state eq "Failed-Removed") {
1135 print "$name: failed previously and doesn't need building. Skipping.\n";
1138 elsif ($state eq "Installed") {
1139 print "$name: Is already installed in archive. Skipping.\n";
1142 elsif ($state eq "Uploaded") {
1143 print "$name: Is already uploaded. Skipping.\n";
1146 elsif ($pkg->{'builder'} &&
1147 $user ne $pkg->{'builder'}) {
1148 print "$name: not taken by you, but by ".
1149 "$pkg->{'builder'}. Skipping.\n";
1152 elsif ( !pkg_version_eq($pkg,$version)) {
1153 print "$name: version mismatch ".
1154 "($pkg->{'version'} ".
1155 "by $pkg->{'builder'})\n";
1158 elsif ($fail_reason =~ /^\s*$/ ||
1159 !parse_deplist( $fail_reason, 1 )) {
1160 print "$name: Bad dependency list\n";
1163 change_state( \$pkg, 'Dep-Wait' );
1164 $pkg->{'builder'} = $user;
1165 if (defined $pkg->{'permbuildpri'}) {
1166 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1168 delete $pkg->{'buildpri'};
1170 my $deplist = parse_deplist( $pkg->{'depends'} );
1171 my $new_deplist = parse_deplist( $fail_reason );
1172 # add new dependencies, maybe overwriting old entries
1173 foreach (keys %$new_deplist) {
1174 $deplist->{$_} = $new_deplist->{$_};
1176 $pkg->{'depends'} = build_deplist($deplist);
1177 log_ta( $pkg, "--dep-wait" );
1178 update_source_info($pkg);
1179 print "$name: registered as waiting for dependencies\n" if $verbose;
1189 my $db = get_all_source_info();
1191 local($/) = ""; # read in paragraph mode
1193 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1195 /^Package:\s*(\S+)$/mi and $name = $1;
1196 /^Version:\s*(\S+)$/mi and $version = $1;
1197 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1198 /^Section:\s*(\S+)$/mi and $section = $1;
1199 /^Priority:\s*(\S+)$/mi and $priority = $1;
1200 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1201 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1202 /^Binary:\s*(.*)$/mi and $binaries = $1;
1204 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1205 $srcver{$name} = $version;
1207 $pkgs{$name}{'ver'} = $version;
1208 $pkgs{$name}{'bin'} = $binaries;
1209 $pkgs{$name}{'dep'} = $builddep;
1210 $pkgs{$name}{'conf'} = $buildconf;
1211 my $pkg = $db->{$name};
1216 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1217 # package is now Arch: all, delete it from db
1218 change_state( \$pkg, 'deleted' );
1219 log_ta( $pkg, "--merge-sources" );
1220 print "$name ($pkg->{'version'}): deleted ".
1221 "from database, because now Arch: all\n"
1223 del_source_info($name);
1224 delete $db->{$name};
1228 # The "Version" should always be the source version --
1229 # not a possible binNMU version number.
1230 $pkg->{'version'} = $version, $change++
1231 if ($pkg->{'state'} eq 'Installed' and
1232 !version_eq( $pkg->{'version'}, $version));
1233 # Always update priority and section, if available
1234 $pkg->{'priority'} = $priority, $change++
1235 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1237 $pkg->{'section'} = $section, $change++
1238 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1240 update_source_info($pkg) if $change;
1243 # Now that we only have the latest source version, build the list
1244 # of binary packages from the Sources point of view
1245 foreach $name (keys %pkgs) {
1246 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1247 $merge_binsrc{$bin} = $name;
1250 # remove installed packages that no longer have source available
1251 # or binaries installed
1252 foreach $name (keys %$db) {
1253 next if $name =~ /^_/;
1254 my $pkg = $db->{$name};
1255 if (not defined($pkgs{$name})) {
1256 change_state( \$pkg, 'deleted' );
1257 log_ta( $pkg, "--merge-sources" );
1258 print "$name ($pkg->{'version'}): ".
1259 "deleted from database, because ".
1260 "not in Sources anymore\n"
1262 del_source_info($name);
1263 delete $db->{$name};
1265 next if !isin( $pkg->{'state'}, qw(Installed) );
1266 if ($full && not defined $merge_srcvers{$name}) {
1267 change_state( \$pkg, 'deleted' );
1268 log_ta( $pkg, "--merge-sources" );
1269 print "$name ($pkg->{'version'}): ".
1270 "deleted from database, because ".
1271 "binaries don't exist anymore\n"
1273 del_source_info($name);
1274 delete $db->{$name};
1275 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1276 print "$name ($pkg->{'version'}): ".
1277 "package is Installed but binaries are from ".
1278 $merge_srcvers{$name}. "\n"
1286 # This function looks through a Packages file and sets the state of
1287 # packages to 'Installed'
1288 sub parse_packages {
1289 my $depwait_only = shift;
1292 my $pkgs = get_all_source_info();
1293 local($/) = ""; # read in paragraph mode
1295 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1297 /^Package:\s*(\S+)$/mi and $name = $1;
1298 /^Version:\s*(\S+)$/mi and $version = $1;
1299 /^Depends:\s*(.*)$/mi and $depends = $1;
1300 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1301 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1302 /^Provides:\s*(.*)$/mi and $provides = $1;
1303 next if !$name || !$version;
1304 next if ($arch ne $architecture and $architecture ne "all");
1305 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1306 version_lesseq( $version, $installed->{$name}{'version'} ));
1307 $installed->{$name}{'version'} = $version;
1308 next if $depwait_only;
1309 $installed->{$name}{'depends'} = $depends;
1310 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1311 undef $installed->{$name}{'Provider'};
1312 $installed->{$name}{'Source'} = $source ? $source : $name;
1314 foreach (split( /\s*,\s*/, $provides )) {
1315 if (not defined ($installed->{$_})) {
1316 $installed->{$_}{'version'} = "";
1317 $installed->{$_}{'Provider'} = $name;
1321 if ( $version =~ /\+b(\d+)$/ ) {
1324 $version = $sourcev if $sourcev;
1325 $binaryv = $version;
1326 $binaryv =~ s/\+b\d+$//;
1327 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1328 $binaryv .= "+b$binnmu" if defined($binnmu);
1330 next if $architecture ne $arch;
1331 $name = $source if $source;
1332 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1333 $merge_srcvers{$name} = $version;
1335 my $pkg = $pkgs->{$name};
1338 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1339 (isin($pkg->{'state'}, qw(Installed)) &&
1340 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1341 print "Skipping $name because State == $pkg->{'state'}\n"
1345 if ($pkg->{'binary_nmu_version'} ) {
1346 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1347 if (version_less( $binaryv, $nmuver )) {
1348 print "Skipping $name ($version) because have newer ".
1349 "version ($nmuver) in db.\n"
1353 } elsif (version_less($version, $pkg->{'version'})) {
1354 print "Skipping $name ($version) because have newer ".
1355 "version ($pkg->{'version'}) in db.\n"
1360 if (!pkg_version_eq($pkg, $version) &&
1361 $pkg->{'state'} ne "Installed") {
1362 warn "Warning: $name: newer version than expected appeared ".
1363 "in archive ($version vs. $pkg->{'version'})\n";
1364 delete $pkg->{'builder'};
1367 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1368 warn "Warning: Package $name was not in uploaded state ".
1369 "before (but in '$pkg->{'state'}').\n";
1370 delete $pkg->{'builder'};
1371 delete $pkg->{'depends'};
1375 $pkg->{'version'} = $version;
1378 change_state( \$pkg, 'Installed' );
1379 $pkg->{'package'} = $name;
1380 $pkg->{'installed_version'} = $binaryv;
1381 if (defined $pkg->{'permbuildpri'}) {
1382 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1384 delete $pkg->{'buildpri'};
1386 $pkg->{'version'} = $version
1387 if version_less( $pkg->{'version'}, $version);
1388 delete $pkg->{'binary_nmu_version'};
1389 delete $pkg->{'binary_nmu_changelog'};
1390 log_ta( $pkg, "--merge-packages" );
1391 update_source_info($pkg);
1392 print "$name ($version) is up-to-date now.\n" if $verbose;
1395 check_dep_wait( "--merge-packages", $installed );
1400 my ($package, $name, $version, $installed);
1402 foreach $package (@_) {
1403 $package =~ s,^.*/,,; # strip path
1404 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1405 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1406 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1407 ($name,$version) = ($1,$2);
1410 warn "$package: can't extract package name and version ".
1414 $installed->{$name}{'version'} = $version;
1417 check_dep_wait( "--pretend-avail", $installed );
1420 sub check_dep_wait {
1422 my $installed = shift;
1424 # check all packages in state Dep-Wait if dependencies are all
1427 my $db = get_all_source_info();
1428 foreach $name (keys %$db) {
1429 next if $name =~ /^_/;
1430 my $pkg = $db->{$name};
1431 next if $pkg->{'state'} ne "Dep-Wait";
1432 my $deps = $pkg->{'depends'};
1434 print "$name: was in state Dep-Wait, but with empty ",
1436 goto make_needs_build;
1438 my $deplist = parse_deplist($deps);
1442 foreach (keys %$deplist) {
1443 if (!exists $installed->{$_} ||
1444 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1445 !version_compare( $installed->{$_}{'version'},
1446 $deplist->{$_}->{'rel'},
1447 $deplist->{$_}->{'version'}))) {
1449 $new_deplist->{$_} = $deplist->{$_};
1452 push( @removed_deps, $_ );
1457 change_state( \$pkg, 'Needs-Build' );
1458 log_ta( $pkg, $action );
1459 delete $pkg->{'builder'};
1460 delete $pkg->{'depends'};
1461 print "$name ($pkg->{'version'}) has all ",
1462 "dependencies available now\n" if $verbose;
1464 update_source_info($pkg);
1466 elsif (@removed_deps) {
1467 $pkg->{'depends'} = build_deplist( $new_deplist );
1468 print "$name ($pkg->{'version'}): some dependencies ",
1469 "(@removed_deps) available now, but not all yet\n"
1471 update_source_info($pkg);
1476 # This function accepts quinn-diff output (either from a file named on
1477 # the command line, or on stdin) and sets the packages named there to
1478 # state 'Needs-Build'.
1479 sub parse_quinn_diff {
1480 my $partial = shift;
1484 my $pkgs = get_all_source_info();
1488 next if !m,^([-\w\d/]*)/ # section
1489 ([-\w\d.+]+)_ # package name
1490 ([\w\d:.~+-]+)\.dsc\s* # version
1491 \[([^:]*): # priority
1492 ([^]]+)\]\s*$,x; # rest of notes
1493 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1494 $quinn_pkgs{$name}++;
1495 $section ||= "unknown";
1496 $priority ||= "unknown";
1497 $priority = "unknown" if $priority eq "-";
1498 $priority = "standard" if ($name eq "debian-installer");
1500 my $pkg = $pkgs->{$name};
1502 # Always update section and priority.
1503 if (defined($pkg)) {
1505 $pkg->{'section'} = $section, $change++ if not defined
1506 $pkg->{'section'} or $section ne "unknown";
1507 $pkg->{'priority'} = $priority, $change++ if not defined
1508 $pkg->{'priority'} or $priority ne "unknown";
1511 if (defined($pkg) &&
1512 $pkg->{'state'} =~ /^Dep-Wait/ &&
1513 version_less( $pkg->{'version'}, $version )) {
1514 change_state( \$pkg, 'Dep-Wait' );
1515 $pkg->{'version'} = $version;
1516 delete $pkg->{'binary_nmu_version'};
1517 delete $pkg->{'binary_nmu_changelog'};
1518 log_ta( $pkg, "--merge-quinn" );
1520 print "$name ($version) still waiting for dependencies.\n"
1523 elsif (defined($pkg) &&
1524 $pkg->{'state'} =~ /-Removed$/ &&
1525 version_eq($pkg->{'version'}, $version)) {
1526 # reinstantiate a package that has been removed earlier
1527 # (probably due to a quinn-diff malfunction...)
1528 my $newstate = $pkg->{'state'};
1529 $newstate =~ s/-Removed$//;
1530 change_state( \$pkg, $newstate );
1531 $pkg->{'version'} = $version;
1532 $pkg->{'notes'} = $notes;
1533 log_ta( $pkg, "--merge-quinn" );
1535 print "$name ($version) reinstantiated to $newstate.\n"
1538 elsif (defined($pkg) &&
1539 $pkg->{'state'} eq "Not-For-Us" &&
1540 version_less( $pkg->{'version'}, $version )) {
1541 # for Not-For-Us packages just update the version etc., but
1543 change_state( \$pkg, "Not-For-Us" );
1544 $pkg->{'package'} = $name;
1545 $pkg->{'version'} = $version;
1546 $pkg->{'notes'} = $notes;
1547 delete $pkg->{'builder'};
1548 log_ta( $pkg, "--merge-quinn" );
1550 print "$name ($version) still Not-For-Us.\n" if $verbose;
1552 elsif (!defined($pkg) ||
1553 $pkg->{'state'} ne "Not-For-Us" &&
1554 (version_less( $pkg->{'version'}, $version ) ||
1555 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1557 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1558 send_mail( $pkg->{'builder'},
1559 "new version of $name (dist=$distribution)",
1560 "As far as I'm informed, you're currently ".
1561 "building the package $name\n".
1562 "in version $pkg->{'version'}.\n\n".
1563 "Now there's a new source version $version. ".
1564 "If you haven't finished\n".
1565 "compiling $name yet, you can stop it to ".
1566 "save some work.\n".
1567 "Just to inform you...\n".
1568 "(This is an automated message)\n" );
1569 print "$name: new version ($version) while building ".
1570 "$pkg->{'version'} -- sending mail ".
1571 "to builder ($pkg->{'builder'})\n"
1574 change_state( \$pkg, 'Needs-Build' );
1575 $pkg->{'package'} = $name;
1576 $pkg->{'version'} = $version;
1577 $pkg->{'section'} = $section;
1578 $pkg->{'priority'} = $priority;
1579 $pkg->{'notes'} = $notes;
1580 delete $pkg->{'builder'};
1581 delete $pkg->{'binary_nmu_version'};
1582 delete $pkg->{'binary_nmu_changelog'};
1583 log_ta( $pkg, "--merge-quinn" );
1586 print "$name ($version) needs rebuilding now.\n" if $verbose;
1588 elsif (defined($pkg) &&
1589 !version_eq( $pkg->{'version'}, $version ) &&
1590 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1591 print "$name: skipping because version in db ".
1592 "($pkg->{'version'}) is >> than ".
1593 "what quinn-diff says ($version) ".
1594 "(state is $pkg->{'state'})\n"
1596 $dubious .= "$pkg->{'state'}: ".
1597 "db ${name}_$pkg->{'version'} >> ".
1598 "quinn $version\n" if !$partial;
1600 elsif ($verbose >= 2) {
1601 if ($pkg->{'state'} eq "Not-For-Us") {
1602 print "Skipping $name because State == ".
1603 "$pkg->{'state'}\n";
1605 elsif (!version_less($pkg->{'version'}, $version)) {
1606 print "Skipping $name because version in db ".
1607 "($pkg->{'version'}) is >= than ".
1608 "what quinn-diff says ($version)\n";
1611 update_source_info($pkg) if $change;
1615 send_mail( $conf::db_maint,
1616 "Dubious versions in " . table_name() . " "
1617 . $distribution . " table",
1618 "The following packages have a newer version in the ".
1619 "wanna-build database\n".
1620 "than what quinn-diff says, and this is strange for ".
1622 "It could be caused by a lame mirror, or the version ".
1623 "in the database\n".
1628 # Now re-check the DB for packages in states Needs-Build, Failed,
1629 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1630 # anymore by quinn-diff.
1633 my $db = get_all_source_info();
1634 foreach $name (keys %$db) {
1635 next if $name =~ /^_/;
1636 my $pkg = $db->{$name};
1637 next if defined $pkg->{'binary_nmu_version'};
1638 next if !isin( $pkg->{'state'},
1639 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1640 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1642 if (!$quinn_pkgs{$name}) {
1643 change_state( \$pkg, $virtual_delete ?
1644 $pkg->{'state'}."-Removed" :
1646 log_ta( $pkg, "--merge-quinn" );
1647 print "$name ($pkg->{'version'}): ".
1648 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1649 "from database, because not in quinn-diff anymore\n"
1651 if ($virtual_delete) {
1652 update_source_info($pkg);
1654 del_source_info($name);
1662 # for sorting priorities and sections
1664 %prioval = ( required => -5,
1672 'debian-installer' => -199,
1693 localizations => -178,
1694 interpreters => -177,
1719 electronics => -152,
1725 foreach my $i (keys %sectval) {
1726 $sectval{"contrib/$i"} = $sectval{$i}+40;
1727 $sectval{"non-free/$i"} = $sectval{$i}+80;
1729 $sectval{'unknown'} = -165;
1731 %catval = ( "none" => -20,
1732 "uploaded-fixed-pkg" => -19,
1733 "fix-expected" => -18,
1734 "reminder-sent" => -17,
1735 "nmu-offered" => -16,
1739 "compiler-error" => -12 );
1742 sub sort_list_func {
1743 my( $letter, $x, $ax, $bx );
1745 foreach $letter (split( "", $list_order )) {
1746 SWITCH: foreach ($letter) {
1748 $x = $b->{'buildpri'} <=> $a->{'buildpri'};
1749 return $x if $x != 0;
1753 $x = $prioval{$a->{'priority'}} <=> $prioval{$b->{'priority'}};
1754 return $x if $x != 0;
1758 $x = $sectval{$a->{'section'}} <=> $sectval{$b->{'section'}};
1759 return $x if $x != 0;
1763 $x = $a->{'package'} cmp $b->{'package'};
1764 return $x if $x != 0;
1768 $x = $a->{'builder'} cmp $b->{'builder'};
1769 return $x if $x != 0;
1773 $ax = ($a->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1774 ($a->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1775 $bx = ($b->{'notes'} =~ /^(out-of-date|partial)/) ? 0 :
1776 ($b->{'notes'} =~ /^uncompiled/) ? 2 : 1;
1778 return $x if $x != 0;
1782 my $ca = defined $a->{'failed_category'} ?
1783 $a->{'failed_category'} : "none";
1784 my $cb = defined $b->{'failed_category'} ?
1785 $b->{'failed_category'} : "none";
1786 $x = $catval{$ca} <=> $catval{$cb};
1787 return $x if $x != 0;
1791 my $pa = $prioval{$a->{'priority'}} >
1792 $prioval{'standard'};
1793 my $pb = $prioval{$b->{'priority'}} >
1794 $prioval{'standard'};
1796 return $x if $x != 0;
1804 sub calculate_prio {
1805 ######################
1806 # priority: required = 50, important = 40, standard = 30, optional = 5
1807 # section: libs = 4, devel = 2
1808 # component: contrib = -10, non-free = -20
1810 # max(floor(waitingdays),6)
1813 $priomap->{'priority'} = { 'required' => 50, 'important' => 40, 'standard' => 30, 'optional' => 5 };
1814 $priomap->{'section'} = { 'libs' => 4, 'devel' => 2 };
1815 $priomap->{'component'} = { 'contrib' => -10, 'non-free' => -20 };
1816 $priomap->{'notes'} = { 'uncompiled' => 20, 'out-of-date' => 40, 'partial' => 40 };
1817 $priomap->{'waitingdays'} = { 'min' => 0, 'max' => 6, scale => 2 };
1819 $pkg->{'calprio'} = 0;
1820 foreach my $k (keys %$priomap) {
1821 $pkg->{'calprio'} += $priomap->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{$k}{$pkg->{$k}};
1824 my $wd = $pkg->{'waiting_days'};
1825 $wd = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $wd < $priomap->{'waitingdays'}->{'min'};
1826 $wd = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $wd > $priomap->{'waitingdays'}->{'max'};
1827 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1828 $pkg->{'calprio'} += $wd * $scale;
1830 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1831 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1839 my( $name, $pkg, @list );
1844 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
1845 foreach $name (keys %$db) {
1846 next if $name =~ /^_/;
1847 push @list, $db->{$name};
1850 foreach $pkg (sort sort_list_func @list) {
1851 print "$pkg->{'section'}/$pkg->{'package'}_$pkg->{'version'}";
1852 print ": $pkg->{'state'}"
1854 print " by $pkg->{'builder'}"
1855 if $pkg->{'state'} ne "Needs-Build" && $pkg->{'builder'};
1856 print " [$pkg->{'priority'}:$pkg->{'notes'}";
1857 print ":PREV-FAILED"
1858 if $pkg->{'previous_state'} =~ /^Failed/;
1859 print ":bp{" . $pkg->{'buildpri'} . "}"
1860 if defined $pkg->{'buildpri'};
1861 print ":binNMU{" . $pkg->{'binary_nmu_version'} . "}"
1862 if defined $pkg->{'binary_nmu_version'};
1864 print " Reasons for failing:\n",
1866 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
1868 join("\n ",split("\n",$pkg->{'failed'})), "\n"
1869 if $pkg->{'state'} =~ /^Failed/;
1870 print " Dependencies: $pkg->{'depends'}\n"
1871 if $pkg->{'state'} eq "Dep-Wait";
1872 print " Reasons for BD-Uninstallable:\n ",
1873 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
1874 if $pkg->{'state'} eq "BD-Uninstallable";
1875 print " Previous state was $pkg->{'previous_state'} until ",
1876 "$pkg->{'state_change'}\n"
1877 if $verbose && $pkg->{'previous_state'};
1878 print " No previous state recorded\n"
1879 if $verbose && !$pkg->{'previous_state'};
1880 print " Previous failing reasons:\n ",
1881 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
1882 if $verbose && $pkg->{'old_failed'};
1884 $scnt{$pkg->{'state'}}++ if $state eq "all";
1886 if ($state eq "all") {
1887 foreach (sort keys %scnt) {
1888 print "Total $scnt{$_} package(s) in state $_.\n";
1891 print "Total $cnt package(s)\n";
1896 my( $name, $pkg, $key, $dist );
1897 my @firstkeys = qw(package version builder state section priority
1898 installed_version previous_state state_change);
1899 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
1901 foreach $name (@_) {
1902 $name =~ s/_.*$//; # strip version
1903 foreach $dist (@dists) {
1904 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1906 $pkg = get_readonly_source_info($name);
1907 if (!defined( $pkg )) {
1908 print "$pname: not registered\n";
1911 $pkg = calculate_prio($pkg);
1914 foreach $key (@firstkeys) {
1915 next if !defined $pkg->{$key};
1916 my $val = $pkg->{$key};
1918 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1920 my $print_key = $key;
1921 $print_key = 'Package' if ($key eq 'package');
1922 $print_key = 'Version' if ($key eq 'version');
1923 $print_key = 'Builder' if ($key eq 'builder');
1924 $print_key = 'State' if ($key eq 'state');
1925 $print_key = 'Section' if ($key eq 'section');
1926 $print_key = 'Priority' if ($key eq 'priority');
1927 $print_key = 'Installed-Version' if ($key eq 'installed_version');
1928 $print_key = 'Previous-State' if ($key eq 'previous_state');
1929 $print_key = 'State-Change' if ($key eq 'state_change');
1930 printf " %-20s: %s\n", $print_key, $val;
1932 foreach $key (sort keys %$pkg) {
1933 next if isin( $key, @firstkeys );
1934 my $val = $pkg->{$key};
1935 next if !defined($val);
1937 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1939 my $print_key = $key;
1940 $print_key = 'BD-Problem' if ($key eq 'bd_problem');
1941 $print_key = 'Binary-NMU-Changelog' if ($key eq 'binary_nmu_changelog');
1942 $print_key = 'Binary-NMU-Version' if ($key eq 'binary_nmu_version');
1943 $print_key = 'BuildPri' if ($key eq 'buildpri');
1944 $print_key = 'Depends' if ($key eq 'depends');
1945 $print_key = 'Failed' if ($key eq 'failed');
1946 $print_key = 'Failed-Category' if ($key eq 'failed_category');
1947 $print_key = 'Notes' if ($key eq 'notes');
1948 $print_key = 'Distribution' if ($key eq 'distribution');
1949 $print_key = 'Old-Failed' if ($key eq 'old_failed');
1950 $print_key = 'PermBuildPri' if ($key eq 'permbuildpri');
1951 $print_key = 'Rel' if ($key eq 'rel');
1952 $print_key = 'CalculatedPri' if ($key eq 'calprio');
1953 $print_key = 'Waiting-Days' if ($key eq 'waiting_days');
1954 printf " %-20s: %s\n", $print_key, $val;
1960 sub forget_packages {
1961 my( $name, $pkg, $key, $data );
1963 foreach $name (@_) {
1964 $name =~ s/_.*$//; # strip version
1965 $pkg = get_source_info($name);
1966 if (!defined( $pkg )) {
1967 print "$name: not registered\n";
1972 foreach $key (sort keys %$pkg) {
1973 my $val = $pkg->{$key};
1976 $data .= sprintf " %-20s: %s\n", $key, $val;
1978 send_mail( $conf::db_maint,
1979 "$name deleted from DB " . table_name() . " " . $distribution,
1980 "The package '$name' has been deleted from the database ".
1982 "Data registered about the deleted package:\n".
1983 "$data\n" ) if $conf::db_maint;
1984 change_state( \$pkg, 'deleted' );
1985 log_ta( $pkg, "--forget" );
1986 del_source_info($name);
1987 print "$name: deleted from database\n" if $verbose;
1992 $dbh->do("DELETE from " . user_table_name() .
1993 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
1999 print "Reading ASCII database from $file..." if $verbose >= 1;
2000 open( F, "<$file" ) or
2001 die "Can't open database $file: $!\n";
2003 local($/) = ""; # read in paragraph mode
2005 my( %thispkg, $name );
2007 s/\n[ \t]+/\376\377/g; # fix continuation lines
2008 s/\376\377\s*\376\377/\376\377/og;
2010 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2011 my ($key, $val) = ($1, $2);
2013 $key =~ tr/A-Z/a-z/;
2014 $val =~ s/\376\377/\n/g;
2015 $thispkg{$key} = $val;
2017 check_entry( \%thispkg );
2019 if (exists($thispkg{'package'})) {
2020 update_source_info(\%thispkg);
2022 elsif(exists($thispkg{'user'})) {
2023 # user in import, username in database.
2024 $dbh->do('INSERT INTO ' . user_table_name() .
2025 ' (username, distribution, last_seen)' .
2026 ' values (?, ?, ?)',
2027 undef, $thispkg{'user'}, $distribution,
2028 $thispkg{'last_seen'})
2029 or die $dbh->errstr;
2033 print "done\n" if $verbose >= 1;
2040 return if $op_mode eq "manual-edit"; # no checks then
2042 # check for required fields
2043 if (exists $pkg->{'user'}) {
2046 if (!exists $pkg->{'package'}) {
2047 print STDERR "Bad entry: ",
2048 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2049 die "Database entry lacks package or username field\n";
2051 # if no State: field, generate one (for old db compat)
2052 if (!exists($pkg->{'state'})) {
2054 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2056 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2057 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2060 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2061 if !isin( $pkg->{'state'},
2062 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2063 Failed Failed-Removed Not-For-Us BD-Uninstallable
2069 my($name,$pkg,$key);
2071 print "Writing ASCII database to $file..." if $verbose >= 1;
2072 open( F, ">$file" ) or
2073 die "Can't open export $file: $!\n";
2075 my $db = get_all_source_info();
2076 foreach $name (keys %$db) {
2077 next if $name =~ /^_/;
2078 my $pkg = $db->{$name};
2079 foreach $key (keys %{$pkg}) {
2080 my $val = $pkg->{$key};
2081 next if !defined($val);
2084 $val =~ s/^ +$/ ./mg;
2085 print F "$key: $val\n";
2090 print "done\n" if $verbose >= 1;
2096 my $newstate = shift;
2097 my $state = \$pkg->{'state'};
2099 return if defined($$state) and $$state eq $newstate;
2100 $pkg->{'previous_state'} = $$state if defined($$state);
2101 $pkg->{'state_change'} = $curr_date;
2103 if (defined($$state) and $$state eq 'Failed') {
2104 $pkg->{'old_failed'} =
2105 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2106 $pkg->{'failed'} . "\n" .
2107 $pkg->{'old_failed'};
2108 delete $pkg->{'failed'};
2109 delete $pkg->{'failed_category'};
2111 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2112 delete $pkg->{'bd_problem'};
2114 $$state = $newstate;
2120 my $dist = $distribution;
2124 $prevstate = $pkg->{'previous_state'};
2125 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2126 "changed from $prevstate to $pkg->{'state'} ".
2127 "by $real_user as $user";
2129 $dbh->do('INSERT INTO ' . transactions_table_name() .
2130 ' (package, distribution, version, action, ' .
2131 ' prevstate, state, real_user, set_user, time) ' .
2132 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2133 undef, $pkg->{'package'}, $distribution,
2134 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2135 $real_user, $user, 'now()') or die $dbh->errstr;
2137 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2138 $str .= " (with --override)"
2140 $mail_logs .= "$str\n";
2147 my $subject = shift;
2150 my $from = $conf::db_maint;
2151 my $domain = $conf::buildd_domain;
2153 $from .= "\@$domain" if $from !~ /\@/;
2155 $to .= '@' . $domain if $to !~ /\@/;
2156 $text =~ s/^\.$/../mg;
2157 local $SIG{'PIPE'} = 'IGNORE';
2158 open( PIPE, "| $conf::mailprog -oem $to" )
2159 or die "Can't open pipe to $conf::mailprog: $!\n";
2161 print PIPE "From: $from\n";
2162 print PIPE "Subject: $subject\n\n";
2163 print PIPE "$text\n";
2167 # for parsing input to dep-wait
2173 foreach (split( /\s*,\s*/, $deps )) {
2175 # verification requires > starting prompts, no | crap
2176 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2181 my @alts = split( /\s*\|\s*/, $_ );
2182 # Anything with an | is ignored, as it can be configured on a
2183 # per-buildd basis what will be installed
2184 next if $#alts != 0;
2187 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2188 warn( "parse_deplist: bad dependency $_\n" );
2191 my($dep, $rel, $relv) = ($1, $3, $4);
2192 $rel = ">>" if defined($rel) and $rel eq ">";
2193 $result{$dep}->{'package'} = $dep;
2194 if ($rel && $relv) {
2195 $result{$dep}->{'rel'} = $rel;
2196 $result{$dep}->{'version'} = $relv;
2199 return 1 if $verify;
2207 foreach $key (keys %$list) {
2208 $result .= ", " if $result;
2210 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2211 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2216 sub call_edos_depcheck {
2217 my $packagesfile = shift;
2221 return if defined ($conf::distributions{$distribution}{noadw});
2223 # We need to check all of needs-build, as any new upload could make
2224 # something in needs-build have uninstallable deps
2225 # We also check everything in bd-uninstallable, as any new upload could
2226 # make that work again
2227 my %interesting_packages;
2228 my $db = get_all_source_info();
2229 foreach $key (keys %$db) {
2230 my $pkg = $db->{$key};
2231 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/)) {
2232 $interesting_packages{$key} = undef;
2236 #print "I would look at these sources with edos-depcheck:\n";
2237 #print join " ", keys %interesting_packages,"\n";
2239 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-";
2241 for( $i = 0;; ++$i ) {
2242 $tmpfile = $tmpfile_pattern . $i;
2243 last if ! -e $tmpfile;
2246 open SOURCES, '>', $tmpfile or die "Could not open temporary file $tmpfile\n";
2247 for my $key (keys %interesting_packages) {
2248 my $pkg = $db->{$key};
2249 print SOURCES "Package: $key\n";
2250 print SOURCES "Version: $pkg->{'version'}\n";
2251 print SOURCES "Build-Depends: $srcs->{$key}{'dep'}\n" if $srcs->{$key}{'dep'};
2252 print SOURCES "Build-Conflicts: $srcs->{$key}{'conf'}\n" if $srcs->{$key}{'conf'};
2253 print SOURCES "Architecture: all\n";
2258 if (open(EDOS,"-|","wb-edos-builddebcheck", "-a", $arch, $packagesfile, $tmpfile))
2260 local($/) = ""; # read in paragraph mode
2262 my( $key, $reason ) ;
2264 /^Package:\s*(\S+)$/mi and $key = $1;
2265 /^Failed-Why:(([^\n]|\n ([^\n]|\.))*)$/msi and $reason = $1;
2266 $reason =~ s/^\s*//mg;
2267 $reason ||= 'No reason given by edos-debcheck';
2269 if (exists $interesting_packages{$key}) {
2270 $interesting_packages{$key} = $reason;
2272 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2277 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2278 "all packages have installable build-dependencies."
2283 for my $key (keys %interesting_packages) {
2284 my $pkg = $db->{$key};
2286 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2287 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2288 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2290 if (defined $interesting_packages{$key}) {
2291 change_state( \$pkg, 'BD-Uninstallable' );
2292 $pkg->{'bd_problem'} = $interesting_packages{$key};
2294 change_state( \$pkg, 'Needs-Build' );
2297 if ($problemchange) {
2298 if (defined $interesting_packages{$key}) {
2299 $pkg->{'bd_problem'} = $interesting_packages{$key};
2303 log_ta( $pkg, "--merge-all" );
2304 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} to $pkg->{'state'}\n" if $verbose;
2306 if ($change || $problemchange) {
2307 update_source_info($pkg);
2314 ($prgname = $0) =~ s,^.*/,,;
2316 Usage: $prgname <options...> <package_version...>
2318 -v, --verbose: Verbose execution.
2319 -A arch: Architecture this operation is for.
2320 --take: Take package for building [default operation]
2321 -f, --failed: Record in database that a build failed due to
2322 deficiencies in the package (that aren't fixable without a new
2324 -u, --uploaded: Record in the database that the packages build
2325 correctly and were uploaded.
2326 -n, --no-build: Record in the database that the packages aren't
2327 desired for this architecture and shouldn't appear in listings even
2328 if they're out of date.
2329 --dep-wait: Record in the database that the packages are waiting
2330 for some source dependencies to become available
2331 --binNMU num: Schedule a re-build of the package with unchanged source, but
2332 a new version number (source-version + "+b<num>")
2333 --give-back: Mark a package as ready to build that is in state Building,
2334 Built or Build-Attempted. To give back a package in state Failed, use
2335 --override. This command will actually put the package in state
2336 BD-Uninstallable, until the installability of its Build-Dependencies
2337 were verified. This happens at each call of --merge-all, usually
2339 --merge-quinn: Merge quinn-diff output into database.
2340 --merge-packages: Merge Packages files into database.
2341 --pretend-avail: Pretend that given packages are available now and give
2342 free packages waiting for them
2343 -i SRC_PKG, --info SRC_PKG: Show information for source package
2344 -l STATE, --list=STATE: List all packages in state STATE; can be
2345 combined with -U to restrict to a specific user; STATE can
2347 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2348 source dependency list
2349 (used with -f, --dep-wait, and --binNMU)
2350 -o, --override: Override another user's lock on a package, i.e.
2351 take it over; a notice mail will be sent to the other user
2352 -U USER, --user=USER: select user name for which listings should
2353 apply, if not given all users are listed.
2354 if -l is missing, set user name to be entered in db; usually
2355 automatically choosen
2356 --import FILE: Import database from a ASCII file FILE
2357 --export FILE: Export database to a ASCII file FILE
2359 The remaining arguments (depending on operation) usually start with
2360 "name_version", the trailer is ignored. This allows to pass the names
2361 of .dsc files, for which file name completion can be used.
2362 --merge-packages and --merge-quinn take Package/quin--diff file names
2363 on the command line or read stdin. --list needs nothing more on the
2364 command line. --info takes source package names (without version).
2369 sub pkg_version_eq {
2371 my $version = shift;
2374 if (defined $pkg->{'binary_nmu_version'}) and
2375 version_compare(binNMU_version($pkg->{'version'},
2376 $pkg->{'binary_nmu_version'}),'=', $version);
2377 return version_compare( $pkg->{'version'}, "=", $version );
2381 return '"' . $arch . $schema_suffix . '".packages';
2384 sub user_table_name {
2385 return '"' . $arch . $schema_suffix . '".users';
2388 sub transactions_table_name {
2389 return '"' . $arch . $schema_suffix . '".transactions';
2392 sub get_readonly_source_info {
2394 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2395 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as waiting_days FROM ' .
2396 table_name() . ' WHERE package = ? AND distribution = ?',
2397 undef, $name, $distribution);
2401 sub get_source_info {
2403 my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' .
2404 table_name() . ' WHERE package = ? AND distribution = ?' .
2406 undef, $name, $distribution);
2410 sub get_all_source_info {
2413 my $q = 'SELECT * FROM ' . table_name()
2414 . ' WHERE distribution = ? ';
2415 my @args = ($distribution);
2416 if ($options{state} && uc($options{state}) ne "ALL") {
2417 $q .= ' AND upper(state) = ? ';
2418 push @args, uc($options{state});
2421 if ($options{user}) {
2422 #this basically means "this user, or no user at all":
2423 $q .= ' AND (builder = ? OR upper(state) = ?)';
2424 push @args, $options{user};
2425 push @args, "NEEDS-BUILD";
2428 if ($options{category}) {
2429 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2430 push @args, $options{category};
2431 push @args, "FAILED";
2434 if ($options{list_min_age} > 0) {
2435 $q .= ' AND age(state_change::timestamp) > ? ';
2436 push @args, $options{list_min_age} . " days";
2439 if ($options{list_min_age} < 0) {
2440 $q .= ' AND age(state_change::timestamp) < ? ';
2441 push @args, -$options{list_min_age} . " days";
2444 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2448 sub update_source_info {
2451 my $pkg2 = get_source_info($pkg->{'package'});
2452 if (! defined $pkg2)
2454 add_source_info($pkg);
2457 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2462 'installed_version = ?, ' .
2463 'previous_state = ?, ' .
2464 'state_change = ?, ' .
2468 'old_failed = ?, ' .
2469 'binary_nmu_version = ?, ' .
2470 'binary_nmu_changelog = ?, ' .
2471 'failed_category = ?, ' .
2472 'permbuildpri = ?, ' .
2477 'WHERE package = ? AND distribution = ?',
2483 $pkg->{'installed_version'},
2484 $pkg->{'previous_state'},
2485 $pkg->{'state_change'},
2489 $pkg->{'old_failed'},
2490 $pkg->{'binary_nmu_version'},
2491 $pkg->{'binary_nmu_changelog'},
2492 $pkg->{'failed_category'},
2493 $pkg->{'permbuildpri'},
2497 $pkg->{'bd_problem'},
2499 $distribution) or die $dbh->errstr;
2502 sub add_source_info {
2504 $dbh->do('INSERT INTO ' . table_name() .
2505 ' (package, distribution) values (?, ?)',
2506 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2509 sub del_source_info {
2511 $dbh->do('DELETE FROM ' . table_name() .
2512 ' WHERE package = ? AND distribution = ?',
2513 undef, $name, $distribution) or die $dbh->errstr;
2518 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2519 user_table_name() . ' WHERE username = ? AND distribution = ?',
2520 undef, $name, $distribution);
2524 sub update_user_info {
2526 $dbh->do('UPDATE ' . user_table_name() .
2527 ' SET last_seen = now() WHERE username = ?' .
2528 ' AND distribution = ?',
2529 undef, $user, $distribution)
2530 or die $dbh->errstr;
2536 $dbh->do('INSERT INTO ' . user_table_name() .
2537 ' (username, distribution, last_seen)' .
2538 ' values (?, ?, now())',
2539 undef, $user, $distribution)
2540 or die $dbh->errstr;
2545 $dbh->do('LOCK TABLE ' . table_name() .
2546 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;