[Tarantool-patches] [PATCH luajit 5/5] test: run luacheck static analysis via CMake

Igor Munkin imun at tarantool.org
Tue Feb 2 23:57:45 MSK 2021


This patch introduces a separate target to run luacheck against all Lua
chunks within LuaJIT repository except those explicitly ignored in
.luacheckrc. There is also a single additional change over the 'luajit'
std defaults: to suppress all false positives related to <misc>
namespace introduced in 5a61e1ab54b5c66bfebd836db1ac47996611e065 ('misc:
add C and Lua API for platform metrics'), this name is added to
<read_globals> list.

All Lua sources originally inherited from LuaJIT vanilla repository are
ignored, to leave them coherent with the upstream.

The new target is a dependency for the root <test> target.

Part of tarantool/tarantool#4862
Part of tarantool/tarantool#5470

Signed-off-by: Igor Munkin <imun at tarantool.org>
---
 .gitignore          |  1 +
 .luacheckrc         | 11 +++++++++++
 test/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 .luacheckrc

diff --git a/.gitignore b/.gitignore
index 35d2580..7902547 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@ Makefile
 cmake_install.cmake
 compile_commands.json
 install_manifest.txt
+luacheck.ok
 luajit-parse-memprof
 luajit.pc
 tests.ok
diff --git a/.luacheckrc b/.luacheckrc
new file mode 100644
index 0000000..0a5d001
--- /dev/null
+++ b/.luacheckrc
@@ -0,0 +1,11 @@
+-- Use the default LuaJIT globals.
+std = 'luajit'
+-- This fork also introduces a new global for misc API namespace.
+read_globals = { 'misc' }
+
+-- These files are inherited from the vanilla LuaJIT and need to
+-- be coherent with the upstream.
+exclude_files = {
+  'dynasm/',
+  'src/',
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f05dd90..c89efc2 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -3,6 +3,36 @@
 # See the rationale in the root CMakeLists.txt.
 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
+find_program(LUACHECK luacheck)
+if(LUACHECK)
+  set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
+  set(LUACHECK_OK ${CMAKE_CURRENT_BINARY_DIR}/luacheck.ok)
+  file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
+  add_custom_command(
+    COMMENT "Running luacheck static analysis"
+    OUTPUT ${LUACHECK_OK}
+    DEPENDS ${LUACHECK} ${LUACHECK_RC} ${LUACHECK_DEPS}
+    COMMAND
+      ${LUACHECK} ${PROJECT_SOURCE_DIR}
+        --codes
+        --config ${LUACHECK_RC}
+      && touch ${LUACHECK_OK}
+      # XXX: Filenames in .luacheckrc are considered relative to
+      # the working directory, hence luacheck should be run in the
+      # project root directory.
+      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+  )
+else()
+  add_custom_command(
+    COMMENT "`luacheck' is not found, so ${PROJECT_NAME}-luacheck target is dummy"
+    OUTPUT luacheck.ok
+    COMMAND touch luacheck.ok
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+  )
+endif()
+
+add_custom_target(${PROJECT_NAME}-luacheck DEPENDS luacheck.ok)
+
 add_subdirectory(tarantool-tests)
 
 add_custom_target(${PROJECT_NAME}-test DEPENDS
@@ -24,5 +54,6 @@ if(LUAJIT_USE_TEST)
 
   add_custom_target(test DEPENDS
     ${PROJECT_NAME}-test
+    ${PROJECT_NAME}-luacheck
   )
 endif()
-- 
2.25.0



More information about the Tarantool-patches mailing list