Hello all*,*

While working on a patch I ran into an issue where the formatting check
script (solenv/clang-format/check-last-commit) fails when *clang-format 18*
is already installed.
*> Problem*

Even though clang-format-18 is correctly installed and available in PATH the
script exits with:

 core git:(master) solenv/clang-format/check-last-commit
Use of uninitialized value $clang_format in -x at
solenv/clang-format/check-last-commit line 43, <FILES> line 9.
solenv/clang-format/check-last-commit: ERROR: no clang-format 5.0.0 was found.

*> Environment*

core git:(master) clang-format-18 --version
Ubuntu clang-format version 18.1.3 (1ubuntu1)

*> Root Cause*

After inspecting solenv/clang-format/ClangFormat.pm it seems the issue
comes from overly strict version checking:

-> The script hardcodes the required version to 5.0.0.

-> The regex used to detect the version doesn’t match Ubuntu’s output
format (e.g., Ubuntu clang-format version 18.1.3 (1ubuntu1)).
*> Proposed Solution*

Instead of requiring an exact version match we could allow any *clang-format
version ≥ 5.0.0*.
example:

sub get_wanted_version()
{
    return "5.0.0";  # minimum required version
}

sub is_matching_clang_format_version($$)

{

    my ($clang_format, $version) = @_;

    if (! -x $clang_format)

    {

        return 0;

    }


    # Allow versions >= 5.0.0 instead of exactly 5.0.0

    my $output = `'$clang_format' -version`;

    return $output =~ /clang-format version
([0-9]+)\.([0-9]+)\.([0-9]+)/ && $1 >= 5;

}

This would:

-> Maintain the minimum required version (5.0.0+)

-> Support newer versions available in modern distributions

Would this be an acceptable approach? Should I go ahead and file a bug
report for this or is there an existing plan to modernize the clang-format
detection logic?

Best regards,
Prawesh Mandal

Reply via email to