Skip to content

Commit b378d8c

Browse files
committed
Lint (shellcheck) and style check generated script
1 parent bd7da3e commit b378d8c

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

CMakeLists.txt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,40 @@ function(caf_compile_executable target main_depend)
452452
DEPENDS "${target}")
453453
endfunction(caf_compile_executable)
454454

455+
enable_testing()
456+
457+
#--------------------------------------------------------
458+
# Setup shellcheck if present for testing/linting scripts
459+
#--------------------------------------------------------
460+
find_program(SHELLCHECK_EXE shellcheck
461+
DOC "Path to shellcheck executable for linting scripts"
462+
)
463+
if (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER})
464+
if(NOT SHELLCHECK_EXE)
465+
message( AUTHOR_WARNING "OpenCoarrays developers should install shellcheck to test/lint all shell scripts.
466+
See https://github.com/koalaman/shellcheck#installing for info on obtaining shellcheck.")
467+
endif()
468+
endif()
469+
470+
function(lint_script script_dir script_name)
471+
if (SHELLCHECK_EXE)
472+
add_test(NAME "shellcheck:${script_name}"
473+
COMMAND ${SHELLCHECK_EXE} -x "${script_dir}/${script_name}"
474+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
475+
elseif (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER})
476+
message( AUTHOR_WARNING "test: shellcheck:${script_name} not run because shellcheck not installed." )
477+
endif()
478+
endfunction()
479+
480+
#-----------------------------------------------
481+
# Setup script style testing & enforcement macro
482+
#-----------------------------------------------
483+
484+
function(check_script_style script_full_path)
485+
add_test(NAME "style:${script_full_path}"
486+
COMMAND "${CMAKE_SOURCE_DIR}/developer-scripts/style.pl" "${script_full_path}")
487+
endfunction()
488+
455489
#-------------------------------
456490
# Recurse into the src directory
457491
#-------------------------------
@@ -499,8 +533,6 @@ configure_file ( "${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in" "${CMAKE_BINARY_
499533
add_custom_target ( uninstall
500534
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/uninstall.cmake" )
501535

502-
enable_testing()
503-
504536
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
505537
# See JSON-Fortran's CMakeLists.txt file to find out how to get the check target to depend
506538
# on the test executables

src/mpi/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,8 @@ configure_file("${CMAKE_SOURCE_DIR}/src/extensions/cafrun.in" "${CMAKE_BINARY_DI
214214
install(PROGRAMS "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun"
215215
"${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/caf"
216216
DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
217+
218+
lint_script("${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" caf)
219+
check_script_style("${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/caf")
220+
lint_script("${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" cafrun)
221+
check_script_style("${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/cafrun")

0 commit comments

Comments
 (0)