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
28 use vars qw< $basedir $dbbase $transactlog $mailprog $buildd_domain >;
30 $basedir ||= "/var/lib/debbuild";
31 $dbbase ||= "build-db";
32 $transactlog ||= "transactions.log";
33 $mailprog ||= "/usr/sbin/sendmail";
34 require "/org/wanna-build/etc/wanna-build.conf";
35 die "$conf::basedir is not a directory\n" if ! -d $conf::basedir;
36 die "dbbase is empty\n" if ! $dbbase;
37 die "transactlog is empty\n" if ! $transactlog;
38 die "mailprog binary $conf::mailprog does not exist or isn't executable\n"
39 if !-x $conf::mailprog;
46 use Getopt::Long qw ( :config gnu_getopt );
47 use lib '/org/wanna-build/lib';
52 use Hash::Merge qw ( merge );
55 use List::Util qw[max];
56 use Dpkg::Version (); # import nothing
57 if ( defined $Dpkg::Version::VERSION ) {
58 *vercmp = \&Dpkg::Version::version_compare;
60 *vercmp = \&Dpkg::Version::vercmp;
63 use Dpkg::Deps; # TODO: same
65 our ($verbose, $mail_logs, $list_order, $list_state,
66 $curr_date, $op_mode, $user, $real_user, $distribution,
67 $fail_reason, $opt_override, $import_from, $export_to,
69 $info_all_dists, $arch,
70 $short_date, $list_min_age, $list_max_age, $dbbase, @curr_time,
71 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
72 $printformat, $ownprintformat, $privmode, $extra_depends, $extra_conflicts,
73 %distributions, %distribution_aliases
75 our $Pas = '/org/buildd.debian.org/etc/packages-arch-specific/Packages-arch-specific';
77 our $simulate_edos = 0;
78 our $api = undef; # allow buildds to specify an different api
79 our $recorduser = undef;
82 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
87 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
88 $short_date = strftime("%m/%d/%y",@curr_time);
91 # set mode of operation based on command line switch. Should be used
92 # by GetOptions below.
93 sub _set_mode_set { $op_mode = "set-$_[0]" }
94 sub _set_mode { $op_mode = "$_[0]" }
96 sub _option_deprecated { warn "Option $_[0] is deprecated" }
99 # this is not supported by all operations (yet)!
100 'simulate' => \$simulate,
101 'simulate-edos' => \$simulate_edos,
102 'simulate-all' => sub { $simulate = 1; $simulate_edos = 1; },
105 die "$api too large" unless $api <= 1;
107 'verbose|v' => \$verbose,
108 'override|o' => \$opt_override,
109 'correct-compare' => \$WannaBuild::opt_correct_version_cmp,
111 # TODO: remove after buildds no longer pass to wanna-build
112 'no-propagation|N' => \&_option_deprecated,
113 'no-down-propagation|D' => \&_option_deprecated,
116 'building|take' => \&_set_mode_set,
117 'failed|f' => \&_set_mode_set,
118 'uploaded|u' => \&_set_mode_set,
119 'not-for-us|no-build|n' => \&_set_mode_set,
120 'built' => \&_set_mode_set,
121 'attempted' => \&_set_mode_set,
122 'needs-build|give-back' => \&_set_mode_set,
123 'dep-wait' => \&_set_mode_set,
124 'update' => \&_set_mode_set,
125 'forget' => \&_set_mode,
126 'forget-user' => \&_set_mode,
127 'merge-v3' => \&_set_mode,
128 'info|i' => \&_set_mode,
129 'binary-nmu|binNMU=i' => sub {
133 'permanent-build-priority|perm-build-priority=i' => sub {
135 $build_priority = $_[1];
137 'build-priority=i' => sub {
139 $build_priority = $_[1];
144 die "Unknown state to list: $list_state\n"
145 if not $list_state ~~ [
146 qw( needs-build building uploaded built
147 build-attempted failed installed
148 dep-wait not-for-us auto-not-for-us
149 all failed-removed install-wait
150 reupload-wait bd-uninstallable ) ];
153 $distribution = $_[1];
155 when ( [qw< a all >] ) {
159 when ('o') { $distribution = 'oldstable'; }
160 when ('s') { $distribution = 'stable'; }
161 when ('t') { $distribution = 'testing'; }
162 when ('u') { $distribution = 'unstable'; }
167 die "Bad ordering character\n"
168 if $list_order !~ /^[PSpsncbCWT]+$/;
170 'message|m=s' => \$fail_reason,
171 'database|b=s' => sub {
172 warn "database is deprecated, please use 'arch' instead.\n";
173 $conf::dbbase = $_[1];
175 'arch|A=s' => \$arch,
176 'user|U=s' => \$user,
177 'min-age|a=i' => \$list_min_age,
178 'max-age=i' => \$list_max_age,
179 'format=s' => \$printformat,
180 'own-format=s' => \$ownprintformat,
182 'extra-depends=s' => \$extra_depends,
183 'extra-conflicts=s' => \$extra_conflicts,
186 'export=s' => sub { _set_mode(@_); $export_to = $_[1]; },
187 'import=s' => sub { _set_mode(@_); $import_from = $_[1]; },
188 'manual-edit' => \&_set_mode,
189 'distribution-architectures' => \&_set_mode,
190 'distribution-aliases' => \&_set_mode,
192 $list_min_age = -1 * $list_max_age if $list_max_age;
199 $dbh->disconnect or warn $dbh->errstr;
203 $distribution ||= "sid";
204 if ($distribution eq 'any-priv') {
206 $distribution = 'any';
208 if ($distribution eq 'any-unpriv') {
210 $distribution = 'any';
213 my $schema_suffix = '';
214 $recorduser //= (not -t and $user//"" =~ /^buildd_/);
215 if ((isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !$recorduser && !($privmode)) || $simulate) {
216 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
217 die "FATAL: Cannot open database: $DBI::errstr\n";
218 $schema_suffix = '_public';
222 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
223 die "FATAL: Cannot open database: $DBI::errstr\n";
226 # TODO: This shouldn't be needed, file a bug.
227 $dbh->{pg_server_prepare} = 0;
229 $dbh->begin_work or die $dbh->errstr;
231 my $q = 'SELECT distribution, public, auto_dep_wait, build_dep_resolver, suppress_successful_logs, archive FROM distributions';
232 my $rows = $dbh->selectall_hashref($q, 'distribution');
233 foreach my $name (keys %$rows) {
234 $distributions{$name} = {};
235 $distributions{$name}->{'noadw'} = 1 if !($rows->{$name}->{'auto_dep_wait'});
236 $distributions{$name}->{'hidden'} = 1 if !($rows->{$name}->{'public'});
237 $distributions{$name}->{'build_dep_resolver'} = $rows->{$name}->{'build_dep_resolver'} if $rows->{$name}->{'build_dep_resolver'};
238 $distributions{$name}->{'suppress_successful_logs'} = $rows->{$name}->{'suppress_successful_logs'} if $rows->{$name}->{'suppress_successful_logs'};
239 $distributions{$name}->{'archive'} = $rows->{$name}->{'archive'} if $rows->{$name}->{'archive'};
242 $q = 'SELECT alias, distribution FROM distribution_aliases';
243 $rows = $dbh->selectall_hashref($q, 'alias');
244 foreach my $name (keys %$rows) {
245 $distribution_aliases{$name} = $rows->{$name}->{'distribution'};
247 $distribution = $distribution_aliases{$distribution} if (isin($distribution, keys %distribution_aliases));
249 $op_mode ||= "set-building";
250 undef $distribution if $distribution eq 'any';
252 my @dists = split(/[, ]+/, $distribution);
253 foreach my $dist (@dists) {
254 die "Bad distribution '$distribution'\n"
255 if !isin($dist, keys %distributions);
258 if (!isin ( $op_mode, qw(list) ) && ( !$distribution || $distribution =~ /[ ,]/)) {
259 die "multiple distributions are only allowed for list";
262 # If they didn't specify an arch, try to get it from database name which
263 # is in the form of $arch/build-db
264 # This is for backwards compatibity with older versions that didn't
265 # specify the arch yet.
266 $conf::dbbase =~ m#^([^/]+)#;
269 # TODO: Check that it's an known arch (for that dist), and give
273 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
274 $version =~ s/(^\$| \$ .*$)//g;
275 print "wanna-build $version for $distribution on $arch\n";
278 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
279 merge-packages manual-edit
280 merge-sources distribution-architectures
281 distribution-aliases))) {
282 warn "No packages given.\n";
286 $real_user = (getpwuid($<))[0];
287 die "Can't determine your user name\n"
288 if $op_mode ne "list" && !$user &&
289 !($user = $real_user);
292 if ($op_mode eq "set-failed" ) {
293 print "Enter reason for failing (end with '.' alone on ".
298 last if $line eq ".\n";
299 $fail_reason .= $line;
301 chomp( $fail_reason );
302 } elsif ($op_mode eq "set-dep-wait") {
303 print "Enter dependencies (one line):\n";
305 while( !$line && !eof(STDIN) ) {
306 chomp( $line = <STDIN> );
308 die "No dependencies given\n" if !$line;
309 $fail_reason = $line;
310 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
311 print "Enter changelog entry (one line):\n";
313 while( !$line && !eof(STDIN) ) {
314 chomp( $line = <STDIN> );
316 die "No changelog entry given\n" if !$line;
317 $fail_reason = $line;
322 my $yamldir = "/org/wanna-build/etc/yaml";
323 my @files = ('wanna-build.yaml');
324 if ((getpwuid($>))[7]) { push (@files, ((getpwuid($>))[7])."/.wanna-build.yaml"); }
325 if ($user && $user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
326 if ($user) { push ( @files, "$user.yaml"); }
327 foreach my $file (@files) {
328 my $cfile = File::Spec->rel2abs( $file, $yamldir );
329 if ($verbose >= 2) { print "Trying to read $file ($cfile) ...\n"; }
330 next unless -f $cfile;
331 if ($verbose >= 2) { print "Read $file ($cfile) ...\n"; }
332 my $m = YAML::Tiny->read( $cfile )->[0];
333 $yamlmap = merge($m, $yamlmap);
336 die "FATAL: no configuration found\n";
338 $list_order = $yamlmap->{"list-order"}{$list_state} if !$list_order and $list_state;
339 $list_order ||= $yamlmap->{"list-order"}{'default'};
340 $api //= $yamlmap->{"api"};
348 if ($mail_logs && $conf::log_mail) {
349 send_mail( $conf::log_mail,
350 "wanna-build $distribution state changes $curr_date",
351 "State changes at $curr_date for distribution ".
352 "$distribution:\n\n$mail_logs\n" );
360 SWITCH: foreach ($op_mode) {
362 add_packages( $1, @ARGV );
366 list_packages( $list_state );
370 info_packages( @ARGV );
373 /^forget-user/ && do {
374 die "This operation is restricted to admin users\n"
375 if (defined @conf::admin_users and
376 !isin( $real_user, @conf::admin_users));
377 forget_users( @ARGV );
381 forget_packages( @ARGV );
385 die "This operation is restricted to admin users\n"
386 if (defined @conf::admin_users and !isin( $real_user, @conf::admin_users) and !$simulate);
387 # call with installed-packages+ . installed-sources+ [ . available-for-build-packages* [ . consider-as-installed-source* ] ]
388 # in case available-for-build-packages is not specified, installed-packages are used
389 lock_table() unless $simulate;
390 my $replacemap = { '%ARCH%' => $arch, '%SUITE%' => $distribution };
391 map { my $k = $_; grep { $k =~ s,$_,$replacemap->{$_}, } keys %{$replacemap}; $_ = $k; } @ARGV;
392 my @ipkgs = &parse_argv( \@ARGV, '.');
393 my @isrcs = &parse_argv( \@ARGV, '.');
394 my @bpkgs = &parse_argv( \@ARGV, '.');
395 my @psrcs = &parse_argv( \@ARGV, '.');
397 my $srcs = WB::QD::readsourcebins($arch, $Pas, \@isrcs, \@ipkgs);
399 my $psrcs = WB::QD::readsourcebins($arch, $Pas, \@psrcs, []);
400 foreach my $k (keys %$$psrcs) {
401 next if $$srcs->{$k};
402 my $pkg = $$psrcs->{$k};
403 $pkg->{'status'} = 'related';
407 parse_all_v3($$srcs, {'arch' => $arch, 'suite' => $distribution, 'time' => $curr_date});
408 @bpkgs = @ipkgs unless @bpkgs;
409 call_edos_depcheck( {'arch' => $arch, 'pkgs' => \@bpkgs, 'srcs' => $$srcs, 'depwait' => 1 });
413 die "This operation is restricted to admin users\n"
414 if (defined @conf::admin_users and
415 !isin( $real_user, @conf::admin_users));
416 $dbh->do("DELETE from " . table_name() .
417 " WHERE distribution = ?", undef,
421 read_db( $import_from );
425 export_db( $export_to );
428 /^distribution-architectures/ && do {
429 show_distribution_architectures();
432 /^distribution-aliases/ && do {
433 show_distribution_aliases();
437 die "Unexpected operation mode $op_mode\n";
440 my $userinfo = get_user_info($user);
441 if (!defined $userinfo)
443 add_user_info($user);
447 update_user_info($user);
453 my $newstate = shift;
454 my( $package, $name, $version, $ok, $reason );
456 foreach $package (@_) {
457 $package =~ s,^.*/,,; # strip path
458 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
459 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
460 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
461 ($name,$version) = ($1,$2);
464 warn "$package: can't extract package name and version ".
468 my $pkg = get_source_info($name);
469 if (!isin($op_mode, qw<set-building>) && (!defined($pkg))) {
470 print "$name: not registered yet.\n";
473 if (isin($op_mode, qw<set-built set-attempted set-uploaded set-dep-wait>)) {
474 if ($pkg->{'builder'} && $user ne $pkg->{'builder'}) {
475 print "$pkg->{'package'}: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
479 if (!isin($op_mode, qw<set-building set-uploaded set-update>)) {
480 if ( !pkg_version_eq($pkg,$version)) {
481 print "$pkg->{package}: version mismatch ($pkg->{'version'} by $pkg->{'builder'})\n";
486 if ($op_mode eq "set-building") {
487 add_one_building( $name, $version, $pkg );
489 elsif ($op_mode eq "set-built") {
490 add_one_built( $pkg );
492 elsif ($op_mode eq "set-attempted") {
493 add_one_attempted( $pkg );
495 elsif ($op_mode eq "set-uploaded") {
496 add_one_uploaded( $name, $version, $pkg );
498 elsif ($op_mode eq "set-failed") {
499 add_one_failed( $pkg );
501 elsif ($op_mode eq "set-not-for-us") {
502 add_one_notforus( $pkg );
504 elsif ($op_mode eq "set-needs-build") {
505 add_one_needsbuild( $pkg );
507 elsif ($op_mode eq "set-dep-wait") {
508 add_one_depwait( $pkg );
510 elsif ($op_mode eq "set-build-priority") {
511 set_one_buildpri( 'buildpri', $pkg );
513 elsif ($op_mode eq "set-permanent-build-priority") {
514 set_one_buildpri( 'permbuildpri', $pkg );
516 elsif ($op_mode eq "set-binary-nmu") {
517 set_one_binnmu( $name, $version, $pkg );
519 elsif ($op_mode eq "set-update") {
520 set_one_update( $pkg );
525 sub add_one_building {
533 if ($pkg->{'state'} eq "Not-For-Us") {
535 $reason = "not suitable for this architecture";
537 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
539 $reason = "not all source dependencies available yet";
541 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
543 $reason = "source dependencies are not installable";
545 elsif ($pkg->{'state'} eq "Uploaded" &&
546 (version_lesseq($version, $pkg->{'version'}))) {
548 $reason = "already uploaded by $pkg->{'builder'}";
549 $reason .= " (in newer version $pkg->{'version'})"
550 if !version_eq($pkg, $version);
552 elsif ($pkg->{'state'} eq "Installed" &&
553 version_less($version,$pkg->{'version'})) {
555 print "$name: Warning: newer version $pkg->{'version'} ".
556 "already installed, but overridden.\n";
560 $reason = "newer version $pkg->{'version'} already in ".
561 "archive; doesn't need rebuilding";
562 print "$name: Note: If the following is due to an epoch ",
563 " change, use --override\n";
566 elsif ($pkg->{'state'} eq "Installed" &&
567 pkg_version_eq($pkg,$version)) {
569 $reason = "is up-to-date in the archive; doesn't need rebuilding";
571 elsif ($pkg->{'state'} eq "Needs-Build" &&
572 version_less($version,$pkg->{'version'})) {
574 print "$name: Warning: newer version $pkg->{'version'} ".
575 "needs building, but overridden.";
579 $reason = "newer version $pkg->{'version'} needs building, ".
583 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
584 if (version_less($pkg->{'version'},$version)) {
585 print "$name: Warning: Older version $pkg->{'version'} ",
586 "is being built by $pkg->{'builder'}\n";
587 if ($pkg->{'builder'} ne $user) {
588 send_mail( $pkg->{'builder'},
589 "package takeover in newer version",
590 "You are building package '$name' in ".
591 "version $version\n".
592 "(as far as I'm informed).\n".
593 "$user now has taken the newer ".
594 "version $version for building.".
595 "You can abort the build if you like.\n" );
600 print "User $pkg->{'builder'} had already ",
601 "taken the following package,\n",
602 "but overriding this as you request:\n";
603 send_mail( $pkg->{'builder'}, "package takeover",
604 "The package '$name' (version $version) that ".
605 "was taken by you\n".
606 "has been taken over by $user\n" );
608 elsif ($pkg->{'builder'} eq $user) {
609 print "$name: Note: already taken by you.\n";
610 print "$name: ok\n" if $verbose;
615 $reason = "already taken by $pkg->{'builder'}";
616 $reason .= " (in newer version $pkg->{'version'})"
617 if !version_eq($pkg->{'version'}, $version);
621 elsif ($pkg->{'state'} =~ /^Failed/ &&
622 pkg_version_eq($pkg, $version)) {
624 print "The following package previously failed ",
625 "(by $pkg->{'builder'})\n",
626 "but overriding this as you request:\n";
627 send_mail( $pkg->{'builder'}, "failed package takeover",
628 "The package '$name' (version $version) that ".
630 "and has failed previously has been taken over ".
632 if $pkg->{'builder'} ne $user;
636 $reason = "build of $version failed previously:\n ";
637 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
638 $reason .= "\nalso the package doesn't need builing"
639 if $pkg->{'state'} eq 'Failed-Removed';
646 if ($pkg->{'binary_nmu_version'}) {
647 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
648 "$pkg->{'binary_nmu_changelog'}\n";
651 print "$name: Warning: Previous version failed!\n"
652 if $pkg->{'previous_state'} =~ /^Failed/ ||
653 $pkg->{'state'} =~ /^Failed/;
655 print "$name: $ok\n" if $verbose;
658 print " - status: ok\n";
659 printf " - pkg-ver: %s_%s\n", $name, $version;
660 print " - binNMU: $pkg->{'binary_nmu_version'}\n" if $pkg->{'binary_nmu_version'};
661 print " - extra-changelog: $pkg->{'binary_nmu_changelog'}\n" if $pkg->{'binary_nmu_changelog'} && $pkg->{'binary_nmu_version'};
662 print " - extra-depends: $pkg->{'extra_depends'}\n" if $pkg->{'extra_depends'};
663 print " - extra-conflicts: $pkg->{'extra_conflicts'}\n" if $pkg->{'extra_conflicts'};
664 print " - archive: $distributions{$distribution}->{'archive'}\n" if $distributions{$distribution}->{'archive'};
665 print " - build_dep_resolver: $distributions{$distribution}->{'build_dep_resolver'}\n" if $distributions{$distribution}->{'build_dep_resolver'};
666 print " - arch_all: $pkg->{'build_arch_all'}\n" if $pkg->{'build_arch_all'};
667 print " - suppress_successful_logs: $distributions{$distribution}->{'suppress_successful_logs'}\n" if $distributions{$distribution}->{'suppress_successful_logs'};
669 change_state( \$pkg, 'Building' );
670 $pkg->{'package'} = $name;
671 $pkg->{'version'} = $version;
672 $pkg->{'builder'} = $user;
673 log_ta( $pkg, "--take" );
674 update_source_info($pkg);
678 print "$name: NOT OK!\n $reason\n";
680 print "- $name:\n - status: not ok\n - reason: \"$reason\"\n";
685 sub add_one_attempted {
687 my $state = $pkg->{'state'};
688 my $name = $pkg->{'package'};
690 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
691 print "$name: not taken for building (state is $pkg->{'state'}). ",
696 change_state( \$pkg, 'Build-Attempted' );
697 log_ta( $pkg, "--attempted" );
698 update_source_info($pkg);
699 print "$name: registered as uploaded\n" if $verbose;
704 my $state = $pkg->{'state'};
705 my $name = $pkg->{'package'};
707 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
708 print "$name: not taken for building (state is $pkg->{'state'}). ",
713 change_state( \$pkg, 'Built' );
714 log_ta( $pkg, "--built" );
715 update_source_info($pkg);
716 print "$name: registered as built\n" if $verbose;
719 sub add_one_uploaded {
724 if ($pkg->{'state'} eq "Uploaded" &&
725 pkg_version_eq($pkg,$version)) {
726 print "$name: already uploaded\n";
729 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
730 print "$name: not taken for building (state is $pkg->{'state'}). ",
734 # strip epoch -- buildd-uploader used to go based on the filename.
735 # (to remove at some point)
737 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
738 $version =~ s/^\d+://; # for command line use
739 if ($pkg->{'binary_nmu_version'} ) {
740 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
741 if (!version_eq( $nmuver, $version )) {
742 print "$name: version mismatch ($nmuver registered). ",
746 } elsif (!version_eq($pkgver, $version)) {
747 print "$name: version mismatch ($pkg->{'version'} registered). ",
752 change_state( \$pkg, 'Uploaded' );
753 log_ta( $pkg, "--uploaded" );
754 update_source_info($pkg);
755 print "$name: registered as uploaded\n" if $verbose;
760 my $state = $pkg->{'state'};
761 my $name = $pkg->{'package'};
763 if ($state eq "Not-For-Us") {
764 print "$name: not suitable for this architecture anyway. Skipping.\n";
767 elsif ($state eq "Failed-Removed") {
768 print "$name: failed previously and doesn't need building. Skipping.\n";
771 elsif ($state eq "Installed") {
772 print "$name: Is already installed in archive. Skipping.\n";
775 elsif ($pkg->{'builder'} &&
776 (($user ne $pkg->{'builder'}) &&
777 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
778 print "$name: not taken by you, but by ".
779 "$pkg->{'builder'}. Skipping.\n";
783 if (isin($state, qw<Needs-Build Uploaded Dep-Wait BD-Uninstallable>)) {
784 print "add_one_failed: $name: Warning: not registered for building previously (but $state), processing anyway.\n";
786 elsif ($state eq "Failed") {
787 print "$name: already registered as failed; will append new message\n"
791 change_state( \$pkg, 'Failed' );
792 $pkg->{'builder'} = $user;
793 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
794 $pkg->{'failed'} .= $fail_reason;
795 log_ta( $pkg, "--failed" );
796 update_source_info($pkg);
797 print "$name: registered as failed\n" if $verbose;
800 sub add_one_notforus {
802 my $state = $pkg->{'state'};
803 my $name = $pkg->{'package'};
805 if ($pkg->{'state'} eq 'Not-For-Us') {
806 # reset Not-For-Us state in case it's called twice; this is
807 # the only way to get a package out of this state...
808 # There is no really good state in which such packages should
809 # be put :-( So use Failed for now.
810 change_state( \$pkg, 'Failed' );
811 $pkg->{'package'} = $name;
812 $pkg->{'failed'} = "Was Not-For-Us previously";
813 delete $pkg->{'builder'};
814 delete $pkg->{'depends'};
815 log_ta( $pkg, "--no-build(rev)" );
816 print "$name: now not unsuitable anymore\n";
818 send_mail( $conf::notforus_maint,
819 "$name moved out of Not-For-Us state",
820 "The package '$name' has been moved out of the Not-For-Us ".
822 "It should probably also be removed from ".
823 "Packages-arch-specific or\n".
824 "the action was wrong.\n" )
825 if $conf::notforus_maint;
828 change_state( \$pkg, 'Not-For-Us' );
829 $pkg->{'package'} = $name;
830 delete $pkg->{'builder'};
831 delete $pkg->{'depends'};
832 delete $pkg->{'binary_nmu_version'};
833 delete $pkg->{'binary_nmu_changelog'};
834 log_ta( $pkg, "--no-build" );
835 print "$name: registered as unsuitable\n" if $verbose;
837 send_mail( $conf::notforus_maint,
838 "$name set to Not-For-Us",
839 "The package '$name' has been set to state Not-For-Us ".
841 "It should probably also be added to ".
842 "Packages-arch-specific or\n".
843 "the Not-For-Us state is wrong.\n" )
844 if $conf::notforus_maint;
846 update_source_info($pkg);
849 sub add_one_needsbuild {
851 my $state = $pkg->{'state'};
852 my $name = $pkg->{'package'};
854 if ($state eq "BD-Uninstallable") {
856 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
858 change_state( \$pkg, 'Needs-Build' );
859 delete $pkg->{'builder'};
860 delete $pkg->{'depends'};
861 log_ta( $pkg, "--give-back" );
862 update_source_info($pkg);
863 print "$name: given back\n" if $verbose;
867 print "$name: has uninstallable build-dependencies. Skipping\n",
868 " (use --override to clear dependency list and ",
869 "give back anyway)\n";
873 elsif ($state eq "Dep-Wait") {
875 print "$name: Forcing source dependency list to be cleared\n";
878 print "$name: waiting for source dependencies. Skipping\n",
879 " (use --override to clear dependency list and ",
880 "give back anyway)\n";
884 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
885 print "$name: not taken for building (state is $state).";
887 print "\n$name: Forcing give-back\n";
890 print " Skipping.\n";
894 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
895 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
897 print "$name: not taken by you, but by ".
898 "$pkg->{'builder'}. Skipping.\n";
901 if (!defined $distributions{$distribution}{noadw}) {
902 change_state( \$pkg, 'BD-Uninstallable' );
903 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
905 change_state( \$pkg, 'Needs-Build' );
907 $pkg->{'builder'} = undef;
908 $pkg->{'depends'} = undef;
909 log_ta( $pkg, "--give-back" );
910 update_source_info($pkg);
911 print "$name: given back\n" if $verbose;
918 my $state = $pkg->{'state'};
920 if (defined $pkg->{'binary_nmu_version'}) {
921 if ($binNMUver == 0) {
922 change_state( \$pkg, 'Installed' );
923 delete $pkg->{'builder'};
924 delete $pkg->{'depends'};
925 delete $pkg->{'binary_nmu_version'};
926 delete $pkg->{'binary_nmu_changelog'};
927 delete $pkg->{'buildpri'};
928 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
929 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
932 $pkg->{'binary_nmu_version'} = $binNMUver;
933 $pkg->{'binary_nmu_changelog'} = $fail_reason;
934 $pkg->{'notes'} = 'out-of-date';
935 delete $pkg->{'buildpri'};
936 if (defined $distributions{$distribution}{noadw}) {
937 change_state( \$pkg, 'Installed' );
939 change_state( \$pkg, 'BD-Uninstallable' );
942 log_ta( $pkg, "--binNMU" );
943 update_source_info($pkg);
945 } elsif ($binNMUver == 0) {
946 print "${name}_$version: no scheduled binNMU to cancel.\n";
950 if ($state ne 'Installed') {
951 print "${name}_$version: not installed; can't register for binNMU.\n";
955 my $fullver = binNMU_version($version,$binNMUver);
956 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
958 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
962 if (!defined $distributions{$distribution}{noadw}) {
963 change_state( \$pkg, 'BD-Uninstallable' );
964 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
968 change_state( \$pkg, 'Needs-Build' );
970 delete $pkg->{'builder'};
971 delete $pkg->{'depends'};
972 $pkg->{'binary_nmu_version'} = $binNMUver;
973 $pkg->{'binary_nmu_changelog'} = $fail_reason;
974 $pkg->{'notes'} = 'out-of-date';
975 delete $pkg->{'buildpri'};
976 log_ta( $pkg, "--binNMU" );
977 update_source_info($pkg);
978 print "${name}: registered for binNMU $fullver\n" if $verbose;
981 sub set_one_buildpri {
984 my $state = $pkg->{'state'};
985 my $name = $pkg->{'package'};
987 if ($state eq "Not-For-Us") {
988 print "$name: not suitable for this architecture. Skipping.\n";
990 } elsif ($state eq "Failed-Removed") {
991 print "$name: failed previously and doesn't need building. Skipping.\n";
994 if ( $build_priority ) {
995 $pkg->{$key} = $build_priority;
999 update_source_info($pkg);
1000 print "$name: set to build priority $build_priority\n" if $verbose;
1003 sub add_one_depwait {
1005 my $state = $pkg->{'state'};
1006 my $name = $pkg->{'package'};
1008 if ($state eq "Dep-Wait") {
1009 print "$name: merging with previously registered dependencies\n";
1012 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1013 print "$name: Warning: not registered for building previously, ".
1014 "but processing anyway.\n";
1017 if (isin( $state, qw<Installed Not-For-Us>)) {
1018 print "add_one_depwait: $name: skiping in state $state\n";
1022 if ($fail_reason =~ /^\s*$/ ||
1023 !parse_deplist( $fail_reason, 1 )) {
1024 print "$name: Bad dependency list\n";
1027 change_state( \$pkg, 'Dep-Wait' );
1028 $pkg->{'builder'} = $user;
1029 my $deplist = parse_deplist( $pkg->{'depends'} );
1030 my $new_deplist = parse_deplist( $fail_reason );
1031 # add new dependencies, maybe overwriting old entries
1032 foreach (keys %$new_deplist) {
1033 $deplist->{$_} = $new_deplist->{$_};
1035 $pkg->{'depends'} = build_deplist($deplist);
1036 log_ta( $pkg, "--dep-wait" ) unless $simulate;
1037 update_source_info($pkg) unless $simulate;
1038 print "$name: registered as waiting for dependencies\n" if $verbose || $simulate;
1041 sub set_one_update {
1043 $pkg->{'version'} =~ s/\+b[0-9]+$//;
1045 log_ta( $pkg, "--update" );
1046 update_source_info($pkg);
1049 # for sorting priorities and sections
1051 %prioval = ( required => -5,
1059 'debian-installer' => -199,
1080 localizations => -178,
1081 interpreters => -177,
1106 electronics => -152,
1112 foreach my $i (keys %sectval) {
1113 $sectval{"contrib/$i"} = $sectval{$i}+40;
1114 $sectval{"non-free/$i"} = $sectval{$i}+80;
1116 $sectval{'unknown'} = -165;
1120 sub sort_list_func {
1122 'C' => ['<->', sub { return $_[0]->{'calprio'}; }],
1123 'W' => ['<->', sub { return $_[0]->{'state_days'}; }],
1124 'P' => ['<->', sub { return ($_[0]->{'buildpri'}//0) + ($_[0]->{'permbuildpri'}//0); }],
1125 'p' => ['<=>', sub { return $prioval{$_[0]->{'priority'}//""}//0; }],
1126 's' => ['<=>', sub { return $sectval{$_[0]->{'section'}//""}//0; }],
1127 'n' => ['cmp', sub { return $_[0]->{'package'}; }],
1128 'b' => ['cmp', sub { return $_[0]->{'builder'}; }],
1129 'c' => ['<=>', sub { return ($_[0]->{'notes'}//"" =~ /^(out-of-date|partial)/) ? 0: ($_[0]->{'notes'}//"" =~ /^uncompiled/) ? 2 : 1; }],
1130 'S' => ['<->', sub { return isin($_[0]->{'priority'}, qw(required important standard)); }],
1131 'T' => ['<->', sub { return $_[0]->{'state_time'} % 86400;} ], # Fractions of a day
1134 foreach my $letter (split( //, $list_order )) {
1136 $r = (&{$map_funcs->{$letter}[1]}($b)//0 ) <=> (&{$map_funcs->{$letter}[1]}($a)//0 ) if $map_funcs->{$letter}[0] eq '<->';
1137 $r = (&{$map_funcs->{$letter}[1]}($a)//0 ) <=> (&{$map_funcs->{$letter}[1]}($b)//0 ) if $map_funcs->{$letter}[0] eq '<=>';
1138 $r = (&{$map_funcs->{$letter}[1]}($a)//"") cmp (&{$map_funcs->{$letter}[1]}($b)//"") if $map_funcs->{$letter}[0] eq 'cmp';
1139 return $r if $r != 0;
1144 sub calculate_prio {
1145 my $priomap = $yamlmap->{priority};
1147 my @s=split("/", $pkg->{'section'}//"");
1148 $pkg->{'component'} = $s[0] if $s[1];
1149 $pkg->{'component'} ||= 'main';
1150 $pkg->{'calprio'} = 0;
1151 foreach my $k (keys %{$priomap->{keys}}) {
1152 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1155 my $days = $pkg->{'state_days'};
1156 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1157 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1158 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1159 $pkg->{'calprio'} += $days * $scale;
1161 my $btime = max($pkg->{'anytime'}//0, $pkg->{'successtime'}//0);
1162 my $bhours = $btime ? int($btime/3600) : ($priomap->{'buildhours'}->{'default'} || 2);
1163 $bhours = $priomap->{'buildhours'}->{'min'} if $priomap->{'buildhours'}->{'min'} and $bhours < $priomap->{'buildhours'}->{'min'};
1164 $bhours = $priomap->{'buildhours'}->{'max'} if $priomap->{'buildhours'}->{'max'} and $bhours > $priomap->{'buildhours'}->{'max'};
1165 $scale = $priomap->{'buildhours'}->{'scale'} || 1;
1166 $pkg->{'calprio'} -= $bhours * $scale;
1168 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1169 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1177 return "" unless $t;
1179 my $min = int($t/60) % 60;
1180 my $hours = int($t / 3600);
1181 return sprintf("%d:%02d:%02d", $hours, $min, $sec) if $hours;
1182 return sprintf("%d:%02d", $min, $sec);
1189 if (ref($_[0]) eq 'CODE') {
1199 return $r unless $t;
1203 if (substr($t,0,1) eq '!') {
1207 return "" unless $r;
1210 return print_format($t, $pkg, $var);
1214 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
1217 my $printfmt = shift;
1223 Within an format string, the following values are allowed (need to be preceded by %).
1224 This can be combined to e.g.
1225 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
1228 c section (e.g. libs or utils)
1229 D in case of BD-Uninstallable the reason for the uninstallability
1231 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
1232 F in case of Failed the fail reason
1234 o time of last successful build (seconds)
1235 O time of last successful build (formated)
1238 q time of last build (seconds)
1239 Q time of last build (formated)
1240 r max time of last (successful) build (seconds)
1241 R max time of last (successful) build (formated)
1243 s Time in this state in full seconds since epoch
1244 t time of state change
1245 T time since state change
1246 u Builder (e.g. buildd_mipsel-rem)
1248 V full Package version (i.e. with +b.., = %v%{+b}B%B
1249 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
1251 %{Text}? print Text in case ? is not empty; ? is never printed
1252 %{!Text}? print Text in case ? is empty; ? is never printed
1253 Text could contain further %. To start with !, use %!
1257 return stringf($printfmt, (
1258 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
1259 'a' => make_fmt( $arch, $pkg, $var),
1260 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
1261 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
1262 'V' => make_fmt( sub { $pkg->{'binary_nmu_version'} ? $pkg->{'version'}."+b".$pkg->{'binary_nmu_version'} : $pkg->{'version'} }, $pkg, $var),
1263 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
1264 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
1265 'X' => make_fmt( sub {
1267 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
1268 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} && $pkg->{'previous_state'} =~ /^Failed/;
1269 $c .= ":bp{" . (($pkg->{'buildpri'}//0)+($pkg->{'permbuildpri'}//0)) . "}" if (($pkg->{'buildpri'}//0)+($pkg->{'permbuildpri'}//0));
1270 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
1271 $c .= ":calprio{". $pkg->{'calprio'}."}";
1272 $c .= ":days{". $pkg->{'state_days'}."}";
1275 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
1276 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
1277 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
1278 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
1279 return ""; }, $pkg, $var),
1280 'F' => make_fmt( sub { return "" unless $pkg->{'failed'};
1281 my $failed = $pkg->{'failed'};
1282 $failed =~ s/\\/\\\\/g;
1283 return $pkg->{'package'}."#".$arch."-failure\n ".
1284 join("\\0a",split("\n",$failed))."\\0a\n"; }, $pkg, $var),
1285 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
1286 return $pkg->{'package'}."#".$arch."-bd-problem\n".
1287 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
1288 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
1289 'd' => make_fmt( $pkg->{'distribution'}, $pkg, $var),
1290 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
1291 'T' => make_fmt( sub { return seconds2time(time() - floor(str2time($pkg->{'state_change'}))); }, $pkg, $var),
1292 'o' => make_fmt( $pkg->{'successtime'}, $pkg, $var),
1293 'O' => make_fmt( sub { return seconds2time ( $pkg->{'successtime'}); }, $pkg, $var),
1294 'q' => make_fmt( $pkg->{'anytime'}, $pkg, $var),
1295 'Q' => make_fmt( sub { return seconds2time ( $pkg->{'anytime'}); }, $pkg, $var),
1296 'r' => make_fmt( sub { my $c = max($pkg->{'successtime'}//0, $pkg->{'anytime'}//0); return $c if $c; return; }, $pkg, $var),
1297 'R' => make_fmt( sub { return seconds2time ( max($pkg->{'successtime'}//0, $pkg->{'anytime'}//0)); }, $pkg, $var),
1303 my( $name, $pkg, @list );
1308 my $db = get_all_source_info(state => $state, user => $user, list_min_age => $list_min_age);
1309 foreach $name (keys %$db) {
1310 next if $name =~ /^_/;
1311 push @list, calculate_prio($db->{$name});
1315 @list = grep { my $i = $_->{'component'}; grep { $i eq $_ } split /[, ]+/, $yamlmap->{"restrict"}{'component'} } @list;
1316 # extra depends / conflicts only from api 1 on
1317 @list = grep { !$_->{'extra_depends'} and !$_->{'extra_conflicts'} } @list if $api < 1 ;
1319 # first adjust ownprintformat, then set printformat accordingly
1320 $printformat ||= $yamlmap->{"format"}{$ownprintformat} if $ownprintformat;
1321 $printformat ||= $yamlmap->{"format"}{"default"}{$state};
1322 $printformat ||= $yamlmap->{"format"}{"default"}{"default"};
1323 undef $printformat if ($ownprintformat && $ownprintformat eq 'none');
1325 foreach $pkg (sort sort_list_func @list) {
1328 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
1330 $scnt{$pkg->{'state'}}++;
1333 print print_format("%c/%p_%v", $pkg, {});
1334 print print_format(": %S", $pkg, {})
1336 print print_format("%{ by }u%u", $pkg, {})
1337 if $pkg->{'state'} ne "Needs-Build";
1338 print print_format(" [%X]\n", $pkg, {});
1339 print " Reasons for failing:\n",
1340 join("\n ",split("\n",$pkg->{'failed'})), "\n"
1341 if $pkg->{'state'} =~ /^Failed/;
1342 print " Dependencies: $pkg->{'depends'}\n"
1343 if $pkg->{'state'} eq "Dep-Wait";
1344 print " Reasons for BD-Uninstallable:\n ",
1345 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
1346 if $pkg->{'state'} eq "BD-Uninstallable";
1347 print " Previous state was $pkg->{'previous_state'}\n"
1348 if $verbose && $pkg->{'previous_state'};
1349 print " No previous state recorded\n"
1350 if $verbose && !$pkg->{'previous_state'};
1351 print " State changed at $pkg->{'state_change'}\n"
1352 if $verbose && $pkg->{'state_change'};
1353 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
1354 if $verbose && $pkg->{'previous_state'};
1355 print " Previous failing reasons:\n ",
1356 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
1357 if $verbose && $pkg->{'old_failed'};
1359 $scnt{$pkg->{'state'}}++ if $state eq "all";
1361 if ($state eq "all" && !$printformat) {
1362 foreach (sort keys %scnt) {
1363 print "Total $scnt{$_} package(s) in state $_.\n";
1366 print "Total $cnt package(s)\n" unless $printformat;
1371 my( $name, $pkg, $key, $dist );
1372 my @firstkeys = qw(package version builder state section priority
1373 installed_version previous_state state_change);
1374 my @dists = $info_all_dists ? keys %distributions : ($distribution);
1375 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
1376 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
1377 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
1378 'state_change' => 'State-Change',
1379 'bd_problem' => 'BD-Problem',
1380 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
1381 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
1383 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
1384 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
1385 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days', 'state_time' => 'State-Time',
1386 'successtime' => 'Success-build-time',
1387 'anytime' => 'Build-time',
1388 'extra_depends' => 'Extra-Dependencies',
1389 'extra_conflicts' => 'Extra-Conflicts',
1390 'build_arch_all' => 'Build-Arch-All',
1393 foreach $name (@_) {
1394 $name =~ s/_.*$//; # strip version
1395 foreach $dist (@dists) {
1396 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1398 $pkg = get_readonly_source_info($name);
1399 if (!defined( $pkg )) {
1400 print "$pname: not registered\n";
1403 $pkg = calculate_prio($pkg);
1406 foreach $key (@firstkeys) {
1407 next if !defined $pkg->{$key};
1408 my $val = $pkg->{$key};
1410 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1412 my $print_key = $key;
1413 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
1414 printf " %-20s: %s\n", $print_key, $val;
1416 foreach $key (sort keys %$pkg) {
1417 next if isin( $key, @firstkeys );
1418 my $val = $pkg->{$key};
1419 next if !defined($val);
1421 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1423 my $print_key = $key;
1424 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
1425 printf " %-20s: %s\n", $print_key, $val;
1431 sub forget_packages {
1433 my( $name, $pkg, $key, $data );
1435 foreach $name (@_) {
1436 $name =~ s/_.*$//; # strip version
1437 $pkg = get_source_info($name);
1438 if (!defined( $pkg )) {
1439 print "$name: not registered\n";
1444 foreach $key (sort keys %$pkg) {
1445 my $val = $pkg->{$key};
1448 $data .= sprintf " %-20s: %s\n", $key, $val;
1450 send_mail( $conf::db_maint,
1451 "$name deleted from DB " . table_name() . " " . $distribution,
1452 "The package '$name' has been deleted from the database ".
1454 "Data registered about the deleted package:\n".
1455 "$data\n" ) if $conf::db_maint;
1456 change_state( \$pkg, 'deleted' );
1457 log_ta( $pkg, "--forget" );
1458 del_source_info($name);
1459 print "$name: deleted from database\n" if $verbose;
1464 $dbh->do("DELETE from " . user_table_name() .
1465 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
1471 print "Reading ASCII database from $file..." if $verbose >= 1;
1472 open( my $fh, '<', $file ) or
1473 die "Can't open database $file: $!\n";
1475 local($/) = ""; # read in paragraph mode
1477 my( %thispkg, $name );
1479 s/\n[ \t]+/\376\377/g; # fix continuation lines
1480 s/\376\377\s*\376\377/\376\377/og;
1482 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
1483 my ($key, $val) = ($1, $2);
1485 $key =~ tr/A-Z/a-z/;
1486 $val =~ s/\376\377/\n/g;
1487 $thispkg{$key} = $val;
1489 check_entry( \%thispkg );
1491 if (exists($thispkg{'package'})) {
1492 update_source_info(\%thispkg);
1494 elsif(exists($thispkg{'user'})) {
1495 # user in import, username in database.
1496 $dbh->do('INSERT INTO ' . user_table_name() .
1497 ' (username, distribution, last_seen)' .
1498 ' values (?, ?, ?)',
1499 undef, $thispkg{'user'}, $distribution,
1500 $thispkg{'last_seen'})
1501 or die $dbh->errstr;
1505 print "done\n" if $verbose >= 1;
1512 return if $op_mode eq "manual-edit"; # no checks then
1514 # check for required fields
1515 if (exists $pkg->{'user'}) {
1518 if (!exists $pkg->{'package'}) {
1519 print STDERR "Bad entry: ",
1520 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
1521 die "Database entry lacks package or username field\n";
1523 # if no State: field, generate one (for old db compat)
1524 if (!exists($pkg->{'state'})) {
1526 exists $pkg->{'failed'} ? 'Failed' : 'Building';
1528 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
1529 die "Database entry for $pkg->{'package'} lacks Version: field\n";
1532 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
1533 if !isin( $pkg->{'state'},
1534 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
1535 Failed Failed-Removed Not-For-Us BD-Uninstallable Auto-Not-For-Us
1541 my($name,$pkg,$key);
1543 print "Writing ASCII database to $file..." if $verbose >= 1;
1544 open( my $fh, '>', $file ) or
1545 die "Can't open export $file: $!\n";
1547 my $db = get_all_source_info();
1548 foreach $name (keys %$db) {
1549 next if $name =~ /^_/;
1550 my $pkg = $db->{$name};
1551 foreach $key (keys %{$pkg}) {
1552 my $val = $pkg->{$key};
1553 next if !defined($val);
1556 $val =~ s/^ +$/ ./mg;
1557 print $fh "$key: $val\n";
1562 print "done\n" if $verbose >= 1;
1568 my $newstate = shift;
1569 my $state = \$pkg->{'state'};
1571 return if defined($$state) and $$state eq $newstate;
1572 $pkg->{'previous_state'} = $$state if defined($$state);
1573 $pkg->{'state_change'} = $curr_date;
1574 $pkg->{'do_state_change'} = 1;
1576 if (defined($$state) and $$state eq 'Failed') {
1577 $pkg->{'old_failed'} =
1578 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
1579 ($pkg->{'failed'} // ""). "\n" .
1580 ($pkg->{'old_failed'} // "");
1581 delete $pkg->{'failed'};
1583 if (defined($$state) and $$state eq 'BD-Uninstallable') {
1584 delete $pkg->{'bd_problem'};
1586 $$state = $newstate;
1592 my $dist = $distribution;
1596 $prevstate = $pkg->{'previous_state'};
1597 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
1598 "changed from $prevstate to $pkg->{'state'} ".
1599 "by $real_user as $user";
1602 printf "update transactions: %s %s %s %s %s %s %s %s\n",
1603 $pkg->{'package'}, $distribution,
1604 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
1608 $dbh->do('INSERT INTO ' . transactions_table_name() .
1609 ' (package, distribution, version, action, ' .
1610 ' prevstate, state, real_user, set_user, time) ' .
1611 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
1612 undef, $pkg->{'package'}, $distribution,
1613 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
1614 $real_user, $user, 'now()') or die $dbh->errstr;
1616 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
1617 $str .= " (with --override)"
1619 $mail_logs .= "$str\n";
1626 my $subject = shift;
1629 my $from = $conf::db_maint;
1630 my $domain = $conf::buildd_domain;
1632 $from .= "\@$domain" if $from !~ /\@/;
1634 $to .= '@' . $domain if $to !~ /\@/;
1635 $text =~ s/^\.$/../mg;
1636 local $SIG{'PIPE'} = 'IGNORE';
1637 open( my $pipe, '|-', "$conf::mailprog -oem $to" )
1638 or die "Can't open pipe to $conf::mailprog: $!\n";
1640 print $pipe "From: $from\n";
1641 print $pipe "Subject: $subject\n\n";
1642 print $pipe "$text\n";
1646 # for parsing input to dep-wait
1652 return $verify ? 0 : \%result unless $deps;
1653 foreach (split( /\s*,\s*/, $deps )) {
1655 # verification requires > starting prompts, no | crap
1656 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
1661 my @alts = split( /\s*\|\s*/, $_ );
1662 # Anything with an | is ignored, as it can be configured on a
1663 # per-buildd basis what will be installed
1664 next if $#alts != 0;
1667 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
1668 warn( "parse_deplist: bad dependency $_\n" );
1671 my($dep, $rel, $relv) = ($1, $3, $4);
1672 $rel = ">>" if defined($rel) and $rel eq ">";
1673 $result{$dep}->{'package'} = $dep;
1674 if ($rel && $relv) {
1675 $result{$dep}->{'rel'} = $rel;
1676 $result{$dep}->{'version'} = $relv;
1679 return 1 if $verify;
1687 foreach $key (keys %$list) {
1688 $result .= ", " if $result;
1690 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
1691 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
1698 return "" unless $_[0];
1699 return Dpkg::Deps::parse($_[0], ("reduce_arch" => 1, "host_arch" => $_[1]))->dump();
1702 sub wb_edos_builddebcheck {
1703 # Copyright (C) 2008 Ralf Treinen <treinen@debian.org>
1704 # This program is free software: you can redistribute it and/or modify it under
1705 # the terms of the GNU General Public License as published by the Free Software
1706 # Foundation, version 2 of the License.
1707 # integrated into wanna-builds code by Andreas Barth 2010
1710 my $sourceprefix="source---";
1711 my $architecture=$args->{'arch'};
1712 my $edosoptions = "-failures -explain -quiet";
1713 my $packagefiles = $args->{'pkgs'};
1714 my $sourcesfile = $args->{'src'};
1717 foreach my $packagefile (@$packagefiles) {
1718 open(my $fh,'<', $packagefile);
1720 next unless /^Architecture/;
1721 next if /^Architecture:\s*all/;
1722 /Architecture:\s*([^\s]*)/;
1723 if ($packagearch eq "") {
1725 } elsif ( $packagearch ne $1) {
1726 return "Package file contains different architectures: $packagearch, $1";
1732 if ( $architecture eq "" ) {
1733 if ( $packagearch eq "" ) {
1734 return "No architecture option given, " .
1735 "and no non-all architecture found in the Packages file";
1737 $architecture = $packagearch;
1740 if ( $packagearch ne "" & $architecture ne $packagearch) {
1741 return "Architecture option is $architecture ".
1742 "but the package file contains architecture $packagearch";
1746 print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n";
1747 open(my $result_cmd, '-|',
1748 "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles));
1754 while (<$result_cmd>) {
1755 # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED
1756 # source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing:
1757 # - libltdl-dev (>= 2.2.6a-2)
1758 # source---libcanberra (= 0.22-1~bpo50+1): FAILED
1759 # source---libcanberra (= 0.22-1~bpo50+1) depends on missing:
1761 # - libltdl7-dev (>= 2.2.6)
1764 s/^(\s*)$sourceprefix(.*)depends on/$1$2build-depends on/o;
1765 s/^(\s*)$sourceprefix(.*) and (.*) conflict/$1$2 build-conflicts with $3/o;
1768 if (/^$sourceprefix(.*) \(.*\): FAILED/o) {
1769 $result->{$binpkg} = $explanation if $binpkg;
1772 } elsif (/^(depwait---.*) \(.*\): FAILED/o) {
1773 $result->{$binpkg} = $explanation if $binpkg;
1776 } else { # else something broken is happening
1777 #print "ignoring $_\n";
1784 $result->{$binpkg} = $explanation if $binpkg;
1790 sub call_edos_depcheck {
1791 return if $simulate_edos;
1793 my $srcs = $args->{'srcs'};
1796 return if defined ($distributions{$distribution}{noadw}) && not defined $args->{'depwait'};
1798 # We need to check all of needs-build, as any new upload could make
1799 # something in needs-build have uninstallable deps
1800 # We also check everything in bd-uninstallable, as any new upload could
1801 # make that work again
1802 my (%interesting_packages, %interesting_packages_depwait);
1803 my $db = get_all_source_info();
1804 foreach $key (keys %$db) {
1805 my $pkg = $db->{$key};
1806 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/) and not defined ($distributions{$distribution}{noadw})) {
1807 $interesting_packages{$key} = undef;
1809 if (defined $pkg and isin($pkg->{'state'}, qw/Dep-Wait/) and defined $args->{'depwait'}) {
1810 $interesting_packages_depwait{$key} = undef;
1811 # we always check for BD-Uninstallability in depwait - could be that depwait is satisfied but package is uninstallable
1812 $interesting_packages{$key} = undef unless defined ($distributions{$distribution}{noadw});
1816 #print "I would look at these sources with edos-depcheck:\n";
1817 #print join " ", keys %interesting_packages,"\n";
1818 return unless %interesting_packages || %interesting_packages_depwait;
1820 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-XXXXX";
1821 use File::Temp qw/ tempfile /;
1822 my ($SOURCES, $tmpfile) = tempfile( $tmpfile_pattern, UNLINK => 1 );
1823 for my $key (keys %interesting_packages) {
1824 my $pkg = $db->{$key};
1825 # we print the source files as binary ones (with "source---"-prefixed),
1826 # so we can try if these "binary" packages are installable.
1827 # If such a "binary" package is installable, the corresponding source package is buildable.
1828 print $SOURCES "Package: source---$key\n";
1829 print $SOURCES "Version: $pkg->{'version'}\n";
1830 my $t = &filterarch($srcs->{$key}{'dep'} || $srcs->{$key}{'depends'}, $arch);
1831 my $tt = &filterarch($pkg->{'extra_depends'}, $arch);
1832 $t = $t ? ($tt ? "$t, $tt" : $t) : $tt;
1833 print $SOURCES "Depends: $t\n" if $t;
1834 my $u = &filterarch($srcs->{$key}{'conf'} || $srcs->{$key}{'conflicts'}, $arch);
1835 my $uu = &filterarch($pkg->{'extra_conflicts'}, $arch);
1836 $u = $u ? ($uu ? "$u, $uu" : $u) : $uu;
1837 print $SOURCES "Conflicts: $u\n" if $u;
1838 print $SOURCES "Architecture: all\n";
1839 print $SOURCES "\n";
1841 for my $key (keys %interesting_packages_depwait) {
1842 my $pkg = $db->{$key};
1843 # we print the source files as binary ones (with "depwait---"-prefixed),
1844 # so we can try if these "binary" packages are installable.
1845 # If such a "binary" package is installable, the corresponding source package goes out of depwait
1846 print $SOURCES "Package: depwait---$key\n";
1847 print $SOURCES "Version: $pkg->{'version'}\n";
1848 print $SOURCES "Depends: $pkg->{'depends'}\n";
1849 print $SOURCES "Architecture: all\n";
1850 print $SOURCES "\n";
1854 my $edosresults = wb_edos_builddebcheck({'arch' => $args->{'arch'}, 'pkgs' => $args->{'pkgs'}, 'src' => $tmpfile});
1855 if (ref($edosresults) eq 'HASH') {
1856 foreach my $key (grep { $_ !~ /^depwait---/ } keys %$edosresults) {
1857 if (exists $interesting_packages{$key}) {
1858 $interesting_packages{$key} = $edosresults->{$key};
1860 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
1863 foreach my $key (grep { $_ =~ /^depwait---/ } keys %$edosresults) {
1864 $key =~ /^depwait---(.*)/ and $key = $1;
1865 if (exists $interesting_packages_depwait{$key}) {
1866 $interesting_packages_depwait{$key} = $edosresults->{"depwait---".$key};
1868 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
1872 # if $edosresults isn't an hash, then something went wrong and the string is the error message
1873 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
1874 "all packages have installable build-dependencies."
1879 for my $key (keys %interesting_packages) {
1880 next if defined $interesting_packages_depwait{$key};
1881 my $pkg = $db->{$key};
1883 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
1884 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
1885 my $problemchange = ($interesting_packages{$key}//"") ne ($pkg->{'bd_problem'}//"");
1887 if (defined $interesting_packages{$key}) {
1888 change_state( \$pkg, 'BD-Uninstallable' );
1889 $pkg->{'bd_problem'} = $interesting_packages{$key};
1891 change_state( \$pkg, 'Needs-Build' );
1894 if ($problemchange) {
1895 if (defined $interesting_packages{$key}) {
1896 $pkg->{'bd_problem'} = $interesting_packages{$key};
1900 log_ta( $pkg, "--merge-all (edos)" ) unless $simulate;
1901 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) to $pkg->{'state'}\n" if $verbose || $simulate;
1903 if ($change || $problemchange) {
1904 update_source_info($pkg) unless $simulate;
1908 for my $key (keys %interesting_packages_depwait) {
1909 if ($interesting_packages_depwait{$key}) {
1910 print "dep-wait for $key ($args->{'arch'}) not fullfiled yet\n" if $verbose || $simulate;
1913 my $pkg = $db->{$key};
1914 if (defined $interesting_packages{$key}) {
1915 change_state( \$pkg, 'BD-Uninstallable' );
1916 $pkg->{'bd_problem'} = $interesting_packages{$key};
1918 change_state( \$pkg, 'Needs-Build' );
1920 log_ta( $pkg, "edos_depcheck: depwait" ) unless $simulate;
1921 update_source_info($pkg) unless $simulate;
1922 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) from dep-wait to $pkg->{'state'}\n" if $verbose || $simulate;
1928 ($prgname = $0) =~ s,^.*/,,;
1930 Usage: $prgname <options...> <package_version...>
1932 -v, --verbose: Verbose execution.
1933 -A arch: Architecture this operation is for.
1934 --take: Take package for building [default operation]
1935 -f, --failed: Record in database that a build failed due to
1936 deficiencies in the package (that aren't fixable without a new
1938 -u, --uploaded: Record in the database that the packages build
1939 correctly and were uploaded.
1940 -n, --no-build: Record in the database that the packages aren't
1941 desired for this architecture and shouldn't appear in listings even
1942 if they're out of date.
1943 --dep-wait: Record in the database that the packages are waiting
1944 for some source dependencies to become available
1945 --binNMU num: Schedule a re-build of the package with unchanged source, but
1946 a new version number (source-version + "+b<num>")
1947 --give-back: Mark a package as ready to build that is in state Building,
1948 Built or Build-Attempted. To give back a package in state Failed, use
1949 --override. This command will actually put the package in state
1950 BD-Uninstallable, until the installability of its Build-Dependencies
1951 were verified. This happens at each call of --merge-all, usually
1953 -i SRC_PKG, --info SRC_PKG: Show information for source package
1954 -l STATE, --list=STATE: List all packages in state STATE; can be
1955 combined with -U to restrict to a specific user; STATE can
1957 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
1958 source dependency list
1959 (used with -f, --dep-wait, and --binNMU)
1960 -o, --override: Override another user's lock on a package, i.e.
1961 take it over; a notice mail will be sent to the other user
1962 -U USER, --user=USER: select user name for which listings should
1963 apply, if not given all users are listed.
1964 if -l is missing, set user name to be entered in db; usually
1965 automatically choosen
1966 --import FILE: Import database from a ASCII file FILE
1967 --export FILE: Export database to a ASCII file FILE
1969 The remaining arguments (depending on operation) usually start with
1970 "name_version", the trailer is ignored. This allows to pass the names
1971 of .dsc files, for which file name completion can be used.
1972 --merge-packages and --merge-quinn take Package/quin--diff file names
1973 on the command line or read stdin. --list needs nothing more on the
1974 command line. --info takes source package names (without version).
1979 sub pkg_version_eq {
1981 my $version = shift;
1984 if (defined $pkg->{'binary_nmu_version'}) and
1985 version_compare(binNMU_version($pkg->{'version'},
1986 $pkg->{'binary_nmu_version'}),'=', $version);
1987 return version_compare( $pkg->{'version'}, "=", $version );
1991 return '"' . $arch . $schema_suffix . '".packages';
1994 sub user_table_name {
1995 return '"' . $arch . $schema_suffix . '".users';
1998 sub transactions_table_name {
1999 return '"' . $arch . $schema_suffix . '".transactions';
2002 sub pkg_history_table_name {
2003 return '"' . $arch . $schema_suffix . '".pkg_history';
2006 sub get_readonly_source_info {
2008 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2009 my $q = "SELECT rel, priority, state_change, permbuildpri, section, buildpri, failed, state, binary_nmu_changelog, bd_problem, version, package, distribution, installed_version, notes, 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"
2010 . ", (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"
2011 . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2012 . ", extra_depends, extra_conflicts, build_arch_all"
2013 . " FROM " . table_name()
2014 . ' WHERE package = ? AND distribution = ?';
2015 my $pkg = $dbh->selectrow_hashref( $q,
2016 undef, $name, $distribution);
2020 sub get_source_info {
2022 return get_readonly_source_info($name) if $simulate;
2023 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 ' .
2024 table_name() . ' WHERE package = ? AND distribution = ?' .
2026 undef, $name, $distribution);
2030 sub get_all_source_info {
2033 my $q = "SELECT rel, priority, state_change, permbuildpri, section, buildpri, failed, state, binary_nmu_changelog, bd_problem, version, package, distribution, installed_version, notes, 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"
2034 # . ", (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"
2035 # . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2036 . ", successtime.build_time as successtime, anytime.build_time as anytime, extra_depends, extra_conflicts"
2037 . " FROM " . table_name()
2039 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." where result = 'successful' order by package, distribution, timestamp "
2040 . " ) as successtime using (package, distribution) "
2042 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." order by package, distribution, timestamp desc"
2043 . " ) as anytime using (package, distribution) "
2046 if ($distribution) {
2047 my @dists = split(/[, ]+/, $distribution);
2048 $q .= ' AND ( distribution = ? '.(' OR distribution = ? ' x $#dists).' )';
2049 foreach my $d ( @dists ) {
2053 if ($options{state} && uc($options{state}) ne "ALL") {
2054 $q .= ' AND upper(state) = ? ';
2055 push @args, uc($options{state});
2058 if ($options{user} && uc($options{state}) ne "NEEDS-BUILD") { # if it's NEEDS-BUILD, we don't look at users
2059 #this basically means "this user, or no user at all":
2060 $q .= " AND (builder = ? OR upper(state) = 'NEEDS-BUILD')";
2061 push @args, $options{user};
2064 if ($options{list_min_age} && $options{list_min_age} > 0) {
2065 $q .= ' AND age(state_change) > ? ';
2066 push @args, $options{list_min_age} . " days";
2069 if ($options{list_min_age} && $options{list_min_age} < 0) {
2070 $q .= ' AND age(state_change) < ? ';
2071 push @args, -$options{list_min_age} . " days";
2074 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2078 sub show_distribution_architectures {
2079 my $q = 'SELECT distribution, spacecat_all(architecture) AS architectures '.
2080 'FROM distribution_architectures '.
2081 'GROUP BY distribution';
2082 my $rows = $dbh->selectall_hashref($q, 'distribution');
2083 foreach my $name (keys %$rows) {
2084 print $name.': '.$rows->{$name}->{'architectures'}."\n";
2088 sub show_distribution_aliases {
2089 foreach my $alias (keys %distribution_aliases) {
2090 print $alias.': '.$distribution_aliases{$alias}."\n";
2094 sub update_source_info {
2096 $pkg->{'extra_depends'} = $extra_depends if defined $extra_depends;
2097 undef $pkg->{'extra_depends'} unless $pkg->{'extra_depends'};
2098 $pkg->{'extra_conflicts'} = $extra_conflicts if defined $extra_conflicts;
2099 undef $pkg->{'extra_conflicts'} unless $pkg->{'extra_conflicts'};
2100 print Dumper $pkg if $verbose and $simulate;
2101 return if $simulate;
2103 my $pkg2 = get_source_info($pkg->{'package'});
2104 if (! defined $pkg2)
2106 add_source_info($pkg);
2109 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2114 'installed_version = ?, ' .
2115 'previous_state = ?, ' .
2116 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2120 'old_failed = ?, ' .
2121 'binary_nmu_version = ?, ' .
2122 'binary_nmu_changelog = ?, ' .
2123 'permbuildpri = ?, ' .
2127 'extra_depends = ?, ' .
2128 'extra_conflicts = ?, ' .
2130 'WHERE package = ? AND distribution = ?',
2136 $pkg->{'installed_version'},
2137 $pkg->{'previous_state'},
2141 $pkg->{'old_failed'},
2142 $pkg->{'binary_nmu_version'},
2143 $pkg->{'binary_nmu_changelog'},
2144 $pkg->{'permbuildpri'},
2148 $pkg->{'extra_depends'},
2149 $pkg->{'extra_conflicts'},
2150 $pkg->{'bd_problem'},
2152 $distribution) or die $dbh->errstr;
2155 sub add_source_info {
2156 return if $simulate;
2158 $dbh->do('INSERT INTO ' . table_name() .
2159 ' (package, distribution) values (?, ?)',
2160 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2163 sub del_source_info {
2164 return if $simulate;
2166 $dbh->do('DELETE FROM ' . table_name() .
2167 ' WHERE package = ? AND distribution = ?',
2168 undef, $name, $distribution) or die $dbh->errstr;
2173 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2174 user_table_name() . ' WHERE username = ? AND distribution = ?',
2175 undef, $name, $distribution);
2179 sub update_user_info {
2180 return if $simulate;
2182 $dbh->do('UPDATE ' . user_table_name() .
2183 ' SET last_seen = now() WHERE username = ?' .
2184 ' AND distribution = ?',
2185 undef, $user, $distribution)
2186 or die $dbh->errstr;
2191 return if $simulate;
2193 $dbh->do('INSERT INTO ' . user_table_name() .
2194 ' (username, distribution, last_seen)' .
2195 ' values (?, ?, now())',
2196 undef, $user, $distribution)
2197 or die $dbh->errstr;
2201 return if $simulate;
2202 $dbh->do('LOCK TABLE ' . table_name() .
2203 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;
2207 # parts the array $_[0] and $_[1] and returns the sub-array (modifies the original one)
2210 my $separator = shift;
2211 while($args->[0] && $args->[0] ne $separator) {
2212 push @ret, shift @$args;
2214 shift @$args if @$args;
2221 my $db = get_all_source_info();
2222 my $binary = $srcs->{'_binary'};
2225 foreach my $name (keys %$srcs) {
2226 next if $name eq '_binary';
2228 # state = installed, out-of-date, uncompiled, packages-arch-specific, overwritten-by-arch-all, arch-not-in-arch-list, arch-all-only
2229 my $pkgs = $srcs->{$name};
2230 next if isin($pkgs->{'status'}, qw <arch-all-only>);
2231 my $pkg = $db->{$name};
2234 next SRCS if $pkgs->{'status'} eq 'packages-arch-specific';
2235 my $logstr = sprintf("merge-v3 %s %s_%s (%s, %s):", $vars->{'time'}, $name, $pkgs->{'version'}, $vars->{'arch'}, $vars->{'suite'});
2237 # does at least one binary exist in the database and is more recent - if so, we're probably just outdated, ignore the source package
2238 for my $bin (@{$pkgs->{'binary'}}) {
2239 if ($binary->{$bin} and vercmp($pkgs->{'version'}, $binary->{$bin}->{'version'}) < 0) {
2240 print "$logstr skipped because binaries (assumed to be) overwritten\n" if $verbose || $simulate;
2244 $pkg->{'package'} = $name;
2246 $pkg->{'version'} ||= "";
2247 $pkg->{'state'} ||= "";
2248 my $logstr = sprintf("merge-v3 %s %s_%s", $vars->{'time'}, $name, $pkgs->{'version'}).
2249 ($pkgs->{'binnmu'} ? ";b".$pkgs->{'binnmu'} : "").
2250 sprintf(" (%s, %s, previous: %s", $vars->{'arch'}, $vars->{'suite'}, $pkg->{'version'}//"").
2251 ($pkg->{'binary_nmu_version'} ? ";b".$pkg->{'binary_nmu_version'} : "").
2252 ", $pkg->{'state'}".($pkg->{'notes'} ? "/".$pkg->{'notes'} : "")."):";
2254 if (isin($pkgs->{'status'}, qw (installed related)) && $pkgs->{'version'} eq $pkg->{'version'} && ($pkgs->{'binnmu'}//0) < int($pkg->{'binary_nmu_version'}//0)) {
2255 $pkgs->{'status'} = 'out-of-date';
2257 if (isin($pkgs->{'status'}, qw <installed related arch-not-in-arch-list packages-arch-specific overwritten-by-arch-all arch-all-only>)) {
2259 my $tstate = {'installed' => 'Installed', 'related' => 'Installed',
2260 'arch-not-in-arch-list' => 'Auto-Not-For-Us', 'packages-arch-specific' => 'Auto-Not-For-Us', 'overwritten-by-arch-all' => 'Auto-Not-For-Us', 'arch-all-only' => 'Auto-Not-For-Us',
2261 }->{$pkgs->{'status'}};
2262 next if isin( $pkg->{'state'}, qw<Not-For-Us Failed Failed-Removed Dep-Wait Dep-Wait-Removed>) && isin( $tstate, qw<Auto-Not-For-Us>);
2263 # if the package is currently current, the status is Installed, not not-for-us
2264 if ($pkg->{'state'} ne $tstate) {
2265 change_state( \$pkg, $tstate);
2266 if (isin( $tstate, qw<Installed>)) {
2267 delete $pkg->{'depends'};
2268 delete $pkg->{'extra_depends'};
2269 delete $pkg->{'extra_conflicts'};
2273 my $attrs = { 'version' => 'version', 'installed_version' => 'version', 'binary_nmu_version' => 'binnmu', 'section' => 'section', 'priority' => 'priority' };
2274 foreach my $k (keys %$attrs) {
2275 next if isin( $tstate, qw<Auto-Not-For-Us>) && isin( $k, qw<installed_version binary_nmu_version>);
2276 if (($pkg->{$k}//"") ne ($pkgs->{$attrs->{$k}}//"")) {
2277 $pkg->{$k} = $pkgs->{$attrs->{$k}};
2281 if (isin($pkgs->{'status'}, qw <related packages-arch-specific overwritten-by-arch-all arch-not-in-arch-list arch-all-only>)) {
2282 my $tnotes = $pkgs->{'status'};
2283 if (($pkg->{'notes'}//"") ne $tnotes) {
2284 $pkg->{'notes'} = $tnotes;
2289 print "$logstr set to $tstate/".($pkg->{'notes'}//"")."\n" if $verbose || $simulate;
2290 log_ta( $pkg, "--merge-v3: $tstate" ) unless $simulate;
2291 update_source_info($pkg) unless $simulate;
2296 # only uncompiled / out-of-date are left, so check if anything new
2297 if (!(isin($pkgs->{'status'}, qw (uncompiled out-of-date)))) {
2298 print "$logstr package in unknown state: $pkgs->{'status'}\n";
2301 next if $pkgs->{'version'} eq $pkg->{'version'} and $pkgs->{'binnmu'}//0 >= int($pkg->{'binary_nmu_version'}//0);
2302 next if $pkgs->{'version'} eq $pkg->{'version'} and !isin( $pkg->{'state'}, qw(Installed));
2303 next if isin( $pkg->{'state'}, qw(Not-For-Us Failed-Removed));
2305 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
2306 send_mail( $pkg->{'builder'},
2307 "new version of $name (dist=$distribution)",
2308 "As far as I'm informed, you're currently building the package $name\n".
2309 "in version $pkg->{'version'}.\n\n".
2310 "Now there's a new source version $pkgs->{'version'}. If you haven't finished\n".
2311 "compiling $name yet, you can stop it to save some work.\n".
2312 "Just to inform you...\n".
2313 "(This is an automated message)\n" ) unless $simulate;
2314 print "$logstr new version while building $pkg->{'version'} -- sending mail to builder ($pkg->{'builder'})\n"
2315 if $verbose || $simulate;
2317 change_state( \$pkg, 'Needs-Build');
2318 $pkg->{'notes'} = $pkgs->{'status'};
2319 $pkg->{'version'} = $pkgs->{'version'};
2320 $pkg->{'section'} = $pkgs->{'section'};
2321 $pkg->{'priority'} = $pkgs->{'priority'};
2322 $pkg->{'dep'} = $pkgs->{'depends'};
2323 $pkg->{'conf'} = $pkgs->{'conflicts'};
2324 delete $pkg->{'builder'};
2325 delete $pkg->{'binary_nmu_version'} unless $pkgs->{'binnmu'};
2326 delete $pkg->{'binary_nmu_changelog'} unless $pkgs->{'binnmu'};
2327 delete $pkg->{'buildpri'};
2328 log_ta( $pkg, "--merge-v3: needs-build" ) unless $simulate;
2329 update_source_info($pkg) unless $simulate;
2330 print "$logstr set to needs-builds\n" if $simulate || $verbose;
2333 foreach my $name (keys %$db) {
2334 next if $srcs->{$name};
2335 my $pkg = $db->{$name};
2336 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkg->{'version'} ($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'state'}):";
2337 # package disappeared - delete
2338 change_state( \$pkg, 'deleted' );
2339 log_ta( $pkg, "--merge-v3: deleted" ) unless $simulate;
2340 print "$logstr deleted from database\n" if $verbose || $simulate;
2341 del_source_info($name) unless $simulate;
2342 delete $db->{$name};