summaryrefslogtreecommitdiff
path: root/tests/release/test_expiry_build_step.cmake
blob: 59e2b9576a375773b5ab6a89ef9cb883d1fbd82a (plain)
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
cmake_minimum_required (VERSION 3.12)

if (NOT SOURCE_DIR OR NOT BINARY_DIR OR NOT TEST_BINARY_DIR)
  message (FATAL_ERROR "SOURCE_DIR, BINARY_DIR, and TEST_BINARY_DIR are required")
endif ()

# A pending re-run of CMake must see the real environment, not the SOURCE_DATE_EPOCH set below.
execute_process (
  COMMAND "${CMAKE_COMMAND}" --build "${BINARY_DIR}" --target revisiontag
  RESULT_VARIABLE build_result
  OUTPUT_VARIABLE build_output
  ERROR_VARIABLE build_output)
if (NOT build_result EQUAL 0)
  message (FATAL_ERROR "Building revisiontag failed:\n${build_output}")
endif ()
file (STRINGS "${BINARY_DIR}/CMakeCache.txt" channel REGEX "^WSJT_RELEASE_CHANNEL:[A-Z]+=")
string (REGEX REPLACE "^[^=]*=" "" channel "${channel}")
if (NOT channel MATCHES "^(DEVEL|BETA|RC|GA)$")
  message (FATAL_ERROR "No release channel in ${BINARY_DIR}/CMakeCache.txt")
endif ()

include ("${SOURCE_DIR}/CMake/Modules/set_build_type.cmake")
set (ENV{SOURCE_DATE_EPOCH} 1700000000)
wsjt_prerelease_expiry ("${channel}" "${SOURCE_DIR}" expected)

set (header "${BINARY_DIR}/prerelease_expiry.h")
# file (COPY) keeps the timestamp, so restoring the header does not recompile main.cpp.
file (REMOVE_RECURSE "${TEST_BINARY_DIR}")
file (COPY "${header}" DESTINATION "${TEST_BINARY_DIR}")
execute_process (
  COMMAND "${CMAKE_COMMAND}" --build "${BINARY_DIR}" --target revisiontag
  RESULT_VARIABLE build_result
  OUTPUT_VARIABLE build_output
  ERROR_VARIABLE build_output)
file (READ "${header}" built)
file (COPY "${TEST_BINARY_DIR}/prerelease_expiry.h" DESTINATION "${BINARY_DIR}")

if (NOT build_result EQUAL 0)
  message (FATAL_ERROR "Building revisiontag failed:\n${build_output}")
endif ()
if (NOT built STREQUAL "#define WSJT_PRERELEASE_EXPIRY ${expected}\n")
  message (FATAL_ERROR "revisiontag wrote '${built}', expected ${expected} from SOURCE_DATE_EPOCH")
endif ()