metadata.pm 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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-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. priority => 999,
  82. packages => []
  83. };
  84. $1 =~ /^DEVICE_/ and $target->{has_devices} = 1;
  85. push @{$target->{profiles}}, $profile;
  86. };
  87. /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
  88. /^Target-Profile-Priority:\s*(\d+)\s*$/ and do {
  89. $profile->{priority} = $1;
  90. $target->{sort} = 1;
  91. };
  92. /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
  93. /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE);
  94. }
  95. close FILE;
  96. foreach my $target (@target) {
  97. if (@{$target->{subtargets}} > 0) {
  98. $target->{profiles} = [];
  99. next;
  100. }
  101. @{$target->{profiles}} > 0 or $target->{profiles} = [
  102. {
  103. id => 'Default',
  104. name => 'Default',
  105. packages => []
  106. }
  107. ];
  108. $target->{sort} and @{$target->{profiles}} = sort {
  109. $a->{priority} <=> $b->{priority} or
  110. $a->{name} cmp $b->{name};
  111. } @{$target->{profiles}};
  112. }
  113. return @target;
  114. }
  115. sub clear_packages() {
  116. %subdir = ();
  117. %preconfig = ();
  118. %package = ();
  119. %srcpackage = ();
  120. %category = ();
  121. %features = ();
  122. %overrides = ();
  123. }
  124. sub parse_package_metadata($) {
  125. my $file = shift;
  126. my $pkg;
  127. my $feature;
  128. my $makefile;
  129. my $preconfig;
  130. my $subdir;
  131. my $src;
  132. my $override;
  133. my %ignore = map { $_ => 1 } @ignore;
  134. open FILE, "<$file" or do {
  135. warn "Cannot open '$file': $!\n";
  136. return undef;
  137. };
  138. while (<FILE>) {
  139. chomp;
  140. /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
  141. $makefile = $1;
  142. $subdir = $2;
  143. $src = $3;
  144. $subdir =~ s/^package\///;
  145. $subdir{$src} = $subdir;
  146. $srcpackage{$src} = [];
  147. $override = "";
  148. undef $pkg;
  149. };
  150. /^Override: \s*(.+?)\s*$/ and do {
  151. $override = $1;
  152. $overrides{$src} = 1;
  153. };
  154. next unless $src;
  155. /^Package:\s*(.+?)\s*$/ and do {
  156. undef $feature;
  157. $pkg = {};
  158. $pkg->{ignore} = $ignore{$src};
  159. $pkg->{src} = $src;
  160. $pkg->{makefile} = $makefile;
  161. $pkg->{name} = $1;
  162. $pkg->{title} = "";
  163. $pkg->{depends} = [];
  164. $pkg->{mdepends} = [];
  165. $pkg->{builddepends} = [];
  166. $pkg->{buildtypes} = [];
  167. $pkg->{subdir} = $subdir;
  168. $pkg->{tristate} = 1;
  169. $pkg->{override} = $override;
  170. $package{$1} = $pkg;
  171. push @{$srcpackage{$src}}, $pkg;
  172. };
  173. /^Feature:\s*(.+?)\s*$/ and do {
  174. undef $pkg;
  175. $feature = {};
  176. $feature->{name} = $1;
  177. $feature->{priority} = 0;
  178. };
  179. $feature and do {
  180. /^Target-Name:\s*(.+?)\s*$/ and do {
  181. $features{$1} or $features{$1} = [];
  182. push @{$features{$1}}, $feature unless $ignore{$src};
  183. };
  184. /^Target-Title:\s*(.+?)\s*$/ and $feature->{target_title} = $1;
  185. /^Feature-Priority:\s*(\d+)\s*$/ and $feature->{priority} = $1;
  186. /^Feature-Name:\s*(.+?)\s*$/ and $feature->{title} = $1;
  187. /^Feature-Description:/ and $feature->{description} = get_multiline(\*FILE, "\t\t\t");
  188. next;
  189. };
  190. next unless $pkg;
  191. /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
  192. /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
  193. /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
  194. /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
  195. /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
  196. /^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
  197. /^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
  198. /^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
  199. /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
  200. /^Provides: \s*(.+)\s*$/ and do {
  201. my @vpkg = split /\s+/, $1;
  202. foreach my $vpkg (@vpkg) {
  203. $package{$vpkg} or $package{$vpkg} = {
  204. name => $vpkg,
  205. vdepends => [],
  206. src => $src,
  207. subdir => $subdir,
  208. makefile => $makefile
  209. };
  210. push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
  211. }
  212. };
  213. /^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
  214. /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
  215. /^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
  216. /^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
  217. /^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
  218. /^Default-Variant: .*/ and $pkg->{variant_default} = 1;
  219. /^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
  220. /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
  221. /^Build-Depends\/(\w+): \s*(.+)\s*$/ and $pkg->{"builddepends/$1"} = [ split /\s+/, $2 ];
  222. /^Build-Types:\s*(.+)\s*$/ and $pkg->{buildtypes} = [ split /\s+/, $1 ];
  223. /^Repository:\s*(.+?)\s*$/ and $pkg->{repository} = $1;
  224. /^Category: \s*(.+)\s*$/ and do {
  225. $pkg->{category} = $1;
  226. defined $category{$1} or $category{$1} = {};
  227. defined $category{$1}->{$src} or $category{$1}->{$src} = [];
  228. push @{$category{$1}->{$src}}, $pkg;
  229. };
  230. /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
  231. /^Type: \s*(.+)\s*$/ and do {
  232. $pkg->{type} = [ split /\s+/, $1 ];
  233. undef $pkg->{tristate};
  234. foreach my $type (@{$pkg->{type}}) {
  235. $type =~ /ipkg/ and $pkg->{tristate} = 1;
  236. }
  237. };
  238. /^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
  239. /^Prereq-Check:/ and $pkg->{prereq} = 1;
  240. /^Preconfig:\s*(.+)\s*$/ and do {
  241. my $pkgname = $pkg->{name};
  242. $preconfig{$pkgname} or $preconfig{$pkgname} = {};
  243. if (exists $preconfig{$pkgname}->{$1}) {
  244. $preconfig = $preconfig{$pkgname}->{$1};
  245. } else {
  246. $preconfig = {
  247. id => $1
  248. };
  249. $preconfig{$pkgname}->{$1} = $preconfig unless $ignore{$src};
  250. }
  251. };
  252. /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
  253. /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
  254. /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
  255. }
  256. close FILE;
  257. return 1;
  258. }
  259. 1;