ExternalProjectUpdateTest.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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}
  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. if(GIT_EXECUTABLE)
  58. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  59. check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
  60. # With the Git UPDATE_COMMAND performance patch, this will not required a
  61. # 'git fetch'
  62. check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
  63. check_a_tag(tag2 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  64. check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
  65. check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
  66. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  67. # This is a remote symbolic ref, so it will always trigger a 'git fetch'
  68. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  69. endif()