diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2023-12-04 20:21:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-04 20:21:38 +0100 |
commit | e5d7003b02c9af96c51ea5638e07eea25057a216 (patch) | |
tree | 1f592edd7865f472aa5481931d19c0fe4f8e8c23 /cmake | |
parent | 66f1563c7a48d76f99c89e32de030e57af2abfb4 (diff) | |
download | rneovim-e5d7003b02c9af96c51ea5638e07eea25057a216.tar.gz rneovim-e5d7003b02c9af96c51ea5638e07eea25057a216.tar.bz2 rneovim-e5d7003b02c9af96c51ea5638e07eea25057a216.zip |
build: rework formatting to use add_glob_target
This will ensure that we can pass flags and make adjustments from the
top level cmake file instead of digging through the cmake directory.
More importantly, this will only format files that have been changed.
This has a slightly higher initial cost compared to previous solution as
all files must be initially formatted, but the gained speed up should
more than make up for it quickly.
`make formatlua` is always run due to a quirk of stylua of always changing
modification time of the file regardless if there were any changes. This is not
a major blocker as stylua is very fast.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Format.cmake | 65 | ||||
-rw-r--r-- | cmake/Util.cmake | 1 |
2 files changed, 1 insertions, 65 deletions
diff --git a/cmake/Format.cmake b/cmake/Format.cmake deleted file mode 100644 index 7097e5766f..0000000000 --- a/cmake/Format.cmake +++ /dev/null @@ -1,65 +0,0 @@ -# Returns a list of all files that has been changed in current branch compared -# to master branch. This includes unstaged, staged and committed files. -function(get_changed_files outvar) - execute_process( - COMMAND git branch --show-current - OUTPUT_VARIABLE current_branch - OUTPUT_STRIP_TRAILING_WHITESPACE) - - execute_process( - COMMAND git merge-base master HEAD - OUTPUT_VARIABLE ancestor_commit - OUTPUT_STRIP_TRAILING_WHITESPACE) - - # Changed files that have been committed - execute_process( - COMMAND git diff --diff-filter=d --name-only ${ancestor_commit}...${current_branch} - OUTPUT_VARIABLE committed_files - OUTPUT_STRIP_TRAILING_WHITESPACE) - separate_arguments(committed_files NATIVE_COMMAND ${committed_files}) - - # Unstaged files - execute_process( - COMMAND git diff --diff-filter=d --name-only - OUTPUT_VARIABLE unstaged_files - OUTPUT_STRIP_TRAILING_WHITESPACE) - separate_arguments(unstaged_files NATIVE_COMMAND ${unstaged_files}) - - # Staged files - execute_process( - COMMAND git diff --diff-filter=d --cached --name-only - OUTPUT_VARIABLE staged_files - OUTPUT_STRIP_TRAILING_WHITESPACE) - separate_arguments(staged_files NATIVE_COMMAND ${staged_files}) - - set(files ${committed_files} ${unstaged_files} ${staged_files}) - list(REMOVE_DUPLICATES files) - - set(${outvar} "${files}" PARENT_SCOPE) -endfunction() - -get_changed_files(changed_files) - -if(LANG STREQUAL c) - list(FILTER changed_files INCLUDE REGEX "\\.[ch]$") - list(FILTER changed_files INCLUDE REGEX "^src/nvim/") - - if(changed_files) - if(FORMAT_PRG) - execute_process(COMMAND ${FORMAT_PRG} -c "src/uncrustify.cfg" --replace --no-backup ${changed_files}) - else() - message(STATUS "Uncrustify not found. Skip formatting C files.") - endif() - endif() -elseif(LANG STREQUAL lua) - list(FILTER changed_files INCLUDE REGEX "\\.lua$") - list(FILTER changed_files INCLUDE REGEX "^runtime/") - - if(changed_files) - if(FORMAT_PRG) - execute_process(COMMAND ${FORMAT_PRG} ${changed_files}) - else() - message(STATUS "Stylua not found. Skip formatting lua files.") - endif() - endif() -endif() diff --git a/cmake/Util.cmake b/cmake/Util.cmake index 01d34d6752..4723ad7e08 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -75,6 +75,7 @@ function(add_glob_target) list(APPEND ARG_FILES ${globfiles}) endforeach() + list(APPEND ARG_EXCLUDE runtime/lua/vim/_meta) # only generated files, always ignore foreach(exclude_pattern ${ARG_EXCLUDE}) list(FILTER ARG_FILES EXCLUDE REGEX ${exclude_pattern}) endforeach() |