You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

75 lines
1.9 KiB

  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. my $dir=shift or die "no directory specified\n";
  10. my %depends;
  11. {
  12. local $/="\n\n";
  13. if (! open (AVAIL, "apt-cache dumpavail |")) {
  14. warn "cannot real available info, so not exanding includes\n";
  15. exit;
  16. }
  17. while (<AVAIL>) {
  18. my ($package)=/Package:\s*(.*?)\n/;
  19. my ($depends)=/Depends:\s*(.*?)\n/;
  20. $depends{$package}=$depends;
  21. }
  22. close AVAIL;
  23. }
  24. use File::Find;
  25. find(\&processfile, $dir);
  26. sub processfile {
  27. my $file=$_; # File::Find craziness.
  28. $file eq 'po' && -d $file && ($File::Find::prune = 1);
  29. return if $File::Find::dir=~/\.svn/;
  30. return unless $file =~ /^[-+_.a-z0-9]+$/ and -f $file;
  31. my @lines;
  32. open (IN, $file) or die "$file: $!";
  33. while (<IN>) {
  34. if (/#\s*endinclude/) {
  35. if ($skipping == 0) {
  36. die "$file: #endinclude without #include\n";
  37. }
  38. $skipping=0;
  39. }
  40. push @lines, $_ unless $skipping == 1;
  41. if (/^#\s*include\s+(\w+)/) {
  42. my $pkg=$1;
  43. if ($skipping) {
  44. die "$file: nested includes near $_\n";
  45. }
  46. if (! exists $depends{$pkg}) {
  47. warn "$file: #include $1 skipped; no such package. Leaving what was there alone.\n";
  48. $skipping=-1;
  49. }
  50. else {
  51. push @lines, "#Automatically added by doincludes.pl; do not edit.\n";
  52. # Split deps and remove alternates and versioned
  53. # deps. Include the metapackage on the list.
  54. push @lines, map { s/[|(].*//; " $_\n" }
  55. split(/,\s+/, $depends{$pkg}), $pkg;
  56. $skipping=1;
  57. }
  58. }
  59. }
  60. close IN;
  61. if ($skipping == 1) {
  62. die "$file: #include without #endinclude";
  63. }
  64. open (OUT, ">$file") or die "$file: $!";
  65. print OUT @lines;
  66. close OUT;
  67. }