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>
6 # Copyright (C) 2010 Andreas Barth <aba@not.so.argh.org>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 $basedir ||= "/var/lib/debbuild";
26 $dbbase ||= "build-db";
27 $transactlog ||= "transactions.log";
28 $mailprog ||= "/usr/sbin/sendmail";
29 require "/org/wanna-build/etc/wanna-build.conf";
30 die "$conf::basedir is not a directory\n" if ! -d $conf::basedir;
31 die "dbbase is empty\n" if ! $dbbase;
32 die "transactlog is empty\n" if ! $transactlog;
33 die "mailprog binary $conf::mailprog does not exist or isn't executable\n"
34 if !-x $conf::mailprog;
42 use lib '/org/wanna-build/lib';
47 use Hash::Merge qw ( merge );
50 use List::Util qw[max];
51 use Dpkg::Version qw(vercmp); # TODO: change this for running with squeeze dpkg
52 use Dpkg::Deps; # TODO: same
54 our ($verbose, $mail_logs, $list_order, $list_state,
55 $curr_date, $op_mode, $user, $real_user, $distribution,
56 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
58 $info_all_dists, $arch,
59 $category, %catval, %short_category,
60 $short_date, $list_min_age, $dbbase, @curr_time,
61 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
62 $printformat, $ownprintformat, $privmode, $extra_depends, $extra_conflicts,
63 %distributions, %distribution_aliases
65 our $Pas = '/org/buildd.debian.org/etc/packages-arch-specific/Packages-arch-specific';
67 our $simulate_edos = 0;
68 our $api = undef; # allow buildds to specify an different api
69 our $recorduser = undef;
72 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
77 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
78 $short_date = strftime("%m/%d/%y",@curr_time);
81 # map program invocation names to operation modes
82 my %prognames = ( "uploaded-build" => "set-uploaded",
83 "failed-build" => "set-failed",
84 "no-build" => "set-not-for-us",
85 "give-back-build" => "set-needs-build",
86 "dep-wait-build" => "set-dep-wait",
87 "forget-build" => "forget",
88 "build-info" => "info" );
90 %short_category = ( u => "uploaded-fixed-pkg",
97 c => "compiler-error",
101 ($progname = $0) =~ s,.*/,,;
102 if ($prognames{$progname}) {
103 $op_mode = $prognames{$progname};
105 elsif ($progname =~ /^list-(.*)$/) {
107 $list_state = ($1 eq "all") ? "" : $1;
112 simulate => { flag => \$simulate }, # this is not supported by all operations (yet)!
113 "simulate-edos" => { flag => \$simulate_edos },
114 "simulate-all" => { code => sub { $simulate = 1; $simulate_edos = 1; } },
115 api => { arg => \$api, code => sub {
116 # official apis are numeric
117 die "$api isn't numeric" unless int($api) eq $api;
118 die "$api too large" unless $api <= 1;
120 verbose => { short => "v", flag => \$verbose },
121 override => { short => "o", flag => \$opt_override },
122 "create-db" => { flag => \$opt_create_db },
123 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
124 # TODO: remove after buildds no longer pass to wanna-build
125 "no-propagation" => { short => "N" },
126 "no-down-propagation" => { short => "D" },
128 take => { mode => "set-building" },
129 failed => { short => "f", mode => "set-failed" },
130 uploaded => { short => "u", mode => "set-uploaded" },
131 "no-build" => { short => "n", mode => "set-not-for-us" },
132 built => { mode => "set-built" },
133 attempted => { mode => "set-attempted" },
134 "give-back" => { mode => "set-needs-build" },
135 "dep-wait" => { mode => "set-dep-wait" },
136 forget => { mode => "forget" },
137 'forget-user' => { mode => 'forget-user' },
138 update => { mode => "set-update" },
139 #"merge-quinn" => { mode => "merge-quinn" },
140 #"merge-partial-quinn" => { mode => "merge-partial-quinn" },
141 #"merge-packages" => { mode => "merge-packages" },
142 #"merge-sources" => { mode => "merge-sources" },
143 "pretend-avail" => { short => "p", mode => "pretend-avail" },
144 #"merge-all" => { mode => "merge-all" },
145 #"merge-all-secondary" => { mode => "merge-all-secondary" },
146 "merge-v3" => { mode => "merge-v3" },
147 info => { short => "i", mode => "info" },
148 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
149 code => sub { die "Invalid binNMU version: $binNMUver\n"
150 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
151 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
152 code => sub { die "Invalid build priority: $build_priority\n"
153 if $build_priority !~ /^-?[\d]+$/; } },
154 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
155 code => sub { die "Invalid build priority: $build_priority\n"
156 if $build_priority !~ /^-?[\d]+$/; } },
158 { short => "l", mode => "list", arg => \$list_state,
160 die "Unknown state to list: $list_state\n"
161 if !isin( $list_state, qw(needs-build building uploaded
162 built build-attempted failed installed dep-wait
163 not-for-us all failed-removed
164 install-wait reupload-wait bd-uninstallable));} },
167 { short => "d", arg => \$distribution,
169 if ($distribution eq "a" || $distribution eq "all") {
174 $distribution = "oldstable" if $distribution eq "o";
175 $distribution = "stable" if $distribution eq "s";
176 $distribution = "testing" if $distribution eq "t";
177 $distribution = "unstable" if $distribution eq "u";
181 { short => "O", arg => \$list_order,
183 die "Bad ordering character\n"
184 if $list_order !~ /^[PSpsncbCWT]+$/;
186 message => { short => "m", arg => \$fail_reason },
187 # database is deprecated, use arch instead.
188 database => { short => "b", arg => \$conf::dbbase },
189 arch => { short => "A", arg => \$arch },
190 user => { short => "U", arg => \$user },
191 category => { short => "c", arg => \$category,
193 $category = $short_category{$category}
194 if exists $short_category{$category};
195 die "Unknown category: $category\n"
196 if !isin( $category, values %short_category );
198 "min-age" => { short => "a", arg => \$list_min_age,
200 die "Argument of --min-age must be a non-zero number\n"
201 if $list_min_age == 0;
203 "max-age" => { arg => \$list_min_age,
205 die "Argument of --max-age must be a non-zero number\n"
206 if $list_min_age == 0;
209 "format" => { arg => \$printformat },
210 "own-format" => { arg => \$ownprintformat },
211 "Pas" => { arg => \$Pas },
212 "extra-depends"=> { arg => \$extra_depends },
213 "extra-conflicts"=> { arg => \$extra_conflicts },
215 export => { arg => \$export_to, mode => "export" },
216 import => { arg => \$import_from, mode => "import" },
217 "manual-edit" => { mode => "manual-edit" },
218 "distribution-architectures" => { mode => "distribution-architectures" },
219 "distribution-aliases" => { mode => "distribution-aliases" },
222 while( @ARGV && $ARGV[0] =~ /^-/ ) {
225 my($opt, $optname, $arg);
226 if (/^--([^=]+)(=|$)/) {
228 $opt = $options{$optname};
229 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
232 $optname = substr( $_, 1, 1 );
233 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
234 $arg = $1 if /^-$optname(.+)$/;
237 warn "Unknown option: --$1\n";
242 die "$optname option missing argument\n" if !@ARGV;
245 ${$opt->{arg}} = $arg;
247 elsif (defined $arg) {
248 die "Option $optname takes no argument\n";
252 die "Conflicting operation modes\n" if $op_mode;
253 $op_mode = $opt->{mode};
268 $dbh->disconnect or warn $dbh->errstr;
272 if ($distribution eq 'any-priv') {
274 $distribution = 'any';
276 if ($distribution eq 'any-unpriv') {
278 $distribution = 'any';
281 my $schema_suffix = '';
282 $recorduser //= (not -t and $user =~ /^buildd_/);
283 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !$recorduser && !($privmode eq 'yes')) {
284 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
285 die "FATAL: Cannot open database: $DBI::errstr\n";
286 $schema_suffix = '_public';
290 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
291 die "FATAL: Cannot open database: $DBI::errstr\n";
294 # TODO: This shouldn't be needed, file a bug.
295 $dbh->{pg_server_prepare} = 0;
297 $dbh->begin_work or die $dbh->errstr;
299 my $q = 'SELECT distribution, public, auto_dep_wait, build_dep_resolver, archive FROM distributions';
300 my $rows = $dbh->selectall_hashref($q, 'distribution');
301 foreach my $name (keys %$rows) {
302 $distributions{$name} = {};
303 $distributions{$name}->{'noadw'} = 1 if !($rows->{$name}->{'auto_dep_wait'});
304 $distributions{$name}->{'hidden'} = 1 if !($rows->{$name}->{'public'});
305 $distributions{$name}->{'build_dep_resolver'} = $rows->{$name}->{'build_dep_resolver'} if $rows->{$name}->{'build_dep_resolver'};
306 $distributions{$name}->{'archive'} = $rows->{$name}->{'archive'} if $rows->{$name}->{'archive'};
309 $q = 'SELECT alias, distribution FROM distribution_aliases';
310 $rows = $dbh->selectall_hashref($q, 'alias');
311 foreach my $name (keys %$rows) {
312 $distribution_aliases{$name} = $rows->{$name}->{'distribution'};
314 $distribution = $distribution_aliases{$distribution} if (isin($distribution, keys %distribution_aliases));
316 $op_mode = $category ? "set-failed" : "set-building"
317 if !$op_mode; # default operation
318 $distribution ||= "sid";
319 undef $distribution if $distribution eq 'any';
321 my @dists = split(/[, ]+/, $distribution);
322 foreach my $dist (@dists) {
323 die "Bad distribution '$distribution'\n"
324 if !isin($dist, keys %distributions);
327 if (!isin ( $op_mode, qw(list) ) && ( !$distribution || $distribution =~ /[ ,]/)) {
328 die "multiple distributions are only allowed for list";
331 # If they didn't specify an arch, try to get it from database name which
332 # is in the form of $arch/build-db
333 # This is for backwards compatibity with older versions that didn't
334 # specify the arch yet.
335 $conf::dbbase =~ m#^([^/]+)#;
338 # TODO: Check that it's an known arch (for that dist), and give
342 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
343 $version =~ s/(^\$| \$ .*$)//g;
344 print "wanna-build $version for $distribution on $arch\n";
347 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
348 merge-packages manual-edit
349 merge-sources distribution-architectures
350 distribution-aliases))) {
351 warn "No packages given.\n";
355 $real_user = (getpwuid($<))[0];
356 die "Can't determine your user name\n"
357 if $op_mode ne "list" && !$user &&
358 !($user = $real_user);
361 if ($op_mode eq "set-failed" && !$category) {
362 print "Enter reason for failing (end with '.' alone on ".
367 last if $line eq ".\n";
368 $fail_reason .= $line;
370 chomp( $fail_reason );
371 } elsif ($op_mode eq "set-dep-wait") {
372 print "Enter dependencies (one line):\n";
374 while( !$line && !eof(STDIN) ) {
375 chomp( $line = <STDIN> );
377 die "No dependencies given\n" if !$line;
378 $fail_reason = $line;
379 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
380 print "Enter changelog entry (one line):\n";
382 while( !$line && !eof(STDIN) ) {
383 chomp( $line = <STDIN> );
385 die "No changelog entry given\n" if !$line;
386 $fail_reason = $line;
391 my $yamldir = "/org/wanna-build/etc/yaml";
392 my @files = ('wanna-build.yaml');
393 if ((getpwuid($>))[7]) { push (@files, ((getpwuid($>))[7])."/.wanna-build.yaml"); }
394 if ($user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
395 if ($user) { push ( @files, "$user.yaml"); }
396 foreach my $file (@files) {
397 my $cfile = File::Spec->rel2abs( $file, $yamldir );
398 if ($verbose >= 2) { print "Trying to read $file ($cfile) ...\n"; }
399 next unless -f $cfile;
400 if ($verbose >= 2) { print "Read $file ($cfile) ...\n"; }
401 my $m = YAML::Tiny->read( $cfile )->[0];
402 $yamlmap = merge($m, $yamlmap);
405 die "FATAL: no configuration found\n";
407 $list_order = $yamlmap->{"list-order"}{$list_state} if !$list_order and $list_state;
408 $list_order ||= $yamlmap->{"list-order"}{'default'};
409 $api //= $yamlmap->{"api"};
417 if ($mail_logs && $conf::log_mail) {
418 send_mail( $conf::log_mail,
419 "wanna-build $distribution state changes $curr_date",
420 "State changes at $curr_date for distribution ".
421 "$distribution:\n\n$mail_logs\n" );
429 SWITCH: foreach ($op_mode) {
431 add_packages( $1, @ARGV );
435 list_packages( $list_state );
439 info_packages( @ARGV );
442 /^forget-user/ && do {
443 die "This operation is restricted to admin users\n"
444 if (defined @conf::admin_users and
445 !isin( $real_user, @conf::admin_users));
446 forget_users( @ARGV );
450 forget_packages( @ARGV );
453 /^merge-partial-quinn/ && do {
454 die "This operation is restricted to admin users\n"
455 if (defined @conf::admin_users and
456 !isin( $real_user, @conf::admin_users));
461 /^merge-quinn/ && do {
462 die "This operation is restricted to admin users\n"
463 if (defined @conf::admin_users and
464 !isin( $real_user, @conf::admin_users));
469 /^merge-packages/ && do {
470 die "This operation is restricted to admin users\n"
471 if (defined @conf::admin_users and
472 !isin( $real_user, @conf::admin_users));
477 /^merge-sources/ && do {
478 die "This operation is restricted to admin users\n"
479 if (defined @conf::admin_users and
480 !isin( $real_user, @conf::admin_users));
485 /^pretend-avail/ && do {
486 pretend_avail( @ARGV );
489 /^merge-all$/ && do {
490 die "This operation is restricted to admin users\n"
491 if (defined @conf::admin_users and
492 !isin( $real_user, @conf::admin_users));
495 @ARGV = ( $ARGS[0] );
496 my $pkgs = parse_packages(0);
497 @ARGV = ( $ARGS[1] );
499 @ARGV = ( $ARGS[2] );
500 my $srcs = parse_sources(1);
501 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[0]), 'srcs' => $srcs });
504 /^merge-all-secondary/ && do {
505 die "This operation is restricted to admin users\n"
506 if (defined @conf::admin_users and
507 !isin( $real_user, @conf::admin_users));
508 # This is in case the chroot has multiple unrelated
509 # dist, for instance unstable and experimental.
510 # This is not for stable and proposed-updates.
511 # The second packages file contains a combination
512 # of all Packages files known to the buildd, the
513 # first only for the current dist.
516 @ARGV = ( $ARGS[0] );
517 my $pkgs = parse_packages(0);
518 @ARGV = ( $ARGS[3] );
519 my $pkgs = parse_packages(1);
520 @ARGV = ( $ARGS[1] );
522 @ARGV = ( $ARGS[2] );
523 my $srcs = parse_sources(1);
524 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[3]), 'srcs' => $srcs });
528 die "This operation is restricted to admin users\n"
529 if (defined @conf::admin_users and !isin( $real_user, @conf::admin_users) and !$simulate);
530 # call with installed-packages+ . installed-sources+ [ . available-for-build-packages* [ . consider-as-installed-source* ] ]
531 # in case available-for-build-packages is not specified, installed-packages are used
532 lock_table() unless $simulate;
533 my $replacemap = { '%ARCH%' => $arch, '%SUITE%' => $distribution };
534 map { my $k = $_; grep { $k =~ s,$_,$replacemap->{$_}, } keys %{$replacemap}; $_ = $k; } @ARGV;
535 my @ipkgs = &parse_argv( \@ARGV, '.');
536 my @isrcs = &parse_argv( \@ARGV, '.');
537 my @bpkgs = &parse_argv( \@ARGV, '.');
538 my @psrcs = &parse_argv( \@ARGV, '.');
540 my $srcs = WB::QD::readsourcebins($arch, $Pas, \@isrcs, \@ipkgs);
542 my $psrcs = WB::QD::readsourcebins($arch, $Pas, \@psrcs, []);
543 foreach my $k (keys %$$psrcs) {
544 next if $$srcs->{$k};
545 my $pkg = $$psrcs->{$k};
546 $pkg->{'status'} = 'related';
550 parse_all_v3($$srcs, {'arch' => $arch, 'suite' => $distribution, 'time' => $curr_date});
551 @bpkgs = @ipkgs unless @bpkgs;
552 call_edos_depcheck( {'arch' => $arch, 'pkgs' => \@bpkgs, 'srcs' => $$srcs, 'depwait' => 1 });
556 die "This operation is restricted to admin users\n"
557 if (defined @conf::admin_users and
558 !isin( $real_user, @conf::admin_users));
559 $dbh->do("DELETE from " . table_name() .
560 " WHERE distribution = ?", undef,
564 read_db( $import_from );
568 export_db( $export_to );
571 /^distribution-architectures/ && do {
572 show_distribution_architectures();
575 /^distribution-aliases/ && do {
576 show_distribution_aliases();
580 die "Unexpected operation mode $op_mode\n";
583 my $userinfo = get_user_info($user);
584 if (!defined $userinfo)
586 add_user_info($user);
590 update_user_info($user);
596 my $newstate = shift;
597 my( $package, $name, $version, $ok, $reason );
599 foreach $package (@_) {
600 $package =~ s,^.*/,,; # strip path
601 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
602 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
603 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
604 ($name,$version) = ($1,$2);
607 warn "$package: can't extract package name and version ".
612 if ($op_mode eq "set-building") {
613 add_one_building( $name, $version );
615 elsif ($op_mode eq "set-built") {
616 add_one_built( $name, $version );
618 elsif ($op_mode eq "set-attempted") {
619 add_one_attempted( $name, $version );
621 elsif ($op_mode eq "set-uploaded") {
622 add_one_uploaded( $name, $version );
624 elsif ($op_mode eq "set-failed") {
625 add_one_failed( $name, $version );
627 elsif ($op_mode eq "set-not-for-us") {
628 add_one_notforus( $name, $version );
630 elsif ($op_mode eq "set-needs-build") {
631 add_one_needsbuild( $name, $version );
633 elsif ($op_mode eq "set-dep-wait") {
634 add_one_depwait( $name, $version );
636 elsif ($op_mode eq "set-build-priority") {
637 set_one_buildpri( $name, $version, 'buildpri' );
639 elsif ($op_mode eq "set-permanent-build-priority") {
640 set_one_buildpri( $name, $version, 'permbuildpri' );
642 elsif ($op_mode eq "set-binary-nmu") {
643 set_one_binnmu( $name, $version );
645 elsif ($op_mode eq "set-update") {
646 set_one_update( $name, $version );
651 sub add_one_building {
657 my $pkg = get_source_info($name);
659 if ($pkg->{'state'} eq "Not-For-Us") {
661 $reason = "not suitable for this architecture";
663 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
665 $reason = "not all source dependencies available yet";
667 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
669 $reason = "source dependencies are not installable";
671 elsif ($pkg->{'state'} eq "Uploaded" &&
672 (version_lesseq($version, $pkg->{'version'}))) {
674 $reason = "already uploaded by $pkg->{'builder'}";
675 $reason .= " (in newer version $pkg->{'version'})"
676 if !version_eq($pkg, $version);
678 elsif ($pkg->{'state'} eq "Installed" &&
679 version_less($version,$pkg->{'version'})) {
681 print "$name: Warning: newer version $pkg->{'version'} ".
682 "already installed, but overridden.\n";
686 $reason = "newer version $pkg->{'version'} already in ".
687 "archive; doesn't need rebuilding";
688 print "$name: Note: If the following is due to an epoch ",
689 " change, use --override\n";
692 elsif ($pkg->{'state'} eq "Installed" &&
693 pkg_version_eq($pkg,$version)) {
695 $reason = "is up-to-date in the archive; doesn't need rebuilding";
697 elsif ($pkg->{'state'} eq "Needs-Build" &&
698 version_less($version,$pkg->{'version'})) {
700 print "$name: Warning: newer version $pkg->{'version'} ".
701 "needs building, but overridden.";
705 $reason = "newer version $pkg->{'version'} needs building, ".
709 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
710 if (version_less($pkg->{'version'},$version)) {
711 print "$name: Warning: Older version $pkg->{'version'} ",
712 "is being built by $pkg->{'builder'}\n";
713 if ($pkg->{'builder'} ne $user) {
714 send_mail( $pkg->{'builder'},
715 "package takeover in newer version",
716 "You are building package '$name' in ".
717 "version $version\n".
718 "(as far as I'm informed).\n".
719 "$user now has taken the newer ".
720 "version $version for building.".
721 "You can abort the build if you like.\n" );
726 print "User $pkg->{'builder'} had already ",
727 "taken the following package,\n",
728 "but overriding this as you request:\n";
729 send_mail( $pkg->{'builder'}, "package takeover",
730 "The package '$name' (version $version) that ".
731 "was taken by you\n".
732 "has been taken over by $user\n" );
734 elsif ($pkg->{'builder'} eq $user) {
735 print "$name: Note: already taken by you.\n";
736 print "$name: ok\n" if $verbose;
741 $reason = "already taken by $pkg->{'builder'}";
742 $reason .= " (in newer version $pkg->{'version'})"
743 if !version_eq($pkg->{'version'}, $version);
747 elsif ($pkg->{'state'} =~ /^Failed/ &&
748 pkg_version_eq($pkg, $version)) {
750 print "The following package previously failed ",
751 "(by $pkg->{'builder'})\n",
752 "but overriding this as you request:\n";
753 send_mail( $pkg->{'builder'}, "failed package takeover",
754 "The package '$name' (version $version) that ".
756 "and has failed previously has been taken over ".
758 if $pkg->{'builder'} ne $user;
762 $reason = "build of $version failed previously:\n ";
763 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
764 $reason .= "\nalso the package doesn't need builing"
765 if $pkg->{'state'} eq 'Failed-Removed';
772 if ($pkg->{'binary_nmu_version'}) {
773 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
774 "$pkg->{'binary_nmu_changelog'}\n";
777 print "$name: Warning: Previous version failed!\n"
778 if $pkg->{'previous_state'} =~ /^Failed/ ||
779 $pkg->{'state'} =~ /^Failed/;
781 print "$name: $ok\n" if $verbose;
784 print " - status: ok\n";
785 printf " - pkg-ver: %s_%s\n", $name, $version;
786 print " - binNMU: $pkg->{'binary_nmu_version'}\n" if $pkg->{'binary_nmu_version'};
787 print " - extra-changelog: $pkg->{'binary_nmu_changelog'}\n" if $pkg->{'binary_nmu_changelog'} && $pkg->{'binary_nmu_version'};
788 print " - extra-depends: $pkg->{'extra_depends'}\n" if $pkg->{'extra_depends'};
789 print " - extra-conflicts: $pkg->{'extra_conflicts'}\n" if $pkg->{'extra_conflicts'};
790 print " - archive: $distributions{$distribution}->{'archive'}\n" if $distributions{$distribution}->{'archive'};
791 print " - build_dep_resolver: $distributions{$distribution}->{'build_dep_resolver'}\n" if $distributions{$distribution}->{'build_dep_resolver'};
793 change_state( \$pkg, 'Building' );
794 $pkg->{'package'} = $name;
795 $pkg->{'version'} = $version;
796 $pkg->{'builder'} = $user;
797 log_ta( $pkg, "--take" );
798 update_source_info($pkg);
802 print "$name: NOT OK!\n $reason\n";
804 print "- $name:\n - status: not ok\n - reason: \"$reason\"\n";
809 sub add_one_attempted {
812 my $pkg = get_source_info($name);
814 if (!defined($pkg)) {
815 print "$name: not registered yet.\n";
819 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
820 print "$name: not taken for building (state is $pkg->{'state'}). ",
824 if ($pkg->{'builder'} ne $user) {
825 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
828 elsif ( !pkg_version_eq($pkg, $version) ) {
829 print "$name: version mismatch ".
830 "$(pkg->{'version'} ".
831 "by $pkg->{'builder'})\n";
835 change_state( \$pkg, 'Build-Attempted' );
836 log_ta( $pkg, "--attempted" );
837 update_source_info($pkg);
838 print "$name: registered as uploaded\n" if $verbose;
844 my $pkg = get_source_info($name);
846 if (!defined($pkg)) {
847 print "$name: not registered yet.\n";
851 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
852 print "$name: not taken for building (state is $pkg->{'state'}). ",
856 if ($pkg->{'builder'} ne $user) {
857 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
860 elsif ( !pkg_version_eq($pkg, $version) ) {
861 print "$name: version mismatch ".
862 "$(pkg->{'version'} ".
863 "by $pkg->{'builder'})\n";
866 change_state( \$pkg, 'Built' );
867 log_ta( $pkg, "--built" );
868 update_source_info($pkg);
869 print "$name: registered as built\n" if $verbose;
872 sub add_one_uploaded {
875 my $pkg = get_source_info($name);
877 if (!defined($pkg)) {
878 print "$name: not registered yet.\n";
882 if ($pkg->{'state'} eq "Uploaded" &&
883 pkg_version_eq($pkg,$version)) {
884 print "$name: already uploaded\n";
887 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
888 print "$name: not taken for building (state is $pkg->{'state'}). ",
892 if ($pkg->{'builder'} ne $user) {
893 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
896 # strip epoch -- buildd-uploader used to go based on the filename.
897 # (to remove at some point)
899 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
900 $version =~ s/^\d+://; # for command line use
901 if ($pkg->{'binary_nmu_version'} ) {
902 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
903 if (!version_eq( $nmuver, $version )) {
904 print "$name: version mismatch ($nmuver registered). ",
908 } elsif (!version_eq($pkgver, $version)) {
909 print "$name: version mismatch ($pkg->{'version'} registered). ",
914 change_state( \$pkg, 'Uploaded' );
915 log_ta( $pkg, "--uploaded" );
916 update_source_info($pkg);
917 print "$name: registered as uploaded\n" if $verbose;
924 my $pkg = get_source_info($name);
926 if (!defined($pkg)) {
927 print "$name: not registered yet.\n";
930 $state = $pkg->{'state'};
932 if ($state eq "Not-For-Us") {
933 print "$name: not suitable for this architecture anyway. Skipping.\n";
936 elsif ($state eq "Failed-Removed") {
937 print "$name: failed previously and doesn't need building. Skipping.\n";
940 elsif ($state eq "Installed") {
941 print "$name: Is already installed in archive. Skipping.\n";
944 elsif ($pkg->{'builder'} &&
945 (($user ne $pkg->{'builder'}) &&
946 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
947 print "$name: not taken by you, but by ".
948 "$pkg->{'builder'}. Skipping.\n";
951 elsif ( !pkg_version_eq($pkg, $version) ) {
952 print "$name: version mismatch ".
953 "$(pkg->{'version'} ".
954 "by $pkg->{'builder'})\n";
959 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
961 $cat = $short_category{$cat} if exists $short_category{$cat};
962 if (!isin( $cat, values %short_category )) {
963 print "$name: Warning: unknown category $cat; discarded\n";
966 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
969 if ($state eq "Needs-Build") {
970 print "$name: Warning: not registered for building previously, ".
971 "but processing anyway.\n";
973 elsif ($state eq "Uploaded") {
974 print "$name: Warning: marked as uploaded previously, ".
975 "but processing anyway.\n";
977 elsif ($state eq "Dep-Wait") {
978 print "$name: Warning: marked as waiting for dependencies, ".
979 "but processing anyway.\n";
981 elsif ($state eq "BD-Uninstallable") {
982 print "$name: Warning: marked as having uninstallable build-dependencies, ".
983 "but processing anyway.\n";
985 elsif ($state eq "Failed") {
986 print "$name: already registered as failed; will append new message\n"
988 print "$name: already registered as failed; changing category\n"
992 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
993 defined $pkg->{'failed_category'} &&
994 $pkg->{'failed_category'} ne $cat) {
995 (my $action = $cat) =~ s/-/ /;
996 $fail_reason .= "\n$short_date: $action";
999 change_state( \$pkg, 'Failed' );
1000 $pkg->{'builder'} = $user;
1001 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
1002 $pkg->{'failed'} .= $fail_reason;
1003 $pkg->{'failed_category'} = $cat if $cat;
1004 if (defined $pkg->{'permbuildpri'}) {
1005 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1007 delete $pkg->{'buildpri'};
1009 log_ta( $pkg, "--failed" );
1010 update_source_info($pkg);
1011 print "$name: registered as failed\n" if $verbose;
1014 sub add_one_notforus {
1016 my $version = shift;
1017 my $pkg = get_source_info($name);
1019 if ($pkg->{'state'} eq 'Not-For-Us') {
1020 # reset Not-For-Us state in case it's called twice; this is
1021 # the only way to get a package out of this state...
1022 # There is no really good state in which such packages should
1023 # be put :-( So use Failed for now.
1024 change_state( \$pkg, 'Failed' );
1025 $pkg->{'package'} = $name;
1026 $pkg->{'failed'} = "Was Not-For-Us previously";
1027 delete $pkg->{'builder'};
1028 delete $pkg->{'depends'};
1029 log_ta( $pkg, "--no-build(rev)" );
1030 print "$name: now not unsuitable anymore\n";
1032 send_mail( $conf::notforus_maint,
1033 "$name moved out of Not-For-Us state",
1034 "The package '$name' has been moved out of the Not-For-Us ".
1035 "state by $user.\n".
1036 "It should probably also be removed from ".
1037 "Packages-arch-specific or\n".
1038 "the action was wrong.\n" )
1039 if $conf::notforus_maint;
1042 change_state( \$pkg, 'Not-For-Us' );
1043 $pkg->{'package'} = $name;
1044 delete $pkg->{'builder'};
1045 delete $pkg->{'depends'};
1046 delete $pkg->{'buildpri'};
1047 delete $pkg->{'binary_nmu_version'};
1048 delete $pkg->{'binary_nmu_changelog'};
1049 log_ta( $pkg, "--no-build" );
1050 print "$name: registered as unsuitable\n" if $verbose;
1052 send_mail( $conf::notforus_maint,
1053 "$name set to Not-For-Us",
1054 "The package '$name' has been set to state Not-For-Us ".
1056 "It should probably also be added to ".
1057 "Packages-arch-specific or\n".
1058 "the Not-For-Us state is wrong.\n" )
1059 if $conf::notforus_maint;
1061 update_source_info($pkg);
1064 sub add_one_needsbuild {
1066 my $version = shift;
1068 my $pkg = get_source_info($name);
1070 if (!defined($pkg)) {
1071 print "$name: not registered; can't give back.\n";
1074 $state = $pkg->{'state'};
1076 if ($state eq "BD-Uninstallable") {
1077 if ($opt_override) {
1078 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
1080 change_state( \$pkg, 'Needs-Build' );
1081 delete $pkg->{'builder'};
1082 delete $pkg->{'depends'};
1083 log_ta( $pkg, "--give-back" );
1084 update_source_info($pkg);
1085 print "$name: given back\n" if $verbose;
1089 print "$name: has uninstallable build-dependencies. Skipping\n",
1090 " (use --override to clear dependency list and ",
1091 "give back anyway)\n";
1095 elsif ($state eq "Dep-Wait") {
1096 if ($opt_override) {
1097 print "$name: Forcing source dependency list to be cleared\n";
1100 print "$name: waiting for source dependencies. Skipping\n",
1101 " (use --override to clear dependency list and ",
1102 "give back anyway)\n";
1106 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1107 print "$name: not taken for building (state is $state).";
1108 if ($opt_override) {
1109 print "\n$name: Forcing give-back\n";
1112 print " Skipping.\n";
1116 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
1117 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
1119 print "$name: not taken by you, but by ".
1120 "$pkg->{'builder'}. Skipping.\n";
1123 if (!pkg_version_eq($pkg, $version)) {
1124 print "$name: version mismatch ($pkg->{'version'} registered). ",
1128 if (!defined $distributions{$distribution}{noadw}) {
1129 change_state( \$pkg, 'BD-Uninstallable' );
1130 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1132 change_state( \$pkg, 'Needs-Build' );
1134 $pkg->{'builder'} = undef;
1135 $pkg->{'depends'} = undef;
1136 log_ta( $pkg, "--give-back" );
1137 update_source_info($pkg);
1138 print "$name: given back\n" if $verbose;
1141 sub set_one_binnmu {
1143 my $version = shift;
1144 my $pkg = get_source_info($name);
1147 if (!defined($pkg)) {
1148 print "$name: not registered; can't register for binNMU.\n";
1151 my $db_ver = $pkg->{'version'};
1153 if (!version_eq($db_ver, $version)) {
1154 print "$name: version mismatch ($db_ver registered). ",
1158 $state = $pkg->{'state'};
1160 if (defined $pkg->{'binary_nmu_version'}) {
1161 if ($binNMUver == 0) {
1162 change_state( \$pkg, 'Installed' );
1163 delete $pkg->{'builder'};
1164 delete $pkg->{'depends'};
1165 delete $pkg->{'binary_nmu_version'};
1166 delete $pkg->{'binary_nmu_changelog'};
1167 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1168 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1171 $pkg->{'binary_nmu_version'} = $binNMUver;
1172 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1173 $pkg->{'notes'} = 'out-of-date';
1174 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1175 if (defined $pkg->{'permbuildpri'});
1176 if (defined $distributions{$distribution}{noadw}) {
1177 change_state( \$pkg, 'Installed' );
1179 change_state( \$pkg, 'BD-Uninstallable' );
1182 log_ta( $pkg, "--binNMU" );
1183 update_source_info($pkg);
1185 } elsif ($binNMUver == 0) {
1186 print "${name}_$version: no scheduled binNMU to cancel.\n";
1190 if ($state ne 'Installed') {
1191 print "${name}_$version: not installed; can't register for binNMU.\n";
1195 my $fullver = binNMU_version($version,$binNMUver);
1196 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1198 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1202 if (!defined $distributions{$distribution}{noadw}) {
1203 change_state( \$pkg, 'BD-Uninstallable' );
1204 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1208 change_state( \$pkg, 'Needs-Build' );
1210 delete $pkg->{'builder'};
1211 delete $pkg->{'depends'};
1212 $pkg->{'binary_nmu_version'} = $binNMUver;
1213 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1214 $pkg->{'notes'} = 'out-of-date';
1215 log_ta( $pkg, "--binNMU" );
1216 update_source_info($pkg);
1217 print "${name}: registered for binNMU $fullver\n" if $verbose;
1220 sub set_one_buildpri {
1222 my $version = shift;
1224 my $pkg = get_source_info($name);
1227 if (!defined($pkg)) {
1228 print "$name: not registered; can't set priority.\n";
1231 $state = $pkg->{'state'};
1233 if ($state eq "Not-For-Us") {
1234 print "$name: not suitable for this architecture. Skipping.\n";
1236 } elsif ($state eq "Failed-Removed") {
1237 print "$name: failed previously and doesn't need building. Skipping.\n";
1240 if (!pkg_version_eq($pkg, $version)) {
1241 print "$name: version mismatch ($pkg->{'version'} registered). ",
1245 if ( $build_priority == 0 ) {
1246 delete $pkg->{'buildpri'}
1247 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1248 and $pkg->{'buildpri'} == $pkg->{$key};
1249 delete $pkg->{$key};
1251 $pkg->{'buildpri'} = $build_priority
1252 if $key eq 'permbuildpri';
1253 $pkg->{$key} = $build_priority;
1255 update_source_info($pkg);
1256 print "$name: set to build priority $build_priority\n" if $verbose;
1259 sub add_one_depwait {
1261 my $version = shift;
1263 my $pkg = get_source_info($name);
1265 if (!defined($pkg)) {
1266 print "$name: not registered yet.\n";
1269 $state = $pkg->{'state'};
1271 if ($state eq "Dep-Wait") {
1272 print "$name: merging with previously registered dependencies\n";
1275 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1276 print "$name: Warning: not registered for building previously, ".
1277 "but processing anyway.\n";
1279 elsif ($state eq "Not-For-Us") {
1280 print "$name: not suitable for this architecture anyway. Skipping.\n";
1283 elsif ($state eq "Failed-Removed") {
1284 print "$name: failed previously and doesn't need building. Skipping.\n";
1287 elsif ($state eq "Installed") {
1288 print "$name: Is already installed in archive. Skipping.\n";
1291 elsif ($state eq "Uploaded") {
1292 print "$name: Is already uploaded. Skipping.\n";
1295 elsif ($pkg->{'builder'} &&
1296 $user ne $pkg->{'builder'}) {
1297 print "$name: not taken by you, but by ".
1298 "$pkg->{'builder'}. Skipping.\n";
1301 elsif ( !pkg_version_eq($pkg,$version)) {
1302 print "$name: version mismatch ".
1303 "($pkg->{'version'} ".
1304 "by $pkg->{'builder'})\n";
1307 elsif ($fail_reason =~ /^\s*$/ ||
1308 !parse_deplist( $fail_reason, 1 )) {
1309 print "$name: Bad dependency list\n";
1312 change_state( \$pkg, 'Dep-Wait' );
1313 $pkg->{'builder'} = $user;
1314 if (defined $pkg->{'permbuildpri'}) {
1315 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1317 delete $pkg->{'buildpri'};
1319 my $deplist = parse_deplist( $pkg->{'depends'} );
1320 my $new_deplist = parse_deplist( $fail_reason );
1321 # add new dependencies, maybe overwriting old entries
1322 foreach (keys %$new_deplist) {
1323 $deplist->{$_} = $new_deplist->{$_};
1325 $pkg->{'depends'} = build_deplist($deplist);
1326 log_ta( $pkg, "--dep-wait" );
1327 update_source_info($pkg);
1328 print "$name: registered as waiting for dependencies\n" if $verbose;
1331 sub set_one_update {
1333 my $version = shift;
1334 my $pkg = get_source_info($name);
1336 if (!defined($pkg)) {
1337 print "$name: not registered yet.\n";
1340 $pkg->{'version'} =~ s/\+b[0-9]+$//;
1342 log_ta( $pkg, "--update" );
1343 update_source_info($pkg);
1353 my $db = get_all_source_info();
1355 local($/) = ""; # read in paragraph mode
1357 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1359 /^Package:\s*(\S+)$/mi and $name = $1;
1360 /^Version:\s*(\S+)$/mi and $version = $1;
1361 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1362 /^Section:\s*(\S+)$/mi and $section = $1;
1363 /^Priority:\s*(\S+)$/mi and $priority = $1;
1364 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1365 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1366 /^Binary:\s*(.*)$/mi and $binaries = $1;
1368 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1369 $srcver{$name} = $version;
1371 $pkgs{$name}{'ver'} = $version;
1372 $pkgs{$name}{'bin'} = $binaries;
1373 $pkgs{$name}{'dep'} = $builddep;
1374 $pkgs{$name}{'conf'} = $buildconf;
1375 my $pkg = $db->{$name};
1380 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1381 # package is now Arch: all, delete it from db
1382 change_state( \$pkg, 'deleted' );
1383 log_ta( $pkg, "--merge-sources" );
1384 print "$name ($pkg->{'version'}): deleted ".
1385 "from database, because now Arch: all\n"
1387 del_source_info($name);
1388 delete $db->{$name};
1392 # The "Version" should always be the source version --
1393 # not a possible binNMU version number.
1394 $pkg->{'version'} = $version, $change++
1395 if ($pkg->{'state'} eq 'Installed' and
1396 !version_eq( $pkg->{'version'}, $version));
1397 # Always update priority and section, if available
1398 $pkg->{'priority'} = $priority, $change++
1399 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1401 $pkg->{'section'} = $section, $change++
1402 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1404 update_source_info($pkg) if $change;
1407 # Now that we only have the latest source version, build the list
1408 # of binary packages from the Sources point of view
1409 foreach $name (keys %pkgs) {
1410 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1411 $merge_binsrc{$bin} = $name;
1414 # remove installed packages that no longer have source available
1415 # or binaries installed
1416 foreach $name (keys %$db) {
1417 next if $name =~ /^_/;
1418 my $pkg = $db->{$name};
1419 if (not defined($pkgs{$name})) {
1420 change_state( \$pkg, 'deleted' );
1421 log_ta( $pkg, "--merge-sources" );
1422 print "$name ($pkg->{'version'}): ".
1423 "deleted from database, because ".
1424 "not in Sources anymore\n"
1426 del_source_info($name);
1427 delete $db->{$name};
1429 next if !isin( $pkg->{'state'}, qw(Installed) );
1430 if ($full && not defined $merge_srcvers{$name}) {
1431 change_state( \$pkg, 'deleted' );
1432 log_ta( $pkg, "--merge-sources" );
1433 print "$name ($pkg->{'version'}): ".
1434 "deleted from database, because ".
1435 "binaries don't exist anymore\n"
1437 del_source_info($name);
1438 delete $db->{$name};
1439 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1440 print "$name ($pkg->{'version'}): ".
1441 "package is Installed but binaries are from ".
1442 $merge_srcvers{$name}. "\n"
1450 # This function looks through a Packages file and sets the state of
1451 # packages to 'Installed'
1452 sub parse_packages {
1453 my $depwait_only = shift;
1456 my $pkgs = get_all_source_info();
1457 local($/) = ""; # read in paragraph mode
1459 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1461 /^Package:\s*(\S+)$/mi and $name = $1;
1462 /^Version:\s*(\S+)$/mi and $version = $1;
1463 /^Depends:\s*(.*)$/mi and $depends = $1;
1464 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1465 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1466 /^Provides:\s*(.*)$/mi and $provides = $1;
1467 next if !$name || !$version;
1468 next if ($arch ne $architecture and $architecture ne "all");
1469 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1470 version_lesseq( $version, $installed->{$name}{'version'} ));
1471 $installed->{$name}{'version'} = $version;
1472 next if $depwait_only;
1473 $installed->{$name}{'depends'} = $depends;
1474 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1475 undef $installed->{$name}{'Provider'};
1476 $installed->{$name}{'Source'} = $source ? $source : $name;
1478 foreach (split( /\s*,\s*/, $provides )) {
1479 if (not defined ($installed->{$_})) {
1480 $installed->{$_}{'version'} = "";
1481 $installed->{$_}{'Provider'} = $name;
1485 if ( $version =~ /\+b(\d+)$/ ) {
1488 $version = $sourcev if $sourcev;
1489 $binaryv = $version;
1490 $binaryv =~ s/\+b\d+$//;
1491 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1492 $binaryv .= "+b$binnmu" if defined($binnmu);
1494 next if $architecture ne $arch;
1495 $name = $source if $source;
1496 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1497 $merge_srcvers{$name} = $version;
1499 my $pkg = $pkgs->{$name};
1502 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1503 (isin($pkg->{'state'}, qw(Installed)) &&
1504 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1505 print "Skipping $name because State == $pkg->{'state'}\n"
1509 if ($pkg->{'binary_nmu_version'} ) {
1510 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1511 if (version_less( $binaryv, $nmuver )) {
1512 print "Skipping $name ($version) because have newer ".
1513 "version ($nmuver) in db.\n"
1517 } elsif (version_less($version, $pkg->{'version'})) {
1518 print "Skipping $name ($version) because have newer ".
1519 "version ($pkg->{'version'}) in db.\n"
1524 if (!pkg_version_eq($pkg, $version) &&
1525 $pkg->{'state'} ne "Installed") {
1526 warn "Warning: $name: newer version than expected appeared ".
1527 "in archive ($version vs. $pkg->{'version'})\n";
1528 delete $pkg->{'builder'};
1531 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1532 warn "Warning: Package $name was not in uploaded state ".
1533 "before (but in '$pkg->{'state'}').\n";
1534 delete $pkg->{'builder'};
1535 delete $pkg->{'depends'};
1539 $pkg->{'version'} = $version;
1542 change_state( \$pkg, 'Installed' );
1543 $pkg->{'package'} = $name;
1544 $pkg->{'installed_version'} = $binaryv;
1545 if (defined $pkg->{'permbuildpri'}) {
1546 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1548 delete $pkg->{'buildpri'};
1550 $pkg->{'version'} = $version
1551 if version_less( $pkg->{'version'}, $version);
1552 delete $pkg->{'binary_nmu_version'};
1553 delete $pkg->{'binary_nmu_changelog'};
1554 log_ta( $pkg, "--merge-packages" );
1555 update_source_info($pkg);
1556 print "$name ($version) is up-to-date now.\n" if $verbose;
1559 check_dep_wait( "--merge-packages", $installed );
1564 my ($package, $name, $version, $installed);
1566 foreach $package (@_) {
1567 $package =~ s,^.*/,,; # strip path
1568 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1569 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1570 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1571 ($name,$version) = ($1,$2);
1574 warn "$package: can't extract package name and version ".
1578 $installed->{$name}{'version'} = $version;
1581 check_dep_wait( "--pretend-avail", $installed );
1584 sub check_dep_wait {
1586 my $installed = shift;
1588 # check all packages in state Dep-Wait if dependencies are all
1591 my $db = get_all_source_info();
1592 foreach $name (keys %$db) {
1593 next if $name =~ /^_/;
1594 my $pkg = $db->{$name};
1595 next if $pkg->{'state'} ne "Dep-Wait";
1596 my $deps = $pkg->{'depends'};
1598 print "$name: was in state Dep-Wait, but with empty ",
1600 goto make_needs_build;
1602 my $deplist = parse_deplist($deps);
1606 foreach (keys %$deplist) {
1607 if (!exists $installed->{$_} ||
1608 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1609 !version_compare( $installed->{$_}{'version'},
1610 $deplist->{$_}->{'rel'},
1611 $deplist->{$_}->{'version'}))) {
1613 $new_deplist->{$_} = $deplist->{$_};
1616 push( @removed_deps, $_ );
1621 change_state( \$pkg, 'Needs-Build' );
1622 log_ta( $pkg, $action );
1623 delete $pkg->{'builder'};
1624 delete $pkg->{'depends'};
1625 print "$name ($pkg->{'version'}) has all ",
1626 "dependencies available now\n" if $verbose;
1628 update_source_info($pkg);
1630 elsif (@removed_deps) {
1631 $pkg->{'depends'} = build_deplist( $new_deplist );
1632 print "$name ($pkg->{'version'}): some dependencies ",
1633 "(@removed_deps) available now, but not all yet\n"
1635 update_source_info($pkg);
1640 # This function accepts quinn-diff output (either from a file named on
1641 # the command line, or on stdin) and sets the packages named there to
1642 # state 'Needs-Build'.
1643 sub parse_quinn_diff {
1644 my $partial = shift;
1648 my $pkgs = get_all_source_info();
1652 next if !m,^([-\w\d/]*)/ # section
1653 ([-\w\d.+]+)_ # package name
1654 ([\w\d:.~+-]+)\.dsc\s* # version
1655 \[([^:]*): # priority
1656 ([^]]+)\]\s*$,x; # rest of notes
1657 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1658 $quinn_pkgs{$name}++;
1659 $section ||= "unknown";
1660 $priority ||= "unknown";
1661 $priority = "unknown" if $priority eq "-";
1662 $priority = "standard" if ($name eq "debian-installer");
1664 my $pkg = $pkgs->{$name};
1666 # Always update section and priority.
1667 if (defined($pkg)) {
1669 $pkg->{'section'} = $section, $change++ if not defined
1670 $pkg->{'section'} or $section ne "unknown";
1671 $pkg->{'priority'} = $priority, $change++ if not defined
1672 $pkg->{'priority'} or $priority ne "unknown";
1675 if (defined($pkg) &&
1676 $pkg->{'state'} =~ /^Dep-Wait/ &&
1677 version_less( $pkg->{'version'}, $version )) {
1678 change_state( \$pkg, 'Dep-Wait' );
1679 $pkg->{'version'} = $version;
1680 delete $pkg->{'binary_nmu_version'};
1681 delete $pkg->{'binary_nmu_changelog'};
1682 log_ta( $pkg, "--merge-quinn" );
1684 print "$name ($version) still waiting for dependencies.\n"
1687 elsif (defined($pkg) &&
1688 $pkg->{'state'} =~ /-Removed$/ &&
1689 version_eq($pkg->{'version'}, $version)) {
1690 # reinstantiate a package that has been removed earlier
1691 # (probably due to a quinn-diff malfunction...)
1692 my $newstate = $pkg->{'state'};
1693 $newstate =~ s/-Removed$//;
1694 change_state( \$pkg, $newstate );
1695 $pkg->{'version'} = $version;
1696 $pkg->{'notes'} = $notes;
1697 log_ta( $pkg, "--merge-quinn" );
1699 print "$name ($version) reinstantiated to $newstate.\n"
1702 elsif (defined($pkg) &&
1703 $pkg->{'state'} eq "Not-For-Us" &&
1704 version_less( $pkg->{'version'}, $version )) {
1705 # for Not-For-Us packages just update the version etc., but
1707 change_state( \$pkg, "Not-For-Us" );
1708 $pkg->{'package'} = $name;
1709 $pkg->{'version'} = $version;
1710 $pkg->{'notes'} = $notes;
1711 delete $pkg->{'builder'};
1712 log_ta( $pkg, "--merge-quinn" );
1714 print "$name ($version) still Not-For-Us.\n" if $verbose;
1716 elsif (!defined($pkg) ||
1717 $pkg->{'state'} ne "Not-For-Us" &&
1718 (version_less( $pkg->{'version'}, $version ) ||
1719 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1721 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1722 send_mail( $pkg->{'builder'},
1723 "new version of $name (dist=$distribution)",
1724 "As far as I'm informed, you're currently ".
1725 "building the package $name\n".
1726 "in version $pkg->{'version'}.\n\n".
1727 "Now there's a new source version $version. ".
1728 "If you haven't finished\n".
1729 "compiling $name yet, you can stop it to ".
1730 "save some work.\n".
1731 "Just to inform you...\n".
1732 "(This is an automated message)\n" );
1733 print "$name: new version ($version) while building ".
1734 "$pkg->{'version'} -- sending mail ".
1735 "to builder ($pkg->{'builder'})\n"
1738 change_state( \$pkg, 'Needs-Build' );
1739 $pkg->{'package'} = $name;
1740 $pkg->{'version'} = $version;
1741 $pkg->{'section'} = $section;
1742 $pkg->{'priority'} = $priority;
1743 $pkg->{'notes'} = $notes;
1744 delete $pkg->{'builder'};
1745 delete $pkg->{'binary_nmu_version'};
1746 delete $pkg->{'binary_nmu_changelog'};
1747 log_ta( $pkg, "--merge-quinn" );
1750 print "$name ($version) needs rebuilding now.\n" if $verbose;
1752 elsif (defined($pkg) &&
1753 !version_eq( $pkg->{'version'}, $version ) &&
1754 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1755 print "$name: skipping because version in db ".
1756 "($pkg->{'version'}) is >> than ".
1757 "what quinn-diff says ($version) ".
1758 "(state is $pkg->{'state'})\n"
1760 $dubious .= "$pkg->{'state'}: ".
1761 "db ${name}_$pkg->{'version'} >> ".
1762 "quinn $version\n" if !$partial;
1764 elsif ($verbose >= 2) {
1765 if ($pkg->{'state'} eq "Not-For-Us") {
1766 print "Skipping $name because State == ".
1767 "$pkg->{'state'}\n";
1769 elsif (!version_less($pkg->{'version'}, $version)) {
1770 print "Skipping $name because version in db ".
1771 "($pkg->{'version'}) is >= than ".
1772 "what quinn-diff says ($version)\n";
1775 update_source_info($pkg) if $change;
1779 send_mail( $conf::db_maint,
1780 "Dubious versions in " . table_name() . " "
1781 . $distribution . " table",
1782 "The following packages have a newer version in the ".
1783 "wanna-build database\n".
1784 "than what quinn-diff says, and this is strange for ".
1786 "It could be caused by a lame mirror, or the version ".
1787 "in the database\n".
1792 # Now re-check the DB for packages in states Needs-Build, Failed,
1793 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1794 # anymore by quinn-diff.
1797 my $db = get_all_source_info();
1798 foreach $name (keys %$db) {
1799 next if $name =~ /^_/;
1800 my $pkg = $db->{$name};
1801 next if defined $pkg->{'binary_nmu_version'};
1802 next if !isin( $pkg->{'state'},
1803 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1804 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1806 if (!$quinn_pkgs{$name}) {
1807 change_state( \$pkg, $virtual_delete ?
1808 $pkg->{'state'}."-Removed" :
1810 log_ta( $pkg, "--merge-quinn" );
1811 print "$name ($pkg->{'version'}): ".
1812 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1813 "from database, because not in quinn-diff anymore\n"
1815 if ($virtual_delete) {
1816 update_source_info($pkg);
1818 del_source_info($name);
1826 # for sorting priorities and sections
1828 %prioval = ( required => -5,
1836 'debian-installer' => -199,
1857 localizations => -178,
1858 interpreters => -177,
1883 electronics => -152,
1889 foreach my $i (keys %sectval) {
1890 $sectval{"contrib/$i"} = $sectval{$i}+40;
1891 $sectval{"non-free/$i"} = $sectval{$i}+80;
1893 $sectval{'unknown'} = -165;
1895 %catval = ( "none" => -20,
1896 "uploaded-fixed-pkg" => -19,
1897 "fix-expected" => -18,
1898 "reminder-sent" => -17,
1899 "nmu-offered" => -16,
1903 "compiler-error" => -12 );
1906 sub sort_list_func {
1908 'C' => ['<->', sub { return $_[0]->{'calprio'}; }],
1909 'W' => ['<->', sub { return $_[0]->{'state_days'}; }],
1910 'P' => ['<->', sub { return $_[0]->{'buildpri'}; }],
1911 'p' => ['<=>', sub { return $prioval{$_[0]->{'priority'}}; }],
1912 's' => ['<=>', sub { return $sectval{$_[0]->{'section'}}; }],
1913 'n' => ['cmp', sub { return $_[0]->{'package'}; }],
1914 'b' => ['cmp', sub { return $_[0]->{'builder'}; }],
1915 'c' => ['<=>', sub { return ($_[0]->{'notes'} =~ /^(out-of-date|partial)/) ? 0: ($_[0]->{'notes'} =~ /^uncompiled/) ? 2 : 1; }],
1916 'f' => ['<=>', sub { return $catval{ $_[0]->{'failed_category'} ? $_[0]->{'failed_category'}: "none" }; }],
1917 'S' => ['<=>', sub { return $prioval{$_[0]->{'priority'}} > $prioval{'standard'}; }],
1918 'T' => ['<->', sub { return $_[0]->{'state_time'} % 86400;} ], # Fractions of a day
1921 foreach my $letter (split( //, $list_order )) {
1923 $r = &{$map_funcs->{$letter}[1]}($b) <=> &{$map_funcs->{$letter}[1]}($a) if $map_funcs->{$letter}[0] eq '<->';
1924 $r = &{$map_funcs->{$letter}[1]}($a) <=> &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq '<=>';
1925 $r = &{$map_funcs->{$letter}[1]}($a) cmp &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq 'cmp';
1926 return $r if $r != 0;
1931 sub calculate_prio {
1932 my $priomap = $yamlmap->{priority};
1934 my @s=split("/", $pkg->{'section'});
1935 $pkg->{'component'} = $s[0] if $s[1];
1936 $pkg->{'component'} ||= 'main';
1937 $pkg->{'calprio'} = 0;
1938 foreach my $k (keys %{$priomap->{keys}}) {
1939 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1942 my $days = $pkg->{'state_days'};
1943 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1944 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1945 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1946 $pkg->{'calprio'} += $days * $scale;
1948 my $btime = max($pkg->{'anytime'}, $pkg->{'successtime'});
1949 my $bhours = defined($btime) ? int($btime/3600) : ($priomap->{'buildhours'}->{'default'} || 2);
1950 $bhours = $priomap->{'buildhours'}->{'min'} if $priomap->{'buildhours'}->{'min'} and $bhours < $priomap->{'buildhours'}->{'min'};
1951 $bhours = $priomap->{'buildhours'}->{'max'} if $priomap->{'buildhours'}->{'max'} and $bhours > $priomap->{'buildhours'}->{'max'};
1952 $scale = $priomap->{'buildhours'}->{'scale'} || 1;
1953 $pkg->{'calprio'} -= $bhours * $scale;
1955 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1956 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1964 return "" unless $t;
1966 my $min = int($t/60) % 60;
1967 my $hours = int($t / 3600);
1968 return sprintf("%d:%02d:%02d", $hours, $min, $sec) if $hours;
1969 return sprintf("%d:%02d", $min, $sec);
1976 if (ref($_[0]) eq 'CODE') {
1986 return $r unless $t;
1990 if (substr($t,0,1) eq '!') {
1994 return "" unless $r;
1997 return print_format($t, $pkg, $var);
2001 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
2004 my $printfmt = shift;
2008 Within an format string, the following values are allowed (need to be preceded by %).
2009 This can be combined to e.g.
2010 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
2013 c section (e.g. libs or utils)
2014 D in case of BD-Uninstallable the reason for the uninstallability
2016 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
2017 F in case of Failed the fail reason
2019 o time of last successful build (seconds)
2020 O time of last successful build (formated)
2023 q time of last build (seconds)
2024 Q time of last build (formated)
2025 r max time of last (successful) build (seconds)
2026 R max time of last (successful) build (formated)
2028 s Time in this state in full seconds since epoch
2029 t time of state change
2030 T time since state change
2031 u Builder (e.g. buildd_mipsel-rem)
2033 V full Package version (i.e. with +b.., = %v%{+b}B%B
2034 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
2036 %{Text}? print Text in case ? is not empty; ? is never printed
2037 %{!Text}? print Text in case ? is empty; ? is never printed
2038 Text could contain further %. To start with !, use %!
2041 return stringf($printfmt, (
2042 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
2043 'a' => make_fmt( $arch, $pkg, $var),
2044 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
2045 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
2046 'V' => make_fmt( sub { $pkg->{'binary_nmu_version'} ? $pkg->{'version'}."+b".$pkg->{'binary_nmu_version'} : $pkg->{'version'} }, $pkg, $var),
2047 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
2048 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
2049 'X' => make_fmt( sub {
2050 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
2051 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} =~ /^Failed/;
2052 $c .= ":bp{" . $pkg->{'buildpri'} . "}" if defined $pkg->{'buildpri'};
2053 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
2054 $c .= ":calprio{". $pkg->{'calprio'}."}";
2055 $c .= ":days{". $pkg->{'state_days'}."}";
2058 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
2059 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
2060 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
2061 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
2062 return ""; }, $pkg, $var),
2063 'F' => make_fmt( sub { return "" unless $pkg->{'failed'};
2064 my $failed = $pkg->{'failed'};
2065 $failed =~ s/\\/\\\\/g;
2066 return $pkg->{'package'}."#".$arch."-failure\n ".
2067 join("\\0a",split("\n",$failed))."\\0a\n"; }, $pkg, $var),
2068 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
2069 return $pkg->{'package'}."#".$arch."-bd-problem\n".
2070 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
2071 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
2072 'd' => make_fmt( $pkg->{'distribution'}, $pkg, $var),
2073 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
2074 'T' => make_fmt( sub { return seconds2time(time() - floor(str2time($pkg->{'state_change'}))); }, $pkg, $var),
2075 'o' => make_fmt( $pkg->{'successtime'}, $pkg, $var),
2076 'O' => make_fmt( sub { return seconds2time ( $pkg->{'successtime'}); }, $pkg, $var),
2077 'q' => make_fmt( $pkg->{'anytime'}, $pkg, $var),
2078 'Q' => make_fmt( sub { return seconds2time ( $pkg->{'anytime'}); }, $pkg, $var),
2079 'r' => make_fmt( sub { return max($pkg->{'successtime'}, $pkg->{'anytime'}); }, $pkg, $var),
2080 'R' => make_fmt( sub { return seconds2time ( max($pkg->{'successtime'}, $pkg->{'anytime'})); }, $pkg, $var),
2086 my( $name, $pkg, @list );
2091 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
2092 foreach $name (keys %$db) {
2093 next if $name =~ /^_/;
2094 push @list, calculate_prio($db->{$name});
2098 @list = grep { my $i = $_->{'component'}; grep { $i eq $_ } split /[, ]+/, $yamlmap->{"restrict"}{'component'} } @list;
2099 # extra depends / conflicts only from api 1 on
2100 @list = grep { !$_->{'extra_depends'} and !$_->{'extra_conflicts'} } @list if $api < 1 ;
2102 # first adjust ownprintformat, then set printformat accordingly
2103 $printformat ||= $yamlmap->{"format"}{$ownprintformat};
2104 $printformat ||= $yamlmap->{"format"}{"default"}{$state};
2105 $printformat ||= $yamlmap->{"format"}{"default"}{"default"};
2106 undef $printformat if ($ownprintformat eq 'none');
2108 foreach $pkg (sort sort_list_func @list) {
2110 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
2112 $scnt{$pkg->{'state'}}++;
2115 print print_format("%c/%p_%v", $pkg, {});
2116 print print_format(": %S", $pkg, {})
2118 print print_format("%{ by }u%u", $pkg, {})
2119 if $pkg->{'state'} ne "Needs-Build";
2120 print print_format(" [%X]\n", $pkg, {});
2121 print " Reasons for failing:\n",
2123 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
2125 join("\n ",split("\n",$pkg->{'failed'})), "\n"
2126 if $pkg->{'state'} =~ /^Failed/;
2127 print " Dependencies: $pkg->{'depends'}\n"
2128 if $pkg->{'state'} eq "Dep-Wait";
2129 print " Reasons for BD-Uninstallable:\n ",
2130 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
2131 if $pkg->{'state'} eq "BD-Uninstallable";
2132 print " Previous state was $pkg->{'previous_state'}\n"
2133 if $verbose && $pkg->{'previous_state'};
2134 print " No previous state recorded\n"
2135 if $verbose && !$pkg->{'previous_state'};
2136 print " State changed at $pkg->{'state_change'}\n"
2137 if $verbose && $pkg->{'state_change'};
2138 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
2139 if $verbose && $pkg->{'previous_state'};
2140 print " Previous failing reasons:\n ",
2141 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
2142 if $verbose && $pkg->{'old_failed'};
2144 $scnt{$pkg->{'state'}}++ if $state eq "all";
2146 if ($state eq "all" && !$printformat) {
2147 foreach (sort keys %scnt) {
2148 print "Total $scnt{$_} package(s) in state $_.\n";
2151 print "Total $cnt package(s)\n" unless $printformat;
2156 my( $name, $pkg, $key, $dist );
2157 my @firstkeys = qw(package version builder state section priority
2158 installed_version previous_state state_change);
2159 my @dists = $info_all_dists ? keys %distributions : ($distribution);
2160 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
2161 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
2162 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
2163 'state_change' => 'State-Change',
2164 'bd_problem' => 'BD-Problem',
2165 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
2166 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
2167 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
2168 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
2169 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
2170 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days', 'state_time' => 'State-Time',
2171 'successtime' => 'Success-build-time',
2172 'anytime' => 'Build-time',
2173 'extra_depends' => 'Extra-Dependencies',
2174 'extra_conflicts' => 'Extra-Conflicts',
2177 foreach $name (@_) {
2178 $name =~ s/_.*$//; # strip version
2179 foreach $dist (@dists) {
2180 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
2182 $pkg = get_readonly_source_info($name);
2183 if (!defined( $pkg )) {
2184 print "$pname: not registered\n";
2187 $pkg = calculate_prio($pkg);
2190 foreach $key (@firstkeys) {
2191 next if !defined $pkg->{$key};
2192 my $val = $pkg->{$key};
2194 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2196 my $print_key = $key;
2197 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2198 printf " %-20s: %s\n", $print_key, $val;
2200 foreach $key (sort keys %$pkg) {
2201 next if isin( $key, @firstkeys );
2202 my $val = $pkg->{$key};
2203 next if !defined($val);
2205 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2207 my $print_key = $key;
2208 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2209 printf " %-20s: %s\n", $print_key, $val;
2215 sub forget_packages {
2216 my( $name, $pkg, $key, $data );
2218 foreach $name (@_) {
2219 $name =~ s/_.*$//; # strip version
2220 $pkg = get_source_info($name);
2221 if (!defined( $pkg )) {
2222 print "$name: not registered\n";
2227 foreach $key (sort keys %$pkg) {
2228 my $val = $pkg->{$key};
2231 $data .= sprintf " %-20s: %s\n", $key, $val;
2233 send_mail( $conf::db_maint,
2234 "$name deleted from DB " . table_name() . " " . $distribution,
2235 "The package '$name' has been deleted from the database ".
2237 "Data registered about the deleted package:\n".
2238 "$data\n" ) if $conf::db_maint;
2239 change_state( \$pkg, 'deleted' );
2240 log_ta( $pkg, "--forget" );
2241 del_source_info($name);
2242 print "$name: deleted from database\n" if $verbose;
2247 $dbh->do("DELETE from " . user_table_name() .
2248 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
2254 print "Reading ASCII database from $file..." if $verbose >= 1;
2255 open( F, "<$file" ) or
2256 die "Can't open database $file: $!\n";
2258 local($/) = ""; # read in paragraph mode
2260 my( %thispkg, $name );
2262 s/\n[ \t]+/\376\377/g; # fix continuation lines
2263 s/\376\377\s*\376\377/\376\377/og;
2265 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2266 my ($key, $val) = ($1, $2);
2268 $key =~ tr/A-Z/a-z/;
2269 $val =~ s/\376\377/\n/g;
2270 $thispkg{$key} = $val;
2272 check_entry( \%thispkg );
2274 if (exists($thispkg{'package'})) {
2275 update_source_info(\%thispkg);
2277 elsif(exists($thispkg{'user'})) {
2278 # user in import, username in database.
2279 $dbh->do('INSERT INTO ' . user_table_name() .
2280 ' (username, distribution, last_seen)' .
2281 ' values (?, ?, ?)',
2282 undef, $thispkg{'user'}, $distribution,
2283 $thispkg{'last_seen'})
2284 or die $dbh->errstr;
2288 print "done\n" if $verbose >= 1;
2295 return if $op_mode eq "manual-edit"; # no checks then
2297 # check for required fields
2298 if (exists $pkg->{'user'}) {
2301 if (!exists $pkg->{'package'}) {
2302 print STDERR "Bad entry: ",
2303 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2304 die "Database entry lacks package or username field\n";
2306 # if no State: field, generate one (for old db compat)
2307 if (!exists($pkg->{'state'})) {
2309 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2311 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2312 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2315 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2316 if !isin( $pkg->{'state'},
2317 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2318 Failed Failed-Removed Not-For-Us BD-Uninstallable
2324 my($name,$pkg,$key);
2326 print "Writing ASCII database to $file..." if $verbose >= 1;
2327 open( F, ">$file" ) or
2328 die "Can't open export $file: $!\n";
2330 my $db = get_all_source_info();
2331 foreach $name (keys %$db) {
2332 next if $name =~ /^_/;
2333 my $pkg = $db->{$name};
2334 foreach $key (keys %{$pkg}) {
2335 my $val = $pkg->{$key};
2336 next if !defined($val);
2339 $val =~ s/^ +$/ ./mg;
2340 print F "$key: $val\n";
2345 print "done\n" if $verbose >= 1;
2351 my $newstate = shift;
2352 my $state = \$pkg->{'state'};
2354 return if defined($$state) and $$state eq $newstate;
2355 $pkg->{'previous_state'} = $$state if defined($$state);
2356 $pkg->{'state_change'} = $curr_date;
2357 $pkg->{'do_state_change'} = 1;
2359 if (defined($$state) and $$state eq 'Failed') {
2360 $pkg->{'old_failed'} =
2361 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2362 $pkg->{'failed'} . "\n" .
2363 $pkg->{'old_failed'};
2364 delete $pkg->{'failed'};
2365 delete $pkg->{'failed_category'};
2367 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2368 delete $pkg->{'bd_problem'};
2370 $$state = $newstate;
2376 my $dist = $distribution;
2380 $prevstate = $pkg->{'previous_state'};
2381 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2382 "changed from $prevstate to $pkg->{'state'} ".
2383 "by $real_user as $user";
2386 printf "update transactions: %s %s %s %s %s %s %s %s\n",
2387 $pkg->{'package'}, $distribution,
2388 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2392 $dbh->do('INSERT INTO ' . transactions_table_name() .
2393 ' (package, distribution, version, action, ' .
2394 ' prevstate, state, real_user, set_user, time) ' .
2395 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2396 undef, $pkg->{'package'}, $distribution,
2397 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2398 $real_user, $user, 'now()') or die $dbh->errstr;
2400 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2401 $str .= " (with --override)"
2403 $mail_logs .= "$str\n";
2410 my $subject = shift;
2413 my $from = $conf::db_maint;
2414 my $domain = $conf::buildd_domain;
2416 $from .= "\@$domain" if $from !~ /\@/;
2418 $to .= '@' . $domain if $to !~ /\@/;
2419 $text =~ s/^\.$/../mg;
2420 local $SIG{'PIPE'} = 'IGNORE';
2421 open( PIPE, "| $conf::mailprog -oem $to" )
2422 or die "Can't open pipe to $conf::mailprog: $!\n";
2424 print PIPE "From: $from\n";
2425 print PIPE "Subject: $subject\n\n";
2426 print PIPE "$text\n";
2430 # for parsing input to dep-wait
2436 foreach (split( /\s*,\s*/, $deps )) {
2438 # verification requires > starting prompts, no | crap
2439 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2444 my @alts = split( /\s*\|\s*/, $_ );
2445 # Anything with an | is ignored, as it can be configured on a
2446 # per-buildd basis what will be installed
2447 next if $#alts != 0;
2450 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2451 warn( "parse_deplist: bad dependency $_\n" );
2454 my($dep, $rel, $relv) = ($1, $3, $4);
2455 $rel = ">>" if defined($rel) and $rel eq ">";
2456 $result{$dep}->{'package'} = $dep;
2457 if ($rel && $relv) {
2458 $result{$dep}->{'rel'} = $rel;
2459 $result{$dep}->{'version'} = $relv;
2462 return 1 if $verify;
2470 foreach $key (keys %$list) {
2471 $result .= ", " if $result;
2473 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2474 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2481 return "" unless $_[0];
2482 return Dpkg::Deps::parse($_[0], ("reduce_arch" => 1, "host_arch" => $_[1]))->dump();
2485 sub wb_edos_builddebcheck {
2486 # Copyright (C) 2008 Ralf Treinen <treinen@debian.org>
2487 # This program is free software: you can redistribute it and/or modify it under
2488 # the terms of the GNU General Public License as published by the Free Software
2489 # Foundation, version 2 of the License.
2490 # integrated into wanna-builds code by Andreas Barth 2010
2493 my $sourceprefix="source---";
2494 my $architecture=$args->{'arch'};
2495 my $edosoptions = "-failures -explain -quiet";
2496 my $packagefiles = $args->{'pkgs'};
2497 my $sourcesfile = $args->{'src'};
2500 foreach my $packagefile (@$packagefiles) {
2501 open(P,$packagefile);
2503 next unless /^Architecture/;
2504 next if /^Architecture:\s*all/;
2505 /Architecture:\s*([^\s]*)/;
2506 if ($packagearch eq "") {
2508 } elsif ( $packagearch ne $1) {
2509 return "Package file contains different architectures: $packagearch, $1";
2515 if ( $architecture eq "" ) {
2516 if ( $packagearch eq "" ) {
2517 return "No architecture option given, " .
2518 "and no non-all architecture found in the Packages file";
2520 $architecture = $packagearch;
2523 if ( $packagearch ne "" & $architecture ne $packagearch) {
2524 return "Architecture option is $architecture ".
2525 "but the package file contains architecture $packagearch";
2529 print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n";
2531 "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles));
2538 # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED
2539 # source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing:
2540 # - libltdl-dev (>= 2.2.6a-2)
2541 # source---libcanberra (= 0.22-1~bpo50+1): FAILED
2542 # source---libcanberra (= 0.22-1~bpo50+1) depends on missing:
2544 # - libltdl7-dev (>= 2.2.6)
2547 s/^(\s*)$sourceprefix(.*)depends on/$1$2build-depends on/o;
2548 s/^(\s*)$sourceprefix(.*) and (.*) conflict/$1$2 build-conflicts with $3/o;
2551 if (/^$sourceprefix(.*) \(.*\): FAILED/o) {
2552 $result->{$binpkg} = $explanation if $binpkg;
2555 } elsif (/^(depwait---.*) \(.*\): FAILED/o) {
2556 $result->{$binpkg} = $explanation if $binpkg;
2559 } else { # else something broken is happening
2560 #print "ignoring $_\n";
2567 $result->{$binpkg} = $explanation if $binpkg;
2573 sub call_edos_depcheck {
2574 return if $simulate_edos;
2576 my $srcs = $args->{'srcs'};
2579 return if defined ($distributions{$distribution}{noadw}) && not defined $args->{'depwait'};
2581 # We need to check all of needs-build, as any new upload could make
2582 # something in needs-build have uninstallable deps
2583 # We also check everything in bd-uninstallable, as any new upload could
2584 # make that work again
2585 my (%interesting_packages, %interesting_packages_depwait);
2586 my $db = get_all_source_info();
2587 foreach $key (keys %$db) {
2588 my $pkg = $db->{$key};
2589 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/) and not defined ($distributions{$distribution}{noadw})) {
2590 $interesting_packages{$key} = undef;
2592 if (defined $pkg and isin($pkg->{'state'}, qw/Dep-Wait/) and defined $args->{'depwait'}) {
2593 $interesting_packages_depwait{$key} = undef;
2594 # we always check for BD-Uninstallability in depwait - could be that depwait is satisfied but package is uninstallable
2595 $interesting_packages{$key} = undef unless defined ($distributions{$distribution}{noadw});
2599 #print "I would look at these sources with edos-depcheck:\n";
2600 #print join " ", keys %interesting_packages,"\n";
2601 return unless %interesting_packages || %interesting_packages_depwait;
2603 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-XXXXX";
2604 use File::Temp qw/ tempfile /;
2605 my ($SOURCES, $tmpfile) = tempfile( $tmpfile_pattern, UNLINK => 1 );
2606 for my $key (keys %interesting_packages) {
2607 my $pkg = $db->{$key};
2608 # we print the source files as binary ones (with "source---"-prefixed),
2609 # so we can try if these "binary" packages are installable.
2610 # If such a "binary" package is installable, the corresponding source package is buildable.
2611 print $SOURCES "Package: source---$key\n";
2612 print $SOURCES "Version: $pkg->{'version'}\n";
2613 my $t = &filterarch($srcs->{$key}{'dep'} || $srcs->{$key}{'depends'}, $arch);
2614 my $tt = &filterarch($pkg->{'extra_depends'}, $arch);
2615 $t = $t ? ($tt ? "$t, $tt" : $t) : $tt;
2616 print $SOURCES "Depends: $t\n" if $t;
2617 my $u = &filterarch($srcs->{$key}{'conf'} || $srcs->{$key}{'conflicts'}, $arch);
2618 my $uu = &filterarch($pkg->{'extra_conflicts'}, $arch);
2619 $u = $u ? ($uu ? "$u, $uu" : $u) : $uu;
2620 print $SOURCES "Conflicts: $u\n" if $u;
2621 print $SOURCES "Architecture: all\n";
2622 print $SOURCES "\n";
2624 for my $key (keys %interesting_packages_depwait) {
2625 my $pkg = $db->{$key};
2626 # we print the source files as binary ones (with "depwait---"-prefixed),
2627 # so we can try if these "binary" packages are installable.
2628 # If such a "binary" package is installable, the corresponding source package goes out of depwait
2629 print $SOURCES "Package: depwait---$key\n";
2630 print $SOURCES "Version: $pkg->{'version'}\n";
2631 print $SOURCES "Depends: $pkg->{'depends'}\n";
2632 print $SOURCES "Architecture: all\n";
2633 print $SOURCES "\n";
2637 my $edosresults = wb_edos_builddebcheck({'arch' => $args->{'arch'}, 'pkgs' => $args->{'pkgs'}, 'src' => $tmpfile});
2638 if (ref($edosresults) eq 'HASH') {
2639 foreach my $key (grep { $_ !~ /^depwait---/ } keys %$edosresults) {
2640 if (exists $interesting_packages{$key}) {
2641 $interesting_packages{$key} = $edosresults->{$key};
2643 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2646 foreach my $key (grep { $_ =~ /^depwait---/ } keys %$edosresults) {
2647 $key =~ /^depwait---(.*)/ and $key = $1;
2648 if (exists $interesting_packages_depwait{$key}) {
2649 $interesting_packages_depwait{$key} = $edosresults->{"depwait---".$key};
2651 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2655 # if $edosresults isn't an hash, then something went wrong and the string is the error message
2656 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2657 "all packages have installable build-dependencies."
2662 for my $key (keys %interesting_packages) {
2663 next if defined $interesting_packages_depwait{$key};
2664 my $pkg = $db->{$key};
2666 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2667 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2668 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2670 if (defined $interesting_packages{$key}) {
2671 change_state( \$pkg, 'BD-Uninstallable' );
2672 $pkg->{'bd_problem'} = $interesting_packages{$key};
2674 change_state( \$pkg, 'Needs-Build' );
2677 if ($problemchange) {
2678 if (defined $interesting_packages{$key}) {
2679 $pkg->{'bd_problem'} = $interesting_packages{$key};
2683 log_ta( $pkg, "--merge-all (edos)" ) unless $simulate;
2684 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) to $pkg->{'state'}\n" if $verbose || $simulate;
2686 if ($change || $problemchange) {
2687 update_source_info($pkg) unless $simulate;
2691 for my $key (keys %interesting_packages_depwait) {
2692 if ($interesting_packages_depwait{$key}) {
2693 print "dep-wait for $key ($args->{'arch'}) not fullfiled yet\n" if $verbose || $simulate;
2696 my $pkg = $db->{$key};
2697 if (defined $interesting_packages{$key}) {
2698 change_state( \$pkg, 'BD-Uninstallable' );
2699 $pkg->{'bd_problem'} = $interesting_packages{$key};
2701 change_state( \$pkg, 'Needs-Build' );
2703 log_ta( $pkg, "edos_depcheck: depwait" ) unless $simulate;
2704 update_source_info($pkg) unless $simulate;
2705 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) from dep-wait to $pkg->{'state'}\n" if $verbose || $simulate;
2711 ($prgname = $0) =~ s,^.*/,,;
2713 Usage: $prgname <options...> <package_version...>
2715 -v, --verbose: Verbose execution.
2716 -A arch: Architecture this operation is for.
2717 --take: Take package for building [default operation]
2718 -f, --failed: Record in database that a build failed due to
2719 deficiencies in the package (that aren't fixable without a new
2721 -u, --uploaded: Record in the database that the packages build
2722 correctly and were uploaded.
2723 -n, --no-build: Record in the database that the packages aren't
2724 desired for this architecture and shouldn't appear in listings even
2725 if they're out of date.
2726 --dep-wait: Record in the database that the packages are waiting
2727 for some source dependencies to become available
2728 --binNMU num: Schedule a re-build of the package with unchanged source, but
2729 a new version number (source-version + "+b<num>")
2730 --give-back: Mark a package as ready to build that is in state Building,
2731 Built or Build-Attempted. To give back a package in state Failed, use
2732 --override. This command will actually put the package in state
2733 BD-Uninstallable, until the installability of its Build-Dependencies
2734 were verified. This happens at each call of --merge-all, usually
2736 --merge-quinn: Merge quinn-diff output into database.
2737 --merge-packages: Merge Packages files into database.
2738 --pretend-avail: Pretend that given packages are available now and give
2739 free packages waiting for them
2740 -i SRC_PKG, --info SRC_PKG: Show information for source package
2741 -l STATE, --list=STATE: List all packages in state STATE; can be
2742 combined with -U to restrict to a specific user; STATE can
2744 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2745 source dependency list
2746 (used with -f, --dep-wait, and --binNMU)
2747 -o, --override: Override another user's lock on a package, i.e.
2748 take it over; a notice mail will be sent to the other user
2749 -U USER, --user=USER: select user name for which listings should
2750 apply, if not given all users are listed.
2751 if -l is missing, set user name to be entered in db; usually
2752 automatically choosen
2753 --import FILE: Import database from a ASCII file FILE
2754 --export FILE: Export database to a ASCII file FILE
2756 The remaining arguments (depending on operation) usually start with
2757 "name_version", the trailer is ignored. This allows to pass the names
2758 of .dsc files, for which file name completion can be used.
2759 --merge-packages and --merge-quinn take Package/quin--diff file names
2760 on the command line or read stdin. --list needs nothing more on the
2761 command line. --info takes source package names (without version).
2766 sub pkg_version_eq {
2768 my $version = shift;
2771 if (defined $pkg->{'binary_nmu_version'}) and
2772 version_compare(binNMU_version($pkg->{'version'},
2773 $pkg->{'binary_nmu_version'}),'=', $version);
2774 return version_compare( $pkg->{'version'}, "=", $version );
2778 return '"' . $arch . $schema_suffix . '".packages';
2781 sub user_table_name {
2782 return '"' . $arch . $schema_suffix . '".users';
2785 sub transactions_table_name {
2786 return '"' . $arch . $schema_suffix . '".transactions';
2789 sub pkg_history_table_name {
2790 return '"' . $arch . $schema_suffix . '".pkg_history';
2793 sub get_readonly_source_info {
2795 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2796 my $q = "SELECT rel, priority, state_change, permbuildpri, section, buildpri, failed, state, binary_nmu_changelog, bd_problem, version, package, distribution, installed_version, notes, failed_category, builder, old_failed, previous_state, binary_nmu_version, depends, extract(days from date_trunc('days', now() - state_change)) as state_days, floor(extract(epoch from now()) - extract(epoch from state_change)) as state_time"
2797 . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution AND result = 'successful') AS successtime"
2798 . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2799 . ", extra_depends, extra_conflicts"
2800 . " FROM " . table_name()
2801 . ' WHERE package = ? AND distribution = ?';
2802 my $pkg = $dbh->selectrow_hashref( $q,
2803 undef, $name, $distribution);
2807 sub get_source_info {
2809 return get_readonly_source_info($name) if $simulate;
2810 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change)) as state_days, floor(extract(epoch from now()) - extract(epoch from state_change)) as state_time FROM ' .
2811 table_name() . ' WHERE package = ? AND distribution = ?' .
2813 undef, $name, $distribution);
2817 sub get_all_source_info {
2820 my $q = "SELECT rel, priority, state_change, permbuildpri, section, buildpri, failed, state, binary_nmu_changelog, bd_problem, version, package, distribution, installed_version, notes, failed_category, builder, old_failed, previous_state, binary_nmu_version, depends, extract(days from date_trunc('days', now() - state_change)) as state_days, floor(extract(epoch from now()) - extract(epoch from state_change)) as state_time"
2821 # . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution AND result = 'successful') AS successtime"
2822 # . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2823 . ", successtime.build_time as successtime, anytime.build_time as anytime, extra_depends, extra_conflicts"
2824 . " FROM " . table_name()
2826 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." where result = 'successful' order by package, distribution, timestamp "
2827 . " ) as successtime using (package, distribution) "
2829 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." order by package, distribution, timestamp desc"
2830 . " ) as anytime using (package, distribution) "
2833 if ($distribution) {
2834 my @dists = split(/[, ]+/, $distribution);
2835 $q .= ' AND ( distribution = ? '.(' OR distribution = ? ' x $#dists).' )';
2836 foreach my $d ( @dists ) {
2840 if ($options{state} && uc($options{state}) ne "ALL") {
2841 $q .= ' AND upper(state) = ? ';
2842 push @args, uc($options{state});
2845 if ($options{user} && uc($options{state}) ne "NEEDS-BUILD") { # if it's NEEDS-BUILD, we don't look at users
2846 #this basically means "this user, or no user at all":
2847 $q .= " AND (builder = ? OR upper(state) = 'NEEDS-BUILD')";
2848 push @args, $options{user};
2851 if ($options{category}) {
2852 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2853 push @args, $options{category};
2854 push @args, "FAILED";
2857 if ($options{list_min_age} > 0) {
2858 $q .= ' AND age(state_change) > ? ';
2859 push @args, $options{list_min_age} . " days";
2862 if ($options{list_min_age} < 0) {
2863 $q .= ' AND age(state_change) < ? ';
2864 push @args, -$options{list_min_age} . " days";
2867 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2871 sub show_distribution_architectures {
2872 my $q = 'SELECT distribution, spacecat_all(architecture) AS architectures '.
2873 'FROM distribution_architectures '.
2874 'GROUP BY distribution';
2875 my $rows = $dbh->selectall_hashref($q, 'distribution');
2876 foreach my $name (keys %$rows) {
2877 print $name.': '.$rows->{$name}->{'architectures'}."\n";
2881 sub show_distribution_aliases {
2882 foreach my $alias (keys %distribution_aliases) {
2883 print $alias.': '.$distribution_aliases{$alias}."\n";
2887 sub update_source_info {
2889 $pkg->{'extra_depends'} = $extra_depends if defined $extra_depends;
2890 undef $pkg->{'extra_depends'} unless $pkg->{'extra_depends'};
2891 $pkg->{'extra_conflicts'} = $extra_conflicts if defined $extra_conflicts;
2892 undef $pkg->{'extra_conflicts'} unless $pkg->{'extra_conflicts'};
2893 print Dumper $pkg if $verbose and $simulate;
2894 return if $simulate;
2896 my $pkg2 = get_source_info($pkg->{'package'});
2897 if (! defined $pkg2)
2899 add_source_info($pkg);
2902 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2907 'installed_version = ?, ' .
2908 'previous_state = ?, ' .
2909 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2913 'old_failed = ?, ' .
2914 'binary_nmu_version = ?, ' .
2915 'binary_nmu_changelog = ?, ' .
2916 'failed_category = ?, ' .
2917 'permbuildpri = ?, ' .
2921 'extra_depends = ?, ' .
2922 'extra_conflicts = ?, ' .
2924 'WHERE package = ? AND distribution = ?',
2930 $pkg->{'installed_version'},
2931 $pkg->{'previous_state'},
2935 $pkg->{'old_failed'},
2936 $pkg->{'binary_nmu_version'},
2937 $pkg->{'binary_nmu_changelog'},
2938 $pkg->{'failed_category'},
2939 $pkg->{'permbuildpri'},
2943 $pkg->{'extra_depends'},
2944 $pkg->{'extra_conflicts'},
2945 $pkg->{'bd_problem'},
2947 $distribution) or die $dbh->errstr;
2950 sub add_source_info {
2951 return if $simulate;
2953 $dbh->do('INSERT INTO ' . table_name() .
2954 ' (package, distribution) values (?, ?)',
2955 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2958 sub del_source_info {
2959 return if $simulate;
2961 $dbh->do('DELETE FROM ' . table_name() .
2962 ' WHERE package = ? AND distribution = ?',
2963 undef, $name, $distribution) or die $dbh->errstr;
2968 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2969 user_table_name() . ' WHERE username = ? AND distribution = ?',
2970 undef, $name, $distribution);
2974 sub update_user_info {
2975 return if $simulate;
2977 $dbh->do('UPDATE ' . user_table_name() .
2978 ' SET last_seen = now() WHERE username = ?' .
2979 ' AND distribution = ?',
2980 undef, $user, $distribution)
2981 or die $dbh->errstr;
2986 return if $simulate;
2988 $dbh->do('INSERT INTO ' . user_table_name() .
2989 ' (username, distribution, last_seen)' .
2990 ' values (?, ?, now())',
2991 undef, $user, $distribution)
2992 or die $dbh->errstr;
2997 return if $simulate;
2998 $dbh->do('LOCK TABLE ' . table_name() .
2999 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;
3003 # parts the array $_[0] and $_[1] and returns the sub-array (modifies the original one)
3006 my $separator = shift;
3007 while($args->[0] && $args->[0] ne $separator) {
3008 push @ret, shift @$args;
3010 shift @$args if @$args;
3014 sub parse_all_v3() {
3017 my $db = get_all_source_info();
3018 my $binary = $srcs->{'_binary'};
3021 foreach my $name (keys %$srcs) {
3022 next if $name eq '_binary';
3024 # state = installed, out-of-date, uncompiled, not-for-us
3025 my $pkgs = $srcs->{$name};
3026 my $pkg = $db->{$name};
3029 next SRCS if $pkgs->{'status'} eq 'not-for-us';
3030 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'} ($vars->{'arch'}, $vars->{'suite'}):";
3032 # does at least one binary exist in the database and is more recent - if so, we're probably just outdated, ignore the source package
3033 for my $bin (@{$pkgs->{'binary'}}) {
3034 if ($binary->{$bin} and vercmp($pkgs->{'version'}, $binary->{$bin}->{'version'}) < 0) {
3035 print "$logstr skipped because binaries (assumed to be) overwritten\n" if $verbose || $simulate;
3039 $pkg->{'package'} = $name;
3041 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'}".
3042 ($pkgs->{'binnmu'} ? ";b".$pkgs->{'binnmu'} : "").
3043 "($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'version'}".
3044 ($pkg->{'binary_nmu_version'} ? ";b".$pkg->{'binary_nmu_version'} : "").
3045 ", $pkg->{'state'}):";
3047 if (isin($pkgs->{'status'}, qw (installed related)) && $pkgs->{'version'} eq $pkg->{'version'} && $pkg->{'binary_nmu_version'} && $pkgs->{'binnmu'} < int($pkg->{'binary_nmu_version'})) {
3048 $pkgs->{'status'} = 'out-of-date';
3050 if (isin($pkgs->{'status'}, qw (installed related))) {
3052 if ($pkg->{'state'} ne 'Installed') {
3053 change_state( \$pkg, 'Installed');
3054 delete $pkg->{'depends'};
3055 delete $pkg->{'extra_depends'};
3056 delete $pkg->{'extra_conflicts'};
3059 my $attrs = { 'version' => 'version', 'installed_version' => 'version', 'binary_nmu_version' => 'binnmu', 'section' => 'section', 'priority' => 'priority' };
3060 foreach my $k (keys %$attrs) {
3061 if ($pkg->{$k} ne $pkgs->{$attrs->{$k}}) {
3062 $pkg->{$k} = $pkgs->{$attrs->{$k}};
3066 if (isin($pkgs->{'status'}, qw (related)) and $pkg->{'notes'} ne "related") {
3067 $pkg->{'notes'} = "related";
3071 print "$logstr set to installed/".$pkg->{'notes'}."\n" if $verbose || $simulate;
3072 log_ta( $pkg, "--merge-v3: installed" ) unless $simulate;
3073 update_source_info($pkg) unless $simulate;
3078 if ($pkgs->{'status'} eq 'not-for-us') {
3079 next if isin( $pkg->{'state'}, qw(Not-For-Us Installed Failed-Removed));
3081 if (isin( $pkg->{'state'}, qw(Failed Build-Attempted Built))) {
3082 change_state( \$pkg, "Failed-Removed" );
3083 log_ta( $pkg, "--merge-v3: Failed-Removed" ) unless $simulate;
3084 update_source_info($pkg) unless $simulate;
3085 print "$logstr (virtually) deleted from database\n" if $verbose || $simulate;
3089 print "$logstr should delete (not-for-us according to P-a-s)\n" if $verbose || $simulate || 1; # not implemented yet on purpose
3093 # only uncompiled / out-of-date are left, so check if anything new
3094 if (!(isin($pkgs->{'status'}, qw (uncompiled out-of-date)))) {
3095 print "$logstr package in unknown state: $pkgs->{'status'}\n";
3098 next if $pkgs->{'version'} eq $pkg->{'version'} and $pkgs->{'binnmu'} >= int($pkg->{'binary_nmu_version'});
3099 next if $pkgs->{'version'} eq $pkg->{'version'} and !isin( $pkg->{'state'}, qw(Installed));
3100 next if isin( $pkg->{'state'}, qw(Not-For-Us Failed-Removed));
3102 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
3103 send_mail( $pkg->{'builder'},
3104 "new version of $name (dist=$distribution)",
3105 "As far as I'm informed, you're currently building the package $name\n".
3106 "in version $pkg->{'version'}.\n\n".
3107 "Now there's a new source version $pkgs->{'version'}. If you haven't finished\n".
3108 "compiling $name yet, you can stop it to save some work.\n".
3109 "Just to inform you...\n".
3110 "(This is an automated message)\n" ) unless $simulate;
3111 print "$logstr new version while building $pkg->{'version'} -- sending mail to builder ($pkg->{'builder'})\n"
3112 if $verbose || $simulate;
3114 change_state( \$pkg, 'Needs-Build');
3115 $pkg->{'notes'} = $pkgs->{'status'};
3116 $pkg->{'version'} = $pkgs->{'version'};
3117 $pkg->{'section'} = $pkgs->{'section'};
3118 $pkg->{'priority'} = $pkgs->{'priority'};
3119 $pkg->{'dep'} = $pkgs->{'depends'};
3120 $pkg->{'conf'} = $pkgs->{'conflicts'};
3121 delete $pkg->{'builder'};
3122 delete $pkg->{'binary_nmu_version'} unless $pkgs->{'binnmu'};
3123 delete $pkg->{'binary_nmu_changelog'} unless $pkgs->{'binnmu'};
3124 log_ta( $pkg, "--merge-v3: needs-build" ) unless $simulate;
3125 update_source_info($pkg) unless $simulate;
3126 print "$logstr set to needs-builds\n" if $simulate || $verbose;
3129 foreach my $name (keys %$db) {
3130 next if $srcs->{$name};
3131 my $pkg = $db->{$name};
3132 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkg->{'version'} ($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'state'}):";
3133 # package disappeared - delete
3134 change_state( \$pkg, 'deleted' );
3135 log_ta( $pkg, "--merge-v3: deleted" ) unless $simulate;
3136 print "$logstr deleted from database\n" if $verbose || $simulate;
3137 del_source_info($name) unless $simulate;
3138 delete $db->{$name};