metadata.pm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package metadata;
  2. use base 'Exporter';
  3. use strict;
  4. use warnings;
  5. our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig clear_packages parse_package_metadata get_multiline);
  6. our %package;
  7. our %preconfig;
  8. our %srcpackage;
  9. our %category;
  10. our %subdir;
  11. sub get_multiline {
  12. my $fh = shift;
  13. my $prefix = shift;
  14. my $str;
  15. while (<$fh>) {
  16. last if /^@@/;
  17. s/^\s*//g;
  18. $str .= (($_ and $prefix) ? $prefix . $_ : $_);
  19. }
  20. return $str ? $str : "";
  21. }
  22. sub clear_packages() {
  23. %subdir = ();
  24. %preconfig = ();
  25. %package = ();
  26. %srcpackage = ();
  27. %category = ();
  28. }
  29. sub parse_package_metadata($) {
  30. my $file = shift;
  31. my $pkg;
  32. my $makefile;
  33. my $preconfig;
  34. my $subdir;
  35. my $src;
  36. open FILE, "<$file" or do {
  37. warn "Cannot open '$file': $!\n";
  38. return undef;
  39. };
  40. while (<FILE>) {
  41. chomp;
  42. /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
  43. $makefile = $1;
  44. $subdir = $2;
  45. $src = $3;
  46. $subdir =~ s/^package\///;
  47. $subdir{$src} = $subdir;
  48. $srcpackage{$src} = [];
  49. undef $pkg;
  50. };
  51. /^Package:\s*(.+?)\s*$/ and do {
  52. $pkg = {};
  53. $pkg->{src} = $src;
  54. $pkg->{makefile} = $makefile;
  55. $pkg->{name} = $1;
  56. $pkg->{default} = "m if ALL";
  57. $pkg->{depends} = [];
  58. $pkg->{builddepends} = [];
  59. $pkg->{subdir} = $subdir;
  60. $package{$1} = $pkg;
  61. push @{$srcpackage{$src}}, $pkg;
  62. };
  63. /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
  64. /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
  65. /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
  66. /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
  67. /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
  68. /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
  69. /^Provides: \s*(.+)\s*$/ and do {
  70. my @vpkg = split /\s+/, $1;
  71. foreach my $vpkg (@vpkg) {
  72. $package{$vpkg} or $package{$vpkg} = { vdepends => [] };
  73. push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
  74. }
  75. };
  76. /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
  77. /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
  78. /^Category: \s*(.+)\s*$/ and do {
  79. $pkg->{category} = $1;
  80. defined $category{$1} or $category{$1} = {};
  81. defined $category{$1}->{$src} or $category{$1}->{$src} = [];
  82. push @{$category{$1}->{$src}}, $pkg;
  83. };
  84. /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
  85. /^Config: \s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE);
  86. /^Prereq-Check:/ and $pkg->{prereq} = 1;
  87. /^Preconfig:\s*(.+)\s*$/ and do {
  88. my $pkgname = $pkg->{name};
  89. $preconfig{$pkgname} or $preconfig{$pkgname} = {};
  90. if (exists $preconfig{$pkgname}->{$1}) {
  91. $preconfig = $preconfig{$pkgname}->{$1};
  92. } else {
  93. $preconfig = {
  94. id => $1
  95. };
  96. $preconfig{$pkgname}->{$1} = $preconfig;
  97. }
  98. };
  99. /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
  100. /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
  101. /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
  102. }
  103. close FILE;
  104. return %category;
  105. }
  106. 1;