Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org,
	Alexander Turenko <alexander.turenko@tarantool.org>
Subject: [Tarantool-patches] [PATCH] tools: fix luacheck invocation in different cases
Date: Tue,  1 Dec 2020 15:32:06 +0300	[thread overview]
Message-ID: <c7b39ccc55c40a993bbed7d7f173c713dcd64468.1606825816.git.alexander.turenko@tarantool.org> (raw)

Now `make luacheck` gracefully handles different cases: in-source and
out-of-source build (within the source tree or outside), current working
directory as a real path or with symlink components.

As result of looking into those problems I filed the issue [1] against
luacheck. It seems, there are problems around absolute paths with
symlinks components.

[1]: https://github.com/mpeterv/luacheck/issues/208
---

no issue
Totktonada/fix-luacheck-invocation
https://github.com/tarantool/tarantool/tree/Totktonada/fix-luacheck-invocation

 CMakeLists.txt        |  5 ++-
 tools/run-luacheck.sh | 71 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 3 deletions(-)
 create mode 100755 tools/run-luacheck.sh

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa6818f8e..10206b943 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,7 +25,6 @@ find_program(BASH bash)
 find_program(GIT git)
 find_program(LD ld)
 find_program(CTAGS ctags)
-find_program(LUACHECK luacheck ENV PATH)
 
 # Define PACKAGE macro in tarantool/config.h
 set(PACKAGE "Tarantool" CACHE STRING "Package name.")
@@ -157,10 +156,10 @@ add_custom_target(ctags DEPENDS tags)
 #
 # Enable 'make luacheck' target.
 #
-
 add_custom_target(luacheck)
 add_custom_command(TARGET luacheck
-    COMMAND ${LUACHECK} --codes --config "${PROJECT_SOURCE_DIR}/.luacheckrc" "${PROJECT_SOURCE_DIR}"
+    COMMAND "${PROJECT_SOURCE_DIR}/tools/run-luacheck.sh"
+            "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}"
     COMMENT "Perform static analysis of Lua code"
 )
 
diff --git a/tools/run-luacheck.sh b/tools/run-luacheck.sh
new file mode 100755
index 000000000..e6ebb78b3
--- /dev/null
+++ b/tools/run-luacheck.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+set -eux
+
+SOURCE_DIR="${1:-}"
+BUILD_DIR="${2:-}"
+
+if [ -z "${SOURCE_DIR}" ] || [ -z "${BUILD_DIR}" ]; then
+    printf "Usage: ${0} /path/to/the/source/tree /path/to/the/build/directory\n"
+    exit 1
+fi
+
+if ! type luacheck; then
+    printf "Unable to find luacheck\n"
+    exit 1
+fi
+
+# Workaround luacheck behaviour around the `include_files`
+# configuration option, a current working directory and a
+# directory path passed as an argument.
+#
+# https://github.com/mpeterv/luacheck/issues/208
+#
+# If we'll just invoke the following command under the
+# `make luacheck` target:
+#
+#  | luacheck --codes                                 \
+#  |     --config "${PROJECT_SOURCE_DIR}/.luacheckrc" \
+#  |     "${PROJECT_SOURCE_DIR}"
+#
+# The linter will fail to find Lua sources in the following cases:
+#
+# 1. In-source build. The current working directory is not a
+#    real path (contains components, which are symlinks).
+# 2. Out-of-source build.
+#
+# It seems, the only reliable way to verify sources is to change
+# the current directory prior to the luacheck call.
+cd "${SOURCE_DIR}"
+
+# Exclude the build directory if it is under the source directory.
+#
+# Except the case, when the build directory is the same as the
+# source directory.
+#
+# We lean on the following assumptions:
+#
+# 1. "${SOURCE_DIR}" and "${BUILD_DIR}" have no the trailing slash.
+# 2. "${SOURCE_DIR}" and "${BUILD_DIR}" are either real paths
+#    (with resolved symlink components) or absolute paths with the
+#    same symlink components (where applicable).
+#
+# Those assumptions should be true when the variables are passed
+# from the CMake variables "${PROJECT_SOURCE_DIR}" and
+# "${PROJECT_BINARY_DIR}".
+#
+# When the prerequisites are hold true, the EXCLUDE_FILES pattern
+# will be relative to the "${SOURCE_DIR}" and luacheck will work
+# as expected.
+EXCLUDE_FILES=""
+case "${BUILD_DIR}" in
+"${SOURCE_DIR}/"*)
+    EXCLUDE_FILES="${BUILD_DIR#"${SOURCE_DIR}/"}/**/*.lua"
+    ;;
+esac
+
+if [ -z "${EXCLUDE_FILES}" ]; then
+    luacheck --codes --config .luacheckrc .
+else
+    luacheck --codes --config .luacheckrc . --exclude-files "${EXCLUDE_FILES}"
+fi
-- 
2.25.0

             reply	other threads:[~2020-12-01 12:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 12:32 Alexander Turenko [this message]
2020-12-16 16:47 ` Sergey Bronnikov
2021-02-18 16:11   ` Alexander Turenko via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c7b39ccc55c40a993bbed7d7f173c713dcd64468.1606825816.git.alexander.turenko@tarantool.org \
    --to=alexander.turenko@tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] tools: fix luacheck invocation in different cases' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox