aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt35
-rw-r--r--cmake/DefCmdTarget.cmake27
-rw-r--r--cmake/RunUncrustify.cmake5
-rw-r--r--cmake/lint.cmake34
-rwxr-xr-xsrc/nvim/CMakeLists.txt14
5 files changed, 72 insertions, 43 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ee59d26a89..d8dc2beae4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -612,6 +612,33 @@ if(NOT BUSTED_OUTPUT_TYPE)
set(BUSTED_OUTPUT_TYPE "nvim")
endif()
+#
+# Lint
+#
+find_program(LUACHECK_PRG luacheck)
+find_program(STYLUA_PRG stylua)
+find_program(FLAKE8_PRG flake8)
+find_program(UNCRUSTIFY_PRG uncrustify)
+find_program(SHELLCHECK_PRG shellcheck)
+include(DefCmdTarget)
+def_cmd_target(lintlua ${LUACHECK_PRG} LUACHECK_PRG true)
+if(LUACHECK_PRG)
+ add_custom_command(OUTPUT lintlua-cmd APPEND COMMAND ${LUACHECK_PRG} -q runtime/ scripts/ src/ test/)
+endif()
+if(STYLUA_PRG)
+ add_custom_command(OUTPUT lintlua-cmd APPEND COMMAND ${STYLUA_PRG} --color=always --check runtime/)
+else()
+ add_custom_command(OUTPUT lintlua-cmd APPEND COMMAND ${CMAKE_COMMAND} -E echo "STYLUA_PRG not found")
+endif()
+def_cmd_target(lintpy ${FLAKE8_PRG} FLAKE8_PRG true)
+if(FLAKE8_PRG)
+ add_custom_command(OUTPUT lintpy-cmd APPEND COMMAND ${FLAKE8_PRG} contrib/ scripts/ src/ test/)
+endif()
+def_cmd_target(lintsh ${SHELLCHECK_PRG} SHELLCHECK_PRG true)
+if(SHELLCHECK_PRG)
+ add_custom_command(OUTPUT lintsh-cmd APPEND COMMAND ${SHELLCHECK_PRG} scripts/vim-patch.sh)
+endif()
+
include(InstallHelpers)
file(GLOB MANPAGES
@@ -745,14 +772,6 @@ if(BUSTED_LUA_PRG)
set_target_properties(functionaltest-lua PROPERTIES FOLDER test)
endif()
-foreach(TARGET IN ITEMS lintlua lintsh lintpy lintuncrustify)
- add_custom_target(${TARGET}
- COMMAND ${CMAKE_COMMAND}
- -DPROJECT_ROOT=${PROJECT_SOURCE_DIR}
- -DTARGET=${TARGET}
- -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)
-endforeach()
-
#add uninstall target
if(NOT TARGET uninstall)
configure_file(
diff --git a/cmake/DefCmdTarget.cmake b/cmake/DefCmdTarget.cmake
new file mode 100644
index 0000000000..1ee5cdd60e
--- /dev/null
+++ b/cmake/DefCmdTarget.cmake
@@ -0,0 +1,27 @@
+# Defines a target named ${target} and a command with (symbolic) output
+# ${target}-cmd. If ${prg} is undefined the target prints "not found".
+#
+# - Use add_custom_command(…APPEND) to build the command after this.
+# - Use add_custom_target(…DEPENDS) to run the command from a target.
+function(def_cmd_target target prg prg_name prg_fatal)
+ # Define a mostly-empty command, which can be appended-to.
+ add_custom_command(OUTPUT ${target}-cmd
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMAND ${CMAKE_COMMAND} -E echo "${target}"
+ )
+ # Symbolic (does not generate an artifact).
+ set_source_files_properties(${target}-cmd PROPERTIES SYMBOLIC "true")
+
+ if(prg OR NOT prg_fatal)
+ add_custom_target(${target}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${target}-cmd)
+ if(NOT prg)
+ add_custom_command(OUTPUT ${target}-cmd APPEND
+ COMMAND ${CMAKE_COMMAND} -E echo "${target}: SKIP: ${prg_name} not found")
+ endif()
+ else()
+ add_custom_target(${target} false
+ COMMENT "${target}: ${prg_name} not found")
+ endif()
+endfunction()
diff --git a/cmake/RunUncrustify.cmake b/cmake/RunUncrustify.cmake
new file mode 100644
index 0000000000..9ebbd6b77c
--- /dev/null
+++ b/cmake/RunUncrustify.cmake
@@ -0,0 +1,5 @@
+# HACK: This script is invoked with "cmake -P …" as a workaround to silence uncrustify.
+
+execute_process(
+ COMMAND ${UNCRUSTIFY_PRG} -c "${PROJECT_SOURCE_DIR}/src/uncrustify.cfg" -q --check ${LINT_NVIM_SOURCES}
+ OUTPUT_QUIET)
diff --git a/cmake/lint.cmake b/cmake/lint.cmake
deleted file mode 100644
index 1fb8c749a8..0000000000
--- a/cmake/lint.cmake
+++ /dev/null
@@ -1,34 +0,0 @@
-function(lint)
- cmake_parse_arguments(LINT "QUIET" "PROGRAM" "FLAGS;FILES" ${ARGN})
-
- if(LINT_QUIET)
- set(OUTPUT_QUIET OUTPUT_QUIET)
- elseif()
- set(OUTPUT_QUIET "")
- endif()
-
- find_program(PROGRAM_EXISTS ${LINT_PROGRAM})
- if(PROGRAM_EXISTS)
- execute_process(COMMAND ${LINT_PROGRAM} ${LINT_FLAGS} ${LINT_FILES}
- WORKING_DIRECTORY ${PROJECT_ROOT}
- RESULT_VARIABLE ret
- ${OUTPUT_QUIET})
- if(ret AND NOT ret EQUAL 0)
- message(FATAL_ERROR "FAILED: ${TARGET}")
- endif()
- else()
- message(STATUS "${TARGET}: ${LINT_PROGRAM} not found. SKIP.")
- endif()
-endfunction()
-
-if(${TARGET} STREQUAL "lintuncrustify")
- file(GLOB_RECURSE FILES ${PROJECT_ROOT}/src/nvim/*.[c,h])
- lint(PROGRAM uncrustify FLAGS -c src/uncrustify.cfg -q --check FILES ${FILES} QUIET)
-elseif(${TARGET} STREQUAL "lintpy")
- lint(PROGRAM flake8 FILES contrib/ scripts/ src/ test/)
-elseif(${TARGET} STREQUAL "lintsh")
- lint(PROGRAM shellcheck FILES scripts/vim-patch.sh)
-elseif(${TARGET} STREQUAL "lintlua")
- lint(PROGRAM luacheck FLAGS -q FILES runtime/ scripts/ src/ test/)
- lint(PROGRAM stylua FLAGS --color=always --check FILES runtime/)
-endif()
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index c902ff6c50..1970a68393 100755
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -1,5 +1,7 @@
option(USE_GCOV "Enable gcov support" OFF)
+include(DefCmdTarget)
+
if(USE_GCOV)
if(CLANG_TSAN)
# GCOV and TSAN results in false data race reports
@@ -802,12 +804,22 @@ foreach(sfile ${LINT_NVIM_SOURCES})
endforeach()
add_custom_target(lintc DEPENDS ${LINT_TARGETS})
+def_cmd_target(lintuncrustify ${UNCRUSTIFY_PRG} UNCRUSTIFY_PRG false) # Non-fatal so that "lintc" target can depend on it.
+if(UNCRUSTIFY_PRG)
+ add_custom_command(OUTPUT lintuncrustify-cmd APPEND
+ COMMAND ${CMAKE_COMMAND}
+ -DUNCRUSTIFY_PRG=${UNCRUSTIFY_PRG}
+ -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
+ -DLINT_NVIM_SOURCES=${LINT_NVIM_SOURCES}
+ -P ${PROJECT_SOURCE_DIR}/cmake/RunUncrustify.cmake)
+endif()
+
add_custom_target(
lintcfull
COMMAND
${LINT_PRG} --suppress-errors=${LINT_SUPPRESS_FILE} ${LINT_NVIM_REL_SOURCES}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${LINT_PRG} ${LINT_NVIM_SOURCES} ${LINT_SUPPRESS_FILE}
+ DEPENDS ${LINT_PRG} ${LINT_NVIM_SOURCES} ${LINT_SUPPRESS_FILE} lintuncrustify
)
add_custom_target(generated-sources DEPENDS