forked from manticoresoftware/manticoresearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sphinxrevcheck.cmake
69 lines (56 loc) · 2.45 KB
/
sphinxrevcheck.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cmake_minimum_required ( VERSION 3.17 )
# this file included by cpack config in order to detect if configured and build version are the same
# guess version strings from current git repo
function ( guess_from_git )
if (NOT EXISTS "${MANTICORE_SOURCE_DIR}/.git")
return ()
endif ()
find_package ( Git QUIET )
if (NOT GIT_FOUND)
return ()
endif ()
# without this in some environments you can get error "detected dubious ownership in repository"
# `git config --global --add safe.directory '*'` in the docker image it runs in may not help. TODO: check why
execute_process ( COMMAND "${GIT_EXECUTABLE}" config --global --add safe.directory "${MANTICORE_SOURCE_DIR}")
# extract short has as CHECK_GIT_COMMIT_ID
execute_process ( COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
WORKING_DIRECTORY "${MANTICORE_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE CHECK_GIT_COMMIT_ID
OUTPUT_STRIP_TRAILING_WHITESPACE )
set ( CHECK_GIT_COMMIT_ID "${CHECK_GIT_COMMIT_ID}" PARENT_SCOPE )
endfunction ()
# guess version strings from template header file (git archive mark it there)
function ( extract_from_git_slug HEADER )
if (EXISTS "${HEADER}")
FILE ( STRINGS "${HEADER}" _CONTENT )
foreach (LINE ${_CONTENT})
# match definitions like - // GIT_*_ID VALUE
if ("${LINE}" MATCHES "^//[ \t]+(GIT_.*_ID)[ \t]\"(.*)\"")
set ( ${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" )
endif ()
endforeach ()
if (GIT_COMMIT_ID STREQUAL "$Format:%h$")
return () # no slug
endif ()
# commit id
set ( CHECK_GIT_COMMIT_ID "${GIT_COMMIT_ID}" PARENT_SCOPE )
endif ()
endfunction ()
# function definitions finished, execution starts from here
##################################
# first try to use binary git
guess_from_git ()
# 2-nd try - if we build from git archive. Correct hash and date provided then, but no branch
if (NOT CHECK_GIT_COMMIT_ID)
message ( STATUS "guess_from_git failed. 2nd try - extract_from_git_slug" )
extract_from_git_slug ( "${MANTICORE_SOURCE_DIR}/src/sphinxversion.h.in" )
endif ()
if (NOT CHECK_GIT_COMMIT_ID)
message ( STATUS "extract_from_git_slug failed. 3rd try - forcing setting CHECK_GIT_COMMIT_ID" )
set ( CHECK_GIT_COMMIT_ID "DEADBEEF" )
endif ()
message ( STATUS "CHECK_GIT_COMMIT_ID=${CHECK_GIT_COMMIT_ID}" )
if (NOT CHECK_GIT_COMMIT_ID STREQUAL "${CONFIGURED_GIT_COMMIT_ID}")
message ( FATAL_ERROR "Current commit ${CHECK_GIT_COMMIT_ID} differs from the stored ${CONFIGURED_GIT_COMMIT_ID}. Run 'cmake .' in build dir to fix" )
endif ()