diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-03 00:08:17 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-03 00:08:17 -0600 |
commit | 9449e1b8d273ff78eb894c588110ffa0c17d6ee3 (patch) | |
tree | 9e4470c33bd4187d9f42f0b2c4aaa995310c5be8 /cmake | |
parent | 308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (diff) | |
parent | b8dcbcc732baf84fc48d6b272c3ade0bcb129b3b (diff) | |
download | rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.gz rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.bz2 rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.zip |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CheckUncrustifyVersion.cmake | 13 | ||||
-rw-r--r-- | cmake/Format.cmake | 67 | ||||
-rw-r--r-- | cmake/GenerateVersion.cmake | 33 |
3 files changed, 91 insertions, 22 deletions
diff --git a/cmake/CheckUncrustifyVersion.cmake b/cmake/CheckUncrustifyVersion.cmake new file mode 100644 index 0000000000..4812c24ace --- /dev/null +++ b/cmake/CheckUncrustifyVersion.cmake @@ -0,0 +1,13 @@ +if(UNCRUSTIFY_PRG) + execute_process(COMMAND uncrustify --version + OUTPUT_VARIABLE user_version + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "[A-Za-z_#-]" "" user_version ${user_version}) + + file(STRINGS ${CONFIG_FILE} required_version LIMIT_COUNT 1) + string(REGEX REPLACE "[A-Za-z_# -]" "" required_version ${required_version}) + + if(NOT user_version STREQUAL required_version) + message(FATAL_ERROR "Wrong uncrustify version! Required version is ${required_version} but found ${user_version}") + endif() +endif() diff --git a/cmake/Format.cmake b/cmake/Format.cmake new file mode 100644 index 0000000000..4115e66705 --- /dev/null +++ b/cmake/Format.cmake @@ -0,0 +1,67 @@ +# 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) + set(default_branch master) + + execute_process( + COMMAND git branch --show-current + OUTPUT_VARIABLE current_branch + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND git merge-base ${default_branch} ${current_branch} + OUTPUT_VARIABLE ancestor_commit + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # Changed files that have been committed + execute_process( + COMMAND git diff --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 --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 --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/GenerateVersion.cmake b/cmake/GenerateVersion.cmake index b9313f2498..6118d8cba7 100644 --- a/cmake/GenerateVersion.cmake +++ b/cmake/GenerateVersion.cmake @@ -1,48 +1,37 @@ -# Handle generating version from Git. -set(use_git_version 0) if(NVIM_VERSION_MEDIUM) message(STATUS "USING NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") return() endif() -find_program(GIT_EXECUTABLE git) -if(NOT GIT_EXECUTABLE) - message(AUTHOR_WARNING "Skipping version-string generation (cannot find git)") - file(WRITE "${OUTPUT}" "") - return() -endif() +set(NVIM_VERSION_MEDIUM + "v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}${NVIM_VERSION_PRERELEASE}") execute_process( - COMMAND git describe --first-parent --tags --always --dirty + COMMAND git describe --first-parent --dirty OUTPUT_VARIABLE GIT_TAG ERROR_VARIABLE ERR RESULT_VARIABLE RES ) -if("${RES}" EQUAL 1) - if(EXISTS ${OUTPUT}) - message(STATUS "Unable to extract version-string from git: keeping the last known version") - else() - # this will only be executed once since the file will get generated afterwards - message(AUTHOR_WARNING "Git tag extraction failed with: " "${ERR}") - file(WRITE "${OUTPUT}" "") - endif() +if(NOT RES EQUAL 0) + message(STATUS "Git tag extraction failed:\n" " ${GIT_TAG}${ERR}" ) + # This will only be executed once since the file will get generated afterwards. + message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") + file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") return() endif() string(STRIP "${GIT_TAG}" GIT_TAG) string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}") -set(NVIM_VERSION_MEDIUM - "v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}-dev-${NVIM_VERSION_GIT}" -) +set(NVIM_VERSION_MEDIUM "${NVIM_VERSION_MEDIUM}-${NVIM_VERSION_GIT}") set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION_MEDIUM}\"\n") -string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}") +string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}") if(EXISTS ${OUTPUT}) file(SHA1 "${OUTPUT}" NVIM_VERSION_HASH) endif() if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}") - message(STATUS "Updating NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") + message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}") file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}") endif() |