3 # wanna-build: coordination script for Debian buildds
4 # Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 # Copyright (C) 2005-2008 Ryan Murray <rmurray@debian.org>
6 # Copyright (C) 2010 Andreas Barth <aba@not.so.argh.org>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 $basedir ||= "/var/lib/debbuild";
26 $dbbase ||= "build-db";
27 $transactlog ||= "transactions.log";
28 $mailprog ||= "/usr/sbin/sendmail";
29 require "/org/wanna-build/etc/wanna-build.conf";
30 die "$conf::basedir is not a directory\n" if ! -d $conf::basedir;
31 die "dbbase is empty\n" if ! $dbbase;
32 die "transactlog is empty\n" if ! $transactlog;
33 die "mailprog binary $conf::mailprog does not exist or isn't executable\n"
34 if !-x $conf::mailprog;
35 die "no distributions defined\n" if ! %distributions;
43 use lib '/org/wanna-build/bin';
44 use lib '/org/wanna-build/lib';
49 use Hash::Merge qw ( merge );
52 use List::Util qw[max];
53 use Dpkg::Version qw(vercmp); # TODO: change this for running with squeeze dpkg
54 use Dpkg::Deps; # TODO: same
56 our ($verbose, $mail_logs, $list_order, $list_state,
57 $curr_date, $op_mode, $user, $real_user, $distribution,
58 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
60 $info_all_dists, $arch,
61 $category, %catval, %short_category,
62 $short_date, $list_min_age, $dbbase, @curr_time,
63 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
64 $printformat, $ownprintformat, $privmode, $extra_depends, $extra_conflicts
66 our $Pas = '/org/buildd.debian.org/etc/packages-arch-specific/Packages-arch-specific';
68 our $simulate_edos = 0;
69 our $api = undef; # allow buildds to specify an different api
72 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
77 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
78 $short_date = strftime("%m/%d/%y",@curr_time);
81 # map program invocation names to operation modes
82 my %prognames = ( "uploaded-build" => "set-uploaded",
83 "failed-build" => "set-failed",
84 "no-build" => "set-not-for-us",
85 "give-back-build" => "set-needs-build",
86 "dep-wait-build" => "set-dep-wait",
87 "forget-build" => "forget",
88 "build-info" => "info" );
90 %short_category = ( u => "uploaded-fixed-pkg",
97 c => "compiler-error",
101 ($progname = $0) =~ s,.*/,,;
102 if ($prognames{$progname}) {
103 $op_mode = $prognames{$progname};
105 elsif ($progname =~ /^list-(.*)$/) {
107 $list_state = ($1 eq "all") ? "" : $1;
112 simulate => { flag => \$simulate }, # this is not supported by all operations (yet)!
113 "simulate-edos" => { flag => \$simulate_edos },
114 "simulate-all" => { code => sub { $simulate = 1; $simulate_edos = 1; } },
115 api => { arg => \$api, code => sub {
116 # official apis are numeric
117 die "$api isn't numeric" unless int($api) eq $api;
118 die "$api too large" unless $api <= 1;
120 verbose => { short => "v", flag => \$verbose },
121 override => { short => "o", flag => \$opt_override },
122 "create-db" => { flag => \$opt_create_db },
123 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
124 # TODO: remove after buildds no longer pass to wanna-build
125 "no-propagation" => { short => "N" },
126 "no-down-propagation" => { short => "D" },
128 take => { mode => "set-building" },
129 failed => { short => "f", mode => "set-failed" },
130 uploaded => { short => "u", mode => "set-uploaded" },
131 "no-build" => { short => "n", mode => "set-not-for-us" },
132 built => { mode => "set-built" },
133 attempted => { mode => "set-attempted" },
134 "give-back" => { mode => "set-needs-build" },
135 "dep-wait" => { mode => "set-dep-wait" },
136 forget => { mode => "forget" },
137 'forget-user' => { mode => 'forget-user' },
138 update => { mode => "set-update" },
139 #"merge-quinn" => { mode => "merge-quinn" },
140 #"merge-partial-quinn" => { mode => "merge-partial-quinn" },
141 #"merge-packages" => { mode => "merge-packages" },
142 #"merge-sources" => { mode => "merge-sources" },
143 "pretend-avail" => { short => "p", mode => "pretend-avail" },
144 #"merge-all" => { mode => "merge-all" },
145 #"merge-all-secondary" => { mode => "merge-all-secondary" },
146 "merge-v3" => { mode => "merge-v3" },
147 info => { short => "i", mode => "info" },
148 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
149 code => sub { die "Invalid binNMU version: $binNMUver\n"
150 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
151 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
152 code => sub { die "Invalid build priority: $build_priority\n"
153 if $build_priority !~ /^-?[\d]+$/; } },
154 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
155 code => sub { die "Invalid build priority: $build_priority\n"
156 if $build_priority !~ /^-?[\d]+$/; } },
158 { short => "l", mode => "list", arg => \$list_state,
160 die "Unknown state to list: $list_state\n"
161 if !isin( $list_state, qw(needs-build building uploaded
162 built build-attempted failed installed dep-wait
163 not-for-us all failed-removed
164 install-wait reupload-wait bd-uninstallable));} },
167 { short => "d", arg => \$distribution,
169 if ($distribution eq "a" || $distribution eq "all") {
174 $distribution = "oldstable" if $distribution eq "o";
175 $distribution = "stable" if $distribution eq "s";
176 $distribution = "testing" if $distribution eq "t";
177 $distribution = "unstable" if $distribution eq "u";
181 { short => "O", arg => \$list_order,
183 die "Bad ordering character\n"
184 if $list_order !~ /^[PSpsncbCW]+$/;
186 message => { short => "m", arg => \$fail_reason },
187 # database is deprecated, use arch instead.
188 database => { short => "b", arg => \$conf::dbbase },
189 arch => { short => "A", arg => \$arch },
190 user => { short => "U", arg => \$user },
191 category => { short => "c", arg => \$category,
193 $category = $short_category{$category}
194 if exists $short_category{$category};
195 die "Unknown category: $category\n"
196 if !isin( $category, values %short_category );
198 "min-age" => { short => "a", arg => \$list_min_age,
200 die "Argument of --min-age must be a non-zero number\n"
201 if $list_min_age == 0;
203 "max-age" => { arg => \$list_min_age,
205 die "Argument of --max-age must be a non-zero number\n"
206 if $list_min_age == 0;
209 "format" => { arg => \$printformat },
210 "own-format" => { arg => \$ownprintformat },
211 "Pas" => { arg => \$Pas },
212 "extra-depends"=> { arg => \$extra_depends },
213 "extra-conflicts"=> { arg => \$extra_conflicts },
215 export => { arg => \$export_to, mode => "export" },
216 import => { arg => \$import_from, mode => "import" },
217 "manual-edit" => { mode => "manual-edit" },
220 while( @ARGV && $ARGV[0] =~ /^-/ ) {
223 my($opt, $optname, $arg);
224 if (/^--([^=]+)(=|$)/) {
226 $opt = $options{$optname};
227 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
230 $optname = substr( $_, 1, 1 );
231 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
232 $arg = $1 if /^-$optname(.+)$/;
235 warn "Unknown option: --$1\n";
240 die "$optname option missing argument\n" if !@ARGV;
243 ${$opt->{arg}} = $arg;
245 elsif (defined $arg) {
246 die "Option $optname takes no argument\n";
250 die "Conflicting operation modes\n" if $op_mode;
251 $op_mode = $opt->{mode};
261 $op_mode = $category ? "set-failed" : "set-building"
262 if !$op_mode; # default operation
263 $distribution ||= "unstable";
264 if ($distribution eq 'any-priv') {
266 $distribution = 'any';
268 if ($distribution eq 'any-unpriv') {
270 $distribution = 'any';
272 undef $distribution if $distribution eq 'any';
274 my @dists = split(/[, ]+/, $distribution);
275 foreach my $dist (@dists) {
276 die "Bad distribution '$distribution'\n"
277 if !isin($dist, keys %conf::distributions);
280 if (!isin ( $op_mode, qw(list) ) && ( !$distribution || $distribution =~ /[ ,]/)) {
281 die "multiple distributions are only allowed for list";
284 # If they didn't specify an arch, try to get it from database name which
285 # is in the form of $arch/build-db
286 # This is for backwards compatibity with older versions that didn't
287 # specify the arch yet.
288 $conf::dbbase =~ m#^([^/]+)#;
291 # TODO: Check that it's an known arch (for that dist), and give
295 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
296 $version =~ s/(^\$| \$ .*$)//g;
297 print "wanna-build $version for $distribution on $arch\n";
300 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
301 merge-packages manual-edit
303 warn "No packages given.\n";
307 $real_user = (getpwuid($<))[0];
308 die "Can't determine your user name\n"
309 if $op_mode ne "list" && !$user &&
310 !($user = $real_user);
313 if ($op_mode eq "set-failed" && !$category) {
314 print "Enter reason for failing (end with '.' alone on ".
319 last if $line eq ".\n";
320 $fail_reason .= $line;
322 chomp( $fail_reason );
323 } elsif ($op_mode eq "set-dep-wait") {
324 print "Enter dependencies (one line):\n";
326 while( !$line && !eof(STDIN) ) {
327 chomp( $line = <STDIN> );
329 die "No dependencies given\n" if !$line;
330 $fail_reason = $line;
331 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
332 print "Enter changelog entry (one line):\n";
334 while( !$line && !eof(STDIN) ) {
335 chomp( $line = <STDIN> );
337 die "No changelog entry given\n" if !$line;
338 $fail_reason = $line;
343 my $yamldir = "/org/wanna-build/etc/yaml";
344 my @files = ('wanna-build.yaml');
345 if ((getpwuid($>))[7]) { push (@files, ((getpwuid($>))[7])."/.wanna-build.yaml"); }
346 if ($user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
347 if ($user) { push ( @files, "$user.yaml"); }
348 foreach my $file (@files) {
349 my $cfile = File::Spec->rel2abs( $file, $yamldir );
350 if ($verbose >= 2) { print "Trying to read $file ($cfile) ...\n"; }
351 next unless -f $cfile;
352 if ($verbose >= 2) { print "Read $file ($cfile) ...\n"; }
353 my $m = YAML::Tiny->read( $cfile )->[0];
354 $yamlmap = merge($m, $yamlmap);
357 die "FATAL: no configuration found\n";
359 $list_order = $yamlmap->{"list-order"}{$list_state} if !$list_order and $list_state;
360 $list_order ||= $yamlmap->{"list-order"}{'default'};
361 $api //= $yamlmap->{"api"};
369 $dbh->disconnect or warn $dbh->errstr;
373 my $schema_suffix = '';
374 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !(not -t and $user =~ /buildd-/) && !($privmode eq 'yes')) {
375 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
376 die "FATAL: Cannot open database: $DBI::errstr\n";
377 $schema_suffix = '_public';
381 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
382 die "FATAL: Cannot open database: $DBI::errstr\n";
385 # TODO: This shouldn't be needed, file a bug.
386 $dbh->{pg_server_prepare} = 0;
388 $dbh->begin_work or die $dbh->errstr;
395 if ($mail_logs && $conf::log_mail) {
396 send_mail( $conf::log_mail,
397 "wanna-build $distribution state changes $curr_date",
398 "State changes at $curr_date for distribution ".
399 "$distribution:\n\n$mail_logs\n" );
407 SWITCH: foreach ($op_mode) {
409 add_packages( $1, @ARGV );
413 list_packages( $list_state );
417 info_packages( @ARGV );
420 /^forget-user/ && do {
421 die "This operation is restricted to admin users\n"
422 if (defined @conf::admin_users and
423 !isin( $real_user, @conf::admin_users));
424 forget_users( @ARGV );
428 forget_packages( @ARGV );
431 /^merge-partial-quinn/ && do {
432 die "This operation is restricted to admin users\n"
433 if (defined @conf::admin_users and
434 !isin( $real_user, @conf::admin_users));
439 /^merge-quinn/ && do {
440 die "This operation is restricted to admin users\n"
441 if (defined @conf::admin_users and
442 !isin( $real_user, @conf::admin_users));
447 /^merge-packages/ && do {
448 die "This operation is restricted to admin users\n"
449 if (defined @conf::admin_users and
450 !isin( $real_user, @conf::admin_users));
455 /^merge-sources/ && do {
456 die "This operation is restricted to admin users\n"
457 if (defined @conf::admin_users and
458 !isin( $real_user, @conf::admin_users));
463 /^pretend-avail/ && do {
464 pretend_avail( @ARGV );
467 /^merge-all$/ && do {
468 die "This operation is restricted to admin users\n"
469 if (defined @conf::admin_users and
470 !isin( $real_user, @conf::admin_users));
473 @ARGV = ( $ARGS[0] );
474 my $pkgs = parse_packages(0);
475 @ARGV = ( $ARGS[1] );
477 @ARGV = ( $ARGS[2] );
478 my $srcs = parse_sources(1);
479 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[0]), 'srcs' => $srcs });
482 /^merge-all-secondary/ && do {
483 die "This operation is restricted to admin users\n"
484 if (defined @conf::admin_users and
485 !isin( $real_user, @conf::admin_users));
486 # This is in case the chroot has multiple unrelated
487 # dist, for instance unstable and experimental.
488 # This is not for stable and proposed-updates.
489 # The second packages file contains a combination
490 # of all Packages files known to the buildd, the
491 # first only for the current dist.
494 @ARGV = ( $ARGS[0] );
495 my $pkgs = parse_packages(0);
496 @ARGV = ( $ARGS[3] );
497 my $pkgs = parse_packages(1);
498 @ARGV = ( $ARGS[1] );
500 @ARGV = ( $ARGS[2] );
501 my $srcs = parse_sources(1);
502 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[3]), 'srcs' => $srcs });
506 die "This operation is restricted to admin users\n"
507 if (defined @conf::admin_users and !isin( $real_user, @conf::admin_users) and !$simulate);
508 # call with installed-packages+ . installed-sources+ [ . available-for-build-packages* [ . consider-as-installed-source* ] ]
509 # in case available-for-build-packages is not specified, installed-packages are used
510 lock_table() unless $simulate;
511 my $replacemap = { '%ARCH%' => $arch, '%SUITE%' => $distribution };
512 map { my $k = $_; grep { $k =~ s,$_,$replacemap->{$_}, } keys %{$replacemap}; $_ = $k; } @ARGV;
513 my @ipkgs = &parse_argv( \@ARGV, '.');
514 my @isrcs = &parse_argv( \@ARGV, '.');
515 my @bpkgs = &parse_argv( \@ARGV, '.');
516 my @psrcs = &parse_argv( \@ARGV, '.');
518 my $srcs = WB::QD::readsourcebins($arch, $Pas, \@isrcs, \@ipkgs);
520 my $psrcs = WB::QD::readsourcebins($arch, $Pas, \@psrcs, []);
521 foreach my $k (keys %$$psrcs) {
522 next if $$srcs->{$k};
523 my $pkg = $$psrcs->{$k};
524 $pkg->{'status'} = 'related';
528 parse_all_v3($$srcs, {'arch' => $arch, 'suite' => $distribution, 'time' => $curr_date});
529 @bpkgs = @ipkgs unless @bpkgs;
530 call_edos_depcheck( {'arch' => $arch, 'pkgs' => \@bpkgs, 'srcs' => $$srcs, 'depwait' => 1 });
534 die "This operation is restricted to admin users\n"
535 if (defined @conf::admin_users and
536 !isin( $real_user, @conf::admin_users));
537 $dbh->do("DELETE from " . table_name() .
538 " WHERE distribution = ?", undef,
542 read_db( $import_from );
546 export_db( $export_to );
550 die "Unexpected operation mode $op_mode\n";
552 if (not -t and $user =~ /buildd-/) {
553 my $userinfo = get_user_info($user);
554 if (!defined $userinfo)
556 add_user_info($user);
560 update_user_info($user);
566 my $newstate = shift;
567 my( $package, $name, $version, $ok, $reason );
569 foreach $package (@_) {
570 $package =~ s,^.*/,,; # strip path
571 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
572 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
573 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
574 ($name,$version) = ($1,$2);
577 warn "$package: can't extract package name and version ".
582 if ($op_mode eq "set-building") {
583 add_one_building( $name, $version );
585 elsif ($op_mode eq "set-built") {
586 add_one_built( $name, $version );
588 elsif ($op_mode eq "set-attempted") {
589 add_one_attempted( $name, $version );
591 elsif ($op_mode eq "set-uploaded") {
592 add_one_uploaded( $name, $version );
594 elsif ($op_mode eq "set-failed") {
595 add_one_failed( $name, $version );
597 elsif ($op_mode eq "set-not-for-us") {
598 add_one_notforus( $name, $version );
600 elsif ($op_mode eq "set-needs-build") {
601 add_one_needsbuild( $name, $version );
603 elsif ($op_mode eq "set-dep-wait") {
604 add_one_depwait( $name, $version );
606 elsif ($op_mode eq "set-build-priority") {
607 set_one_buildpri( $name, $version, 'buildpri' );
609 elsif ($op_mode eq "set-permanent-build-priority") {
610 set_one_buildpri( $name, $version, 'permbuildpri' );
612 elsif ($op_mode eq "set-binary-nmu") {
613 set_one_binnmu( $name, $version );
615 elsif ($op_mode eq "set-update") {
616 set_one_update( $name, $version );
621 sub add_one_building {
627 my $pkg = get_source_info($name);
629 if ($pkg->{'state'} eq "Not-For-Us") {
631 $reason = "not suitable for this architecture";
633 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
635 $reason = "not all source dependencies available yet";
637 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
639 $reason = "source dependencies are not installable";
641 elsif ($pkg->{'state'} eq "Uploaded" &&
642 (version_lesseq($version, $pkg->{'version'}))) {
644 $reason = "already uploaded by $pkg->{'builder'}";
645 $reason .= " (in newer version $pkg->{'version'})"
646 if !version_eq($pkg, $version);
648 elsif ($pkg->{'state'} eq "Installed" &&
649 version_less($version,$pkg->{'version'})) {
651 print "$name: Warning: newer version $pkg->{'version'} ".
652 "already installed, but overridden.\n";
656 $reason = "newer version $pkg->{'version'} already in ".
657 "archive; doesn't need rebuilding";
658 print "$name: Note: If the following is due to an epoch ",
659 " change, use --override\n";
662 elsif ($pkg->{'state'} eq "Installed" &&
663 pkg_version_eq($pkg,$version)) {
665 $reason = "is up-to-date in the archive; doesn't need rebuilding";
667 elsif ($pkg->{'state'} eq "Needs-Build" &&
668 version_less($version,$pkg->{'version'})) {
670 print "$name: Warning: newer version $pkg->{'version'} ".
671 "needs building, but overridden.";
675 $reason = "newer version $pkg->{'version'} needs building, ".
679 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
680 if (version_less($pkg->{'version'},$version)) {
681 print "$name: Warning: Older version $pkg->{'version'} ",
682 "is being built by $pkg->{'builder'}\n";
683 if ($pkg->{'builder'} ne $user) {
684 send_mail( $pkg->{'builder'},
685 "package takeover in newer version",
686 "You are building package '$name' in ".
687 "version $version\n".
688 "(as far as I'm informed).\n".
689 "$user now has taken the newer ".
690 "version $version for building.".
691 "You can abort the build if you like.\n" );
696 print "User $pkg->{'builder'} had already ",
697 "taken the following package,\n",
698 "but overriding this as you request:\n";
699 send_mail( $pkg->{'builder'}, "package takeover",
700 "The package '$name' (version $version) that ".
701 "was taken by you\n".
702 "has been taken over by $user\n" );
704 elsif ($pkg->{'builder'} eq $user) {
705 print "$name: Note: already taken by you.\n";
706 print "$name: ok\n" if $verbose;
711 $reason = "already taken by $pkg->{'builder'}";
712 $reason .= " (in newer version $pkg->{'version'})"
713 if !version_eq($pkg->{'version'}, $version);
717 elsif ($pkg->{'state'} =~ /^Failed/ &&
718 pkg_version_eq($pkg, $version)) {
720 print "The following package previously failed ",
721 "(by $pkg->{'builder'})\n",
722 "but overriding this as you request:\n";
723 send_mail( $pkg->{'builder'}, "failed package takeover",
724 "The package '$name' (version $version) that ".
726 "and has failed previously has been taken over ".
728 if $pkg->{'builder'} ne $user;
732 $reason = "build of $version failed previously:\n ";
733 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
734 $reason .= "\nalso the package doesn't need builing"
735 if $pkg->{'state'} eq 'Failed-Removed';
742 if ($pkg->{'binary_nmu_version'}) {
743 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
744 "$pkg->{'binary_nmu_changelog'}\n";
747 print "$name: Warning: Previous version failed!\n"
748 if $pkg->{'previous_state'} =~ /^Failed/ ||
749 $pkg->{'state'} =~ /^Failed/;
751 print "$name: $ok\n" if $verbose;
754 print " - status: ok\n";
755 printf " - pkg-ver: %s_%s\n", $name, $version;
756 print " - binNMU: $pkg->{'binary_nmu_version'}\n" if $pkg->{'binary_nmu_version'};
757 print " - extra-changelog: $pkg->{'binary_nmu_changelog'}\n" if $pkg->{'binary_nmu_changelog'} && $pkg->{'binary_nmu_version'};
758 print " - extra-depends: $pkg->{'extra_depends'}\n" if $pkg->{'extra_depends'};
759 print " - extra-conflicts: $pkg->{'extra_conflicts'}\n" if $pkg->{'extra_conflicts'};
761 change_state( \$pkg, 'Building' );
762 $pkg->{'package'} = $name;
763 $pkg->{'version'} = $version;
764 $pkg->{'builder'} = $user;
765 log_ta( $pkg, "--take" );
766 update_source_info($pkg);
770 print "$name: NOT OK!\n $reason\n";
772 print "- $name:\n - status: not ok\n - reason: \"$reason\"\n";
777 sub add_one_attempted {
780 my $pkg = get_source_info($name);
782 if (!defined($pkg)) {
783 print "$name: not registered yet.\n";
787 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
788 print "$name: not taken for building (state is $pkg->{'state'}). ",
792 if ($pkg->{'builder'} ne $user) {
793 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
796 elsif ( !pkg_version_eq($pkg, $version) ) {
797 print "$name: version mismatch ".
798 "$(pkg->{'version'} ".
799 "by $pkg->{'builder'})\n";
803 change_state( \$pkg, 'Build-Attempted' );
804 log_ta( $pkg, "--attempted" );
805 update_source_info($pkg);
806 print "$name: registered as uploaded\n" if $verbose;
812 my $pkg = get_source_info($name);
814 if (!defined($pkg)) {
815 print "$name: not registered yet.\n";
819 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
820 print "$name: not taken for building (state is $pkg->{'state'}). ",
824 if ($pkg->{'builder'} ne $user) {
825 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
828 elsif ( !pkg_version_eq($pkg, $version) ) {
829 print "$name: version mismatch ".
830 "$(pkg->{'version'} ".
831 "by $pkg->{'builder'})\n";
834 change_state( \$pkg, 'Built' );
835 log_ta( $pkg, "--built" );
836 update_source_info($pkg);
837 print "$name: registered as built\n" if $verbose;
840 sub add_one_uploaded {
843 my $pkg = get_source_info($name);
845 if (!defined($pkg)) {
846 print "$name: not registered yet.\n";
850 if ($pkg->{'state'} eq "Uploaded" &&
851 pkg_version_eq($pkg,$version)) {
852 print "$name: already uploaded\n";
855 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
856 print "$name: not taken for building (state is $pkg->{'state'}). ",
860 if ($pkg->{'builder'} ne $user) {
861 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
864 # strip epoch -- buildd-uploader used to go based on the filename.
865 # (to remove at some point)
867 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
868 $version =~ s/^\d+://; # for command line use
869 if ($pkg->{'binary_nmu_version'} ) {
870 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
871 if (!version_eq( $nmuver, $version )) {
872 print "$name: version mismatch ($nmuver registered). ",
876 } elsif (!version_eq($pkgver, $version)) {
877 print "$name: version mismatch ($pkg->{'version'} registered). ",
882 change_state( \$pkg, 'Uploaded' );
883 log_ta( $pkg, "--uploaded" );
884 update_source_info($pkg);
885 print "$name: registered as uploaded\n" if $verbose;
892 my $pkg = get_source_info($name);
894 if (!defined($pkg)) {
895 print "$name: not registered yet.\n";
898 $state = $pkg->{'state'};
900 if ($state eq "Not-For-Us") {
901 print "$name: not suitable for this architecture anyway. Skipping.\n";
904 elsif ($state eq "Failed-Removed") {
905 print "$name: failed previously and doesn't need building. Skipping.\n";
908 elsif ($state eq "Installed") {
909 print "$name: Is already installed in archive. Skipping.\n";
912 elsif ($pkg->{'builder'} &&
913 (($user ne $pkg->{'builder'}) &&
914 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
915 print "$name: not taken by you, but by ".
916 "$pkg->{'builder'}. Skipping.\n";
919 elsif ( !pkg_version_eq($pkg, $version) ) {
920 print "$name: version mismatch ".
921 "$(pkg->{'version'} ".
922 "by $pkg->{'builder'})\n";
927 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
929 $cat = $short_category{$cat} if exists $short_category{$cat};
930 if (!isin( $cat, values %short_category )) {
931 print "$name: Warning: unknown category $cat; discarded\n";
934 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
937 if ($state eq "Needs-Build") {
938 print "$name: Warning: not registered for building previously, ".
939 "but processing anyway.\n";
941 elsif ($state eq "Uploaded") {
942 print "$name: Warning: marked as uploaded previously, ".
943 "but processing anyway.\n";
945 elsif ($state eq "Dep-Wait") {
946 print "$name: Warning: marked as waiting for dependencies, ".
947 "but processing anyway.\n";
949 elsif ($state eq "BD-Uninstallable") {
950 print "$name: Warning: marked as having uninstallable build-dependencies, ".
951 "but processing anyway.\n";
953 elsif ($state eq "Failed") {
954 print "$name: already registered as failed; will append new message\n"
956 print "$name: already registered as failed; changing category\n"
960 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
961 defined $pkg->{'failed_category'} &&
962 $pkg->{'failed_category'} ne $cat) {
963 (my $action = $cat) =~ s/-/ /;
964 $fail_reason .= "\n$short_date: $action";
967 change_state( \$pkg, 'Failed' );
968 $pkg->{'builder'} = $user;
969 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
970 $pkg->{'failed'} .= $fail_reason;
971 $pkg->{'failed_category'} = $cat if $cat;
972 if (defined $pkg->{'permbuildpri'}) {
973 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
975 delete $pkg->{'buildpri'};
977 log_ta( $pkg, "--failed" );
978 update_source_info($pkg);
979 print "$name: registered as failed\n" if $verbose;
982 sub add_one_notforus {
985 my $pkg = get_source_info($name);
987 if ($pkg->{'state'} eq 'Not-For-Us') {
988 # reset Not-For-Us state in case it's called twice; this is
989 # the only way to get a package out of this state...
990 # There is no really good state in which such packages should
991 # be put :-( So use Failed for now.
992 change_state( \$pkg, 'Failed' );
993 $pkg->{'package'} = $name;
994 $pkg->{'failed'} = "Was Not-For-Us previously";
995 delete $pkg->{'builder'};
996 delete $pkg->{'depends'};
997 log_ta( $pkg, "--no-build(rev)" );
998 print "$name: now not unsuitable anymore\n";
1000 send_mail( $conf::notforus_maint,
1001 "$name moved out of Not-For-Us state",
1002 "The package '$name' has been moved out of the Not-For-Us ".
1003 "state by $user.\n".
1004 "It should probably also be removed from ".
1005 "Packages-arch-specific or\n".
1006 "the action was wrong.\n" )
1007 if $conf::notforus_maint;
1010 change_state( \$pkg, 'Not-For-Us' );
1011 $pkg->{'package'} = $name;
1012 delete $pkg->{'builder'};
1013 delete $pkg->{'depends'};
1014 delete $pkg->{'buildpri'};
1015 delete $pkg->{'binary_nmu_version'};
1016 delete $pkg->{'binary_nmu_changelog'};
1017 log_ta( $pkg, "--no-build" );
1018 print "$name: registered as unsuitable\n" if $verbose;
1020 send_mail( $conf::notforus_maint,
1021 "$name set to Not-For-Us",
1022 "The package '$name' has been set to state Not-For-Us ".
1024 "It should probably also be added to ".
1025 "Packages-arch-specific or\n".
1026 "the Not-For-Us state is wrong.\n" )
1027 if $conf::notforus_maint;
1029 update_source_info($pkg);
1032 sub add_one_needsbuild {
1034 my $version = shift;
1036 my $pkg = get_source_info($name);
1038 if (!defined($pkg)) {
1039 print "$name: not registered; can't give back.\n";
1042 $state = $pkg->{'state'};
1044 if ($state eq "BD-Uninstallable") {
1045 if ($opt_override) {
1046 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
1048 change_state( \$pkg, 'Needs-Build' );
1049 delete $pkg->{'builder'};
1050 delete $pkg->{'depends'};
1051 log_ta( $pkg, "--give-back" );
1052 update_source_info($pkg);
1053 print "$name: given back\n" if $verbose;
1057 print "$name: has uninstallable build-dependencies. Skipping\n",
1058 " (use --override to clear dependency list and ",
1059 "give back anyway)\n";
1063 elsif ($state eq "Dep-Wait") {
1064 if ($opt_override) {
1065 print "$name: Forcing source dependency list to be cleared\n";
1068 print "$name: waiting for source dependencies. Skipping\n",
1069 " (use --override to clear dependency list and ",
1070 "give back anyway)\n";
1074 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1075 print "$name: not taken for building (state is $state).";
1076 if ($opt_override) {
1077 print "\n$name: Forcing give-back\n";
1080 print " Skipping.\n";
1084 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
1085 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
1087 print "$name: not taken by you, but by ".
1088 "$pkg->{'builder'}. Skipping.\n";
1091 if (!pkg_version_eq($pkg, $version)) {
1092 print "$name: version mismatch ($pkg->{'version'} registered). ",
1096 if ($distribution eq "unstable") {
1097 change_state( \$pkg, 'BD-Uninstallable' );
1098 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1100 change_state( \$pkg, 'Needs-Build' );
1102 $pkg->{'builder'} = undef;
1103 $pkg->{'depends'} = undef;
1104 log_ta( $pkg, "--give-back" );
1105 update_source_info($pkg);
1106 print "$name: given back\n" if $verbose;
1109 sub set_one_binnmu {
1111 my $version = shift;
1112 my $pkg = get_source_info($name);
1115 if (!defined($pkg)) {
1116 print "$name: not registered; can't register for binNMU.\n";
1119 my $db_ver = $pkg->{'version'};
1121 if (!version_eq($db_ver, $version)) {
1122 print "$name: version mismatch ($db_ver registered). ",
1126 $state = $pkg->{'state'};
1128 if (defined $pkg->{'binary_nmu_version'}) {
1129 if ($binNMUver == 0) {
1130 change_state( \$pkg, 'Installed' );
1131 delete $pkg->{'builder'};
1132 delete $pkg->{'depends'};
1133 delete $pkg->{'binary_nmu_version'};
1134 delete $pkg->{'binary_nmu_changelog'};
1135 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1136 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1139 $pkg->{'binary_nmu_version'} = $binNMUver;
1140 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1141 $pkg->{'notes'} = 'out-of-date';
1142 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1143 if (defined $pkg->{'permbuildpri'});
1145 log_ta( $pkg, "--binNMU" );
1146 update_source_info($pkg);
1148 } elsif ($binNMUver == 0) {
1149 print "${name}_$version: no scheduled binNMU to cancel.\n";
1153 if ($state ne 'Installed') {
1154 print "${name}_$version: not installed; can't register for binNMU.\n";
1158 my $fullver = binNMU_version($version,$binNMUver);
1159 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1161 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1165 if ($distribution eq "unstable") {
1166 change_state( \$pkg, 'BD-Uninstallable' );
1167 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1171 change_state( \$pkg, 'Needs-Build' );
1173 delete $pkg->{'builder'};
1174 delete $pkg->{'depends'};
1175 $pkg->{'binary_nmu_version'} = $binNMUver;
1176 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1177 $pkg->{'notes'} = 'out-of-date';
1178 log_ta( $pkg, "--binNMU" );
1179 update_source_info($pkg);
1180 print "${name}: registered for binNMU $fullver\n" if $verbose;
1183 sub set_one_buildpri {
1185 my $version = shift;
1187 my $pkg = get_source_info($name);
1190 if (!defined($pkg)) {
1191 print "$name: not registered; can't set priority.\n";
1194 $state = $pkg->{'state'};
1196 if ($state eq "Not-For-Us") {
1197 print "$name: not suitable for this architecture. Skipping.\n";
1199 } elsif ($state eq "Failed-Removed") {
1200 print "$name: failed previously and doesn't need building. Skipping.\n";
1203 if (!pkg_version_eq($pkg, $version)) {
1204 print "$name: version mismatch ($pkg->{'version'} registered). ",
1208 if ( $build_priority == 0 ) {
1209 delete $pkg->{'buildpri'}
1210 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1211 and $pkg->{'buildpri'} == $pkg->{$key};
1212 delete $pkg->{$key};
1214 $pkg->{'buildpri'} = $build_priority
1215 if $key eq 'permbuildpri';
1216 $pkg->{$key} = $build_priority;
1218 update_source_info($pkg);
1219 print "$name: set to build priority $build_priority\n" if $verbose;
1222 sub add_one_depwait {
1224 my $version = shift;
1226 my $pkg = get_source_info($name);
1228 if (!defined($pkg)) {
1229 print "$name: not registered yet.\n";
1232 $state = $pkg->{'state'};
1234 if ($state eq "Dep-Wait") {
1235 print "$name: merging with previously registered dependencies\n";
1238 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1239 print "$name: Warning: not registered for building previously, ".
1240 "but processing anyway.\n";
1242 elsif ($state eq "Not-For-Us") {
1243 print "$name: not suitable for this architecture anyway. Skipping.\n";
1246 elsif ($state eq "Failed-Removed") {
1247 print "$name: failed previously and doesn't need building. Skipping.\n";
1250 elsif ($state eq "Installed") {
1251 print "$name: Is already installed in archive. Skipping.\n";
1254 elsif ($state eq "Uploaded") {
1255 print "$name: Is already uploaded. Skipping.\n";
1258 elsif ($pkg->{'builder'} &&
1259 $user ne $pkg->{'builder'}) {
1260 print "$name: not taken by you, but by ".
1261 "$pkg->{'builder'}. Skipping.\n";
1264 elsif ( !pkg_version_eq($pkg,$version)) {
1265 print "$name: version mismatch ".
1266 "($pkg->{'version'} ".
1267 "by $pkg->{'builder'})\n";
1270 elsif ($fail_reason =~ /^\s*$/ ||
1271 !parse_deplist( $fail_reason, 1 )) {
1272 print "$name: Bad dependency list\n";
1275 change_state( \$pkg, 'Dep-Wait' );
1276 $pkg->{'builder'} = $user;
1277 if (defined $pkg->{'permbuildpri'}) {
1278 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1280 delete $pkg->{'buildpri'};
1282 my $deplist = parse_deplist( $pkg->{'depends'} );
1283 my $new_deplist = parse_deplist( $fail_reason );
1284 # add new dependencies, maybe overwriting old entries
1285 foreach (keys %$new_deplist) {
1286 $deplist->{$_} = $new_deplist->{$_};
1288 $pkg->{'depends'} = build_deplist($deplist);
1289 log_ta( $pkg, "--dep-wait" );
1290 update_source_info($pkg);
1291 print "$name: registered as waiting for dependencies\n" if $verbose;
1294 sub set_one_update {
1296 my $version = shift;
1297 my $pkg = get_source_info($name);
1299 if (!defined($pkg)) {
1300 print "$name: not registered yet.\n";
1303 $pkg->{'version'} =~ s/\+b[0-9]+$//;
1305 log_ta( $pkg, "--update" );
1306 update_source_info($pkg);
1316 my $db = get_all_source_info();
1318 local($/) = ""; # read in paragraph mode
1320 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1322 /^Package:\s*(\S+)$/mi and $name = $1;
1323 /^Version:\s*(\S+)$/mi and $version = $1;
1324 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1325 /^Section:\s*(\S+)$/mi and $section = $1;
1326 /^Priority:\s*(\S+)$/mi and $priority = $1;
1327 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1328 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1329 /^Binary:\s*(.*)$/mi and $binaries = $1;
1331 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1332 $srcver{$name} = $version;
1334 $pkgs{$name}{'ver'} = $version;
1335 $pkgs{$name}{'bin'} = $binaries;
1336 $pkgs{$name}{'dep'} = $builddep;
1337 $pkgs{$name}{'conf'} = $buildconf;
1338 my $pkg = $db->{$name};
1343 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1344 # package is now Arch: all, delete it from db
1345 change_state( \$pkg, 'deleted' );
1346 log_ta( $pkg, "--merge-sources" );
1347 print "$name ($pkg->{'version'}): deleted ".
1348 "from database, because now Arch: all\n"
1350 del_source_info($name);
1351 delete $db->{$name};
1355 # The "Version" should always be the source version --
1356 # not a possible binNMU version number.
1357 $pkg->{'version'} = $version, $change++
1358 if ($pkg->{'state'} eq 'Installed' and
1359 !version_eq( $pkg->{'version'}, $version));
1360 # Always update priority and section, if available
1361 $pkg->{'priority'} = $priority, $change++
1362 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1364 $pkg->{'section'} = $section, $change++
1365 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1367 update_source_info($pkg) if $change;
1370 # Now that we only have the latest source version, build the list
1371 # of binary packages from the Sources point of view
1372 foreach $name (keys %pkgs) {
1373 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1374 $merge_binsrc{$bin} = $name;
1377 # remove installed packages that no longer have source available
1378 # or binaries installed
1379 foreach $name (keys %$db) {
1380 next if $name =~ /^_/;
1381 my $pkg = $db->{$name};
1382 if (not defined($pkgs{$name})) {
1383 change_state( \$pkg, 'deleted' );
1384 log_ta( $pkg, "--merge-sources" );
1385 print "$name ($pkg->{'version'}): ".
1386 "deleted from database, because ".
1387 "not in Sources anymore\n"
1389 del_source_info($name);
1390 delete $db->{$name};
1392 next if !isin( $pkg->{'state'}, qw(Installed) );
1393 if ($full && not defined $merge_srcvers{$name}) {
1394 change_state( \$pkg, 'deleted' );
1395 log_ta( $pkg, "--merge-sources" );
1396 print "$name ($pkg->{'version'}): ".
1397 "deleted from database, because ".
1398 "binaries don't exist anymore\n"
1400 del_source_info($name);
1401 delete $db->{$name};
1402 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1403 print "$name ($pkg->{'version'}): ".
1404 "package is Installed but binaries are from ".
1405 $merge_srcvers{$name}. "\n"
1413 # This function looks through a Packages file and sets the state of
1414 # packages to 'Installed'
1415 sub parse_packages {
1416 my $depwait_only = shift;
1419 my $pkgs = get_all_source_info();
1420 local($/) = ""; # read in paragraph mode
1422 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1424 /^Package:\s*(\S+)$/mi and $name = $1;
1425 /^Version:\s*(\S+)$/mi and $version = $1;
1426 /^Depends:\s*(.*)$/mi and $depends = $1;
1427 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1428 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1429 /^Provides:\s*(.*)$/mi and $provides = $1;
1430 next if !$name || !$version;
1431 next if ($arch ne $architecture and $architecture ne "all");
1432 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1433 version_lesseq( $version, $installed->{$name}{'version'} ));
1434 $installed->{$name}{'version'} = $version;
1435 next if $depwait_only;
1436 $installed->{$name}{'depends'} = $depends;
1437 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1438 undef $installed->{$name}{'Provider'};
1439 $installed->{$name}{'Source'} = $source ? $source : $name;
1441 foreach (split( /\s*,\s*/, $provides )) {
1442 if (not defined ($installed->{$_})) {
1443 $installed->{$_}{'version'} = "";
1444 $installed->{$_}{'Provider'} = $name;
1448 if ( $version =~ /\+b(\d+)$/ ) {
1451 $version = $sourcev if $sourcev;
1452 $binaryv = $version;
1453 $binaryv =~ s/\+b\d+$//;
1454 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1455 $binaryv .= "+b$binnmu" if defined($binnmu);
1457 next if $architecture ne $arch;
1458 $name = $source if $source;
1459 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1460 $merge_srcvers{$name} = $version;
1462 my $pkg = $pkgs->{$name};
1465 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1466 (isin($pkg->{'state'}, qw(Installed)) &&
1467 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1468 print "Skipping $name because State == $pkg->{'state'}\n"
1472 if ($pkg->{'binary_nmu_version'} ) {
1473 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1474 if (version_less( $binaryv, $nmuver )) {
1475 print "Skipping $name ($version) because have newer ".
1476 "version ($nmuver) in db.\n"
1480 } elsif (version_less($version, $pkg->{'version'})) {
1481 print "Skipping $name ($version) because have newer ".
1482 "version ($pkg->{'version'}) in db.\n"
1487 if (!pkg_version_eq($pkg, $version) &&
1488 $pkg->{'state'} ne "Installed") {
1489 warn "Warning: $name: newer version than expected appeared ".
1490 "in archive ($version vs. $pkg->{'version'})\n";
1491 delete $pkg->{'builder'};
1494 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1495 warn "Warning: Package $name was not in uploaded state ".
1496 "before (but in '$pkg->{'state'}').\n";
1497 delete $pkg->{'builder'};
1498 delete $pkg->{'depends'};
1502 $pkg->{'version'} = $version;
1505 change_state( \$pkg, 'Installed' );
1506 $pkg->{'package'} = $name;
1507 $pkg->{'installed_version'} = $binaryv;
1508 if (defined $pkg->{'permbuildpri'}) {
1509 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1511 delete $pkg->{'buildpri'};
1513 $pkg->{'version'} = $version
1514 if version_less( $pkg->{'version'}, $version);
1515 delete $pkg->{'binary_nmu_version'};
1516 delete $pkg->{'binary_nmu_changelog'};
1517 log_ta( $pkg, "--merge-packages" );
1518 update_source_info($pkg);
1519 print "$name ($version) is up-to-date now.\n" if $verbose;
1522 check_dep_wait( "--merge-packages", $installed );
1527 my ($package, $name, $version, $installed);
1529 foreach $package (@_) {
1530 $package =~ s,^.*/,,; # strip path
1531 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1532 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1533 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1534 ($name,$version) = ($1,$2);
1537 warn "$package: can't extract package name and version ".
1541 $installed->{$name}{'version'} = $version;
1544 check_dep_wait( "--pretend-avail", $installed );
1547 sub check_dep_wait {
1549 my $installed = shift;
1551 # check all packages in state Dep-Wait if dependencies are all
1554 my $db = get_all_source_info();
1555 foreach $name (keys %$db) {
1556 next if $name =~ /^_/;
1557 my $pkg = $db->{$name};
1558 next if $pkg->{'state'} ne "Dep-Wait";
1559 my $deps = $pkg->{'depends'};
1561 print "$name: was in state Dep-Wait, but with empty ",
1563 goto make_needs_build;
1565 my $deplist = parse_deplist($deps);
1569 foreach (keys %$deplist) {
1570 if (!exists $installed->{$_} ||
1571 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1572 !version_compare( $installed->{$_}{'version'},
1573 $deplist->{$_}->{'rel'},
1574 $deplist->{$_}->{'version'}))) {
1576 $new_deplist->{$_} = $deplist->{$_};
1579 push( @removed_deps, $_ );
1584 change_state( \$pkg, 'Needs-Build' );
1585 log_ta( $pkg, $action );
1586 delete $pkg->{'builder'};
1587 delete $pkg->{'depends'};
1588 print "$name ($pkg->{'version'}) has all ",
1589 "dependencies available now\n" if $verbose;
1591 update_source_info($pkg);
1593 elsif (@removed_deps) {
1594 $pkg->{'depends'} = build_deplist( $new_deplist );
1595 print "$name ($pkg->{'version'}): some dependencies ",
1596 "(@removed_deps) available now, but not all yet\n"
1598 update_source_info($pkg);
1603 # This function accepts quinn-diff output (either from a file named on
1604 # the command line, or on stdin) and sets the packages named there to
1605 # state 'Needs-Build'.
1606 sub parse_quinn_diff {
1607 my $partial = shift;
1611 my $pkgs = get_all_source_info();
1615 next if !m,^([-\w\d/]*)/ # section
1616 ([-\w\d.+]+)_ # package name
1617 ([\w\d:.~+-]+)\.dsc\s* # version
1618 \[([^:]*): # priority
1619 ([^]]+)\]\s*$,x; # rest of notes
1620 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1621 $quinn_pkgs{$name}++;
1622 $section ||= "unknown";
1623 $priority ||= "unknown";
1624 $priority = "unknown" if $priority eq "-";
1625 $priority = "standard" if ($name eq "debian-installer");
1627 my $pkg = $pkgs->{$name};
1629 # Always update section and priority.
1630 if (defined($pkg)) {
1632 $pkg->{'section'} = $section, $change++ if not defined
1633 $pkg->{'section'} or $section ne "unknown";
1634 $pkg->{'priority'} = $priority, $change++ if not defined
1635 $pkg->{'priority'} or $priority ne "unknown";
1638 if (defined($pkg) &&
1639 $pkg->{'state'} =~ /^Dep-Wait/ &&
1640 version_less( $pkg->{'version'}, $version )) {
1641 change_state( \$pkg, 'Dep-Wait' );
1642 $pkg->{'version'} = $version;
1643 delete $pkg->{'binary_nmu_version'};
1644 delete $pkg->{'binary_nmu_changelog'};
1645 log_ta( $pkg, "--merge-quinn" );
1647 print "$name ($version) still waiting for dependencies.\n"
1650 elsif (defined($pkg) &&
1651 $pkg->{'state'} =~ /-Removed$/ &&
1652 version_eq($pkg->{'version'}, $version)) {
1653 # reinstantiate a package that has been removed earlier
1654 # (probably due to a quinn-diff malfunction...)
1655 my $newstate = $pkg->{'state'};
1656 $newstate =~ s/-Removed$//;
1657 change_state( \$pkg, $newstate );
1658 $pkg->{'version'} = $version;
1659 $pkg->{'notes'} = $notes;
1660 log_ta( $pkg, "--merge-quinn" );
1662 print "$name ($version) reinstantiated to $newstate.\n"
1665 elsif (defined($pkg) &&
1666 $pkg->{'state'} eq "Not-For-Us" &&
1667 version_less( $pkg->{'version'}, $version )) {
1668 # for Not-For-Us packages just update the version etc., but
1670 change_state( \$pkg, "Not-For-Us" );
1671 $pkg->{'package'} = $name;
1672 $pkg->{'version'} = $version;
1673 $pkg->{'notes'} = $notes;
1674 delete $pkg->{'builder'};
1675 log_ta( $pkg, "--merge-quinn" );
1677 print "$name ($version) still Not-For-Us.\n" if $verbose;
1679 elsif (!defined($pkg) ||
1680 $pkg->{'state'} ne "Not-For-Us" &&
1681 (version_less( $pkg->{'version'}, $version ) ||
1682 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1684 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1685 send_mail( $pkg->{'builder'},
1686 "new version of $name (dist=$distribution)",
1687 "As far as I'm informed, you're currently ".
1688 "building the package $name\n".
1689 "in version $pkg->{'version'}.\n\n".
1690 "Now there's a new source version $version. ".
1691 "If you haven't finished\n".
1692 "compiling $name yet, you can stop it to ".
1693 "save some work.\n".
1694 "Just to inform you...\n".
1695 "(This is an automated message)\n" );
1696 print "$name: new version ($version) while building ".
1697 "$pkg->{'version'} -- sending mail ".
1698 "to builder ($pkg->{'builder'})\n"
1701 change_state( \$pkg, 'Needs-Build' );
1702 $pkg->{'package'} = $name;
1703 $pkg->{'version'} = $version;
1704 $pkg->{'section'} = $section;
1705 $pkg->{'priority'} = $priority;
1706 $pkg->{'notes'} = $notes;
1707 delete $pkg->{'builder'};
1708 delete $pkg->{'binary_nmu_version'};
1709 delete $pkg->{'binary_nmu_changelog'};
1710 log_ta( $pkg, "--merge-quinn" );
1713 print "$name ($version) needs rebuilding now.\n" if $verbose;
1715 elsif (defined($pkg) &&
1716 !version_eq( $pkg->{'version'}, $version ) &&
1717 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1718 print "$name: skipping because version in db ".
1719 "($pkg->{'version'}) is >> than ".
1720 "what quinn-diff says ($version) ".
1721 "(state is $pkg->{'state'})\n"
1723 $dubious .= "$pkg->{'state'}: ".
1724 "db ${name}_$pkg->{'version'} >> ".
1725 "quinn $version\n" if !$partial;
1727 elsif ($verbose >= 2) {
1728 if ($pkg->{'state'} eq "Not-For-Us") {
1729 print "Skipping $name because State == ".
1730 "$pkg->{'state'}\n";
1732 elsif (!version_less($pkg->{'version'}, $version)) {
1733 print "Skipping $name because version in db ".
1734 "($pkg->{'version'}) is >= than ".
1735 "what quinn-diff says ($version)\n";
1738 update_source_info($pkg) if $change;
1742 send_mail( $conf::db_maint,
1743 "Dubious versions in " . table_name() . " "
1744 . $distribution . " table",
1745 "The following packages have a newer version in the ".
1746 "wanna-build database\n".
1747 "than what quinn-diff says, and this is strange for ".
1749 "It could be caused by a lame mirror, or the version ".
1750 "in the database\n".
1755 # Now re-check the DB for packages in states Needs-Build, Failed,
1756 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1757 # anymore by quinn-diff.
1760 my $db = get_all_source_info();
1761 foreach $name (keys %$db) {
1762 next if $name =~ /^_/;
1763 my $pkg = $db->{$name};
1764 next if defined $pkg->{'binary_nmu_version'};
1765 next if !isin( $pkg->{'state'},
1766 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1767 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1769 if (!$quinn_pkgs{$name}) {
1770 change_state( \$pkg, $virtual_delete ?
1771 $pkg->{'state'}."-Removed" :
1773 log_ta( $pkg, "--merge-quinn" );
1774 print "$name ($pkg->{'version'}): ".
1775 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1776 "from database, because not in quinn-diff anymore\n"
1778 if ($virtual_delete) {
1779 update_source_info($pkg);
1781 del_source_info($name);
1789 # for sorting priorities and sections
1791 %prioval = ( required => -5,
1799 'debian-installer' => -199,
1820 localizations => -178,
1821 interpreters => -177,
1846 electronics => -152,
1852 foreach my $i (keys %sectval) {
1853 $sectval{"contrib/$i"} = $sectval{$i}+40;
1854 $sectval{"non-free/$i"} = $sectval{$i}+80;
1856 $sectval{'unknown'} = -165;
1858 %catval = ( "none" => -20,
1859 "uploaded-fixed-pkg" => -19,
1860 "fix-expected" => -18,
1861 "reminder-sent" => -17,
1862 "nmu-offered" => -16,
1866 "compiler-error" => -12 );
1869 sub sort_list_func {
1871 'C' => ['<=>', sub { return (-1) * $_[0]->{'calprio'}; }],
1872 'W' => ['<=>', sub { return (-1) * $_[0]->{'state_days'}; }],
1873 'P' => ['<=>', sub { return (-1) * $_[0]->{'buildpri'}; }],
1874 'p' => ['<=>', sub { return $prioval{$_[0]->{'priority'}}; }],
1875 's' => ['<=>', sub { return $sectval{$_[0]->{'section'}}; }],
1876 'n' => ['cmp', sub { return $_[0]->{'package'}; }],
1877 'b' => ['cmp', sub { return $_[0]->{'builder'}; }],
1878 'c' => ['<=>', sub { return ($_[0]->{'notes'} =~ /^(out-of-date|partial)/) ? 0: ($_[0]->{'notes'} =~ /^uncompiled/) ? 2 : 1; }],
1879 'f' => ['<=>', sub { return $catval{ $_[0]->{'failed_category'} ? $_[0]->{'failed_category'}: "none" }; }],
1880 'S' => ['<=>', sub { return $prioval{$_[0]->{'priority'}} > $prioval{'standard'}; }],
1883 foreach my $letter (split( //, $list_order )) {
1885 $r = &{$map_funcs->{$letter}[1]}($a) <=> &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq '<=>';
1886 $r = &{$map_funcs->{$letter}[1]}($a) cmp &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq 'cmp';
1887 return $r if $r != 0;
1892 sub calculate_prio {
1893 my $priomap = $yamlmap->{priority};
1895 my @s=split("/", $pkg->{'section'});
1896 $pkg->{'component'} = $s[0] if $s[1];
1897 $pkg->{'component'} ||= 'main';
1898 $pkg->{'calprio'} = 0;
1899 foreach my $k (keys %{$priomap->{keys}}) {
1900 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1903 my $days = $pkg->{'state_days'};
1904 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1905 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1906 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1907 $pkg->{'calprio'} += $days * $scale;
1909 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1910 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1918 return "" unless $t;
1920 my $min = int($t/60) % 60;
1921 my $hours = int($t / 3600);
1922 return sprintf("%d:%02d:%02d", $hours, $min, $sec) if $hours;
1923 return sprintf("%d:%02d", $min, $sec);
1930 if (ref($_[0]) eq 'CODE') {
1940 return $r unless $t;
1944 if (substr($t,0,1) eq '!') {
1948 return "" unless $r;
1951 return print_format($t, $pkg, $var);
1955 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
1958 my $printfmt = shift;
1962 Within an format string, the following values are allowed (need to be preceded by %).
1963 This can be combined to e.g.
1964 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
1967 c section (e.g. libs or utils)
1968 D in case of BD-Uninstallable the reason for the uninstallability
1970 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
1971 F in case of Failed the fail reason
1973 o time of last successful build (seconds)
1974 O time of last successful build (formated)
1977 q time of last build (seconds)
1978 Q time of last build (formated)
1979 r max time of last (successful) build (seconds)
1980 R max time of last (successful) build (formated)
1982 s Time in this state in full seconds since epoch
1983 t time of state change
1984 T time since state change
1985 u Builder (e.g. buildd_mipsel-rem)
1987 V full Package version (i.e. with +b.., = %v%{+b}B%B
1988 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
1990 %{Text}? print Text in case ? is not empty; ? is never printed
1991 %{!Text}? print Text in case ? is empty; ? is never printed
1992 Text could contain further %. To start with !, use %!
1995 return stringf($printfmt, (
1996 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
1997 'a' => make_fmt( $arch, $pkg, $var),
1998 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
1999 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
2000 'V' => make_fmt( sub { $pkg->{'binary_nmu_version'} ? $pkg->{'version'}."+b".$pkg->{'binary_nmu_version'} : $pkg->{'version'} }, $pkg, $var),
2001 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
2002 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
2003 'X' => make_fmt( sub {
2004 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
2005 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} =~ /^Failed/;
2006 $c .= ":bp{" . $pkg->{'buildpri'} . "}" if defined $pkg->{'buildpri'};
2007 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
2008 $c .= ":calprio{". $pkg->{'calprio'}."}";
2009 $c .= ":days{". $pkg->{'state_days'}."}";
2012 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
2013 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
2014 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
2015 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
2016 return ""; }, $pkg, $var),
2017 'F' => make_fmt( sub { return "" unless $pkg->{'failed'};
2018 my $failed = $pkg->{'failed'};
2019 $failed =~ s/\\/\\\\/g;
2020 return $pkg->{'package'}."#".$arch."-failure\n ".
2021 join("\\0a",split("\n",$failed))."\\0a\n"; }, $pkg, $var),
2022 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
2023 return $pkg->{'package'}."#".$arch."-bd-problem\n".
2024 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
2025 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
2026 'd' => make_fmt( $pkg->{'distribution'}, $pkg, $var),
2027 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
2028 'T' => make_fmt( sub { return seconds2time(time() - floor(str2time($pkg->{'state_change'}))); }, $pkg, $var),
2029 'o' => make_fmt( $pkg->{'successtime'}, $pkg, $var),
2030 'O' => make_fmt( sub { return seconds2time ( $pkg->{'successtime'}); }, $pkg, $var),
2031 'q' => make_fmt( $pkg->{'anytime'}, $pkg, $var),
2032 'Q' => make_fmt( sub { return seconds2time ( $pkg->{'anytime'}); }, $pkg, $var),
2033 'r' => make_fmt( sub { return max($pkg->{'successtime'}, $pkg->{'anytime'}); }, $pkg, $var),
2034 'R' => make_fmt( sub { return seconds2time ( max($pkg->{'successtime'}, $pkg->{'anytime'})); }, $pkg, $var),
2040 my( $name, $pkg, @list );
2045 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
2046 foreach $name (keys %$db) {
2047 next if $name =~ /^_/;
2048 push @list, calculate_prio($db->{$name});
2052 @list = grep { my $i = $_->{'component'}; grep { $i eq $_ } split /[, ]+/, $yamlmap->{"restrict"}{'component'} } @list;
2053 # extra depends / conflicts only from api 1 on
2054 @list = grep { !$_->{'extra_depends'} and !$_->{'extra_conflicts'} } @list if $api < 1 ;
2056 # first adjust ownprintformat, then set printformat accordingly
2057 $printformat ||= $yamlmap->{"format"}{$ownprintformat};
2058 $printformat ||= $yamlmap->{"format"}{"default"}{$state};
2059 $printformat ||= $yamlmap->{"format"}{"default"}{"default"};
2060 undef $printformat if ($ownprintformat eq 'none');
2062 foreach $pkg (sort sort_list_func @list) {
2064 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
2066 $scnt{$pkg->{'state'}}++;
2069 print print_format("%c/%p_%v", $pkg, {});
2070 print print_format(": %S", $pkg, {})
2072 print print_format("%{ by }u%u", $pkg, {})
2073 if $pkg->{'state'} ne "Needs-Build";
2074 print print_format(" [%X]\n", $pkg, {});
2075 print " Reasons for failing:\n",
2077 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
2079 join("\n ",split("\n",$pkg->{'failed'})), "\n"
2080 if $pkg->{'state'} =~ /^Failed/;
2081 print " Dependencies: $pkg->{'depends'}\n"
2082 if $pkg->{'state'} eq "Dep-Wait";
2083 print " Reasons for BD-Uninstallable:\n ",
2084 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
2085 if $pkg->{'state'} eq "BD-Uninstallable";
2086 print " Previous state was $pkg->{'previous_state'}\n"
2087 if $verbose && $pkg->{'previous_state'};
2088 print " No previous state recorded\n"
2089 if $verbose && !$pkg->{'previous_state'};
2090 print " State changed at $pkg->{'state_change'}\n"
2091 if $verbose && $pkg->{'state_change'};
2092 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
2093 if $verbose && $pkg->{'previous_state'};
2094 print " Previous failing reasons:\n ",
2095 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
2096 if $verbose && $pkg->{'old_failed'};
2098 $scnt{$pkg->{'state'}}++ if $state eq "all";
2100 if ($state eq "all" && !$printformat) {
2101 foreach (sort keys %scnt) {
2102 print "Total $scnt{$_} package(s) in state $_.\n";
2105 print "Total $cnt package(s)\n" unless $printformat;
2110 my( $name, $pkg, $key, $dist );
2111 my @firstkeys = qw(package version builder state section priority
2112 installed_version previous_state state_change);
2113 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
2114 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
2115 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
2116 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
2117 'state_change' => 'State-Change',
2118 'bd_problem' => 'BD-Problem',
2119 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
2120 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
2121 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
2122 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
2123 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
2124 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days',
2125 'successtime' => 'Success-build-time',
2126 'anytime' => 'Build-time',
2127 'extra_depends' => 'Extra-Dependencies',
2128 'extra_conflicts' => 'Extra-Conflicts',
2131 foreach $name (@_) {
2132 $name =~ s/_.*$//; # strip version
2133 foreach $dist (@dists) {
2134 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
2136 $pkg = get_readonly_source_info($name);
2137 if (!defined( $pkg )) {
2138 print "$pname: not registered\n";
2141 $pkg = calculate_prio($pkg);
2144 foreach $key (@firstkeys) {
2145 next if !defined $pkg->{$key};
2146 my $val = $pkg->{$key};
2148 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2150 my $print_key = $key;
2151 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2152 printf " %-20s: %s\n", $print_key, $val;
2154 foreach $key (sort keys %$pkg) {
2155 next if isin( $key, @firstkeys );
2156 my $val = $pkg->{$key};
2157 next if !defined($val);
2159 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2161 my $print_key = $key;
2162 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2163 printf " %-20s: %s\n", $print_key, $val;
2169 sub forget_packages {
2170 my( $name, $pkg, $key, $data );
2172 foreach $name (@_) {
2173 $name =~ s/_.*$//; # strip version
2174 $pkg = get_source_info($name);
2175 if (!defined( $pkg )) {
2176 print "$name: not registered\n";
2181 foreach $key (sort keys %$pkg) {
2182 my $val = $pkg->{$key};
2185 $data .= sprintf " %-20s: %s\n", $key, $val;
2187 send_mail( $conf::db_maint,
2188 "$name deleted from DB " . table_name() . " " . $distribution,
2189 "The package '$name' has been deleted from the database ".
2191 "Data registered about the deleted package:\n".
2192 "$data\n" ) if $conf::db_maint;
2193 change_state( \$pkg, 'deleted' );
2194 log_ta( $pkg, "--forget" );
2195 del_source_info($name);
2196 print "$name: deleted from database\n" if $verbose;
2201 $dbh->do("DELETE from " . user_table_name() .
2202 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
2208 print "Reading ASCII database from $file..." if $verbose >= 1;
2209 open( F, "<$file" ) or
2210 die "Can't open database $file: $!\n";
2212 local($/) = ""; # read in paragraph mode
2214 my( %thispkg, $name );
2216 s/\n[ \t]+/\376\377/g; # fix continuation lines
2217 s/\376\377\s*\376\377/\376\377/og;
2219 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2220 my ($key, $val) = ($1, $2);
2222 $key =~ tr/A-Z/a-z/;
2223 $val =~ s/\376\377/\n/g;
2224 $thispkg{$key} = $val;
2226 check_entry( \%thispkg );
2228 if (exists($thispkg{'package'})) {
2229 update_source_info(\%thispkg);
2231 elsif(exists($thispkg{'user'})) {
2232 # user in import, username in database.
2233 $dbh->do('INSERT INTO ' . user_table_name() .
2234 ' (username, distribution, last_seen)' .
2235 ' values (?, ?, ?)',
2236 undef, $thispkg{'user'}, $distribution,
2237 $thispkg{'last_seen'})
2238 or die $dbh->errstr;
2242 print "done\n" if $verbose >= 1;
2249 return if $op_mode eq "manual-edit"; # no checks then
2251 # check for required fields
2252 if (exists $pkg->{'user'}) {
2255 if (!exists $pkg->{'package'}) {
2256 print STDERR "Bad entry: ",
2257 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2258 die "Database entry lacks package or username field\n";
2260 # if no State: field, generate one (for old db compat)
2261 if (!exists($pkg->{'state'})) {
2263 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2265 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2266 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2269 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2270 if !isin( $pkg->{'state'},
2271 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2272 Failed Failed-Removed Not-For-Us BD-Uninstallable
2278 my($name,$pkg,$key);
2280 print "Writing ASCII database to $file..." if $verbose >= 1;
2281 open( F, ">$file" ) or
2282 die "Can't open export $file: $!\n";
2284 my $db = get_all_source_info();
2285 foreach $name (keys %$db) {
2286 next if $name =~ /^_/;
2287 my $pkg = $db->{$name};
2288 foreach $key (keys %{$pkg}) {
2289 my $val = $pkg->{$key};
2290 next if !defined($val);
2293 $val =~ s/^ +$/ ./mg;
2294 print F "$key: $val\n";
2299 print "done\n" if $verbose >= 1;
2305 my $newstate = shift;
2306 my $state = \$pkg->{'state'};
2308 return if defined($$state) and $$state eq $newstate;
2309 $pkg->{'previous_state'} = $$state if defined($$state);
2310 $pkg->{'state_change'} = $curr_date;
2311 $pkg->{'do_state_change'} = 1;
2313 if (defined($$state) and $$state eq 'Failed') {
2314 $pkg->{'old_failed'} =
2315 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2316 $pkg->{'failed'} . "\n" .
2317 $pkg->{'old_failed'};
2318 delete $pkg->{'failed'};
2319 delete $pkg->{'failed_category'};
2321 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2322 delete $pkg->{'bd_problem'};
2324 $$state = $newstate;
2330 my $dist = $distribution;
2334 $prevstate = $pkg->{'previous_state'};
2335 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2336 "changed from $prevstate to $pkg->{'state'} ".
2337 "by $real_user as $user";
2340 printf "update transactions: %s %s %s %s %s %s %s %s\n",
2341 $pkg->{'package'}, $distribution,
2342 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2346 $dbh->do('INSERT INTO ' . transactions_table_name() .
2347 ' (package, distribution, version, action, ' .
2348 ' prevstate, state, real_user, set_user, time) ' .
2349 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2350 undef, $pkg->{'package'}, $distribution,
2351 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2352 $real_user, $user, 'now()') or die $dbh->errstr;
2354 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2355 $str .= " (with --override)"
2357 $mail_logs .= "$str\n";
2364 my $subject = shift;
2367 my $from = $conf::db_maint;
2368 my $domain = $conf::buildd_domain;
2370 $from .= "\@$domain" if $from !~ /\@/;
2372 $to .= '@' . $domain if $to !~ /\@/;
2373 $text =~ s/^\.$/../mg;
2374 local $SIG{'PIPE'} = 'IGNORE';
2375 open( PIPE, "| $conf::mailprog -oem $to" )
2376 or die "Can't open pipe to $conf::mailprog: $!\n";
2378 print PIPE "From: $from\n";
2379 print PIPE "Subject: $subject\n\n";
2380 print PIPE "$text\n";
2384 # for parsing input to dep-wait
2390 foreach (split( /\s*,\s*/, $deps )) {
2392 # verification requires > starting prompts, no | crap
2393 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2398 my @alts = split( /\s*\|\s*/, $_ );
2399 # Anything with an | is ignored, as it can be configured on a
2400 # per-buildd basis what will be installed
2401 next if $#alts != 0;
2404 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2405 warn( "parse_deplist: bad dependency $_\n" );
2408 my($dep, $rel, $relv) = ($1, $3, $4);
2409 $rel = ">>" if defined($rel) and $rel eq ">";
2410 $result{$dep}->{'package'} = $dep;
2411 if ($rel && $relv) {
2412 $result{$dep}->{'rel'} = $rel;
2413 $result{$dep}->{'version'} = $relv;
2416 return 1 if $verify;
2424 foreach $key (keys %$list) {
2425 $result .= ", " if $result;
2427 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2428 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2435 return "" unless $_[0];
2436 return Dpkg::Deps::parse($_[0], ("reduce_arch" => 1, "host_arch" => $_[1]))->dump();
2439 sub wb_edos_builddebcheck {
2440 # Copyright (C) 2008 Ralf Treinen <treinen@debian.org>
2441 # This program is free software: you can redistribute it and/or modify it under
2442 # the terms of the GNU General Public License as published by the Free Software
2443 # Foundation, version 2 of the License.
2444 # integrated into wanna-builds code by Andreas Barth 2010
2447 my $sourceprefix="source---";
2448 my $architecture=$args->{'arch'};
2449 my $edosoptions = "-failures -explain -quiet";
2450 my $packagefiles = $args->{'pkgs'};
2451 my $sourcesfile = $args->{'src'};
2454 foreach my $packagefile (@$packagefiles) {
2455 open(P,$packagefile);
2457 next unless /^Architecture/;
2458 next if /^Architecture:\s*all/;
2459 /Architecture:\s*([^\s]*)/;
2460 if ($packagearch eq "") {
2462 } elsif ( $packagearch ne $1) {
2463 return "Package file contains different architectures: $packagearch, $1";
2469 if ( $architecture eq "" ) {
2470 if ( $packagearch eq "" ) {
2471 return "No architecture option given, " .
2472 "and no non-all architecture found in the Packages file";
2474 $architecture = $packagearch;
2477 if ( $packagearch ne "" & $architecture ne $packagearch) {
2478 return "Architecture option is $architecture ".
2479 "but the package file contains architecture $packagearch";
2483 print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n";
2485 "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles));
2492 # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED
2493 # source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing:
2494 # - libltdl-dev (>= 2.2.6a-2)
2495 # source---libcanberra (= 0.22-1~bpo50+1): FAILED
2496 # source---libcanberra (= 0.22-1~bpo50+1) depends on missing:
2498 # - libltdl7-dev (>= 2.2.6)
2501 s/^(\s*)$sourceprefix(.*)depends on/$1$2build-depends on/o;
2502 s/^(\s*)$sourceprefix(.*) and (.*) conflict/$1$2 build-conflicts with $3/o;
2505 if (/^$sourceprefix(.*) \(.*\): FAILED/o) {
2506 $result->{$binpkg} = $explanation if $binpkg;
2509 } elsif (/^(depwait---.*) \(.*\): FAILED/o) {
2510 $result->{$binpkg} = $explanation if $binpkg;
2513 } else { # else something broken is happening
2514 #print "ignoring $_\n";
2521 $result->{$binpkg} = $explanation if $binpkg;
2527 sub call_edos_depcheck {
2528 return if $simulate_edos;
2530 my $srcs = $args->{'srcs'};
2533 return if defined ($conf::distributions{$distribution}{noadw}) && not defined $args->{'depwait'};
2535 # We need to check all of needs-build, as any new upload could make
2536 # something in needs-build have uninstallable deps
2537 # We also check everything in bd-uninstallable, as any new upload could
2538 # make that work again
2539 my (%interesting_packages, %interesting_packages_depwait);
2540 my $db = get_all_source_info();
2541 foreach $key (keys %$db) {
2542 my $pkg = $db->{$key};
2543 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/) and not defined ($conf::distributions{$distribution}{noadw})) {
2544 $interesting_packages{$key} = undef;
2546 if (defined $pkg and isin($pkg->{'state'}, qw/Dep-Wait/) and defined $args->{'depwait'}) {
2547 $interesting_packages_depwait{$key} = undef;
2548 # we always check for BD-Uninstallability in depwait - could be that depwait is satisfied but package is uninstallable
2549 $interesting_packages{$key} = undef unless defined ($conf::distributions{$distribution}{noadw});
2553 #print "I would look at these sources with edos-depcheck:\n";
2554 #print join " ", keys %interesting_packages,"\n";
2555 return unless %interesting_packages || %interesting_packages_depwait;
2557 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-XXXXX";
2558 use File::Temp qw/ tempfile /;
2559 my ($SOURCES, $tmpfile) = tempfile( $tmpfile_pattern, UNLINK => 1 );
2560 for my $key (keys %interesting_packages) {
2561 my $pkg = $db->{$key};
2562 # we print the source files as binary ones (with "source---"-prefixed),
2563 # so we can try if these "binary" packages are installable.
2564 # If such a "binary" package is installable, the corresponding source package is buildable.
2565 print $SOURCES "Package: source---$key\n";
2566 print $SOURCES "Version: $pkg->{'version'}\n";
2567 my $t = &filterarch($srcs->{$key}{'dep'} || $srcs->{$key}{'depends'}, $arch);
2568 my $tt = &filterarch($pkg->{'extra_depends'}, $arch);
2569 $t = $t ? ($tt ? "$t, $tt" : $t) : $tt;
2570 print $SOURCES "Depends: $t\n" if $t;
2571 my $u = &filterarch($srcs->{$key}{'conf'} || $srcs->{$key}{'conflicts'}, $arch);
2572 my $uu = &filterarch($pkg->{'extra_conflicts'}, $arch);
2573 $u = $u ? ($uu ? "$u, $uu" : $u) : $uu;
2574 print $SOURCES "Conflicts: $u\n" if $u;
2575 print $SOURCES "Architecture: all\n";
2576 print $SOURCES "\n";
2578 for my $key (keys %interesting_packages_depwait) {
2579 my $pkg = $db->{$key};
2580 # we print the source files as binary ones (with "depwait---"-prefixed),
2581 # so we can try if these "binary" packages are installable.
2582 # If such a "binary" package is installable, the corresponding source package goes out of depwait
2583 print $SOURCES "Package: depwait---$key\n";
2584 print $SOURCES "Version: $pkg->{'version'}\n";
2585 print $SOURCES "Depends: $pkg->{'depends'}\n";
2586 print $SOURCES "Architecture: all\n";
2587 print $SOURCES "\n";
2591 my $edosresults = wb_edos_builddebcheck({'arch' => $args->{'arch'}, 'pkgs' => $args->{'pkgs'}, 'src' => $tmpfile});
2592 if (ref($edosresults) eq 'HASH') {
2593 foreach my $key (grep { $_ !~ /^depwait---/ } keys %$edosresults) {
2594 if (exists $interesting_packages{$key}) {
2595 $interesting_packages{$key} = $edosresults->{$key};
2597 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2600 foreach my $key (grep { $_ =~ /^depwait---/ } keys %$edosresults) {
2601 $key =~ /^depwait---(.*)/ and $key = $1;
2602 if (exists $interesting_packages_depwait{$key}) {
2603 $interesting_packages_depwait{$key} = $edosresults->{"depwait---".$key};
2605 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2609 # if $edosresults isn't an hash, then something went wrong and the string is the error message
2610 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2611 "all packages have installable build-dependencies."
2616 for my $key (keys %interesting_packages) {
2617 next if defined $interesting_packages_depwait{$key};
2618 my $pkg = $db->{$key};
2620 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2621 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2622 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2624 if (defined $interesting_packages{$key}) {
2625 change_state( \$pkg, 'BD-Uninstallable' );
2626 $pkg->{'bd_problem'} = $interesting_packages{$key};
2628 change_state( \$pkg, 'Needs-Build' );
2631 if ($problemchange) {
2632 if (defined $interesting_packages{$key}) {
2633 $pkg->{'bd_problem'} = $interesting_packages{$key};
2637 log_ta( $pkg, "--merge-all (edos)" ) unless $simulate;
2638 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) to $pkg->{'state'}\n" if $verbose || $simulate;
2640 if ($change || $problemchange) {
2641 update_source_info($pkg) unless $simulate;
2645 for my $key (keys %interesting_packages_depwait) {
2646 if ($interesting_packages_depwait{$key}) {
2647 print "dep-wait for $key ($args->{'arch'}) not fullfiled yet\n" if $verbose || $simulate;
2650 my $pkg = $db->{$key};
2651 if (defined $interesting_packages{$key}) {
2652 change_state( \$pkg, 'BD-Uninstallable' );
2653 $pkg->{'bd_problem'} = $interesting_packages{$key};
2655 change_state( \$pkg, 'Needs-Build' );
2657 log_ta( $pkg, "edos_depcheck: depwait" ) unless $simulate;
2658 update_source_info($pkg) unless $simulate;
2659 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) from dep-wait to $pkg->{'state'}\n" if $verbose || $simulate;
2665 ($prgname = $0) =~ s,^.*/,,;
2667 Usage: $prgname <options...> <package_version...>
2669 -v, --verbose: Verbose execution.
2670 -A arch: Architecture this operation is for.
2671 --take: Take package for building [default operation]
2672 -f, --failed: Record in database that a build failed due to
2673 deficiencies in the package (that aren't fixable without a new
2675 -u, --uploaded: Record in the database that the packages build
2676 correctly and were uploaded.
2677 -n, --no-build: Record in the database that the packages aren't
2678 desired for this architecture and shouldn't appear in listings even
2679 if they're out of date.
2680 --dep-wait: Record in the database that the packages are waiting
2681 for some source dependencies to become available
2682 --binNMU num: Schedule a re-build of the package with unchanged source, but
2683 a new version number (source-version + "+b<num>")
2684 --give-back: Mark a package as ready to build that is in state Building,
2685 Built or Build-Attempted. To give back a package in state Failed, use
2686 --override. This command will actually put the package in state
2687 BD-Uninstallable, until the installability of its Build-Dependencies
2688 were verified. This happens at each call of --merge-all, usually
2690 --merge-quinn: Merge quinn-diff output into database.
2691 --merge-packages: Merge Packages files into database.
2692 --pretend-avail: Pretend that given packages are available now and give
2693 free packages waiting for them
2694 -i SRC_PKG, --info SRC_PKG: Show information for source package
2695 -l STATE, --list=STATE: List all packages in state STATE; can be
2696 combined with -U to restrict to a specific user; STATE can
2698 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2699 source dependency list
2700 (used with -f, --dep-wait, and --binNMU)
2701 -o, --override: Override another user's lock on a package, i.e.
2702 take it over; a notice mail will be sent to the other user
2703 -U USER, --user=USER: select user name for which listings should
2704 apply, if not given all users are listed.
2705 if -l is missing, set user name to be entered in db; usually
2706 automatically choosen
2707 --import FILE: Import database from a ASCII file FILE
2708 --export FILE: Export database to a ASCII file FILE
2710 The remaining arguments (depending on operation) usually start with
2711 "name_version", the trailer is ignored. This allows to pass the names
2712 of .dsc files, for which file name completion can be used.
2713 --merge-packages and --merge-quinn take Package/quin--diff file names
2714 on the command line or read stdin. --list needs nothing more on the
2715 command line. --info takes source package names (without version).
2720 sub pkg_version_eq {
2722 my $version = shift;
2725 if (defined $pkg->{'binary_nmu_version'}) and
2726 version_compare(binNMU_version($pkg->{'version'},
2727 $pkg->{'binary_nmu_version'}),'=', $version);
2728 return version_compare( $pkg->{'version'}, "=", $version );
2732 return '"' . $arch . $schema_suffix . '".packages';
2735 sub user_table_name {
2736 return '"' . $arch . $schema_suffix . '".users';
2739 sub transactions_table_name {
2740 return '"' . $arch . $schema_suffix . '".transactions';
2743 sub pkg_history_table_name {
2744 return '"' . $arch . $schema_suffix . '".pkg_history';
2747 sub get_readonly_source_info {
2749 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2750 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"
2751 . ", (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"
2752 . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2753 . ", extra_depends, extra_conflicts"
2754 . " FROM " . table_name()
2755 . ' WHERE package = ? AND distribution = ?';
2756 my $pkg = $dbh->selectrow_hashref( $q,
2757 undef, $name, $distribution);
2761 sub get_source_info {
2763 return get_readonly_source_info($name) if $simulate;
2764 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change)) as state_days FROM ' .
2765 table_name() . ' WHERE package = ? AND distribution = ?' .
2767 undef, $name, $distribution);
2771 sub get_all_source_info {
2774 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"
2775 # . ", (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"
2776 # . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2777 . ", successtime.build_time as successtime, anytime.build_time as anytime, extra_depends, extra_conflicts"
2778 . " FROM " . table_name()
2780 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." where result = 'successful' order by package, distribution, timestamp "
2781 . " ) as successtime using (package, distribution) "
2783 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." order by package, distribution, timestamp desc"
2784 . " ) as anytime using (package, distribution) "
2787 if ($distribution) {
2788 my @dists = split(/[, ]+/, $distribution);
2789 $q .= ' AND ( distribution = ? '.(' OR distribution = ? ' x $#dists).' )';
2790 foreach my $d ( @dists ) {
2794 if ($options{state} && uc($options{state}) ne "ALL") {
2795 $q .= ' AND upper(state) = ? ';
2796 push @args, uc($options{state});
2799 if ($options{user} && uc($options{state}) ne "NEEDS-BUILD") { # if it's NEEDS-BUILD, we don't look at users
2800 #this basically means "this user, or no user at all":
2801 $q .= " AND (builder = ? OR upper(state) = 'NEEDS-BUILD')";
2802 push @args, $options{user};
2805 if ($options{category}) {
2806 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2807 push @args, $options{category};
2808 push @args, "FAILED";
2811 if ($options{list_min_age} > 0) {
2812 $q .= ' AND age(state_change) > ? ';
2813 push @args, $options{list_min_age} . " days";
2816 if ($options{list_min_age} < 0) {
2817 $q .= ' AND age(state_change) < ? ';
2818 push @args, -$options{list_min_age} . " days";
2821 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2825 sub update_source_info {
2827 $pkg->{'extra_depends'} = $extra_depends if defined $extra_depends;
2828 undef $pkg->{'extra_depends'} unless $pkg->{'extra_depends'};
2829 $pkg->{'extra_conflicts'} = $extra_conflicts if defined $extra_conflicts;
2830 undef $pkg->{'extra_conflicts'} unless $pkg->{'extra_conflicts'};
2831 print Dumper $pkg if $verbose and $simulate;
2832 return if $simulate;
2834 my $pkg2 = get_source_info($pkg->{'package'});
2835 if (! defined $pkg2)
2837 add_source_info($pkg);
2840 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2845 'installed_version = ?, ' .
2846 'previous_state = ?, ' .
2847 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2851 'old_failed = ?, ' .
2852 'binary_nmu_version = ?, ' .
2853 'binary_nmu_changelog = ?, ' .
2854 'failed_category = ?, ' .
2855 'permbuildpri = ?, ' .
2859 'extra_depends = ?, ' .
2860 'extra_conflicts = ?, ' .
2862 'WHERE package = ? AND distribution = ?',
2868 $pkg->{'installed_version'},
2869 $pkg->{'previous_state'},
2873 $pkg->{'old_failed'},
2874 $pkg->{'binary_nmu_version'},
2875 $pkg->{'binary_nmu_changelog'},
2876 $pkg->{'failed_category'},
2877 $pkg->{'permbuildpri'},
2881 $pkg->{'extra_depends'},
2882 $pkg->{'extra_conflicts'},
2883 $pkg->{'bd_problem'},
2885 $distribution) or die $dbh->errstr;
2888 sub add_source_info {
2889 return if $simulate;
2891 $dbh->do('INSERT INTO ' . table_name() .
2892 ' (package, distribution) values (?, ?)',
2893 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2896 sub del_source_info {
2897 return if $simulate;
2899 $dbh->do('DELETE FROM ' . table_name() .
2900 ' WHERE package = ? AND distribution = ?',
2901 undef, $name, $distribution) or die $dbh->errstr;
2906 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2907 user_table_name() . ' WHERE username = ? AND distribution = ?',
2908 undef, $name, $distribution);
2912 sub update_user_info {
2913 return if $simulate;
2915 $dbh->do('UPDATE ' . user_table_name() .
2916 ' SET last_seen = now() WHERE username = ?' .
2917 ' AND distribution = ?',
2918 undef, $user, $distribution)
2919 or die $dbh->errstr;
2924 return if $simulate;
2926 $dbh->do('INSERT INTO ' . user_table_name() .
2927 ' (username, distribution, last_seen)' .
2928 ' values (?, ?, now())',
2929 undef, $user, $distribution)
2930 or die $dbh->errstr;
2935 return if $simulate;
2936 $dbh->do('LOCK TABLE ' . table_name() .
2937 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;
2941 # parts the array $_[0] and $_[1] and returns the sub-array (modifies the original one)
2944 my $separator = shift;
2945 while($args->[0] && $args->[0] ne $separator) {
2946 push @ret, shift @$args;
2948 shift @$args if @$args;
2952 sub parse_all_v3() {
2955 my $db = get_all_source_info();
2956 my $binary = $srcs->{'_binary'};
2959 foreach my $name (keys %$srcs) {
2960 next if $name eq '_binary';
2962 # state = installed, out-of-date, uncompiled, not-for-us
2963 my $pkgs = $srcs->{$name};
2964 my $pkg = $db->{$name};
2967 next SRCS if $pkgs->{'status'} eq 'not-for-us';
2968 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'} ($vars->{'arch'}, $vars->{'suite'}):";
2970 # does at least one binary exist in the database and is more recent - if so, we're probably just outdated, ignore the source package
2971 for my $bin (@{$pkgs->{'binary'}}) {
2972 if ($binary->{$bin} and vercmp($pkgs->{'version'}, $binary->{$bin}->{'version'}) < 0) {
2973 print "$logstr skipped because binaries (assumed to be) overwritten\n" if $verbose || $simulate;
2977 $pkg->{'package'} = $name;
2979 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'}".
2980 ($pkgs->{'binnmu'} ? ";b".$pkgs->{'binnmu'} : "").
2981 "($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'version'}".
2982 ($pkg->{'binary_nmu_version'} ? ";b".$pkg->{'binary_nmu_version'} : "").
2983 ", $pkg->{'state'}):";
2985 if (isin($pkgs->{'status'}, qw (installed related)) && $pkg->{'binary_nmu_version'} && $pkgs->{'binnmu'} < int($pkg->{'binary_nmu_version'})) {
2986 $pkgs->{'status'} = 'out-of-date';
2988 if (isin($pkgs->{'status'}, qw (installed related))) {
2990 if ($pkg->{'state'} ne 'Installed') {
2991 change_state( \$pkg, 'Installed');
2992 delete $pkg->{'depends'};
2993 delete $pkg->{'extra_depends'};
2994 delete $pkg->{'extra_conflicts'};
2997 my $attrs = { 'version' => 'version', 'installed_version' => 'version', 'binary_nmu_version' => 'binnmu', 'section' => 'section', 'priority' => 'priority' };
2998 foreach my $k (keys %$attrs) {
2999 if ($pkg->{$k} ne $pkgs->{$attrs->{$k}}) {
3000 $pkg->{$k} = $pkgs->{$attrs->{$k}};
3004 if (isin($pkgs->{'status'}, qw (related)) and $pkg->{'notes'} ne "related") {
3005 $pkg->{'notes'} = "related";
3009 print "$logstr set to installed/".$pkg->{'notes'}."\n" if $verbose || $simulate;
3010 log_ta( $pkg, "--merge-v3: installed" ) unless $simulate;
3011 update_source_info($pkg) unless $simulate;
3016 if ($pkgs->{'status'} eq 'not-for-us') {
3017 next if isin( $pkg->{'state'}, qw(Not-For-Us Installed Failed-Removed));
3019 if (isin( $pkg->{'state'}, qw(Failed Build-Attempted Built))) {
3020 change_state( \$pkg, "Failed-Removed" );
3021 log_ta( $pkg, "--merge-v3: Failed-Removed" ) unless $simulate;
3022 update_source_info($pkg) unless $simulate;
3023 print "$logstr (virtually) deleted from database\n" if $verbose || $simulate;
3027 print "$logstr should delete (not-for-us according to P-a-s)\n" if $verbose || $simulate || 1; # not implemented yet on purpose
3031 # only uncompiled / out-of-date are left, so check if anything new
3032 if (!(isin($pkgs->{'status'}, qw (uncompiled out-of-date)))) {
3033 print "$logstr package in unknown state: $pkgs->{'status'}\n";
3036 next if $pkgs->{'version'} eq $pkg->{'version'} and $pkgs->{'binnmu'} >= int($pkg->{'binary_nmu_version'});
3037 next if $pkgs->{'version'} eq $pkg->{'version'} and !isin( $pkg->{'state'}, qw(Installed));
3038 next if isin( $pkg->{'state'}, qw(Not-For-Us Failed-Removed));
3040 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
3041 send_mail( $pkg->{'builder'},
3042 "new version of $name (dist=$distribution)",
3043 "As far as I'm informed, you're currently building the package $name\n".
3044 "in version $pkg->{'version'}.\n\n".
3045 "Now there's a new source version $pkgs->{'version'}. If you haven't finished\n".
3046 "compiling $name yet, you can stop it to save some work.\n".
3047 "Just to inform you...\n".
3048 "(This is an automated message)\n" ) unless $simulate;
3049 print "$logstr new version while building $pkg->{'version'} -- sending mail to builder ($pkg->{'builder'})\n"
3050 if $verbose || $simulate;
3052 change_state( \$pkg, 'Needs-Build');
3053 $pkg->{'notes'} = $pkgs->{'status'};
3054 $pkg->{'version'} = $pkgs->{'version'};
3055 $pkg->{'section'} = $pkgs->{'section'};
3056 $pkg->{'priority'} = $pkgs->{'priority'};
3057 $pkg->{'dep'} = $pkgs->{'depends'};
3058 $pkg->{'conf'} = $pkgs->{'conflicts'};
3059 delete $pkg->{'builder'};
3060 delete $pkg->{'binary_nmu_version'} unless $pkgs->{'binnmu'};
3061 delete $pkg->{'binary_nmu_changelog'} unless $pkgs->{'binnmu'};
3062 log_ta( $pkg, "--merge-v3: needs-build" ) unless $simulate;
3063 update_source_info($pkg) unless $simulate;
3064 print "$logstr set to needs-builds\n" if $simulate || $verbose;
3067 foreach my $name (keys %$db) {
3068 next if $srcs->{$name};
3069 my $pkg = $db->{$name};
3070 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkg->{'version'} ($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'state'}):";
3071 # package disappeared - delete
3072 change_state( \$pkg, 'deleted' );
3073 log_ta( $pkg, "--merge-v3: deleted" ) unless $simulate;
3074 print "$logstr deleted from database\n" if $verbose || $simulate;
3075 del_source_info($name) unless $simulate;
3076 delete $db->{$name};