From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 616426EC58; Thu, 18 Feb 2021 19:09:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 616426EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1613664550; bh=xJBIThu6p2CVkR4f4ZeM88/VbyL8w+u15Mq41EFjMSI=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=IlASU/ZJ+OXBaTWr9ZouueL3ULXDpkQq0Nauxy2TaKHq5aqxAOhZjPUWI6K76heEt YguV8DKOha3Y9751QAreVTKZ0yMg2vtTmxnjTEsT0XIYbqtgOvgUOI2Ov0haTa025u u8/5DCwctNRj1lVw/S2JP49IrH53T2F8k+wwWjfs= Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [94.100.177.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2EC896EC58 for ; Thu, 18 Feb 2021 19:09:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2EC896EC58 Received: by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1lClrY-0001tU-1o; Thu, 18 Feb 2021 19:09:08 +0300 To: Sergey Bronnikov Date: Thu, 18 Feb 2021 19:09:07 +0300 Message-Id: <524c0ce8acc18111ab4c8b36e383ff192779c780.1613661908.git.alexander.turenko@tarantool.org> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD975C3EC174F5669229511437AA01F46811CFCF616A939B362182A05F5380850406BA2E7392D3FE9B78E0860C5051980145A35FD966B1A66D56903AE73D4CA6BF1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7EA4B66823129EB3CEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637BC9F889FE9D346E88638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC3231DD511257BFF3F374E21C4E5EBBE7648E5F28798A7D11389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D082881546D93491CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FC9F5955FECEF5819E75ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4930A3850AC1BE2E735458315FA5AE40766C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F49DBD40FC3B05A732623479134186CDE6BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF81F587C2CCB19334097A20A12C0D5E5D56E269F6379B6659C2B6934AE262D3EE7EAB7254005DCED2465BA557073FD9C1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B06CE7B4E551862B828E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C75F910DBB8BE89800BFD9387AEB451D15560FCF2D31A6551B5DA27E7A61CDAFC1154A9FAB8B49CD1D7E09C32AA3244C1DB577FCE6284BCB0413BECB315E6478C3B3ADDA61883BB5927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojbL9S8ysBdXjMfWLKATMGa0Bwgpu+O4AV X-Mailru-Sender: 3B9A0136629DC9120A41FA45E5DF9B9D4AEBDD30ACB3D09D6105E26BE073BA135E6A6BA515280ED4E7E9AC22BF8F68B8043D6CCB234D47A84F4DA692B4D09B99EA14D4C13BB08888112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2] tools: fix luacheck invocation in different cases X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Alexander Turenko via Tarantool-patches Reply-To: Alexander Turenko Cc: tarantool-patches@dev.tarantool.org, Alexander Turenko Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 Changes since v1: * Moved the logic to CMake, dropped the shell wrapper. * Shrink comments. * Handled the case, when a build directory is in the source directory, and cmake is called not like `cmake ..`, but `cmake /path/to/source`, where the path is not a real path. CMakeLists.txt | 28 ++++++++++++++++++++++++++-- cmake/utils.cmake | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fbd19558..97cfff7ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,12 +158,36 @@ add_custom_target(ctags DEPENDS tags) # # Enable 'make luacheck' target. # - +# The code looks tricky, because of luacheck side problems +# (see [1]). +# +# The following circumstances may lead to missing of source files +# or exclusions: +# +# * Calling `luacheck "${dir}/.luacheckrc" "${dir}"` from +# outside of ${dir} or when ${dir} is not a real path. +# * Using of a path with symlink components in --exclude-files. +# +# [1]: https://github.com/mpeterv/luacheck/issues/208 +# +set(EXCLUDE_FILES) +get_filename_component(BINARY_REALPATH "${PROJECT_BINARY_DIR}" REALPATH) +get_filename_component(SOURCE_REALPATH "${PROJECT_SOURCE_DIR}" REALPATH) +file_is_in_directory(BINARY_DIR_INSIDE_SOURCE_DIR "${BINARY_REALPATH}" + "${SOURCE_REALPATH}") +if (BINARY_DIR_INSIDE_SOURCE_DIR) + set(EXCLUDE_FILES --exclude-files "${BINARY_REALPATH}/**/*.lua") +endif() add_custom_target(luacheck) add_custom_command(TARGET luacheck - COMMAND ${LUACHECK} --codes --config "${PROJECT_SOURCE_DIR}/.luacheckrc" "${PROJECT_SOURCE_DIR}" + COMMAND ${LUACHECK} --codes --config .luacheckrc . ${EXCLUDE_FILES} + WORKING_DIRECTORY ${SOURCE_REALPATH} COMMENT "Perform static analysis of Lua code" ) +unset(BINARY_REALPATH) +unset(SOURCE_REALPATH) +unset(BINARY_DIR_INSIDE_SOURCE_DIR) +unset(EXCLUDE_FILES) if (WITH_JEPSEN) ExternalProject_Add( diff --git a/cmake/utils.cmake b/cmake/utils.cmake index eaec821b3..e9b5fed5d 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -86,3 +86,25 @@ function(bin_source varname srcfile dstfile) endfunction() +# +# Whether a file is descendant to a directory. +# +# If the file is the directory itself, the answer is FALSE. +# +function(file_is_in_directory varname file dir) + file(RELATIVE_PATH file_relative "${dir}" "${file}") + if (file_relative STREQUAL "") + # and is the same directory. + set(${varname} FALSE PARENT_SCOPE) + elseif (file_relative STREQUAL "..") + # inside a (so it is a directory too), not + # vice versa. + set(${varname} FALSE PARENT_SCOPE) + elseif (file_relative MATCHES "^\\.\\./") + # somewhere outside of the . + set(${varname} FALSE PARENT_SCOPE) + else() + # is descendant to . + set(${varname} TRUE PARENT_SCOPE) + endif() +endfunction() -- 2.30.0