Skip to content

Commit

Permalink
ci: introduce CI_LINT option
Browse files Browse the repository at this point in the history
This will abort if lint programs are not found, and is meant primarily
for the lint job in CI. Supersedes the REQUIRED argument in
add_glob_target as it's a superior replacement by being a built-in
solution.
  • Loading branch information
dundargoc authored Jun 23, 2023
1 parent 4dc8647 commit 46e9590
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
cmake --build .deps
- if: success() || failure() && steps.abort_job.outputs.status == 'success'
run: cmake -B build -G Ninja
run: cmake -B build -G Ninja -D CI_LINT=ON

- if: "!cancelled()"
name: Determine if run should be aborted
Expand Down
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ endif()
#
# Lint
#
find_program(SHELLCHECK_PRG shellcheck)
find_program(STYLUA_PRG stylua)
option(CI_LINT "Abort if lint programs not found" OFF)
if(CI_LINT)
set(LINT_REQUIRED "REQUIRED")
endif()
find_program(SHELLCHECK_PRG shellcheck ${LINT_REQUIRED})
find_program(STYLUA_PRG stylua ${LINT_REQUIRED})

add_glob_target(
REQUIRED
TARGET lintlua-luacheck
COMMAND ${DEPS_BIN_DIR}/luacheck
FLAGS -q
Expand Down
13 changes: 3 additions & 10 deletions cmake/Util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# depends on the value of TOUCH_STRATEGY.
#
# Options:
# REQUIRED - Abort if COMMAND doesn't exist.
#
# Single value arguments:
# TARGET - Name of the target
Expand Down Expand Up @@ -53,22 +52,16 @@
# files.
function(add_glob_target)
cmake_parse_arguments(ARG
"REQUIRED"
""
"TARGET;COMMAND;GLOB_PAT;TOUCH_STRATEGY"
"FLAGS;FILES;GLOB_DIRS;EXCLUDE"
${ARGN}
)

if(NOT ARG_COMMAND)
add_custom_target(${ARG_TARGET})
if(ARG_REQUIRED)
add_custom_command(TARGET ${ARG_TARGET}
COMMAND ${CMAKE_COMMAND} -E echo "${ARG_TARGET}: ${ARG_COMMAND} not found"
COMMAND false)
else()
add_custom_command(TARGET ${ARG_TARGET}
COMMAND ${CMAKE_COMMAND} -E echo "${ARG_TARGET} SKIP: ${ARG_COMMAND} not found")
endif()
add_custom_command(TARGET ${ARG_TARGET}
COMMAND ${CMAKE_COMMAND} -E echo "${ARG_TARGET} SKIP: ${ARG_COMMAND} not found")
return()
endif()

Expand Down

0 comments on commit 46e9590

Please sign in to comment.