Skip to content

Commit c48c8ee

Browse files
committed
test: run luacheck static analysis via CMake
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 5a61e1a ('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. Resolves tarantool/tarantool#5470 Part of tarantool/tarantool#4862 Reviewed-by: Timur Safin <[email protected]> Reviewed-by: Sergey Kaplun <[email protected]> Signed-off-by: Igor Munkin <[email protected]>
1 parent 6998119 commit c48c8ee

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.luacheckrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Use the default LuaJIT globals.
2+
std = 'luajit'
3+
-- This fork also introduces a new global for misc API namespace.
4+
read_globals = { 'misc' }
5+
6+
-- These files are inherited from the vanilla LuaJIT and need to
7+
-- be coherent with the upstream.
8+
exclude_files = {
9+
'dynasm/',
10+
'src/',
11+
}

test/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@
33
# See the rationale in the root CMakeLists.txt.
44
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
55

6+
find_program(LUACHECK luacheck)
7+
if(LUACHECK)
8+
set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
9+
file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
10+
add_custom_target(${PROJECT_NAME}-luacheck
11+
DEPENDS ${LUACHECK_RC} ${LUACHECK_DEPS}
12+
)
13+
add_custom_command(TARGET ${PROJECT_NAME}-luacheck
14+
COMMENT "Running luacheck static analysis"
15+
COMMAND
16+
${LUACHECK} ${PROJECT_SOURCE_DIR}
17+
--codes
18+
--config ${LUACHECK_RC}
19+
# XXX: jit/vmdef.lua is an autogenerated Lua source, so
20+
# there is no need to run luacheck against it. Hence
21+
# explicitly exclude this file from the list for check.
22+
--exclude-files ${LUAJIT_BINARY_DIR}/jit/vmdef.lua
23+
# XXX: Filenames in .luacheckrc are considered relative to
24+
# the working directory, hence luacheck should be run in the
25+
# project root directory.
26+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
27+
)
28+
else()
29+
add_custom_target(${PROJECT_NAME}-luacheck)
30+
add_custom_command(TARGET ${PROJECT_NAME}-luacheck
31+
COMMENT "`luacheck' is not found, so ${PROJECT_NAME}-luacheck target is dummy"
32+
)
33+
endif()
34+
635
add_subdirectory(tarantool-tests)
736

837
add_custom_target(${PROJECT_NAME}-test DEPENDS
@@ -24,5 +53,6 @@ if(LUAJIT_USE_TEST)
2453

2554
add_custom_target(test DEPENDS
2655
${PROJECT_NAME}-test
56+
${PROJECT_NAME}-luacheck
2757
)
2858
endif()

0 commit comments

Comments
 (0)