summaryrefslogtreecommitdiffstats
path: root/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake
blob: fed40ef49e424a1b180b9b99891eff27912bcc0b (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Set the ExternalProject GIT_TAG to desired_tag, and make sure the
# resulting checked out version is resulting_sha and a rebuild.
# This check's the viability of the ExternalProject UPDATE_COMMAND.
macro(check_a_tag desired_tag resulting_sha)
  # Configure
  execute_process(COMMAND ${CMAKE_COMMAND}
    -G ${CMAKE_TEST_GENERATOR}
    -DTEST_GIT_TAG:STRING=${desired_tag}
    ${ExternalProjectUpdate_SOURCE_DIR}
    WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}
    RESULT_VARIABLE error_code
    )
  if(error_code)
    message(FATAL_ERROR "Could not configure the project.")
  endif()

  # Build
  execute_process(COMMAND ${CMAKE_COMMAND}
    --build ${ExternalProjectUpdate_BINARY_DIR}
    RESULT_VARIABLE error_code
    )
  if(error_code)
    message(FATAL_ERROR "Could not build the project.")
  endif()

  # Check the resulting SHA
  execute_process(COMMAND ${GIT_EXECUTABLE}
    rev-list --max-count=1 HEAD
    WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT
    RESULT_VARIABLE error_code
    OUTPUT_VARIABLE tag_sha
    )
  if(error_code)
    message(FATAL_ERROR "Could not check the sha.")
  endif()

  string(STRIP "${tag_sha}" tag_sha)
  if(NOT (${tag_sha} STREQUAL ${resulting_sha}))
    message(FATAL_ERROR "UPDATE_COMMAND produced
  ${tag_sha}
when
  ${resulting_sha}
was expected."
    )
  endif()
endmacro()

find_package(Git)
if(GIT_EXECUTABLE)
  check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7)
  check_a_tag(tag1          d1970730310fe8bc07e73f15dc570071f9f9654a)
  # With the Git UPDATE_COMMAND performance patch, this will not required a
  # 'git fetch'
  check_a_tag(tag1          d1970730310fe8bc07e73f15dc570071f9f9654a)
  check_a_tag(tag2          5842b503ba4113976d9bb28d57b5aee1ad2736b7)
  check_a_tag(d19707303     d1970730310fe8bc07e73f15dc570071f9f9654a)
  check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7)
endif()