Files
CPM.cmake/test/unit/cache.cmake

140 lines
3.9 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
include(${CPM_PATH}/testing.cmake)
include(CMakePackageConfigHelpers)
set(CPM_SOURCE_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/CPM")
2020-06-15 10:16:30 +02:00
set(TEST_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/remote_dependency)
function(clear_cache)
message(STATUS "clearing CPM cache")
file(REMOVE_RECURSE ${CPM_SOURCE_CACHE_DIR})
assert_not_exists("${CPM_SOURCE_CACHE_DIR}")
endfunction()
function(update_cmake_lists)
configure_package_config_file(
2020-06-15 10:16:30 +02:00
"${CMAKE_CURRENT_LIST_DIR}/remote_dependency/CMakeLists.txt.in"
"${CMAKE_CURRENT_LIST_DIR}/remote_dependency/CMakeLists.txt"
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/junk
)
endfunction()
function(reset_test)
clear_cache()
file(REMOVE_RECURSE ${TEST_BUILD_DIR})
update_cmake_lists()
endfunction()
Add file locking to support parallel runs. (#427) * Add file locking to support parallel runs. * Fixed formatting. * Prevent double locking file. * Fix SegFault from test 2. * Remove unnecessary debugging messages. * Lock the package directory rather than the cache directory. Only synchronize if CPM_SOURCE_CACHE is defined. * Lock the version specific cache entry rather than the package specific entry. * Remove unnecessary arguments in conditional statements. * Change back to locking entire cache directory. * Only check CPM_HAS_CACHE_LOCK. * Lock on a per-package basis rather than the entire cache. * Clean up the locked file. * Unlock then remove to fix Windows. * Specify use of cmake.lock as the lock file. * - Changed CPM_HAS_CACHE_LOCK to ${CPM_ARGS_NAME}_CPM_HAS_CACHE_LOCK. - Removed redundant variable initialization. * Add unit test. * Actually test if resulting git cache is clean in unit test. * - Added comments - Fixed formatting - Removed unnecessary imports * convert parallelism test to integration test * remove comment * - Removed now unnecessary variable. - Only delete file instead of unlocking it then deleting it. * Forgot to change variable name. * Add similar changes to the missed section. * Fixed formatting. * Unlock the file, but do not delete it. * Only unlock the file if it exists. * Changed cache.cmake test to ignore non-directory entries. * Integration test lib make_project: * keyword args * 'name' arg to allow multiple projects from the same test * - Moved checks to function. - Fixed small grammatical errors. * - Fix formatting * Switch to snake case. --------- Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> Co-authored-by: Lars Melchior <lars.melchior@gmail.com> Co-authored-by: Borislav Stanimirov <b.stanimirov@abv.bg>
2023-01-28 08:36:44 -05:00
function(assert_cache_directory_count directory count)
set(version_count 0)
file(GLOB potential_versions ${directory})
foreach(entry ${potential_versions})
if(IS_DIRECTORY ${entry})
math(EXPR version_count "${version_count} + 1")
endif()
endforeach()
assert_equal("${version_count}" "${count}")
endfunction()
set(FIBONACCI_VERSION 1.0)
# Read CPM_SOURCE_CACHE from arguments
reset_test()
execute_process(
COMMAND ${CMAKE_COMMAND} "-S${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}"
"-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" RESULT_VARIABLE ret
)
assert_equal(${ret} "0")
assert_exists("${CPM_SOURCE_CACHE_DIR}/fibonacci")
Add file locking to support parallel runs. (#427) * Add file locking to support parallel runs. * Fixed formatting. * Prevent double locking file. * Fix SegFault from test 2. * Remove unnecessary debugging messages. * Lock the package directory rather than the cache directory. Only synchronize if CPM_SOURCE_CACHE is defined. * Lock the version specific cache entry rather than the package specific entry. * Remove unnecessary arguments in conditional statements. * Change back to locking entire cache directory. * Only check CPM_HAS_CACHE_LOCK. * Lock on a per-package basis rather than the entire cache. * Clean up the locked file. * Unlock then remove to fix Windows. * Specify use of cmake.lock as the lock file. * - Changed CPM_HAS_CACHE_LOCK to ${CPM_ARGS_NAME}_CPM_HAS_CACHE_LOCK. - Removed redundant variable initialization. * Add unit test. * Actually test if resulting git cache is clean in unit test. * - Added comments - Fixed formatting - Removed unnecessary imports * convert parallelism test to integration test * remove comment * - Removed now unnecessary variable. - Only delete file instead of unlocking it then deleting it. * Forgot to change variable name. * Add similar changes to the missed section. * Fixed formatting. * Unlock the file, but do not delete it. * Only unlock the file if it exists. * Changed cache.cmake test to ignore non-directory entries. * Integration test lib make_project: * keyword args * 'name' arg to allow multiple projects from the same test * - Moved checks to function. - Fixed small grammatical errors. * - Fix formatting * Switch to snake case. --------- Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> Co-authored-by: Lars Melchior <lars.melchior@gmail.com> Co-authored-by: Borislav Stanimirov <b.stanimirov@abv.bg>
2023-01-28 08:36:44 -05:00
assert_cache_directory_count("${CPM_SOURCE_CACHE_DIR}/fibonacci/*" 1)
# Update dependency and keep CPM_SOURCE_CACHE
set(FIBONACCI_VERSION 2.0)
update_cmake_lists()
execute_process(COMMAND ${CMAKE_COMMAND} ${TEST_BUILD_DIR} RESULT_VARIABLE ret)
assert_equal(${ret} "0")
Add file locking to support parallel runs. (#427) * Add file locking to support parallel runs. * Fixed formatting. * Prevent double locking file. * Fix SegFault from test 2. * Remove unnecessary debugging messages. * Lock the package directory rather than the cache directory. Only synchronize if CPM_SOURCE_CACHE is defined. * Lock the version specific cache entry rather than the package specific entry. * Remove unnecessary arguments in conditional statements. * Change back to locking entire cache directory. * Only check CPM_HAS_CACHE_LOCK. * Lock on a per-package basis rather than the entire cache. * Clean up the locked file. * Unlock then remove to fix Windows. * Specify use of cmake.lock as the lock file. * - Changed CPM_HAS_CACHE_LOCK to ${CPM_ARGS_NAME}_CPM_HAS_CACHE_LOCK. - Removed redundant variable initialization. * Add unit test. * Actually test if resulting git cache is clean in unit test. * - Added comments - Fixed formatting - Removed unnecessary imports * convert parallelism test to integration test * remove comment * - Removed now unnecessary variable. - Only delete file instead of unlocking it then deleting it. * Forgot to change variable name. * Add similar changes to the missed section. * Fixed formatting. * Unlock the file, but do not delete it. * Only unlock the file if it exists. * Changed cache.cmake test to ignore non-directory entries. * Integration test lib make_project: * keyword args * 'name' arg to allow multiple projects from the same test * - Moved checks to function. - Fixed small grammatical errors. * - Fix formatting * Switch to snake case. --------- Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> Co-authored-by: Lars Melchior <lars.melchior@gmail.com> Co-authored-by: Borislav Stanimirov <b.stanimirov@abv.bg>
2023-01-28 08:36:44 -05:00
assert_cache_directory_count("${CPM_SOURCE_CACHE_DIR}/fibonacci/*" 2)
# Clear cache and update
clear_cache()
execute_process(COMMAND ${CMAKE_COMMAND} ${TEST_BUILD_DIR} RESULT_VARIABLE ret)
assert_equal(${ret} "0")
assert_exists("${CPM_SOURCE_CACHE_DIR}/fibonacci")
# Read CPM_SOURCE_CACHE from environment
reset_test()
execute_process(
COMMAND ${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND}
"-S${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}" RESULT_VARIABLE ret
)
assert_equal(${ret} "0")
assert_exists("${CPM_SOURCE_CACHE_DIR}/fibonacci")
# Reuse cached packages for other build
execute_process(
COMMAND ${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND}
"-S${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}-2"
RESULT_VARIABLE ret
)
assert_equal(${ret} "0")
# Overwrite CPM_SOURCE_CACHE with argument
reset_test()
execute_process(
COMMAND
${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CMAKE_CURRENT_BINARY_DIR}/junk" ${CMAKE_COMMAND}
"-S${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}"
"-DCPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}"
RESULT_VARIABLE ret
)
assert_equal(${ret} "0")
assert_exists("${CPM_SOURCE_CACHE_DIR}/fibonacci")
# Use NO_CACHE option
set(FIBONACCI_PACKAGE_ARGS "NO_CACHE YES")
2020-06-15 10:16:30 +02:00
set(FIBONACCI_VERSION 1.0)
update_cmake_lists()
reset_test()
execute_process(
COMMAND ${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND}
"-S${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}" RESULT_VARIABLE ret
2020-06-15 10:16:30 +02:00
)
assert_equal(${ret} "0")
assert_not_exists("${CPM_SOURCE_CACHE_DIR}/fibonacci")
2020-06-15 10:16:30 +02:00
# Use commit hash after version
2020-06-15 10:16:30 +02:00
set(FIBONACCI_PACKAGE_ARGS "NO_CACHE YES GIT_TAG e9ebf168ca0fffaa4ef8c6fefc6346aaa22f6ed5")
set(FIBONACCI_VERSION 1.1)
update_cmake_lists()
execute_process(
COMMAND ${CMAKE_COMMAND} -E env "CPM_SOURCE_CACHE=${CPM_SOURCE_CACHE_DIR}" ${CMAKE_COMMAND}
"-S${CMAKE_CURRENT_LIST_DIR}/remote_dependency" "-B${TEST_BUILD_DIR}" RESULT_VARIABLE ret
)
assert_equal(${ret} "0")
assert_not_exists("${CPM_SOURCE_CACHE_DIR}/fibonacci")