ExternalProjectUpdateTest.cmake 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Set the ExternalProject GIT_TAG to desired_tag, and make sure the
  2. # resulting checked out version is resulting_sha and rebuild.
  3. # This check's the correct behavior of the ExternalProject UPDATE_COMMAND.
  4. # Also verify that a fetch only occurs when fetch_expected is 1.
  5. macro(check_a_tag desired_tag resulting_sha fetch_expected)
  6. message( STATUS "Checking ExternalProjectUpdate to tag: ${desired_tag}" )
  7. # Remove the FETCH_HEAD file, so we can check if it gets replaced with a 'git
  8. # fetch'.
  9. set( FETCH_HEAD_file ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT/.git/FETCH_HEAD )
  10. file( REMOVE ${FETCH_HEAD_file} )
  11. # Configure
  12. execute_process(COMMAND ${CMAKE_COMMAND}
  13. -G ${CMAKE_TEST_GENERATOR} -T "${CMAKE_TEST_GENERATOR_TOOLSET}"
  14. -DTEST_GIT_TAG:STRING=${desired_tag}
  15. ${ExternalProjectUpdate_SOURCE_DIR}
  16. WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}
  17. RESULT_VARIABLE error_code
  18. )
  19. if(error_code)
  20. message(FATAL_ERROR "Could not configure the project.")
  21. endif()
  22. # Build
  23. execute_process(COMMAND ${CMAKE_COMMAND}
  24. --build ${ExternalProjectUpdate_BINARY_DIR}
  25. RESULT_VARIABLE error_code
  26. )
  27. if(error_code)
  28. message(FATAL_ERROR "Could not build the project.")
  29. endif()
  30. # Check the resulting SHA
  31. execute_process(COMMAND ${GIT_EXECUTABLE}
  32. rev-list --max-count=1 HEAD
  33. WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT
  34. RESULT_VARIABLE error_code
  35. OUTPUT_VARIABLE tag_sha
  36. OUTPUT_STRIP_TRAILING_WHITESPACE
  37. )
  38. if(error_code)
  39. message(FATAL_ERROR "Could not check the sha.")
  40. endif()
  41. if(NOT (${tag_sha} STREQUAL ${resulting_sha}))
  42. message(FATAL_ERROR "UPDATE_COMMAND produced
  43. ${tag_sha}
  44. when
  45. ${resulting_sha}
  46. was expected."
  47. )
  48. endif()
  49. if( NOT EXISTS ${FETCH_HEAD_file} AND ${fetch_expected})
  50. message( FATAL_ERROR "Fetch did NOT occur when it was expected.")
  51. endif()
  52. if( EXISTS ${FETCH_HEAD_file} AND NOT ${fetch_expected})
  53. message( FATAL_ERROR "Fetch DID occur when it was not expected.")
  54. endif()
  55. endmacro()
  56. find_package(Git)
  57. set(do_git_tests 0)
  58. if(GIT_EXECUTABLE)
  59. set(do_git_tests 1)
  60. execute_process(
  61. COMMAND "${GIT_EXECUTABLE}" --version
  62. OUTPUT_VARIABLE ov
  63. OUTPUT_STRIP_TRAILING_WHITESPACE
  64. )
  65. string(REGEX REPLACE "^git version (.+)$" "\\1" git_version "${ov}")
  66. message(STATUS "git_version='${git_version}'")
  67. if(git_version VERSION_LESS 1.6.5)
  68. message(STATUS "No ExternalProject git tests with git client less than version 1.6.5")
  69. set(do_git_tests 0)
  70. endif()
  71. endif()
  72. if(do_git_tests)
  73. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  74. check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
  75. # With the Git UPDATE_COMMAND performance patch, this will not required a
  76. # 'git fetch'
  77. check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
  78. check_a_tag(tag2 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  79. check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
  80. check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
  81. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  82. # This is a remote symbolic ref, so it will always trigger a 'git fetch'
  83. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  84. endif()