ExternalProjectUpdateTest.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_GENERATOR} -T "${CMAKE_GENERATOR_TOOLSET}"
  14. -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
  15. -DTEST_GIT_TAG:STRING=${desired_tag}
  16. ${ExternalProjectUpdate_SOURCE_DIR}
  17. WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}
  18. RESULT_VARIABLE error_code
  19. )
  20. if(error_code)
  21. message(FATAL_ERROR "Could not configure the project.")
  22. endif()
  23. # Build
  24. execute_process(COMMAND ${CMAKE_COMMAND}
  25. --build ${ExternalProjectUpdate_BINARY_DIR}
  26. RESULT_VARIABLE error_code
  27. )
  28. if(error_code)
  29. message(FATAL_ERROR "Could not build the project.")
  30. endif()
  31. # Check the resulting SHA
  32. execute_process(COMMAND ${GIT_EXECUTABLE}
  33. rev-list --max-count=1 HEAD
  34. WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT
  35. RESULT_VARIABLE error_code
  36. OUTPUT_VARIABLE tag_sha
  37. OUTPUT_STRIP_TRAILING_WHITESPACE
  38. )
  39. if(error_code)
  40. message(FATAL_ERROR "Could not check the sha.")
  41. endif()
  42. if(NOT (${tag_sha} STREQUAL ${resulting_sha}))
  43. message(FATAL_ERROR "UPDATE_COMMAND produced
  44. ${tag_sha}
  45. when
  46. ${resulting_sha}
  47. was expected."
  48. )
  49. endif()
  50. if( NOT EXISTS ${FETCH_HEAD_file} AND ${fetch_expected})
  51. message( FATAL_ERROR "Fetch did NOT occur when it was expected.")
  52. endif()
  53. if( EXISTS ${FETCH_HEAD_file} AND NOT ${fetch_expected})
  54. message( FATAL_ERROR "Fetch DID occur when it was not expected.")
  55. endif()
  56. endmacro()
  57. find_package(Git)
  58. set(do_git_tests 0)
  59. if(GIT_EXECUTABLE)
  60. set(do_git_tests 1)
  61. execute_process(
  62. COMMAND "${GIT_EXECUTABLE}" --version
  63. OUTPUT_VARIABLE ov
  64. OUTPUT_STRIP_TRAILING_WHITESPACE
  65. )
  66. string(REGEX REPLACE "^git version (.+)$" "\\1" git_version "${ov}")
  67. message(STATUS "git_version='${git_version}'")
  68. if(git_version VERSION_LESS 1.6.5)
  69. message(STATUS "No ExternalProject git tests with git client less than version 1.6.5")
  70. set(do_git_tests 0)
  71. endif()
  72. endif()
  73. if(do_git_tests)
  74. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  75. check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
  76. # With the Git UPDATE_COMMAND performance patch, this will not required a
  77. # 'git fetch'
  78. check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
  79. check_a_tag(tag2 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  80. check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 1)
  81. check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 0)
  82. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  83. # This is a remote symbolic ref, so it will always trigger a 'git fetch'
  84. check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1)
  85. endif()