checkpatch: Document config file in help
PATCH 1/2 checkpatch: Document config file in help
---
This can be squashed to the following commit.
I added it separately just in case if following patch will be rejected.
Kind regards,
Petr
scripts/checkpatch.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +7 -3
@@ -57,6 +57,7 @@ my %ignore_type = (); my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; +my $def_configuration_dirs = ".:$ENV{HOME}:.scripts"; my $max_line_length = 100; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0;
@@ -146,6 +147,9 @@ Options: -h, --help, --version display this help and exit When FILE is - read standard input. + +Script searches for a configuration file $configuration_file in path: +$def_configuration_dirs EOM exit($exitcode);
@@ -237,7 +241,7 @@ sub list_types { exit($exitcode); } -my $conf = which_conf($configuration_file); +my $conf = which_conf($configuration_file, $def_configuration_dirs); if (-f $conf) { my @conf_args; open(my $conffile, '<', "$conf")
@@ -1530,9 +1534,9 @@ sub which { } sub which_conf { - my ($conf) = @_; + my ($conf, $dirs) = @_; - foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) { + foreach my $path (split(/:/, $dirs)) { if (-e "$path/$conf") { return "$path/$conf"; }
Signature · 1 line
2.51.0
PATCH 2/2 checkpatch: Add --conf-dir option
This allows to directly use project configuration file for projects which vendored checkpatch.pl (e.g. LTP or u-boot).
Options from the configuration file has been read before processing command line options with Getopt::Long since the start (000d1cc1829f9) because options read from config file needs to be unshifted from command line arguments (@ARGV) before processing with Getopt::Long. Therefore parse --conf-dir with direct reading @ARGV.
---
@ARGV can be probably processed cleaner.
Kind regards,
Petr
scripts/checkpatch.pl | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +29 -2
@@ -58,6 +58,7 @@ my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; my $def_configuration_dirs = ".:$ENV{HOME}:.scripts"; +my $configuration_dir = ""; my $max_line_length = 100; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0;
@@ -144,12 +145,14 @@ Options: is a terminal ('auto'). Default is 'auto'. --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default ${CONFIG_}) + --conf-dir=DIR directory with $configuration_file configuration file + (default:$def_configuration_dirs) -h, --help, --version display this help and exit When FILE is - read standard input. Script searches for a configuration file $configuration_file in path: -$def_configuration_dirs +$def_configuration_dirs (can be overwritten by --conf-dir) EOM exit($exitcode);
@@ -241,7 +244,31 @@ sub list_types { exit($exitcode); } -my $conf = which_conf($configuration_file, $def_configuration_dirs); +# parse --conf-dir before the other options +my @argv; +while (@ARGV) { + my $arg = shift @ARGV; + if ($arg eq '--conf-dir') { + $configuration_dir = shift @ARGV; + die "--conf-dir requires value" unless ($configuration_dir); + } elsif ($arg =~ /^--conf-dir=(.+)$/) { + $configuration_dir = $1; + die "--conf-dir requires value" unless ($configuration_dir); + } else { + push @argv, $arg; + } +} +@ARGV = @argv; + +my $conf; +if ($configuration_dir) { + die "Dir. $configuration_dir does not exist" unless (-d $configuration_dir); + $conf = "$configuration_dir/$configuration_file"; + die "File $conf does not exist" unless (-f $conf); +} else { + $conf = which_conf($configuration_file, $def_configuration_dirs); +} + if (-f $conf) { my @conf_args; open(my $conffile, '<', "$conf")
Signature · 1 line
2.51.0
Re: [PATCH 2/2] checkpatch: Add --conf-dir option
Hi,
gently ping about the patchset. We can keep the functionality out of tree, but I suppose more project which use checkpatch.pl would benefit from it.
Kind regards,
Petr
Quoted 80 lines
This allows to directly use project configuration file for projects which vendored checkpatch.pl (e.g. LTP or u-boot).
Options from the configuration file has been read before processing command line options with
Getopt::Longsince the start (000d1cc1829f9) because options read from config file needs to be unshifted from command line arguments (@ARGV) before processing withGetopt::Long. Therefore parse --conf-dir with direct reading @ARGV.Signed-off-by Petr Vorel <[email protected]>---
@ARGV can be probably processed cleaner.Kind regards,
Petrscripts/checkpatch.pl | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)scripts/checkpatch.pl +29
-2@@ -58,6 +58,7 @@ my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; my $def_configuration_dirs = ".:$ENV{HOME}:.scripts"; +my $configuration_dir = ""; my $max_line_length = 100; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0;@@ -144,12 +145,14 @@ Options: is a terminal ('auto'). Default is 'auto'. --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default ${CONFIG_}) + --conf-dir=DIR directory with $configuration_file configuration file + (default:$def_configuration_dirs) -h, --help, --version display this help and exit When FILE is - read standard input. Script searches for a configuration file $configuration_file in path: -$def_configuration_dirs +$def_configuration_dirs (can be overwritten by --conf-dir) EOM exit($exitcode);@@ -241,7 +244,31 @@ sub list_types { exit($exitcode); } -my $conf = which_conf($configuration_file, $def_configuration_dirs); +# parse --conf-dir before the other options +my @argv; +while (@ARGV) { + my $arg = shift @ARGV; + if ($arg eq '--conf-dir') { + $configuration_dir = shift @ARGV; + die "--conf-dir requires value" unless ($configuration_dir); + } elsif ($arg =~ /^--conf-dir=(.+)$/) { + $configuration_dir = $1; + die "--conf-dir requires value" unless ($configuration_dir); + } else { + push @argv, $arg; + } +} +@ARGV = @argv; + +my $conf; +if ($configuration_dir) { + die "Dir. $configuration_dir does not exist" unless (-d $configuration_dir); + $conf = "$configuration_dir/$configuration_file"; + die "File $conf does not exist" unless (-f $conf); +} else { + $conf = which_conf($configuration_file, $def_configuration_dirs); +} + if (-f $conf) { my @conf_args; open(my $conffile, '<', "$conf")
Re: [PATCH 2/2] checkpatch: Add --conf-dir option
In reply to Petr VorelQuoted 9 lines · Petr Vorel
```
This allows to directly use project configuration file for projects which vendored checkpatch.pl (e.g. LTP or u-boot).Options from the configuration file has been read before processing command line options with
Getopt::Longsince the start (000d1cc1829f9) because options read from config file needs to be unshifted from command line arguments (@ARGV) before processing withGetopt::Long. Therefore parse --conf-dir with direct reading @ARGV.
nack.
Extend 'sub which_conf {' and the perhaps the code that uses it if you really need this capability.
Though I think it's not all that useful.
Re: [PATCH 2/2] checkpatch: Add --conf-dir option
Quoted 11 lines · Petr Vorel
Quoted 9 lines
```
This allows to directly use project configuration file for projects which vendored checkpatch.pl (e.g. LTP or u-boot).Options from the configuration file has been read before processing command line options with
Getopt::Longsince the start (000d1cc1829f9) because options read from config file needs to be unshifted from command line arguments (@ARGV) before processing withGetopt::Long. Therefore parse --conf-dir with direct reading @ARGV.
Quoted 4 lines
nack.
Extend 'sub
which_conf{' and the perhaps the code that uses it if you really need this capability.
Thanks for a hint. If there is a chance it will be accepted I'll have look on it. We would certainly appreciated not having to carry yet another checkpatch.pl patch in LTP.
Quoted 1 line
Though I think it's not all that useful.
We use LTP in makefile targets run from various subdirectories. For that we define our checkpatch.pl options (--ignore list and others) in certain Makefile. Then we have b4 configuration, where we also use checkpatch.pl options.
Mixing cd to rootdir and passing path to the sources is of course doable (to reach config file in .scripts in project root directory) but quite ugly.
Also, allowing to pass a configuration file (quite common feature for any software) would allow to run checkpatch.pl with different configs for different projects.
Kind regards,
Petr
Joe Perches
maintainerRe: [PATCH 2/2] checkpatch: Add --conf-dir option
Quoted 3 lines · Petr Vorel
Quoted 2 lines · Petr Vorel
Quoted 2 lines
This allows to directly use project configuration file for projects which vendored checkpatch.pl (e.g. LTP or u-boot).
[]
Quoted 6 lines
Quoted 2 lines
Extend 'sub
which_conf{' and the perhaps the code that uses it if you really need this capability.Thanks for a hint. If there is a chance it will be accepted I'll have look on it. We would certainly appreciated not having to carry yet another checkpatch.pl patch in LTP.
[]
Quoted 1 line
Quoted 1 line
Though I think it's not all that useful.
[]
Quoted 10 lines
We use LTP in makefile targets run from various subdirectories. For that we define our checkpatch.pl options (--ignore list and others) in certain
Makefile. Then we have b4 configuration, where we also use checkpatch.pl options.Mixing cd to rootdir and passing path to the sources is of course doable (to reach config file in .scripts in project root directory) but quite ugly.
Also, allowing to pass a configuration file (quite common feature for any software) would allow to run checkpatch.pl with different configs for different projects.
Right now the HOME environment variable is used in which_conf. Perhaps prepend a CHECKPATCH_CONFIG environment where the right <somedir>.checkpatch.conf would be found?
Maybe something like the below and executed with something like
$ CHECKPATCH_CONFIG=<dir> <path_to>checkpatch.pl etc... ---
scripts/checkpatch.pl +5 -1
@@ -1532,7 +1532,11 @@ sub which { sub which_conf { my ($conf) = @_; - foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) { + my $env_config_path = 'CHECKPATCH_CONFIG'; + my $paths = $ENV{$env_config_path} . ':' if exists($ENV{$env_config_path}); + $paths .= ".:$ENV{'HOME'}:.scripts"; + + foreach my $path (split(/:/, $paths)) { if (-e "$path/$conf") { return "$path/$conf"; }
Re: [PATCH 2/2] checkpatch: Add --conf-dir option
Quoted 18 lines · Petr Vorel
Quoted 3 lines · Petr Vorel
Quoted 2 lines
Quoted 2 lines
This allows to directly use project configuration file for projects which vendored checkpatch.pl (e.g. LTP or u-boot).
[]
Quoted 6 lines
Quoted 2 lines
Extend 'sub
which_conf{' and the perhaps the code that uses it if you really need this capability.Thanks for a hint. If there is a chance it will be accepted I'll have look on it. We would certainly appreciated not having to carry yet another checkpatch.pl patch in LTP.
[]
Quoted 1 line
Quoted 1 line
Though I think it's not all that useful.
[]
Quoted 3 lines
We use LTP in makefile targets run from various subdirectories. For that we define our checkpatch.pl options (--ignore list and others) in certain
Makefile. Then we have b4 configuration, where we also use checkpatch.pl options.
Quoted 8 lines
Quoted 6 lines
Mixing cd to rootdir and passing path to the sources is of course doable (to reach config file in .scripts in project root directory) but quite ugly.
Also, allowing to pass a configuration file (quite common feature for any software) would allow to run checkpatch.pl with different configs for different projects.
Right now the HOME environment variable is used in
which_conf.
Yes (and that's not enough for the case I described).
Quoted 2 lines
Perhaps prepend a
CHECKPATCH_CONFIGenvironment where the right <somedir>.checkpatch.conf would be found?
Sure, if you prefer not processing @ARGV twice (and modifying it), using environment variable works as well. The reason I touched @ARGV was to be slightly more convenient for user with a bit more complicated code. But when variable is properly documented, there is practically no difference (if I ignore the fact that in the future somebody writes bash-completion support, which will ignore environment variables).
Anyway, thanks for being open to the idea. I'll send a patch based on the code you proposed.
Kind regards,
Petr
Quoted 20 lines
Maybe something like the below and executed with something like
$ CHECKPATCH_CONFIG=<dir> <path_to>checkpatch.pl etc... ---scripts/checkpatch.pl +5
-1@@ -1532,7 +1532,11 @@ sub which { sub which_conf { my ($conf) = @_; - foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) { + my $env_config_path = 'CHECKPATCH_CONFIG'; + my $paths = $ENV{$env_config_path} . ':' if exists($ENV{$env_config_path}); + $paths .= ".:$ENV{'HOME'}:.scripts"; + + foreach my $path (split(/:/, $paths)) { if (-e "$path/$conf") { return "$path/$conf"; }