Search code examples
linux-kernelcode-formatting

Configuration file for checkpatch.pl tool


According to the explanation from this source, the .checkpatch.conf file that specifies the configuration options for checkpatch.pl tool must be in the top-level directory of the project. Would it be possible that we put checkpatch.conf on some other location and somehow specify the path to it in checkpatch.pl (or somewhere else)?

I tried to do it the following way in checkpatch.pl file:

my $configuration_file = "<path_to_the>/.checkpatch.conf";

but to no avail.


Solution

  • So, in addition to (or perhaps instead of) changing the value assigned to the $configuration_file variable, you need to slightly alter the which_conf subroutine.

    The original sub routine is:

    sub which_conf {
        my ($conf) = @_;
    
        foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
            if (-e "$path/$conf") {
                return "$path/$conf";
            }
        }
    
        return "";
    }
    

    this takes a configuration file name as input and returns the path to the first occurrence of the file found in a list of predefined directories. Here's how it works:

    • It receives the filename ($conf) as an argument.
    • It iterates over a list of directories (".:$ENV{HOME}:.scripts"), separated by colons.
    • For each directory, it checks if the configuration file exists by appending the directory and filename together ("$path/$conf") and using the -e file test operator.
    • If the file is found, the subroutine immediately returns the path to the file.
    • If no file is found in any of the directories, an empty string is returned.

    So it's likely the reason that simply changing the value of $configuration_file does not work is because it's getting evaluated as /some/base/path/<path_to_the>/.checkpatch.conf which will not exist.

    I would try instead of altering $configuration_file variable at all, adding the base path you want it to search to find your checkpatch.conf file using a colon as a delimiter.

    foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts:./my/sub/path"))
    

    or

    foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts:/my/full/path"))