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, $opt_create_db,
69 $info_all_dists, $arch,
70 $category, %catval, %short_category,
71 $short_date, $list_min_age, $dbbase, @curr_time,
72 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
73 $printformat, $ownprintformat, $privmode, $extra_depends, $extra_conflicts,
74 %distributions, %distribution_aliases
76 our $Pas = '/org/buildd.debian.org/etc/packages-arch-specific/Packages-arch-specific';
78 our $simulate_edos = 0;
79 our $api = undef; # allow buildds to specify an different api
80 our $recorduser = undef;
83 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
88 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
89 $short_date = strftime("%m/%d/%y",@curr_time);
92 %short_category = ( u => "uploaded-fixed-pkg",
99 c => "compiler-error",
102 # set mode of operation based on command line switch. Should be used
103 # by GetOptions below.
104 sub _set_mode_set { $op_mode = "set-$_[0]" }
105 sub _set_mode { $op_mode = "$_[0]" }
107 sub _option_deprecated { warn "Option $_[0] is deprecated" }
110 # this is not supported by all operations (yet)!
111 'simulate' => \$simulate,
112 'simulate-edos' => \$simulate_edos,
113 'simulate-all' => sub { $simulate = 1; $simulate_edos = 1; },
116 die "$api too large" unless $api <= 1;
118 'verbose|v' => \$verbose,
119 'override|o' => \$opt_override,
120 'create-db' => \$opt_create_db,
121 'correct-compare' => \$WannaBuild::opt_correct_version_cmp,
123 # TODO: remove after buildds no longer pass to wanna-build
124 'no-propagation|N' => \&_option_deprecated,
125 'no-down-propagation|D' => \&_option_deprecated,
128 'building|take' => \&_set_mode_set,
129 'failed|f' => \&_set_mode_set,
130 'uploaded|u' => \&_set_mode_set,
131 'not-for-us|no-build|n' => \&_set_mode_set,
132 'built' => \&_set_mode_set,
133 'attempted' => \&_set_mode_set,
134 'needs-build|give-back' => \&_set_mode_set,
135 'dep-wait' => \&_set_mode_set,
136 'update' => \&_set_mode_set,
137 'forget' => \&_set_mode,
138 'forget-user' => \&_set_mode,
139 'merge-v3' => \&_set_mode,
140 'info|i' => \&_set_mode,
141 'binary-nmu|binNMU=i' => sub {
145 'permanent-build-priority|perm-build-priority=i' => sub {
147 $build_priority = $_[1];
149 'build-priority=i' => sub {
151 $build_priority = $_[1];
156 die "Unknown state to list: $list_state\n"
157 if not $list_state ~~ [
158 qw( needs-build building uploaded built
159 build-attempted failed installed
160 dep-wait not-for-us auto-not-for-us
161 all failed-removed install-wait
162 reupload-wait bd-uninstallable ) ];
166 when ( [qw< a all >] ) {
170 when ('o') { $distribution = 'oldstable'; }
171 when ('s') { $distribution = 'stable'; }
172 when ('t') { $distribution = 'testing'; }
173 when ('u') { $distribution = 'unstable'; }
178 die "Bad ordering character\n"
179 if $list_order !~ /^[PSpsncbCWT]+$/;
181 'message|m=s' => \$fail_reason,
182 'database|b=s' => sub {
183 warn "database is deprecated, please use 'arch' instead.\n";
184 $conf::dbbase = $_[1];
186 'arch|A=s' => \$arch,
187 'user|U=s' => \$user,
188 'category|c=s' => sub {
190 $category = $short_category{$category}
191 if exists $short_category{$category};
192 die "Unknown category: $category\n"
193 if not $category ~~ [ values %short_category ];
195 'min-age|a=i' => \$list_min_age,
196 'max-age=i' => \$list_min_age,
197 'format=s' => \$printformat,
198 'own-format=s' => \$ownprintformat,
200 'extra-depends=s' => \$extra_depends,
201 'extra-conflicts=s' => \$extra_conflicts,
204 'export' => sub { _set_mode(@_); $export_to = $_[1]; },
205 'import' => sub { _set_mode(@_); $import_from = $_[1]; },
206 'manual-edit' => \&_set_mode,
207 'distribution-architectures' => \&_set_mode,
208 'distribution-aliases' => \&_set_mode,
216 $dbh->disconnect or warn $dbh->errstr;
220 $distribution ||= "sid";
221 if ($distribution eq 'any-priv') {
223 $distribution = 'any';
225 if ($distribution eq 'any-unpriv') {
227 $distribution = 'any';
230 my $schema_suffix = '';
231 $recorduser //= (not -t and $user//"" =~ /^buildd_/);
232 if ((isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !$recorduser && !($privmode)) || $simulate) {
233 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
234 die "FATAL: Cannot open database: $DBI::errstr\n";
235 $schema_suffix = '_public';
239 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
240 die "FATAL: Cannot open database: $DBI::errstr\n";
243 # TODO: This shouldn't be needed, file a bug.
244 $dbh->{pg_server_prepare} = 0;
246 $dbh->begin_work or die $dbh->errstr;
248 my $q = 'SELECT distribution, public, auto_dep_wait, build_dep_resolver, suppress_successful_logs, archive FROM distributions';
249 my $rows = $dbh->selectall_hashref($q, 'distribution');
250 foreach my $name (keys %$rows) {
251 $distributions{$name} = {};
252 $distributions{$name}->{'noadw'} = 1 if !($rows->{$name}->{'auto_dep_wait'});
253 $distributions{$name}->{'hidden'} = 1 if !($rows->{$name}->{'public'});
254 $distributions{$name}->{'build_dep_resolver'} = $rows->{$name}->{'build_dep_resolver'} if $rows->{$name}->{'build_dep_resolver'};
255 $distributions{$name}->{'suppress_successful_logs'} = $rows->{$name}->{'suppress_successful_logs'} if $rows->{$name}->{'suppress_successful_logs'};
256 $distributions{$name}->{'archive'} = $rows->{$name}->{'archive'} if $rows->{$name}->{'archive'};
259 $q = 'SELECT alias, distribution FROM distribution_aliases';
260 $rows = $dbh->selectall_hashref($q, 'alias');
261 foreach my $name (keys %$rows) {
262 $distribution_aliases{$name} = $rows->{$name}->{'distribution'};
264 $distribution = $distribution_aliases{$distribution} if (isin($distribution, keys %distribution_aliases));
266 $op_mode = $category ? "set-failed" : "set-building"
267 if !$op_mode; # default operation
268 undef $distribution if $distribution eq 'any';
270 my @dists = split(/[, ]+/, $distribution);
271 foreach my $dist (@dists) {
272 die "Bad distribution '$distribution'\n"
273 if !isin($dist, keys %distributions);
276 if (!isin ( $op_mode, qw(list) ) && ( !$distribution || $distribution =~ /[ ,]/)) {
277 die "multiple distributions are only allowed for list";
280 # If they didn't specify an arch, try to get it from database name which
281 # is in the form of $arch/build-db
282 # This is for backwards compatibity with older versions that didn't
283 # specify the arch yet.
284 $conf::dbbase =~ m#^([^/]+)#;
287 # TODO: Check that it's an known arch (for that dist), and give
291 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
292 $version =~ s/(^\$| \$ .*$)//g;
293 print "wanna-build $version for $distribution on $arch\n";
296 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
297 merge-packages manual-edit
298 merge-sources distribution-architectures
299 distribution-aliases))) {
300 warn "No packages given.\n";
304 $real_user = (getpwuid($<))[0];
305 die "Can't determine your user name\n"
306 if $op_mode ne "list" && !$user &&
307 !($user = $real_user);
310 if ($op_mode eq "set-failed" && !$category) {
311 print "Enter reason for failing (end with '.' alone on ".
316 last if $line eq ".\n";
317 $fail_reason .= $line;
319 chomp( $fail_reason );
320 } elsif ($op_mode eq "set-dep-wait") {
321 print "Enter dependencies (one line):\n";
323 while( !$line && !eof(STDIN) ) {
324 chomp( $line = <STDIN> );
326 die "No dependencies given\n" if !$line;
327 $fail_reason = $line;
328 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
329 print "Enter changelog entry (one line):\n";
331 while( !$line && !eof(STDIN) ) {
332 chomp( $line = <STDIN> );
334 die "No changelog entry given\n" if !$line;
335 $fail_reason = $line;
340 my $yamldir = "/org/wanna-build/etc/yaml";
341 my @files = ('wanna-build.yaml');
342 if ((getpwuid($>))[7]) { push (@files, ((getpwuid($>))[7])."/.wanna-build.yaml"); }
343 if ($user && $user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
344 if ($user) { push ( @files, "$user.yaml"); }
345 foreach my $file (@files) {
346 my $cfile = File::Spec->rel2abs( $file, $yamldir );
347 if ($verbose >= 2) { print "Trying to read $file ($cfile) ...\n"; }
348 next unless -f $cfile;
349 if ($verbose >= 2) { print "Read $file ($cfile) ...\n"; }
350 my $m = YAML::Tiny->read( $cfile )->[0];
351 $yamlmap = merge($m, $yamlmap);
354 die "FATAL: no configuration found\n";
356 $list_order = $yamlmap->{"list-order"}{$list_state} if !$list_order and $list_state;
357 $list_order ||= $yamlmap->{"list-order"}{'default'};
358 $api //= $yamlmap->{"api"};
366 if ($mail_logs && $conf::log_mail) {
367 send_mail( $conf::log_mail,
368 "wanna-build $distribution state changes $curr_date",
369 "State changes at $curr_date for distribution ".
370 "$distribution:\n\n$mail_logs\n" );
378 SWITCH: foreach ($op_mode) {
380 add_packages( $1, @ARGV );
384 list_packages( $list_state );
388 info_packages( @ARGV );
391 /^forget-user/ && do {
392 die "This operation is restricted to admin users\n"
393 if (defined @conf::admin_users and
394 !isin( $real_user, @conf::admin_users));
395 forget_users( @ARGV );
399 forget_packages( @ARGV );
403 die "This operation is restricted to admin users\n"
404 if (defined @conf::admin_users and !isin( $real_user, @conf::admin_users) and !$simulate);
405 # call with installed-packages+ . installed-sources+ [ . available-for-build-packages* [ . consider-as-installed-source* ] ]
406 # in case available-for-build-packages is not specified, installed-packages are used
407 lock_table() unless $simulate;
408 my $replacemap = { '%ARCH%' => $arch, '%SUITE%' => $distribution };
409 map { my $k = $_; grep { $k =~ s,$_,$replacemap->{$_}, } keys %{$replacemap}; $_ = $k; } @ARGV;
410 my @ipkgs = &parse_argv( \@ARGV, '.');
411 my @isrcs = &parse_argv( \@ARGV, '.');
412 my @bpkgs = &parse_argv( \@ARGV, '.');
413 my @psrcs = &parse_argv( \@ARGV, '.');
415 my $srcs = WB::QD::readsourcebins($arch, $Pas, \@isrcs, \@ipkgs);
417 my $psrcs = WB::QD::readsourcebins($arch, $Pas, \@psrcs, []);
418 foreach my $k (keys %$$psrcs) {
419 next if $$srcs->{$k};
420 my $pkg = $$psrcs->{$k};
421 $pkg->{'status'} = 'related';
425 parse_all_v3($$srcs, {'arch' => $arch, 'suite' => $distribution, 'time' => $curr_date});
426 @bpkgs = @ipkgs unless @bpkgs;
427 call_edos_depcheck( {'arch' => $arch, 'pkgs' => \@bpkgs, 'srcs' => $$srcs, 'depwait' => 1 });
431 die "This operation is restricted to admin users\n"
432 if (defined @conf::admin_users and
433 !isin( $real_user, @conf::admin_users));
434 $dbh->do("DELETE from " . table_name() .
435 " WHERE distribution = ?", undef,
439 read_db( $import_from );
443 export_db( $export_to );
446 /^distribution-architectures/ && do {
447 show_distribution_architectures();
450 /^distribution-aliases/ && do {
451 show_distribution_aliases();
455 die "Unexpected operation mode $op_mode\n";
458 my $userinfo = get_user_info($user);
459 if (!defined $userinfo)
461 add_user_info($user);
465 update_user_info($user);
471 my $newstate = shift;
472 my( $package, $name, $version, $ok, $reason );
474 foreach $package (@_) {
475 $package =~ s,^.*/,,; # strip path
476 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
477 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
478 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
479 ($name,$version) = ($1,$2);
482 warn "$package: can't extract package name and version ".
487 if ($op_mode eq "set-building") {
488 add_one_building( $name, $version );
490 elsif ($op_mode eq "set-built") {
491 add_one_built( $name, $version );
493 elsif ($op_mode eq "set-attempted") {
494 add_one_attempted( $name, $version );
496 elsif ($op_mode eq "set-uploaded") {
497 add_one_uploaded( $name, $version );
499 elsif ($op_mode eq "set-failed") {
500 add_one_failed( $name, $version );
502 elsif ($op_mode eq "set-not-for-us") {
503 add_one_notforus( $name, $version );
505 elsif ($op_mode eq "set-needs-build") {
506 add_one_needsbuild( $name, $version );
508 elsif ($op_mode eq "set-dep-wait") {
509 add_one_depwait( $name, $version );
511 elsif ($op_mode eq "set-build-priority") {
512 set_one_buildpri( $name, $version, 'buildpri' );
514 elsif ($op_mode eq "set-permanent-build-priority") {
515 set_one_buildpri( $name, $version, 'permbuildpri' );
517 elsif ($op_mode eq "set-binary-nmu") {
518 set_one_binnmu( $name, $version );
520 elsif ($op_mode eq "set-update") {
521 set_one_update( $name, $version );
526 sub add_one_building {
532 my $pkg = get_source_info($name);
534 if ($pkg->{'state'} eq "Not-For-Us") {
536 $reason = "not suitable for this architecture";
538 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
540 $reason = "not all source dependencies available yet";
542 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
544 $reason = "source dependencies are not installable";
546 elsif ($pkg->{'state'} eq "Uploaded" &&
547 (version_lesseq($version, $pkg->{'version'}))) {
549 $reason = "already uploaded by $pkg->{'builder'}";
550 $reason .= " (in newer version $pkg->{'version'})"
551 if !version_eq($pkg, $version);
553 elsif ($pkg->{'state'} eq "Installed" &&
554 version_less($version,$pkg->{'version'})) {
556 print "$name: Warning: newer version $pkg->{'version'} ".
557 "already installed, but overridden.\n";
561 $reason = "newer version $pkg->{'version'} already in ".
562 "archive; doesn't need rebuilding";
563 print "$name: Note: If the following is due to an epoch ",
564 " change, use --override\n";
567 elsif ($pkg->{'state'} eq "Installed" &&
568 pkg_version_eq($pkg,$version)) {
570 $reason = "is up-to-date in the archive; doesn't need rebuilding";
572 elsif ($pkg->{'state'} eq "Needs-Build" &&
573 version_less($version,$pkg->{'version'})) {
575 print "$name: Warning: newer version $pkg->{'version'} ".
576 "needs building, but overridden.";
580 $reason = "newer version $pkg->{'version'} needs building, ".
584 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
585 if (version_less($pkg->{'version'},$version)) {
586 print "$name: Warning: Older version $pkg->{'version'} ",
587 "is being built by $pkg->{'builder'}\n";
588 if ($pkg->{'builder'} ne $user) {
589 send_mail( $pkg->{'builder'},
590 "package takeover in newer version",
591 "You are building package '$name' in ".
592 "version $version\n".
593 "(as far as I'm informed).\n".
594 "$user now has taken the newer ".
595 "version $version for building.".
596 "You can abort the build if you like.\n" );
601 print "User $pkg->{'builder'} had already ",
602 "taken the following package,\n",
603 "but overriding this as you request:\n";
604 send_mail( $pkg->{'builder'}, "package takeover",
605 "The package '$name' (version $version) that ".
606 "was taken by you\n".
607 "has been taken over by $user\n" );
609 elsif ($pkg->{'builder'} eq $user) {
610 print "$name: Note: already taken by you.\n";
611 print "$name: ok\n" if $verbose;
616 $reason = "already taken by $pkg->{'builder'}";
617 $reason .= " (in newer version $pkg->{'version'})"
618 if !version_eq($pkg->{'version'}, $version);
622 elsif ($pkg->{'state'} =~ /^Failed/ &&
623 pkg_version_eq($pkg, $version)) {
625 print "The following package previously failed ",
626 "(by $pkg->{'builder'})\n",
627 "but overriding this as you request:\n";
628 send_mail( $pkg->{'builder'}, "failed package takeover",
629 "The package '$name' (version $version) that ".
631 "and has failed previously has been taken over ".
633 if $pkg->{'builder'} ne $user;
637 $reason = "build of $version failed previously:\n ";
638 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
639 $reason .= "\nalso the package doesn't need builing"
640 if $pkg->{'state'} eq 'Failed-Removed';
647 if ($pkg->{'binary_nmu_version'}) {
648 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
649 "$pkg->{'binary_nmu_changelog'}\n";
652 print "$name: Warning: Previous version failed!\n"
653 if $pkg->{'previous_state'} =~ /^Failed/ ||
654 $pkg->{'state'} =~ /^Failed/;
656 print "$name: $ok\n" if $verbose;
659 print " - status: ok\n";
660 printf " - pkg-ver: %s_%s\n", $name, $version;
661 print " - binNMU: $pkg->{'binary_nmu_version'}\n" if $pkg->{'binary_nmu_version'};
662 print " - extra-changelog: $pkg->{'binary_nmu_changelog'}\n" if $pkg->{'binary_nmu_changelog'} && $pkg->{'binary_nmu_version'};
663 print " - extra-depends: $pkg->{'extra_depends'}\n" if $pkg->{'extra_depends'};
664 print " - extra-conflicts: $pkg->{'extra_conflicts'}\n" if $pkg->{'extra_conflicts'};
665 print " - archive: $distributions{$distribution}->{'archive'}\n" if $distributions{$distribution}->{'archive'};
666 print " - build_dep_resolver: $distributions{$distribution}->{'build_dep_resolver'}\n" if $distributions{$distribution}->{'build_dep_resolver'};
667 print " - arch_all: $pkg->{'build_arch_all'}\n" if $pkg->{'build_arch_all'};
668 print " - suppress_successful_logs: $distributions{$distribution}->{'suppress_successful_logs'}\n" if $distributions{$distribution}->{'suppress_successful_logs'};
670 change_state( \$pkg, 'Building' );
671 $pkg->{'package'} = $name;
672 $pkg->{'version'} = $version;
673 $pkg->{'builder'} = $user;
674 log_ta( $pkg, "--take" );
675 update_source_info($pkg);
679 print "$name: NOT OK!\n $reason\n";
681 print "- $name:\n - status: not ok\n - reason: \"$reason\"\n";
686 sub add_one_attempted {
689 my $pkg = get_source_info($name);
691 if (!defined($pkg)) {
692 print "$name: not registered yet.\n";
696 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
697 print "$name: not taken for building (state is $pkg->{'state'}). ",
701 if ($pkg->{'builder'} ne $user) {
702 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
705 elsif ( !pkg_version_eq($pkg, $version) ) {
706 print "$name: version mismatch ".
707 "$(pkg->{'version'} ".
708 "by $pkg->{'builder'})\n";
712 change_state( \$pkg, 'Build-Attempted' );
713 log_ta( $pkg, "--attempted" );
714 update_source_info($pkg);
715 print "$name: registered as uploaded\n" if $verbose;
721 my $pkg = get_source_info($name);
723 if (!defined($pkg)) {
724 print "$name: not registered yet.\n";
728 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
729 print "$name: not taken for building (state is $pkg->{'state'}). ",
733 if ($pkg->{'builder'} ne $user) {
734 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
737 elsif ( !pkg_version_eq($pkg, $version) ) {
738 print "$name: version mismatch ".
739 "$(pkg->{'version'} ".
740 "by $pkg->{'builder'})\n";
743 change_state( \$pkg, 'Built' );
744 log_ta( $pkg, "--built" );
745 update_source_info($pkg);
746 print "$name: registered as built\n" if $verbose;
749 sub add_one_uploaded {
752 my $pkg = get_source_info($name);
754 if (!defined($pkg)) {
755 print "$name: not registered yet.\n";
759 if ($pkg->{'state'} eq "Uploaded" &&
760 pkg_version_eq($pkg,$version)) {
761 print "$name: already uploaded\n";
764 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
765 print "$name: not taken for building (state is $pkg->{'state'}). ",
769 if ($pkg->{'builder'} ne $user) {
770 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
773 # strip epoch -- buildd-uploader used to go based on the filename.
774 # (to remove at some point)
776 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
777 $version =~ s/^\d+://; # for command line use
778 if ($pkg->{'binary_nmu_version'} ) {
779 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
780 if (!version_eq( $nmuver, $version )) {
781 print "$name: version mismatch ($nmuver registered). ",
785 } elsif (!version_eq($pkgver, $version)) {
786 print "$name: version mismatch ($pkg->{'version'} registered). ",
791 change_state( \$pkg, 'Uploaded' );
792 log_ta( $pkg, "--uploaded" );
793 update_source_info($pkg);
794 print "$name: registered as uploaded\n" if $verbose;
801 my $pkg = get_source_info($name);
803 if (!defined($pkg)) {
804 print "$name: not registered yet.\n";
807 $state = $pkg->{'state'};
809 if ($state eq "Not-For-Us") {
810 print "$name: not suitable for this architecture anyway. Skipping.\n";
813 elsif ($state eq "Failed-Removed") {
814 print "$name: failed previously and doesn't need building. Skipping.\n";
817 elsif ($state eq "Installed") {
818 print "$name: Is already installed in archive. Skipping.\n";
821 elsif ($pkg->{'builder'} &&
822 (($user ne $pkg->{'builder'}) &&
823 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
824 print "$name: not taken by you, but by ".
825 "$pkg->{'builder'}. Skipping.\n";
828 elsif ( !pkg_version_eq($pkg, $version) ) {
829 print "$name: version mismatch ".
830 "$(pkg->{'version'} ".
831 "by $pkg->{'builder'})\n";
836 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
838 $cat = $short_category{$cat} if exists $short_category{$cat};
839 if (!isin( $cat, values %short_category )) {
840 print "$name: Warning: unknown category $cat; discarded\n";
843 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
846 if ($state eq "Needs-Build") {
847 print "$name: Warning: not registered for building previously, ".
848 "but processing anyway.\n";
850 elsif ($state eq "Uploaded") {
851 print "$name: Warning: marked as uploaded previously, ".
852 "but processing anyway.\n";
854 elsif ($state eq "Dep-Wait") {
855 print "$name: Warning: marked as waiting for dependencies, ".
856 "but processing anyway.\n";
858 elsif ($state eq "BD-Uninstallable") {
859 print "$name: Warning: marked as having uninstallable build-dependencies, ".
860 "but processing anyway.\n";
862 elsif ($state eq "Failed") {
863 print "$name: already registered as failed; will append new message\n"
865 print "$name: already registered as failed; changing category\n"
869 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
870 defined $pkg->{'failed_category'} &&
871 $pkg->{'failed_category'} ne $cat) {
872 (my $action = $cat) =~ s/-/ /;
873 $fail_reason .= "\n$short_date: $action";
876 change_state( \$pkg, 'Failed' );
877 $pkg->{'builder'} = $user;
878 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
879 $pkg->{'failed'} .= $fail_reason;
880 $pkg->{'failed_category'} = $cat if $cat;
881 if (defined $pkg->{'permbuildpri'}) {
882 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
884 delete $pkg->{'buildpri'};
886 log_ta( $pkg, "--failed" );
887 update_source_info($pkg);
888 print "$name: registered as failed\n" if $verbose;
891 sub add_one_notforus {
894 my $pkg = get_source_info($name);
896 if ($pkg->{'state'} eq 'Not-For-Us') {
897 # reset Not-For-Us state in case it's called twice; this is
898 # the only way to get a package out of this state...
899 # There is no really good state in which such packages should
900 # be put :-( So use Failed for now.
901 change_state( \$pkg, 'Failed' );
902 $pkg->{'package'} = $name;
903 $pkg->{'failed'} = "Was Not-For-Us previously";
904 delete $pkg->{'builder'};
905 delete $pkg->{'depends'};
906 log_ta( $pkg, "--no-build(rev)" );
907 print "$name: now not unsuitable anymore\n";
909 send_mail( $conf::notforus_maint,
910 "$name moved out of Not-For-Us state",
911 "The package '$name' has been moved out of the Not-For-Us ".
913 "It should probably also be removed from ".
914 "Packages-arch-specific or\n".
915 "the action was wrong.\n" )
916 if $conf::notforus_maint;
919 change_state( \$pkg, 'Not-For-Us' );
920 $pkg->{'package'} = $name;
921 delete $pkg->{'builder'};
922 delete $pkg->{'depends'};
923 delete $pkg->{'buildpri'};
924 delete $pkg->{'binary_nmu_version'};
925 delete $pkg->{'binary_nmu_changelog'};
926 log_ta( $pkg, "--no-build" );
927 print "$name: registered as unsuitable\n" if $verbose;
929 send_mail( $conf::notforus_maint,
930 "$name set to Not-For-Us",
931 "The package '$name' has been set to state Not-For-Us ".
933 "It should probably also be added to ".
934 "Packages-arch-specific or\n".
935 "the Not-For-Us state is wrong.\n" )
936 if $conf::notforus_maint;
938 update_source_info($pkg);
941 sub add_one_needsbuild {
945 my $pkg = get_source_info($name);
947 if (!defined($pkg)) {
948 print "$name: not registered; can't give back.\n";
951 $state = $pkg->{'state'};
953 if ($state eq "BD-Uninstallable") {
955 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
957 change_state( \$pkg, 'Needs-Build' );
958 delete $pkg->{'builder'};
959 delete $pkg->{'depends'};
960 log_ta( $pkg, "--give-back" );
961 update_source_info($pkg);
962 print "$name: given back\n" if $verbose;
966 print "$name: has uninstallable build-dependencies. Skipping\n",
967 " (use --override to clear dependency list and ",
968 "give back anyway)\n";
972 elsif ($state eq "Dep-Wait") {
974 print "$name: Forcing source dependency list to be cleared\n";
977 print "$name: waiting for source dependencies. Skipping\n",
978 " (use --override to clear dependency list and ",
979 "give back anyway)\n";
983 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
984 print "$name: not taken for building (state is $state).";
986 print "\n$name: Forcing give-back\n";
989 print " Skipping.\n";
993 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
994 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
996 print "$name: not taken by you, but by ".
997 "$pkg->{'builder'}. Skipping.\n";
1000 if (!pkg_version_eq($pkg, $version)) {
1001 print "$name: version mismatch ($pkg->{'version'} registered). ",
1005 if (!defined $distributions{$distribution}{noadw}) {
1006 change_state( \$pkg, 'BD-Uninstallable' );
1007 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1009 change_state( \$pkg, 'Needs-Build' );
1011 $pkg->{'builder'} = undef;
1012 $pkg->{'depends'} = undef;
1013 log_ta( $pkg, "--give-back" );
1014 update_source_info($pkg);
1015 print "$name: given back\n" if $verbose;
1018 sub set_one_binnmu {
1020 my $version = shift;
1021 my $pkg = get_source_info($name);
1024 if (!defined($pkg)) {
1025 print "$name: not registered; can't register for binNMU.\n";
1028 my $db_ver = $pkg->{'version'};
1030 if (!version_eq($db_ver, $version)) {
1031 print "$name: version mismatch ($db_ver registered). ",
1035 $state = $pkg->{'state'};
1037 if (defined $pkg->{'binary_nmu_version'}) {
1038 if ($binNMUver == 0) {
1039 change_state( \$pkg, 'Installed' );
1040 delete $pkg->{'builder'};
1041 delete $pkg->{'depends'};
1042 delete $pkg->{'binary_nmu_version'};
1043 delete $pkg->{'binary_nmu_changelog'};
1044 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1045 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1048 $pkg->{'binary_nmu_version'} = $binNMUver;
1049 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1050 $pkg->{'notes'} = 'out-of-date';
1051 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1052 if (defined $pkg->{'permbuildpri'});
1053 if (defined $distributions{$distribution}{noadw}) {
1054 change_state( \$pkg, 'Installed' );
1056 change_state( \$pkg, 'BD-Uninstallable' );
1059 log_ta( $pkg, "--binNMU" );
1060 update_source_info($pkg);
1062 } elsif ($binNMUver == 0) {
1063 print "${name}_$version: no scheduled binNMU to cancel.\n";
1067 if ($state ne 'Installed') {
1068 print "${name}_$version: not installed; can't register for binNMU.\n";
1072 my $fullver = binNMU_version($version,$binNMUver);
1073 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1075 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1079 if (!defined $distributions{$distribution}{noadw}) {
1080 change_state( \$pkg, 'BD-Uninstallable' );
1081 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1085 change_state( \$pkg, 'Needs-Build' );
1087 delete $pkg->{'builder'};
1088 delete $pkg->{'depends'};
1089 $pkg->{'binary_nmu_version'} = $binNMUver;
1090 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1091 $pkg->{'notes'} = 'out-of-date';
1092 log_ta( $pkg, "--binNMU" );
1093 update_source_info($pkg);
1094 print "${name}: registered for binNMU $fullver\n" if $verbose;
1097 sub set_one_buildpri {
1099 my $version = shift;
1101 my $pkg = get_source_info($name);
1104 if (!defined($pkg)) {
1105 print "$name: not registered; can't set priority.\n";
1108 $state = $pkg->{'state'};
1110 if ($state eq "Not-For-Us") {
1111 print "$name: not suitable for this architecture. Skipping.\n";
1113 } elsif ($state eq "Failed-Removed") {
1114 print "$name: failed previously and doesn't need building. Skipping.\n";
1117 if (!pkg_version_eq($pkg, $version)) {
1118 print "$name: version mismatch ($pkg->{'version'} registered). ",
1122 if ( $build_priority == 0 ) {
1123 delete $pkg->{'buildpri'}
1124 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1125 and $pkg->{'buildpri'} == $pkg->{$key};
1126 delete $pkg->{$key};
1128 $pkg->{'buildpri'} = $build_priority
1129 if $key eq 'permbuildpri';
1130 $pkg->{$key} = $build_priority;
1132 update_source_info($pkg);
1133 print "$name: set to build priority $build_priority\n" if $verbose;
1136 sub add_one_depwait {
1138 my $version = shift;
1140 my $pkg = get_source_info($name);
1142 if (!defined($pkg)) {
1143 print "$name: not registered yet.\n";
1146 $state = $pkg->{'state'};
1148 if ($state eq "Dep-Wait") {
1149 print "$name: merging with previously registered dependencies\n";
1152 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1153 print "$name: Warning: not registered for building previously, ".
1154 "but processing anyway.\n";
1156 elsif ($state eq "Not-For-Us") {
1157 print "$name: not suitable for this architecture anyway. Skipping.\n";
1160 elsif ($state eq "Failed-Removed") {
1161 print "$name: failed previously and doesn't need building. Skipping.\n";
1164 elsif ($state eq "Installed") {
1165 print "$name: Is already installed in archive. Skipping.\n";
1168 elsif ($state eq "Uploaded") {
1169 print "$name: Is already uploaded. Skipping.\n";
1172 elsif ($pkg->{'builder'} &&
1173 $user ne $pkg->{'builder'}) {
1174 print "$name: not taken by you, but by ".
1175 "$pkg->{'builder'}. Skipping.\n";
1178 elsif ( !pkg_version_eq($pkg,$version)) {
1179 print "$name: version mismatch ".
1180 "($pkg->{'version'} ".
1181 "by $pkg->{'builder'})\n";
1184 elsif ($fail_reason =~ /^\s*$/ ||
1185 !parse_deplist( $fail_reason, 1 )) {
1186 print "$name: Bad dependency list\n";
1189 change_state( \$pkg, 'Dep-Wait' );
1190 $pkg->{'builder'} = $user;
1191 if (defined $pkg->{'permbuildpri'}) {
1192 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1194 delete $pkg->{'buildpri'};
1196 my $deplist = parse_deplist( $pkg->{'depends'} );
1197 my $new_deplist = parse_deplist( $fail_reason );
1198 # add new dependencies, maybe overwriting old entries
1199 foreach (keys %$new_deplist) {
1200 $deplist->{$_} = $new_deplist->{$_};
1202 $pkg->{'depends'} = build_deplist($deplist);
1203 log_ta( $pkg, "--dep-wait" );
1204 update_source_info($pkg);
1205 print "$name: registered as waiting for dependencies\n" if $verbose;
1208 sub set_one_update {
1210 my $version = shift;
1211 my $pkg = get_source_info($name);
1213 if (!defined($pkg)) {
1214 print "$name: not registered yet.\n";
1217 $pkg->{'version'} =~ s/\+b[0-9]+$//;
1219 log_ta( $pkg, "--update" );
1220 update_source_info($pkg);
1224 # for sorting priorities and sections
1226 %prioval = ( required => -5,
1234 'debian-installer' => -199,
1255 localizations => -178,
1256 interpreters => -177,
1281 electronics => -152,
1287 foreach my $i (keys %sectval) {
1288 $sectval{"contrib/$i"} = $sectval{$i}+40;
1289 $sectval{"non-free/$i"} = $sectval{$i}+80;
1291 $sectval{'unknown'} = -165;
1293 %catval = ( "none" => -20,
1294 "uploaded-fixed-pkg" => -19,
1295 "fix-expected" => -18,
1296 "reminder-sent" => -17,
1297 "nmu-offered" => -16,
1301 "compiler-error" => -12 );
1304 sub sort_list_func {
1306 'C' => ['<->', sub { return $_[0]->{'calprio'}; }],
1307 'W' => ['<->', sub { return $_[0]->{'state_days'}; }],
1308 'P' => ['<->', sub { return $_[0]->{'buildpri'}; }],
1309 'p' => ['<=>', sub { return $prioval{$_[0]->{'priority'}//""}//0; }],
1310 's' => ['<=>', sub { return $sectval{$_[0]->{'section'}//""}//0; }],
1311 'n' => ['cmp', sub { return $_[0]->{'package'}; }],
1312 'b' => ['cmp', sub { return $_[0]->{'builder'}; }],
1313 'c' => ['<=>', sub { return ($_[0]->{'notes'}//"" =~ /^(out-of-date|partial)/) ? 0: ($_[0]->{'notes'}//"" =~ /^uncompiled/) ? 2 : 1; }],
1314 'f' => ['<=>', sub { return $catval{ $_[0]->{'failed_category'} ? $_[0]->{'failed_category'}: "none" }; }],
1315 'S' => ['<->', sub { return isin($_[0]->{'priority'}, qw(required important standard)); }],
1316 'T' => ['<->', sub { return $_[0]->{'state_time'} % 86400;} ], # Fractions of a day
1319 foreach my $letter (split( //, $list_order )) {
1321 $r = (&{$map_funcs->{$letter}[1]}($b)//0 ) <=> (&{$map_funcs->{$letter}[1]}($a)//0 ) if $map_funcs->{$letter}[0] eq '<->';
1322 $r = (&{$map_funcs->{$letter}[1]}($a)//0 ) <=> (&{$map_funcs->{$letter}[1]}($b)//0 ) if $map_funcs->{$letter}[0] eq '<=>';
1323 $r = (&{$map_funcs->{$letter}[1]}($a)//"") cmp (&{$map_funcs->{$letter}[1]}($b)//"") if $map_funcs->{$letter}[0] eq 'cmp';
1324 return $r if $r != 0;
1329 sub calculate_prio {
1330 my $priomap = $yamlmap->{priority};
1332 my @s=split("/", $pkg->{'section'});
1333 $pkg->{'component'} = $s[0] if $s[1];
1334 $pkg->{'component'} ||= 'main';
1335 $pkg->{'calprio'} = 0;
1336 foreach my $k (keys %{$priomap->{keys}}) {
1337 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1340 my $days = $pkg->{'state_days'};
1341 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1342 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1343 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1344 $pkg->{'calprio'} += $days * $scale;
1346 my $btime = max($pkg->{'anytime'}//0, $pkg->{'successtime'}//0);
1347 my $bhours = $btime ? int($btime/3600) : ($priomap->{'buildhours'}->{'default'} || 2);
1348 $bhours = $priomap->{'buildhours'}->{'min'} if $priomap->{'buildhours'}->{'min'} and $bhours < $priomap->{'buildhours'}->{'min'};
1349 $bhours = $priomap->{'buildhours'}->{'max'} if $priomap->{'buildhours'}->{'max'} and $bhours > $priomap->{'buildhours'}->{'max'};
1350 $scale = $priomap->{'buildhours'}->{'scale'} || 1;
1351 $pkg->{'calprio'} -= $bhours * $scale;
1353 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1354 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1362 return "" unless $t;
1364 my $min = int($t/60) % 60;
1365 my $hours = int($t / 3600);
1366 return sprintf("%d:%02d:%02d", $hours, $min, $sec) if $hours;
1367 return sprintf("%d:%02d", $min, $sec);
1374 if (ref($_[0]) eq 'CODE') {
1384 return $r unless $t;
1388 if (substr($t,0,1) eq '!') {
1392 return "" unless $r;
1395 return print_format($t, $pkg, $var);
1399 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
1402 my $printfmt = shift;
1408 Within an format string, the following values are allowed (need to be preceded by %).
1409 This can be combined to e.g.
1410 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
1413 c section (e.g. libs or utils)
1414 D in case of BD-Uninstallable the reason for the uninstallability
1416 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
1417 F in case of Failed the fail reason
1419 o time of last successful build (seconds)
1420 O time of last successful build (formated)
1423 q time of last build (seconds)
1424 Q time of last build (formated)
1425 r max time of last (successful) build (seconds)
1426 R max time of last (successful) build (formated)
1428 s Time in this state in full seconds since epoch
1429 t time of state change
1430 T time since state change
1431 u Builder (e.g. buildd_mipsel-rem)
1433 V full Package version (i.e. with +b.., = %v%{+b}B%B
1434 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
1436 %{Text}? print Text in case ? is not empty; ? is never printed
1437 %{!Text}? print Text in case ? is empty; ? is never printed
1438 Text could contain further %. To start with !, use %!
1442 return stringf($printfmt, (
1443 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
1444 'a' => make_fmt( $arch, $pkg, $var),
1445 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
1446 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
1447 'V' => make_fmt( sub { $pkg->{'binary_nmu_version'} ? $pkg->{'version'}."+b".$pkg->{'binary_nmu_version'} : $pkg->{'version'} }, $pkg, $var),
1448 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
1449 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
1450 'X' => make_fmt( sub {
1452 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
1453 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} && $pkg->{'previous_state'} =~ /^Failed/;
1454 $c .= ":bp{" . $pkg->{'buildpri'} . "}" if defined $pkg->{'buildpri'};
1455 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
1456 $c .= ":calprio{". $pkg->{'calprio'}."}";
1457 $c .= ":days{". $pkg->{'state_days'}."}";
1460 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
1461 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
1462 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
1463 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
1464 return ""; }, $pkg, $var),
1465 'F' => make_fmt( sub { return "" unless $pkg->{'failed'};
1466 my $failed = $pkg->{'failed'};
1467 $failed =~ s/\\/\\\\/g;
1468 return $pkg->{'package'}."#".$arch."-failure\n ".
1469 join("\\0a",split("\n",$failed))."\\0a\n"; }, $pkg, $var),
1470 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
1471 return $pkg->{'package'}."#".$arch."-bd-problem\n".
1472 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
1473 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
1474 'd' => make_fmt( $pkg->{'distribution'}, $pkg, $var),
1475 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
1476 'T' => make_fmt( sub { return seconds2time(time() - floor(str2time($pkg->{'state_change'}))); }, $pkg, $var),
1477 'o' => make_fmt( $pkg->{'successtime'}, $pkg, $var),
1478 'O' => make_fmt( sub { return seconds2time ( $pkg->{'successtime'}); }, $pkg, $var),
1479 'q' => make_fmt( $pkg->{'anytime'}, $pkg, $var),
1480 'Q' => make_fmt( sub { return seconds2time ( $pkg->{'anytime'}); }, $pkg, $var),
1481 'r' => make_fmt( sub { my $c = max($pkg->{'successtime'}//0, $pkg->{'anytime'}//0); return $c if $c; return; }, $pkg, $var),
1482 'R' => make_fmt( sub { return seconds2time ( max($pkg->{'successtime'}//0, $pkg->{'anytime'}//0)); }, $pkg, $var),
1488 my( $name, $pkg, @list );
1493 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
1494 foreach $name (keys %$db) {
1495 next if $name =~ /^_/;
1496 push @list, calculate_prio($db->{$name});
1500 @list = grep { my $i = $_->{'component'}; grep { $i eq $_ } split /[, ]+/, $yamlmap->{"restrict"}{'component'} } @list;
1501 # extra depends / conflicts only from api 1 on
1502 @list = grep { !$_->{'extra_depends'} and !$_->{'extra_conflicts'} } @list if $api < 1 ;
1504 # first adjust ownprintformat, then set printformat accordingly
1505 $printformat ||= $yamlmap->{"format"}{$ownprintformat} if $ownprintformat;
1506 $printformat ||= $yamlmap->{"format"}{"default"}{$state};
1507 $printformat ||= $yamlmap->{"format"}{"default"}{"default"};
1508 undef $printformat if ($ownprintformat && $ownprintformat eq 'none');
1510 foreach $pkg (sort sort_list_func @list) {
1512 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
1514 $scnt{$pkg->{'state'}}++;
1517 print print_format("%c/%p_%v", $pkg, {});
1518 print print_format(": %S", $pkg, {})
1520 print print_format("%{ by }u%u", $pkg, {})
1521 if $pkg->{'state'} ne "Needs-Build";
1522 print print_format(" [%X]\n", $pkg, {});
1523 print " Reasons for failing:\n",
1525 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
1527 join("\n ",split("\n",$pkg->{'failed'})), "\n"
1528 if $pkg->{'state'} =~ /^Failed/;
1529 print " Dependencies: $pkg->{'depends'}\n"
1530 if $pkg->{'state'} eq "Dep-Wait";
1531 print " Reasons for BD-Uninstallable:\n ",
1532 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
1533 if $pkg->{'state'} eq "BD-Uninstallable";
1534 print " Previous state was $pkg->{'previous_state'}\n"
1535 if $verbose && $pkg->{'previous_state'};
1536 print " No previous state recorded\n"
1537 if $verbose && !$pkg->{'previous_state'};
1538 print " State changed at $pkg->{'state_change'}\n"
1539 if $verbose && $pkg->{'state_change'};
1540 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
1541 if $verbose && $pkg->{'previous_state'};
1542 print " Previous failing reasons:\n ",
1543 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
1544 if $verbose && $pkg->{'old_failed'};
1546 $scnt{$pkg->{'state'}}++ if $state eq "all";
1548 if ($state eq "all" && !$printformat) {
1549 foreach (sort keys %scnt) {
1550 print "Total $scnt{$_} package(s) in state $_.\n";
1553 print "Total $cnt package(s)\n" unless $printformat;
1558 my( $name, $pkg, $key, $dist );
1559 my @firstkeys = qw(package version builder state section priority
1560 installed_version previous_state state_change);
1561 my @dists = $info_all_dists ? keys %distributions : ($distribution);
1562 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
1563 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
1564 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
1565 'state_change' => 'State-Change',
1566 'bd_problem' => 'BD-Problem',
1567 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
1568 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
1569 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
1570 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
1571 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
1572 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days', 'state_time' => 'State-Time',
1573 'successtime' => 'Success-build-time',
1574 'anytime' => 'Build-time',
1575 'extra_depends' => 'Extra-Dependencies',
1576 'extra_conflicts' => 'Extra-Conflicts',
1577 'build_arch_all' => 'Build-Arch-All',
1580 foreach $name (@_) {
1581 $name =~ s/_.*$//; # strip version
1582 foreach $dist (@dists) {
1583 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
1585 $pkg = get_readonly_source_info($name);
1586 if (!defined( $pkg )) {
1587 print "$pname: not registered\n";
1590 $pkg = calculate_prio($pkg);
1593 foreach $key (@firstkeys) {
1594 next if !defined $pkg->{$key};
1595 my $val = $pkg->{$key};
1597 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1599 my $print_key = $key;
1600 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
1601 printf " %-20s: %s\n", $print_key, $val;
1603 foreach $key (sort keys %$pkg) {
1604 next if isin( $key, @firstkeys );
1605 my $val = $pkg->{$key};
1606 next if !defined($val);
1608 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
1610 my $print_key = $key;
1611 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
1612 printf " %-20s: %s\n", $print_key, $val;
1618 sub forget_packages {
1619 my( $name, $pkg, $key, $data );
1621 foreach $name (@_) {
1622 $name =~ s/_.*$//; # strip version
1623 $pkg = get_source_info($name);
1624 if (!defined( $pkg )) {
1625 print "$name: not registered\n";
1630 foreach $key (sort keys %$pkg) {
1631 my $val = $pkg->{$key};
1634 $data .= sprintf " %-20s: %s\n", $key, $val;
1636 send_mail( $conf::db_maint,
1637 "$name deleted from DB " . table_name() . " " . $distribution,
1638 "The package '$name' has been deleted from the database ".
1640 "Data registered about the deleted package:\n".
1641 "$data\n" ) if $conf::db_maint;
1642 change_state( \$pkg, 'deleted' );
1643 log_ta( $pkg, "--forget" );
1644 del_source_info($name);
1645 print "$name: deleted from database\n" if $verbose;
1650 $dbh->do("DELETE from " . user_table_name() .
1651 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
1657 print "Reading ASCII database from $file..." if $verbose >= 1;
1658 open( my $fh, '<', $file ) or
1659 die "Can't open database $file: $!\n";
1661 local($/) = ""; # read in paragraph mode
1663 my( %thispkg, $name );
1665 s/\n[ \t]+/\376\377/g; # fix continuation lines
1666 s/\376\377\s*\376\377/\376\377/og;
1668 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
1669 my ($key, $val) = ($1, $2);
1671 $key =~ tr/A-Z/a-z/;
1672 $val =~ s/\376\377/\n/g;
1673 $thispkg{$key} = $val;
1675 check_entry( \%thispkg );
1677 if (exists($thispkg{'package'})) {
1678 update_source_info(\%thispkg);
1680 elsif(exists($thispkg{'user'})) {
1681 # user in import, username in database.
1682 $dbh->do('INSERT INTO ' . user_table_name() .
1683 ' (username, distribution, last_seen)' .
1684 ' values (?, ?, ?)',
1685 undef, $thispkg{'user'}, $distribution,
1686 $thispkg{'last_seen'})
1687 or die $dbh->errstr;
1691 print "done\n" if $verbose >= 1;
1698 return if $op_mode eq "manual-edit"; # no checks then
1700 # check for required fields
1701 if (exists $pkg->{'user'}) {
1704 if (!exists $pkg->{'package'}) {
1705 print STDERR "Bad entry: ",
1706 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
1707 die "Database entry lacks package or username field\n";
1709 # if no State: field, generate one (for old db compat)
1710 if (!exists($pkg->{'state'})) {
1712 exists $pkg->{'failed'} ? 'Failed' : 'Building';
1714 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
1715 die "Database entry for $pkg->{'package'} lacks Version: field\n";
1718 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
1719 if !isin( $pkg->{'state'},
1720 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
1721 Failed Failed-Removed Not-For-Us BD-Uninstallable Auto-Not-For-Us
1727 my($name,$pkg,$key);
1729 print "Writing ASCII database to $file..." if $verbose >= 1;
1730 open( my $fh, '>', $file ) or
1731 die "Can't open export $file: $!\n";
1733 my $db = get_all_source_info();
1734 foreach $name (keys %$db) {
1735 next if $name =~ /^_/;
1736 my $pkg = $db->{$name};
1737 foreach $key (keys %{$pkg}) {
1738 my $val = $pkg->{$key};
1739 next if !defined($val);
1742 $val =~ s/^ +$/ ./mg;
1743 print $fh "$key: $val\n";
1748 print "done\n" if $verbose >= 1;
1754 my $newstate = shift;
1755 my $state = \$pkg->{'state'};
1757 return if defined($$state) and $$state eq $newstate;
1758 $pkg->{'previous_state'} = $$state if defined($$state);
1759 $pkg->{'state_change'} = $curr_date;
1760 $pkg->{'do_state_change'} = 1;
1762 if (defined($$state) and $$state eq 'Failed') {
1763 $pkg->{'old_failed'} =
1764 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
1765 ($pkg->{'failed'} // ""). "\n" .
1766 ($pkg->{'old_failed'} // "");
1767 delete $pkg->{'failed'};
1768 delete $pkg->{'failed_category'};
1770 if (defined($$state) and $$state eq 'BD-Uninstallable') {
1771 delete $pkg->{'bd_problem'};
1773 $$state = $newstate;
1779 my $dist = $distribution;
1783 $prevstate = $pkg->{'previous_state'};
1784 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
1785 "changed from $prevstate to $pkg->{'state'} ".
1786 "by $real_user as $user";
1789 printf "update transactions: %s %s %s %s %s %s %s %s\n",
1790 $pkg->{'package'}, $distribution,
1791 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
1795 $dbh->do('INSERT INTO ' . transactions_table_name() .
1796 ' (package, distribution, version, action, ' .
1797 ' prevstate, state, real_user, set_user, time) ' .
1798 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
1799 undef, $pkg->{'package'}, $distribution,
1800 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
1801 $real_user, $user, 'now()') or die $dbh->errstr;
1803 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
1804 $str .= " (with --override)"
1806 $mail_logs .= "$str\n";
1813 my $subject = shift;
1816 my $from = $conf::db_maint;
1817 my $domain = $conf::buildd_domain;
1819 $from .= "\@$domain" if $from !~ /\@/;
1821 $to .= '@' . $domain if $to !~ /\@/;
1822 $text =~ s/^\.$/../mg;
1823 local $SIG{'PIPE'} = 'IGNORE';
1824 open( my $pipe, '|-', "$conf::mailprog -oem $to" )
1825 or die "Can't open pipe to $conf::mailprog: $!\n";
1827 print $pipe "From: $from\n";
1828 print $pipe "Subject: $subject\n\n";
1829 print $pipe "$text\n";
1833 # for parsing input to dep-wait
1839 foreach (split( /\s*,\s*/, $deps )) {
1841 # verification requires > starting prompts, no | crap
1842 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
1847 my @alts = split( /\s*\|\s*/, $_ );
1848 # Anything with an | is ignored, as it can be configured on a
1849 # per-buildd basis what will be installed
1850 next if $#alts != 0;
1853 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
1854 warn( "parse_deplist: bad dependency $_\n" );
1857 my($dep, $rel, $relv) = ($1, $3, $4);
1858 $rel = ">>" if defined($rel) and $rel eq ">";
1859 $result{$dep}->{'package'} = $dep;
1860 if ($rel && $relv) {
1861 $result{$dep}->{'rel'} = $rel;
1862 $result{$dep}->{'version'} = $relv;
1865 return 1 if $verify;
1873 foreach $key (keys %$list) {
1874 $result .= ", " if $result;
1876 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
1877 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
1884 return "" unless $_[0];
1885 return Dpkg::Deps::parse($_[0], ("reduce_arch" => 1, "host_arch" => $_[1]))->dump();
1888 sub wb_edos_builddebcheck {
1889 # Copyright (C) 2008 Ralf Treinen <treinen@debian.org>
1890 # This program is free software: you can redistribute it and/or modify it under
1891 # the terms of the GNU General Public License as published by the Free Software
1892 # Foundation, version 2 of the License.
1893 # integrated into wanna-builds code by Andreas Barth 2010
1896 my $sourceprefix="source---";
1897 my $architecture=$args->{'arch'};
1898 my $edosoptions = "-failures -explain -quiet";
1899 my $packagefiles = $args->{'pkgs'};
1900 my $sourcesfile = $args->{'src'};
1903 foreach my $packagefile (@$packagefiles) {
1904 open(my $fh,'<', $packagefile);
1906 next unless /^Architecture/;
1907 next if /^Architecture:\s*all/;
1908 /Architecture:\s*([^\s]*)/;
1909 if ($packagearch eq "") {
1911 } elsif ( $packagearch ne $1) {
1912 return "Package file contains different architectures: $packagearch, $1";
1918 if ( $architecture eq "" ) {
1919 if ( $packagearch eq "" ) {
1920 return "No architecture option given, " .
1921 "and no non-all architecture found in the Packages file";
1923 $architecture = $packagearch;
1926 if ( $packagearch ne "" & $architecture ne $packagearch) {
1927 return "Architecture option is $architecture ".
1928 "but the package file contains architecture $packagearch";
1932 print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n";
1933 open(my $result_cmd, '-|',
1934 "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles));
1940 while (<$result_cmd>) {
1941 # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED
1942 # source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing:
1943 # - libltdl-dev (>= 2.2.6a-2)
1944 # source---libcanberra (= 0.22-1~bpo50+1): FAILED
1945 # source---libcanberra (= 0.22-1~bpo50+1) depends on missing:
1947 # - libltdl7-dev (>= 2.2.6)
1950 s/^(\s*)$sourceprefix(.*)depends on/$1$2build-depends on/o;
1951 s/^(\s*)$sourceprefix(.*) and (.*) conflict/$1$2 build-conflicts with $3/o;
1954 if (/^$sourceprefix(.*) \(.*\): FAILED/o) {
1955 $result->{$binpkg} = $explanation if $binpkg;
1958 } elsif (/^(depwait---.*) \(.*\): FAILED/o) {
1959 $result->{$binpkg} = $explanation if $binpkg;
1962 } else { # else something broken is happening
1963 #print "ignoring $_\n";
1970 $result->{$binpkg} = $explanation if $binpkg;
1976 sub call_edos_depcheck {
1977 return if $simulate_edos;
1979 my $srcs = $args->{'srcs'};
1982 return if defined ($distributions{$distribution}{noadw}) && not defined $args->{'depwait'};
1984 # We need to check all of needs-build, as any new upload could make
1985 # something in needs-build have uninstallable deps
1986 # We also check everything in bd-uninstallable, as any new upload could
1987 # make that work again
1988 my (%interesting_packages, %interesting_packages_depwait);
1989 my $db = get_all_source_info();
1990 foreach $key (keys %$db) {
1991 my $pkg = $db->{$key};
1992 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/) and not defined ($distributions{$distribution}{noadw})) {
1993 $interesting_packages{$key} = undef;
1995 if (defined $pkg and isin($pkg->{'state'}, qw/Dep-Wait/) and defined $args->{'depwait'}) {
1996 $interesting_packages_depwait{$key} = undef;
1997 # we always check for BD-Uninstallability in depwait - could be that depwait is satisfied but package is uninstallable
1998 $interesting_packages{$key} = undef unless defined ($distributions{$distribution}{noadw});
2002 #print "I would look at these sources with edos-depcheck:\n";
2003 #print join " ", keys %interesting_packages,"\n";
2004 return unless %interesting_packages || %interesting_packages_depwait;
2006 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-XXXXX";
2007 use File::Temp qw/ tempfile /;
2008 my ($SOURCES, $tmpfile) = tempfile( $tmpfile_pattern, UNLINK => 1 );
2009 for my $key (keys %interesting_packages) {
2010 my $pkg = $db->{$key};
2011 # we print the source files as binary ones (with "source---"-prefixed),
2012 # so we can try if these "binary" packages are installable.
2013 # If such a "binary" package is installable, the corresponding source package is buildable.
2014 print $SOURCES "Package: source---$key\n";
2015 print $SOURCES "Version: $pkg->{'version'}\n";
2016 my $t = &filterarch($srcs->{$key}{'dep'} || $srcs->{$key}{'depends'}, $arch);
2017 my $tt = &filterarch($pkg->{'extra_depends'}, $arch);
2018 $t = $t ? ($tt ? "$t, $tt" : $t) : $tt;
2019 print $SOURCES "Depends: $t\n" if $t;
2020 my $u = &filterarch($srcs->{$key}{'conf'} || $srcs->{$key}{'conflicts'}, $arch);
2021 my $uu = &filterarch($pkg->{'extra_conflicts'}, $arch);
2022 $u = $u ? ($uu ? "$u, $uu" : $u) : $uu;
2023 print $SOURCES "Conflicts: $u\n" if $u;
2024 print $SOURCES "Architecture: all\n";
2025 print $SOURCES "\n";
2027 for my $key (keys %interesting_packages_depwait) {
2028 my $pkg = $db->{$key};
2029 # we print the source files as binary ones (with "depwait---"-prefixed),
2030 # so we can try if these "binary" packages are installable.
2031 # If such a "binary" package is installable, the corresponding source package goes out of depwait
2032 print $SOURCES "Package: depwait---$key\n";
2033 print $SOURCES "Version: $pkg->{'version'}\n";
2034 print $SOURCES "Depends: $pkg->{'depends'}\n";
2035 print $SOURCES "Architecture: all\n";
2036 print $SOURCES "\n";
2040 my $edosresults = wb_edos_builddebcheck({'arch' => $args->{'arch'}, 'pkgs' => $args->{'pkgs'}, 'src' => $tmpfile});
2041 if (ref($edosresults) eq 'HASH') {
2042 foreach my $key (grep { $_ !~ /^depwait---/ } keys %$edosresults) {
2043 if (exists $interesting_packages{$key}) {
2044 $interesting_packages{$key} = $edosresults->{$key};
2046 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2049 foreach my $key (grep { $_ =~ /^depwait---/ } keys %$edosresults) {
2050 $key =~ /^depwait---(.*)/ and $key = $1;
2051 if (exists $interesting_packages_depwait{$key}) {
2052 $interesting_packages_depwait{$key} = $edosresults->{"depwait---".$key};
2054 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2058 # if $edosresults isn't an hash, then something went wrong and the string is the error message
2059 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2060 "all packages have installable build-dependencies."
2065 for my $key (keys %interesting_packages) {
2066 next if defined $interesting_packages_depwait{$key};
2067 my $pkg = $db->{$key};
2069 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2070 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2071 my $problemchange = ($interesting_packages{$key}//"") ne ($pkg->{'bd_problem'}//"");
2073 if (defined $interesting_packages{$key}) {
2074 change_state( \$pkg, 'BD-Uninstallable' );
2075 $pkg->{'bd_problem'} = $interesting_packages{$key};
2077 change_state( \$pkg, 'Needs-Build' );
2080 if ($problemchange) {
2081 if (defined $interesting_packages{$key}) {
2082 $pkg->{'bd_problem'} = $interesting_packages{$key};
2086 log_ta( $pkg, "--merge-all (edos)" ) unless $simulate;
2087 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) to $pkg->{'state'}\n" if $verbose || $simulate;
2089 if ($change || $problemchange) {
2090 update_source_info($pkg) unless $simulate;
2094 for my $key (keys %interesting_packages_depwait) {
2095 if ($interesting_packages_depwait{$key}) {
2096 print "dep-wait for $key ($args->{'arch'}) not fullfiled yet\n" if $verbose || $simulate;
2099 my $pkg = $db->{$key};
2100 if (defined $interesting_packages{$key}) {
2101 change_state( \$pkg, 'BD-Uninstallable' );
2102 $pkg->{'bd_problem'} = $interesting_packages{$key};
2104 change_state( \$pkg, 'Needs-Build' );
2106 log_ta( $pkg, "edos_depcheck: depwait" ) unless $simulate;
2107 update_source_info($pkg) unless $simulate;
2108 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) from dep-wait to $pkg->{'state'}\n" if $verbose || $simulate;
2114 ($prgname = $0) =~ s,^.*/,,;
2116 Usage: $prgname <options...> <package_version...>
2118 -v, --verbose: Verbose execution.
2119 -A arch: Architecture this operation is for.
2120 --take: Take package for building [default operation]
2121 -f, --failed: Record in database that a build failed due to
2122 deficiencies in the package (that aren't fixable without a new
2124 -u, --uploaded: Record in the database that the packages build
2125 correctly and were uploaded.
2126 -n, --no-build: Record in the database that the packages aren't
2127 desired for this architecture and shouldn't appear in listings even
2128 if they're out of date.
2129 --dep-wait: Record in the database that the packages are waiting
2130 for some source dependencies to become available
2131 --binNMU num: Schedule a re-build of the package with unchanged source, but
2132 a new version number (source-version + "+b<num>")
2133 --give-back: Mark a package as ready to build that is in state Building,
2134 Built or Build-Attempted. To give back a package in state Failed, use
2135 --override. This command will actually put the package in state
2136 BD-Uninstallable, until the installability of its Build-Dependencies
2137 were verified. This happens at each call of --merge-all, usually
2139 -i SRC_PKG, --info SRC_PKG: Show information for source package
2140 -l STATE, --list=STATE: List all packages in state STATE; can be
2141 combined with -U to restrict to a specific user; STATE can
2143 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2144 source dependency list
2145 (used with -f, --dep-wait, and --binNMU)
2146 -o, --override: Override another user's lock on a package, i.e.
2147 take it over; a notice mail will be sent to the other user
2148 -U USER, --user=USER: select user name for which listings should
2149 apply, if not given all users are listed.
2150 if -l is missing, set user name to be entered in db; usually
2151 automatically choosen
2152 --import FILE: Import database from a ASCII file FILE
2153 --export FILE: Export database to a ASCII file FILE
2155 The remaining arguments (depending on operation) usually start with
2156 "name_version", the trailer is ignored. This allows to pass the names
2157 of .dsc files, for which file name completion can be used.
2158 --merge-packages and --merge-quinn take Package/quin--diff file names
2159 on the command line or read stdin. --list needs nothing more on the
2160 command line. --info takes source package names (without version).
2165 sub pkg_version_eq {
2167 my $version = shift;
2170 if (defined $pkg->{'binary_nmu_version'}) and
2171 version_compare(binNMU_version($pkg->{'version'},
2172 $pkg->{'binary_nmu_version'}),'=', $version);
2173 return version_compare( $pkg->{'version'}, "=", $version );
2177 return '"' . $arch . $schema_suffix . '".packages';
2180 sub user_table_name {
2181 return '"' . $arch . $schema_suffix . '".users';
2184 sub transactions_table_name {
2185 return '"' . $arch . $schema_suffix . '".transactions';
2188 sub pkg_history_table_name {
2189 return '"' . $arch . $schema_suffix . '".pkg_history';
2192 sub get_readonly_source_info {
2194 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2195 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"
2196 . ", (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"
2197 . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2198 . ", extra_depends, extra_conflicts, build_arch_all"
2199 . " FROM " . table_name()
2200 . ' WHERE package = ? AND distribution = ?';
2201 my $pkg = $dbh->selectrow_hashref( $q,
2202 undef, $name, $distribution);
2206 sub get_source_info {
2208 return get_readonly_source_info($name) if $simulate;
2209 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 ' .
2210 table_name() . ' WHERE package = ? AND distribution = ?' .
2212 undef, $name, $distribution);
2216 sub get_all_source_info {
2219 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"
2220 # . ", (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"
2221 # . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2222 . ", successtime.build_time as successtime, anytime.build_time as anytime, extra_depends, extra_conflicts"
2223 . " FROM " . table_name()
2225 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." where result = 'successful' order by package, distribution, timestamp "
2226 . " ) as successtime using (package, distribution) "
2228 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." order by package, distribution, timestamp desc"
2229 . " ) as anytime using (package, distribution) "
2232 if ($distribution) {
2233 my @dists = split(/[, ]+/, $distribution);
2234 $q .= ' AND ( distribution = ? '.(' OR distribution = ? ' x $#dists).' )';
2235 foreach my $d ( @dists ) {
2239 if ($options{state} && uc($options{state}) ne "ALL") {
2240 $q .= ' AND upper(state) = ? ';
2241 push @args, uc($options{state});
2244 if ($options{user} && uc($options{state}) ne "NEEDS-BUILD") { # if it's NEEDS-BUILD, we don't look at users
2245 #this basically means "this user, or no user at all":
2246 $q .= " AND (builder = ? OR upper(state) = 'NEEDS-BUILD')";
2247 push @args, $options{user};
2250 if ($options{category}) {
2251 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2252 push @args, $options{category};
2253 push @args, "FAILED";
2256 if ($options{list_min_age} && $options{list_min_age} > 0) {
2257 $q .= ' AND age(state_change) > ? ';
2258 push @args, $options{list_min_age} . " days";
2261 if ($options{list_min_age} && $options{list_min_age} < 0) {
2262 $q .= ' AND age(state_change) < ? ';
2263 push @args, -$options{list_min_age} . " days";
2266 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2270 sub show_distribution_architectures {
2271 my $q = 'SELECT distribution, spacecat_all(architecture) AS architectures '.
2272 'FROM distribution_architectures '.
2273 'GROUP BY distribution';
2274 my $rows = $dbh->selectall_hashref($q, 'distribution');
2275 foreach my $name (keys %$rows) {
2276 print $name.': '.$rows->{$name}->{'architectures'}."\n";
2280 sub show_distribution_aliases {
2281 foreach my $alias (keys %distribution_aliases) {
2282 print $alias.': '.$distribution_aliases{$alias}."\n";
2286 sub update_source_info {
2288 $pkg->{'extra_depends'} = $extra_depends if defined $extra_depends;
2289 undef $pkg->{'extra_depends'} unless $pkg->{'extra_depends'};
2290 $pkg->{'extra_conflicts'} = $extra_conflicts if defined $extra_conflicts;
2291 undef $pkg->{'extra_conflicts'} unless $pkg->{'extra_conflicts'};
2292 print Dumper $pkg if $verbose and $simulate;
2293 return if $simulate;
2295 my $pkg2 = get_source_info($pkg->{'package'});
2296 if (! defined $pkg2)
2298 add_source_info($pkg);
2301 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2306 'installed_version = ?, ' .
2307 'previous_state = ?, ' .
2308 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2312 'old_failed = ?, ' .
2313 'binary_nmu_version = ?, ' .
2314 'binary_nmu_changelog = ?, ' .
2315 'failed_category = ?, ' .
2316 'permbuildpri = ?, ' .
2320 'extra_depends = ?, ' .
2321 'extra_conflicts = ?, ' .
2323 'WHERE package = ? AND distribution = ?',
2329 $pkg->{'installed_version'},
2330 $pkg->{'previous_state'},
2334 $pkg->{'old_failed'},
2335 $pkg->{'binary_nmu_version'},
2336 $pkg->{'binary_nmu_changelog'},
2337 $pkg->{'failed_category'},
2338 $pkg->{'permbuildpri'},
2342 $pkg->{'extra_depends'},
2343 $pkg->{'extra_conflicts'},
2344 $pkg->{'bd_problem'},
2346 $distribution) or die $dbh->errstr;
2349 sub add_source_info {
2350 return if $simulate;
2352 $dbh->do('INSERT INTO ' . table_name() .
2353 ' (package, distribution) values (?, ?)',
2354 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2357 sub del_source_info {
2358 return if $simulate;
2360 $dbh->do('DELETE FROM ' . table_name() .
2361 ' WHERE package = ? AND distribution = ?',
2362 undef, $name, $distribution) or die $dbh->errstr;
2367 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2368 user_table_name() . ' WHERE username = ? AND distribution = ?',
2369 undef, $name, $distribution);
2373 sub update_user_info {
2374 return if $simulate;
2376 $dbh->do('UPDATE ' . user_table_name() .
2377 ' SET last_seen = now() WHERE username = ?' .
2378 ' AND distribution = ?',
2379 undef, $user, $distribution)
2380 or die $dbh->errstr;
2385 return if $simulate;
2387 $dbh->do('INSERT INTO ' . user_table_name() .
2388 ' (username, distribution, last_seen)' .
2389 ' values (?, ?, now())',
2390 undef, $user, $distribution)
2391 or die $dbh->errstr;
2395 return if $simulate;
2396 $dbh->do('LOCK TABLE ' . table_name() .
2397 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;
2401 # parts the array $_[0] and $_[1] and returns the sub-array (modifies the original one)
2404 my $separator = shift;
2405 while($args->[0] && $args->[0] ne $separator) {
2406 push @ret, shift @$args;
2408 shift @$args if @$args;
2415 my $db = get_all_source_info();
2416 my $binary = $srcs->{'_binary'};
2419 foreach my $name (keys %$srcs) {
2420 next if $name eq '_binary';
2422 # state = installed, out-of-date, uncompiled, not-for-us, auto-not-for-us
2423 my $pkgs = $srcs->{$name};
2424 my $pkg = $db->{$name};
2427 next SRCS if $pkgs->{'status'} eq 'not-for-us';
2428 my $logstr = sprintf("merge-v3 %s %s_%s (%s, %s):", $vars->{'time'}, $name, $pkgs->{'version'}, $vars->{'arch'}, $vars->{'suite'});
2430 # does at least one binary exist in the database and is more recent - if so, we're probably just outdated, ignore the source package
2431 for my $bin (@{$pkgs->{'binary'}}) {
2432 if ($binary->{$bin} and vercmp($pkgs->{'version'}, $binary->{$bin}->{'version'}) < 0) {
2433 print "$logstr skipped because binaries (assumed to be) overwritten\n" if $verbose || $simulate;
2437 $pkg->{'package'} = $name;
2439 my $logstr = sprintf("merge-v3 %s %s_%s", $vars->{'time'}, $name, $pkgs->{'version'}).
2440 ($pkgs->{'binnmu'} ? ";b".$pkgs->{'binnmu'} : "").
2441 sprintf(" (%s, %s, previous: %s", $vars->{'arch'}, $vars->{'suite'}, $pkg->{'version'}//"").
2442 ($pkg->{'binary_nmu_version'} ? ";b".$pkg->{'binary_nmu_version'} : "").
2443 ", $pkg->{'state'}):";
2445 if (isin($pkgs->{'status'}, qw (installed related)) && $pkgs->{'version'} eq $pkg->{'version'} && ($pkgs->{'binnmu'}//0) < int($pkg->{'binary_nmu_version'}//0)) {
2446 $pkgs->{'status'} = 'out-of-date';
2448 if (isin($pkgs->{'status'}, qw (installed related auto-not-for-us))) {
2450 my $tstate = {'installed' => 'Installed', 'related' => 'Installed', 'auto-not-for-us' => 'Auto-Not-For-Us'}->{$pkgs->{'status'}};
2451 next if isin( $pkg->{'state'}, qw<Not-For-Us Failed Failed-Removed Dep-Wait Dep-Wait-Removed>) && isin( $tstate, qw<Auto-Not-For-Us>);
2452 # if the package is currently current, the status is Installed, not not-for-us
2453 if ($pkg->{'state'} ne $tstate) {
2454 change_state( \$pkg, $tstate);
2455 if (isin( $tstate, qw<Installed>)) {
2456 delete $pkg->{'depends'};
2457 delete $pkg->{'extra_depends'};
2458 delete $pkg->{'extra_conflicts'};
2462 my $attrs = { 'version' => 'version', 'installed_version' => 'version', 'binary_nmu_version' => 'binnmu', 'section' => 'section', 'priority' => 'priority' };
2463 foreach my $k (keys %$attrs) {
2464 next if isin( $tstate, qw<Auto-Not-For-Us>) && isin( $k, qw<installed_version binary_nmu_version>);
2465 if (($pkg->{$k}//"") ne ($pkgs->{$attrs->{$k}}//"")) {
2466 $pkg->{$k} = $pkgs->{$attrs->{$k}};
2470 if (isin($pkgs->{'status'}, qw (related)) and $pkg->{'notes'} ne "related") {
2471 $pkg->{'notes'} = "related";
2475 print "$logstr set to $tstate/".($pkg->{'notes'}//"")."\n" if $verbose || $simulate;
2476 log_ta( $pkg, "--merge-v3: $tstate" ) unless $simulate;
2477 update_source_info($pkg) unless $simulate;
2482 if ($pkgs->{'status'} eq 'not-for-us') {
2483 next if isin( $pkg->{'state'}, qw(Not-For-Us Installed Failed-Removed));
2485 if (isin( $pkg->{'state'}, qw(Failed Build-Attempted Built))) {
2486 change_state( \$pkg, "Failed-Removed" );
2487 log_ta( $pkg, "--merge-v3: Failed-Removed" ) unless $simulate;
2488 update_source_info($pkg) unless $simulate;
2489 print "$logstr (virtually) deleted from database\n" if $verbose || $simulate;
2493 print "$logstr should delete (not-for-us according to P-a-s)\n" if $verbose || $simulate || 1; # not implemented yet on purpose
2497 # only uncompiled / out-of-date are left, so check if anything new
2498 if (!(isin($pkgs->{'status'}, qw (uncompiled out-of-date)))) {
2499 print "$logstr package in unknown state: $pkgs->{'status'}\n";
2502 next if $pkgs->{'version'} eq $pkg->{'version'} and $pkgs->{'binnmu'}//0 >= int($pkg->{'binary_nmu_version'}//0);
2503 next if $pkgs->{'version'} eq $pkg->{'version'} and !isin( $pkg->{'state'}, qw(Installed));
2504 next if isin( $pkg->{'state'}, qw(Not-For-Us Failed-Removed));
2506 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
2507 send_mail( $pkg->{'builder'},
2508 "new version of $name (dist=$distribution)",
2509 "As far as I'm informed, you're currently building the package $name\n".
2510 "in version $pkg->{'version'}.\n\n".
2511 "Now there's a new source version $pkgs->{'version'}. If you haven't finished\n".
2512 "compiling $name yet, you can stop it to save some work.\n".
2513 "Just to inform you...\n".
2514 "(This is an automated message)\n" ) unless $simulate;
2515 print "$logstr new version while building $pkg->{'version'} -- sending mail to builder ($pkg->{'builder'})\n"
2516 if $verbose || $simulate;
2518 change_state( \$pkg, 'Needs-Build');
2519 $pkg->{'notes'} = $pkgs->{'status'};
2520 $pkg->{'version'} = $pkgs->{'version'};
2521 $pkg->{'section'} = $pkgs->{'section'};
2522 $pkg->{'priority'} = $pkgs->{'priority'};
2523 $pkg->{'dep'} = $pkgs->{'depends'};
2524 $pkg->{'conf'} = $pkgs->{'conflicts'};
2525 delete $pkg->{'builder'};
2526 delete $pkg->{'binary_nmu_version'} unless $pkgs->{'binnmu'};
2527 delete $pkg->{'binary_nmu_changelog'} unless $pkgs->{'binnmu'};
2528 log_ta( $pkg, "--merge-v3: needs-build" ) unless $simulate;
2529 update_source_info($pkg) unless $simulate;
2530 print "$logstr set to needs-builds\n" if $simulate || $verbose;
2533 foreach my $name (keys %$db) {
2534 next if $srcs->{$name};
2535 my $pkg = $db->{$name};
2536 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkg->{'version'} ($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'state'}):";
2537 # package disappeared - delete
2538 change_state( \$pkg, 'deleted' );
2539 log_ta( $pkg, "--merge-v3: deleted" ) unless $simulate;
2540 print "$logstr deleted from database\n" if $verbose || $simulate;
2541 del_source_info($name) unless $simulate;
2542 delete $db->{$name};