]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc-all: rewrite in Perl, remove `checksrc.bat`
authorViktor Szakats <commit@vsz.me>
Thu, 10 Jul 2025 07:55:02 +0000 (09:55 +0200)
committerViktor Szakats <commit@vsz.me>
Fri, 11 Jul 2025 10:28:46 +0000 (12:28 +0200)
`checksrc.bat` was outdated and required Perl for `checksrc.pl` anyway.
Rewrite `checksrc-all.sh` in Perl, making it usable in envs without
a POSIX shell.

Closes #17882

.github/workflows/checksrc.yml
.github/workflows/distcheck.yml
Makefile.am
projects/checksrc.bat [deleted file]
scripts/Makefile.am
scripts/checksrc-all.pl [new file with mode: 0755]
scripts/checksrc-all.sh [deleted file]

index d1771ef05c083e6e14d716f357bb919e0e71caf5..f7835499ebb75d4861b85f53ed1d19fd6cab4aea 100644 (file)
@@ -43,7 +43,7 @@ jobs:
           persist-credentials: false
 
       - name: 'check'
-        run: scripts/checksrc-all.sh
+        run: scripts/checksrc-all.pl
 
   codespell-cmakelint-pytype-ruff:
     name: 'codespell, cmakelint, pytype, ruff'
index 955eae998dfa2b6281aa7f176b67d0a88b832a78..90db76ad4be16b866bfcbd18e56fb4f1e15b9098 100644 (file)
@@ -113,7 +113,7 @@ jobs:
           make test-ci
           make install
           popd
-          scripts/checksrc-all.sh
+          scripts/checksrc-all.pl
 
   verify-out-of-tree-cmake:
     name: 'CM out-of-tree'
index f96ad249f8e2aef8ab46ea544a38d458be2a6b43..08d59e807f8cb6881776de566d12f0c1c9ed252f 100644 (file)
@@ -65,9 +65,7 @@ CMAKE_DIST =                                    \
  tests/cmake/test.c                             \
  tests/cmake/test.sh
 
-VC_DIST = projects/README.md                           \
- projects/checksrc.bat                                 \
- projects/generate.bat
+VC_DIST = projects/README.md projects/generate.bat
 
 WINBUILD_DIST = winbuild/README.md \
  winbuild/MakefileBuild.vc winbuild/Makefile.vc winbuild/makedebug.bat
diff --git a/projects/checksrc.bat b/projects/checksrc.bat
deleted file mode 100644 (file)
index cbabad6..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-@echo off
-rem ***************************************************************************
-rem *                                  _   _ ____  _
-rem *  Project                     ___| | | |  _ \| |
-rem *                             / __| | | | |_) | |
-rem *                            | (__| |_| |  _ <| |___
-rem *                             \___|\___/|_| \_\_____|
-rem *
-rem * Copyright (C) Steve Holme, <steve_holme@hotmail.com>.
-rem *
-rem * This software is licensed as described in the file COPYING, which
-rem * you should have received as part of this distribution. The terms
-rem * are also available at https://curl.se/docs/copyright.html.
-rem *
-rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
-rem * copies of the Software, and permit persons to whom the Software is
-rem * furnished to do so, under the terms of the COPYING file.
-rem *
-rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
-rem * KIND, either express or implied.
-rem *
-rem * SPDX-License-Identifier: curl
-rem *
-rem ***************************************************************************
-
-:begin
-  rem Check we are running on a Windows NT derived OS
-  if not "%OS%" == "Windows_NT" goto nodos
-
-  rem Set our variables
-  setlocal
-  set CHECK_LIB=TRUE
-  set CHECK_SRC=TRUE
-  set CHECK_TESTS=TRUE
-  set CHECK_EXAMPLES=TRUE
-  set SRC_DIR=
-  set CUR_DIR=%cd%
-  set ARG0_DIR=%~dp0
-
-:parseArgs
-  if "%~1" == "" goto prerequisites
-
-  if /i "%~1" == "-?" (
-    goto syntax
-  ) else if /i "%~1" == "-h" (
-    goto syntax
-  ) else if /i "%~1" == "-help" (
-    goto syntax
-  ) else if /i "%~1" == "lib" (
-    set CHECK_LIB=TRUE
-    set CHECK_SRC=FALSE
-    set CHECK_TESTS=FALSE
-    set CHECK_EXAMPLES=FALSE
-  ) else if /i "%~1" == "src" (
-    set CHECK_LIB=FALSE
-    set CHECK_SRC=TRUE
-    set CHECK_TESTS=FALSE
-    set CHECK_EXAMPLES=FALSE
-  ) else if /i "%~1" == "tests" (
-    set CHECK_LIB=FALSE
-    set CHECK_SRC=FALSE
-    set CHECK_TESTS=TRUE
-    set CHECK_EXAMPLES=FALSE
-  ) else if /i "%~1" == "examples" (
-    set CHECK_LIB=FALSE
-    set CHECK_SRC=FALSE
-    set CHECK_TESTS=FALSE
-    set CHECK_EXAMPLES=TRUE
-  ) else (
-    if not defined SRC_DIR (
-      set SRC_DIR=%~1%
-    ) else (
-      goto unknown
-    )
-  )
-
-  shift & goto parseArgs
-
-:prerequisites
-  rem Check we have Perl in our path
-  perl --version <NUL 1>NUL 2>&1
-  if errorlevel 1 (
-    rem It isn't so check we have it installed and set the path if it is
-    if exist "%SystemDrive%\Perl" (
-      set "PATH=%SystemDrive%\Perl\bin;%PATH%"
-    ) else (
-      if exist "%SystemDrive%\Perl64" (
-        set "PATH=%SystemDrive%\Perl64\bin;%PATH%"
-      ) else (
-        goto noperl
-      )
-    )
-  )
-
-:configure
-  if "%SRC_DIR%" == "" (
-    rem Are we being executed from the "projects" or main directory?
-    if "%CUR_DIR%\" == "%ARG0_DIR%" (
-      set SRC_DIR=..
-    ) else if exist projects (
-      if exist docs (
-        if exist lib (
-          if exist src (
-            if exist tests (
-              set SRC_DIR=.
-            )
-          )
-        )
-      )
-    )
-  )
-  if not exist "%SRC_DIR%" goto nosrc
-
-:start
-  if "%CHECK_SRC%" == "TRUE" (
-    rem Check the src directory
-    if exist %SRC_DIR%\src (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\src\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\src" -Wtool_ca_embed.c -Wtool_hugehelp.c "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\src\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\src" "%%i"
-    )
-  )
-
-  if "%CHECK_LIB%" == "TRUE" (
-    rem Check the lib directory
-    if exist %SRC_DIR%\lib (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib" -Wcurl_config.h.cmake -Wcurl_config.h.in -Wcurl_config.h "%%i"
-    )
-
-    rem Check the lib\vauth directory
-    if exist %SRC_DIR%\lib\vauth (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vauth\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vauth" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vauth\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vauth" "%%i"
-    )
-
-    rem Check the lib\vquic directory
-    if exist %SRC_DIR%\lib\vquic (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vquic\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vquic" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vquic\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vquic" "%%i"
-    )
-
-    rem Check the lib\vssh directory
-    if exist %SRC_DIR%\lib\vssh (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vssh\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vssh" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vssh\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vssh" "%%i"
-    )
-
-    rem Check the lib\vtls directory
-    if exist %SRC_DIR%\lib\vtls (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vtls\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vtls" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\lib\vtls\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\lib\vtls" "%%i"
-    )
-  )
-
-  if "%CHECK_TESTS%" == "TRUE" (
-    rem Check the tests\libtest directory
-    if exist %SRC_DIR%\tests\libtest (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\libtest\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\libtest" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\libtest\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\libtest" "%%i"
-    )
-
-    rem Check the tests\unit directory
-    if exist %SRC_DIR%\tests\unit (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\unit\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\unit" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\unit\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\unit" "%%i"
-    )
-
-    rem Check the tests\server directory
-    if exist %SRC_DIR%\tests\server (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\server\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\server" "%%i"
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\tests\server\*.h.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\tests\server" "%%i"
-    )
-  )
-
-  if "%CHECK_EXAMPLES%" == "TRUE" (
-    rem Check the docs\examples directory
-    if exist %SRC_DIR%\docs\examples (
-      for /f "delims=" %%i in ('dir "%SRC_DIR%\docs\examples\*.c.*" /b 2^>NUL') do @perl "%SRC_DIR%\scripts\checksrc.pl" "-D%SRC_DIR%\docs\examples" "%%i"
-    )
-  )
-
-  goto success
-
-:syntax
-  rem Display the help
-  echo.
-  echo Usage: checksrc [what] [directory]
-  echo.
-  echo What to scan:
-  echo.
-  echo lib       - Scan the libcurl source
-  echo src       - Scan the command-line tool source
-  echo tests     - Scan the library tests and unit tests
-  echo examples  - Scan the examples
-  echo.
-  echo directory - Specifies the curl source directory
-  goto success
-
-:unknown
-  echo.
-  echo Error: Unknown argument '%1'
-  goto error
-
-:nodos
-  echo.
-  echo Error: Only a Windows NT based Operating System is supported
-  goto error
-
-:noperl
-  echo.
-  echo Error: Perl is not installed
-  goto error
-
-:nosrc
-  echo.
-  echo Error: "%SRC_DIR%" does not exist
-  goto error
-
-:error
-  if "%OS%" == "Windows_NT" endlocal
-  exit /B 1
-
-:success
-  endlocal
-  exit /B 0
index b4e3c0757b9403d99208a60c10694004c11e6753..2c98aac9f7b60a589f6024689ff0698d48e8b908 100644 (file)
@@ -22,7 +22,7 @@
 #
 ###########################################################################
 
-EXTRA_DIST = coverage.sh completion.pl firefox-db2pem.sh checksrc.pl checksrc-all.sh \
+EXTRA_DIST = coverage.sh completion.pl firefox-db2pem.sh checksrc.pl checksrc-all.pl \
   mk-ca-bundle.pl mk-unity.pl schemetable.c cd2nroff nroff2cd cdall cd2cd managen    \
   dmaketgz maketgz release-tools.sh verify-release cmakelint.sh mdlinkcheck          \
   CMakeLists.txt pythonlint.sh randdisable wcurl top-complexity extract-unit-protos
diff --git a/scripts/checksrc-all.pl b/scripts/checksrc-all.pl
new file mode 100755 (executable)
index 0000000..08ff6cf
--- /dev/null
@@ -0,0 +1,38 @@
+#!/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 @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", @files) != 0) {
+        $anyfailed = 1;
+    }
+}
+
+exit $anyfailed;
diff --git a/scripts/checksrc-all.sh b/scripts/checksrc-all.sh
deleted file mode 100755 (executable)
index 2c4b3c5..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-# Copyright (C) Viktor Szakats
-#
-# SPDX-License-Identifier: curl
-
-set -eu
-
-anyfailed=0
-
-for dir in $({
-    if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
-      git ls-files '*.[ch]'
-    else
-      find . -name '*.[ch]'
-    fi
-    [ -n "${1:-}" ] && find "$@" -name '*.[ch]'
-  } | grep -v -F '/CMakeFiles/' | sed -E 's|/[^/]+$||' | sort -u); do
-  if ! ./scripts/checksrc.pl "${dir}"/*.[ch]; then
-    anyfailed=1
-  fi
-done
-
-exit "${anyfailed}"