metadata.pm 4.9 KB

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