| 1 |
#!/usr/bin/perl
|
| 2 |
#
|
| 3 |
# doincludes directory
|
| 4 |
#
|
| 5 |
# Expands #include directives in files in the directory. This is used
|
| 6 |
# to let task package pull in the contents of metapackages, keeping the
|
| 7 |
# contents up-to-date, w/o actually pulling in the metapackages themselves,
|
| 8 |
# since some metapackages are rather prone to breakage near release time.
|
| 9 |
|
| 10 |
my $dir=shift or die "no directory specified\n";
|
| 11 |
|
| 12 |
my %depends;
|
| 13 |
{
|
| 14 |
local $/="\n\n";
|
| 15 |
if (! open (AVAIL, "apt-cache dumpavail |")) {
|
| 16 |
warn "cannot real available info, so not exanding includes\n";
|
| 17 |
exit;
|
| 18 |
}
|
| 19 |
while (<AVAIL>) {
|
| 20 |
my ($package)=/Package:\s*(.*?)\n/;
|
| 21 |
my ($depends)=/Depends:\s*(.*?)\n/;
|
| 22 |
$depends{$package}=$depends;
|
| 23 |
}
|
| 24 |
close AVAIL;
|
| 25 |
}
|
| 26 |
|
| 27 |
use File::Find;
|
| 28 |
find(\&processfile, $dir);
|
| 29 |
|
| 30 |
sub processfile {
|
| 31 |
my $file=$_; # File::Find craziness.
|
| 32 |
$file eq 'po' && -d $file && ($File::Find::prune = 1);
|
| 33 |
return if $File::Find::dir=~/\.svn/;
|
| 34 |
return unless $file =~ /^[-+_.a-z0-9]+$/ and -f $file;
|
| 35 |
my @lines;
|
| 36 |
open (IN, $file) or die "$file: $!";
|
| 37 |
while (<IN>) {
|
| 38 |
if (/#\s*endinclude/) {
|
| 39 |
if ($skipping == 0) {
|
| 40 |
die "$file: #endinclude without #include\n";
|
| 41 |
}
|
| 42 |
$skipping=0;
|
| 43 |
}
|
| 44 |
|
| 45 |
push @lines, $_ unless $skipping == 1;
|
| 46 |
|
| 47 |
if (/^#\s*include\s+(\w+)/) {
|
| 48 |
my $pkg=$1;
|
| 49 |
if ($skipping) {
|
| 50 |
die "$file: nested includes near $_\n";
|
| 51 |
}
|
| 52 |
if (! exists $depends{$pkg}) {
|
| 53 |
warn "$file: #include $1 skipped; no such package. Leaving what was there alone.\n";
|
| 54 |
$skipping=-1;
|
| 55 |
}
|
| 56 |
else {
|
| 57 |
push @lines, "#Automatically added by doincludes.pl; do not edit.\n";
|
| 58 |
# Split deps and remove alternates and versioned
|
| 59 |
# deps. Include the metapackage on the list.
|
| 60 |
push @lines, map { s/[|(].*//; " $_\n" }
|
| 61 |
split(/,\s+/, $depends{$pkg}), $pkg;
|
| 62 |
$skipping=1;
|
| 63 |
}
|
| 64 |
}
|
| 65 |
}
|
| 66 |
close IN;
|
| 67 |
if ($skipping == 1) {
|
| 68 |
die "$file: #include without #endinclude";
|
| 69 |
}
|
| 70 |
|
| 71 |
open (OUT, ">$file") or die "$file: $!";
|
| 72 |
print OUT @lines;
|
| 73 |
close OUT;
|
| 74 |
}
|