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
66 use Getopt::Long;
77 use File::Find;
88 use Fcntl ':mode';
9+use Cwd 'abs_path';
910
1011 my $help;
1112 my $man;
1213 my $debug;
1314 my $arch;
1415 my $feat;
15−my $prefix="Documentation/features";
16+
17+my $basename = abs_path($0);
18+$basename =~ s,/[^/]+$,/,;
19+
20+my $prefix=$basename . "../Documentation/features";
1621
1722 GetOptions(
1823 "debug|d+" => \$debug,
@@ -20,17 +25,19 @@ GetOptions( · 1 unmodified line
2025 'help|?' => \$help,
2126 'arch=s' => \$arch,
2227 'feat=s' => \$feat,
28+ 'feature=s' => \$feat,
2329 man => \$man
2430 ) or pod2usage(2);
2531
2632 pod2usage(1) if $help;
2733 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
2834
29−pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2);
35+pod2usage(1) if (scalar @ARGV < 1 || @ARGV > 2);
3036
3137 my ($cmd, $arg) = @ARGV;
3238
33−pod2usage(2) if ($cmd ne "current" && $cmd ne "rest" && $cmd ne "validate");
39+pod2usage(2) if ($cmd ne "current" && $cmd ne "rest" && $cmd ne "validate"
40+ && $cmd ne "ls" && $cmd ne "list");
3441
3542 require Data::Dumper if ($debug);
3643
@@ -213,7 +220,7 @@ sub output_arch_table { · 176 unmodified lines
213220
214221 foreach my $name (sort {
215222 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) ||
216− ($data{$a}->{name} cmp $data{$b}->{name})
223+ ("\L$a" cmp "\L$b")
217224 } keys %data) {
218225 next if ($feat && $name ne $feat);
219226
@@ -222,7 +229,7 @@ sub output_arch_table { · 2 unmodified lines
222229 printf "%-${max_size_name}s ", $name;
223230 printf "%-${max_size_kconfig}s ", $data{$name}->{kconfig};
224231 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};
226233 }
227234
228235 print "=" x $max_size_subsys;
@@ -237,6 +244,31 @@ sub output_arch_table { · 8 unmodified lines
237244 print "\n";
238245 }
239246
247+#
248+# list feature(s) for a given architecture
249+#
250+sub 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+
240272 #
241273 # Output a feature on all architectures
242274 #
@@ -337,7 +369,7 @@ sub output_matrix { · 94 unmodified lines
337369 my $cur_subsys = "";
338370 foreach my $name (sort {
339371 ($data{$a}->{subsys} cmp $data{$b}->{subsys}) or
340− ($a cmp $b)
372+ ("\L$a" cmp "\L$b")
341373 } keys %data) {
342374
343375 if ($cur_subsys ne $data{$name}->{subsys}) {
@@ -400,6 +432,17 @@ if ($cmd eq "current") { · 56 unmodified lines
400432 $arch =~s/\s+$//;
401433 }
402434
435+if ($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+
403446 if ($cmd ne "validate") {
404447 if ($arch) {
405448 output_arch_table;
@@ -418,18 +461,26 @@ get_feat.pl - parse the Linux Feature files and produce a ReST book. · 12 unmodified lines
418461
419462 =head1 SYNOPSIS
420463
421−B<get_feat.pl> [--debug] [--man] [--help] [--dir=<dir>]
422− [--arch=<arch>] [--feat=<feature>] <COMAND> [<ARGUMENT>]
464+B<get_feat.pl> [--debug] [--man] [--help] [--dir=<dir>] [--arch=<arch>]
465+ [--feature=<feature>|--feat=<feature>] <COMAND> [<ARGUMENT>]
423466
424467 Where <COMMAND> can be:
425468
426469 =over 8
427470
428−B<current> - output features for this machine's architecture
471+B<current> - output table in ReST compatible ASCII format
472+ with features for this machine's architecture
473+
474+B<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.
429477
430−B<rest> - output features in ReST markup language
478+B<validate> - validate the contents of the files under
479+ Documentation/features.
431480
432−B<validate> - validate the feature contents
481+B<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.
433484
434485 =back
435486
@@ -442,9 +493,9 @@ B<validate> - validate the feature contents · 6 unmodified lines
442493 Output features for an specific architecture, optionally filtering for
443494 a single specific feature.
444495
445−=item B<--feat>
496+=item B<--feat> or B<--feature>
446497
447−Output features for a single specific architecture.
498+Output features for a single specific feature.
448499
449500 =item B<--dir>
450501