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
70 our $recorduser = undef;
73 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
78 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
79 $short_date = strftime("%m/%d/%y",@curr_time);
82 # map program invocation names to operation modes
83 my %prognames = ( "uploaded-build" => "set-uploaded",
84 "failed-build" => "set-failed",
85 "no-build" => "set-not-for-us",
86 "give-back-build" => "set-needs-build",
87 "dep-wait-build" => "set-dep-wait",
88 "forget-build" => "forget",
89 "build-info" => "info" );
91 %short_category = ( u => "uploaded-fixed-pkg",
98 c => "compiler-error",
102 ($progname = $0) =~ s,.*/,,;
103 if ($prognames{$progname}) {
104 $op_mode = $prognames{$progname};
106 elsif ($progname =~ /^list-(.*)$/) {
108 $list_state = ($1 eq "all") ? "" : $1;
113 simulate => { flag => \$simulate }, # this is not supported by all operations (yet)!
114 "simulate-edos" => { flag => \$simulate_edos },
115 "simulate-all" => { code => sub { $simulate = 1; $simulate_edos = 1; } },
116 api => { arg => \$api, code => sub {
117 # official apis are numeric
118 die "$api isn't numeric" unless int($api) eq $api;
119 die "$api too large" unless $api <= 1;
121 verbose => { short => "v", flag => \$verbose },
122 override => { short => "o", flag => \$opt_override },
123 "create-db" => { flag => \$opt_create_db },
124 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
125 # TODO: remove after buildds no longer pass to wanna-build
126 "no-propagation" => { short => "N" },
127 "no-down-propagation" => { short => "D" },
129 take => { mode => "set-building" },
130 failed => { short => "f", mode => "set-failed" },
131 uploaded => { short => "u", mode => "set-uploaded" },
132 "no-build" => { short => "n", mode => "set-not-for-us" },
133 built => { mode => "set-built" },
134 attempted => { mode => "set-attempted" },
135 "give-back" => { mode => "set-needs-build" },
136 "dep-wait" => { mode => "set-dep-wait" },
137 forget => { mode => "forget" },
138 'forget-user' => { mode => 'forget-user' },
139 update => { mode => "set-update" },
140 #"merge-quinn" => { mode => "merge-quinn" },
141 #"merge-partial-quinn" => { mode => "merge-partial-quinn" },
142 #"merge-packages" => { mode => "merge-packages" },
143 #"merge-sources" => { mode => "merge-sources" },
144 "pretend-avail" => { short => "p", mode => "pretend-avail" },
145 #"merge-all" => { mode => "merge-all" },
146 #"merge-all-secondary" => { mode => "merge-all-secondary" },
147 "merge-v3" => { mode => "merge-v3" },
148 info => { short => "i", mode => "info" },
149 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
150 code => sub { die "Invalid binNMU version: $binNMUver\n"
151 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
152 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
153 code => sub { die "Invalid build priority: $build_priority\n"
154 if $build_priority !~ /^-?[\d]+$/; } },
155 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
156 code => sub { die "Invalid build priority: $build_priority\n"
157 if $build_priority !~ /^-?[\d]+$/; } },
159 { short => "l", mode => "list", arg => \$list_state,
161 die "Unknown state to list: $list_state\n"
162 if !isin( $list_state, qw(needs-build building uploaded
163 built build-attempted failed installed dep-wait
164 not-for-us all failed-removed
165 install-wait reupload-wait bd-uninstallable));} },
168 { short => "d", arg => \$distribution,
170 if ($distribution eq "a" || $distribution eq "all") {
175 $distribution = "oldstable" if $distribution eq "o";
176 $distribution = "stable" if $distribution eq "s";
177 $distribution = "testing" if $distribution eq "t";
178 $distribution = "unstable" if $distribution eq "u";
182 { short => "O", arg => \$list_order,
184 die "Bad ordering character\n"
185 if $list_order !~ /^[PSpsncbCW]+$/;
187 message => { short => "m", arg => \$fail_reason },
188 # database is deprecated, use arch instead.
189 database => { short => "b", arg => \$conf::dbbase },
190 arch => { short => "A", arg => \$arch },
191 user => { short => "U", arg => \$user },
192 category => { short => "c", arg => \$category,
194 $category = $short_category{$category}
195 if exists $short_category{$category};
196 die "Unknown category: $category\n"
197 if !isin( $category, values %short_category );
199 "min-age" => { short => "a", arg => \$list_min_age,
201 die "Argument of --min-age must be a non-zero number\n"
202 if $list_min_age == 0;
204 "max-age" => { arg => \$list_min_age,
206 die "Argument of --max-age must be a non-zero number\n"
207 if $list_min_age == 0;
210 "format" => { arg => \$printformat },
211 "own-format" => { arg => \$ownprintformat },
212 "Pas" => { arg => \$Pas },
213 "extra-depends"=> { arg => \$extra_depends },
214 "extra-conflicts"=> { arg => \$extra_conflicts },
216 export => { arg => \$export_to, mode => "export" },
217 import => { arg => \$import_from, mode => "import" },
218 "manual-edit" => { mode => "manual-edit" },
221 while( @ARGV && $ARGV[0] =~ /^-/ ) {
224 my($opt, $optname, $arg);
225 if (/^--([^=]+)(=|$)/) {
227 $opt = $options{$optname};
228 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
231 $optname = substr( $_, 1, 1 );
232 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
233 $arg = $1 if /^-$optname(.+)$/;
236 warn "Unknown option: --$1\n";
241 die "$optname option missing argument\n" if !@ARGV;
244 ${$opt->{arg}} = $arg;
246 elsif (defined $arg) {
247 die "Option $optname takes no argument\n";
251 die "Conflicting operation modes\n" if $op_mode;
252 $op_mode = $opt->{mode};
262 $op_mode = $category ? "set-failed" : "set-building"
263 if !$op_mode; # default operation
264 $distribution ||= "unstable";
265 if ($distribution eq 'any-priv') {
267 $distribution = 'any';
269 if ($distribution eq 'any-unpriv') {
271 $distribution = 'any';
273 undef $distribution if $distribution eq 'any';
275 my @dists = split(/[, ]+/, $distribution);
276 foreach my $dist (@dists) {
277 die "Bad distribution '$distribution'\n"
278 if !isin($dist, keys %conf::distributions);
281 if (!isin ( $op_mode, qw(list) ) && ( !$distribution || $distribution =~ /[ ,]/)) {
282 die "multiple distributions are only allowed for list";
285 # If they didn't specify an arch, try to get it from database name which
286 # is in the form of $arch/build-db
287 # This is for backwards compatibity with older versions that didn't
288 # specify the arch yet.
289 $conf::dbbase =~ m#^([^/]+)#;
292 # TODO: Check that it's an known arch (for that dist), and give
296 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
297 $version =~ s/(^\$| \$ .*$)//g;
298 print "wanna-build $version for $distribution on $arch\n";
301 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
302 merge-packages manual-edit
304 warn "No packages given.\n";
308 $real_user = (getpwuid($<))[0];
309 die "Can't determine your user name\n"
310 if $op_mode ne "list" && !$user &&
311 !($user = $real_user);
314 if ($op_mode eq "set-failed" && !$category) {
315 print "Enter reason for failing (end with '.' alone on ".
320 last if $line eq ".\n";
321 $fail_reason .= $line;
323 chomp( $fail_reason );
324 } elsif ($op_mode eq "set-dep-wait") {
325 print "Enter dependencies (one line):\n";
327 while( !$line && !eof(STDIN) ) {
328 chomp( $line = <STDIN> );
330 die "No dependencies given\n" if !$line;
331 $fail_reason = $line;
332 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
333 print "Enter changelog entry (one line):\n";
335 while( !$line && !eof(STDIN) ) {
336 chomp( $line = <STDIN> );
338 die "No changelog entry given\n" if !$line;
339 $fail_reason = $line;
344 my $yamldir = "/org/wanna-build/etc/yaml";
345 my @files = ('wanna-build.yaml');
346 if ((getpwuid($>))[7]) { push (@files, ((getpwuid($>))[7])."/.wanna-build.yaml"); }
347 if ($user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
348 if ($user) { push ( @files, "$user.yaml"); }
349 foreach my $file (@files) {
350 my $cfile = File::Spec->rel2abs( $file, $yamldir );
351 if ($verbose >= 2) { print "Trying to read $file ($cfile) ...\n"; }
352 next unless -f $cfile;
353 if ($verbose >= 2) { print "Read $file ($cfile) ...\n"; }
354 my $m = YAML::Tiny->read( $cfile )->[0];
355 $yamlmap = merge($m, $yamlmap);
358 die "FATAL: no configuration found\n";
360 $list_order = $yamlmap->{"list-order"}{$list_state} if !$list_order and $list_state;
361 $list_order ||= $yamlmap->{"list-order"}{'default'};
362 $api //= $yamlmap->{"api"};
370 $dbh->disconnect or warn $dbh->errstr;
374 my $schema_suffix = '';
375 $recorduser //= (not -t and $user =~ /^buildd_/);
376 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !$recorduser && !($privmode eq 'yes')) {
377 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
378 die "FATAL: Cannot open database: $DBI::errstr\n";
379 $schema_suffix = '_public';
383 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
384 die "FATAL: Cannot open database: $DBI::errstr\n";
387 # TODO: This shouldn't be needed, file a bug.
388 $dbh->{pg_server_prepare} = 0;
390 $dbh->begin_work or die $dbh->errstr;
397 if ($mail_logs && $conf::log_mail) {
398 send_mail( $conf::log_mail,
399 "wanna-build $distribution state changes $curr_date",
400 "State changes at $curr_date for distribution ".
401 "$distribution:\n\n$mail_logs\n" );
409 SWITCH: foreach ($op_mode) {
411 add_packages( $1, @ARGV );
415 list_packages( $list_state );
419 info_packages( @ARGV );
422 /^forget-user/ && do {
423 die "This operation is restricted to admin users\n"
424 if (defined @conf::admin_users and
425 !isin( $real_user, @conf::admin_users));
426 forget_users( @ARGV );
430 forget_packages( @ARGV );
433 /^merge-partial-quinn/ && do {
434 die "This operation is restricted to admin users\n"
435 if (defined @conf::admin_users and
436 !isin( $real_user, @conf::admin_users));
441 /^merge-quinn/ && do {
442 die "This operation is restricted to admin users\n"
443 if (defined @conf::admin_users and
444 !isin( $real_user, @conf::admin_users));
449 /^merge-packages/ && do {
450 die "This operation is restricted to admin users\n"
451 if (defined @conf::admin_users and
452 !isin( $real_user, @conf::admin_users));
457 /^merge-sources/ && do {
458 die "This operation is restricted to admin users\n"
459 if (defined @conf::admin_users and
460 !isin( $real_user, @conf::admin_users));
465 /^pretend-avail/ && do {
466 pretend_avail( @ARGV );
469 /^merge-all$/ && do {
470 die "This operation is restricted to admin users\n"
471 if (defined @conf::admin_users and
472 !isin( $real_user, @conf::admin_users));
475 @ARGV = ( $ARGS[0] );
476 my $pkgs = parse_packages(0);
477 @ARGV = ( $ARGS[1] );
479 @ARGV = ( $ARGS[2] );
480 my $srcs = parse_sources(1);
481 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[0]), 'srcs' => $srcs });
484 /^merge-all-secondary/ && do {
485 die "This operation is restricted to admin users\n"
486 if (defined @conf::admin_users and
487 !isin( $real_user, @conf::admin_users));
488 # This is in case the chroot has multiple unrelated
489 # dist, for instance unstable and experimental.
490 # This is not for stable and proposed-updates.
491 # The second packages file contains a combination
492 # of all Packages files known to the buildd, the
493 # first only for the current dist.
496 @ARGV = ( $ARGS[0] );
497 my $pkgs = parse_packages(0);
498 @ARGV = ( $ARGS[3] );
499 my $pkgs = parse_packages(1);
500 @ARGV = ( $ARGS[1] );
502 @ARGV = ( $ARGS[2] );
503 my $srcs = parse_sources(1);
504 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[3]), 'srcs' => $srcs });
508 die "This operation is restricted to admin users\n"
509 if (defined @conf::admin_users and !isin( $real_user, @conf::admin_users) and !$simulate);
510 # call with installed-packages+ . installed-sources+ [ . available-for-build-packages* [ . consider-as-installed-source* ] ]
511 # in case available-for-build-packages is not specified, installed-packages are used
512 lock_table() unless $simulate;
513 my $replacemap = { '%ARCH%' => $arch, '%SUITE%' => $distribution };
514 map { my $k = $_; grep { $k =~ s,$_,$replacemap->{$_}, } keys %{$replacemap}; $_ = $k; } @ARGV;
515 my @ipkgs = &parse_argv( \@ARGV, '.');
516 my @isrcs = &parse_argv( \@ARGV, '.');
517 my @bpkgs = &parse_argv( \@ARGV, '.');
518 my @psrcs = &parse_argv( \@ARGV, '.');
520 my $srcs = WB::QD::readsourcebins($arch, $Pas, \@isrcs, \@ipkgs);
522 my $psrcs = WB::QD::readsourcebins($arch, $Pas, \@psrcs, []);
523 foreach my $k (keys %$$psrcs) {
524 next if $$srcs->{$k};
525 my $pkg = $$psrcs->{$k};
526 $pkg->{'status'} = 'related';
530 parse_all_v3($$srcs, {'arch' => $arch, 'suite' => $distribution, 'time' => $curr_date});
531 @bpkgs = @ipkgs unless @bpkgs;
532 call_edos_depcheck( {'arch' => $arch, 'pkgs' => \@bpkgs, 'srcs' => $$srcs, 'depwait' => 1 });
536 die "This operation is restricted to admin users\n"
537 if (defined @conf::admin_users and
538 !isin( $real_user, @conf::admin_users));
539 $dbh->do("DELETE from " . table_name() .
540 " WHERE distribution = ?", undef,
544 read_db( $import_from );
548 export_db( $export_to );
552 die "Unexpected operation mode $op_mode\n";
555 my $userinfo = get_user_info($user);
556 if (!defined $userinfo)
558 add_user_info($user);
562 update_user_info($user);
568 my $newstate = shift;
569 my( $package, $name, $version, $ok, $reason );
571 foreach $package (@_) {
572 $package =~ s,^.*/,,; # strip path
573 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
574 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
575 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
576 ($name,$version) = ($1,$2);
579 warn "$package: can't extract package name and version ".
584 if ($op_mode eq "set-building") {
585 add_one_building( $name, $version );
587 elsif ($op_mode eq "set-built") {
588 add_one_built( $name, $version );
590 elsif ($op_mode eq "set-attempted") {
591 add_one_attempted( $name, $version );
593 elsif ($op_mode eq "set-uploaded") {
594 add_one_uploaded( $name, $version );
596 elsif ($op_mode eq "set-failed") {
597 add_one_failed( $name, $version );
599 elsif ($op_mode eq "set-not-for-us") {
600 add_one_notforus( $name, $version );
602 elsif ($op_mode eq "set-needs-build") {
603 add_one_needsbuild( $name, $version );
605 elsif ($op_mode eq "set-dep-wait") {
606 add_one_depwait( $name, $version );
608 elsif ($op_mode eq "set-build-priority") {
609 set_one_buildpri( $name, $version, 'buildpri' );
611 elsif ($op_mode eq "set-permanent-build-priority") {
612 set_one_buildpri( $name, $version, 'permbuildpri' );
614 elsif ($op_mode eq "set-binary-nmu") {
615 set_one_binnmu( $name, $version );
617 elsif ($op_mode eq "set-update") {
618 set_one_update( $name, $version );
623 sub add_one_building {
629 my $pkg = get_source_info($name);
631 if ($pkg->{'state'} eq "Not-For-Us") {
633 $reason = "not suitable for this architecture";
635 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
637 $reason = "not all source dependencies available yet";
639 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
641 $reason = "source dependencies are not installable";
643 elsif ($pkg->{'state'} eq "Uploaded" &&
644 (version_lesseq($version, $pkg->{'version'}))) {
646 $reason = "already uploaded by $pkg->{'builder'}";
647 $reason .= " (in newer version $pkg->{'version'})"
648 if !version_eq($pkg, $version);
650 elsif ($pkg->{'state'} eq "Installed" &&
651 version_less($version,$pkg->{'version'})) {
653 print "$name: Warning: newer version $pkg->{'version'} ".
654 "already installed, but overridden.\n";
658 $reason = "newer version $pkg->{'version'} already in ".
659 "archive; doesn't need rebuilding";
660 print "$name: Note: If the following is due to an epoch ",
661 " change, use --override\n";
664 elsif ($pkg->{'state'} eq "Installed" &&
665 pkg_version_eq($pkg,$version)) {
667 $reason = "is up-to-date in the archive; doesn't need rebuilding";
669 elsif ($pkg->{'state'} eq "Needs-Build" &&
670 version_less($version,$pkg->{'version'})) {
672 print "$name: Warning: newer version $pkg->{'version'} ".
673 "needs building, but overridden.";
677 $reason = "newer version $pkg->{'version'} needs building, ".
681 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
682 if (version_less($pkg->{'version'},$version)) {
683 print "$name: Warning: Older version $pkg->{'version'} ",
684 "is being built by $pkg->{'builder'}\n";
685 if ($pkg->{'builder'} ne $user) {
686 send_mail( $pkg->{'builder'},
687 "package takeover in newer version",
688 "You are building package '$name' in ".
689 "version $version\n".
690 "(as far as I'm informed).\n".
691 "$user now has taken the newer ".
692 "version $version for building.".
693 "You can abort the build if you like.\n" );
698 print "User $pkg->{'builder'} had already ",
699 "taken the following package,\n",
700 "but overriding this as you request:\n";
701 send_mail( $pkg->{'builder'}, "package takeover",
702 "The package '$name' (version $version) that ".
703 "was taken by you\n".
704 "has been taken over by $user\n" );
706 elsif ($pkg->{'builder'} eq $user) {
707 print "$name: Note: already taken by you.\n";
708 print "$name: ok\n" if $verbose;
713 $reason = "already taken by $pkg->{'builder'}";
714 $reason .= " (in newer version $pkg->{'version'})"
715 if !version_eq($pkg->{'version'}, $version);
719 elsif ($pkg->{'state'} =~ /^Failed/ &&
720 pkg_version_eq($pkg, $version)) {
722 print "The following package previously failed ",
723 "(by $pkg->{'builder'})\n",
724 "but overriding this as you request:\n";
725 send_mail( $pkg->{'builder'}, "failed package takeover",
726 "The package '$name' (version $version) that ".
728 "and has failed previously has been taken over ".
730 if $pkg->{'builder'} ne $user;
734 $reason = "build of $version failed previously:\n ";
735 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
736 $reason .= "\nalso the package doesn't need builing"
737 if $pkg->{'state'} eq 'Failed-Removed';
744 if ($pkg->{'binary_nmu_version'}) {
745 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
746 "$pkg->{'binary_nmu_changelog'}\n";
749 print "$name: Warning: Previous version failed!\n"
750 if $pkg->{'previous_state'} =~ /^Failed/ ||
751 $pkg->{'state'} =~ /^Failed/;
753 print "$name: $ok\n" if $verbose;
756 print " - status: ok\n";
757 printf " - pkg-ver: %s_%s\n", $name, $version;
758 print " - binNMU: $pkg->{'binary_nmu_version'}\n" if $pkg->{'binary_nmu_version'};
759 print " - extra-changelog: $pkg->{'binary_nmu_changelog'}\n" if $pkg->{'binary_nmu_changelog'} && $pkg->{'binary_nmu_version'};
760 print " - extra-depends: $pkg->{'extra_depends'}\n" if $pkg->{'extra_depends'};
761 print " - extra-conflicts: $pkg->{'extra_conflicts'}\n" if $pkg->{'extra_conflicts'};
763 change_state( \$pkg, 'Building' );
764 $pkg->{'package'} = $name;
765 $pkg->{'version'} = $version;
766 $pkg->{'builder'} = $user;
767 log_ta( $pkg, "--take" );
768 update_source_info($pkg);
772 print "$name: NOT OK!\n $reason\n";
774 print "- $name:\n - status: not ok\n - reason: \"$reason\"\n";
779 sub add_one_attempted {
782 my $pkg = get_source_info($name);
784 if (!defined($pkg)) {
785 print "$name: not registered yet.\n";
789 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
790 print "$name: not taken for building (state is $pkg->{'state'}). ",
794 if ($pkg->{'builder'} ne $user) {
795 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
798 elsif ( !pkg_version_eq($pkg, $version) ) {
799 print "$name: version mismatch ".
800 "($pkg->{'version'} ".
801 "by $pkg->{'builder'})\n";
805 change_state( \$pkg, 'Build-Attempted' );
806 log_ta( $pkg, "--attempted" );
807 update_source_info($pkg);
808 print "$name: registered as uploaded\n" if $verbose;
814 my $pkg = get_source_info($name);
816 if (!defined($pkg)) {
817 print "$name: not registered yet.\n";
821 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
822 print "$name: not taken for building (state is $pkg->{'state'}). ",
826 if ($pkg->{'builder'} ne $user) {
827 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
830 elsif ( !pkg_version_eq($pkg, $version) ) {
831 print "$name: version mismatch ".
832 "($pkg->{'version'} ".
833 "by $pkg->{'builder'})\n";
836 change_state( \$pkg, 'Built' );
837 log_ta( $pkg, "--built" );
838 update_source_info($pkg);
839 print "$name: registered as built\n" if $verbose;
842 sub add_one_uploaded {
845 my $pkg = get_source_info($name);
847 if (!defined($pkg)) {
848 print "$name: not registered yet.\n";
852 if ($pkg->{'state'} eq "Uploaded" &&
853 pkg_version_eq($pkg,$version)) {
854 print "$name: already uploaded\n";
857 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
858 print "$name: not taken for building (state is $pkg->{'state'}). ",
862 if ($pkg->{'builder'} ne $user) {
863 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
866 # strip epoch -- buildd-uploader used to go based on the filename.
867 # (to remove at some point)
869 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
870 $version =~ s/^\d+://; # for command line use
871 if ($pkg->{'binary_nmu_version'} ) {
872 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
873 if (!version_eq( $nmuver, $version )) {
874 print "$name: version mismatch ($nmuver registered). ",
878 } elsif (!version_eq($pkgver, $version)) {
879 print "$name: version mismatch ($pkg->{'version'} registered). ",
884 change_state( \$pkg, 'Uploaded' );
885 log_ta( $pkg, "--uploaded" );
886 update_source_info($pkg);
887 print "$name: registered as uploaded\n" if $verbose;
894 my $pkg = get_source_info($name);
896 if (!defined($pkg)) {
897 print "$name: not registered yet.\n";
900 $state = $pkg->{'state'};
902 if ($state eq "Not-For-Us") {
903 print "$name: not suitable for this architecture anyway. Skipping.\n";
906 elsif ($state eq "Failed-Removed") {
907 print "$name: failed previously and doesn't need building. Skipping.\n";
910 elsif ($state eq "Installed") {
911 print "$name: Is already installed in archive. Skipping.\n";
914 elsif ($pkg->{'builder'} &&
915 (($user ne $pkg->{'builder'}) &&
916 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
917 print "$name: not taken by you, but by ".
918 "$pkg->{'builder'}. Skipping.\n";
921 elsif ( !pkg_version_eq($pkg, $version) ) {
922 print "$name: version mismatch ".
923 "($pkg->{'version'} ".
924 "by $pkg->{'builder'})\n";
929 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
931 $cat = $short_category{$cat} if exists $short_category{$cat};
932 if (!isin( $cat, values %short_category )) {
933 print "$name: Warning: unknown category $cat; discarded\n";
936 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
939 if ($state eq "Needs-Build") {
940 print "$name: Warning: not registered for building previously, ".
941 "but processing anyway.\n";
943 elsif ($state eq "Uploaded") {
944 print "$name: Warning: marked as uploaded previously, ".
945 "but processing anyway.\n";
947 elsif ($state eq "Dep-Wait") {
948 print "$name: Warning: marked as waiting for dependencies, ".
949 "but processing anyway.\n";
951 elsif ($state eq "BD-Uninstallable") {
952 print "$name: Warning: marked as having uninstallable build-dependencies, ".
953 "but processing anyway.\n";
955 elsif ($state eq "Failed") {
956 print "$name: already registered as failed; will append new message\n"
958 print "$name: already registered as failed; changing category\n"
962 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
963 defined $pkg->{'failed_category'} &&
964 $pkg->{'failed_category'} ne $cat) {
965 (my $action = $cat) =~ s/-/ /;
966 $fail_reason .= "\n$short_date: $action";
969 change_state( \$pkg, 'Failed' );
970 $pkg->{'builder'} = $user;
971 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
972 $pkg->{'failed'} .= $fail_reason;
973 $pkg->{'failed_category'} = $cat if $cat;
974 if (defined $pkg->{'permbuildpri'}) {
975 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
977 delete $pkg->{'buildpri'};
979 log_ta( $pkg, "--failed" );
980 update_source_info($pkg);
981 print "$name: registered as failed\n" if $verbose;
984 sub add_one_notforus {
987 my $pkg = get_source_info($name);
989 if ($pkg->{'state'} eq 'Not-For-Us') {
990 # reset Not-For-Us state in case it's called twice; this is
991 # the only way to get a package out of this state...
992 # There is no really good state in which such packages should
993 # be put :-( So use Failed for now.
994 change_state( \$pkg, 'Failed' );
995 $pkg->{'package'} = $name;
996 $pkg->{'failed'} = "Was Not-For-Us previously";
997 delete $pkg->{'builder'};
998 delete $pkg->{'depends'};
999 log_ta( $pkg, "--no-build(rev)" );
1000 print "$name: now not unsuitable anymore\n";
1002 send_mail( $conf::notforus_maint,
1003 "$name moved out of Not-For-Us state",
1004 "The package '$name' has been moved out of the Not-For-Us ".
1005 "state by $user.\n".
1006 "It should probably also be removed from ".
1007 "Packages-arch-specific or\n".
1008 "the action was wrong.\n" )
1009 if $conf::notforus_maint;
1012 change_state( \$pkg, 'Not-For-Us' );
1013 $pkg->{'package'} = $name;
1014 delete $pkg->{'builder'};
1015 delete $pkg->{'depends'};
1016 delete $pkg->{'buildpri'};
1017 delete $pkg->{'binary_nmu_version'};
1018 delete $pkg->{'binary_nmu_changelog'};
1019 log_ta( $pkg, "--no-build" );
1020 print "$name: registered as unsuitable\n" if $verbose;
1022 send_mail( $conf::notforus_maint,
1023 "$name set to Not-For-Us",
1024 "The package '$name' has been set to state Not-For-Us ".
1026 "It should probably also be added to ".
1027 "Packages-arch-specific or\n".
1028 "the Not-For-Us state is wrong.\n" )
1029 if $conf::notforus_maint;
1031 update_source_info($pkg);
1034 sub add_one_needsbuild {
1036 my $version = shift;
1038 my $pkg = get_source_info($name);
1040 if (!defined($pkg)) {
1041 print "$name: not registered; can't give back.\n";
1044 $state = $pkg->{'state'};
1046 if ($state eq "BD-Uninstallable") {
1047 if ($opt_override) {
1048 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
1050 change_state( \$pkg, 'Needs-Build' );
1051 delete $pkg->{'builder'};
1052 delete $pkg->{'depends'};
1053 log_ta( $pkg, "--give-back" );
1054 update_source_info($pkg);
1055 print "$name: given back\n" if $verbose;
1059 print "$name: has uninstallable build-dependencies. Skipping\n",
1060 " (use --override to clear dependency list and ",
1061 "give back anyway)\n";
1065 elsif ($state eq "Dep-Wait") {
1066 if ($opt_override) {
1067 print "$name: Forcing source dependency list to be cleared\n";
1070 print "$name: waiting for source dependencies. Skipping\n",
1071 " (use --override to clear dependency list and ",
1072 "give back anyway)\n";
1076 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1077 print "$name: not taken for building (state is $state).";
1078 if ($opt_override) {
1079 print "\n$name: Forcing give-back\n";
1082 print " Skipping.\n";
1086 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
1087 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
1089 print "$name: not taken by you, but by ".
1090 "$pkg->{'builder'}. Skipping.\n";
1093 if (!pkg_version_eq($pkg, $version)) {
1094 print "$name: version mismatch ($pkg->{'version'} registered). ",
1098 if ($distribution eq "unstable") {
1099 change_state( \$pkg, 'BD-Uninstallable' );
1100 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1102 change_state( \$pkg, 'Needs-Build' );
1104 $pkg->{'builder'} = undef;
1105 $pkg->{'depends'} = undef;
1106 log_ta( $pkg, "--give-back" );
1107 update_source_info($pkg);
1108 print "$name: given back\n" if $verbose;
1111 sub set_one_binnmu {
1113 my $version = shift;
1114 my $pkg = get_source_info($name);
1117 if (!defined($pkg)) {
1118 print "$name: not registered; can't register for binNMU.\n";
1121 my $db_ver = $pkg->{'version'};
1123 if (!version_eq($db_ver, $version)) {
1124 print "$name: version mismatch ($db_ver registered). ",
1128 $state = $pkg->{'state'};
1130 if (defined $pkg->{'binary_nmu_version'}) {
1131 if ($binNMUver == 0) {
1132 change_state( \$pkg, 'Installed' );
1133 delete $pkg->{'builder'};
1134 delete $pkg->{'depends'};
1135 delete $pkg->{'binary_nmu_version'};
1136 delete $pkg->{'binary_nmu_changelog'};
1137 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1138 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1141 $pkg->{'binary_nmu_version'} = $binNMUver;
1142 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1143 $pkg->{'notes'} = 'out-of-date';
1144 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1145 if (defined $pkg->{'permbuildpri'});
1147 log_ta( $pkg, "--binNMU" );
1148 update_source_info($pkg);
1150 } elsif ($binNMUver == 0) {
1151 print "${name}_$version: no scheduled binNMU to cancel.\n";
1155 if ($state ne 'Installed') {
1156 print "${name}_$version: not installed; can't register for binNMU.\n";
1160 my $fullver = binNMU_version($version,$binNMUver);
1161 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1163 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1167 if ($distribution eq "unstable") {
1168 change_state( \$pkg, 'BD-Uninstallable' );
1169 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1173 change_state( \$pkg, 'Needs-Build' );
1175 delete $pkg->{'builder'};
1176 delete $pkg->{'depends'};
1177 $pkg->{'binary_nmu_version'} = $binNMUver;
1178 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1179 $pkg->{'notes'} = 'out-of-date';
1180 log_ta( $pkg, "--binNMU" );
1181 update_source_info($pkg);
1182 print "${name}: registered for binNMU $fullver\n" if $verbose;
1185 sub set_one_buildpri {
1187 my $version = shift;
1189 my $pkg = get_source_info($name);
1192 if (!defined($pkg)) {
1193 print "$name: not registered; can't set priority.\n";
1196 $state = $pkg->{'state'};
1198 if ($state eq "Not-For-Us") {
1199 print "$name: not suitable for this architecture. Skipping.\n";
1201 } elsif ($state eq "Failed-Removed") {
1202 print "$name: failed previously and doesn't need building. Skipping.\n";
1205 if (!pkg_version_eq($pkg, $version)) {
1206 print "$name: version mismatch ($pkg->{'version'} registered). ",
1210 if ( $build_priority == 0 ) {
1211 delete $pkg->{'buildpri'}
1212 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1213 and $pkg->{'buildpri'} == $pkg->{$key};
1214 delete $pkg->{$key};
1216 $pkg->{'buildpri'} = $build_priority
1217 if $key eq 'permbuildpri';
1218 $pkg->{$key} = $build_priority;
1220 update_source_info($pkg);
1221 print "$name: set to build priority $build_priority\n" if $verbose;
1224 sub add_one_depwait {
1226 my $version = shift;
1228 my $pkg = get_source_info($name);
1230 if (!defined($pkg)) {
1231 print "$name: not registered yet.\n";
1234 $state = $pkg->{'state'};
1236 if ($state eq "Dep-Wait") {
1237 print "$name: merging with previously registered dependencies\n";
1240 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1241 print "$name: Warning: not registered for building previously, ".
1242 "but processing anyway.\n";
1244 elsif ($state eq "Not-For-Us") {
1245 print "$name: not suitable for this architecture anyway. Skipping.\n";
1248 elsif ($state eq "Failed-Removed") {
1249 print "$name: failed previously and doesn't need building. Skipping.\n";
1252 elsif ($state eq "Installed") {
1253 print "$name: Is already installed in archive. Skipping.\n";
1256 elsif ($state eq "Uploaded") {
1257 print "$name: Is already uploaded. Skipping.\n";
1260 elsif ($pkg->{'builder'} &&
1261 $user ne $pkg->{'builder'}) {
1262 print "$name: not taken by you, but by ".
1263 "$pkg->{'builder'}. Skipping.\n";
1266 elsif ( !pkg_version_eq($pkg,$version)) {
1267 print "$name: version mismatch ".
1268 "($pkg->{'version'} ".
1269 "by $pkg->{'builder'})\n";
1272 elsif ($fail_reason =~ /^\s*$/ ||
1273 !parse_deplist( $fail_reason, 1 )) {
1274 print "$name: Bad dependency list\n";
1277 change_state( \$pkg, 'Dep-Wait' );
1278 $pkg->{'builder'} = $user;
1279 if (defined $pkg->{'permbuildpri'}) {
1280 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1282 delete $pkg->{'buildpri'};
1284 my $deplist = parse_deplist( $pkg->{'depends'} );
1285 my $new_deplist = parse_deplist( $fail_reason );
1286 # add new dependencies, maybe overwriting old entries
1287 foreach (keys %$new_deplist) {
1288 $deplist->{$_} = $new_deplist->{$_};
1290 $pkg->{'depends'} = build_deplist($deplist);
1291 log_ta( $pkg, "--dep-wait" );
1292 update_source_info($pkg);
1293 print "$name: registered as waiting for dependencies\n" if $verbose;
1296 sub set_one_update {
1298 my $version = shift;
1299 my $pkg = get_source_info($name);
1301 if (!defined($pkg)) {
1302 print "$name: not registered yet.\n";
1305 $pkg->{'version'} =~ s/\+b[0-9]+$//;
1307 log_ta( $pkg, "--update" );
1308 update_source_info($pkg);
1318 my $db = get_all_source_info();
1320 local($/) = ""; # read in paragraph mode
1322 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1324 /^Package:\s*(\S+)$/mi and $name = $1;
1325 /^Version:\s*(\S+)$/mi and $version = $1;
1326 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1327 /^Section:\s*(\S+)$/mi and $section = $1;
1328 /^Priority:\s*(\S+)$/mi and $priority = $1;
1329 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1330 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1331 /^Binary:\s*(.*)$/mi and $binaries = $1;
1333 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1334 $srcver{$name} = $version;
1336 $pkgs{$name}{'ver'} = $version;
1337 $pkgs{$name}{'bin'} = $binaries;
1338 $pkgs{$name}{'dep'} = $builddep;
1339 $pkgs{$name}{'conf'} = $buildconf;
1340 my $pkg = $db->{$name};
1345 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1346 # package is now Arch: all, delete it from db
1347 change_state( \$pkg, 'deleted' );
1348 log_ta( $pkg, "--merge-sources" );
1349 print "$name ($pkg->{'version'}): deleted ".
1350 "from database, because now Arch: all\n"
1352 del_source_info($name);
1353 delete $db->{$name};
1357 # The "Version" should always be the source version --
1358 # not a possible binNMU version number.
1359 $pkg->{'version'} = $version, $change++
1360 if ($pkg->{'state'} eq 'Installed' and
1361 !version_eq( $pkg->{'version'}, $version));
1362 # Always update priority and section, if available
1363 $pkg->{'priority'} = $priority, $change++
1364 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1366 $pkg->{'section'} = $section, $change++
1367 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1369 update_source_info($pkg) if $change;
1372 # Now that we only have the latest source version, build the list
1373 # of binary packages from the Sources point of view
1374 foreach $name (keys %pkgs) {
1375 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1376 $merge_binsrc{$bin} = $name;
1379 # remove installed packages that no longer have source available
1380 # or binaries installed
1381 foreach $name (keys %$db) {
1382 next if $name =~ /^_/;
1383 my $pkg = $db->{$name};
1384 if (not defined($pkgs{$name})) {
1385 change_state( \$pkg, 'deleted' );
1386 log_ta( $pkg, "--merge-sources" );
1387 print "$name ($pkg->{'version'}): ".
1388 "deleted from database, because ".
1389 "not in Sources anymore\n"
1391 del_source_info($name);
1392 delete $db->{$name};
1394 next if !isin( $pkg->{'state'}, qw(Installed) );
1395 if ($full && not defined $merge_srcvers{$name}) {
1396 change_state( \$pkg, 'deleted' );
1397 log_ta( $pkg, "--merge-sources" );
1398 print "$name ($pkg->{'version'}): ".
1399 "deleted from database, because ".
1400 "binaries don't exist anymore\n"
1402 del_source_info($name);
1403 delete $db->{$name};
1404 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1405 print "$name ($pkg->{'version'}): ".
1406 "package is Installed but binaries are from ".
1407 $merge_srcvers{$name}. "\n"
1415 # This function looks through a Packages file and sets the state of
1416 # packages to 'Installed'
1417 sub parse_packages {
1418 my $depwait_only = shift;
1421 my $pkgs = get_all_source_info();
1422 local($/) = ""; # read in paragraph mode
1424 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1426 /^Package:\s*(\S+)$/mi and $name = $1;
1427 /^Version:\s*(\S+)$/mi and $version = $1;
1428 /^Depends:\s*(.*)$/mi and $depends = $1;
1429 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1430 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1431 /^Provides:\s*(.*)$/mi and $provides = $1;
1432 next if !$name || !$version;
1433 next if ($arch ne $architecture and $architecture ne "all");
1434 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1435 version_lesseq( $version, $installed->{$name}{'version'} ));
1436 $installed->{$name}{'version'} = $version;
1437 next if $depwait_only;
1438 $installed->{$name}{'depends'} = $depends;
1439 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1440 undef $installed->{$name}{'Provider'};
1441 $installed->{$name}{'Source'} = $source ? $source : $name;
1443 foreach (split( /\s*,\s*/, $provides )) {
1444 if (not defined ($installed->{$_})) {
1445 $installed->{$_}{'version'} = "";
1446 $installed->{$_}{'Provider'} = $name;
1450 if ( $version =~ /\+b(\d+)$/ ) {
1453 $version = $sourcev if $sourcev;
1454 $binaryv = $version;
1455 $binaryv =~ s/\+b\d+$//;
1456 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1457 $binaryv .= "+b$binnmu" if defined($binnmu);
1459 next if $architecture ne $arch;
1460 $name = $source if $source;
1461 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1462 $merge_srcvers{$name} = $version;
1464 my $pkg = $pkgs->{$name};
1467 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1468 (isin($pkg->{'state'}, qw(Installed)) &&
1469 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1470 print "Skipping $name because State == $pkg->{'state'}\n"
1474 if ($pkg->{'binary_nmu_version'} ) {
1475 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1476 if (version_less( $binaryv, $nmuver )) {
1477 print "Skipping $name ($version) because have newer ".
1478 "version ($nmuver) in db.\n"
1482 } elsif (version_less($version, $pkg->{'version'})) {
1483 print "Skipping $name ($version) because have newer ".
1484 "version ($pkg->{'version'}) in db.\n"
1489 if (!pkg_version_eq($pkg, $version) &&
1490 $pkg->{'state'} ne "Installed") {
1491 warn "Warning: $name: newer version than expected appeared ".
1492 "in archive ($version vs. $pkg->{'version'})\n";
1493 delete $pkg->{'builder'};
1496 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1497 warn "Warning: Package $name was not in uploaded state ".
1498 "before (but in '$pkg->{'state'}').\n";
1499 delete $pkg->{'builder'};
1500 delete $pkg->{'depends'};
1504 $pkg->{'version'} = $version;
1507 change_state( \$pkg, 'Installed' );
1508 $pkg->{'package'} = $name;
1509 $pkg->{'installed_version'} = $binaryv;
1510 if (defined $pkg->{'permbuildpri'}) {
1511 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1513 delete $pkg->{'buildpri'};
1515 $pkg->{'version'} = $version
1516 if version_less( $pkg->{'version'}, $version);
1517 delete $pkg->{'binary_nmu_version'};
1518 delete $pkg->{'binary_nmu_changelog'};
1519 log_ta( $pkg, "--merge-packages" );
1520 update_source_info($pkg);
1521 print "$name ($version) is up-to-date now.\n" if $verbose;
1524 check_dep_wait( "--merge-packages", $installed );
1529 my ($package, $name, $version, $installed);
1531 foreach $package (@_) {
1532 $package =~ s,^.*/,,; # strip path
1533 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1534 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1535 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1536 ($name,$version) = ($1,$2);
1539 warn "$package: can't extract package name and version ".
1543 $installed->{$name}{'version'} = $version;
1546 check_dep_wait( "--pretend-avail", $installed );
1549 sub check_dep_wait {
1551 my $installed = shift;
1553 # check all packages in state Dep-Wait if dependencies are all
1556 my $db = get_all_source_info();
1557 foreach $name (keys %$db) {
1558 next if $name =~ /^_/;
1559 my $pkg = $db->{$name};
1560 next if $pkg->{'state'} ne "Dep-Wait";
1561 my $deps = $pkg->{'depends'};
1563 print "$name: was in state Dep-Wait, but with empty ",
1565 goto make_needs_build;
1567 my $deplist = parse_deplist($deps);
1571 foreach (keys %$deplist) {
1572 if (!exists $installed->{$_} ||
1573 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1574 !version_compare( $installed->{$_}{'version'},
1575 $deplist->{$_}->{'rel'},
1576 $deplist->{$_}->{'version'}))) {
1578 $new_deplist->{$_} = $deplist->{$_};
1581 push( @removed_deps, $_ );
1586 change_state( \$pkg, 'Needs-Build' );
1587 log_ta( $pkg, $action );
1588 delete $pkg->{'builder'};
1589 delete $pkg->{'depends'};
1590 print "$name ($pkg->{'version'}) has all ",
1591 "dependencies available now\n" if $verbose;
1593 update_source_info($pkg);
1595 elsif (@removed_deps) {
1596 $pkg->{'depends'} = build_deplist( $new_deplist );
1597 print "$name ($pkg->{'version'}): some dependencies ",
1598 "(@removed_deps) available now, but not all yet\n"
1600 update_source_info($pkg);
1605 # This function accepts quinn-diff output (either from a file named on
1606 # the command line, or on stdin) and sets the packages named there to
1607 # state 'Needs-Build'.
1608 sub parse_quinn_diff {
1609 my $partial = shift;
1613 my $pkgs = get_all_source_info();
1617 next if !m,^([-\w\d/]*)/ # section
1618 ([-\w\d.+]+)_ # package name
1619 ([\w\d:.~+-]+)\.dsc\s* # version
1620 \[([^:]*): # priority
1621 ([^]]+)\]\s*$,x; # rest of notes
1622 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1623 $quinn_pkgs{$name}++;
1624 $section ||= "unknown";
1625 $priority ||= "unknown";
1626 $priority = "unknown" if $priority eq "-";
1627 $priority = "standard" if ($name eq "debian-installer");
1629 my $pkg = $pkgs->{$name};
1631 # Always update section and priority.
1632 if (defined($pkg)) {
1634 $pkg->{'section'} = $section, $change++ if not defined
1635 $pkg->{'section'} or $section ne "unknown";
1636 $pkg->{'priority'} = $priority, $change++ if not defined
1637 $pkg->{'priority'} or $priority ne "unknown";
1640 if (defined($pkg) &&
1641 $pkg->{'state'} =~ /^Dep-Wait/ &&
1642 version_less( $pkg->{'version'}, $version )) {
1643 change_state( \$pkg, 'Dep-Wait' );
1644 $pkg->{'version'} = $version;
1645 delete $pkg->{'binary_nmu_version'};
1646 delete $pkg->{'binary_nmu_changelog'};
1647 log_ta( $pkg, "--merge-quinn" );
1649 print "$name ($version) still waiting for dependencies.\n"
1652 elsif (defined($pkg) &&
1653 $pkg->{'state'} =~ /-Removed$/ &&
1654 version_eq($pkg->{'version'}, $version)) {
1655 # reinstantiate a package that has been removed earlier
1656 # (probably due to a quinn-diff malfunction...)
1657 my $newstate = $pkg->{'state'};
1658 $newstate =~ s/-Removed$//;
1659 change_state( \$pkg, $newstate );
1660 $pkg->{'version'} = $version;
1661 $pkg->{'notes'} = $notes;
1662 log_ta( $pkg, "--merge-quinn" );
1664 print "$name ($version) reinstantiated to $newstate.\n"
1667 elsif (defined($pkg) &&
1668 $pkg->{'state'} eq "Not-For-Us" &&
1669 version_less( $pkg->{'version'}, $version )) {
1670 # for Not-For-Us packages just update the version etc., but
1672 change_state( \$pkg, "Not-For-Us" );
1673 $pkg->{'package'} = $name;
1674 $pkg->{'version'} = $version;
1675 $pkg->{'notes'} = $notes;
1676 delete $pkg->{'builder'};
1677 log_ta( $pkg, "--merge-quinn" );
1679 print "$name ($version) still Not-For-Us.\n" if $verbose;
1681 elsif (!defined($pkg) ||
1682 $pkg->{'state'} ne "Not-For-Us" &&
1683 (version_less( $pkg->{'version'}, $version ) ||
1684 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1686 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1687 send_mail( $pkg->{'builder'},
1688 "new version of $name (dist=$distribution)",
1689 "As far as I'm informed, you're currently ".
1690 "building the package $name\n".
1691 "in version $pkg->{'version'}.\n\n".
1692 "Now there's a new source version $version. ".
1693 "If you haven't finished\n".
1694 "compiling $name yet, you can stop it to ".
1695 "save some work.\n".
1696 "Just to inform you...\n".
1697 "(This is an automated message)\n" );
1698 print "$name: new version ($version) while building ".
1699 "$pkg->{'version'} -- sending mail ".
1700 "to builder ($pkg->{'builder'})\n"
1703 change_state( \$pkg, 'Needs-Build' );
1704 $pkg->{'package'} = $name;
1705 $pkg->{'version'} = $version;
1706 $pkg->{'section'} = $section;
1707 $pkg->{'priority'} = $priority;
1708 $pkg->{'notes'} = $notes;
1709 delete $pkg->{'builder'};
1710 delete $pkg->{'binary_nmu_version'};
1711 delete $pkg->{'binary_nmu_changelog'};
1712 log_ta( $pkg, "--merge-quinn" );
1715 print "$name ($version) needs rebuilding now.\n" if $verbose;
1717 elsif (defined($pkg) &&
1718 !version_eq( $pkg->{'version'}, $version ) &&
1719 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1720 print "$name: skipping because version in db ".
1721 "($pkg->{'version'}) is >> than ".
1722 "what quinn-diff says ($version) ".
1723 "(state is $pkg->{'state'})\n"
1725 $dubious .= "$pkg->{'state'}: ".
1726 "db ${name}_$pkg->{'version'} >> ".
1727 "quinn $version\n" if !$partial;
1729 elsif ($verbose >= 2) {
1730 if ($pkg->{'state'} eq "Not-For-Us") {
1731 print "Skipping $name because State == ".
1732 "$pkg->{'state'}\n";
1734 elsif (!version_less($pkg->{'version'}, $version)) {
1735 print "Skipping $name because version in db ".
1736 "($pkg->{'version'}) is >= than ".
1737 "what quinn-diff says ($version)\n";
1740 update_source_info($pkg) if $change;
1744 send_mail( $conf::db_maint,
1745 "Dubious versions in " . table_name() . " "
1746 . $distribution . " table",
1747 "The following packages have a newer version in the ".
1748 "wanna-build database\n".
1749 "than what quinn-diff says, and this is strange for ".
1751 "It could be caused by a lame mirror, or the version ".
1752 "in the database\n".
1757 # Now re-check the DB for packages in states Needs-Build, Failed,
1758 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1759 # anymore by quinn-diff.
1762 my $db = get_all_source_info();
1763 foreach $name (keys %$db) {
1764 next if $name =~ /^_/;
1765 my $pkg = $db->{$name};
1766 next if defined $pkg->{'binary_nmu_version'};
1767 next if !isin( $pkg->{'state'},
1768 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1769 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1771 if (!$quinn_pkgs{$name}) {
1772 change_state( \$pkg, $virtual_delete ?
1773 $pkg->{'state'}."-Removed" :
1775 log_ta( $pkg, "--merge-quinn" );
1776 print "$name ($pkg->{'version'}): ".
1777 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1778 "from database, because not in quinn-diff anymore\n"
1780 if ($virtual_delete) {
1781 update_source_info($pkg);
1783 del_source_info($name);
1791 # for sorting priorities and sections
1793 %prioval = ( required => -5,
1801 'debian-installer' => -199,
1822 localizations => -178,
1823 interpreters => -177,
1848 electronics => -152,
1854 foreach my $i (keys %sectval) {
1855 $sectval{"contrib/$i"} = $sectval{$i}+40;
1856 $sectval{"non-free/$i"} = $sectval{$i}+80;
1858 $sectval{'unknown'} = -165;
1860 %catval = ( "none" => -20,
1861 "uploaded-fixed-pkg" => -19,
1862 "fix-expected" => -18,
1863 "reminder-sent" => -17,
1864 "nmu-offered" => -16,
1868 "compiler-error" => -12 );
1871 sub sort_list_func {
1873 'C' => ['<=>', sub { return (-1) * $_[0]->{'calprio'}; }],
1874 'W' => ['<=>', sub { return (-1) * $_[0]->{'state_days'}; }],
1875 'P' => ['<=>', sub { return (-1) * $_[0]->{'buildpri'}; }],
1876 'p' => ['<=>', sub { return $prioval{$_[0]->{'priority'}}; }],
1877 's' => ['<=>', sub { return $sectval{$_[0]->{'section'}}; }],
1878 'n' => ['cmp', sub { return $_[0]->{'package'}; }],
1879 'b' => ['cmp', sub { return $_[0]->{'builder'}; }],
1880 'c' => ['<=>', sub { return ($_[0]->{'notes'} =~ /^(out-of-date|partial)/) ? 0: ($_[0]->{'notes'} =~ /^uncompiled/) ? 2 : 1; }],
1881 'f' => ['<=>', sub { return $catval{ $_[0]->{'failed_category'} ? $_[0]->{'failed_category'}: "none" }; }],
1882 'S' => ['<=>', sub { return $prioval{$_[0]->{'priority'}} > $prioval{'standard'}; }],
1885 foreach my $letter (split( //, $list_order )) {
1887 $r = &{$map_funcs->{$letter}[1]}($a) <=> &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq '<=>';
1888 $r = &{$map_funcs->{$letter}[1]}($a) cmp &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq 'cmp';
1889 return $r if $r != 0;
1894 sub calculate_prio {
1895 my $priomap = $yamlmap->{priority};
1897 my @s=split("/", $pkg->{'section'});
1898 $pkg->{'component'} = $s[0] if $s[1];
1899 $pkg->{'component'} ||= 'main';
1900 $pkg->{'calprio'} = 0;
1901 foreach my $k (keys %{$priomap->{keys}}) {
1902 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1905 my $days = $pkg->{'state_days'};
1906 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1907 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1908 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1909 $pkg->{'calprio'} += $days * $scale;
1911 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1912 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1920 return "" unless $t;
1922 my $min = int($t/60) % 60;
1923 my $hours = int($t / 3600);
1924 return sprintf("%d:%02d:%02d", $hours, $min, $sec) if $hours;
1925 return sprintf("%d:%02d", $min, $sec);
1932 if (ref($_[0]) eq 'CODE') {
1942 return $r unless $t;
1946 if (substr($t,0,1) eq '!') {
1950 return "" unless $r;
1953 return print_format($t, $pkg, $var);
1957 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
1960 my $printfmt = shift;
1964 Within an format string, the following values are allowed (need to be preceded by %).
1965 This can be combined to e.g.
1966 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
1969 c section (e.g. libs or utils)
1970 D in case of BD-Uninstallable the reason for the uninstallability
1972 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
1973 F in case of Failed the fail reason
1975 o time of last successful build (seconds)
1976 O time of last successful build (formated)
1979 q time of last build (seconds)
1980 Q time of last build (formated)
1981 r max time of last (successful) build (seconds)
1982 R max time of last (successful) build (formated)
1984 s Time in this state in full seconds since epoch
1985 t time of state change
1986 T time since state change
1987 u Builder (e.g. buildd_mipsel-rem)
1989 V full Package version (i.e. with +b.., = %v%{+b}B%B
1990 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
1992 %{Text}? print Text in case ? is not empty; ? is never printed
1993 %{!Text}? print Text in case ? is empty; ? is never printed
1994 Text could contain further %. To start with !, use %!
1997 return stringf($printfmt, (
1998 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
1999 'a' => make_fmt( $arch, $pkg, $var),
2000 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
2001 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
2002 'V' => make_fmt( sub { $pkg->{'binary_nmu_version'} ? $pkg->{'version'}."+b".$pkg->{'binary_nmu_version'} : $pkg->{'version'} }, $pkg, $var),
2003 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
2004 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
2005 'X' => make_fmt( sub {
2006 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
2007 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} =~ /^Failed/;
2008 $c .= ":bp{" . $pkg->{'buildpri'} . "}" if defined $pkg->{'buildpri'};
2009 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
2010 $c .= ":calprio{". $pkg->{'calprio'}."}";
2011 $c .= ":days{". $pkg->{'state_days'}."}";
2014 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
2015 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
2016 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
2017 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
2018 return ""; }, $pkg, $var),
2019 'F' => make_fmt( sub { return "" unless $pkg->{'failed'};
2020 my $failed = $pkg->{'failed'};
2021 $failed =~ s/\\/\\\\/g;
2022 return $pkg->{'package'}."#".$arch."-failure\n ".
2023 join("\\0a",split("\n",$failed))."\\0a\n"; }, $pkg, $var),
2024 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
2025 return $pkg->{'package'}."#".$arch."-bd-problem\n".
2026 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
2027 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
2028 'd' => make_fmt( $pkg->{'distribution'}, $pkg, $var),
2029 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
2030 'T' => make_fmt( sub { return seconds2time(time() - floor(str2time($pkg->{'state_change'}))); }, $pkg, $var),
2031 'o' => make_fmt( $pkg->{'successtime'}, $pkg, $var),
2032 'O' => make_fmt( sub { return seconds2time ( $pkg->{'successtime'}); }, $pkg, $var),
2033 'q' => make_fmt( $pkg->{'anytime'}, $pkg, $var),
2034 'Q' => make_fmt( sub { return seconds2time ( $pkg->{'anytime'}); }, $pkg, $var),
2035 'r' => make_fmt( sub { return max($pkg->{'successtime'}, $pkg->{'anytime'}); }, $pkg, $var),
2036 'R' => make_fmt( sub { return seconds2time ( max($pkg->{'successtime'}, $pkg->{'anytime'})); }, $pkg, $var),
2042 my( $name, $pkg, @list );
2047 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
2048 foreach $name (keys %$db) {
2049 next if $name =~ /^_/;
2050 push @list, calculate_prio($db->{$name});
2054 @list = grep { my $i = $_->{'component'}; grep { $i eq $_ } split /[, ]+/, $yamlmap->{"restrict"}{'component'} } @list;
2055 # extra depends / conflicts only from api 1 on
2056 @list = grep { !$_->{'extra_depends'} and !$_->{'extra_conflicts'} } @list if $api < 1 ;
2058 # first adjust ownprintformat, then set printformat accordingly
2059 $printformat ||= $yamlmap->{"format"}{$ownprintformat};
2060 $printformat ||= $yamlmap->{"format"}{"default"}{$state};
2061 $printformat ||= $yamlmap->{"format"}{"default"}{"default"};
2062 undef $printformat if ($ownprintformat eq 'none');
2064 foreach $pkg (sort sort_list_func @list) {
2066 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
2068 $scnt{$pkg->{'state'}}++;
2071 print print_format("%c/%p_%v", $pkg, {});
2072 print print_format(": %S", $pkg, {})
2074 print print_format("%{ by }u%u", $pkg, {})
2075 if $pkg->{'state'} ne "Needs-Build";
2076 print print_format(" [%X]\n", $pkg, {});
2077 print " Reasons for failing:\n",
2079 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
2081 join("\n ",split("\n",$pkg->{'failed'})), "\n"
2082 if $pkg->{'state'} =~ /^Failed/;
2083 print " Dependencies: $pkg->{'depends'}\n"
2084 if $pkg->{'state'} eq "Dep-Wait";
2085 print " Reasons for BD-Uninstallable:\n ",
2086 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
2087 if $pkg->{'state'} eq "BD-Uninstallable";
2088 print " Previous state was $pkg->{'previous_state'}\n"
2089 if $verbose && $pkg->{'previous_state'};
2090 print " No previous state recorded\n"
2091 if $verbose && !$pkg->{'previous_state'};
2092 print " State changed at $pkg->{'state_change'}\n"
2093 if $verbose && $pkg->{'state_change'};
2094 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
2095 if $verbose && $pkg->{'previous_state'};
2096 print " Previous failing reasons:\n ",
2097 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
2098 if $verbose && $pkg->{'old_failed'};
2100 $scnt{$pkg->{'state'}}++ if $state eq "all";
2102 if ($state eq "all" && !$printformat) {
2103 foreach (sort keys %scnt) {
2104 print "Total $scnt{$_} package(s) in state $_.\n";
2107 print "Total $cnt package(s)\n" unless $printformat;
2112 my( $name, $pkg, $key, $dist );
2113 my @firstkeys = qw(package version builder state section priority
2114 installed_version previous_state state_change);
2115 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
2116 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
2117 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
2118 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
2119 'state_change' => 'State-Change',
2120 'bd_problem' => 'BD-Problem',
2121 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
2122 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
2123 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
2124 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
2125 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
2126 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days',
2127 'successtime' => 'Success-build-time',
2128 'anytime' => 'Build-time',
2129 'extra_depends' => 'Extra-Dependencies',
2130 'extra_conflicts' => 'Extra-Conflicts',
2133 foreach $name (@_) {
2134 $name =~ s/_.*$//; # strip version
2135 foreach $dist (@dists) {
2136 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
2138 $pkg = get_readonly_source_info($name);
2139 if (!defined( $pkg )) {
2140 print "$pname: not registered\n";
2143 $pkg = calculate_prio($pkg);
2146 foreach $key (@firstkeys) {
2147 next if !defined $pkg->{$key};
2148 my $val = $pkg->{$key};
2150 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2152 my $print_key = $key;
2153 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2154 printf " %-20s: %s\n", $print_key, $val;
2156 foreach $key (sort keys %$pkg) {
2157 next if isin( $key, @firstkeys );
2158 my $val = $pkg->{$key};
2159 next if !defined($val);
2161 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2163 my $print_key = $key;
2164 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2165 printf " %-20s: %s\n", $print_key, $val;
2171 sub forget_packages {
2172 my( $name, $pkg, $key, $data );
2174 foreach $name (@_) {
2175 $name =~ s/_.*$//; # strip version
2176 $pkg = get_source_info($name);
2177 if (!defined( $pkg )) {
2178 print "$name: not registered\n";
2183 foreach $key (sort keys %$pkg) {
2184 my $val = $pkg->{$key};
2187 $data .= sprintf " %-20s: %s\n", $key, $val;
2189 send_mail( $conf::db_maint,
2190 "$name deleted from DB " . table_name() . " " . $distribution,
2191 "The package '$name' has been deleted from the database ".
2193 "Data registered about the deleted package:\n".
2194 "$data\n" ) if $conf::db_maint;
2195 change_state( \$pkg, 'deleted' );
2196 log_ta( $pkg, "--forget" );
2197 del_source_info($name);
2198 print "$name: deleted from database\n" if $verbose;
2203 $dbh->do("DELETE from " . user_table_name() .
2204 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
2210 print "Reading ASCII database from $file..." if $verbose >= 1;
2211 open( F, "<$file" ) or
2212 die "Can't open database $file: $!\n";
2214 local($/) = ""; # read in paragraph mode
2216 my( %thispkg, $name );
2218 s/\n[ \t]+/\376\377/g; # fix continuation lines
2219 s/\376\377\s*\376\377/\376\377/og;
2221 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2222 my ($key, $val) = ($1, $2);
2224 $key =~ tr/A-Z/a-z/;
2225 $val =~ s/\376\377/\n/g;
2226 $thispkg{$key} = $val;
2228 check_entry( \%thispkg );
2230 if (exists($thispkg{'package'})) {
2231 update_source_info(\%thispkg);
2233 elsif(exists($thispkg{'user'})) {
2234 # user in import, username in database.
2235 $dbh->do('INSERT INTO ' . user_table_name() .
2236 ' (username, distribution, last_seen)' .
2237 ' values (?, ?, ?)',
2238 undef, $thispkg{'user'}, $distribution,
2239 $thispkg{'last_seen'})
2240 or die $dbh->errstr;
2244 print "done\n" if $verbose >= 1;
2251 return if $op_mode eq "manual-edit"; # no checks then
2253 # check for required fields
2254 if (exists $pkg->{'user'}) {
2257 if (!exists $pkg->{'package'}) {
2258 print STDERR "Bad entry: ",
2259 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2260 die "Database entry lacks package or username field\n";
2262 # if no State: field, generate one (for old db compat)
2263 if (!exists($pkg->{'state'})) {
2265 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2267 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2268 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2271 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2272 if !isin( $pkg->{'state'},
2273 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2274 Failed Failed-Removed Not-For-Us BD-Uninstallable
2280 my($name,$pkg,$key);
2282 print "Writing ASCII database to $file..." if $verbose >= 1;
2283 open( F, ">$file" ) or
2284 die "Can't open export $file: $!\n";
2286 my $db = get_all_source_info();
2287 foreach $name (keys %$db) {
2288 next if $name =~ /^_/;
2289 my $pkg = $db->{$name};
2290 foreach $key (keys %{$pkg}) {
2291 my $val = $pkg->{$key};
2292 next if !defined($val);
2295 $val =~ s/^ +$/ ./mg;
2296 print F "$key: $val\n";
2301 print "done\n" if $verbose >= 1;
2307 my $newstate = shift;
2308 my $state = \$pkg->{'state'};
2310 return if defined($$state) and $$state eq $newstate;
2311 $pkg->{'previous_state'} = $$state if defined($$state);
2312 $pkg->{'state_change'} = $curr_date;
2313 $pkg->{'do_state_change'} = 1;
2315 if (defined($$state) and $$state eq 'Failed') {
2316 $pkg->{'old_failed'} =
2317 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2318 $pkg->{'failed'} . "\n" .
2319 $pkg->{'old_failed'};
2320 delete $pkg->{'failed'};
2321 delete $pkg->{'failed_category'};
2323 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2324 delete $pkg->{'bd_problem'};
2326 $$state = $newstate;
2332 my $dist = $distribution;
2336 $prevstate = $pkg->{'previous_state'};
2337 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2338 "changed from $prevstate to $pkg->{'state'} ".
2339 "by $real_user as $user";
2342 printf "update transactions: %s %s %s %s %s %s %s %s\n",
2343 $pkg->{'package'}, $distribution,
2344 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2348 $dbh->do('INSERT INTO ' . transactions_table_name() .
2349 ' (package, distribution, version, action, ' .
2350 ' prevstate, state, real_user, set_user, time) ' .
2351 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2352 undef, $pkg->{'package'}, $distribution,
2353 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2354 $real_user, $user, 'now()') or die $dbh->errstr;
2356 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2357 $str .= " (with --override)"
2359 $mail_logs .= "$str\n";
2366 my $subject = shift;
2369 my $from = $conf::db_maint;
2370 my $domain = $conf::buildd_domain;
2372 $from .= "\@$domain" if $from !~ /\@/;
2374 $to .= '@' . $domain if $to !~ /\@/;
2375 $text =~ s/^\.$/../mg;
2376 local $SIG{'PIPE'} = 'IGNORE';
2377 open( PIPE, "| $conf::mailprog -oem $to" )
2378 or die "Can't open pipe to $conf::mailprog: $!\n";
2380 print PIPE "From: $from\n";
2381 print PIPE "Subject: $subject\n\n";
2382 print PIPE "$text\n";
2386 # for parsing input to dep-wait
2392 foreach (split( /\s*,\s*/, $deps )) {
2394 # verification requires > starting prompts, no | crap
2395 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2400 my @alts = split( /\s*\|\s*/, $_ );
2401 # Anything with an | is ignored, as it can be configured on a
2402 # per-buildd basis what will be installed
2403 next if $#alts != 0;
2406 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2407 warn( "parse_deplist: bad dependency $_\n" );
2410 my($dep, $rel, $relv) = ($1, $3, $4);
2411 $rel = ">>" if defined($rel) and $rel eq ">";
2412 $result{$dep}->{'package'} = $dep;
2413 if ($rel && $relv) {
2414 $result{$dep}->{'rel'} = $rel;
2415 $result{$dep}->{'version'} = $relv;
2418 return 1 if $verify;
2426 foreach $key (keys %$list) {
2427 $result .= ", " if $result;
2429 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2430 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2437 return "" unless $_[0];
2438 return Dpkg::Deps::parse($_[0], ("reduce_arch" => 1, "host_arch" => $_[1]))->dump();
2441 sub wb_edos_builddebcheck {
2442 # Copyright (C) 2008 Ralf Treinen <treinen@debian.org>
2443 # This program is free software: you can redistribute it and/or modify it under
2444 # the terms of the GNU General Public License as published by the Free Software
2445 # Foundation, version 2 of the License.
2446 # integrated into wanna-builds code by Andreas Barth 2010
2449 my $sourceprefix="source---";
2450 my $architecture=$args->{'arch'};
2451 my $edosoptions = "-failures -explain -quiet";
2452 my $packagefiles = $args->{'pkgs'};
2453 my $sourcesfile = $args->{'src'};
2456 foreach my $packagefile (@$packagefiles) {
2457 open(P,$packagefile);
2459 next unless /^Architecture/;
2460 next if /^Architecture:\s*all/;
2461 /Architecture:\s*([^\s]*)/;
2462 if ($packagearch eq "") {
2464 } elsif ( $packagearch ne $1) {
2465 return "Package file contains different architectures: $packagearch, $1";
2471 if ( $architecture eq "" ) {
2472 if ( $packagearch eq "" ) {
2473 return "No architecture option given, " .
2474 "and no non-all architecture found in the Packages file";
2476 $architecture = $packagearch;
2479 if ( $packagearch ne "" & $architecture ne $packagearch) {
2480 return "Architecture option is $architecture ".
2481 "but the package file contains architecture $packagearch";
2485 print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n";
2487 "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles));
2494 # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED
2495 # source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing:
2496 # - libltdl-dev (>= 2.2.6a-2)
2497 # source---libcanberra (= 0.22-1~bpo50+1): FAILED
2498 # source---libcanberra (= 0.22-1~bpo50+1) depends on missing:
2500 # - libltdl7-dev (>= 2.2.6)
2503 s/^(\s*)$sourceprefix(.*)depends on/$1$2build-depends on/o;
2504 s/^(\s*)$sourceprefix(.*) and (.*) conflict/$1$2 build-conflicts with $3/o;
2507 if (/^$sourceprefix(.*) \(.*\): FAILED/o) {
2508 $result->{$binpkg} = $explanation if $binpkg;
2511 } elsif (/^(depwait---.*) \(.*\): FAILED/o) {
2512 $result->{$binpkg} = $explanation if $binpkg;
2515 } else { # else something broken is happening
2516 #print "ignoring $_\n";
2523 $result->{$binpkg} = $explanation if $binpkg;
2529 sub call_edos_depcheck {
2530 return if $simulate_edos;
2532 my $srcs = $args->{'srcs'};
2535 return if defined ($conf::distributions{$distribution}{noadw}) && not defined $args->{'depwait'};
2537 # We need to check all of needs-build, as any new upload could make
2538 # something in needs-build have uninstallable deps
2539 # We also check everything in bd-uninstallable, as any new upload could
2540 # make that work again
2541 my (%interesting_packages, %interesting_packages_depwait);
2542 my $db = get_all_source_info();
2543 foreach $key (keys %$db) {
2544 my $pkg = $db->{$key};
2545 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/) and not defined ($conf::distributions{$distribution}{noadw})) {
2546 $interesting_packages{$key} = undef;
2548 if (defined $pkg and isin($pkg->{'state'}, qw/Dep-Wait/) and defined $args->{'depwait'}) {
2549 $interesting_packages_depwait{$key} = undef;
2550 # we always check for BD-Uninstallability in depwait - could be that depwait is satisfied but package is uninstallable
2551 $interesting_packages{$key} = undef unless defined ($conf::distributions{$distribution}{noadw});
2555 #print "I would look at these sources with edos-depcheck:\n";
2556 #print join " ", keys %interesting_packages,"\n";
2557 return unless %interesting_packages || %interesting_packages_depwait;
2559 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-XXXXX";
2560 use File::Temp qw/ tempfile /;
2561 my ($SOURCES, $tmpfile) = tempfile( $tmpfile_pattern, UNLINK => 1 );
2562 for my $key (keys %interesting_packages) {
2563 my $pkg = $db->{$key};
2564 # we print the source files as binary ones (with "source---"-prefixed),
2565 # so we can try if these "binary" packages are installable.
2566 # If such a "binary" package is installable, the corresponding source package is buildable.
2567 print $SOURCES "Package: source---$key\n";
2568 print $SOURCES "Version: $pkg->{'version'}\n";
2569 my $t = &filterarch($srcs->{$key}{'dep'} || $srcs->{$key}{'depends'}, $arch);
2570 my $tt = &filterarch($pkg->{'extra_depends'}, $arch);
2571 $t = $t ? ($tt ? "$t, $tt" : $t) : $tt;
2572 print $SOURCES "Depends: $t\n" if $t;
2573 my $u = &filterarch($srcs->{$key}{'conf'} || $srcs->{$key}{'conflicts'}, $arch);
2574 my $uu = &filterarch($pkg->{'extra_conflicts'}, $arch);
2575 $u = $u ? ($uu ? "$u, $uu" : $u) : $uu;
2576 print $SOURCES "Conflicts: $u\n" if $u;
2577 print $SOURCES "Architecture: all\n";
2578 print $SOURCES "\n";
2580 for my $key (keys %interesting_packages_depwait) {
2581 my $pkg = $db->{$key};
2582 # we print the source files as binary ones (with "depwait---"-prefixed),
2583 # so we can try if these "binary" packages are installable.
2584 # If such a "binary" package is installable, the corresponding source package goes out of depwait
2585 print $SOURCES "Package: depwait---$key\n";
2586 print $SOURCES "Version: $pkg->{'version'}\n";
2587 print $SOURCES "Depends: $pkg->{'depends'}\n";
2588 print $SOURCES "Architecture: all\n";
2589 print $SOURCES "\n";
2593 my $edosresults = wb_edos_builddebcheck({'arch' => $args->{'arch'}, 'pkgs' => $args->{'pkgs'}, 'src' => $tmpfile});
2594 if (ref($edosresults) eq 'HASH') {
2595 foreach my $key (grep { $_ !~ /^depwait---/ } keys %$edosresults) {
2596 if (exists $interesting_packages{$key}) {
2597 $interesting_packages{$key} = $edosresults->{$key};
2599 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2602 foreach my $key (grep { $_ =~ /^depwait---/ } keys %$edosresults) {
2603 $key =~ /^depwait---(.*)/ and $key = $1;
2604 if (exists $interesting_packages_depwait{$key}) {
2605 $interesting_packages_depwait{$key} = $edosresults->{"depwait---".$key};
2607 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2611 # if $edosresults isn't an hash, then something went wrong and the string is the error message
2612 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2613 "all packages have installable build-dependencies."
2618 for my $key (keys %interesting_packages) {
2619 next if defined $interesting_packages_depwait{$key};
2620 my $pkg = $db->{$key};
2622 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2623 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2624 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2626 if (defined $interesting_packages{$key}) {
2627 change_state( \$pkg, 'BD-Uninstallable' );
2628 $pkg->{'bd_problem'} = $interesting_packages{$key};
2630 change_state( \$pkg, 'Needs-Build' );
2633 if ($problemchange) {
2634 if (defined $interesting_packages{$key}) {
2635 $pkg->{'bd_problem'} = $interesting_packages{$key};
2639 log_ta( $pkg, "--merge-all (edos)" ) unless $simulate;
2640 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) to $pkg->{'state'}\n" if $verbose || $simulate;
2642 if ($change || $problemchange) {
2643 update_source_info($pkg) unless $simulate;
2647 for my $key (keys %interesting_packages_depwait) {
2648 if ($interesting_packages_depwait{$key}) {
2649 print "dep-wait for $key ($args->{'arch'}) not fullfiled yet\n" if $verbose || $simulate;
2652 my $pkg = $db->{$key};
2653 if (defined $interesting_packages{$key}) {
2654 change_state( \$pkg, 'BD-Uninstallable' );
2655 $pkg->{'bd_problem'} = $interesting_packages{$key};
2657 change_state( \$pkg, 'Needs-Build' );
2659 log_ta( $pkg, "edos_depcheck: depwait" ) unless $simulate;
2660 update_source_info($pkg) unless $simulate;
2661 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) from dep-wait to $pkg->{'state'}\n" if $verbose || $simulate;
2667 ($prgname = $0) =~ s,^.*/,,;
2669 Usage: $prgname <options...> <package_version...>
2671 -v, --verbose: Verbose execution.
2672 -A arch: Architecture this operation is for.
2673 --take: Take package for building [default operation]
2674 -f, --failed: Record in database that a build failed due to
2675 deficiencies in the package (that aren't fixable without a new
2677 -u, --uploaded: Record in the database that the packages build
2678 correctly and were uploaded.
2679 -n, --no-build: Record in the database that the packages aren't
2680 desired for this architecture and shouldn't appear in listings even
2681 if they're out of date.
2682 --dep-wait: Record in the database that the packages are waiting
2683 for some source dependencies to become available
2684 --binNMU num: Schedule a re-build of the package with unchanged source, but
2685 a new version number (source-version + "+b<num>")
2686 --give-back: Mark a package as ready to build that is in state Building,
2687 Built or Build-Attempted. To give back a package in state Failed, use
2688 --override. This command will actually put the package in state
2689 BD-Uninstallable, until the installability of its Build-Dependencies
2690 were verified. This happens at each call of --merge-all, usually
2692 --merge-quinn: Merge quinn-diff output into database.
2693 --merge-packages: Merge Packages files into database.
2694 --pretend-avail: Pretend that given packages are available now and give
2695 free packages waiting for them
2696 -i SRC_PKG, --info SRC_PKG: Show information for source package
2697 -l STATE, --list=STATE: List all packages in state STATE; can be
2698 combined with -U to restrict to a specific user; STATE can
2700 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2701 source dependency list
2702 (used with -f, --dep-wait, and --binNMU)
2703 -o, --override: Override another user's lock on a package, i.e.
2704 take it over; a notice mail will be sent to the other user
2705 -U USER, --user=USER: select user name for which listings should
2706 apply, if not given all users are listed.
2707 if -l is missing, set user name to be entered in db; usually
2708 automatically choosen
2709 --import FILE: Import database from a ASCII file FILE
2710 --export FILE: Export database to a ASCII file FILE
2712 The remaining arguments (depending on operation) usually start with
2713 "name_version", the trailer is ignored. This allows to pass the names
2714 of .dsc files, for which file name completion can be used.
2715 --merge-packages and --merge-quinn take Package/quin--diff file names
2716 on the command line or read stdin. --list needs nothing more on the
2717 command line. --info takes source package names (without version).
2722 sub pkg_version_eq {
2724 my $version = shift;
2727 if (defined $pkg->{'binary_nmu_version'}) and
2728 version_compare(binNMU_version($pkg->{'version'},
2729 $pkg->{'binary_nmu_version'}),'=', $version);
2730 return version_compare( $pkg->{'version'}, "=", $version );
2734 return '"' . $arch . $schema_suffix . '".packages';
2737 sub user_table_name {
2738 return '"' . $arch . $schema_suffix . '".users';
2741 sub transactions_table_name {
2742 return '"' . $arch . $schema_suffix . '".transactions';
2745 sub pkg_history_table_name {
2746 return '"' . $arch . $schema_suffix . '".pkg_history';
2749 sub get_readonly_source_info {
2751 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2752 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"
2753 . ", (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"
2754 . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2755 . ", extra_depends, extra_conflicts"
2756 . " FROM " . table_name()
2757 . ' WHERE package = ? AND distribution = ?';
2758 my $pkg = $dbh->selectrow_hashref( $q,
2759 undef, $name, $distribution);
2763 sub get_source_info {
2765 return get_readonly_source_info($name) if $simulate;
2766 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change)) as state_days FROM ' .
2767 table_name() . ' WHERE package = ? AND distribution = ?' .
2769 undef, $name, $distribution);
2773 sub get_all_source_info {
2776 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"
2777 # . ", (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"
2778 # . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2779 . ", successtime.build_time as successtime, anytime.build_time as anytime, extra_depends, extra_conflicts"
2780 . " FROM " . table_name()
2782 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." where result = 'successful' order by package, distribution, timestamp "
2783 . " ) as successtime using (package, distribution) "
2785 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." order by package, distribution, timestamp desc"
2786 . " ) as anytime using (package, distribution) "
2789 if ($distribution) {
2790 my @dists = split(/[, ]+/, $distribution);
2791 $q .= ' AND ( distribution = ? '.(' OR distribution = ? ' x $#dists).' )';
2792 foreach my $d ( @dists ) {
2796 if ($options{state} && uc($options{state}) ne "ALL") {
2797 $q .= ' AND upper(state) = ? ';
2798 push @args, uc($options{state});
2801 if ($options{user} && uc($options{state}) ne "NEEDS-BUILD") { # if it's NEEDS-BUILD, we don't look at users
2802 #this basically means "this user, or no user at all":
2803 $q .= " AND (builder = ? OR upper(state) = 'NEEDS-BUILD')";
2804 push @args, $options{user};
2807 if ($options{category}) {
2808 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2809 push @args, $options{category};
2810 push @args, "FAILED";
2813 if ($options{list_min_age} > 0) {
2814 $q .= ' AND age(state_change) > ? ';
2815 push @args, $options{list_min_age} . " days";
2818 if ($options{list_min_age} < 0) {
2819 $q .= ' AND age(state_change) < ? ';
2820 push @args, -$options{list_min_age} . " days";
2823 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2827 sub update_source_info {
2829 $pkg->{'extra_depends'} = $extra_depends if defined $extra_depends;
2830 undef $pkg->{'extra_depends'} unless $pkg->{'extra_depends'};
2831 $pkg->{'extra_conflicts'} = $extra_conflicts if defined $extra_conflicts;
2832 undef $pkg->{'extra_conflicts'} unless $pkg->{'extra_conflicts'};
2833 print Dumper $pkg if $verbose and $simulate;
2834 return if $simulate;
2836 my $pkg2 = get_source_info($pkg->{'package'});
2837 if (! defined $pkg2)
2839 add_source_info($pkg);
2842 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2847 'installed_version = ?, ' .
2848 'previous_state = ?, ' .
2849 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2853 'old_failed = ?, ' .
2854 'binary_nmu_version = ?, ' .
2855 'binary_nmu_changelog = ?, ' .
2856 'failed_category = ?, ' .
2857 'permbuildpri = ?, ' .
2861 'extra_depends = ?, ' .
2862 'extra_conflicts = ?, ' .
2864 'WHERE package = ? AND distribution = ?',
2870 $pkg->{'installed_version'},
2871 $pkg->{'previous_state'},
2875 $pkg->{'old_failed'},
2876 $pkg->{'binary_nmu_version'},
2877 $pkg->{'binary_nmu_changelog'},
2878 $pkg->{'failed_category'},
2879 $pkg->{'permbuildpri'},
2883 $pkg->{'extra_depends'},
2884 $pkg->{'extra_conflicts'},
2885 $pkg->{'bd_problem'},
2887 $distribution) or die $dbh->errstr;
2890 sub add_source_info {
2891 return if $simulate;
2893 $dbh->do('INSERT INTO ' . table_name() .
2894 ' (package, distribution) values (?, ?)',
2895 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2898 sub del_source_info {
2899 return if $simulate;
2901 $dbh->do('DELETE FROM ' . table_name() .
2902 ' WHERE package = ? AND distribution = ?',
2903 undef, $name, $distribution) or die $dbh->errstr;
2908 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2909 user_table_name() . ' WHERE username = ? AND distribution = ?',
2910 undef, $name, $distribution);
2914 sub update_user_info {
2915 return if $simulate;
2917 $dbh->do('UPDATE ' . user_table_name() .
2918 ' SET last_seen = now() WHERE username = ?' .
2919 ' AND distribution = ?',
2920 undef, $user, $distribution)
2921 or die $dbh->errstr;
2926 return if $simulate;
2928 $dbh->do('INSERT INTO ' . user_table_name() .
2929 ' (username, distribution, last_seen)' .
2930 ' values (?, ?, now())',
2931 undef, $user, $distribution)
2932 or die $dbh->errstr;
2937 return if $simulate;
2938 $dbh->do('LOCK TABLE ' . table_name() .
2939 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;
2943 # parts the array $_[0] and $_[1] and returns the sub-array (modifies the original one)
2946 my $separator = shift;
2947 while($args->[0] && $args->[0] ne $separator) {
2948 push @ret, shift @$args;
2950 shift @$args if @$args;
2954 sub parse_all_v3() {
2957 my $db = get_all_source_info();
2958 my $binary = $srcs->{'_binary'};
2961 foreach my $name (keys %$srcs) {
2962 next if $name eq '_binary';
2964 # state = installed, out-of-date, uncompiled, not-for-us
2965 my $pkgs = $srcs->{$name};
2966 my $pkg = $db->{$name};
2969 next SRCS if $pkgs->{'status'} eq 'not-for-us';
2970 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'} ($vars->{'arch'}, $vars->{'suite'}):";
2972 # does at least one binary exist in the database and is more recent - if so, we're probably just outdated, ignore the source package
2973 for my $bin (@{$pkgs->{'binary'}}) {
2974 if ($binary->{$bin} and vercmp($pkgs->{'version'}, $binary->{$bin}->{'version'}) < 0) {
2975 print "$logstr skipped because binaries (assumed to be) overwritten\n" if $verbose || $simulate;
2979 $pkg->{'package'} = $name;
2981 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'}".
2982 ($pkgs->{'binnmu'} ? ";b".$pkgs->{'binnmu'} : "").
2983 "($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'version'}".
2984 ($pkg->{'binary_nmu_version'} ? ";b".$pkg->{'binary_nmu_version'} : "").
2985 ", $pkg->{'state'}):";
2987 if (isin($pkgs->{'status'}, qw (installed related)) && $pkgs->{'version'} eq $pkg->{'version'} && $pkg->{'binary_nmu_version'} && $pkgs->{'binnmu'} < int($pkg->{'binary_nmu_version'})) {
2988 $pkgs->{'status'} = 'out-of-date';
2990 if (isin($pkgs->{'status'}, qw (installed related))) {
2992 if ($pkg->{'state'} ne 'Installed') {
2993 change_state( \$pkg, 'Installed');
2994 delete $pkg->{'depends'};
2995 delete $pkg->{'extra_depends'};
2996 delete $pkg->{'extra_conflicts'};
2999 my $attrs = { 'version' => 'version', 'installed_version' => 'version', 'binary_nmu_version' => 'binnmu', 'section' => 'section', 'priority' => 'priority' };
3000 foreach my $k (keys %$attrs) {
3001 if ($pkg->{$k} ne $pkgs->{$attrs->{$k}}) {
3002 $pkg->{$k} = $pkgs->{$attrs->{$k}};
3006 if (isin($pkgs->{'status'}, qw (related)) and $pkg->{'notes'} ne "related") {
3007 $pkg->{'notes'} = "related";
3011 print "$logstr set to installed/".$pkg->{'notes'}."\n" if $verbose || $simulate;
3012 log_ta( $pkg, "--merge-v3: installed" ) unless $simulate;
3013 update_source_info($pkg) unless $simulate;
3018 if ($pkgs->{'status'} eq 'not-for-us') {
3019 next if isin( $pkg->{'state'}, qw(Not-For-Us Installed Failed-Removed));
3021 if (isin( $pkg->{'state'}, qw(Failed Build-Attempted Built))) {
3022 change_state( \$pkg, "Failed-Removed" );
3023 log_ta( $pkg, "--merge-v3: Failed-Removed" ) unless $simulate;
3024 update_source_info($pkg) unless $simulate;
3025 print "$logstr (virtually) deleted from database\n" if $verbose || $simulate;
3029 print "$logstr should delete (not-for-us according to P-a-s)\n" if $verbose || $simulate || 1; # not implemented yet on purpose
3033 # only uncompiled / out-of-date are left, so check if anything new
3034 if (!(isin($pkgs->{'status'}, qw (uncompiled out-of-date)))) {
3035 print "$logstr package in unknown state: $pkgs->{'status'}\n";
3038 next if $pkgs->{'version'} eq $pkg->{'version'} and $pkgs->{'binnmu'} >= int($pkg->{'binary_nmu_version'});
3039 next if $pkgs->{'version'} eq $pkg->{'version'} and !isin( $pkg->{'state'}, qw(Installed));
3040 next if isin( $pkg->{'state'}, qw(Not-For-Us Failed-Removed));
3042 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
3043 send_mail( $pkg->{'builder'},
3044 "new version of $name (dist=$distribution)",
3045 "As far as I'm informed, you're currently building the package $name\n".
3046 "in version $pkg->{'version'}.\n\n".
3047 "Now there's a new source version $pkgs->{'version'}. If you haven't finished\n".
3048 "compiling $name yet, you can stop it to save some work.\n".
3049 "Just to inform you...\n".
3050 "(This is an automated message)\n" ) unless $simulate;
3051 print "$logstr new version while building $pkg->{'version'} -- sending mail to builder ($pkg->{'builder'})\n"
3052 if $verbose || $simulate;
3054 change_state( \$pkg, 'Needs-Build');
3055 $pkg->{'notes'} = $pkgs->{'status'};
3056 $pkg->{'version'} = $pkgs->{'version'};
3057 $pkg->{'section'} = $pkgs->{'section'};
3058 $pkg->{'priority'} = $pkgs->{'priority'};
3059 $pkg->{'dep'} = $pkgs->{'depends'};
3060 $pkg->{'conf'} = $pkgs->{'conflicts'};
3061 delete $pkg->{'builder'};
3062 delete $pkg->{'binary_nmu_version'} unless $pkgs->{'binnmu'};
3063 delete $pkg->{'binary_nmu_changelog'} unless $pkgs->{'binnmu'};
3064 log_ta( $pkg, "--merge-v3: needs-build" ) unless $simulate;
3065 update_source_info($pkg) unless $simulate;
3066 print "$logstr set to needs-builds\n" if $simulate || $verbose;
3069 foreach my $name (keys %$db) {
3070 next if $srcs->{$name};
3071 my $pkg = $db->{$name};
3072 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkg->{'version'} ($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'state'}):";
3073 # package disappeared - delete
3074 change_state( \$pkg, 'deleted' );
3075 log_ta( $pkg, "--merge-v3: deleted" ) unless $simulate;
3076 print "$logstr deleted from database\n" if $verbose || $simulate;
3077 del_source_info($name) unless $simulate;
3078 delete $db->{$name};