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
|
#!/usr/bin/perl
=pod
=head1 Name
emtargetcmp - Compare the Emdebian target repository with Debian unstable
=head1 Copyright and Licence
Copyright (C) 2007-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/>.
=head1 Bugs
A long standing bug in apt is that when switching architecture or when
switching between repository sources, apt has a habit of purging the lists
directory of whatever cache is being used. Despite apt-cross using
-o APT::Get::List-Cleanup=off in all calls, this behaviour has returned
in recent versions of apt.
To get around this, emtargetcmp now creates a temporary directory,
copies the system cache, queries that and then removes the copy. This allows
apt to use lock files and status files in the temporary directory without
requiring sudo. (The temporary directory used is $apt_cache_dir/host/.)
=cut
use Cache::Apt::Lookup;
use Cache::Apt::Config;
use Cache::Apt::Package;
use Emdebian::Tools;
use Text::FormatTable;
use Config::Auto;
use File::Basename;
use strict;
use warnings;
use Term::ANSIColor qw(:constants);
use Text::Wrap;
use vars qw/ @newer @older @equal %sources %chain @cross_triplet $verbose $arch $suite $progname $apt_cross_dir $our_version /;
$progname = basename($0);
$our_version = &tools_version();
sub usageversion {
print(STDERR <<END)
$progname version $our_version
Usage:
$progname [-a ARCH] [-v|--verbose] [-q|--quiet]
$progname -?|-h|--help|--version
END
or die "$0: failed to write usage: $!\n";
}
$verbose = 2;
$arch = "arm"; # only arm packages are built so far.
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 (/^(-a|--arch)$/) {
$arch = shift(@ARGV);
}
else
{
&usageversion();
die RED, "unrecognised option: $_.", RESET . "\n";
}
}
# need support for tweaking this.
$suite = "unstable";
$progname = basename($0);
$apt_cross_dir = &get_aptcross_dir;
&set_verbose ($verbose - 1);
&set_suite($suite);
&check_cache_arch($arch) if (defined ($arch));
my $cache = $apt_cross_dir;
if (not -d $cache)
{
mkdir ($cache) or die ("Unable to create the cache directory: $!");
}
# host == Handheld (arm)
# builD == desktop (amd64)
if (not -d "$cache/host")
{
# have to duplicate them or use sudo.
mkdir ("$cache/host") or die ("Unable to create the host cache directory: $!");
open (STATUS, ">$cache/host/status");
close (STATUS);
mkdir "$cache/host/$suite";
mkdir "$cache/host/$suite/lists";
mkdir "$cache/host/$suite/lists/partial";
}
open (SRC, "$cache/sources.unstable");
open (SOURCE, ">$cache/host/sources.compare.$suite")
or die ("Cannot create sources list for comparison: $!");
print SOURCE "deb http://www.emdebian.org/emdebian/ unstable main\n";
print SOURCE "deb-src http://www.emdebian.org/emdebian/ unstable main\n";
close (SOURCE);
&set_cachedir("$cache/host");
&use_mysources("sources.compare.$suite");
&force_update;
my $config = &init_cache($verbose - 1);
my $iter = &get_cache_iter();
my $pkg;
my @package_names = ();
my %h = ();
do
{
$pkg = $iter->next;
$h{$pkg}++ if ($pkg);
} while ($pkg);
@package_names = sort (keys %h);
# array of AptCrossPackage structs, ordered by package name
my @packages = ();
foreach my $p (@package_names)
{
my $emp = AptCrossPackage->new();
$emp->Package($p);
$emp = &lookup_pkg($emp);
push @packages, $emp;
}
foreach my $package (@packages)
{
my $src = $$package->Source;
my $vers = $$package->Version;
next unless defined $vers;
$vers =~ s/em[0-9]+$//;
$sources{$src} = $vers;
}
print CYAN, "found " . scalar (keys %sources) . " source packages with a version string.\n", RESET if ($verbose >= 2);
#`rm -rf $cache/host`;
# we don't need the other cache again. Start the build_cache.
$arch = `dpkg-architecture -qDEB_BUILD_ARCH`;
chomp($arch);
&check_cache_arch ($arch);
if (not -d "$cache/build")
{
# have to duplicate them or use sudo.
mkdir ("$cache/build") or die ("Unable to create the build cache directory: $!");
open (STATUS, ">$cache/build/status");
close (STATUS);
open (SRC, "$cache/sources.unstable");
open (CMP, ">$cache/build/sources.unstable");
my @l = <SRC>;
print CMP @l;
close (SRC);
close (CMP);
mkdir "$cache/build/$suite";
mkdir "$cache/build/$suite/lists";
mkdir "$cache/build/$suite/lists/partial";
}
&set_cachedir("$cache/build");
&use_hostsources;
opendir (BUILDLISTS, "/var/lib/apt/lists/") or die;
my @buildlists=grep(!/^\.\.?/, readdir BUILDLISTS);
foreach my $buildfile (@buildlists)
{
next if (-d "/var/lib/apt/lists/$buildfile");
open (SRC, "/var/lib/apt/lists/$buildfile") or next;
open (DEST, ">$cache/build/unstable/lists/$buildfile") or
die ("Cannot copy $cache/build/unstable/lists/$buildfile! $!\n");
my @data=<SRC>;
print DEST @data;
close (SRC);
close (DEST);
}
closedir (BUILDLISTS);
&setup_config;
$config = &init_host_cache($verbose);
# remove the temporary host cache
#`rm -rf $cache/build`;
@older = ();
@newer = ();
@equal = ();
my @list = ();
@list = sort (keys %sources);
$| = 1;
print GREEN, "Updating embug flags",RESET," . . " if ($verbose > 1);
my $bugconfig = &target_config();
my $table = Text::FormatTable->new('25l 25l 25l');
$table->head("Package", "Emdebian", "Debian");
$table->rule('=');
foreach my $check (@list)
{
my $host;
my $name;
my $host_ver;
$host = &srclookup($check);
$name = $sources{$check};
unless (defined $host->{'Version'})
{
push (@newer, $check);
next;
}
$name =~ s/[0-9]://;
$host_ver = $host->{'Version'};
$host_ver =~ s/[0-9]://;
my $cmp = &ver_compare ($name, $host_ver);
if ($cmp < 0)
{
push (@older, $check);
$table->row($check, $name, $host_ver);
$bugconfig->{$check}="debian" if (not defined $bugconfig->{$check});
}
push (@newer, $check) if ($cmp > 0);
if ($cmp == 0)
{
push (@equal, $check);
my $status = $bugconfig->{"$check"} if (defined $bugconfig->{"$check"});
undef ($bugconfig->{$check}) if (defined $status);
}
print ". " if ($verbose > 1);
}
#unlink ("$cache/sources.compare.$suite");
&write_target_config($bugconfig);
print " : done.\n" if ($verbose > 1);
$|=0;
if ((scalar @older > 0) and ($verbose >= 1))
{
print CYAN, "The following " . scalar @older .
" source packages are older in Emdebian than in Debian:\n", RESET;
print RED;
print $table->render(20);
print RESET ."\n";
}
if (((scalar @equal) > 0) and ($verbose >= 2))
{
print CYAN, "The following " . scalar @equal .
" source packages are the same version in Emdebian as in Debian:\n", RESET;
print GREEN, wrap('', '', @equal), RESET;
print "\n";
}
if (((scalar @newer) > 0) and ($verbose >= 2))
{
print CYAN, "The following source packages are newer in Emdebian than in Debian:\n", RESET;
print CYAN, wrap('', '', @newer), RESET;
print "\n";
}
my @scripts = qw#/usr/lib/emdebian-tools/emdebian.crossd
/usr/lib/emdebian-tools/emdebian.gtk /usr/lib/emdebian-tools/emdebian.gpe#;
for my $script (@scripts)
{
my $parser = qq% mirror_style() { echo -n; }; download_style() { echo -n; }; . $script; work_out_debs; echo -n \$base \$required;%;
$arch = "arm";
my $base = `$parser`;
# more than just chomp
$base =~ s/\n//g;
print CYAN, "\nTesting Emdebian rootfs (" . basename($script) . ")\n\n", RESET;
my $packages = "www.emdebian.org_emdebian_dists_" . $suite;
$packages .= "_main_binary-" . $arch . "_Packages";
system ("edos-debcheck -explain -failures $base < $cache/host/$suite/lists/$packages");
print "\n";
}
=head1 Description
emtargetcmp prepares cache data from the emdebian/emdebian target cache
at buildd.emdebian.org against the Debian unstable cache at ftp.uk.debian.org
for arm with support for mapping Emdebian version strings to Debian versions.
Uses ftk.uk.debian.org or ftp.de.debian.org due to location of buildd.emdebian.org
One of the remaining issues with this approach is the apparent lack of support
for creating a sources.list in memory without needing lots of little files.
Therefore emtargetcmp creates a special sources list in the apt-cross
directory (e.g. ~/.apt-cross/) and switches the content of the file as
necessary.
This small utility also serves as an example of what can be done with
Cache::Apt::* from libcache-apt-perl.
Currently, emtargetcmp only supports ARM because Emdebian only has a
root filesystem for ARM.
Output uses ANSIColor (where supported) so that packages which are older
in Emdebian than in Debian are listed in red and packages which are the
same version in Emdebian as in Debian (accounting for the emdebian version
suffix) are shown in green. If, for whatever reason, Emdebian contains packages
that are newer than in Debian, these are shown in blue.
=head1 Commands and options
-a|--arch
Override the dpkg-cross default architecture.
-v|--verbose
Make the output more verbose.
-q|--quiet
Make the output quieter.
=cut
|