1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
|
#!/usr/bin/perl
# embug : Track cross-building bugs from within package builds.
# Copyright (C) 2008 Neil Williams <codehelp@debian.org>
#
# This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use Cwd;
use Text::Wrap;
use Config::Auto;
use File::Basename;
use Emdebian::Tools;
use Text::FormatTable;
use Cache::Apt::Lookup;
use Debian::DpkgCross;
use Dpkg::Control;
# Adds dependency on libsoap-lite-perl but this is already recommended
# by devscripts.
use SOAP::Lite;
use Term::ANSIColor qw(:constants);
use strict;
use warnings;
use vars qw( $our_version $verbose $apt_cross_dir $progname $soap $usertag %buglist
$bugs $package $flag $number $mode $list $control $source $listing $lintian);
$our_version = &tools_version;
$verbose = 1;
$listing = 0;
$progname = basename($0);
&read_config();
$apt_cross_dir = &get_aptcross_dir;
sub usageversion {
print(STDERR <<END)
$progname version $our_version
Usage:
$progname [-v|--verbose] [-q|--quiet] [-p|--package] -f|--flag
$progname [-v|--verbose] [-q|--quiet] [-p|--package] -r|--remove
$progname [-v|--verbose] [-q|--quiet] [-p|--package] -g|--get-number
$progname [-v|--verbose] [-q|--quiet] [-p|--package] -o|--outdated
$progname [-v|--verbose] [-q|--quiet] [-p|--package] -d|--debian
$progname [-v|--verbose] [-q|--quiet] [-p|--package] -w|--waiting
$progname [-v|--verbose] [-q|--quiet] --prepare
$progname [-v|--verbose] [-q|--quiet] -l|--list
$progname [-v|--verbose] [-q|--quiet] --list-bugs
$progname [-v|--verbose] [-q|--quiet] --list-newer
$progname [-v|--verbose] [-q|--quiet] -u|--update
$progname [-v|--verbose] [-q|--quiet] -m|--missing
$progname -?|-h|--help|--version
Commands:
-f|--flag: Flag this package as needing a bug report.
-g|--get-number: Get the bug number of the report filed for this package.
-l|--list: List all known bug report numbers, with package names,
and packages with newer versions or outdated patches.
--list-bugs: List only the bug report numbers with package names.
--list-newer: List only packages with newer versions, outdated patches
or needing an update due to a failed lintian check.
-m|--missing: List all flagged packages without bug reports.
-r|--remove: Remove the flag if no bug report has been filed.
-u|--update: Update the list of known cross-building bugs
by querying bugs.debian.org.
-o|--outdated: Record that the Emdebian SVN patches are out of date.
-d|--debian: Record that the Emdebian package is older than the Debian package.
-w|--waiting: Record that the Emdebian package is waiting for another package.
--lintian: Record that the Emdebian package has failed a lintian test.
--failed: Record that the Emdebian package failed to build.
--prepare: Create a temporary directory suitable for patch creation
and testing.
-?|-h|--help: Print this usage message and exit
--version: Print this usage message and exit
Options:
-p|--package: Specify the source package name instead of looking in
debian/control.
-v|--verbose: be verbose (repeat for more verbosity)
-q|--quiet: be quiet [default]
$progname assumes that each source package only has one bug
tagged with the 'crossbuilt' usertag for user 'codehelp\@debian.org'.
Package flags have a fixed priority:
Lowest: Newer in Debian embug -d
Patches failed embug -o
Highest: Lintian errors embug --lintian
Virtual: Fails to crossbuild. embug --failed
"Failed" is only set if the patches are up to date, otherwise most
packages listed as "Failed" would just be failed patches. "Failed" also
replaces "lintian" if the patches are up to date.
END
|| die "$0: failed to write usage: $!\n";
exit 0;
}
while( @ARGV ) {
$_= shift( @ARGV );
last if m/^--$/;
if (!/^-/) {
unshift(@ARGV,$_);
last;
}
elsif (/^(-\?|-h|--help|--version)$/) {
&usageversion();
exit( 0 );
}
elsif (/^(-v|--verbose)$/) {
$verbose++;
}
elsif (/^(-q|--quiet)$/) {
$verbose--;
}
elsif (/^(-p|--package)$/) {
$package = shift(@ARGV);
}
elsif (/^(-o|--outdated)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'record';
}
elsif (/^(-g|--get-number)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'get';
}
elsif (/^(-f|--flag)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'flag';
}
elsif (/^(-u|--update)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'update';
}
elsif (/^(-d|--debian)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'debian';
}
elsif (/^(-l|--list)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'list';
$listing = 1;
}
elsif (/^(--list-bugs)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'list';
$listing = 2;
}
elsif (/^(-l|--list-newer)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'list';
$listing = 3;
}
elsif (/^(-m|--missing)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'missing';
}
elsif (/^(-r|--remove)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'remove';
}
elsif (/^(--prepare)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'prepare';
}
elsif (/^(--lintian)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'lintian';
}
elsif (/^(--failed)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'failed';
}
elsif (/^(-w|--waiting)$/) {
die "$progname: Only one action can be specified!\n" if $mode;
$mode = 'waiting';
}
else {
die RED, "$progname: Unknown option $_.", RESET, "\n";
}
}
if (not defined $mode)
{
print (RED, "$progname: At least one command must be specified.", RESET, "\n");
&usageversion;
exit (1);
}
&get if ($mode eq "get");
&flag if ($mode eq "flag");
&list if ($mode eq "list");
&missing if ($mode eq "missing");
&update if ($mode eq "update");
&remove if ($mode eq "remove");
&prepare if ($mode eq "prepare");
&record if ($mode eq "record");
&debian if ($mode eq "debian");
&lintian if ($mode eq "lintian");
&failed if ($mode eq "failed");
&waiting if ($mode eq "waiting");
exit (0);
# if package is defined, it must have come from the user.
# just run that passed ~/.apt-cross/embug
sub get_package
{
if (not defined $package)
{
print CYAN, "Checking for debian/control\n", RESET if ($verbose >= 2);
until (-f "debian/control")
{
chdir ".." or die "Cannot change directory ../ $!";
if (cwd() eq '/')
{
die (RED, wrap('','',"$progname: Cannot find debian/control" .
" anywhere!\nUse --package if you are not in the source code tree."),
RESET, "\n");
}
}
$control = Dpkg::Control->new();
$package = $control->get_source()->{Source};
}
print GREEN, "Using source package: $package\n", RESET if ($verbose >= 2);
return $package;
}
# flag
# append source package name to a file in ~/.apt-cross/ (embug)
sub flag
{
my $config = &bug_config();
&get_package;
print GREEN, "Flagging $package\n", RESET if ($verbose >= 1);
$config->{$package}="";
&write_config($config);
}
sub debian
{
my $config = &target_config();
&get_package;
# lowest priority - don't overwrite other flags.
return if (defined $config->{$package});
print GREEN, wrap('','',"Recording that Debian has a newer version of ",
"'$package'.\n"), RESET if ($verbose >= 1);
$config->{$package}="debian";
&write_target_config($config);
}
sub lintian
{
my $config = &target_config();
&get_package;
print GREEN, wrap('','',"Recording that '$package' has failed a lintian check",
"\n"), RESET if ($verbose >= 1);
$config->{$package}="lintian";
&write_target_config($config);
}
sub failed
{
my $config = &target_config();
&get_package;
# overwrite any flags but only if patches are up to date.
if ((defined ($config->{$package})) and
($config->{$package} eq "patches"))
{
print RED, wrap('','',"Package failed to build but patches are ".
"marked as out of date. Ignoring build failure.\n"), RESET
if ($verbose >= 1);
return;
}
print GREEN, wrap('','',"Recording that the package failed to build.\n"), RESET
if ($verbose >= 1);
$config->{$package}="failed";
&write_target_config($config);
}
# record that the Emdebian SVN patches are out of date
sub record
{
my $config = &target_config();
&get_package;
# don't overwrite higher flags
return if ((defined $config->{$package}) and ($config->{$package} eq "lintian"));
print GREEN, wrap('','',"Recording that the Emdebian SVN patches are ",
"out of date for $package.\n"), RESET if ($verbose >= 1);
$config->{$package}="patches";
&write_target_config($config);
}
# remove source package name from the file in ~/.apt-cross/ (embug)
sub remove
{
my $config = &bug_config();
&get_package;
my $number = $config->{"$package"} if (defined $config->{"$package"});
if (not defined $number)
{
print GREEN, "No cross-building bugs for $package\n", RESET
if ($verbose >= 1);
}
elsif ($number eq "")
{
print GREEN, "Removing flag for $package\n", RESET if ($verbose >= 1);
undef ($config->{$package});
}
&write_config($config);
$config = &target_config();
my $status = $config->{"$package"} if (defined $config->{"$package"});
return if (not defined $status);
print GREEN, "Removing flag for $package\n", RESET if ($verbose >= 1);
undef ($config->{$package});
&write_target_config($config);
}
# list
# call list from ~/.apt-cross/embug and output
sub list
{
my $config = &bug_config();
print GREEN, scalar keys %$config, " open crossbuilt bugs.", RESET, "\n";
my $table = Text::FormatTable->new('30l 50l');
$table->head("Package", "Bug #");
$table->rule('=');
foreach my $pkg (sort keys %$config)
{
my $r = $config->{$pkg};
my $rr = (ref($r) eq 'ARRAY') ? join(', ', @$r) : $r;
$table->row("$pkg ", $rr);
}
print $table->render(20) if (($listing == 1) or ($listing == 2));
$config = &target_config();
return unless $config;
print "\n\n";
undef $table;
$table = Text::FormatTable->new('30l 20l 20l 20l');
$table->head("Package", "Lintian", "Patches", "Debian");
$table->rule('=');
foreach my $pkg (sort keys %$config)
{
my $s = $config->{$pkg};
my $d = $s =~ /debian/ ? "Newer in Debian" : "";
my $p = $s =~ /patches/ ? "Patches failed" : "";
$p = $s =~ /failed/ ? "Failed to build" : $p;
my $l = $s =~ /lintian/ ? "Lintian errors" : "";
if ($s =~ /waiting/)
{
$d = "emdebcheck wait";
$l = "";
$p = "";
}
$table->row("$pkg ", $l, $p, $d);
}
print $table->render(20) if (($listing == 1) or ($listing == 3));
}
sub missing
{
my $config = &bug_config();
my @list=();
my @fail=();
my $c = 0;
foreach my $pkg (sort keys %$config)
{
push @list, $pkg if ($config->{$pkg} eq "");
push @fail, $pkg if ($config->{$pkg} eq "patches");
}
return if ((!@list) and (!@fail));
print RED, "Packages flagged but with no bug report.", RESET, "\n";
foreach my $pkg (sort @list)
{
$c++;
print "$c: ".CYAN."$pkg", RESET, "\n";
}
print RED, "Packages with out of date patches.", RESET, "\n";
foreach my $pkg (sort @fail)
{
$c++;
print "$c: ".CYAN."$pkg", RESET, "\n";
}
}
# update
# call SOAP, add bug numbers to names from ~/.apt-cross/embug if listed in SOAP.
sub update
{
my $config;
my $cfile = $apt_cross_dir . "/embug";
# read existing data
if (-f $cfile)
{
open (CFILE, "$cfile") or
die (RED, "$progname: cannot read config file: $!",RESET,"\n");
$config = Config::Auto::parse("$cfile", format => "colon");
close (CFILE);
}
$soap = SOAP::Lite->uri('Debbugs/SOAP')->proxy('http://bugs.debian.org/cgi-bin/soap.cgi');
$usertag = $soap->get_usertag('codehelp@debian.org')->result();
my $nums = $usertag->{'crossbuilt'};
my $buildnums = $usertag->{'buildd.emdebian.org'};
push @$nums, @$buildnums;
foreach my $b (sort @$nums)
{
my $stats = $soap->get_status($b)->result->{$b};
my $pkg = ($stats->{'package'});
my $str = $config->{$pkg};
if ($stats->{'done'})
{
# unset flags if a real bug has been closed.
print GREEN, "$progname: $b, filed against $pkg, has been closed.\n",
RESET if ($verbose >= 1);
$str =~ s/$b// if (defined $str);
$config->{$pkg} = $str;
next;
}
# overlay the real bug data, space separated.
$str .= " $b";
$str =~ s/\s\s+/ /g;
$config->{$pkg} = $str;
print "setting $b for $pkg\n" if ($verbose >= 3);
}
# remove duplicates
print "processing bug numbers\n" if ($verbose >= 1);
my %list = ();
foreach my $p (keys %$config)
{
my %seen=();
# ignore missing flags
next unless (defined $config->{$p});
my @split = split (" ", $config->{$p});
foreach my $bugnumber (@split)
{
print "checking $bugnumber for $p\n" if ($verbose >= 2);
print ". " if ($verbose == 1);
next if (defined $seen{$bugnumber});
$seen{$bugnumber}++;
$list{$p}.=" $bugnumber";
}
}
print "\n" if ($verbose == 1);
foreach my $l (keys %list)
{
$config->{$l} = $list{$l};
}
&write_config($config);
}
sub write_config
{
my $config = shift;
if (not defined $config)
{
print "no defined config.\n";
return;
}
my $cfile = $apt_cross_dir . "/embug";
open (CFILE, ">$cfile") or
die (RED, "$progname: cannot write config file: $!",RESET,"\n");
foreach my $pkg (sort keys %$config)
{
# write $pkg and $b to CFILE
print CFILE "$pkg: " . $config->{$pkg} . "\n" if (defined $config->{$pkg});
}
close (CFILE);
}
# get
# Read ~/.apt-cross/embug. print status of this package.
sub get
{
&get_package;
my $config = &bug_config();
$number = $config->{"$package"} if (defined $config->{"$package"});
if (not defined $number)
{
print GREEN, "No cross-building bugs for $package\n", RESET;
}
elsif ($number eq "")
{
print GREEN, "$package is flagged but no bug has been reported.\n", RESET;
}
else
{
my $rr = (ref($number) eq 'ARRAY') ? join(' #', @$number) : $number;
print GREEN, "Bug: #$rr\n", RESET;
$rr = (ref($number) eq 'ARRAY') ? join("\nhttp://bugs.debian.org/", @$number) : $number;
print GREEN, "http://bugs.debian.org/$rr\n", RESET;
}
$config = &target_config();
$number = $config->{"$package"} if (defined $config->{"$package"});
if ($number eq "patches")
{
print GREEN, "Emdebian patches for $package are out of date.\n", RESET;
}
my $s = $config->{$package};
my $d = $s =~ /debian/ ? "Newer in Debian " : "";
my $p = $s =~ /patches/ ? "Patches failed " : "";
$p = $s =~ /failed/ ? "Failed to build " : $p;
my $l = $s =~ /lintian/ ? "Lintian errors " : "";
my $w = $s =~ /waiting/ ? "Waiting for dependency " : "";
print RED, "$package : ", $l, $p, $d, $w, "\n", RESET;
}
sub waiting
{
my $config = &target_config();
&get_package;
# don't overwrite higher flags
return if ((defined $config->{$package}) and ($config->{$package} eq "lintian"));
return if ((defined $config->{$package}) and ($config->{$package} eq "failed"));
print GREEN, wrap('','',"Recording that $package is waiting for another dependency.\n"), RESET if ($verbose >= 1);
$config->{$package}="waiting";
&write_target_config($config);
}
# idea: copy the source into ../../branches/bug/,
# unpack and copy the emdebian patch files
sub prepare
{
&get_package;
my $check_package;
# we might be in a different package - check.
if (-f "debian/control")
{
my $control = Dpkg::Control->new();
$check_package = $control->get_source()->{Source};
if ($check_package ne $package)
{
my ($indexchar)=split(//, $package);
my $workdir = &get_workdir;
$workdir = "/" if ($workdir eq "");
my $msg = &check_workdir($workdir);
die RED, $msg, RESET if ($msg ne "");
my $chkdir = "$workdir/trunk/$indexchar/$package/trunk/";
die (RED,"Unable to find $chkdir for $package",RESET,"\n")
unless (-d $chkdir);
system ("emsource --where $package");
die (RED,wrap('','', "The current directory is for '$check_package'. ".
"Please change to the above directory ".
"for '$package' and run $progname --prepare again."),RESET,"\n");
}
}
&check_emdebian_control;
my $cwd = basename(cwd);
my $base = $cwd;
$base =~ s/-([0-9])/.$1/g;
$base =~ s/\+/\\+/g;
print "$base\n";
opendir (SRC, "../") or die ("Cannot open parent directory! $!\n");
my @possible = grep(/^$base.*$/, readdir (SRC));
closedir (SRC);
my @dsc = ();
my @orig = ();
my @diff = ();
foreach my $file (@possible)
{
push @dsc, $file if (($file =~ /^$base.*\.dsc$/) and
($file !~ /tdeb/));
push @orig, $file if ($file =~ /^$base.*\.tar\.gz/);
push @diff, $file if ($file =~ /^$base.*\.diff\.gz$/);
}
my $dir = `mktemp -d ../../branches/bugXXXXXX`;
chomp($dir);
foreach my $d (@dsc)
{
`cp ../$d $dir/` unless (-d "../$d");
}
foreach my $o (@orig)
{
`cp ../$o $dir/` unless (-d "../$o");
}
foreach my $f (@diff)
{
`cp ../$f $dir/` unless (-d "../$f");
}
chdir ($dir);
foreach my $s (@dsc)
{
if ($s =~ /^$base.*em([0-9])\.dsc$/)
{
system ("dpkg-source -x $s");
system ("mv $cwd $cwd.emdebian") if (-d $cwd);
system ("mv ${cwd}em${1} ${cwd}.emdebian") if (-d "${cwd}em${1}");
}
else
{
system ("dpkg-source -x $s");
system ("mv $cwd $cwd.debian");
}
}
print GREEN, "\n$progname: prepared source is in $dir\n", RESET;
system ("ls -l") if ($verbose >= 1);
print CYAN, "\n$progname: $cwd is ready for patch creation.\n" .
"e.g. 'cd $dir ; meld $cwd.debian/debian/rules $cwd.emdebian/debian/rules'\n",
RESET if ($verbose >= 1);
}
|