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.
Showing the changes to scripts (1 of 2 files). Show all
Unified · Split
| @@ -6,13 +6,18 @@ use Pod::Usage; · 5 unmodified lines | |||
| 6 | use Getopt::Long; | 6 | use Getopt::Long; |
| 7 | use File::Find; | 7 | use File::Find; |
| 8 | use Fcntl ':mode'; | 8 | use Fcntl ':mode'; |
| 9 | use Cwd 'abs_path'; | ||
| 9 | 10 | ||
| 10 | my $help; | 11 | my $help; |
| 11 | my $man; | 12 | my $man; |
| 12 | my $debug; | 13 | my $debug; |
| 13 | my $arch; | 14 | my $arch; |
| 14 | my $feat; | 15 | my $feat; |
| 15 | my $prefix="Documentation/features"; | 16 | |
| 17 | my $basename = abs_path($0); | ||
| 18 | $basename =~ s,/[^/]+$,/,; | ||
| 19 | |||
| 20 | my $prefix=$basename . "../Documentation/features"; | ||
| 16 | 21 | ||
| 17 | GetOptions( | 22 | GetOptions( |
| 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 => \$man | 29 | man => \$man |
| 24 | ) or pod2usage(2); | 30 | ) or pod2usage(2); |
| 25 | 31 | ||
| 26 | pod2usage(1) if $help; | 32 | pod2usage(1) if $help; |
| 27 | pod2usage(-exitstatus => 0, -verbose => 2) if $man; | 33 | pod2usage(-exitstatus => 0, -verbose => 2) if $man; |
| 28 | 34 | ||
| 29 | pod2usage(2) if (scalar @ARGV < 1 || @ARGV > 2); | 35 | pod2usage(1) if (scalar @ARGV < 1 || @ARGV > 2); |
| 30 | 36 | ||
| 31 | my ($cmd, $arg) = @ARGV; | 37 | my ($cmd, $arg) = @ARGV; |
| 32 | 38 | ||
| 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"); | ||
| 34 | 41 | ||
| 35 | require Data::Dumper if ($debug); | 42 | require 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 | # | ||
| 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 | |||
| 240 | # | 272 | # |
| 241 | # Output a feature on all architectures | 273 | # 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}) or | 371 | ($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 | ||
| 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 | |||
| 403 | if ($cmd ne "validate") { | 446 | if ($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 SYNOPSIS | 462 | =head1 SYNOPSIS |
| 420 | 463 | ||
| 421 | B<get_feat.pl> [--debug] [--man] [--help] [--dir=<dir>] | 464 | B<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 | ||
| 424 | Where <COMMAND> can be: | 467 | Where <COMMAND> can be: |
| 425 | 468 | ||
| 426 | =over 8 | 469 | =over 8 |
| 427 | 470 | ||
| 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. | ||
| 429 | 477 | ||
| 430 | B<rest> - output features in ReST markup language | 478 | B<validate> - validate the contents of the files under |
| 479 | Documentation/features. | ||
| 431 | 480 | ||
| 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. | ||
| 433 | 484 | ||
| 434 | =back | 485 | =back |
| 435 | 486 | ||
| @@ -442,9 +493,9 @@ B<validate> - validate the feature contents · 6 unmodified lines | |||
| 442 | Output features for an specific architecture, optionally filtering for | 493 | Output features for an specific architecture, optionally filtering for |
| 443 | a single specific feature. | 494 | a single specific feature. |
| 444 | 495 | ||
| 445 | =item B<--feat> | 496 | =item B<--feat> or B<--feature> |
| 446 | 497 | ||
| 447 | Output features for a single specific architecture. | 498 | Output features for a single specific feature. |
| 448 | 499 | ||
| 449 | =item B<--dir> | 500 | =item B<--dir> |
| 450 | 501 | ||