Skip to content

Commit

Permalink
As we use glob recurse, set format properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hrzlgnm committed Dec 15, 2024
1 parent 4207dac commit c19c4e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmake/lint-targets.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(FORMAT_PATTERNS
source/**/*.cpp source/**/*.hpp test/**/*.cpp test/**/*.hpp
source/*.cpp source/*.hpp test/*.cpp test/*.hpp
CACHE STRING
"; separated patterns relative to the project source dir to format")

Expand Down
36 changes: 18 additions & 18 deletions cmake/lint.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
cmake_minimum_required(VERSION 3.14)

macro(default name)
if(NOT DEFINED "${name}")
set("${name}" "${ARGN}")
endif()
if(NOT DEFINED "${name}")
set("${name}" "${ARGN}")
endif()
endmacro()

default(FORMAT_COMMAND clang-format)
default(PATTERNS source/**/*.cpp source/**/*.hpp test/**/*.cpp test/**/*.hpp)
default(PATTERNS source/*.cpp source/*.hpp test/*.cpp test/*.hpp)
default(FIX NO)

set(flag --output-replacements-xml)
set(args OUTPUT_VARIABLE output)
if(FIX)
set(flag -i)
set(args "")
set(flag -i)
set(args "")
endif()

file(GLOB_RECURSE files ${PATTERNS})
Expand All @@ -23,22 +23,22 @@ set(output "")
string(LENGTH "${CMAKE_SOURCE_DIR}/" path_prefix_length)

foreach(file IN LISTS files)
execute_process(
execute_process(
COMMAND "${FORMAT_COMMAND}" --style=file "${flag}" "${file}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE result ${args})
if(NOT result EQUAL "0")
message(FATAL_ERROR "'${file}': formatter returned with ${result}")
endif()
if(NOT FIX AND output MATCHES "\n<replacement offset")
string(SUBSTRING "${file}" "${path_prefix_length}" -1 relative_file)
list(APPEND badly_formatted "${relative_file}")
endif()
set(output "")
if(NOT result EQUAL "0")
message(FATAL_ERROR "'${file}': formatter returned with ${result}")
endif()
if(NOT FIX AND output MATCHES "\n<replacement offset")
string(SUBSTRING "${file}" "${path_prefix_length}" -1 relative_file)
list(APPEND badly_formatted "${relative_file}")
endif()
set(output "")
endforeach()

if(NOT badly_formatted STREQUAL "")
list(JOIN badly_formatted "\n" bad_list)
message("The following files are badly formatted:\n\n${bad_list}\n")
message(FATAL_ERROR "Run again with FIX=YES to fix these files.")
list(JOIN badly_formatted "\n" bad_list)
message("The following files are badly formatted:\n\n${bad_list}\n")
message(FATAL_ERROR "Run again with FIX=YES to fix these files.")
endif()

0 comments on commit c19c4e7

Please sign in to comment.