-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: fix luacheck invocation in different cases
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]: mpeterv/luacheck#208
- Loading branch information
1 parent
99d6c8a
commit a1d2ce9
Showing
2 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |