This repository has been archived by the owner on Sep 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mklists.pl
executable file
·119 lines (110 loc) · 3.41 KB
/
mklists.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/perl
# ABSTRACT: Generate machine parsable package lists for depchase tooling.
use strict;
use warnings;
use autodie;
use Getopt::Std;
use List::Util 1.33 qw/none/;
use Text::CSV_XS qw/csv/;
use Data::Dumper;
use File::Path qw/make_path/;
my $module = undef;
my $package = undef;
my $rationale = undef;
my $arches = undef;
my $sources = undef;
my @arches = ();
my @sources = ();
my %modules;
my %packages;
# Hash table with all known arches
my %arches = map { $_ => 1 }
qw/aarch64 armv7hl i686 ppc64 ppc64le x86_64 s390x/;
sub HELP_MESSAGE {
print "Usage: mklists.pl -t topdir -r REPO_NAME\n";
print "Select what module lists should be generated.\n";
exit;
}
my %opts;
getopts('r:t:', \%opts);
my $repo = $opts{r} or HELP_MESSAGE;
my $topdir = $opts{t} or HELP_MESSAGE;
open my $fh, '<', "${topdir}/${repo}/README.md";
while (<$fh>) {
chomp;
if (/^#{3}\s\`(?<module>[^`]+)\`$/) {
$module = $+{module};
$package = undef;
$modules{$module} = {};
next;
}
if (/^\*\s\`(?<package>[^`]+)\`
(\s?\(
(?<sources>\`.+?\`)?
(?:;\s?)?
(?<arches>\*.+?\*)?
\))?
(?:,\s?(?<rationale>.*))?$/x && defined $module) {
$package = $+{package};
$rationale = $+{rationale} // '';
$arches = $+{arches};
$sources = $+{sources};
@sources = defined $sources
? ( split /,\s?/, $sources =~ s/\`//gr )
: ( $package );
@arches = defined $arches
? ( split /,\s?/, $arches =~ s/^\*|\*$//gr )
: ();
for (@arches) {
$arches{$_} = 1;
}
for (@sources) {
$modules{$module}->{$_} = {
rationale => $modules{$module}->{$_}->{rationale}
? $modules{$module}->{$_}->{rationale} . "; ${rationale}"
: $rationale,
arches => [ @arches ],
};
}
$packages{$package} = {
count => defined $packages{$package}
? $packages{$package} + 1
: 1,
arches => [ @arches ],
};
} elsif (defined $module && defined $package && ! /^$/) {
s/^\s+|\s+$//g;
for my $src (@sources) {
$modules{$module}->{$src}->{rationale} .= ' '
if $modules{$module}->{$src}->{rationale};
$modules{$module}->{$src}->{rationale} .= $_;
}
} else {
$package = undef;
@arches = ();
@sources = ();
}
}
close $fh;
make_path "${topdir}/modules" unless -d "${topdir}/modules";
for my $module (keys %modules) {
mkdir "${topdir}/modules/${module}" unless -d "${topdir}/modules/${module}";
for my $arch (keys %arches) {
mkdir "${topdir}/modules/${module}/${arch}" unless -d "${topdir}/modules/${module}/${arch}";
open $fh, '>', "${topdir}/modules/${module}/${arch}/toplevel-binary-packages.txt";
for my $pkg (keys %{ $modules{$module} } ) {
next if @{ $modules{$module}->{$pkg}->{arches} } and
not ($arch ~~ $modules{$module}->{$pkg}->{arches});
print {$fh} "$pkg\n";
}
close $fh;
}
}
for $module (keys %modules) {
csv in => [
map
{ [ $_, $modules{$module}->{$_}->{rationale} ] }
sort keys %{ $modules{$module} }
],
out => "${topdir}/modules/${module}/${module}.csv";
}