metadata.pm 7.6 KB

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