History

scripts: get_feat.pl: use its implementation for list-arch.sh

Add support for the same output format as the bash script, and use its implementation instead of the previous one. I opted to do such patch in order to have a single script responsible for parsing Documentation/features and produce different outputs. As someone may rely on the past format, which is easy to parse it, get_feat.pl now gains a new command with the same output format as the previous script. As a side effect, the perl script is a lot faster, as it reads each file only once, instead of parsing files several times via a for command and grep commands inside it. This patch also changes the features list order to be case-insensitive, in order to better match the output of the existing script.

Mauro Carvalho Chehab committed 5 years ago

Commit ca908571 parent ba813f72 files · +66 −28Browse files

Showing the changes to scripts (1 of 2 files). Show all

Unified · Split

scripts/get_feat.pl+64−13
@@ -6,13 +6,18 @@ use Pod::Usage; · 5 unmodified lines
6use Getopt::Long;6use Getopt::Long;
7use File::Find;7use File::Find;
8use Fcntl ':mode';8use Fcntl ':mode';
9use Cwd 'abs_path';
9 10
10my $help;11my $help;
11my $man;12my $man;
12my $debug;13my $debug;
13my $arch;14my $arch;
14my $feat;15my $feat;
15my $prefix="Documentation/features";16
17my $basename = abs_path($0);
18$basename =~ s,/[^/]+$,/,;
19
20my $prefix=$basename . "../Documentation/features";
16 21
17GetOptions(22GetOptions(
18 "debug|d+" => \$debug,23 "debug|d+" => \$debug,
@@ -20,17 +25,19 @@ GetOptions( · 1 unmodified line
20 'help|?' => \$help,25 'help|?' => \$help,
21 'arch=s' => \$arch,26 'arch=s' => \$arch,
22 'feat=s' => \$feat,27 'feat=s' => \$feat,
28 'feature=s' => \$feat,
23 man => \$man29 man => \$man
24) or pod2usage(2);30) or pod2usage(2);
25 31
26pod2usage(1) if $help;32pod2usage(1) if $help;
27pod2usage(-exitstatus => 0, -verbose => 2) if $man;33pod2usage(-exitstatus => 0, -verbose => 2) if $man;
28 34
29pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2);35pod2usage(1) if (scalar @ARGV < 1 || @ARGV > 2);
30 36
31my ($cmd, $arg) = @ARGV;37my ($cmd, $arg) = @ARGV;
32 38
33pod2usage(2) if ($cmd ne "current" && $cmd ne "rest" && $cmd ne "validate");39pod2usage(2) if ($cmd ne "current" && $cmd ne "rest" && $cmd ne "validate"
40 && $cmd ne "ls" && $cmd ne "list");
34 41
35require Data::Dumper if ($debug);42require Data::Dumper if ($debug);
36 43
@@ -213,7 +220,7 @@ sub output_arch_table { · 176 unmodified lines
213 220
214 foreach my $name (sort {221 foreach my $name (sort {
215 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) ||222 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) ||
216 ($data{$a}->{name} cmp $data{$b}->{name})223 ("\L$a" cmp "\L$b")
217 } keys %data) {224 } keys %data) {
218 next if ($feat && $name ne $feat);225 next if ($feat && $name ne $feat);
219 226
@@ -222,7 +229,7 @@ sub output_arch_table { · 2 unmodified lines
222 printf "%-${max_size_name}s ", $name;229 printf "%-${max_size_name}s ", $name;
223 printf "%-${max_size_kconfig}s ", $data{$name}->{kconfig};230 printf "%-${max_size_kconfig}s ", $data{$name}->{kconfig};
224 printf "%-${max_size_status}s ", $arch_table{$arch};231 printf "%-${max_size_status}s ", $arch_table{$arch};
225 printf "%-${max_size_description}s\n", $data{$name}->{description};232 printf "%-s\n", $data{$name}->{description};
226 }233 }
227 234
228 print "=" x $max_size_subsys;235 print "=" x $max_size_subsys;
@@ -237,6 +244,31 @@ sub output_arch_table { · 8 unmodified lines
237 print "\n";244 print "\n";
238}245}
239 246
247#
248# list feature(s) for a given architecture
249#
250sub list_arch_features {
251 print "#\n# Kernel feature support matrix of the '$arch' architecture:\n#\n";
252
253 foreach my $name (sort {
254 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) ||
255 ("\L$a" cmp "\L$b")
256 } keys %data) {
257 next if ($feat && $name ne $feat);
258
259 my %arch_table = %{$data{$name}->{table}};
260
261 my $status = $arch_table{$arch};
262 $status = " " x ((4 - length($status)) / 2) . $status;
263
264 printf " %${max_size_subsys}s/ ", $data{$name}->{subsys};
265 printf "%-${max_size_name}s: ", $name;
266 printf "%-5s| ", $status;
267 printf "%${max_size_kconfig}s # ", $data{$name}->{kconfig};
268 printf " %s\n", $data{$name}->{description};
269 }
270}
271
240#272#
241# Output a feature on all architectures273# Output a feature on all architectures
242#274#
@@ -337,7 +369,7 @@ sub output_matrix { · 94 unmodified lines
337 my $cur_subsys = "";369 my $cur_subsys = "";
338 foreach my $name (sort {370 foreach my $name (sort {
339 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) or371 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) or
340 ($a cmp $b)372 ("\L$a" cmp "\L$b")
341 } keys %data) {373 } keys %data) {
342 374
343 if ($cur_subsys ne $data{$name}->{subsys}) {375 if ($cur_subsys ne $data{$name}->{subsys}) {
@@ -400,6 +432,17 @@ if ($cmd eq "current") { · 56 unmodified lines
400 $arch =~s/\s+$//;432 $arch =~s/\s+$//;
401}433}
402 434
435if ($cmd eq "ls" or $cmd eq "list") {
436 if (!$arch) {
437 $arch = qx(uname -m | sed 's/x86_64/x86/' | sed 's/i386/x86/');
438 $arch =~s/\s+$//;
439 }
440
441 list_arch_features;
442
443 exit;
444}
445
403if ($cmd ne "validate") {446if ($cmd ne "validate") {
404 if ($arch) {447 if ($arch) {
405 output_arch_table;448 output_arch_table;
@@ -418,18 +461,26 @@ get_feat.pl - parse the Linux Feature files and produce a ReST book. · 12 unmodified lines
418 461
419=head1 SYNOPSIS462=head1 SYNOPSIS
420 463
421B<get_feat.pl> [--debug] [--man] [--help] [--dir=<dir>]464B<get_feat.pl> [--debug] [--man] [--help] [--dir=<dir>] [--arch=<arch>]
422 [--arch=<arch>] [--feat=<feature>] <COMAND> [<ARGUMENT>]465 [--feature=<feature>|--feat=<feature>] <COMAND> [<ARGUMENT>]
423 466
424Where <COMMAND> can be:467Where <COMMAND> can be:
425 468
426=over 8469=over 8
427 470
428B<current> - output features for this machine's architecture471B<current> - output table in ReST compatible ASCII format
472 with features for this machine's architecture
473
474B<rest> - output table(s) in ReST compatible ASCII format
475 with features in ReST markup language. The output
476 is affected by --arch or --feat/--feature flags.
429 477
430B<rest> - output features in ReST markup language478B<validate> - validate the contents of the files under
479 Documentation/features.
431 480
432B<validate> - validate the feature contents481B<ls> or B<list> - list features for this machine's architecture,
482 using an easier to parse format.
483 The output is affected by --arch flag.
433 484
434=back485=back
435 486
@@ -442,9 +493,9 @@ B<validate> - validate the feature contents · 6 unmodified lines
442Output features for an specific architecture, optionally filtering for493Output features for an specific architecture, optionally filtering for
443a single specific feature.494a single specific feature.
444 495
445=item B<--feat>496=item B<--feat> or B<--feature>
446 497
447Output features for a single specific architecture.498Output features for a single specific feature.
448 499
449=item B<--dir>500=item B<--dir>
450 501