metadata.pm 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 parse_target_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 confstr($) {
  24. my $conf = shift;
  25. $conf =~ tr#/\.\-/#___#;
  26. return $conf;
  27. }
  28. sub parse_target_metadata($) {
  29. my $file = shift;
  30. my ($target, @target, $profile);
  31. my %target;
  32. my $makefile;
  33. open FILE, "<$file" or do {
  34. warn "Can't open file '$file': $!\n";
  35. return;
  36. };
  37. while (<FILE>) {
  38. chomp;
  39. /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and $makefile = $1;
  40. /^Target:\s*(.+)\s*$/ and do {
  41. my $name = $1;
  42. $target = {
  43. id => $name,
  44. board => $name,
  45. makefile => $makefile,
  46. boardconf => confstr($name),
  47. conf => confstr($name),
  48. profiles => [],
  49. features => [],
  50. depends => [],
  51. subtargets => []
  52. };
  53. push @target, $target;
  54. $target{$name} = $target;
  55. if ($name =~ /([^\/]+)\/([^\/]+)/) {
  56. push @{$target{$1}->{subtargets}}, $2;
  57. $target->{board} = $1;
  58. $target->{boardconf} = confstr($1);
  59. $target->{subtarget} = 1;
  60. $target->{parent} = $target{$1};
  61. }
  62. };
  63. /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
  64. /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1;
  65. /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
  66. /^Target-Arch-Packages:\s*(.+)\s*$/ and $target->{arch_packages} = $1;
  67. /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
  68. /^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ];
  69. /^Target-Description:/ and $target->{desc} = get_multiline(*FILE);
  70. /^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1;
  71. /^CPU-Type:\s*(.+)\s*$/ and $target->{cputype} = $1;
  72. /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
  73. /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
  74. /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
  75. /^Default-Subtarget:\s*(.+)\s*$/ and $target->{def_subtarget} = $1;
  76. /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
  77. /^Target-Profile:\s*(.+)\s*$/ and do {
  78. $profile = {
  79. id => $1,
  80. name => $1,
  81. packages => []
  82. };
  83. push @{$target->{profiles}}, $profile;
  84. };
  85. /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
  86. /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
  87. /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE);
  88. /^Target-Profile-Config:/ and $profile->{config} = get_multiline(*FILE, "\t");
  89. /^Target-Profile-Kconfig:/ and $profile->{kconfig} = 1;
  90. }
  91. close FILE;
  92. foreach my $target (@target) {
  93. if (@{$target->{subtargets}} > 0) {
  94. $target->{profiles} = [];
  95. next;
  96. }
  97. @{$target->{profiles}} > 0 or $target->{profiles} = [
  98. {
  99. id => 'Default',
  100. name => 'Default',
  101. packages => []
  102. }
  103. ];
  104. }
  105. return @target;
  106. }
  107. sub clear_packages() {
  108. %subdir = ();
  109. %preconfig = ();
  110. %package = ();
  111. %srcpackage = ();
  112. %category = ();
  113. %features = ();
  114. %overrides = ();
  115. }
  116. sub parse_package_metadata($) {
  117. my $file = shift;
  118. my $pkg;
  119. my $feature;
  120. my $makefile;
  121. my $preconfig;
  122. my $subdir;
  123. my $src;
  124. my $override;
  125. open FILE, "<$file" or do {
  126. warn "Cannot open '$file': $!\n";
  127. return undef;
  128. };
  129. while (<FILE>) {
  130. chomp;
  131. /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
  132. $makefile = $1;
  133. $subdir = $2;
  134. $src = $3;
  135. $subdir =~ s/^package\///;
  136. $subdir{$src} = $subdir;
  137. $srcpackage{$src} = [];
  138. $override = "";
  139. undef $pkg;
  140. };
  141. /^Override: \s*(.+?)\s*$/ and do {
  142. $override = $1;
  143. $overrides{$src} = 1;
  144. };
  145. next unless $src;
  146. /^Package:\s*(.+?)\s*$/ and do {
  147. undef $feature;
  148. $pkg = {};
  149. $pkg->{src} = $src;
  150. $pkg->{makefile} = $makefile;
  151. $pkg->{name} = $1;
  152. $pkg->{title} = "";
  153. $pkg->{depends} = [];
  154. $pkg->{mdepends} = [];
  155. $pkg->{builddepends} = [];
  156. $pkg->{buildtypes} = [];
  157. $pkg->{subdir} = $subdir;
  158. $pkg->{tristate} = 1;
  159. $pkg->{override} = $override;
  160. $package{$1} = $pkg;
  161. push @{$srcpackage{$src}}, $pkg;
  162. };
  163. /^Feature:\s*(.+?)\s*$/ and do {
  164. undef $pkg;
  165. $feature = {};
  166. $feature->{name} = $1;
  167. $feature->{priority} = 0;
  168. };
  169. $feature and do {
  170. /^Target-Name:\s*(.+?)\s*$/ and do {
  171. $features{$1} or $features{$1} = [];
  172. push @{$features{$1}}, $feature;
  173. };
  174. /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
  175. /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
  176. /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
  177. /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
  178. next;
  179. };
  180. next unless $pkg;
  181. /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
  182. /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
  183. /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
  184. /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
  185. /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
  186. /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
  187. /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
  188. /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
  189. /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
  190. /^Provides: \s*(.+)\s*$/ and do {
  191. my @vpkg = split /\s+/, $1;
  192. foreach my $vpkg (@vpkg) {
  193. $package{$vpkg} or $package{$vpkg} = {
  194. name => $vpkg,
  195. vdepends => [],
  196. src => $src,
  197. subdir => $subdir,
  198. makefile => $makefile
  199. };
  200. push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
  201. }
  202. };
  203. /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
  204. /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
  205. /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
  206. /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
  207. /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
  208. /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
  209. /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
  210. /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
  211. /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg->{"builddepends/$1"} = [ split /\s+/, $2 ];
  212. /^Build-Types:\s*(.+)\s*$/ and $pkg->{buildtypes} = [ split /\s+/, $1 ];
  213. /^Feed:\s*(.+?)\s*$/ and $pkg->{feed} = $1;
  214. /^Category: \s*(.+)\s*$/ and do {
  215. $pkg->{category} = $1;
  216. defined $category{$1} or $category{$1} = {};
  217. defined $category{$1}->{$src} or $category{$1}->{$src} = [];
  218. push @{$category{$1}->{$src}}, $pkg;
  219. };
  220. /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
  221. /^Type: \s*(.+)\s*$/ and do {
  222. $pkg->{type} = [ split /\s+/, $1 ];
  223. undef $pkg->{tristate};
  224. foreach my $type (@{$pkg->{type}}) {
  225. $type =~ /ipkg/ and $pkg->{tristate} = 1;
  226. }
  227. };
  228. /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
  229. /^Prereq-Check:/ and $pkg->{prereq} = 1;
  230. /^Preconfig:\s*(.+)\s*$/ and do {
  231. my $pkgname = $pkg->{name};
  232. $preconfig{$pkgname} or $preconfig{$pkgname} = {};
  233. if (exists $preconfig{$pkgname}->{$1}) {
  234. $preconfig = $preconfig{$pkgname}->{$1};
  235. } else {
  236. $preconfig = {
  237. id => $1
  238. };
  239. $preconfig{$pkgname}->{$1} = $preconfig;
  240. }
  241. };
  242. /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
  243. /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
  244. /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
  245. }
  246. close FILE;
  247. return 1;
  248. }
  249. 1;