metadata.pm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package metadata;
  2. use base 'Exporter';
  3. use strict;
  4. use warnings;
  5. our @EXPORT = qw(%package %srcpackage %category %subdir %preconfig %features clear_packages parse_package_metadata get_multiline);
  6. our %package;
  7. our %preconfig;
  8. our %srcpackage;
  9. our %category;
  10. our %subdir;
  11. our %features;
  12. sub get_multiline {
  13. my $fh = shift;
  14. my $prefix = shift;
  15. my $str;
  16. while (<$fh>) {
  17. last if /^@@/;
  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. %features = ();
  29. }
  30. sub parse_package_metadata($) {
  31. my $file = shift;
  32. my $pkg;
  33. my $feature;
  34. my $makefile;
  35. my $preconfig;
  36. my $subdir;
  37. my $src;
  38. open FILE, "<$file" or do {
  39. warn "Cannot open '$file': $!\n";
  40. return undef;
  41. };
  42. while (<FILE>) {
  43. chomp;
  44. /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
  45. $makefile = $1;
  46. $subdir = $2;
  47. $src = $3;
  48. $subdir =~ s/^package\///;
  49. $subdir{$src} = $subdir;
  50. $srcpackage{$src} = [];
  51. undef $pkg;
  52. };
  53. next unless $src;
  54. /^Package:\s*(.+?)\s*$/ and do {
  55. undef $feature;
  56. $pkg = {};
  57. $pkg->{src} = $src;
  58. $pkg->{makefile} = $makefile;
  59. $pkg->{name} = $1;
  60. $pkg->{title} = "";
  61. $pkg->{depends} = [];
  62. $pkg->{mdepends} = [];
  63. $pkg->{builddepends} = [];
  64. $pkg->{buildtypes} = [];
  65. $pkg->{subdir} = $subdir;
  66. $pkg->{tristate} = 1;
  67. $package{$1} = $pkg;
  68. push @{$srcpackage{$src}}, $pkg;
  69. };
  70. /^Feature:\s*(.+?)\s*$/ and do {
  71. undef $pkg;
  72. $feature = {};
  73. $feature->{name} = $1;
  74. $feature->{priority} = 0;
  75. };
  76. $feature and do {
  77. /^Target-Name:\s*(.+?)\s*$/ and do {
  78. $features{$1} or $features{$1} = [];
  79. push @{$features{$1}}, $feature;
  80. };
  81. /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
  82. /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
  83. /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
  84. /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
  85. next;
  86. };
  87. next unless $pkg;
  88. /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
  89. /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
  90. /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
  91. /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
  92. /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
  93. /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
  94. /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
  95. /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
  96. /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
  97. /^Provides: \s*(.+)\s*$/ and do {
  98. my @vpkg = split /\s+/, $1;
  99. foreach my $vpkg (@vpkg) {
  100. $package{$vpkg} or $package{$vpkg} = {
  101. name => $vpkg,
  102. vdepends => [],
  103. src => $src,
  104. subdir => $subdir,
  105. makefile => $makefile
  106. };
  107. push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
  108. }
  109. };
  110. /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
  111. /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
  112. /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
  113. /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
  114. /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
  115. /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
  116. /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
  117. /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
  118. /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg->{"builddepends/$1"} = [ split /\s+/, $2 ];
  119. /^Build-Types:\s*(.+)\s*$/ and $pkg->{buildtypes} = [ split /\s+/, $1 ];
  120. /^Feed:\s*(.+?)\s*$/ and $pkg->{feed} = $1;
  121. /^Category: \s*(.+)\s*$/ and do {
  122. $pkg->{category} = $1;
  123. defined $category{$1} or $category{$1} = {};
  124. defined $category{$1}->{$src} or $category{$1}->{$src} = [];
  125. push @{$category{$1}->{$src}}, $pkg;
  126. };
  127. /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
  128. /^Type: \s*(.+)\s*$/ and do {
  129. $pkg->{type} = [ split /\s+/, $1 ];
  130. undef $pkg->{tristate};
  131. foreach my $type (@{$pkg->{type}}) {
  132. $type =~ /ipkg/ and $pkg->{tristate} = 1;
  133. }
  134. };
  135. /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
  136. /^Prereq-Check:/ and $pkg->{prereq} = 1;
  137. /^Preconfig:\s*(.+)\s*$/ and do {
  138. my $pkgname = $pkg->{name};
  139. $preconfig{$pkgname} or $preconfig{$pkgname} = {};
  140. if (exists $preconfig{$pkgname}->{$1}) {
  141. $preconfig = $preconfig{$pkgname}->{$1};
  142. } else {
  143. $preconfig = {
  144. id => $1
  145. };
  146. $preconfig{$pkgname}->{$1} = $preconfig;
  147. }
  148. };
  149. /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
  150. /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
  151. /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
  152. }
  153. close FILE;
  154. return 1;
  155. }
  156. 1;