From 14de8476c311ee54c240b06d2a24f2e275edc5c0 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 3 Jan 2026 12:34:44 +0100 Subject: [PATCH] checksrc: replace bash starter with `checksrc-all.pl` To remove dependence on a shell script to start `checksrc.pl`. Fixes #1775 Closes #1778 --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 14 +++++++-- Makefile.am | 2 +- ci/checksrc-all.pl | 63 ++++++++++++++++++++++++++++++++++++++++ ci/checksrc.sh | 30 ------------------- 5 files changed, 76 insertions(+), 35 deletions(-) create mode 100755 ci/checksrc-all.pl delete mode 100755 ci/checksrc.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a296574..786dce28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: with: persist-credentials: false - name: 'checksrc' - run: ci/checksrc.sh + run: ci/checksrc-all.pl linters: name: 'linters' diff --git a/CMakeLists.txt b/CMakeLists.txt index a8169eaf..6c711f50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -538,8 +538,18 @@ if(BUILD_TESTING) endif() option(LINT "Check style while building" OFF) +option(LIBSSH2_BUILD_DOCS "Build man pages" ON) + +if(LINT OR LIBSSH2_BUILD_DOCS) + find_package(Perl) +endif() + if(LINT) - add_custom_target(lint ALL "./ci/checksrc.sh" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + add_custom_target(lint ALL + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/ci/checksrc-all.pl" + DEPENDS "${PROJECT_SOURCE_DIR}/ci/checksrc-all.pl" "${PROJECT_SOURCE_DIR}/ci/checksrc.pl" + ) if(BUILD_STATIC_LIBS) add_dependencies(${LIB_STATIC} lint) else() @@ -547,10 +557,8 @@ if(LINT) endif() endif() -option(LIBSSH2_BUILD_DOCS "Build man pages" ON) set(_build_docs FALSE) if(LIBSSH2_BUILD_DOCS) - find_package(Perl) if(PERL_FOUND) set(_build_docs TRUE) add_subdirectory(docs) diff --git a/Makefile.am b/Makefile.am index 0934fb81..cd6f8e7a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -81,4 +81,4 @@ gen-coverage: coverage: init-coverage build-coverage gen-coverage checksrc: - ci/checksrc.sh + ci/checksrc-all.pl diff --git a/ci/checksrc-all.pl b/ci/checksrc-all.pl new file mode 100755 index 00000000..4d73bbba --- /dev/null +++ b/ci/checksrc-all.pl @@ -0,0 +1,63 @@ +#!/usr/bin/env perl +# Copyright (C) Viktor Szakats +# +# SPDX-License-Identifier: curl + +use strict; +use warnings; + +use File::Basename; +use File::Find; +use Cwd 'abs_path'; + +my @options = ( + "-i4", "-m79", + "-AFIXME", "-AERRNOVAR", "-AFOPENMODE", "-ATYPEDEFSTRUCT", + "-aaccept", + "-aatoi", + "-acalloc", + "-aCreateFileA", + "-afclose", + "-afopen", + "-afprintf", + "-afree", + "-amalloc", + "-aprintf", + "-arealloc", + "-arecv", + "-asend", + "-asnprintf", + "-asocket", + "-asocketpair", + "-astrdup", + "-astrtok", + "-astrtol", + "-avsnprintf", +); + +my @files; +if(system('git rev-parse --is-inside-work-tree >/dev/null 2>&1') == 0) { + @files = `git ls-files '*.[ch]'`; +} +else { + find(sub { if(/\.[ch]$/) { push(@files, $File::Find::name) } }, ('.')); +} +if(@ARGV) { + find(sub { if(/\.[ch]$/) { push(@files, $File::Find::name) } }, @ARGV); +} + +@files = grep !/\/CMakeFiles\//, @files; +@files = map { dirname($_) } @files; +my @dirs = sort { $a cmp $b } keys %{{ map { $_ => 1 } @files }}; + +my $scripts_dir = dirname(abs_path($0)); +my $anyfailed = 0; + +for my $dir (@dirs) { + @files = glob("$dir/*.[ch]"); + if(@files && system("$scripts_dir/checksrc.pl", @options, @files) != 0) { + $anyfailed = 1; + } +} + +exit $anyfailed; diff --git a/ci/checksrc.sh b/ci/checksrc.sh deleted file mode 100755 index 32ccbf87..00000000 --- a/ci/checksrc.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) The libssh2 project and its contributors. -# SPDX-License-Identifier: BSD-3-Clause - -set -eu - -cd "$(dirname "$0")"/.. - -git ls-files '*.[ch]' '*.cc' | xargs -n1 \ -ci/checksrc.pl -i4 -m79 -AFIXME -AERRNOVAR -AFOPENMODE -ATYPEDEFSTRUCT \ - -aaccept \ - -aatoi \ - -acalloc \ - -aCreateFileA \ - -afclose \ - -afopen \ - -afprintf \ - -afree \ - -amalloc \ - -aprintf \ - -arealloc \ - -arecv \ - -asend \ - -asnprintf \ - -asocket \ - -asocketpair \ - -astrdup \ - -astrtok \ - -astrtol \ - -avsnprintf