diff options
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | cmake/GetGitRevisionDescription.cmake | 56 | ||||
-rw-r--r-- | neovim.rb | 1 |
3 files changed, 41 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8fab8d52e5..87dd600606 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,9 @@ list(APPEND CMAKE_PREFIX_PATH ${DEPS_INSTALL_DIR}) # Version tokens include(GetGitRevisionDescription) get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT) +if (NOT NVIM_VERSION_COMMIT) + set(NVIM_VERSION_COMMIT "?") +endif() set(NVIM_VERSION_MAJOR 0) set(NVIM_VERSION_MINOR 0) set(NVIM_VERSION_PATCH 0) @@ -22,7 +25,9 @@ set(NVIM_VERSION_PRERELEASE "-alpha") # TODO(justinmk): UTC time would be nice here #1071 git_timestamp(GIT_TIMESTAMP) # TODO(justinmk): do not set this for "release" builds #1071 -set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") +if (GIT_TIMESTAMP) + set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") +endif() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake index 42775057f1..dec748d094 100644 --- a/cmake/GetGitRevisionDescription.cmake +++ b/cmake/GetGitRevisionDescription.cmake @@ -41,16 +41,18 @@ set(__get_git_revision_description YES) # to find the path to this module rather than the path to a calling list file get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) -function(get_git_head_revision _refspecvar _hashvar) - set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories +function(get_git_dir _gitdir) + # check GIT_DIR in environment first + set(GIT_DIR "$ENV{GIT_DIR}") + if(NOT GIT_DIR) + set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endif() + # .git dir not found, search parent directories + while(NOT EXISTS "${GIT_DIR}") set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) - # We have reached the root directory, we are not in git - set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) return() endif() set(GIT_DIR "${GIT_PARENT_DIR}/.git") @@ -62,6 +64,15 @@ function(get_git_head_revision _refspecvar _hashvar) get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) endif() + set(${_gitdir} ${GIT_DIR} PARENT_SCOPE) +endfunction() + +function(get_git_head_revision _refspecvar _hashvar) + get_git_dir(GIT_DIR) + if(NOT GIT_DIR) + return() + endif() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") if(NOT EXISTS "${GIT_DATA}") file(MAKE_DIRECTORY "${GIT_DATA}") @@ -83,36 +94,32 @@ function(get_git_head_revision _refspecvar _hashvar) endfunction() function(git_describe _var) + get_git_dir(GIT_DIR) + if(NOT GIT_DIR) + return() + endif() + if(NOT GIT_FOUND) find_package(Git QUIET) endif() - get_git_head_revision(refspec hash) if(NOT GIT_FOUND) set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) return() endif() + + get_git_head_revision(refspec hash) if(NOT hash) set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) return() endif() - # TODO sanitize - #if((${ARGN}" MATCHES "&&") OR - # (ARGN MATCHES "||") OR - # (ARGN MATCHES "\\;")) - # message("Please report the following error to the project!") - # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") - #endif() - - #message(STATUS "Arguments to execute_process: ${ARGN}") - execute_process(COMMAND "${GIT_EXECUTABLE}" describe ${hash} ${ARGN} WORKING_DIRECTORY - "${CMAKE_SOURCE_DIR}" + "${GIT_DIR}" RESULT_VARIABLE res OUTPUT_VARIABLE @@ -127,21 +134,26 @@ function(git_describe _var) endfunction() function(git_timestamp _var) + get_git_dir(GIT_DIR) + if(NOT GIT_DIR) + return() + endif() + if(NOT GIT_FOUND) find_package(Git QUIET) endif() - get_git_head_revision(refspec hash) if(NOT GIT_FOUND) - set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) return() endif() + + get_git_head_revision(refspec hash) if(NOT hash) set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) return() endif() execute_process(COMMAND "${GIT_EXECUTABLE}" log -1 --format="%ci" ${hash} ${ARGN} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + WORKING_DIRECTORY "${GIT_DIR}" RESULT_VARIABLE res OUTPUT_VARIABLE out ERROR_QUIET @@ -10,6 +10,7 @@ class Neovim < Formula depends_on "autoconf" => :build def install + ENV["GIT_DIR"] = cached_download/".git" if build.head? ENV.deparallelize system "make", "CMAKE_EXTRA_FLAGS=\"-DCMAKE_INSTALL_PREFIX:PATH=#{prefix}\"", "install" end |