2007-09-23 02:39:01 +00:00
|
|
|
package metadata;
|
|
|
|
use base 'Exporter';
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2018-01-08 11:31:03 +00:00
|
|
|
our @EXPORT = qw(%package %vpackage %srcpackage %category %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
|
2007-09-23 02:39:01 +00:00
|
|
|
|
|
|
|
our %package;
|
2018-01-08 11:17:30 +00:00
|
|
|
our %vpackage;
|
2007-09-23 02:39:01 +00:00
|
|
|
our %srcpackage;
|
|
|
|
our %category;
|
2015-02-09 12:09:43 +00:00
|
|
|
our %overrides;
|
2016-01-10 16:35:16 +00:00
|
|
|
our @ignore;
|
2007-09-23 02:39:01 +00:00
|
|
|
|
2017-06-13 09:03:38 +00:00
|
|
|
our %usernames;
|
|
|
|
our %groupnames;
|
|
|
|
our %userids;
|
|
|
|
our %groupids;
|
|
|
|
|
2007-09-23 02:39:01 +00:00
|
|
|
sub get_multiline {
|
|
|
|
my $fh = shift;
|
|
|
|
my $prefix = shift;
|
|
|
|
my $str;
|
|
|
|
while (<$fh>) {
|
|
|
|
last if /^@@/;
|
|
|
|
$str .= (($_ and $prefix) ? $prefix . $_ : $_);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $str ? $str : "";
|
|
|
|
}
|
|
|
|
|
2015-03-15 11:07:40 +00:00
|
|
|
sub confstr($) {
|
|
|
|
my $conf = shift;
|
|
|
|
$conf =~ tr#/\.\-/#___#;
|
|
|
|
return $conf;
|
|
|
|
}
|
|
|
|
|
2017-06-13 09:03:38 +00:00
|
|
|
sub parse_package_metadata_usergroup($$$$$) {
|
|
|
|
my $makefile = shift;
|
|
|
|
my $typename = shift;
|
|
|
|
my $names = shift;
|
|
|
|
my $ids = shift;
|
|
|
|
my $spec = shift;
|
|
|
|
my $name;
|
|
|
|
my $id;
|
|
|
|
|
|
|
|
# the regex for name is taken from is_valid_name() of package shadow
|
|
|
|
if ($spec =~ /^([a-z_][a-z0-9_-]*\$?)$/) {
|
|
|
|
$name = $spec;
|
|
|
|
$id = -1;
|
|
|
|
} elsif ($spec =~ /^([a-z_][a-z0-9_-]*\$?)=(\d+)$/) {
|
|
|
|
$name = $1;
|
|
|
|
$id = $2;
|
|
|
|
} else {
|
|
|
|
warn "$makefile: invalid $typename spec $spec\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($id =~ /^[1-9]\d*$/) {
|
|
|
|
if ($id >= 65536) {
|
|
|
|
warn "$makefile: $typename $name id $id >= 65536";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (not exists $ids->{$id}) {
|
|
|
|
$ids->{$id} = {
|
|
|
|
name => $name,
|
|
|
|
makefile => $makefile,
|
|
|
|
};
|
|
|
|
} elsif ($ids->{$id}{name} ne $name) {
|
|
|
|
warn "$makefile: $typename $name id $id is already taken by $ids->{$id}{makefile}\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} elsif ($id != -1) {
|
|
|
|
warn "$makefile: $typename $name has invalid id $id\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not exists $names->{$name}) {
|
|
|
|
$names->{$name} = {
|
|
|
|
id => $id,
|
|
|
|
makefile => $makefile,
|
|
|
|
};
|
|
|
|
} elsif ($names->{$name}{id} != $id) {
|
|
|
|
warn "$makefile: id of $typename $name collides with that defined defined in $names->{$name}{makefile}\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-03-15 11:07:40 +00:00
|
|
|
sub parse_target_metadata($) {
|
|
|
|
my $file = shift;
|
|
|
|
my ($target, @target, $profile);
|
|
|
|
my %target;
|
2015-03-15 11:08:01 +00:00
|
|
|
my $makefile;
|
2015-03-15 11:07:40 +00:00
|
|
|
|
|
|
|
open FILE, "<$file" or do {
|
|
|
|
warn "Can't open file '$file': $!\n";
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
while (<FILE>) {
|
|
|
|
chomp;
|
2015-03-15 11:08:01 +00:00
|
|
|
/^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and $makefile = $1;
|
2015-03-15 11:07:40 +00:00
|
|
|
/^Target:\s*(.+)\s*$/ and do {
|
|
|
|
my $name = $1;
|
|
|
|
$target = {
|
|
|
|
id => $name,
|
|
|
|
board => $name,
|
2015-03-15 11:08:01 +00:00
|
|
|
makefile => $makefile,
|
2015-03-15 11:07:40 +00:00
|
|
|
boardconf => confstr($name),
|
|
|
|
conf => confstr($name),
|
|
|
|
profiles => [],
|
|
|
|
features => [],
|
|
|
|
depends => [],
|
|
|
|
subtargets => []
|
|
|
|
};
|
|
|
|
push @target, $target;
|
|
|
|
$target{$name} = $target;
|
|
|
|
if ($name =~ /([^\/]+)\/([^\/]+)/) {
|
|
|
|
push @{$target{$1}->{subtargets}}, $2;
|
|
|
|
$target->{board} = $1;
|
|
|
|
$target->{boardconf} = confstr($1);
|
|
|
|
$target->{subtarget} = 1;
|
|
|
|
$target->{parent} = $target{$1};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
|
|
|
|
/^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
|
|
|
|
/^Target-Arch-Packages:\s*(.+)\s*$/ and $target->{arch_packages} = $1;
|
|
|
|
/^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
|
|
|
|
/^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ];
|
|
|
|
/^Target-Description:/ and $target->{desc} = get_multiline(*FILE);
|
|
|
|
/^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1;
|
|
|
|
/^CPU-Type:\s*(.+)\s*$/ and $target->{cputype} = $1;
|
|
|
|
/^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
|
2019-04-27 17:13:07 +00:00
|
|
|
/^Linux-Testing-Version:\s*(.+)\s*$/ and $target->{testing_version} = $1;
|
2015-03-15 11:07:40 +00:00
|
|
|
/^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
|
|
|
|
/^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
|
|
|
|
/^Default-Subtarget:\s*(.+)\s*$/ and $target->{def_subtarget} = $1;
|
|
|
|
/^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
|
|
|
|
/^Target-Profile:\s*(.+)\s*$/ and do {
|
|
|
|
$profile = {
|
|
|
|
id => $1,
|
|
|
|
name => $1,
|
2019-03-06 13:45:15 +00:00
|
|
|
has_image_metadata => 0,
|
2019-03-11 04:32:29 +00:00
|
|
|
supported_devices => [],
|
2016-05-10 12:43:46 +00:00
|
|
|
priority => 999,
|
2019-08-13 10:33:47 +00:00
|
|
|
packages => [],
|
|
|
|
default => "y if TARGET_ALL_PROFILES"
|
2015-03-15 11:07:40 +00:00
|
|
|
};
|
2016-05-22 20:02:31 +00:00
|
|
|
$1 =~ /^DEVICE_/ and $target->{has_devices} = 1;
|
2015-03-15 11:07:40 +00:00
|
|
|
push @{$target->{profiles}}, $profile;
|
|
|
|
};
|
2016-05-11 17:17:42 +00:00
|
|
|
/^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
|
2019-03-06 13:45:15 +00:00
|
|
|
/^Target-Profile-hasImageMetadata:\s*(\d+)\s*$/ and $profile->{has_image_metadata} = $1;
|
2019-03-11 04:32:29 +00:00
|
|
|
/^Target-Profile-SupportedDevices:\s*(.+)\s*$/ and $profile->{supported_devices} = [ split(/\s+/, $1) ];
|
2016-05-11 17:17:42 +00:00
|
|
|
/^Target-Profile-Priority:\s*(\d+)\s*$/ and do {
|
|
|
|
$profile->{priority} = $1;
|
2016-05-10 12:43:46 +00:00
|
|
|
$target->{sort} = 1;
|
|
|
|
};
|
2015-03-15 11:07:40 +00:00
|
|
|
/^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
|
|
|
|
/^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE);
|
2019-08-13 10:33:47 +00:00
|
|
|
/^Target-Profile-Default:\s*(.+)\s*$/ and $profile->{default} = $1;
|
2015-03-15 11:07:40 +00:00
|
|
|
}
|
|
|
|
close FILE;
|
|
|
|
foreach my $target (@target) {
|
|
|
|
if (@{$target->{subtargets}} > 0) {
|
|
|
|
$target->{profiles} = [];
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
@{$target->{profiles}} > 0 or $target->{profiles} = [
|
|
|
|
{
|
|
|
|
id => 'Default',
|
|
|
|
name => 'Default',
|
|
|
|
packages => []
|
|
|
|
}
|
|
|
|
];
|
2016-05-13 14:31:58 +00:00
|
|
|
|
|
|
|
$target->{sort} and @{$target->{profiles}} = sort {
|
|
|
|
$a->{priority} <=> $b->{priority} or
|
|
|
|
$a->{name} cmp $b->{name};
|
|
|
|
} @{$target->{profiles}};
|
2015-03-15 11:07:40 +00:00
|
|
|
}
|
|
|
|
return @target;
|
|
|
|
}
|
|
|
|
|
2007-09-23 02:39:01 +00:00
|
|
|
sub clear_packages() {
|
|
|
|
%package = ();
|
2018-01-08 11:17:30 +00:00
|
|
|
%vpackage = ();
|
2007-09-23 02:39:01 +00:00
|
|
|
%srcpackage = ();
|
|
|
|
%category = ();
|
2015-02-09 12:09:43 +00:00
|
|
|
%overrides = ();
|
2017-06-13 09:03:38 +00:00
|
|
|
%usernames = ();
|
|
|
|
%groupnames = ();
|
2007-09-23 02:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_package_metadata($) {
|
|
|
|
my $file = shift;
|
|
|
|
my $pkg;
|
|
|
|
my $src;
|
2015-02-09 12:09:43 +00:00
|
|
|
my $override;
|
2016-01-10 16:35:16 +00:00
|
|
|
my %ignore = map { $_ => 1 } @ignore;
|
2007-09-23 02:39:01 +00:00
|
|
|
|
|
|
|
open FILE, "<$file" or do {
|
|
|
|
warn "Cannot open '$file': $!\n";
|
|
|
|
return undef;
|
|
|
|
};
|
|
|
|
while (<FILE>) {
|
|
|
|
chomp;
|
2018-01-06 18:28:52 +00:00
|
|
|
/^Source-Makefile: \s*((?:package\/)?((?:.+\/)?([^\/]+))\/Makefile)\s*$/ and do {
|
2018-01-06 17:01:25 +00:00
|
|
|
$src = {
|
|
|
|
makefile => $1,
|
2018-01-06 18:28:52 +00:00
|
|
|
path => $2,
|
2018-01-06 17:01:25 +00:00
|
|
|
name => $3,
|
|
|
|
ignore => $ignore{$3},
|
2018-01-04 18:52:18 +00:00
|
|
|
packages => [],
|
2018-01-06 12:53:42 +00:00
|
|
|
buildtypes => [],
|
2018-01-06 13:49:08 +00:00
|
|
|
builddepends => [],
|
2018-01-04 18:52:18 +00:00
|
|
|
};
|
2018-01-06 17:01:25 +00:00
|
|
|
$srcpackage{$3} = $src;
|
2015-02-09 12:09:43 +00:00
|
|
|
$override = "";
|
2007-09-23 02:39:01 +00:00
|
|
|
undef $pkg;
|
|
|
|
};
|
2015-02-09 12:09:43 +00:00
|
|
|
/^Override: \s*(.+?)\s*$/ and do {
|
|
|
|
$override = $1;
|
2018-01-06 17:01:25 +00:00
|
|
|
$overrides{$src->{name}} = 1;
|
2015-02-09 12:09:43 +00:00
|
|
|
};
|
2008-08-16 17:00:50 +00:00
|
|
|
next unless $src;
|
2007-09-23 02:39:01 +00:00
|
|
|
/^Package:\s*(.+?)\s*$/ and do {
|
|
|
|
$pkg = {};
|
|
|
|
$pkg->{src} = $src;
|
|
|
|
$pkg->{name} = $1;
|
2009-05-04 18:50:58 +00:00
|
|
|
$pkg->{title} = "";
|
2007-09-23 02:39:01 +00:00
|
|
|
$pkg->{depends} = [];
|
2011-04-05 19:03:51 +00:00
|
|
|
$pkg->{mdepends} = [];
|
2018-01-11 17:38:42 +00:00
|
|
|
$pkg->{provides} = [$1];
|
2007-09-29 01:21:56 +00:00
|
|
|
$pkg->{tristate} = 1;
|
2015-02-09 12:09:43 +00:00
|
|
|
$pkg->{override} = $override;
|
2007-09-23 02:39:01 +00:00
|
|
|
$package{$1} = $pkg;
|
2018-01-06 17:01:25 +00:00
|
|
|
push @{$src->{packages}}, $pkg;
|
2018-01-08 11:17:30 +00:00
|
|
|
|
|
|
|
$vpackage{$1} or $vpackage{$1} = [];
|
|
|
|
unshift @{$vpackage{$1}}, $pkg;
|
2007-09-23 02:39:01 +00:00
|
|
|
};
|
2018-01-06 17:01:25 +00:00
|
|
|
/^Build-Depends: \s*(.+)\s*$/ and $src->{builddepends} = [ split /\s+/, $1 ];
|
|
|
|
/^Build-Depends\/(\w+): \s*(.+)\s*$/ and $src->{"builddepends/$1"} = [ split /\s+/, $2 ];
|
|
|
|
/^Build-Types:\s*(.+)\s*$/ and $src->{buildtypes} = [ split /\s+/, $1 ];
|
2009-10-17 22:11:21 +00:00
|
|
|
next unless $pkg;
|
2007-09-23 02:39:01 +00:00
|
|
|
/^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
|
2019-01-18 11:43:06 +00:00
|
|
|
/^ABIVersion: \s*(.+)\s*$/ and $pkg->{abiversion} = $1;
|
2007-09-23 02:39:01 +00:00
|
|
|
/^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
|
|
|
|
/^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
|
|
|
|
/^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
|
|
|
|
/^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
|
2009-03-01 09:35:53 +00:00
|
|
|
/^Source: \s*(.+)\s*$/ and $pkg->{source} = $1;
|
2014-10-26 16:57:33 +00:00
|
|
|
/^License: \s*(.+)\s*$/ and $pkg->{license} = $1;
|
|
|
|
/^LicenseFiles: \s*(.+)\s*$/ and $pkg->{licensefiles} = $1;
|
2007-09-23 02:39:01 +00:00
|
|
|
/^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
|
|
|
|
/^Provides: \s*(.+)\s*$/ and do {
|
|
|
|
my @vpkg = split /\s+/, $1;
|
2018-01-11 17:38:42 +00:00
|
|
|
@{$pkg->{provides}} = ($pkg->{name}, @vpkg);
|
2007-09-23 02:39:01 +00:00
|
|
|
foreach my $vpkg (@vpkg) {
|
2018-09-05 15:29:25 +00:00
|
|
|
next if ($vpkg eq $pkg->{name});
|
2018-01-08 11:17:30 +00:00
|
|
|
$vpackage{$vpkg} or $vpackage{$vpkg} = [];
|
|
|
|
push @{$vpackage{$vpkg}}, $pkg;
|
2007-09-23 02:39:01 +00:00
|
|
|
}
|
|
|
|
};
|
2011-04-05 19:03:51 +00:00
|
|
|
/^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];
|
2007-09-23 02:39:01 +00:00
|
|
|
/^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
|
2014-10-05 16:41:33 +00:00
|
|
|
/^Conflicts: \s*(.+)\s*$/ and $pkg->{conflicts} = [ split /\s+/, $1 ];
|
2011-07-02 06:49:09 +00:00
|
|
|
/^Hidden: \s*(.+)\s*$/ and $pkg->{hidden} = 1;
|
2010-01-23 08:28:15 +00:00
|
|
|
/^Build-Variant: \s*([\w\-]+)\s*/ and $pkg->{variant} = $1;
|
2014-09-23 10:41:15 +00:00
|
|
|
/^Default-Variant: .*/ and $pkg->{variant_default} = 1;
|
2009-01-13 02:02:56 +00:00
|
|
|
/^Build-Only: \s*(.+)\s*$/ and $pkg->{buildonly} = 1;
|
2016-04-13 13:33:53 +00:00
|
|
|
/^Repository:\s*(.+?)\s*$/ and $pkg->{repository} = $1;
|
2007-09-23 02:39:01 +00:00
|
|
|
/^Category: \s*(.+)\s*$/ and do {
|
|
|
|
$pkg->{category} = $1;
|
|
|
|
defined $category{$1} or $category{$1} = {};
|
2018-01-06 17:01:25 +00:00
|
|
|
defined $category{$1}{$src->{name}} or $category{$1}{$src->{name}} = [];
|
|
|
|
push @{$category{$1}{$src->{name}}}, $pkg;
|
2007-09-23 02:39:01 +00:00
|
|
|
};
|
|
|
|
/^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline(*FILE, "\t\t ");
|
2007-09-29 01:21:56 +00:00
|
|
|
/^Type: \s*(.+)\s*$/ and do {
|
|
|
|
$pkg->{type} = [ split /\s+/, $1 ];
|
|
|
|
undef $pkg->{tristate};
|
|
|
|
foreach my $type (@{$pkg->{type}}) {
|
|
|
|
$type =~ /ipkg/ and $pkg->{tristate} = 1;
|
|
|
|
}
|
|
|
|
};
|
2009-03-03 14:03:37 +00:00
|
|
|
/^Config:\s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline(*FILE, "\t");
|
2007-09-23 02:39:01 +00:00
|
|
|
/^Prereq-Check:/ and $pkg->{prereq} = 1;
|
2017-06-13 09:03:38 +00:00
|
|
|
/^Require-User:\s*(.*?)\s*$/ and do {
|
|
|
|
my @ugspecs = split /\s+/, $1;
|
|
|
|
|
|
|
|
for my $ugspec (@ugspecs) {
|
|
|
|
my @ugspec = split /:/, $ugspec, 2;
|
2018-02-26 06:10:32 +00:00
|
|
|
if ($ugspec[0]) {
|
|
|
|
parse_package_metadata_usergroup($src->{makefile}, "user", \%usernames, \%userids, $ugspec[0]) or return 0;
|
|
|
|
}
|
|
|
|
if ($ugspec[1]) {
|
2018-01-06 17:01:25 +00:00
|
|
|
parse_package_metadata_usergroup($src->{makefile}, "group", \%groupnames, \%groupids, $ugspec[1]) or return 0;
|
2017-06-13 09:03:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2007-09-23 02:39:01 +00:00
|
|
|
}
|
|
|
|
close FILE;
|
2007-12-14 00:33:25 +00:00
|
|
|
return 1;
|
2007-09-23 02:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|