From 26b30a4af97f0e87029bff3e5b908b825f1d2d40 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 15 Nov 2026 10:15:46 +0100 Subject: [PATCH 1/5] Keep the configure downloads once per machine and retry them (#570) The bootstrap environment, the test registry and jasmine-core were downloaded again by every new build tree, in one attempt: a network hiccup stopped the configure, and a second tree on the same machine paid the download again. webfront_download_verified() now serves both provisioners. A download goes to WEBFRONT_DOWNLOAD_CACHE (the environment variable of that name, else CPM's cache, else the user's cache directory for WebFront's own build; a consuming project keeps its downloads in its build tree unless it sets one), under the first half of its SHA-512, written aside and renamed once verified. The build tree then links it, or copies it where a link cannot be made. A failed download is tried three times; data with another digest never reaches the cache or the build tree. BootstrapProvisioning covers the cache: a fill, a second tree served without the source, a damaged entry downloaded again, a wrong digest kept out, and the retries before the offline hint. --- AGENTS.md | 5 +- cmake/WebFrontBootstrap.cmake | 120 +++++++++++++++++--- cmake/WebFrontRegistry.cmake | 29 ++--- docs/CHANGELOG.md | 1 + docs/DEVELOPER_ENVIRONMENT.md | 8 +- test/cmake/CheckBootstrapProvisioning.cmake | 57 ++++++++-- 6 files changed, 169 insertions(+), 51 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 6d651de7..07614c0c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -82,8 +82,9 @@ Important CMake options: The headers of the embedded assets are generated, and checked by CTest, in pure CMake (`js/core/EmbedAsset.cmake`; the `webfront-embedded-assets` target regenerates them). Normal C++ builds consume the versioned headers. Configuring with `WEBFRONT_ENABLE_TESTING=ON` downloads the pinned bootstrap environment and the packages of the test registry, each verified -against its SHA-512; `-DWEBFRONT_BOOTSTRAP_DIR` and `-DWEBFRONT_REGISTRY_DIR` replace those downloads on a machine -without network access. +against its SHA-512, tried three times and kept once per machine (`WEBFRONT_DOWNLOAD_CACHE`, by default in CPM's cache or +the user's cache directory), so a new build tree links them instead of downloading them again; `-DWEBFRONT_BOOTSTRAP_DIR` +and `-DWEBFRONT_REGISTRY_DIR` replace those downloads on a machine without network access. - `WEBFRONT_EMBED_CEF=OFF` (default): CEF is unavailable; this is the normal unit-test build. `ON` downloads/links CEF and enables the automated browser test; it makes `CEFFrontend` available but does not select it: `webfront::WebFront` always uses the system browser. - `WEBFRONT_EMBED_WEBVIEW2=OFF` (default): Windows-only opt-in SDK and static loader for `WebView2Frontend`; requires the separately installed Evergreen runtime. Select it explicitly with `WebFrontWithFrontend`. With tests enabled, `WEBFRONT_WEBTEST_FRONTEND=WebView2` runs the shared Jasmine suite and lifecycle cases. diff --git a/cmake/WebFrontBootstrap.cmake b/cmake/WebFrontBootstrap.cmake index dba1b6fb..6dbe2943 100644 --- a/cmake/WebFrontBootstrap.cmake +++ b/cmake/WebFrontBootstrap.cmake @@ -15,6 +15,105 @@ set(WEBFRONT_BOOTSTRAP_INTEGRITY "sha512-qaSYOJvxcXtKIbrjfjZFFvfoQrda5NfBq24ttQ7 # A directory holding environment.tgz (the pinned archive) replaces the download on a machine without network access. set(WEBFRONT_BOOTSTRAP_DIR "" CACHE PATH "Directory with the pinned bootstrap environment.tgz, instead of downloading it") +# The verified downloads of the configure, kept once per machine: a new build tree links them instead of downloading them +# again. WEBFRONT_DOWNLOAD_CACHE or CPM's cache chooses the place; WebFront's own build otherwise uses the user's cache +# directory, and a project that consumes WebFront keeps each download in its build tree unless it asks. Empty disables it. +get_filename_component(_webfront_source "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) +set(_webfront_download_cache "") +if(DEFINED ENV{WEBFRONT_DOWNLOAD_CACHE}) + set(_webfront_download_cache "$ENV{WEBFRONT_DOWNLOAD_CACHE}") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(_webfront_download_cache "$ENV{CPM_SOURCE_CACHE}/webfront-downloads") +elseif(NOT CMAKE_SOURCE_DIR STREQUAL _webfront_source) + # A consuming project: each download stays in its build tree. +elseif(CMAKE_HOST_WIN32 AND DEFINED ENV{LOCALAPPDATA}) + set(_webfront_download_cache "$ENV{LOCALAPPDATA}/WebFront/downloads") +elseif(CMAKE_HOST_APPLE AND DEFINED ENV{HOME}) + set(_webfront_download_cache "$ENV{HOME}/Library/Caches/WebFront/downloads") +elseif(DEFINED ENV{XDG_CACHE_HOME}) + set(_webfront_download_cache "$ENV{XDG_CACHE_HOME}/webfront/downloads") +elseif(DEFINED ENV{HOME}) + set(_webfront_download_cache "$ENV{HOME}/.cache/webfront/downloads") +endif() +set(WEBFRONT_DOWNLOAD_CACHE "${_webfront_download_cache}" CACHE PATH "Directory keeping the verified configure downloads for every build tree (empty: none)") +# A download that fails is tried again, WEBFRONT_DOWNLOAD_ATTEMPTS times in all, WEBFRONT_DOWNLOAD_RETRY_DELAY seconds apart. +if(NOT DEFINED WEBFRONT_DOWNLOAD_ATTEMPTS) + set(WEBFRONT_DOWNLOAD_ATTEMPTS 3) +endif() +if(NOT DEFINED WEBFRONT_DOWNLOAD_RETRY_DELAY) + set(WEBFRONT_DOWNLOAD_RETRY_DELAY 5) +endif() + +# webfront_download_verified( URL SHA512 FAILURE MISMATCH ): makes a file whose SHA-512 +# is . A file already there with that digest is kept. Otherwise the machine's download cache provides it, a download +# filling the cache first; is then a link to the cached file, or a copy where a link cannot be made. A download that +# fails is tried again; when it still fails, the configure stops with FAILURE and the reason, and with MISMATCH when the +# data it brought has another digest. No file without the expected digest is ever left at or in the cache. +function(webfront_download_verified path) + cmake_parse_arguments(ARG "" "URL;SHA512;FAILURE;MISMATCH" "" ${ARGN}) + if(EXISTS "${path}") + file(SHA512 "${path}" actual) + if(actual STREQUAL ARG_SHA512) + return() + endif() + file(REMOVE "${path}") + endif() + get_filename_component(name "${path}" NAME) + get_filename_component(destination "${path}" DIRECTORY) + file(MAKE_DIRECTORY "${destination}") + set(target "${path}") + if(WEBFRONT_DOWNLOAD_CACHE) + # The first half of the digest names the entry: two files of the same name and version never meet. + string(SUBSTRING "${ARG_SHA512}" 0 32 key) + file(MAKE_DIRECTORY "${WEBFRONT_DOWNLOAD_CACHE}/${key}" RESULT made) + if(made EQUAL 0) + set(target "${WEBFRONT_DOWNLOAD_CACHE}/${key}/${name}") + else() + message(WARNING "The download cache ${WEBFRONT_DOWNLOAD_CACHE} cannot be written (${made}): ${name} is kept in the build tree only") + endif() + endif() + set(present FALSE) + if(NOT target STREQUAL path AND EXISTS "${target}") + file(SHA512 "${target}" actual) + if(actual STREQUAL ARG_SHA512) + set(present TRUE) + else() + file(REMOVE "${target}") + endif() + endif() + if(NOT present) + foreach(attempt RANGE 1 ${WEBFRONT_DOWNLOAD_ATTEMPTS}) + # Written aside, then renamed once verified: a concurrent configure never reads a partial file. + string(RANDOM LENGTH 12 suffix) + set(partial "${target}.${suffix}.partial") + file(DOWNLOAD "${ARG_URL}" "${partial}" STATUS result TLS_VERIFY ON INACTIVITY_TIMEOUT 60 TIMEOUT 600) + list(GET result 0 code) + if(code EQUAL 0) + file(SHA512 "${partial}" actual) + if(NOT actual STREQUAL ARG_SHA512) + file(REMOVE "${partial}") + message(FATAL_ERROR "${ARG_MISMATCH}") + endif() + file(RENAME "${partial}" "${target}") + set(present TRUE) + break() + endif() + file(REMOVE "${partial}") + list(GET result 1 reason) + if(attempt LESS WEBFRONT_DOWNLOAD_ATTEMPTS) + message(STATUS "Download of ${ARG_URL} failed (${reason}); trying again in ${WEBFRONT_DOWNLOAD_RETRY_DELAY} s") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep ${WEBFRONT_DOWNLOAD_RETRY_DELAY}) + endif() + endforeach() + if(NOT present) + message(FATAL_ERROR "${ARG_FAILURE}: ${reason} (${WEBFRONT_DOWNLOAD_ATTEMPTS} attempts)") + endif() + endif() + if(NOT target STREQUAL path) + file(CREATE_LINK "${target}" "${path}" COPY_ON_ERROR) + endif() +endfunction() + # Converts a base64 value to lowercase hexadecimal bytes. function(webfront_base64_to_hex value output) set(alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") @@ -86,24 +185,9 @@ function(webfront_provision_bootstrap archive) endif() else() set(path "${ARG_DESTINATION}/${name}") - set(present FALSE) - if(EXISTS "${path}") - file(SHA512 "${path}" actual) - if(actual STREQUAL expected) - set(present TRUE) - endif() - endif() - if(NOT present) - file(MAKE_DIRECTORY "${ARG_DESTINATION}") - file(DOWNLOAD "${ARG_URL}" "${path}" STATUS result TLS_VERIFY ON INACTIVITY_TIMEOUT 60 TIMEOUT 600) - list(GET result 0 code) - if(NOT code EQUAL 0) - file(REMOVE "${path}") - list(GET result 1 reason) - message(FATAL_ERROR "Cannot download the bootstrap environment ${ARG_URL}: ${reason}. " - "Provision it with -DWEBFRONT_BOOTSTRAP_DIR=.") - endif() - endif() + webfront_download_verified("${path}" URL "${ARG_URL}" SHA512 "${expected}" + FAILURE "Cannot download the bootstrap environment ${ARG_URL}. Provision it with -DWEBFRONT_BOOTSTRAP_DIR=" + MISMATCH "Bootstrap environment integrity check failed for ${ARG_URL}: expected ${ARG_INTEGRITY}") endif() file(SHA512 "${path}" actual) if(NOT actual STREQUAL expected) diff --git a/cmake/WebFrontRegistry.cmake b/cmake/WebFrontRegistry.cmake index be76d82c..5b313fba 100644 --- a/cmake/WebFrontRegistry.cmake +++ b/cmake/WebFrontRegistry.cmake @@ -25,28 +25,15 @@ function(webfront_provision_registry output list directory) set(name "${CMAKE_MATCH_1}-${name}") endif() set(path "${directory}/${name}") - set(present FALSE) - if(EXISTS "${path}") - file(SHA512 "${path}" actual) - if(actual STREQUAL expected) - set(present TRUE) - endif() - endif() - if(NOT present) - if(WEBFRONT_REGISTRY_DIR) - if(NOT EXISTS "${WEBFRONT_REGISTRY_DIR}/${name}") - message(FATAL_ERROR "Test registry archive ${WEBFRONT_REGISTRY_DIR}/${name} is missing: WEBFRONT_REGISTRY_DIR must hold it") - endif() - file(COPY_FILE "${WEBFRONT_REGISTRY_DIR}/${name}" "${path}" ONLY_IF_DIFFERENT) - else() - file(DOWNLOAD "${url}" "${path}" STATUS result TLS_VERIFY ON INACTIVITY_TIMEOUT 60 TIMEOUT 600) - list(GET result 0 code) - if(NOT code EQUAL 0) - file(REMOVE "${path}") - list(GET result 1 reason) - message(FATAL_ERROR "Cannot download ${url}: ${reason}. Provision the archives with -DWEBFRONT_REGISTRY_DIR=.") - endif() + if(WEBFRONT_REGISTRY_DIR) + if(NOT EXISTS "${WEBFRONT_REGISTRY_DIR}/${name}") + message(FATAL_ERROR "Test registry archive ${WEBFRONT_REGISTRY_DIR}/${name} is missing: WEBFRONT_REGISTRY_DIR must hold it") endif() + file(COPY_FILE "${WEBFRONT_REGISTRY_DIR}/${name}" "${path}" ONLY_IF_DIFFERENT) + else() + webfront_download_verified("${path}" URL "${url}" SHA512 "${expected}" + FAILURE "Cannot download ${url}. Provision the archives with -DWEBFRONT_REGISTRY_DIR=" + MISMATCH "Integrity check failed for ${name}: expected ${integrity}") endif() file(SHA512 "${path}" actual) if(NOT actual STREQUAL expected) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 10fa1973..3253cd6c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -29,6 +29,7 @@ these entries stays in the GitHub releases and the Git history. - Keep automated browser windows visible (#544, #556, `docs/TEST_PERFORMANCE.md`). - Run each developer integration part and each wf command of the tests in a process of its own again: the shared windows of #544 and #556 made the driver cases about a third slower on Windows and failed more often. Remove the timing analysis tools and their CI steps, and repeat the desktop suite through one path, with `desktop_passes` on a manual dispatch (#570, `docs/TEST_PERFORMANCE.md`). - Close the test driver's window with `requestClose()` instead of asking the page: a spec that blocks the page now ends with the driver's timeout report instead of a forced exit (#570). +- Keep the configure downloads of the tests (bootstrap environment, test registry, jasmine-core) once per machine, in `WEBFRONT_DOWNLOAD_CACHE`, and try a failed download three times: a new build tree links the verified archives instead of downloading them again (#570, `docs/DEVELOPER_ENVIRONMENT.md`). - Declare GCC 13 as the best-effort S2 minimum for the library and examples, document the GCC 14 exit clause and qualified Clang scope, and add GCC 13 ASan/UBSan fast tests (#525, ADR-022). - Skip the cases that configure a CMake project (label `configuration`, about 75 s of worker time) and the coverage capture on a pull request that does not change the build system, and drop the compiler-cache probe step; a push to `develop` and the full tier still run them (#545). diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index 85f04b53..bfdb2b38 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -673,8 +673,12 @@ webfront-wf --project [--environment --integrity /bootstrap/` and verifies the - digest; a wrong digest or an unreachable URL stops the configure. On a machine without network access, pass - `-DWEBFRONT_BOOTSTRAP_DIR=`: the archive is verified the same way. + digest; a wrong digest, or a URL still unreachable after three attempts, stops the configure. The verified downloads are + kept once per machine in `WEBFRONT_DOWNLOAD_CACHE` (the `WEBFRONT_DOWNLOAD_CACHE` environment variable, else + `$CPM_SOURCE_CACHE/webfront-downloads`, else the user's cache directory for WebFront's own build; a consuming project keeps + them in its build tree unless it sets one): a new build tree links them instead of downloading them again. On a machine + without network access, pass `-DWEBFRONT_BOOTSTRAP_DIR=`: the archive is verified the + same way. - `--environment` and `--integrity` run an archive built elsewhere, such as the one built from the current sources (the environment under test of #315). `--registry-dir` serves a local npm registry from the driver's origin and imposes it. `--manifest-dir` keeps the manifest and the lock in that directory of the project (usage error 64 when it is absolute, has an empty or dot component or leaves the project). diff --git a/test/cmake/CheckBootstrapProvisioning.cmake b/test/cmake/CheckBootstrapProvisioning.cmake index 7b107b08..bc1fafac 100644 --- a/test/cmake/CheckBootstrapProvisioning.cmake +++ b/test/cmake/CheckBootstrapProvisioning.cmake @@ -1,4 +1,5 @@ -# Bootstrap provisioning at configure time: SRI conversion, verified download, local directory, integrity failures. +# Bootstrap provisioning at configure time: SRI conversion, verified download, machine download cache, retries, local +# directory, integrity failures. # Usage: cmake -DROOT= -DWORK= -P CheckBootstrapProvisioning.cmake include("${ROOT}/cmake/WebFrontBootstrap.cmake") @@ -35,18 +36,23 @@ file(WRITE "${WORK}/local/environment.tgz" "${content}") file(WRITE "${WORK}/tampered.tgz" "tampered\n") file(WRITE "${WORK}/run.cmake" [[ include("${ROOT}/cmake/WebFrontBootstrap.cmake") +if(NOT DESTINATION) + set(DESTINATION "${WORK}/cache") +endif() if(LOCAL) - webfront_provision_bootstrap(archive URL "${URL}" INTEGRITY "${INTEGRITY}" DESTINATION "${WORK}/cache" LOCAL_DIR "${LOCAL}") + webfront_provision_bootstrap(archive URL "${URL}" INTEGRITY "${INTEGRITY}" DESTINATION "${DESTINATION}" LOCAL_DIR "${LOCAL}") else() - webfront_provision_bootstrap(archive URL "${URL}" INTEGRITY "${INTEGRITY}" DESTINATION "${WORK}/cache") + webfront_provision_bootstrap(archive URL "${URL}" INTEGRITY "${INTEGRITY}" DESTINATION "${DESTINATION}") endif() message(STATUS "provisioned ${archive}") ]]) function(provision name result_var output_var) - cmake_parse_arguments(ARG "" "URL;INTEGRITY;LOCAL" "" ${ARGN}) + cmake_parse_arguments(ARG "" "URL;INTEGRITY;LOCAL;DESTINATION;CACHE" "" ${ARGN}) + # No retry delay, and the machine cache only where a case names one. execute_process(COMMAND "${CMAKE_COMMAND}" -DROOT=${ROOT} -DWORK=${WORK} -DURL=${ARG_URL} -DINTEGRITY=${ARG_INTEGRITY} - -DLOCAL=${ARG_LOCAL} -P "${WORK}/run.cmake" + -DLOCAL=${ARG_LOCAL} -DDESTINATION=${ARG_DESTINATION} -DWEBFRONT_DOWNLOAD_CACHE=${ARG_CACHE} + -DWEBFRONT_DOWNLOAD_RETRY_DELAY=0 -P "${WORK}/run.cmake" RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) set(${result_var} "${result}" PARENT_SCOPE) set(${output_var} "${out}${err}" PARENT_SCOPE) @@ -83,10 +89,45 @@ if(EXISTS "${WORK}/cache/environment.tgz") message(FATAL_ERROR "A downloaded archive that fails its integrity check must be removed") endif() -# A download failure names the offline alternative. +# A download failure is tried again, then names the offline alternative. provision(missing result text URL "${scheme}${WORK}/absent/environment.tgz" INTEGRITY "${sri}") -if(result EQUAL 0 OR NOT text MATCHES "WEBFRONT_BOOTSTRAP_DIR") - message(FATAL_ERROR "A failed download must point to WEBFRONT_BOOTSTRAP_DIR: ${result} ${text}") +if(result EQUAL 0 OR NOT text MATCHES "WEBFRONT_BOOTSTRAP_DIR" OR NOT text MATCHES "3 attempts" OR NOT text MATCHES "trying again") + message(FATAL_ERROR "A failed download must be tried again, then point to WEBFRONT_BOOTSTRAP_DIR: ${result} ${text}") +endif() + +# The machine download cache: a download fills it, and another build tree then gets the archive from it alone. +file(WRITE "${WORK}/source/environment.tgz" "${content}") +set(machine "${WORK}/machine") +string(SUBSTRING "${hex}" 0 32 key) +provision(cacheFill result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-a" CACHE "${machine}") +expect_equal("${result}" 0 "A download must fill the machine cache: ${text}") +foreach(file "${machine}/${key}/environment.tgz" "${WORK}/tree-a/environment.tgz") + file(SHA512 "${file}" digest) + expect_equal("${digest}" "${hex}" "The cached and provisioned archives must be the verified one (${file})") +endforeach() +file(GLOB partials "${machine}/${key}/*.partial") +expect_equal("${partials}" "" "No partial download may stay in the cache") +file(REMOVE "${WORK}/source/environment.tgz") +provision(cacheHit result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-b" CACHE "${machine}") +expect_equal("${result}" 0 "A new build tree must be provisioned from the machine cache without the source: ${text}") +file(SHA512 "${WORK}/tree-b/environment.tgz" digest) +expect_equal("${digest}" "${hex}" "The archive linked from the cache") +# A damaged cache entry is downloaded again, never used. +file(REMOVE "${machine}/${key}/environment.tgz") +file(WRITE "${machine}/${key}/environment.tgz" "damaged") +file(WRITE "${WORK}/source/environment.tgz" "${content}") +provision(cacheRepair result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-c" CACHE "${machine}") +expect_equal("${result}" 0 "A damaged cache entry must be downloaded again: ${text}") +foreach(file "${machine}/${key}/environment.tgz" "${WORK}/tree-c/environment.tgz") + file(SHA512 "${file}" digest) + expect_equal("${digest}" "${hex}" "The repaired archive (${file})") +endforeach() +# Data with another digest stops the configure and stays out of the cache. +file(WRITE "${WORK}/source/environment.tgz" "tampered") +file(REMOVE_RECURSE "${machine}") +provision(cacheWrong result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-d" CACHE "${machine}") +if(result EQUAL 0 OR NOT text MATCHES "integrity check failed" OR EXISTS "${machine}/${key}/environment.tgz" OR EXISTS "${WORK}/tree-d/environment.tgz") + message(FATAL_ERROR "A wrong digest must fail and leave nothing in the cache or the build tree: ${result} ${text}") endif() # A local provisioning directory replaces the download and is verified too. From bffdbc7a43abff0552e690e1c28b82ab64c26b35 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:34:10 +0100 Subject: [PATCH 2/5] Use a read-only download cache and a provisioned registry without failing (#570) - A cache directory that exists but refuses files stopped the configure: file(MAKE_DIRECTORY) succeeds on it, and the download then failed to create its partial file. A verified entry of such a cache now serves without writing, and a download goes to the cache only when a probe file can be created there; otherwise it stays in the build tree with a warning. - The test registry looked for each archive in WEBFRONT_REGISTRY_DIR before the verified copy already in the build tree, so a configure failed once the offline directory was no longer mounted. The verified copy is kept first, as before the cache. BootstrapProvisioning covers both: a read-only cache, empty then holding the entry (POSIX, skipped where the process writes through permissions), and a registry provisioned again after its offline directory went away. Its checks read CMake's wrapped messages on one line. --- cmake/WebFrontBootstrap.cmake | 89 ++++++++++++--------- cmake/WebFrontRegistry.cmake | 12 ++- test/cmake/CheckBootstrapProvisioning.cmake | 56 ++++++++++++- 3 files changed, 119 insertions(+), 38 deletions(-) diff --git a/cmake/WebFrontBootstrap.cmake b/cmake/WebFrontBootstrap.cmake index 6dbe2943..265bdf35 100644 --- a/cmake/WebFrontBootstrap.cmake +++ b/cmake/WebFrontBootstrap.cmake @@ -44,6 +44,23 @@ if(NOT DEFINED WEBFRONT_DOWNLOAD_RETRY_DELAY) set(WEBFRONT_DOWNLOAD_RETRY_DELAY 5) endif() +# Sets to TRUE when a file can be created in , which is created when missing. An existing directory +# may still refuse files (a read-only cache, a mount of another user's): a probe file tells. +function(_webfront_writable_directory directory output) + set(${output} FALSE PARENT_SCOPE) + file(MAKE_DIRECTORY "${directory}" RESULT made) + if(NOT made EQUAL 0) + return() + endif() + string(RANDOM LENGTH 12 suffix) + set(probe "${directory}/.webfront-probe-${suffix}") + execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${probe}" RESULT_VARIABLE touched OUTPUT_QUIET ERROR_QUIET) + if(touched EQUAL 0 AND EXISTS "${probe}") + file(REMOVE "${probe}") + set(${output} TRUE PARENT_SCOPE) + endif() +endfunction() + # webfront_download_verified( URL SHA512 FAILURE MISMATCH ): makes a file whose SHA-512 # is . A file already there with that digest is kept. Otherwise the machine's download cache provides it, a download # filling the cache first; is then a link to the cached file, or a copy where a link cannot be made. A download that @@ -65,49 +82,49 @@ function(webfront_download_verified path) if(WEBFRONT_DOWNLOAD_CACHE) # The first half of the digest names the entry: two files of the same name and version never meet. string(SUBSTRING "${ARG_SHA512}" 0 32 key) - file(MAKE_DIRECTORY "${WEBFRONT_DOWNLOAD_CACHE}/${key}" RESULT made) - if(made EQUAL 0) - set(target "${WEBFRONT_DOWNLOAD_CACHE}/${key}/${name}") + set(entry "${WEBFRONT_DOWNLOAD_CACHE}/${key}/${name}") + # A verified entry serves even a cache that cannot be written, such as a shared read-only one. + if(EXISTS "${entry}") + file(SHA512 "${entry}" actual) + if(actual STREQUAL ARG_SHA512) + file(CREATE_LINK "${entry}" "${path}" COPY_ON_ERROR) + return() + endif() + endif() + # A download fills the cache only where a file can be created; a damaged entry is replaced once verified. + _webfront_writable_directory("${WEBFRONT_DOWNLOAD_CACHE}/${key}" writable) + if(writable) + set(target "${entry}") else() - message(WARNING "The download cache ${WEBFRONT_DOWNLOAD_CACHE} cannot be written (${made}): ${name} is kept in the build tree only") + message(WARNING "The download cache ${WEBFRONT_DOWNLOAD_CACHE} cannot be written: ${name} is kept in the build tree only") endif() endif() set(present FALSE) - if(NOT target STREQUAL path AND EXISTS "${target}") - file(SHA512 "${target}" actual) - if(actual STREQUAL ARG_SHA512) + foreach(attempt RANGE 1 ${WEBFRONT_DOWNLOAD_ATTEMPTS}) + # Written aside, then renamed once verified: a concurrent configure never reads a partial file. + string(RANDOM LENGTH 12 suffix) + set(partial "${target}.${suffix}.partial") + file(DOWNLOAD "${ARG_URL}" "${partial}" STATUS result TLS_VERIFY ON INACTIVITY_TIMEOUT 60 TIMEOUT 600) + list(GET result 0 code) + if(code EQUAL 0) + file(SHA512 "${partial}" actual) + if(NOT actual STREQUAL ARG_SHA512) + file(REMOVE "${partial}") + message(FATAL_ERROR "${ARG_MISMATCH}") + endif() + file(RENAME "${partial}" "${target}") set(present TRUE) - else() - file(REMOVE "${target}") + break() endif() - endif() - if(NOT present) - foreach(attempt RANGE 1 ${WEBFRONT_DOWNLOAD_ATTEMPTS}) - # Written aside, then renamed once verified: a concurrent configure never reads a partial file. - string(RANDOM LENGTH 12 suffix) - set(partial "${target}.${suffix}.partial") - file(DOWNLOAD "${ARG_URL}" "${partial}" STATUS result TLS_VERIFY ON INACTIVITY_TIMEOUT 60 TIMEOUT 600) - list(GET result 0 code) - if(code EQUAL 0) - file(SHA512 "${partial}" actual) - if(NOT actual STREQUAL ARG_SHA512) - file(REMOVE "${partial}") - message(FATAL_ERROR "${ARG_MISMATCH}") - endif() - file(RENAME "${partial}" "${target}") - set(present TRUE) - break() - endif() - file(REMOVE "${partial}") - list(GET result 1 reason) - if(attempt LESS WEBFRONT_DOWNLOAD_ATTEMPTS) - message(STATUS "Download of ${ARG_URL} failed (${reason}); trying again in ${WEBFRONT_DOWNLOAD_RETRY_DELAY} s") - execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep ${WEBFRONT_DOWNLOAD_RETRY_DELAY}) - endif() - endforeach() - if(NOT present) - message(FATAL_ERROR "${ARG_FAILURE}: ${reason} (${WEBFRONT_DOWNLOAD_ATTEMPTS} attempts)") + file(REMOVE "${partial}") + list(GET result 1 reason) + if(attempt LESS WEBFRONT_DOWNLOAD_ATTEMPTS) + message(STATUS "Download of ${ARG_URL} failed (${reason}); trying again in ${WEBFRONT_DOWNLOAD_RETRY_DELAY} s") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep ${WEBFRONT_DOWNLOAD_RETRY_DELAY}) endif() + endforeach() + if(NOT present) + message(FATAL_ERROR "${ARG_FAILURE}: ${reason} (${WEBFRONT_DOWNLOAD_ATTEMPTS} attempts)") endif() if(NOT target STREQUAL path) file(CREATE_LINK "${target}" "${path}" COPY_ON_ERROR) diff --git a/cmake/WebFrontRegistry.cmake b/cmake/WebFrontRegistry.cmake index 5b313fba..3b670b89 100644 --- a/cmake/WebFrontRegistry.cmake +++ b/cmake/WebFrontRegistry.cmake @@ -25,7 +25,17 @@ function(webfront_provision_registry output list directory) set(name "${CMAKE_MATCH_1}-${name}") endif() set(path "${directory}/${name}") - if(WEBFRONT_REGISTRY_DIR) + # A verified archive already in the build tree is kept: the offline directory need not stay mounted. + set(present FALSE) + if(EXISTS "${path}") + file(SHA512 "${path}" actual) + if(actual STREQUAL expected) + set(present TRUE) + endif() + endif() + if(present) + continue() + elseif(WEBFRONT_REGISTRY_DIR) if(NOT EXISTS "${WEBFRONT_REGISTRY_DIR}/${name}") message(FATAL_ERROR "Test registry archive ${WEBFRONT_REGISTRY_DIR}/${name} is missing: WEBFRONT_REGISTRY_DIR must hold it") endif() diff --git a/test/cmake/CheckBootstrapProvisioning.cmake b/test/cmake/CheckBootstrapProvisioning.cmake index bc1fafac..548f6efb 100644 --- a/test/cmake/CheckBootstrapProvisioning.cmake +++ b/test/cmake/CheckBootstrapProvisioning.cmake @@ -55,7 +55,9 @@ function(provision name result_var output_var) -DWEBFRONT_DOWNLOAD_RETRY_DELAY=0 -P "${WORK}/run.cmake" RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) set(${result_var} "${result}" PARENT_SCOPE) - set(${output_var} "${out}${err}" PARENT_SCOPE) + # CMake wraps a long message wherever its paths make it long: the checks read it on one line. + string(REGEX REPLACE "[ \t\r\n]+" " " text "${out}${err}") + set(${output_var} "${text}" PARENT_SCOPE) endfunction() # A file URL: a Windows drive letter needs a third slash. @@ -144,6 +146,58 @@ if(result EQUAL 0 OR NOT text MATCHES "is missing") message(FATAL_ERROR "An absent local archive must fail the configure: ${result} ${text}") endif() +# A cache that exists but refuses files (a shared, read-only one): a verified entry still serves, and a download falls back +# to the build tree with a warning instead of stopping the configure. Only POSIX permissions can make it so, and a process +# that writes through them (root) cannot test it. +if(NOT CMAKE_HOST_WIN32) + file(WRITE "${WORK}/source/environment.tgz" "${content}") + set(readonly "${WORK}/readonly") + file(REMOVE_RECURSE "${readonly}") + file(MAKE_DIRECTORY "${readonly}/${key}") + file(CHMOD "${readonly}" "${readonly}/${key}" DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) + execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${readonly}/${key}/probe" RESULT_VARIABLE writable OUTPUT_QUIET ERROR_QUIET) + if(writable EQUAL 0) + file(REMOVE "${readonly}/${key}/probe") + message(STATUS "This process writes into read-only directories: the read-only cache cases are skipped") + else() + provision(readonlyEmpty result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-e" CACHE "${readonly}") + expect_equal("${result}" 0 "A read-only cache must not stop the configure: ${text}") + if(NOT text MATCHES "cannot be written") + message(FATAL_ERROR "A read-only cache must be reported: ${text}") + endif() + file(SHA512 "${WORK}/tree-e/environment.tgz" digest) + expect_equal("${digest}" "${hex}" "The archive kept in the build tree beside a read-only cache") + file(CHMOD "${readonly}/${key}" DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) + file(COPY_FILE "${WORK}/source/environment.tgz" "${readonly}/${key}/environment.tgz") + file(CHMOD "${readonly}/${key}" DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + file(REMOVE "${WORK}/source/environment.tgz") + provision(readonlyEntry result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-f" CACHE "${readonly}") + expect_equal("${result}" 0 "A verified entry of a read-only cache must serve without the source: ${text}") + file(SHA512 "${WORK}/tree-f/environment.tgz" digest) + expect_equal("${digest}" "${hex}" "The archive linked from a read-only cache") + endif() + file(CHMOD "${readonly}" "${readonly}/${key}" DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) +endif() + +# The test registry keeps the verified archives already in the build tree: its offline directory need not stay mounted. +file(MAKE_DIRECTORY "${WORK}/offline") +file(WRITE "${WORK}/offline/environment.tgz" "${content}") +file(WRITE "${WORK}/packages.json" "{\"packages\": [{\"name\": \"environment\", \"url\": \"https://offline.invalid/environment.tgz\", \"integrity\": \"${sri}\"}]}") +file(WRITE "${WORK}/registry.cmake" [[ +list(APPEND CMAKE_MODULE_PATH "${ROOT}/cmake") +include("${ROOT}/cmake/WebFrontRegistry.cmake") +webfront_provision_registry(directory "${WORK}/packages.json" "${WORK}/registry-tree") +message(STATUS "provisioned ${directory}") +]]) +foreach(round mounted unmounted) + execute_process(COMMAND "${CMAKE_COMMAND}" -DROOT=${ROOT} -DWORK=${WORK} -DWEBFRONT_REGISTRY_DIR=${WORK}/offline + -DWEBFRONT_DOWNLOAD_CACHE= -P "${WORK}/registry.cmake" + RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + expect_equal("${result}" 0 "The ${round} offline registry directory must provision the build tree: ${out}${err}") + file(REMOVE_RECURSE "${WORK}/offline") +endforeach() + # A malformed integrity is refused before anything is downloaded. provision(malformed result text URL "${url}" INTEGRITY "sha256-abc") if(result EQUAL 0 OR NOT text MATCHES "sha512- SRI") From 62408ddf720936618b0a55f2997302c8fd51b7ec Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:38:51 +0100 Subject: [PATCH 3/5] Count an empty environment variable as unset when choosing the download cache (#570) DEFINED ENV{CPM_SOURCE_CACHE} is true for a variable set to nothing: the default cache then became /webfront-downloads, at the root, even for a consuming project that asked for no shared cache. Every variable that chooses the place (WEBFRONT_DOWNLOAD_CACHE, CPM_SOURCE_CACHE, LOCALAPPDATA, XDG_CACHE_HOME, HOME) now counts only when it has a value, and the choice goes on to the next; -DWEBFRONT_DOWNLOAD_CACHE= still disables the cache. BootstrapProvisioning reads the default cache under an empty CPM_SOURCE_CACHE, an empty WEBFRONT_DOWNLOAD_CACHE and both set. --- cmake/WebFrontBootstrap.cmake | 16 ++++++++------- test/cmake/CheckBootstrapProvisioning.cmake | 22 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cmake/WebFrontBootstrap.cmake b/cmake/WebFrontBootstrap.cmake index 265bdf35..152b1bd0 100644 --- a/cmake/WebFrontBootstrap.cmake +++ b/cmake/WebFrontBootstrap.cmake @@ -17,22 +17,24 @@ set(WEBFRONT_BOOTSTRAP_DIR "" CACHE PATH "Directory with the pinned bootstrap en # The verified downloads of the configure, kept once per machine: a new build tree links them instead of downloading them # again. WEBFRONT_DOWNLOAD_CACHE or CPM's cache chooses the place; WebFront's own build otherwise uses the user's cache -# directory, and a project that consumes WebFront keeps each download in its build tree unless it asks. Empty disables it. +# directory, and a project that consumes WebFront keeps each download in its build tree unless it asks. An environment +# variable set to nothing counts as unset, so that it never makes a path at the root; -DWEBFRONT_DOWNLOAD_CACHE= disables +# the cache. get_filename_component(_webfront_source "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) set(_webfront_download_cache "") -if(DEFINED ENV{WEBFRONT_DOWNLOAD_CACHE}) +if(NOT "$ENV{WEBFRONT_DOWNLOAD_CACHE}" STREQUAL "") set(_webfront_download_cache "$ENV{WEBFRONT_DOWNLOAD_CACHE}") -elseif(DEFINED ENV{CPM_SOURCE_CACHE}) +elseif(NOT "$ENV{CPM_SOURCE_CACHE}" STREQUAL "") set(_webfront_download_cache "$ENV{CPM_SOURCE_CACHE}/webfront-downloads") elseif(NOT CMAKE_SOURCE_DIR STREQUAL _webfront_source) # A consuming project: each download stays in its build tree. -elseif(CMAKE_HOST_WIN32 AND DEFINED ENV{LOCALAPPDATA}) +elseif(CMAKE_HOST_WIN32 AND NOT "$ENV{LOCALAPPDATA}" STREQUAL "") set(_webfront_download_cache "$ENV{LOCALAPPDATA}/WebFront/downloads") -elseif(CMAKE_HOST_APPLE AND DEFINED ENV{HOME}) +elseif(CMAKE_HOST_APPLE AND NOT "$ENV{HOME}" STREQUAL "") set(_webfront_download_cache "$ENV{HOME}/Library/Caches/WebFront/downloads") -elseif(DEFINED ENV{XDG_CACHE_HOME}) +elseif(NOT "$ENV{XDG_CACHE_HOME}" STREQUAL "") set(_webfront_download_cache "$ENV{XDG_CACHE_HOME}/webfront/downloads") -elseif(DEFINED ENV{HOME}) +elseif(NOT "$ENV{HOME}" STREQUAL "") set(_webfront_download_cache "$ENV{HOME}/.cache/webfront/downloads") endif() set(WEBFRONT_DOWNLOAD_CACHE "${_webfront_download_cache}" CACHE PATH "Directory keeping the verified configure downloads for every build tree (empty: none)") diff --git a/test/cmake/CheckBootstrapProvisioning.cmake b/test/cmake/CheckBootstrapProvisioning.cmake index 548f6efb..c7e5964f 100644 --- a/test/cmake/CheckBootstrapProvisioning.cmake +++ b/test/cmake/CheckBootstrapProvisioning.cmake @@ -198,6 +198,28 @@ foreach(round mounted unmounted) file(REMOVE_RECURSE "${WORK}/offline") endforeach() +# The default cache: an environment variable set to nothing counts as unset, so that it never makes a path at the root. The +# probe runs as a consuming project would (its source is not WebFront's), which keeps its downloads in its build tree. +file(WRITE "${WORK}/default-cache.cmake" [[ +include("${ROOT}/cmake/WebFrontBootstrap.cmake") +message(STATUS "cache=[${WEBFRONT_DOWNLOAD_CACHE}]") +]]) +function(default_cache output) + execute_process(COMMAND "${CMAKE_COMMAND}" -E env --unset=WEBFRONT_DOWNLOAD_CACHE --unset=CPM_SOURCE_CACHE ${ARGN} + "${CMAKE_COMMAND}" -DROOT=${ROOT} -P "${WORK}/default-cache.cmake" + WORKING_DIRECTORY "${WORK}" RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) + if(NOT result EQUAL 0 OR NOT out MATCHES "cache=\\[([^]]*)\\]") + message(FATAL_ERROR "The default cache could not be read: ${result} ${out}${err}") + endif() + set(${output} "${CMAKE_MATCH_1}" PARENT_SCOPE) +endfunction() +default_cache(chosen "CPM_SOURCE_CACHE=") +expect_equal("${chosen}" "" "An empty CPM_SOURCE_CACHE must not choose a cache for a consuming project") +default_cache(chosen "WEBFRONT_DOWNLOAD_CACHE=" "CPM_SOURCE_CACHE=${WORK}/cpm") +expect_equal("${chosen}" "${WORK}/cpm/webfront-downloads" "An empty WEBFRONT_DOWNLOAD_CACHE must leave the choice to CPM's cache") +default_cache(chosen "WEBFRONT_DOWNLOAD_CACHE=${WORK}/chosen" "CPM_SOURCE_CACHE=${WORK}/cpm") +expect_equal("${chosen}" "${WORK}/chosen" "WEBFRONT_DOWNLOAD_CACHE comes first") + # A malformed integrity is refused before anything is downloaded. provision(malformed result text URL "${url}" INTEGRITY "sha256-abc") if(result EQUAL 0 OR NOT text MATCHES "sha512- SRI") From b35bfc16d046e83b6d10a404fdbc5bb2f2ee1320 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:39:49 +0100 Subject: [PATCH 4/5] Keep only the provisioning checks that reproduce the review findings (#570) The read-only cache keeps the case that stopped the configure, and the default cache the case of an empty CPM_SOURCE_CACHE; the other combinations repeated what those prove. All of them stay inside BootstrapProvisioning: no CTest case is added. --- test/cmake/CheckBootstrapProvisioning.cmake | 38 +++++---------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/test/cmake/CheckBootstrapProvisioning.cmake b/test/cmake/CheckBootstrapProvisioning.cmake index c7e5964f..9e23fac4 100644 --- a/test/cmake/CheckBootstrapProvisioning.cmake +++ b/test/cmake/CheckBootstrapProvisioning.cmake @@ -146,8 +146,8 @@ if(result EQUAL 0 OR NOT text MATCHES "is missing") message(FATAL_ERROR "An absent local archive must fail the configure: ${result} ${text}") endif() -# A cache that exists but refuses files (a shared, read-only one): a verified entry still serves, and a download falls back -# to the build tree with a warning instead of stopping the configure. Only POSIX permissions can make it so, and a process +# A cache that exists but refuses files (a shared, read-only one): a download falls back to the build tree with a warning +# instead of stopping the configure. Only POSIX permissions can make it so, and a process # that writes through them (root) cannot test it. if(NOT CMAKE_HOST_WIN32) file(WRITE "${WORK}/source/environment.tgz" "${content}") @@ -166,16 +166,6 @@ if(NOT CMAKE_HOST_WIN32) if(NOT text MATCHES "cannot be written") message(FATAL_ERROR "A read-only cache must be reported: ${text}") endif() - file(SHA512 "${WORK}/tree-e/environment.tgz" digest) - expect_equal("${digest}" "${hex}" "The archive kept in the build tree beside a read-only cache") - file(CHMOD "${readonly}/${key}" DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) - file(COPY_FILE "${WORK}/source/environment.tgz" "${readonly}/${key}/environment.tgz") - file(CHMOD "${readonly}/${key}" DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) - file(REMOVE "${WORK}/source/environment.tgz") - provision(readonlyEntry result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-f" CACHE "${readonly}") - expect_equal("${result}" 0 "A verified entry of a read-only cache must serve without the source: ${text}") - file(SHA512 "${WORK}/tree-f/environment.tgz" digest) - expect_equal("${digest}" "${hex}" "The archive linked from a read-only cache") endif() file(CHMOD "${readonly}" "${readonly}/${key}" DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE) endif() @@ -198,27 +188,17 @@ foreach(round mounted unmounted) file(REMOVE_RECURSE "${WORK}/offline") endforeach() -# The default cache: an environment variable set to nothing counts as unset, so that it never makes a path at the root. The -# probe runs as a consuming project would (its source is not WebFront's), which keeps its downloads in its build tree. +# An environment variable set to nothing counts as unset: an empty CPM_SOURCE_CACHE gives a consuming project no cache, +# not one at the root. file(WRITE "${WORK}/default-cache.cmake" [[ include("${ROOT}/cmake/WebFrontBootstrap.cmake") message(STATUS "cache=[${WEBFRONT_DOWNLOAD_CACHE}]") ]]) -function(default_cache output) - execute_process(COMMAND "${CMAKE_COMMAND}" -E env --unset=WEBFRONT_DOWNLOAD_CACHE --unset=CPM_SOURCE_CACHE ${ARGN} - "${CMAKE_COMMAND}" -DROOT=${ROOT} -P "${WORK}/default-cache.cmake" - WORKING_DIRECTORY "${WORK}" RESULT_VARIABLE result OUTPUT_VARIABLE out ERROR_VARIABLE err) - if(NOT result EQUAL 0 OR NOT out MATCHES "cache=\\[([^]]*)\\]") - message(FATAL_ERROR "The default cache could not be read: ${result} ${out}${err}") - endif() - set(${output} "${CMAKE_MATCH_1}" PARENT_SCOPE) -endfunction() -default_cache(chosen "CPM_SOURCE_CACHE=") -expect_equal("${chosen}" "" "An empty CPM_SOURCE_CACHE must not choose a cache for a consuming project") -default_cache(chosen "WEBFRONT_DOWNLOAD_CACHE=" "CPM_SOURCE_CACHE=${WORK}/cpm") -expect_equal("${chosen}" "${WORK}/cpm/webfront-downloads" "An empty WEBFRONT_DOWNLOAD_CACHE must leave the choice to CPM's cache") -default_cache(chosen "WEBFRONT_DOWNLOAD_CACHE=${WORK}/chosen" "CPM_SOURCE_CACHE=${WORK}/cpm") -expect_equal("${chosen}" "${WORK}/chosen" "WEBFRONT_DOWNLOAD_CACHE comes first") +execute_process(COMMAND "${CMAKE_COMMAND}" -E env --unset=WEBFRONT_DOWNLOAD_CACHE CPM_SOURCE_CACHE= "${CMAKE_COMMAND}" -DROOT=${ROOT} + -P "${WORK}/default-cache.cmake" WORKING_DIRECTORY "${WORK}" OUTPUT_VARIABLE out ERROR_VARIABLE out) +if(NOT out MATCHES "cache=\\[\\]") + message(FATAL_ERROR "An empty CPM_SOURCE_CACHE must not choose a cache: ${out}") +endif() # A malformed integrity is refused before anything is downloaded. provision(malformed result text URL "${url}" INTEGRITY "sha256-abc") From 6995b06d64f47d55f19598784c276d6680352fae Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:40:17 +0100 Subject: [PATCH 5/5] Drop the cache checks that repeat the download and digest checks (#570) A damaged entry is replaced by the same download that fills the cache, and a wrong digest is refused by the same verification with or without a cache: the fill and the second build tree served from the cache remain. --- test/cmake/CheckBootstrapProvisioning.cmake | 25 ++------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/test/cmake/CheckBootstrapProvisioning.cmake b/test/cmake/CheckBootstrapProvisioning.cmake index 9e23fac4..4a639e4f 100644 --- a/test/cmake/CheckBootstrapProvisioning.cmake +++ b/test/cmake/CheckBootstrapProvisioning.cmake @@ -103,34 +103,13 @@ set(machine "${WORK}/machine") string(SUBSTRING "${hex}" 0 32 key) provision(cacheFill result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-a" CACHE "${machine}") expect_equal("${result}" 0 "A download must fill the machine cache: ${text}") -foreach(file "${machine}/${key}/environment.tgz" "${WORK}/tree-a/environment.tgz") - file(SHA512 "${file}" digest) - expect_equal("${digest}" "${hex}" "The cached and provisioned archives must be the verified one (${file})") -endforeach() -file(GLOB partials "${machine}/${key}/*.partial") -expect_equal("${partials}" "" "No partial download may stay in the cache") file(REMOVE "${WORK}/source/environment.tgz") provision(cacheHit result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-b" CACHE "${machine}") expect_equal("${result}" 0 "A new build tree must be provisioned from the machine cache without the source: ${text}") -file(SHA512 "${WORK}/tree-b/environment.tgz" digest) -expect_equal("${digest}" "${hex}" "The archive linked from the cache") -# A damaged cache entry is downloaded again, never used. -file(REMOVE "${machine}/${key}/environment.tgz") -file(WRITE "${machine}/${key}/environment.tgz" "damaged") -file(WRITE "${WORK}/source/environment.tgz" "${content}") -provision(cacheRepair result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-c" CACHE "${machine}") -expect_equal("${result}" 0 "A damaged cache entry must be downloaded again: ${text}") -foreach(file "${machine}/${key}/environment.tgz" "${WORK}/tree-c/environment.tgz") +foreach(file "${machine}/${key}/environment.tgz" "${WORK}/tree-a/environment.tgz" "${WORK}/tree-b/environment.tgz") file(SHA512 "${file}" digest) - expect_equal("${digest}" "${hex}" "The repaired archive (${file})") + expect_equal("${digest}" "${hex}" "The cached and provisioned archives must be the verified one (${file})") endforeach() -# Data with another digest stops the configure and stays out of the cache. -file(WRITE "${WORK}/source/environment.tgz" "tampered") -file(REMOVE_RECURSE "${machine}") -provision(cacheWrong result text URL "${url}" INTEGRITY "${sri}" DESTINATION "${WORK}/tree-d" CACHE "${machine}") -if(result EQUAL 0 OR NOT text MATCHES "integrity check failed" OR EXISTS "${machine}/${key}/environment.tgz" OR EXISTS "${WORK}/tree-d/environment.tgz") - message(FATAL_ERROR "A wrong digest must fail and leave nothing in the cache or the build tree: ${result} ${text}") -endif() # A local provisioning directory replaces the download and is verified too. provision(local result text URL "https://offline.invalid/environment.tgz" INTEGRITY "${sri}" LOCAL "${WORK}/local")