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
55 our ($verbose, $mail_logs, $list_order, $list_state,
56 $curr_date, $op_mode, $user, $real_user, $distribution,
57 $fail_reason, $opt_override, $import_from, $export_to, $opt_create_db,
59 $info_all_dists, $arch,
60 $category, %catval, %short_category,
61 $short_date, $list_min_age, $dbbase, @curr_time,
62 $build_priority, %new_vers, $binNMUver, %merge_srcvers, %merge_binsrc,
63 $printformat, $ownprintformat, $privmode, $extra_depends, $extra_conflicts
65 our $Pas = '/org/buildd.debian.org/etc/packages-arch-specific/Packages-arch-specific';
67 our $simulate_edos = 0;
68 our $api = undef; # allow buildds to specify an different api
71 $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
76 $curr_date = strftime("%Y %b %d %H:%M:%S",@curr_time);
77 $short_date = strftime("%m/%d/%y",@curr_time);
80 # map program invocation names to operation modes
81 my %prognames = ( "uploaded-build" => "set-uploaded",
82 "failed-build" => "set-failed",
83 "no-build" => "set-not-for-us",
84 "give-back-build" => "set-needs-build",
85 "dep-wait-build" => "set-dep-wait",
86 "forget-build" => "forget",
87 "build-info" => "info" );
89 %short_category = ( u => "uploaded-fixed-pkg",
96 c => "compiler-error",
100 ($progname = $0) =~ s,.*/,,;
101 if ($prognames{$progname}) {
102 $op_mode = $prognames{$progname};
104 elsif ($progname =~ /^list-(.*)$/) {
106 $list_state = ($1 eq "all") ? "" : $1;
111 simulate => { flag => \$simulate }, # this is not supported by all operations (yet)!
112 "simulate-edos" => { flag => \$simulate_edos },
113 "simulate-all" => { code => sub { $simulate = 1; $simulate_edos = 1; } },
114 api => { arg => \$api, code => sub {
115 # official apis are numeric
116 die "$api isn't numeric" unless int($api) eq $api;
117 die "$api too large" unless $api <= 1;
119 verbose => { short => "v", flag => \$verbose },
120 override => { short => "o", flag => \$opt_override },
121 "create-db" => { flag => \$opt_create_db },
122 "correct-compare" => { flag => \$WannaBuild::opt_correct_version_cmp },
123 # TODO: remove after buildds no longer pass to wanna-build
124 "no-propagation" => { short => "N" },
125 "no-down-propagation" => { short => "D" },
127 take => { mode => "set-building" },
128 failed => { short => "f", mode => "set-failed" },
129 uploaded => { short => "u", mode => "set-uploaded" },
130 "no-build" => { short => "n", mode => "set-not-for-us" },
131 built => { mode => "set-built" },
132 attempted => { mode => "set-attempted" },
133 "give-back" => { mode => "set-needs-build" },
134 "dep-wait" => { mode => "set-dep-wait" },
135 forget => { mode => "forget" },
136 'forget-user' => { mode => 'forget-user' },
137 update => { mode => "set-update" },
138 #"merge-quinn" => { mode => "merge-quinn" },
139 #"merge-partial-quinn" => { mode => "merge-partial-quinn" },
140 #"merge-packages" => { mode => "merge-packages" },
141 #"merge-sources" => { mode => "merge-sources" },
142 "pretend-avail" => { short => "p", mode => "pretend-avail" },
143 #"merge-all" => { mode => "merge-all" },
144 #"merge-all-secondary" => { mode => "merge-all-secondary" },
145 "merge-v3" => { mode => "merge-v3" },
146 info => { short => "i", mode => "info" },
147 'binNMU' => { mode => 'set-binary-nmu', arg => \$binNMUver,
148 code => sub { die "Invalid binNMU version: $binNMUver\n"
149 if $binNMUver !~ /^([\d]*)$/ and $1 >= 0; } },
150 'perm-build-priority' => { mode => "set-permanent-build-priority", arg => \$build_priority,
151 code => sub { die "Invalid build priority: $build_priority\n"
152 if $build_priority !~ /^-?[\d]+$/; } },
153 'build-priority' => { mode => "set-build-priority", arg => \$build_priority,
154 code => sub { die "Invalid build priority: $build_priority\n"
155 if $build_priority !~ /^-?[\d]+$/; } },
157 { short => "l", mode => "list", arg => \$list_state,
159 die "Unknown state to list: $list_state\n"
160 if !isin( $list_state, qw(needs-build building uploaded
161 built build-attempted failed installed dep-wait
162 not-for-us all failed-removed
163 install-wait reupload-wait bd-uninstallable));} },
166 { short => "d", arg => \$distribution,
168 if ($distribution eq "a" || $distribution eq "all") {
173 $distribution = "oldstable" if $distribution eq "o";
174 $distribution = "stable" if $distribution eq "s";
175 $distribution = "testing" if $distribution eq "t";
176 $distribution = "unstable" if $distribution eq "u";
180 { short => "O", arg => \$list_order,
182 die "Bad ordering character\n"
183 if $list_order !~ /^[PSpsncbCW]+$/;
185 message => { short => "m", arg => \$fail_reason },
186 # database is deprecated, use arch instead.
187 database => { short => "b", arg => \$conf::dbbase },
188 arch => { short => "A", arg => \$arch },
189 user => { short => "U", arg => \$user },
190 category => { short => "c", arg => \$category,
192 $category = $short_category{$category}
193 if exists $short_category{$category};
194 die "Unknown category: $category\n"
195 if !isin( $category, values %short_category );
197 "min-age" => { short => "a", arg => \$list_min_age,
199 die "Argument of --min-age must be a non-zero number\n"
200 if $list_min_age == 0;
202 "max-age" => { arg => \$list_min_age,
204 die "Argument of --max-age must be a non-zero number\n"
205 if $list_min_age == 0;
208 "format" => { arg => \$printformat },
209 "own-format" => { arg => \$ownprintformat },
210 "Pas" => { arg => \$Pas },
211 "extra-depends"=> { arg => \$extra_depends },
212 "extra-conflicts"=> { arg => \$extra_conflicts },
214 export => { arg => \$export_to, mode => "export" },
215 import => { arg => \$import_from, mode => "import" },
216 "manual-edit" => { mode => "manual-edit" },
219 while( @ARGV && $ARGV[0] =~ /^-/ ) {
222 my($opt, $optname, $arg);
223 if (/^--([^=]+)(=|$)/) {
225 $opt = $options{$optname};
226 $arg = $1 if /^--\Q$optname\E=((.|\n)*)$/;
229 $optname = substr( $_, 1, 1 );
230 $opt = (grep { defined($_->{short}) ? $_->{short} eq $optname : 0} values %options)[0];
231 $arg = $1 if /^-$optname(.+)$/;
234 warn "Unknown option: --$1\n";
239 die "$optname option missing argument\n" if !@ARGV;
242 ${$opt->{arg}} = $arg;
244 elsif (defined $arg) {
245 die "Option $optname takes no argument\n";
249 die "Conflicting operation modes\n" if $op_mode;
250 $op_mode = $opt->{mode};
260 $op_mode = $category ? "set-failed" : "set-building"
261 if !$op_mode; # default operation
262 $distribution ||= "unstable";
263 if ($distribution eq 'any-priv') {
265 $distribution = 'any';
267 if ($distribution eq 'any-unpriv') {
269 $distribution = 'any';
271 undef $distribution if $distribution eq 'any';
273 my @dists = split(/[, ]+/, $distribution);
274 foreach my $dist (@dists) {
275 die "Bad distribution '$distribution'\n"
276 if !isin($dist, keys %conf::distributions);
279 if (!isin ( $op_mode, qw(list) ) && ( !$distribution || $distribution =~ /[ ,]/)) {
280 die "multiple distributions are only allowed for list";
283 # If they didn't specify an arch, try to get it from database name which
284 # is in the form of $arch/build-db
285 # This is for backwards compatibity with older versions that didn't
286 # specify the arch yet.
287 $conf::dbbase =~ m#^([^/]+)#;
290 # TODO: Check that it's an known arch (for that dist), and give
294 my $version = '$Revision: db181a534e9d $ $Date: 2008/03/26 06:20:22 $ $Author: rmurray $';
295 $version =~ s/(^\$| \$ .*$)//g;
296 print "wanna-build $version for $distribution on $arch\n";
299 if (!@ARGV && !isin( $op_mode, qw(list merge-quinn merge-partial-quinn import export
300 merge-packages manual-edit
302 warn "No packages given.\n";
306 $real_user = (getpwuid($<))[0];
307 die "Can't determine your user name\n"
308 if $op_mode ne "list" && !$user &&
309 !($user = $real_user);
312 if ($op_mode eq "set-failed" && !$category) {
313 print "Enter reason for failing (end with '.' alone on ".
318 last if $line eq ".\n";
319 $fail_reason .= $line;
321 chomp( $fail_reason );
322 } elsif ($op_mode eq "set-dep-wait") {
323 print "Enter dependencies (one line):\n";
325 while( !$line && !eof(STDIN) ) {
326 chomp( $line = <STDIN> );
328 die "No dependencies given\n" if !$line;
329 $fail_reason = $line;
330 } elsif ($op_mode eq "set-binary-nmu" and $binNMUver > 0) {
331 print "Enter changelog entry (one line):\n";
333 while( !$line && !eof(STDIN) ) {
334 chomp( $line = <STDIN> );
336 die "No changelog entry given\n" if !$line;
337 $fail_reason = $line;
342 my $yamldir = "/org/wanna-build/etc/yaml";
343 my @files = ('wanna-build.yaml');
344 if ((getpwuid($>))[7]) { push (@files, ((getpwuid($>))[7])."/.wanna-build.yaml"); }
345 if ($user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
346 if ($user) { push ( @files, "$user.yaml"); }
347 foreach my $file (@files) {
348 my $cfile = File::Spec->rel2abs( $file, $yamldir );
349 if ($verbose >= 2) { print "Trying to read $file ($cfile) ...\n"; }
350 next unless -f $cfile;
351 if ($verbose >= 2) { print "Read $file ($cfile) ...\n"; }
352 my $m = YAML::Tiny->read( $cfile )->[0];
353 $yamlmap = merge($m, $yamlmap);
356 die "FATAL: no configuration found\n";
358 $list_order = $yamlmap->{"list-order"}{$list_state} if !$list_order and $list_state;
359 $list_order ||= $yamlmap->{"list-order"}{'default'};
360 $api //= $yamlmap->{"api"};
368 $dbh->disconnect or warn $dbh->errstr;
372 my $schema_suffix = '';
373 if (isin( $op_mode, qw(list info)) && $distribution !~ /security/ && !(not -t and $user =~ /buildd-/) && !($privmode eq 'yes')) {
374 $dbh = DBI->connect("DBI:Pg:service=wanna-build") ||
375 die "FATAL: Cannot open database: $DBI::errstr\n";
376 $schema_suffix = '_public';
380 $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") ||
381 die "FATAL: Cannot open database: $DBI::errstr\n";
384 # TODO: This shouldn't be needed, file a bug.
385 $dbh->{pg_server_prepare} = 0;
387 $dbh->begin_work or die $dbh->errstr;
394 if ($mail_logs && $conf::log_mail) {
395 send_mail( $conf::log_mail,
396 "wanna-build $distribution state changes $curr_date",
397 "State changes at $curr_date for distribution ".
398 "$distribution:\n\n$mail_logs\n" );
406 SWITCH: foreach ($op_mode) {
408 add_packages( $1, @ARGV );
412 list_packages( $list_state );
416 info_packages( @ARGV );
419 /^forget-user/ && do {
420 die "This operation is restricted to admin users\n"
421 if (defined @conf::admin_users and
422 !isin( $real_user, @conf::admin_users));
423 forget_users( @ARGV );
427 forget_packages( @ARGV );
430 /^merge-partial-quinn/ && do {
431 die "This operation is restricted to admin users\n"
432 if (defined @conf::admin_users and
433 !isin( $real_user, @conf::admin_users));
438 /^merge-quinn/ && do {
439 die "This operation is restricted to admin users\n"
440 if (defined @conf::admin_users and
441 !isin( $real_user, @conf::admin_users));
446 /^merge-packages/ && do {
447 die "This operation is restricted to admin users\n"
448 if (defined @conf::admin_users and
449 !isin( $real_user, @conf::admin_users));
454 /^merge-sources/ && do {
455 die "This operation is restricted to admin users\n"
456 if (defined @conf::admin_users and
457 !isin( $real_user, @conf::admin_users));
462 /^pretend-avail/ && do {
463 pretend_avail( @ARGV );
466 /^merge-all$/ && do {
467 die "This operation is restricted to admin users\n"
468 if (defined @conf::admin_users and
469 !isin( $real_user, @conf::admin_users));
472 @ARGV = ( $ARGS[0] );
473 my $pkgs = parse_packages(0);
474 @ARGV = ( $ARGS[1] );
476 @ARGV = ( $ARGS[2] );
477 my $srcs = parse_sources(1);
478 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[0]), 'srcs' => $srcs });
481 /^merge-all-secondary/ && do {
482 die "This operation is restricted to admin users\n"
483 if (defined @conf::admin_users and
484 !isin( $real_user, @conf::admin_users));
485 # This is in case the chroot has multiple unrelated
486 # dist, for instance unstable and experimental.
487 # This is not for stable and proposed-updates.
488 # The second packages file contains a combination
489 # of all Packages files known to the buildd, the
490 # first only for the current dist.
493 @ARGV = ( $ARGS[0] );
494 my $pkgs = parse_packages(0);
495 @ARGV = ( $ARGS[3] );
496 my $pkgs = parse_packages(1);
497 @ARGV = ( $ARGS[1] );
499 @ARGV = ( $ARGS[2] );
500 my $srcs = parse_sources(1);
501 call_edos_depcheck( {'arch' => $arch, 'pkgs' => ($ARGS[3]), 'srcs' => $srcs });
505 die "This operation is restricted to admin users\n"
506 if (defined @conf::admin_users and !isin( $real_user, @conf::admin_users) and !$simulate);
507 # call with installed-packages+ . installed-sources+ [ . available-for-build-packages* [ . consider-as-installed-source* ] ]
508 # in case available-for-build-packages is not specified, installed-packages are used
509 lock_table() unless $simulate;
510 my $replacemap = { '%ARCH%' => $arch, '%SUITE%' => $distribution };
511 map { my $k = $_; grep { $k =~ s,$_,$replacemap->{$_}, } keys %{$replacemap}; $_ = $k; } @ARGV;
512 my @ipkgs = &parse_argv( \@ARGV, '.');
513 my @isrcs = &parse_argv( \@ARGV, '.');
514 my @bpkgs = &parse_argv( \@ARGV, '.');
515 my @psrcs = &parse_argv( \@ARGV, '.');
517 my $srcs = WB::QD::readsourcebins($arch, $Pas, \@isrcs, \@ipkgs);
519 my $psrcs = WB::QD::readsourcebins($arch, $Pas, \@psrcs, []);
520 foreach my $k (keys %$$psrcs) {
521 next if $$srcs->{$k};
522 my $pkg = $$psrcs->{$k};
523 $pkg->{'status'} = 'related';
527 parse_all_v3($$srcs, {'arch' => $arch, 'suite' => $distribution, 'time' => $curr_date});
528 @bpkgs = @ipkgs unless @bpkgs;
529 call_edos_depcheck( {'arch' => $arch, 'pkgs' => \@bpkgs, 'srcs' => $$srcs, 'depwait' => 1 });
533 die "This operation is restricted to admin users\n"
534 if (defined @conf::admin_users and
535 !isin( $real_user, @conf::admin_users));
536 $dbh->do("DELETE from " . table_name() .
537 " WHERE distribution = ?", undef,
541 read_db( $import_from );
545 export_db( $export_to );
549 die "Unexpected operation mode $op_mode\n";
551 if (not -t and $user =~ /buildd-/) {
552 my $userinfo = get_user_info($user);
553 if (!defined $userinfo)
555 add_user_info($user);
559 update_user_info($user);
565 my $newstate = shift;
566 my( $package, $name, $version, $ok, $reason );
568 foreach $package (@_) {
569 $package =~ s,^.*/,,; # strip path
570 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
571 $package =~ s/_[a-zA-Z\d-]+\.changes$//; # strip extension
572 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
573 ($name,$version) = ($1,$2);
576 warn "$package: can't extract package name and version ".
581 if ($op_mode eq "set-building") {
582 add_one_building( $name, $version );
584 elsif ($op_mode eq "set-built") {
585 add_one_built( $name, $version );
587 elsif ($op_mode eq "set-attempted") {
588 add_one_attempted( $name, $version );
590 elsif ($op_mode eq "set-uploaded") {
591 add_one_uploaded( $name, $version );
593 elsif ($op_mode eq "set-failed") {
594 add_one_failed( $name, $version );
596 elsif ($op_mode eq "set-not-for-us") {
597 add_one_notforus( $name, $version );
599 elsif ($op_mode eq "set-needs-build") {
600 add_one_needsbuild( $name, $version );
602 elsif ($op_mode eq "set-dep-wait") {
603 add_one_depwait( $name, $version );
605 elsif ($op_mode eq "set-build-priority") {
606 set_one_buildpri( $name, $version, 'buildpri' );
608 elsif ($op_mode eq "set-permanent-build-priority") {
609 set_one_buildpri( $name, $version, 'permbuildpri' );
611 elsif ($op_mode eq "set-binary-nmu") {
612 set_one_binnmu( $name, $version );
614 elsif ($op_mode eq "set-update") {
615 set_one_update( $name, $version );
620 sub add_one_building {
626 my $pkg = get_source_info($name);
628 if ($pkg->{'state'} eq "Not-For-Us") {
630 $reason = "not suitable for this architecture";
632 elsif ($pkg->{'state'} =~ /^Dep-Wait/) {
634 $reason = "not all source dependencies available yet";
636 elsif ($pkg->{'state'} =~ /^BD-Uninstallable/) {
638 $reason = "source dependencies are not installable";
640 elsif ($pkg->{'state'} eq "Uploaded" &&
641 (version_lesseq($version, $pkg->{'version'}))) {
643 $reason = "already uploaded by $pkg->{'builder'}";
644 $reason .= " (in newer version $pkg->{'version'})"
645 if !version_eq($pkg, $version);
647 elsif ($pkg->{'state'} eq "Installed" &&
648 version_less($version,$pkg->{'version'})) {
650 print "$name: Warning: newer version $pkg->{'version'} ".
651 "already installed, but overridden.\n";
655 $reason = "newer version $pkg->{'version'} already in ".
656 "archive; doesn't need rebuilding";
657 print "$name: Note: If the following is due to an epoch ",
658 " change, use --override\n";
661 elsif ($pkg->{'state'} eq "Installed" &&
662 pkg_version_eq($pkg,$version)) {
664 $reason = "is up-to-date in the archive; doesn't need rebuilding";
666 elsif ($pkg->{'state'} eq "Needs-Build" &&
667 version_less($version,$pkg->{'version'})) {
669 print "$name: Warning: newer version $pkg->{'version'} ".
670 "needs building, but overridden.";
674 $reason = "newer version $pkg->{'version'} needs building, ".
678 elsif (isin($pkg->{'state'},qw(Building Built Build-Attempted))) {
679 if (version_less($pkg->{'version'},$version)) {
680 print "$name: Warning: Older version $pkg->{'version'} ",
681 "is being built by $pkg->{'builder'}\n";
682 if ($pkg->{'builder'} ne $user) {
683 send_mail( $pkg->{'builder'},
684 "package takeover in newer version",
685 "You are building package '$name' in ".
686 "version $version\n".
687 "(as far as I'm informed).\n".
688 "$user now has taken the newer ".
689 "version $version for building.".
690 "You can abort the build if you like.\n" );
695 print "User $pkg->{'builder'} had already ",
696 "taken the following package,\n",
697 "but overriding this as you request:\n";
698 send_mail( $pkg->{'builder'}, "package takeover",
699 "The package '$name' (version $version) that ".
700 "was taken by you\n".
701 "has been taken over by $user\n" );
703 elsif ($pkg->{'builder'} eq $user) {
704 print "$name: Note: already taken by you.\n";
705 print "$name: ok\n" if $verbose;
710 $reason = "already taken by $pkg->{'builder'}";
711 $reason .= " (in newer version $pkg->{'version'})"
712 if !version_eq($pkg->{'version'}, $version);
716 elsif ($pkg->{'state'} =~ /^Failed/ &&
717 pkg_version_eq($pkg, $version)) {
719 print "The following package previously failed ",
720 "(by $pkg->{'builder'})\n",
721 "but overriding this as you request:\n";
722 send_mail( $pkg->{'builder'}, "failed package takeover",
723 "The package '$name' (version $version) that ".
725 "and has failed previously has been taken over ".
727 if $pkg->{'builder'} ne $user;
731 $reason = "build of $version failed previously:\n ";
732 $reason .= join( "\n ", split( "\n", $pkg->{'failed'} ));
733 $reason .= "\nalso the package doesn't need builing"
734 if $pkg->{'state'} eq 'Failed-Removed';
741 if ($pkg->{'binary_nmu_version'}) {
742 print "$name: Warning: needs binary NMU $pkg->{'binary_nmu_version'}\n" .
743 "$pkg->{'binary_nmu_changelog'}\n";
746 print "$name: Warning: Previous version failed!\n"
747 if $pkg->{'previous_state'} =~ /^Failed/ ||
748 $pkg->{'state'} =~ /^Failed/;
750 print "$name: $ok\n" if $verbose;
753 print " - status: ok\n";
754 printf " - pkg-ver: %s_%s\n", $name, $version;
755 print " - binNMU: $pkg->{'binary_nmu_version'}\n" if $pkg->{'binary_nmu_version'};
756 print " - extra-changelog: $pkg->{'binary_nmu_changelog'}\n" if $pkg->{'binary_nmu_changelog'} && $pkg->{'binary_nmu_version'};
757 print " - extra-depends: $pkg->{'extra_depends'}\n" if $pkg->{'extra_depends'};
758 print " - extra-conflicts: $pkg->{'extra_conflicts'}\n" if $pkg->{'extra_conflicts'};
760 change_state( \$pkg, 'Building' );
761 $pkg->{'package'} = $name;
762 $pkg->{'version'} = $version;
763 $pkg->{'builder'} = $user;
764 log_ta( $pkg, "--take" );
765 update_source_info($pkg);
769 print "$name: NOT OK!\n $reason\n";
771 print "- $name:\n - status: not ok\n - reason: \"$reason\"\n";
776 sub add_one_attempted {
779 my $pkg = get_source_info($name);
781 if (!defined($pkg)) {
782 print "$name: not registered yet.\n";
786 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
787 print "$name: not taken for building (state is $pkg->{'state'}). ",
791 if ($pkg->{'builder'} ne $user) {
792 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
795 elsif ( !pkg_version_eq($pkg, $version) ) {
796 print "$name: version mismatch ".
797 "$(pkg->{'version'} ".
798 "by $pkg->{'builder'})\n";
802 change_state( \$pkg, 'Build-Attempted' );
803 log_ta( $pkg, "--attempted" );
804 update_source_info($pkg);
805 print "$name: registered as uploaded\n" if $verbose;
811 my $pkg = get_source_info($name);
813 if (!defined($pkg)) {
814 print "$name: not registered yet.\n";
818 if (($pkg->{'state'} ne "Building") && ($pkg->{'state'} ne "Build-Attempted")) {
819 print "$name: not taken for building (state is $pkg->{'state'}). ",
823 if ($pkg->{'builder'} ne $user) {
824 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
827 elsif ( !pkg_version_eq($pkg, $version) ) {
828 print "$name: version mismatch ".
829 "$(pkg->{'version'} ".
830 "by $pkg->{'builder'})\n";
833 change_state( \$pkg, 'Built' );
834 log_ta( $pkg, "--built" );
835 update_source_info($pkg);
836 print "$name: registered as built\n" if $verbose;
839 sub add_one_uploaded {
842 my $pkg = get_source_info($name);
844 if (!defined($pkg)) {
845 print "$name: not registered yet.\n";
849 if ($pkg->{'state'} eq "Uploaded" &&
850 pkg_version_eq($pkg,$version)) {
851 print "$name: already uploaded\n";
854 if (!isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
855 print "$name: not taken for building (state is $pkg->{'state'}). ",
859 if ($pkg->{'builder'} ne $user) {
860 print "$name: not taken by you, but by $pkg->{'builder'}. Skipping.\n";
863 # strip epoch -- buildd-uploader used to go based on the filename.
864 # (to remove at some point)
866 ($pkgver = $pkg->{'version'}) =~ s/^\d+://;
867 $version =~ s/^\d+://; # for command line use
868 if ($pkg->{'binary_nmu_version'} ) {
869 my $nmuver = binNMU_version($pkgver, $pkg->{'binary_nmu_version'});
870 if (!version_eq( $nmuver, $version )) {
871 print "$name: version mismatch ($nmuver registered). ",
875 } elsif (!version_eq($pkgver, $version)) {
876 print "$name: version mismatch ($pkg->{'version'} registered). ",
881 change_state( \$pkg, 'Uploaded' );
882 log_ta( $pkg, "--uploaded" );
883 update_source_info($pkg);
884 print "$name: registered as uploaded\n" if $verbose;
891 my $pkg = get_source_info($name);
893 if (!defined($pkg)) {
894 print "$name: not registered yet.\n";
897 $state = $pkg->{'state'};
899 if ($state eq "Not-For-Us") {
900 print "$name: not suitable for this architecture anyway. Skipping.\n";
903 elsif ($state eq "Failed-Removed") {
904 print "$name: failed previously and doesn't need building. Skipping.\n";
907 elsif ($state eq "Installed") {
908 print "$name: Is already installed in archive. Skipping.\n";
911 elsif ($pkg->{'builder'} &&
912 (($user ne $pkg->{'builder'}) &&
913 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user))) {
914 print "$name: not taken by you, but by ".
915 "$pkg->{'builder'}. Skipping.\n";
918 elsif ( !pkg_version_eq($pkg, $version) ) {
919 print "$name: version mismatch ".
920 "$(pkg->{'version'} ".
921 "by $pkg->{'builder'})\n";
926 if (!$cat && $fail_reason =~ /^\[([^\]]+)\]/) {
928 $cat = $short_category{$cat} if exists $short_category{$cat};
929 if (!isin( $cat, values %short_category )) {
930 print "$name: Warning: unknown category $cat; discarded\n";
933 $fail_reason =~ s/^\[[^\]]+\][ \t]*\n*//;
936 if ($state eq "Needs-Build") {
937 print "$name: Warning: not registered for building previously, ".
938 "but processing anyway.\n";
940 elsif ($state eq "Uploaded") {
941 print "$name: Warning: marked as uploaded previously, ".
942 "but processing anyway.\n";
944 elsif ($state eq "Dep-Wait") {
945 print "$name: Warning: marked as waiting for dependencies, ".
946 "but processing anyway.\n";
948 elsif ($state eq "BD-Uninstallable") {
949 print "$name: Warning: marked as having uninstallable build-dependencies, ".
950 "but processing anyway.\n";
952 elsif ($state eq "Failed") {
953 print "$name: already registered as failed; will append new message\n"
955 print "$name: already registered as failed; changing category\n"
959 if (($cat eq "reminder-sent" || $cat eq "nmu-offered") &&
960 defined $pkg->{'failed_category'} &&
961 $pkg->{'failed_category'} ne $cat) {
962 (my $action = $cat) =~ s/-/ /;
963 $fail_reason .= "\n$short_date: $action";
966 change_state( \$pkg, 'Failed' );
967 $pkg->{'builder'} = $user;
968 $pkg->{'failed'} .= "\n" if $pkg->{'failed'};
969 $pkg->{'failed'} .= $fail_reason;
970 $pkg->{'failed_category'} = $cat if $cat;
971 if (defined $pkg->{'permbuildpri'}) {
972 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
974 delete $pkg->{'buildpri'};
976 log_ta( $pkg, "--failed" );
977 update_source_info($pkg);
978 print "$name: registered as failed\n" if $verbose;
981 sub add_one_notforus {
984 my $pkg = get_source_info($name);
986 if ($pkg->{'state'} eq 'Not-For-Us') {
987 # reset Not-For-Us state in case it's called twice; this is
988 # the only way to get a package out of this state...
989 # There is no really good state in which such packages should
990 # be put :-( So use Failed for now.
991 change_state( \$pkg, 'Failed' );
992 $pkg->{'package'} = $name;
993 $pkg->{'failed'} = "Was Not-For-Us previously";
994 delete $pkg->{'builder'};
995 delete $pkg->{'depends'};
996 log_ta( $pkg, "--no-build(rev)" );
997 print "$name: now not unsuitable anymore\n";
999 send_mail( $conf::notforus_maint,
1000 "$name moved out of Not-For-Us state",
1001 "The package '$name' has been moved out of the Not-For-Us ".
1002 "state by $user.\n".
1003 "It should probably also be removed from ".
1004 "Packages-arch-specific or\n".
1005 "the action was wrong.\n" )
1006 if $conf::notforus_maint;
1009 change_state( \$pkg, 'Not-For-Us' );
1010 $pkg->{'package'} = $name;
1011 delete $pkg->{'builder'};
1012 delete $pkg->{'depends'};
1013 delete $pkg->{'buildpri'};
1014 delete $pkg->{'binary_nmu_version'};
1015 delete $pkg->{'binary_nmu_changelog'};
1016 log_ta( $pkg, "--no-build" );
1017 print "$name: registered as unsuitable\n" if $verbose;
1019 send_mail( $conf::notforus_maint,
1020 "$name set to Not-For-Us",
1021 "The package '$name' has been set to state Not-For-Us ".
1023 "It should probably also be added to ".
1024 "Packages-arch-specific or\n".
1025 "the Not-For-Us state is wrong.\n" )
1026 if $conf::notforus_maint;
1028 update_source_info($pkg);
1031 sub add_one_needsbuild {
1033 my $version = shift;
1035 my $pkg = get_source_info($name);
1037 if (!defined($pkg)) {
1038 print "$name: not registered; can't give back.\n";
1041 $state = $pkg->{'state'};
1043 if ($state eq "BD-Uninstallable") {
1044 if ($opt_override) {
1045 print "$name: Forcing uninstallability mark to be removed. This is not permanent and might be reset with the next trigger run\n";
1047 change_state( \$pkg, 'Needs-Build' );
1048 delete $pkg->{'builder'};
1049 delete $pkg->{'depends'};
1050 log_ta( $pkg, "--give-back" );
1051 update_source_info($pkg);
1052 print "$name: given back\n" if $verbose;
1056 print "$name: has uninstallable build-dependencies. Skipping\n",
1057 " (use --override to clear dependency list and ",
1058 "give back anyway)\n";
1062 elsif ($state eq "Dep-Wait") {
1063 if ($opt_override) {
1064 print "$name: Forcing source dependency list to be cleared\n";
1067 print "$name: waiting for source dependencies. Skipping\n",
1068 " (use --override to clear dependency list and ",
1069 "give back anyway)\n";
1073 elsif (!isin( $state, qw(Building Built Build-Attempted))) {
1074 print "$name: not taken for building (state is $state).";
1075 if ($opt_override) {
1076 print "\n$name: Forcing give-back\n";
1079 print " Skipping.\n";
1083 if (defined ($pkg->{'builder'}) && $user ne $pkg->{'builder'} &&
1084 !($pkg->{'builder'} =~ /^(\w+)-\w+/ && $1 eq $user) &&
1086 print "$name: not taken by you, but by ".
1087 "$pkg->{'builder'}. Skipping.\n";
1090 if (!pkg_version_eq($pkg, $version)) {
1091 print "$name: version mismatch ($pkg->{'version'} registered). ",
1095 if ($distribution eq "unstable") {
1096 change_state( \$pkg, 'BD-Uninstallable' );
1097 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1099 change_state( \$pkg, 'Needs-Build' );
1101 $pkg->{'builder'} = undef;
1102 $pkg->{'depends'} = undef;
1103 log_ta( $pkg, "--give-back" );
1104 update_source_info($pkg);
1105 print "$name: given back\n" if $verbose;
1108 sub set_one_binnmu {
1110 my $version = shift;
1111 my $pkg = get_source_info($name);
1114 if (!defined($pkg)) {
1115 print "$name: not registered; can't register for binNMU.\n";
1118 my $db_ver = $pkg->{'version'};
1120 if (!version_eq($db_ver, $version)) {
1121 print "$name: version mismatch ($db_ver registered). ",
1125 $state = $pkg->{'state'};
1127 if (defined $pkg->{'binary_nmu_version'}) {
1128 if ($binNMUver == 0) {
1129 change_state( \$pkg, 'Installed' );
1130 delete $pkg->{'builder'};
1131 delete $pkg->{'depends'};
1132 delete $pkg->{'binary_nmu_version'};
1133 delete $pkg->{'binary_nmu_changelog'};
1134 } elsif ($binNMUver <= $pkg->{'binary_nmu_version'}) {
1135 print "$name: already building binNMU $pkg->{'binary_nmu_version'}\n";
1138 $pkg->{'binary_nmu_version'} = $binNMUver;
1139 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1140 $pkg->{'notes'} = 'out-of-date';
1141 $pkg->{'buildpri'} = $pkg->{'permbuildpri'}
1142 if (defined $pkg->{'permbuildpri'});
1144 log_ta( $pkg, "--binNMU" );
1145 update_source_info($pkg);
1147 } elsif ($binNMUver == 0) {
1148 print "${name}_$version: no scheduled binNMU to cancel.\n";
1152 if ($state ne 'Installed') {
1153 print "${name}_$version: not installed; can't register for binNMU.\n";
1157 my $fullver = binNMU_version($version,$binNMUver);
1158 if ( version_lesseq( $fullver, $pkg->{'installed_version'} ) )
1160 print "$name: binNMU $fullver is not newer than current version $pkg->{'installed_version'}\n";
1164 if ($distribution eq "unstable") {
1165 change_state( \$pkg, 'BD-Uninstallable' );
1166 $pkg->{'bd_problem'} = "Installability of build dependencies not tested yet";
1170 change_state( \$pkg, 'Needs-Build' );
1172 delete $pkg->{'builder'};
1173 delete $pkg->{'depends'};
1174 $pkg->{'binary_nmu_version'} = $binNMUver;
1175 $pkg->{'binary_nmu_changelog'} = $fail_reason;
1176 $pkg->{'notes'} = 'out-of-date';
1177 log_ta( $pkg, "--binNMU" );
1178 update_source_info($pkg);
1179 print "${name}: registered for binNMU $fullver\n" if $verbose;
1182 sub set_one_buildpri {
1184 my $version = shift;
1186 my $pkg = get_source_info($name);
1189 if (!defined($pkg)) {
1190 print "$name: not registered; can't set priority.\n";
1193 $state = $pkg->{'state'};
1195 if ($state eq "Not-For-Us") {
1196 print "$name: not suitable for this architecture. Skipping.\n";
1198 } elsif ($state eq "Failed-Removed") {
1199 print "$name: failed previously and doesn't need building. Skipping.\n";
1202 if (!pkg_version_eq($pkg, $version)) {
1203 print "$name: version mismatch ($pkg->{'version'} registered). ",
1207 if ( $build_priority == 0 ) {
1208 delete $pkg->{'buildpri'}
1209 if $key eq 'permbuildpri' and defined $pkg->{'buildpri'}
1210 and $pkg->{'buildpri'} == $pkg->{$key};
1211 delete $pkg->{$key};
1213 $pkg->{'buildpri'} = $build_priority
1214 if $key eq 'permbuildpri';
1215 $pkg->{$key} = $build_priority;
1217 update_source_info($pkg);
1218 print "$name: set to build priority $build_priority\n" if $verbose;
1221 sub add_one_depwait {
1223 my $version = shift;
1225 my $pkg = get_source_info($name);
1227 if (!defined($pkg)) {
1228 print "$name: not registered yet.\n";
1231 $state = $pkg->{'state'};
1233 if ($state eq "Dep-Wait") {
1234 print "$name: merging with previously registered dependencies\n";
1237 if (isin( $state, qw(Needs-Build Failed BD-Uninstallable))) {
1238 print "$name: Warning: not registered for building previously, ".
1239 "but processing anyway.\n";
1241 elsif ($state eq "Not-For-Us") {
1242 print "$name: not suitable for this architecture anyway. Skipping.\n";
1245 elsif ($state eq "Failed-Removed") {
1246 print "$name: failed previously and doesn't need building. Skipping.\n";
1249 elsif ($state eq "Installed") {
1250 print "$name: Is already installed in archive. Skipping.\n";
1253 elsif ($state eq "Uploaded") {
1254 print "$name: Is already uploaded. Skipping.\n";
1257 elsif ($pkg->{'builder'} &&
1258 $user ne $pkg->{'builder'}) {
1259 print "$name: not taken by you, but by ".
1260 "$pkg->{'builder'}. Skipping.\n";
1263 elsif ( !pkg_version_eq($pkg,$version)) {
1264 print "$name: version mismatch ".
1265 "($pkg->{'version'} ".
1266 "by $pkg->{'builder'})\n";
1269 elsif ($fail_reason =~ /^\s*$/ ||
1270 !parse_deplist( $fail_reason, 1 )) {
1271 print "$name: Bad dependency list\n";
1274 change_state( \$pkg, 'Dep-Wait' );
1275 $pkg->{'builder'} = $user;
1276 if (defined $pkg->{'permbuildpri'}) {
1277 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1279 delete $pkg->{'buildpri'};
1281 my $deplist = parse_deplist( $pkg->{'depends'} );
1282 my $new_deplist = parse_deplist( $fail_reason );
1283 # add new dependencies, maybe overwriting old entries
1284 foreach (keys %$new_deplist) {
1285 $deplist->{$_} = $new_deplist->{$_};
1287 $pkg->{'depends'} = build_deplist($deplist);
1288 log_ta( $pkg, "--dep-wait" );
1289 update_source_info($pkg);
1290 print "$name: registered as waiting for dependencies\n" if $verbose;
1293 sub set_one_update {
1295 my $version = shift;
1296 my $pkg = get_source_info($name);
1298 if (!defined($pkg)) {
1299 print "$name: not registered yet.\n";
1302 $pkg->{'version'} =~ s/\+b[0-9]+$//;
1304 log_ta( $pkg, "--update" );
1305 update_source_info($pkg);
1315 my $db = get_all_source_info();
1317 local($/) = ""; # read in paragraph mode
1319 my( $version, $arch, $section, $priority, $builddep, $buildconf, $binaries );
1321 /^Package:\s*(\S+)$/mi and $name = $1;
1322 /^Version:\s*(\S+)$/mi and $version = $1;
1323 /^Architecture:\s*(\S+)$/mi and $arch = $1;
1324 /^Section:\s*(\S+)$/mi and $section = $1;
1325 /^Priority:\s*(\S+)$/mi and $priority = $1;
1326 /^Build-Depends:\s*(.*)$/mi and $builddep = $1;
1327 /^Build-Conflicts:\s*(.*)$/mi and $buildconf = $1;
1328 /^Binary:\s*(.*)$/mi and $binaries = $1;
1330 next if (defined $srcver{$name} and version_less( $version, $srcver{$name} ));
1331 $srcver{$name} = $version;
1333 $pkgs{$name}{'ver'} = $version;
1334 $pkgs{$name}{'bin'} = $binaries;
1335 $pkgs{$name}{'dep'} = $builddep;
1336 $pkgs{$name}{'conf'} = $buildconf;
1337 my $pkg = $db->{$name};
1342 if ($arch eq "all" && !version_less( $version, $pkg->{'version'} )) {
1343 # package is now Arch: all, delete it from db
1344 change_state( \$pkg, 'deleted' );
1345 log_ta( $pkg, "--merge-sources" );
1346 print "$name ($pkg->{'version'}): deleted ".
1347 "from database, because now Arch: all\n"
1349 del_source_info($name);
1350 delete $db->{$name};
1354 # The "Version" should always be the source version --
1355 # not a possible binNMU version number.
1356 $pkg->{'version'} = $version, $change++
1357 if ($pkg->{'state'} eq 'Installed' and
1358 !version_eq( $pkg->{'version'}, $version));
1359 # Always update priority and section, if available
1360 $pkg->{'priority'} = $priority, $change++
1361 if defined $priority and (not defined($pkg->{'priority'}) or $pkg->{'priority'} ne $priority);
1363 $pkg->{'section'} = $section, $change++
1364 if defined $section and (not defined($pkg->{'section'}) or $pkg->{'section'} ne $section);
1366 update_source_info($pkg) if $change;
1369 # Now that we only have the latest source version, build the list
1370 # of binary packages from the Sources point of view
1371 foreach $name (keys %pkgs) {
1372 foreach my $bin (split( /\s*,\s*/, $pkgs{$name}{'bin'} ) ) {
1373 $merge_binsrc{$bin} = $name;
1376 # remove installed packages that no longer have source available
1377 # or binaries installed
1378 foreach $name (keys %$db) {
1379 next if $name =~ /^_/;
1380 my $pkg = $db->{$name};
1381 if (not defined($pkgs{$name})) {
1382 change_state( \$pkg, 'deleted' );
1383 log_ta( $pkg, "--merge-sources" );
1384 print "$name ($pkg->{'version'}): ".
1385 "deleted from database, because ".
1386 "not in Sources anymore\n"
1388 del_source_info($name);
1389 delete $db->{$name};
1391 next if !isin( $pkg->{'state'}, qw(Installed) );
1392 if ($full && not defined $merge_srcvers{$name}) {
1393 change_state( \$pkg, 'deleted' );
1394 log_ta( $pkg, "--merge-sources" );
1395 print "$name ($pkg->{'version'}): ".
1396 "deleted from database, because ".
1397 "binaries don't exist anymore\n"
1399 del_source_info($name);
1400 delete $db->{$name};
1401 } elsif ($full && version_less( $merge_srcvers{$name}, $pkg->{'version'})) {
1402 print "$name ($pkg->{'version'}): ".
1403 "package is Installed but binaries are from ".
1404 $merge_srcvers{$name}. "\n"
1412 # This function looks through a Packages file and sets the state of
1413 # packages to 'Installed'
1414 sub parse_packages {
1415 my $depwait_only = shift;
1418 my $pkgs = get_all_source_info();
1419 local($/) = ""; # read in paragraph mode
1421 my( $name, $version, $depends, $source, $sourcev, $architecture, $provides, $binaryv, $binnmu );
1423 /^Package:\s*(\S+)$/mi and $name = $1;
1424 /^Version:\s*(\S+)$/mi and $version = $1;
1425 /^Depends:\s*(.*)$/mi and $depends = $1;
1426 /^Source:\s*(\S+)(\s*\((\S+)\))?$/mi and ($source,$sourcev) = ($1, $3);
1427 /^Architecture:\s*(\S+)$/mi and $architecture = $1;
1428 /^Provides:\s*(.*)$/mi and $provides = $1;
1429 next if !$name || !$version;
1430 next if ($arch ne $architecture and $architecture ne "all");
1431 next if (defined ($installed->{$name}) and $installed->{$name}{'version'} ne "" and
1432 version_lesseq( $version, $installed->{$name}{'version'} ));
1433 $installed->{$name}{'version'} = $version;
1434 next if $depwait_only;
1435 $installed->{$name}{'depends'} = $depends;
1436 $installed->{$name}{'all'} = 1 if $architecture eq "all";
1437 undef $installed->{$name}{'Provider'};
1438 $installed->{$name}{'Source'} = $source ? $source : $name;
1440 foreach (split( /\s*,\s*/, $provides )) {
1441 if (not defined ($installed->{$_})) {
1442 $installed->{$_}{'version'} = "";
1443 $installed->{$_}{'Provider'} = $name;
1447 if ( $version =~ /\+b(\d+)$/ ) {
1450 $version = $sourcev if $sourcev;
1451 $binaryv = $version;
1452 $binaryv =~ s/\+b\d+$//;
1453 $installed->{$name}{'Sourcev'} = $sourcev ? $sourcev : $binaryv;
1454 $binaryv .= "+b$binnmu" if defined($binnmu);
1456 next if $architecture ne $arch;
1457 $name = $source if $source;
1458 next if defined($merge_srcvers{$name}) and $merge_srcvers{$name} eq $version;
1459 $merge_srcvers{$name} = $version;
1461 my $pkg = $pkgs->{$name};
1464 if (isin( $pkg->{'state'}, qw(Not-For-Us)) ||
1465 (isin($pkg->{'state'}, qw(Installed)) &&
1466 version_lesseq($binaryv, $pkg->{'installed_version'}))) {
1467 print "Skipping $name because State == $pkg->{'state'}\n"
1471 if ($pkg->{'binary_nmu_version'} ) {
1472 my $nmuver = binNMU_version($pkg->{'version'}, $pkg->{'binary_nmu_version'});
1473 if (version_less( $binaryv, $nmuver )) {
1474 print "Skipping $name ($version) because have newer ".
1475 "version ($nmuver) in db.\n"
1479 } elsif (version_less($version, $pkg->{'version'})) {
1480 print "Skipping $name ($version) because have newer ".
1481 "version ($pkg->{'version'}) in db.\n"
1486 if (!pkg_version_eq($pkg, $version) &&
1487 $pkg->{'state'} ne "Installed") {
1488 warn "Warning: $name: newer version than expected appeared ".
1489 "in archive ($version vs. $pkg->{'version'})\n";
1490 delete $pkg->{'builder'};
1493 if (!isin( $pkg->{'state'}, qw(Uploaded) )) {
1494 warn "Warning: Package $name was not in uploaded state ".
1495 "before (but in '$pkg->{'state'}').\n";
1496 delete $pkg->{'builder'};
1497 delete $pkg->{'depends'};
1501 $pkg->{'version'} = $version;
1504 change_state( \$pkg, 'Installed' );
1505 $pkg->{'package'} = $name;
1506 $pkg->{'installed_version'} = $binaryv;
1507 if (defined $pkg->{'permbuildpri'}) {
1508 $pkg->{'buildpri'} = $pkg->{'permbuildpri'};
1510 delete $pkg->{'buildpri'};
1512 $pkg->{'version'} = $version
1513 if version_less( $pkg->{'version'}, $version);
1514 delete $pkg->{'binary_nmu_version'};
1515 delete $pkg->{'binary_nmu_changelog'};
1516 log_ta( $pkg, "--merge-packages" );
1517 update_source_info($pkg);
1518 print "$name ($version) is up-to-date now.\n" if $verbose;
1521 check_dep_wait( "--merge-packages", $installed );
1526 my ($package, $name, $version, $installed);
1528 foreach $package (@_) {
1529 $package =~ s,^.*/,,; # strip path
1530 $package =~ s/\.(dsc|diff\.gz|tar\.gz|deb)$//; # strip extension
1531 $package =~ s/_[\w\d]+\.changes$//; # strip extension
1532 if ($package =~ /^([\w\d.+-]+)_([\w\d:.+~-]+)/) {
1533 ($name,$version) = ($1,$2);
1536 warn "$package: can't extract package name and version ".
1540 $installed->{$name}{'version'} = $version;
1543 check_dep_wait( "--pretend-avail", $installed );
1546 sub check_dep_wait {
1548 my $installed = shift;
1550 # check all packages in state Dep-Wait if dependencies are all
1553 my $db = get_all_source_info();
1554 foreach $name (keys %$db) {
1555 next if $name =~ /^_/;
1556 my $pkg = $db->{$name};
1557 next if $pkg->{'state'} ne "Dep-Wait";
1558 my $deps = $pkg->{'depends'};
1560 print "$name: was in state Dep-Wait, but with empty ",
1562 goto make_needs_build;
1564 my $deplist = parse_deplist($deps);
1568 foreach (keys %$deplist) {
1569 if (!exists $installed->{$_} ||
1570 ($deplist->{$_}->{'rel'} && $deplist->{$_}->{'version'} &&
1571 !version_compare( $installed->{$_}{'version'},
1572 $deplist->{$_}->{'rel'},
1573 $deplist->{$_}->{'version'}))) {
1575 $new_deplist->{$_} = $deplist->{$_};
1578 push( @removed_deps, $_ );
1583 change_state( \$pkg, 'Needs-Build' );
1584 log_ta( $pkg, $action );
1585 delete $pkg->{'builder'};
1586 delete $pkg->{'depends'};
1587 print "$name ($pkg->{'version'}) has all ",
1588 "dependencies available now\n" if $verbose;
1590 update_source_info($pkg);
1592 elsif (@removed_deps) {
1593 $pkg->{'depends'} = build_deplist( $new_deplist );
1594 print "$name ($pkg->{'version'}): some dependencies ",
1595 "(@removed_deps) available now, but not all yet\n"
1597 update_source_info($pkg);
1602 # This function accepts quinn-diff output (either from a file named on
1603 # the command line, or on stdin) and sets the packages named there to
1604 # state 'Needs-Build'.
1605 sub parse_quinn_diff {
1606 my $partial = shift;
1610 my $pkgs = get_all_source_info();
1614 next if !m,^([-\w\d/]*)/ # section
1615 ([-\w\d.+]+)_ # package name
1616 ([\w\d:.~+-]+)\.dsc\s* # version
1617 \[([^:]*): # priority
1618 ([^]]+)\]\s*$,x; # rest of notes
1619 my($section,$name,$version,$priority,$notes) = ($1, $2, $3, $4, $5);
1620 $quinn_pkgs{$name}++;
1621 $section ||= "unknown";
1622 $priority ||= "unknown";
1623 $priority = "unknown" if $priority eq "-";
1624 $priority = "standard" if ($name eq "debian-installer");
1626 my $pkg = $pkgs->{$name};
1628 # Always update section and priority.
1629 if (defined($pkg)) {
1631 $pkg->{'section'} = $section, $change++ if not defined
1632 $pkg->{'section'} or $section ne "unknown";
1633 $pkg->{'priority'} = $priority, $change++ if not defined
1634 $pkg->{'priority'} or $priority ne "unknown";
1637 if (defined($pkg) &&
1638 $pkg->{'state'} =~ /^Dep-Wait/ &&
1639 version_less( $pkg->{'version'}, $version )) {
1640 change_state( \$pkg, 'Dep-Wait' );
1641 $pkg->{'version'} = $version;
1642 delete $pkg->{'binary_nmu_version'};
1643 delete $pkg->{'binary_nmu_changelog'};
1644 log_ta( $pkg, "--merge-quinn" );
1646 print "$name ($version) still waiting for dependencies.\n"
1649 elsif (defined($pkg) &&
1650 $pkg->{'state'} =~ /-Removed$/ &&
1651 version_eq($pkg->{'version'}, $version)) {
1652 # reinstantiate a package that has been removed earlier
1653 # (probably due to a quinn-diff malfunction...)
1654 my $newstate = $pkg->{'state'};
1655 $newstate =~ s/-Removed$//;
1656 change_state( \$pkg, $newstate );
1657 $pkg->{'version'} = $version;
1658 $pkg->{'notes'} = $notes;
1659 log_ta( $pkg, "--merge-quinn" );
1661 print "$name ($version) reinstantiated to $newstate.\n"
1664 elsif (defined($pkg) &&
1665 $pkg->{'state'} eq "Not-For-Us" &&
1666 version_less( $pkg->{'version'}, $version )) {
1667 # for Not-For-Us packages just update the version etc., but
1669 change_state( \$pkg, "Not-For-Us" );
1670 $pkg->{'package'} = $name;
1671 $pkg->{'version'} = $version;
1672 $pkg->{'notes'} = $notes;
1673 delete $pkg->{'builder'};
1674 log_ta( $pkg, "--merge-quinn" );
1676 print "$name ($version) still Not-For-Us.\n" if $verbose;
1678 elsif (!defined($pkg) ||
1679 $pkg->{'state'} ne "Not-For-Us" &&
1680 (version_less( $pkg->{'version'}, $version ) ||
1681 ($pkg->{'state'} eq "Installed" && version_less($pkg->{'installed_version'}, $version)))) {
1683 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
1684 send_mail( $pkg->{'builder'},
1685 "new version of $name (dist=$distribution)",
1686 "As far as I'm informed, you're currently ".
1687 "building the package $name\n".
1688 "in version $pkg->{'version'}.\n\n".
1689 "Now there's a new source version $version. ".
1690 "If you haven't finished\n".
1691 "compiling $name yet, you can stop it to ".
1692 "save some work.\n".
1693 "Just to inform you...\n".
1694 "(This is an automated message)\n" );
1695 print "$name: new version ($version) while building ".
1696 "$pkg->{'version'} -- sending mail ".
1697 "to builder ($pkg->{'builder'})\n"
1700 change_state( \$pkg, 'Needs-Build' );
1701 $pkg->{'package'} = $name;
1702 $pkg->{'version'} = $version;
1703 $pkg->{'section'} = $section;
1704 $pkg->{'priority'} = $priority;
1705 $pkg->{'notes'} = $notes;
1706 delete $pkg->{'builder'};
1707 delete $pkg->{'binary_nmu_version'};
1708 delete $pkg->{'binary_nmu_changelog'};
1709 log_ta( $pkg, "--merge-quinn" );
1712 print "$name ($version) needs rebuilding now.\n" if $verbose;
1714 elsif (defined($pkg) &&
1715 !version_eq( $pkg->{'version'}, $version ) &&
1716 isin( $pkg->{'state'}, qw(Installed Not-For-Us) )) {
1717 print "$name: skipping because version in db ".
1718 "($pkg->{'version'}) is >> than ".
1719 "what quinn-diff says ($version) ".
1720 "(state is $pkg->{'state'})\n"
1722 $dubious .= "$pkg->{'state'}: ".
1723 "db ${name}_$pkg->{'version'} >> ".
1724 "quinn $version\n" if !$partial;
1726 elsif ($verbose >= 2) {
1727 if ($pkg->{'state'} eq "Not-For-Us") {
1728 print "Skipping $name because State == ".
1729 "$pkg->{'state'}\n";
1731 elsif (!version_less($pkg->{'version'}, $version)) {
1732 print "Skipping $name because version in db ".
1733 "($pkg->{'version'}) is >= than ".
1734 "what quinn-diff says ($version)\n";
1737 update_source_info($pkg) if $change;
1741 send_mail( $conf::db_maint,
1742 "Dubious versions in " . table_name() . " "
1743 . $distribution . " table",
1744 "The following packages have a newer version in the ".
1745 "wanna-build database\n".
1746 "than what quinn-diff says, and this is strange for ".
1748 "It could be caused by a lame mirror, or the version ".
1749 "in the database\n".
1754 # Now re-check the DB for packages in states Needs-Build, Failed,
1755 # Dep-Wait or BD-Uninstallable and remove them if they're not listed
1756 # anymore by quinn-diff.
1759 my $db = get_all_source_info();
1760 foreach $name (keys %$db) {
1761 next if $name =~ /^_/;
1762 my $pkg = $db->{$name};
1763 next if defined $pkg->{'binary_nmu_version'};
1764 next if !isin( $pkg->{'state'},
1765 qw(Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait BD-Uninstallable) );
1766 my $virtual_delete = $pkg->{'state'} eq 'Failed';
1768 if (!$quinn_pkgs{$name}) {
1769 change_state( \$pkg, $virtual_delete ?
1770 $pkg->{'state'}."-Removed" :
1772 log_ta( $pkg, "--merge-quinn" );
1773 print "$name ($pkg->{'version'}): ".
1774 ($virtual_delete ? "(virtually) " : "") . "deleted ".
1775 "from database, because not in quinn-diff anymore\n"
1777 if ($virtual_delete) {
1778 update_source_info($pkg);
1780 del_source_info($name);
1788 # for sorting priorities and sections
1790 %prioval = ( required => -5,
1798 'debian-installer' => -199,
1819 localizations => -178,
1820 interpreters => -177,
1845 electronics => -152,
1851 foreach my $i (keys %sectval) {
1852 $sectval{"contrib/$i"} = $sectval{$i}+40;
1853 $sectval{"non-free/$i"} = $sectval{$i}+80;
1855 $sectval{'unknown'} = -165;
1857 %catval = ( "none" => -20,
1858 "uploaded-fixed-pkg" => -19,
1859 "fix-expected" => -18,
1860 "reminder-sent" => -17,
1861 "nmu-offered" => -16,
1865 "compiler-error" => -12 );
1868 sub sort_list_func {
1870 'C' => ['<=>', sub { return (-1) * $_[0]->{'calprio'}; }],
1871 'W' => ['<=>', sub { return (-1) * $_[0]->{'state_days'}; }],
1872 'P' => ['<=>', sub { return (-1) * $_[0]->{'buildpri'}; }],
1873 'p' => ['<=>', sub { return $prioval{$_[0]->{'priority'}}; }],
1874 's' => ['<=>', sub { return $sectval{$_[0]->{'section'}}; }],
1875 'n' => ['cmp', sub { return $_[0]->{'package'}; }],
1876 'b' => ['cmp', sub { return $_[0]->{'builder'}; }],
1877 'c' => ['<=>', sub { return ($_[0]->{'notes'} =~ /^(out-of-date|partial)/) ? 0: ($_[0]->{'notes'} =~ /^uncompiled/) ? 2 : 1; }],
1878 'f' => ['<=>', sub { return $catval{ $_[0]->{'failed_category'} ? $_[0]->{'failed_category'}: "none" }; }],
1879 'S' => ['<=>', sub { return $prioval{$_[0]->{'priority'}} > $prioval{'standard'}; }],
1882 foreach my $letter (split( //, $list_order )) {
1884 $r = &{$map_funcs->{$letter}[1]}($a) <=> &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq '<=>';
1885 $r = &{$map_funcs->{$letter}[1]}($a) cmp &{$map_funcs->{$letter}[1]}($b) if $map_funcs->{$letter}[0] eq 'cmp';
1886 return $r if $r != 0;
1891 sub calculate_prio {
1892 my $priomap = $yamlmap->{priority};
1894 my @s=split("/", $pkg->{'section'});
1895 $pkg->{'component'} = $s[0] if $s[1];
1896 $pkg->{'component'} ||= 'main';
1897 $pkg->{'calprio'} = 0;
1898 foreach my $k (keys %{$priomap->{keys}}) {
1899 $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
1902 my $days = $pkg->{'state_days'};
1903 $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
1904 $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
1905 my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
1906 $pkg->{'calprio'} += $days * $scale;
1908 $pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
1909 $pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
1917 return "" unless $t;
1919 my $min = int($t/60) % 60;
1920 my $hours = int($t / 3600);
1921 return sprintf("%d:%02d:%02d", $hours, $min, $sec) if $hours;
1922 return sprintf("%d:%02d", $min, $sec);
1929 if (ref($_[0]) eq 'CODE') {
1939 return $r unless $t;
1943 if (substr($t,0,1) eq '!') {
1947 return "" unless $r;
1950 return print_format($t, $pkg, $var);
1954 sub make_fmt { my $c = shift; my $pkg = shift; my $var = shift; return sub { use_fmt($c, $_[0], $pkg, $var); } };
1957 my $printfmt = shift;
1961 Within an format string, the following values are allowed (need to be preceded by %).
1962 This can be combined to e.g.
1963 wanna-build --format='wanna-build -A %a --give-back %p_%v' -A mipsel --list=failed
1966 c section (e.g. libs or utils)
1967 D in case of BD-Uninstallable the reason for the uninstallability
1969 E in case of Dep-Wait the packages being waited on, in case of Needs-Build the number in the queue
1970 F in case of Failed the fail reason
1972 o time of last successful build (seconds)
1973 O time of last successful build (formated)
1976 q time of last build (seconds)
1977 Q time of last build (formated)
1978 r max time of last (successful) build (seconds)
1979 R max time of last (successful) build (formated)
1981 s Time in this state in full seconds since epoch
1982 t time of state change
1983 T time since state change
1984 u Builder (e.g. buildd_mipsel-rem)
1986 V full Package version (i.e. with +b.., = %v%{+b}B%B
1987 X the string normally between [], e.g. optional:out-of-date:calprio{61}:days{25}
1989 %{Text}? print Text in case ? is not empty; ? is never printed
1990 %{!Text}? print Text in case ? is empty; ? is never printed
1991 Text could contain further %. To start with !, use %!
1994 return stringf($printfmt, (
1995 'p' => make_fmt( $pkg->{'package'}, $pkg, $var),
1996 'a' => make_fmt( $arch, $pkg, $var),
1997 's' => make_fmt( sub { return floor(str2time($pkg->{'state_change'})); }, $pkg, $var),
1998 'v' => make_fmt( $pkg->{'version'}, $pkg, $var),
1999 'V' => make_fmt( sub { $pkg->{'binary_nmu_version'} ? $pkg->{'version'}."+b".$pkg->{'binary_nmu_version'} : $pkg->{'version'} }, $pkg, $var),
2000 'S' => make_fmt( $pkg->{'state'}, $pkg, $var),
2001 'u' => make_fmt( $pkg->{'builder'}, $pkg, $var),
2002 'X' => make_fmt( sub {
2003 my $c = "$pkg->{'priority'}:$pkg->{'notes'}";
2004 $c .= ":PREV-FAILED" if $pkg->{'previous_state'} =~ /^Failed/;
2005 $c .= ":bp{" . $pkg->{'buildpri'} . "}" if defined $pkg->{'buildpri'};
2006 $c .= ":binNMU{" . $pkg->{'binary_nmu_version'} . "}" if defined $pkg->{'binary_nmu_version'};
2007 $c .= ":calprio{". $pkg->{'calprio'}."}";
2008 $c .= ":days{". $pkg->{'state_days'}."}";
2011 'c' => make_fmt( $pkg->{'section'}, $pkg, $var),
2012 'P' => make_fmt( $pkg->{'previous_state'} || "unknwon", $pkg, $var),
2013 'E' => make_fmt( sub { return $pkg->{'depends'} if $pkg->{'state'} eq "Dep-Wait";
2014 return $var->{scnt}{'Needs-Build'} + 1 if $pkg->{'state'} eq 'Needs-Build';
2015 return ""; }, $pkg, $var),
2016 'F' => make_fmt( sub { return "" unless $pkg->{'failed'};
2017 my $failed = $pkg->{'failed'};
2018 $failed =~ s/\\/\\\\/g;
2019 return $pkg->{'package'}."#".$arch."-failure\n ".
2020 join("\\0a",split("\n",$failed))."\\0a\n"; }, $pkg, $var),
2021 'D' => make_fmt( sub { return "" unless $pkg->{'bd_problem'};
2022 return $pkg->{'package'}."#".$arch."-bd-problem\n".
2023 join("\\0a",split("\n",$pkg->{'bd_problem'}))."\\0a\n"; }, $pkg, $var),
2024 'B' => make_fmt( sub { return $pkg->{'binary_nmu_version'} if defined $pkg->{'binary_nmu_version'}; }, $pkg, $var),
2025 'd' => make_fmt( $pkg->{'distribution'}, $pkg, $var),
2026 't' => make_fmt( $pkg->{'state_change'}, $pkg, $var),
2027 'T' => make_fmt( sub { return seconds2time(time() - floor(str2time($pkg->{'state_change'}))); }, $pkg, $var),
2028 'o' => make_fmt( $pkg->{'successtime'}, $pkg, $var),
2029 'O' => make_fmt( sub { return seconds2time ( $pkg->{'successtime'}); }, $pkg, $var),
2030 'q' => make_fmt( $pkg->{'anytime'}, $pkg, $var),
2031 'Q' => make_fmt( sub { return seconds2time ( $pkg->{'anytime'}); }, $pkg, $var),
2032 'r' => make_fmt( sub { return max($pkg->{'successtime'}, $pkg->{'anytime'}); }, $pkg, $var),
2033 'R' => make_fmt( sub { return seconds2time ( max($pkg->{'successtime'}, $pkg->{'anytime'})); }, $pkg, $var),
2039 my( $name, $pkg, @list );
2044 my $db = get_all_source_info(state => $state, user => $user, category => $category, list_min_age => $list_min_age);
2045 foreach $name (keys %$db) {
2046 next if $name =~ /^_/;
2047 push @list, calculate_prio($db->{$name});
2051 @list = grep { my $i = $_->{'component'}; grep { $i eq $_ } split /[, ]+/, $yamlmap->{"restrict"}{'component'} } @list;
2052 # extra depends / conflicts only from api 1 on
2053 @list = grep { !$_->{'extra_depends'} and !$_->{'extra_conflicts'} } @list if $api < 1 ;
2055 # first adjust ownprintformat, then set printformat accordingly
2056 $printformat ||= $yamlmap->{"format"}{$ownprintformat};
2057 $printformat ||= $yamlmap->{"format"}{"default"}{$state};
2058 $printformat ||= $yamlmap->{"format"}{"default"}{"default"};
2059 undef $printformat if ($ownprintformat eq 'none');
2061 foreach $pkg (sort sort_list_func @list) {
2063 print print_format($printformat, $pkg, {'cnt' => $cnt, 'scnt' => \%scnt})."\n";
2065 $scnt{$pkg->{'state'}}++;
2068 print print_format("%c/%p_%v", $pkg, {});
2069 print print_format(": %S", $pkg, {})
2071 print print_format("%{ by }u%u", $pkg, {})
2072 if $pkg->{'state'} ne "Needs-Build";
2073 print print_format(" [%X]\n", $pkg, {});
2074 print " Reasons for failing:\n",
2076 defined $pkg->{'failed_category'} ? $pkg->{'failed_category'} : "none",
2078 join("\n ",split("\n",$pkg->{'failed'})), "\n"
2079 if $pkg->{'state'} =~ /^Failed/;
2080 print " Dependencies: $pkg->{'depends'}\n"
2081 if $pkg->{'state'} eq "Dep-Wait";
2082 print " Reasons for BD-Uninstallable:\n ",
2083 join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
2084 if $pkg->{'state'} eq "BD-Uninstallable";
2085 print " Previous state was $pkg->{'previous_state'}\n"
2086 if $verbose && $pkg->{'previous_state'};
2087 print " No previous state recorded\n"
2088 if $verbose && !$pkg->{'previous_state'};
2089 print " State changed at $pkg->{'state_change'}\n"
2090 if $verbose && $pkg->{'state_change'};
2091 print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
2092 if $verbose && $pkg->{'previous_state'};
2093 print " Previous failing reasons:\n ",
2094 join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
2095 if $verbose && $pkg->{'old_failed'};
2097 $scnt{$pkg->{'state'}}++ if $state eq "all";
2099 if ($state eq "all" && !$printformat) {
2100 foreach (sort keys %scnt) {
2101 print "Total $scnt{$_} package(s) in state $_.\n";
2104 print "Total $cnt package(s)\n" unless $printformat;
2109 my( $name, $pkg, $key, $dist );
2110 my @firstkeys = qw(package version builder state section priority
2111 installed_version previous_state state_change);
2112 my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
2113 my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
2114 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
2115 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
2116 'state_change' => 'State-Change',
2117 'bd_problem' => 'BD-Problem',
2118 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
2119 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
2120 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
2121 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
2122 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
2123 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days',
2124 'successtime' => 'Success-build-time',
2125 'anytime' => 'Build-time',
2126 'extra_depends' => 'Extra-Dependencies',
2127 'extra_conflicts' => 'Extra-Conflicts',
2130 foreach $name (@_) {
2131 $name =~ s/_.*$//; # strip version
2132 foreach $dist (@dists) {
2133 my $pname = "$name" . ($info_all_dists ? "($dist)" : "");
2135 $pkg = get_readonly_source_info($name);
2136 if (!defined( $pkg )) {
2137 print "$pname: not registered\n";
2140 $pkg = calculate_prio($pkg);
2143 foreach $key (@firstkeys) {
2144 next if !defined $pkg->{$key};
2145 my $val = $pkg->{$key};
2147 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2149 my $print_key = $key;
2150 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2151 printf " %-20s: %s\n", $print_key, $val;
2153 foreach $key (sort keys %$pkg) {
2154 next if isin( $key, @firstkeys );
2155 my $val = $pkg->{$key};
2156 next if !defined($val);
2158 $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
2160 my $print_key = $key;
2161 $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
2162 printf " %-20s: %s\n", $print_key, $val;
2168 sub forget_packages {
2169 my( $name, $pkg, $key, $data );
2171 foreach $name (@_) {
2172 $name =~ s/_.*$//; # strip version
2173 $pkg = get_source_info($name);
2174 if (!defined( $pkg )) {
2175 print "$name: not registered\n";
2180 foreach $key (sort keys %$pkg) {
2181 my $val = $pkg->{$key};
2184 $data .= sprintf " %-20s: %s\n", $key, $val;
2186 send_mail( $conf::db_maint,
2187 "$name deleted from DB " . table_name() . " " . $distribution,
2188 "The package '$name' has been deleted from the database ".
2190 "Data registered about the deleted package:\n".
2191 "$data\n" ) if $conf::db_maint;
2192 change_state( \$pkg, 'deleted' );
2193 log_ta( $pkg, "--forget" );
2194 del_source_info($name);
2195 print "$name: deleted from database\n" if $verbose;
2200 $dbh->do("DELETE from " . user_table_name() .
2201 " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
2207 print "Reading ASCII database from $file..." if $verbose >= 1;
2208 open( F, "<$file" ) or
2209 die "Can't open database $file: $!\n";
2211 local($/) = ""; # read in paragraph mode
2213 my( %thispkg, $name );
2215 s/\n[ \t]+/\376\377/g; # fix continuation lines
2216 s/\376\377\s*\376\377/\376\377/og;
2218 while( /^(\S+):[ \t]*(.*)[ \t]*$/mg ) {
2219 my ($key, $val) = ($1, $2);
2221 $key =~ tr/A-Z/a-z/;
2222 $val =~ s/\376\377/\n/g;
2223 $thispkg{$key} = $val;
2225 check_entry( \%thispkg );
2227 if (exists($thispkg{'package'})) {
2228 update_source_info(\%thispkg);
2230 elsif(exists($thispkg{'user'})) {
2231 # user in import, username in database.
2232 $dbh->do('INSERT INTO ' . user_table_name() .
2233 ' (username, distribution, last_seen)' .
2234 ' values (?, ?, ?)',
2235 undef, $thispkg{'user'}, $distribution,
2236 $thispkg{'last_seen'})
2237 or die $dbh->errstr;
2241 print "done\n" if $verbose >= 1;
2248 return if $op_mode eq "manual-edit"; # no checks then
2250 # check for required fields
2251 if (exists $pkg->{'user'}) {
2254 if (!exists $pkg->{'package'}) {
2255 print STDERR "Bad entry: ",
2256 join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
2257 die "Database entry lacks package or username field\n";
2259 # if no State: field, generate one (for old db compat)
2260 if (!exists($pkg->{'state'})) {
2262 exists $pkg->{'failed'} ? 'Failed' : 'Building';
2264 if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
2265 die "Database entry for $pkg->{'package'} lacks Version: field\n";
2268 die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
2269 if !isin( $pkg->{'state'},
2270 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
2271 Failed Failed-Removed Not-For-Us BD-Uninstallable
2277 my($name,$pkg,$key);
2279 print "Writing ASCII database to $file..." if $verbose >= 1;
2280 open( F, ">$file" ) or
2281 die "Can't open export $file: $!\n";
2283 my $db = get_all_source_info();
2284 foreach $name (keys %$db) {
2285 next if $name =~ /^_/;
2286 my $pkg = $db->{$name};
2287 foreach $key (keys %{$pkg}) {
2288 my $val = $pkg->{$key};
2289 next if !defined($val);
2292 $val =~ s/^ +$/ ./mg;
2293 print F "$key: $val\n";
2298 print "done\n" if $verbose >= 1;
2304 my $newstate = shift;
2305 my $state = \$pkg->{'state'};
2307 return if defined($$state) and $$state eq $newstate;
2308 $pkg->{'previous_state'} = $$state if defined($$state);
2309 $pkg->{'state_change'} = $curr_date;
2310 $pkg->{'do_state_change'} = 1;
2312 if (defined($$state) and $$state eq 'Failed') {
2313 $pkg->{'old_failed'} =
2314 "-"x20 . " $pkg->{'version'} " . "-"x20 . "\n" .
2315 $pkg->{'failed'} . "\n" .
2316 $pkg->{'old_failed'};
2317 delete $pkg->{'failed'};
2318 delete $pkg->{'failed_category'};
2320 if (defined($$state) and $$state eq 'BD-Uninstallable') {
2321 delete $pkg->{'bd_problem'};
2323 $$state = $newstate;
2329 my $dist = $distribution;
2333 $prevstate = $pkg->{'previous_state'};
2334 $str = "$action($dist): $pkg->{'package'}_$pkg->{'version'} ".
2335 "changed from $prevstate to $pkg->{'state'} ".
2336 "by $real_user as $user";
2339 printf "update transactions: %s %s %s %s %s %s %s %s\n",
2340 $pkg->{'package'}, $distribution,
2341 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2345 $dbh->do('INSERT INTO ' . transactions_table_name() .
2346 ' (package, distribution, version, action, ' .
2347 ' prevstate, state, real_user, set_user, time) ' .
2348 ' values (?, ?, ?, ?, ?, ?, ?, ?, ?)',
2349 undef, $pkg->{'package'}, $distribution,
2350 $pkg->{'version'}, $action, $prevstate, $pkg->{'state'},
2351 $real_user, $user, 'now()') or die $dbh->errstr;
2353 if (!($prevstate eq 'Failed' && $pkg->{'state'} eq 'Failed')) {
2354 $str .= " (with --override)"
2356 $mail_logs .= "$str\n";
2363 my $subject = shift;
2366 my $from = $conf::db_maint;
2367 my $domain = $conf::buildd_domain;
2369 $from .= "\@$domain" if $from !~ /\@/;
2371 $to .= '@' . $domain if $to !~ /\@/;
2372 $text =~ s/^\.$/../mg;
2373 local $SIG{'PIPE'} = 'IGNORE';
2374 open( PIPE, "| $conf::mailprog -oem $to" )
2375 or die "Can't open pipe to $conf::mailprog: $!\n";
2377 print PIPE "From: $from\n";
2378 print PIPE "Subject: $subject\n\n";
2379 print PIPE "$text\n";
2383 # for parsing input to dep-wait
2389 foreach (split( /\s*,\s*/, $deps )) {
2391 # verification requires > starting prompts, no | crap
2392 if (!/^(\S+)\s*(\(\s*(>(?:[>=])?)\s*(\S+)\s*\))?\s*$/) {
2397 my @alts = split( /\s*\|\s*/, $_ );
2398 # Anything with an | is ignored, as it can be configured on a
2399 # per-buildd basis what will be installed
2400 next if $#alts != 0;
2403 if (!/^(\S+)\s*(\(\s*(>=|=|==|>|>>|<<|<=)\s*(\S+)\s*\))?\s*$/) {
2404 warn( "parse_deplist: bad dependency $_\n" );
2407 my($dep, $rel, $relv) = ($1, $3, $4);
2408 $rel = ">>" if defined($rel) and $rel eq ">";
2409 $result{$dep}->{'package'} = $dep;
2410 if ($rel && $relv) {
2411 $result{$dep}->{'rel'} = $rel;
2412 $result{$dep}->{'version'} = $relv;
2415 return 1 if $verify;
2423 foreach $key (keys %$list) {
2424 $result .= ", " if $result;
2426 $result .= " ($list->{$key}->{'rel'} $list->{$key}->{'version'})"
2427 if $list->{$key}->{'rel'} && $list->{$key}->{'version'};
2434 my ($gapkglong, $gaarch) = @_;
2435 my ($gapkg, $gaarchs) = split(/ \[/, $gapkglong);
2438 chop($gaarchs); # take away the ]
2439 my @gaarches = split(/ /, $gaarchs);
2440 if (substr($gaarches[0], 0, 1) eq '!') {
2441 return 0 if grep /^!$gaarch$/, @gaarches;
2442 } else { # positive case
2443 return 0 unless grep /^$gaarch$/, @gaarches;
2450 return join(', ', grep { &greparch($_, $faarch) } split(/, ?/, $_[0]));
2453 sub wb_edos_builddebcheck {
2454 # Copyright (C) 2008 Ralf Treinen <treinen@debian.org>
2455 # This program is free software: you can redistribute it and/or modify it under
2456 # the terms of the GNU General Public License as published by the Free Software
2457 # Foundation, version 2 of the License.
2458 # integrated into wanna-builds code by Andreas Barth 2010
2461 my $sourceprefix="source---";
2462 my $architecture=$args->{'arch'};
2463 my $edosoptions = "-failures -explain -quiet";
2464 my $packagefiles = $args->{'pkgs'};
2465 my $sourcesfile = $args->{'src'};
2468 foreach my $packagefile (@$packagefiles) {
2469 open(P,$packagefile);
2471 next unless /^Architecture/;
2472 next if /^Architecture:\s*all/;
2473 /Architecture:\s*([^\s]*)/;
2474 if ($packagearch eq "") {
2476 } elsif ( $packagearch ne $1) {
2477 return "Package file contains different architectures: $packagearch, $1";
2483 if ( $architecture eq "" ) {
2484 if ( $packagearch eq "" ) {
2485 return "No architecture option given, " .
2486 "and no non-all architecture found in the Packages file";
2488 $architecture = $packagearch;
2491 if ( $packagearch ne "" & $architecture ne $packagearch) {
2492 return "Architecture option is $architecture ".
2493 "but the package file contains architecture $packagearch";
2497 print "calling: edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles)."\n";
2499 "edos-debcheck $edosoptions < $sourcesfile ".join('', map {" '-base FILE' ".$_ } @$packagefiles));
2506 # source---pulseaudio (= 0.9.15-4.1~bpo50+1): FAILED
2507 # source---pulseaudio (= 0.9.15-4.1~bpo50+1) depends on missing:
2508 # - libltdl-dev (>= 2.2.6a-2)
2509 # source---libcanberra (= 0.22-1~bpo50+1): FAILED
2510 # source---libcanberra (= 0.22-1~bpo50+1) depends on missing:
2512 # - libltdl7-dev (>= 2.2.6)
2515 s/^(\s*)$sourceprefix(.*)depends on/$1$2build-depends on/o;
2516 s/^(\s*)$sourceprefix(.*) and (.*) conflict/$1$2 build-conflicts with $3/o;
2519 if (/^$sourceprefix(.*) \(.*\): FAILED/o) {
2520 $result->{$binpkg} = $explanation if $binpkg;
2523 } elsif (/^(depwait---.*) \(.*\): FAILED/o) {
2524 $result->{$binpkg} = $explanation if $binpkg;
2527 } else { # else something broken is happening
2528 #print "ignoring $_\n";
2535 $result->{$binpkg} = $explanation if $binpkg;
2541 sub call_edos_depcheck {
2542 return if $simulate_edos;
2544 my $srcs = $args->{'srcs'};
2547 return if defined ($conf::distributions{$distribution}{noadw}) && not defined $args->{'depwait'};
2549 # We need to check all of needs-build, as any new upload could make
2550 # something in needs-build have uninstallable deps
2551 # We also check everything in bd-uninstallable, as any new upload could
2552 # make that work again
2553 my (%interesting_packages, %interesting_packages_depwait);
2554 my $db = get_all_source_info();
2555 foreach $key (keys %$db) {
2556 my $pkg = $db->{$key};
2557 if (defined $pkg and isin($pkg->{'state'}, qw/Needs-Build BD-Uninstallable/) and not defined ($conf::distributions{$distribution}{noadw})) {
2558 $interesting_packages{$key} = undef;
2560 if (defined $pkg and isin($pkg->{'state'}, qw/Dep-Wait/) and defined $args->{'depwait'}) {
2561 $interesting_packages_depwait{$key} = undef;
2562 # we always check for BD-Uninstallability in depwait - could be that depwait is satisfied but package is uninstallable
2563 $interesting_packages{$key} = undef unless defined ($conf::distributions{$distribution}{noadw});
2567 #print "I would look at these sources with edos-depcheck:\n";
2568 #print join " ", keys %interesting_packages,"\n";
2569 return unless %interesting_packages || %interesting_packages_depwait;
2571 my $tmpfile_pattern = "/tmp/wanna-build-interesting-sources-$distribution.$$-XXXXX";
2572 use File::Temp qw/ tempfile /;
2573 my ($SOURCES, $tmpfile) = tempfile( $tmpfile_pattern, UNLINK => 1 );
2574 for my $key (keys %interesting_packages) {
2575 my $pkg = $db->{$key};
2576 # we print the source files as binary ones (with "source---"-prefixed),
2577 # so we can try if these "binary" packages are installable.
2578 # If such a "binary" package is installable, the corresponding source package is buildable.
2579 print $SOURCES "Package: source---$key\n";
2580 print $SOURCES "Version: $pkg->{'version'}\n";
2581 my $t = &filterarch($srcs->{$key}{'dep'} || $srcs->{$key}{'depends'}, $arch);
2582 my $tt = &filterarch($pkg->{'extra_depends'}, $arch);
2583 $t = $t ? ($tt ? "$t, $tt" : $t) : $tt;
2584 print $SOURCES "Depends: $t\n" if $t;
2585 my $u = &filterarch($srcs->{$key}{'conf'} || $srcs->{$key}{'conflicts'}, $arch);
2586 my $uu = &filterarch($pkg->{'extra_conflicts'}, $arch);
2587 $u = $u ? ($uu ? "$u, $uu" : $u) : $uu;
2588 print $SOURCES "Conflicts: $u\n" if $u;
2589 print $SOURCES "Architecture: all\n";
2590 print $SOURCES "\n";
2592 for my $key (keys %interesting_packages_depwait) {
2593 my $pkg = $db->{$key};
2594 # we print the source files as binary ones (with "depwait---"-prefixed),
2595 # so we can try if these "binary" packages are installable.
2596 # If such a "binary" package is installable, the corresponding source package goes out of depwait
2597 print $SOURCES "Package: depwait---$key\n";
2598 print $SOURCES "Version: $pkg->{'version'}\n";
2599 print $SOURCES "Depends: $pkg->{'depends'}\n";
2600 print $SOURCES "Architecture: all\n";
2601 print $SOURCES "\n";
2605 my $edosresults = wb_edos_builddebcheck({'arch' => $args->{'arch'}, 'pkgs' => $args->{'pkgs'}, 'src' => $tmpfile});
2606 if (ref($edosresults) eq 'HASH') {
2607 foreach my $key (grep { $_ !~ /^depwait---/ } keys %$edosresults) {
2608 if (exists $interesting_packages{$key}) {
2609 $interesting_packages{$key} = $edosresults->{$key};
2611 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2614 foreach my $key (grep { $_ =~ /^depwait---/ } keys %$edosresults) {
2615 $key =~ /^depwait---(.*)/ and $key = $1;
2616 if (exists $interesting_packages_depwait{$key}) {
2617 $interesting_packages_depwait{$key} = $edosresults->{"depwait---".$key};
2619 #print "TODO: edos reported a package we do not care about now\n" if $verbose;
2623 # if $edosresults isn't an hash, then something went wrong and the string is the error message
2624 print "ERROR: Could not run wb-edos-builddebcheck. I am continuing, assuming\n" .
2625 "all packages have installable build-dependencies."
2630 for my $key (keys %interesting_packages) {
2631 next if defined $interesting_packages_depwait{$key};
2632 my $pkg = $db->{$key};
2634 (defined $interesting_packages{$key} and $pkg->{'state'} eq 'Needs-Build') ||
2635 (not defined $interesting_packages{$key} and $pkg->{'state'} eq 'BD-Uninstallable');
2636 my $problemchange = $interesting_packages{$key} ne $pkg->{'bd_problem'};
2638 if (defined $interesting_packages{$key}) {
2639 change_state( \$pkg, 'BD-Uninstallable' );
2640 $pkg->{'bd_problem'} = $interesting_packages{$key};
2642 change_state( \$pkg, 'Needs-Build' );
2645 if ($problemchange) {
2646 if (defined $interesting_packages{$key}) {
2647 $pkg->{'bd_problem'} = $interesting_packages{$key};
2651 log_ta( $pkg, "--merge-all (edos)" ) unless $simulate;
2652 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) to $pkg->{'state'}\n" if $verbose || $simulate;
2654 if ($change || $problemchange) {
2655 update_source_info($pkg) unless $simulate;
2659 for my $key (keys %interesting_packages_depwait) {
2660 if ($interesting_packages_depwait{$key}) {
2661 print "dep-wait for $key ($args->{'arch'}) not fullfiled yet\n" if $verbose || $simulate;
2664 my $pkg = $db->{$key};
2665 if (defined $interesting_packages{$key}) {
2666 change_state( \$pkg, 'BD-Uninstallable' );
2667 $pkg->{'bd_problem'} = $interesting_packages{$key};
2669 change_state( \$pkg, 'Needs-Build' );
2671 log_ta( $pkg, "edos_depcheck: depwait" ) unless $simulate;
2672 update_source_info($pkg) unless $simulate;
2673 print "edos-builddebchange changed state of ${key}_$pkg->{'version'} ($args->{'arch'}) from dep-wait to $pkg->{'state'}\n" if $verbose || $simulate;
2679 ($prgname = $0) =~ s,^.*/,,;
2681 Usage: $prgname <options...> <package_version...>
2683 -v, --verbose: Verbose execution.
2684 -A arch: Architecture this operation is for.
2685 --take: Take package for building [default operation]
2686 -f, --failed: Record in database that a build failed due to
2687 deficiencies in the package (that aren't fixable without a new
2689 -u, --uploaded: Record in the database that the packages build
2690 correctly and were uploaded.
2691 -n, --no-build: Record in the database that the packages aren't
2692 desired for this architecture and shouldn't appear in listings even
2693 if they're out of date.
2694 --dep-wait: Record in the database that the packages are waiting
2695 for some source dependencies to become available
2696 --binNMU num: Schedule a re-build of the package with unchanged source, but
2697 a new version number (source-version + "+b<num>")
2698 --give-back: Mark a package as ready to build that is in state Building,
2699 Built or Build-Attempted. To give back a package in state Failed, use
2700 --override. This command will actually put the package in state
2701 BD-Uninstallable, until the installability of its Build-Dependencies
2702 were verified. This happens at each call of --merge-all, usually
2704 --merge-quinn: Merge quinn-diff output into database.
2705 --merge-packages: Merge Packages files into database.
2706 --pretend-avail: Pretend that given packages are available now and give
2707 free packages waiting for them
2708 -i SRC_PKG, --info SRC_PKG: Show information for source package
2709 -l STATE, --list=STATE: List all packages in state STATE; can be
2710 combined with -U to restrict to a specific user; STATE can
2712 -m MESSAGE, --message=MESSAGE: Give reason why package failed or
2713 source dependency list
2714 (used with -f, --dep-wait, and --binNMU)
2715 -o, --override: Override another user's lock on a package, i.e.
2716 take it over; a notice mail will be sent to the other user
2717 -U USER, --user=USER: select user name for which listings should
2718 apply, if not given all users are listed.
2719 if -l is missing, set user name to be entered in db; usually
2720 automatically choosen
2721 --import FILE: Import database from a ASCII file FILE
2722 --export FILE: Export database to a ASCII file FILE
2724 The remaining arguments (depending on operation) usually start with
2725 "name_version", the trailer is ignored. This allows to pass the names
2726 of .dsc files, for which file name completion can be used.
2727 --merge-packages and --merge-quinn take Package/quin--diff file names
2728 on the command line or read stdin. --list needs nothing more on the
2729 command line. --info takes source package names (without version).
2734 sub pkg_version_eq {
2736 my $version = shift;
2739 if (defined $pkg->{'binary_nmu_version'}) and
2740 version_compare(binNMU_version($pkg->{'version'},
2741 $pkg->{'binary_nmu_version'}),'=', $version);
2742 return version_compare( $pkg->{'version'}, "=", $version );
2746 return '"' . $arch . $schema_suffix . '".packages';
2749 sub user_table_name {
2750 return '"' . $arch . $schema_suffix . '".users';
2753 sub transactions_table_name {
2754 return '"' . $arch . $schema_suffix . '".transactions';
2757 sub pkg_history_table_name {
2758 return '"' . $arch . $schema_suffix . '".pkg_history';
2761 sub get_readonly_source_info {
2763 # SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
2764 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"
2765 . ", (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"
2766 . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2767 . ", extra_depends, extra_conflicts"
2768 . " FROM " . table_name()
2769 . ' WHERE package = ? AND distribution = ?';
2770 my $pkg = $dbh->selectrow_hashref( $q,
2771 undef, $name, $distribution);
2775 sub get_source_info {
2777 return get_readonly_source_info($name) if $simulate;
2778 my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change)) as state_days FROM ' .
2779 table_name() . ' WHERE package = ? AND distribution = ?' .
2781 undef, $name, $distribution);
2785 sub get_all_source_info {
2788 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"
2789 # . ", (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"
2790 # . ", (SELECT max(build_time) FROM ".pkg_history_table_name()." WHERE pkg_history.package = packages.package AND pkg_history.distribution = packages.distribution ) AS anytime"
2791 . ", successtime.build_time as successtime, anytime.build_time as anytime, extra_depends, extra_conflicts"
2792 . " FROM " . table_name()
2794 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." where result = 'successful' order by package, distribution, timestamp "
2795 . " ) as successtime using (package, distribution) "
2797 . "select distinct on (package, distribution) build_time, package, distribution from ".pkg_history_table_name()." order by package, distribution, timestamp desc"
2798 . " ) as anytime using (package, distribution) "
2801 if ($distribution) {
2802 my @dists = split(/[, ]+/, $distribution);
2803 $q .= ' AND ( distribution = ? '.(' OR distribution = ? ' x $#dists).' )';
2804 foreach my $d ( @dists ) {
2808 if ($options{state} && uc($options{state}) ne "ALL") {
2809 $q .= ' AND upper(state) = ? ';
2810 push @args, uc($options{state});
2813 if ($options{user} && uc($options{state}) ne "NEEDS-BUILD") { # if it's NEEDS-BUILD, we don't look at users
2814 #this basically means "this user, or no user at all":
2815 $q .= " AND (builder = ? OR upper(state) = 'NEEDS-BUILD')";
2816 push @args, $options{user};
2819 if ($options{category}) {
2820 $q .= ' AND failed_category <> ? AND upper(state) = ? ';
2821 push @args, $options{category};
2822 push @args, "FAILED";
2825 if ($options{list_min_age} > 0) {
2826 $q .= ' AND age(state_change) > ? ';
2827 push @args, $options{list_min_age} . " days";
2830 if ($options{list_min_age} < 0) {
2831 $q .= ' AND age(state_change) < ? ';
2832 push @args, -$options{list_min_age} . " days";
2835 my $db = $dbh->selectall_hashref($q, 'package', undef, @args);
2839 sub update_source_info {
2841 $pkg->{'extra_depends'} = $extra_depends if defined $extra_depends;
2842 undef $pkg->{'extra_depends'} unless $pkg->{'extra_depends'};
2843 $pkg->{'extra_conflicts'} = $extra_conflicts if defined $extra_conflicts;
2844 undef $pkg->{'extra_conflicts'} unless $pkg->{'extra_conflicts'};
2845 print Dumper $pkg if $verbose and $simulate;
2846 return if $simulate;
2848 my $pkg2 = get_source_info($pkg->{'package'});
2849 if (! defined $pkg2)
2851 add_source_info($pkg);
2854 $dbh->do('UPDATE ' . table_name() . ' SET ' .
2859 'installed_version = ?, ' .
2860 'previous_state = ?, ' .
2861 (($pkg->{'do_state_change'}) ? "state_change = now()," : "").
2865 'old_failed = ?, ' .
2866 'binary_nmu_version = ?, ' .
2867 'binary_nmu_changelog = ?, ' .
2868 'failed_category = ?, ' .
2869 'permbuildpri = ?, ' .
2873 'extra_depends = ?, ' .
2874 'extra_conflicts = ?, ' .
2876 'WHERE package = ? AND distribution = ?',
2882 $pkg->{'installed_version'},
2883 $pkg->{'previous_state'},
2887 $pkg->{'old_failed'},
2888 $pkg->{'binary_nmu_version'},
2889 $pkg->{'binary_nmu_changelog'},
2890 $pkg->{'failed_category'},
2891 $pkg->{'permbuildpri'},
2895 $pkg->{'extra_depends'},
2896 $pkg->{'extra_conflicts'},
2897 $pkg->{'bd_problem'},
2899 $distribution) or die $dbh->errstr;
2902 sub add_source_info {
2903 return if $simulate;
2905 $dbh->do('INSERT INTO ' . table_name() .
2906 ' (package, distribution) values (?, ?)',
2907 undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
2910 sub del_source_info {
2911 return if $simulate;
2913 $dbh->do('DELETE FROM ' . table_name() .
2914 ' WHERE package = ? AND distribution = ?',
2915 undef, $name, $distribution) or die $dbh->errstr;
2920 my $user = $dbh->selectrow_hashref('SELECT * FROM ' .
2921 user_table_name() . ' WHERE username = ? AND distribution = ?',
2922 undef, $name, $distribution);
2926 sub update_user_info {
2927 return if $simulate;
2929 $dbh->do('UPDATE ' . user_table_name() .
2930 ' SET last_seen = now() WHERE username = ?' .
2931 ' AND distribution = ?',
2932 undef, $user, $distribution)
2933 or die $dbh->errstr;
2938 return if $simulate;
2940 $dbh->do('INSERT INTO ' . user_table_name() .
2941 ' (username, distribution, last_seen)' .
2942 ' values (?, ?, now())',
2943 undef, $user, $distribution)
2944 or die $dbh->errstr;
2949 return if $simulate;
2950 $dbh->do('LOCK TABLE ' . table_name() .
2951 ' IN EXCLUSIVE MODE', undef) or die $dbh->errstr;
2955 # parts the array $_[0] and $_[1] and returns the sub-array (modifies the original one)
2958 my $separator = shift;
2959 while($args->[0] && $args->[0] ne $separator) {
2960 push @ret, shift @$args;
2962 shift @$args if @$args;
2966 sub parse_all_v3() {
2969 my $db = get_all_source_info();
2970 my $binary = $srcs->{'_binary'};
2973 foreach my $name (keys %$srcs) {
2974 next if $name eq '_binary';
2976 # state = installed, out-of-date, uncompiled, not-for-us
2977 my $pkgs = $srcs->{$name};
2978 my $pkg = $db->{$name};
2981 next SRCS if $pkgs->{'status'} eq 'not-for-us';
2982 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'} ($vars->{'arch'}, $vars->{'suite'}):";
2984 # does at least one binary exist in the database and is more recent - if so, we're probably just outdated, ignore the source package
2985 for my $bin (@{$pkgs->{'binary'}}) {
2986 if ($binary->{$bin} and vercmp($pkgs->{'version'}, $binary->{$bin}->{'version'}) < 0) {
2987 print "$logstr skipped because binaries (assumed to be) overwritten\n" if $verbose || $simulate;
2991 $pkg->{'package'} = $name;
2993 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkgs->{'version'}".
2994 ($pkgs->{'binnmu'} ? ";b".$pkgs->{'binnmu'} : "").
2995 "($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'version'}".
2996 ($pkg->{'binary_nmu_version'} ? ";b".$pkg->{'binary_nmu_version'} : "").
2997 ", $pkg->{'state'}):";
2999 if (isin($pkgs->{'status'}, qw (installed related)) && $pkg->{'binary_nmu_version'} && $pkgs->{'binnmu'} < int($pkg->{'binary_nmu_version'})) {
3000 $pkgs->{'status'} = 'out-of-date';
3002 if (isin($pkgs->{'status'}, qw (installed related))) {
3004 if ($pkg->{'state'} ne 'Installed') {
3005 change_state( \$pkg, 'Installed');
3006 delete $pkg->{'depends'};
3007 delete $pkg->{'extra_depends'};
3008 delete $pkg->{'extra_conflicts'};
3011 my $attrs = { 'version' => 'version', 'installed_version' => 'version', 'binary_nmu_version' => 'binnmu', 'section' => 'section', 'priority' => 'priority' };
3012 foreach my $k (keys %$attrs) {
3013 if ($pkg->{$k} ne $pkgs->{$attrs->{$k}}) {
3014 $pkg->{$k} = $pkgs->{$attrs->{$k}};
3018 if (isin($pkgs->{'status'}, qw (related)) and $pkg->{'notes'} ne "related") {
3019 $pkg->{'notes'} = "related";
3023 print "$logstr set to installed/".$pkg->{'notes'}."\n" if $verbose || $simulate;
3024 log_ta( $pkg, "--merge-v3: installed" ) unless $simulate;
3025 update_source_info($pkg) unless $simulate;
3030 if ($pkgs->{'status'} eq 'not-for-us') {
3031 next if isin( $pkg->{'state'}, qw(Not-For-Us Installed Failed-Removed));
3033 if (isin( $pkg->{'state'}, qw(Failed Build-Attempted Built))) {
3034 change_state( \$pkg, "Failed-Removed" );
3035 log_ta( $pkg, "--merge-v3: Failed-Removed" ) unless $simulate;
3036 update_source_info($pkg) unless $simulate;
3037 print "$logstr (virtually) deleted from database\n" if $verbose || $simulate;
3041 print "$logstr should delete (not-for-us according to P-a-s)\n" if $verbose || $simulate || 1; # not implemented yet on purpose
3045 # only uncompiled / out-of-date are left, so check if anything new
3046 if (!(isin($pkgs->{'status'}, qw (uncompiled out-of-date)))) {
3047 print "$logstr package in unknown state: $pkgs->{'status'}\n";
3050 next if $pkgs->{'version'} eq $pkg->{'version'} and $pkgs->{'binnmu'} >= int($pkg->{'binary_nmu_version'});
3051 next if $pkgs->{'version'} eq $pkg->{'version'} and !isin( $pkg->{'state'}, qw(Installed));
3052 next if isin( $pkg->{'state'}, qw(Not-For-Us Failed-Removed));
3054 if (defined( $pkg->{'state'} ) && isin( $pkg->{'state'}, qw(Building Built Build-Attempted))) {
3055 send_mail( $pkg->{'builder'},
3056 "new version of $name (dist=$distribution)",
3057 "As far as I'm informed, you're currently building the package $name\n".
3058 "in version $pkg->{'version'}.\n\n".
3059 "Now there's a new source version $pkgs->{'version'}. If you haven't finished\n".
3060 "compiling $name yet, you can stop it to save some work.\n".
3061 "Just to inform you...\n".
3062 "(This is an automated message)\n" ) unless $simulate;
3063 print "$logstr new version while building $pkg->{'version'} -- sending mail to builder ($pkg->{'builder'})\n"
3064 if $verbose || $simulate;
3066 change_state( \$pkg, 'Needs-Build');
3067 $pkg->{'notes'} = $pkgs->{'status'};
3068 $pkg->{'version'} = $pkgs->{'version'};
3069 $pkg->{'section'} = $pkgs->{'section'};
3070 $pkg->{'priority'} = $pkgs->{'priority'};
3071 $pkg->{'dep'} = $pkgs->{'depends'};
3072 $pkg->{'conf'} = $pkgs->{'conflicts'};
3073 delete $pkg->{'builder'};
3074 delete $pkg->{'binary_nmu_version'} unless $pkgs->{'binnmu'};
3075 delete $pkg->{'binary_nmu_changelog'} unless $pkgs->{'binnmu'};
3076 log_ta( $pkg, "--merge-v3: needs-build" ) unless $simulate;
3077 update_source_info($pkg) unless $simulate;
3078 print "$logstr set to needs-builds\n" if $simulate || $verbose;
3081 foreach my $name (keys %$db) {
3082 next if $srcs->{$name};
3083 my $pkg = $db->{$name};
3084 my $logstr = "merge-v3 $vars->{'time'} ".$name."_$pkg->{'version'} ($vars->{'arch'}, $vars->{'suite'}, previous: $pkg->{'state'}):";
3085 # package disappeared - delete
3086 change_state( \$pkg, 'deleted' );
3087 log_ta( $pkg, "--merge-v3: deleted" ) unless $simulate;
3088 print "$logstr deleted from database\n" if $verbose || $simulate;
3089 del_source_info($name) unless $simulate;
3090 delete $db->{$name};