mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
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.
This commit is contained in:
parent
66f1563c7a
commit
e5d7003b02
@ -47,5 +47,6 @@ exclude_files = {
|
|||||||
'runtime/lua/vim/_meta/vimfn.lua',
|
'runtime/lua/vim/_meta/vimfn.lua',
|
||||||
'runtime/lua/vim/_meta/api.lua',
|
'runtime/lua/vim/_meta/api.lua',
|
||||||
'runtime/lua/vim/re.lua',
|
'runtime/lua/vim/re.lua',
|
||||||
|
'runtime/lua/coxpcall.lua',
|
||||||
'src/nvim/eval.lua',
|
'src/nvim/eval.lua',
|
||||||
}
|
}
|
||||||
|
@ -226,9 +226,6 @@ add_glob_target(
|
|||||||
FLAGS -ll ${PROJECT_SOURCE_DIR}/test/lua_runner.lua ${CMAKE_BINARY_DIR}/usr luacheck -q
|
FLAGS -ll ${PROJECT_SOURCE_DIR}/test/lua_runner.lua ${CMAKE_BINARY_DIR}/usr luacheck -q
|
||||||
GLOB_DIRS runtime/ scripts/ src/ test/
|
GLOB_DIRS runtime/ scripts/ src/ test/
|
||||||
GLOB_PAT *.lua
|
GLOB_PAT *.lua
|
||||||
EXCLUDE
|
|
||||||
runtime/lua/vim/_meta/.*
|
|
||||||
runtime/lua/coxpcall.lua
|
|
||||||
TOUCH_STRATEGY SINGLE)
|
TOUCH_STRATEGY SINGLE)
|
||||||
add_dependencies(lintlua-luacheck lua-dev-deps)
|
add_dependencies(lintlua-luacheck lua-dev-deps)
|
||||||
|
|
||||||
@ -238,8 +235,6 @@ add_glob_target(
|
|||||||
FLAGS --color=always --check --respect-ignores
|
FLAGS --color=always --check --respect-ignores
|
||||||
GLOB_DIRS runtime/
|
GLOB_DIRS runtime/
|
||||||
GLOB_PAT *.lua
|
GLOB_PAT *.lua
|
||||||
EXCLUDE
|
|
||||||
/runtime/lua/vim/_meta
|
|
||||||
TOUCH_STRATEGY SINGLE)
|
TOUCH_STRATEGY SINGLE)
|
||||||
|
|
||||||
add_custom_target(lintlua)
|
add_custom_target(lintlua)
|
||||||
@ -261,12 +256,12 @@ add_custom_target(lint)
|
|||||||
add_dependencies(lint lintc lintlua lintsh lintcommit)
|
add_dependencies(lint lintc lintlua lintsh lintcommit)
|
||||||
|
|
||||||
# Format
|
# Format
|
||||||
add_custom_target(formatlua
|
add_glob_target(
|
||||||
COMMAND ${CMAKE_COMMAND}
|
TARGET formatlua
|
||||||
-D FORMAT_PRG=${STYLUA_PRG}
|
COMMAND ${STYLUA_PRG}
|
||||||
-D LANG=lua
|
FLAGS --respect-ignores
|
||||||
-P ${PROJECT_SOURCE_DIR}/cmake/Format.cmake
|
GLOB_DIRS runtime
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
GLOB_PAT *.lua)
|
||||||
|
|
||||||
add_custom_target(format)
|
add_custom_target(format)
|
||||||
add_dependencies(format formatc formatlua)
|
add_dependencies(format formatc formatlua)
|
||||||
|
@ -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()
|
|
@ -75,6 +75,7 @@ function(add_glob_target)
|
|||||||
list(APPEND ARG_FILES ${globfiles})
|
list(APPEND ARG_FILES ${globfiles})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
list(APPEND ARG_EXCLUDE runtime/lua/vim/_meta) # only generated files, always ignore
|
||||||
foreach(exclude_pattern ${ARG_EXCLUDE})
|
foreach(exclude_pattern ${ARG_EXCLUDE})
|
||||||
list(FILTER ARG_FILES EXCLUDE REGEX ${exclude_pattern})
|
list(FILTER ARG_FILES EXCLUDE REGEX ${exclude_pattern})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
@ -879,12 +879,11 @@ add_glob_target(
|
|||||||
FLAGS -c ${UNCRUSTIFY_CONFIG} -q --check
|
FLAGS -c ${UNCRUSTIFY_CONFIG} -q --check
|
||||||
FILES ${LINT_NVIM_SOURCES})
|
FILES ${LINT_NVIM_SOURCES})
|
||||||
|
|
||||||
add_custom_target(formatc
|
add_glob_target(
|
||||||
COMMAND ${CMAKE_COMMAND}
|
TARGET formatc
|
||||||
-D FORMAT_PRG=${UNCRUSTIFY_PRG}
|
COMMAND ${UNCRUSTIFY_PRG}
|
||||||
-D LANG=c
|
FLAGS -c ${UNCRUSTIFY_CONFIG} --replace --no-backup
|
||||||
-P ${PROJECT_SOURCE_DIR}/cmake/Format.cmake
|
FILES ${LINT_NVIM_SOURCES})
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
|
||||||
|
|
||||||
add_dependencies(lintc-uncrustify uncrustify_update_config)
|
add_dependencies(lintc-uncrustify uncrustify_update_config)
|
||||||
add_dependencies(formatc uncrustify_update_config)
|
add_dependencies(formatc uncrustify_update_config)
|
||||||
|
Loading…
Reference in New Issue
Block a user