Skip to content

Commit

Permalink
test: fix luacheck invocation for non-real paths
Browse files Browse the repository at this point in the history
Unfortunately, luacheck doesn't handle the working directory or one used
in options if it is not a real path. As a result of this patch both
PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR are resolved prior to be used
within luacheck target custom command.

The issue has been already fixed in Tarantool repo after applying
af448464d15f60b87f1c9ef41a7816911c889459 ('tools: fix luacheck
invocation in different cases'), and this patch is necessary, since
<LuaJIT-luacheck> is a dependency for Tarantool <luacheck> target.

Relates to mpeterv/luacheck#208

Reported-by: Alexander Turenko <[email protected]>
Reviewed-by: Alexander Turenko <[email protected]>
Reviewed-by: Sergey Kaplun <[email protected]>
Signed-off-by: Igor Munkin <[email protected]>
  • Loading branch information
igormunkin committed Mar 9, 2021
1 parent 82932be commit 6171a68
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,33 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

find_program(LUACHECK luacheck)
if(LUACHECK)
set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
# XXX: The tweak below relates to luacheck problem with paths.
# If the working directory or one used in luacheck options is
# not a real path, luacheck doesn't handle it the right way.
# Hence the paths used by luacheck in CMake ought to be resolved
# to the real ones. For more info, see the following issue.
# https://github.com/mpeterv/luacheck/issues/208
get_filename_component(LUACHECK_SOURCE_DIR "${PROJECT_SOURCE_DIR}" REALPATH)
get_filename_component(LUACHECK_BINARY_DIR "${PROJECT_BINARY_DIR}" REALPATH)
set(LUACHECK_RC ${LUACHECK_SOURCE_DIR}/.luacheckrc)
file(GLOB_RECURSE LUACHECK_DEPS ${LUACHECK_SOURCE_DIR}/*.lua)
add_custom_target(${PROJECT_NAME}-luacheck
DEPENDS ${LUACHECK_RC} ${LUACHECK_DEPS}
)
add_custom_command(TARGET ${PROJECT_NAME}-luacheck
COMMENT "Running luacheck static analysis"
COMMAND
${LUACHECK} ${PROJECT_SOURCE_DIR}
${LUACHECK} ${LUACHECK_SOURCE_DIR}
--codes
--config ${LUACHECK_RC}
# XXX: jit/vmdef.lua is an autogenerated Lua source, so
# there is no need to run luacheck against it. Hence
# explicitly exclude this file from the list for check.
--exclude-files ${LUAJIT_BINARY_DIR}/jit/vmdef.lua
--exclude-files ${LUACHECK_BINARY_DIR}/src/jit/vmdef.lua
# 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}
WORKING_DIRECTORY ${LUACHECK_SOURCE_DIR}
)
else()
add_custom_target(${PROJECT_NAME}-luacheck)
Expand Down

0 comments on commit 6171a68

Please sign in to comment.