1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

gitcommit.cmake: stop needing TOPLEVEL_SOURCE_DIR.

It's always the same as the cwd when the script is invoked, and by
having the script get it _from_ its own cwd, we arrange a bit of
automatic normalisation in situations where you need to invoke it with
some non-canonical path like one ending in "/.." - which I'll do in
the next commit.
This commit is contained in:
Simon Tatham 2021-05-08 10:24:14 +01:00
parent 62283226da
commit c931c7f02a
3 changed files with 6 additions and 8 deletions

View File

@ -3,19 +3,19 @@
set(DEFAULT_COMMIT "unavailable") set(DEFAULT_COMMIT "unavailable")
set(commit "${DEFAULT_COMMIT}") set(commit "${DEFAULT_COMMIT}")
set(TOPLEVEL_SOURCE_DIR ${CMAKE_SOURCE_DIR})
execute_process( execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${TOPLEVEL_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --show-toplevel
rev-parse --show-toplevel
OUTPUT_VARIABLE git_worktree OUTPUT_VARIABLE git_worktree
ERROR_VARIABLE stderr ERROR_VARIABLE stderr
RESULT_VARIABLE status) RESULT_VARIABLE status)
string(REGEX REPLACE "\n$" "" git_worktree "${git_worktree}") string(REGEX REPLACE "\n$" "" git_worktree "${git_worktree}")
if(status EQUAL 0) if(status EQUAL 0)
if(git_worktree STREQUAL TOPLEVEL_SOURCE_DIR) if(git_worktree STREQUAL CMAKE_SOURCE_DIR)
execute_process( execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${TOPLEVEL_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
rev-parse HEAD
OUTPUT_VARIABLE git_commit OUTPUT_VARIABLE git_commit
ERROR_VARIABLE stderr ERROR_VARIABLE stderr
RESULT_VARIABLE status) RESULT_VARIABLE status)
@ -28,7 +28,7 @@ if(status EQUAL 0)
endif() endif()
else() else()
if(commit STREQUAL "unavailable") if(commit STREQUAL "unavailable")
message("Unable to determine git commit: top-level source dir ${TOPLEVEL_SOURCE_DIR} is not the root of a repository") message("Unable to determine git commit: top-level source dir ${CMAKE_SOURCE_DIR} is not the root of a repository")
endif() endif()
endif() endif()
else() else()

View File

@ -42,7 +42,6 @@ add_custom_target(check_git_commit
BYPRODUCTS ${INTERMEDIATE_COMMIT_C} BYPRODUCTS ${INTERMEDIATE_COMMIT_C}
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DTOPLEVEL_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-DOUTPUT_FILE=${INTERMEDIATE_COMMIT_C} -DOUTPUT_FILE=${INTERMEDIATE_COMMIT_C}
-DOUTPUT_TYPE=header -DOUTPUT_TYPE=header
-P ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake -P ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake

View File

@ -21,7 +21,6 @@ if(HALIBUT AND PERL_EXECUTABLE)
BYPRODUCTS ${INTERMEDIATE_VERSION_BUT} BYPRODUCTS ${INTERMEDIATE_VERSION_BUT}
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DTOPLEVEL_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-DOUTPUT_FILE=${INTERMEDIATE_VERSION_BUT} -DOUTPUT_FILE=${INTERMEDIATE_VERSION_BUT}
-DOUTPUT_TYPE=halibut -DOUTPUT_TYPE=halibut
-P ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake -P ${CMAKE_SOURCE_DIR}/cmake/gitcommit.cmake