diff --git a/build-tools/scripts/DownloadFileWithRetry.targets b/build-tools/scripts/DownloadFileWithRetry.targets index 93021e1ff30..ccf78712d5c 100644 --- a/build-tools/scripts/DownloadFileWithRetry.targets +++ b/build-tools/scripts/DownloadFileWithRetry.targets @@ -49,6 +49,23 @@ whose contents drove the expected hash) so the next build re-fetches them. + Incremental no-op gate: + A per-file stamp file next to the cached download + (`$(_DownloadFolder)\$(_DownloadFileName).$(_DownloadSha256).stamp`, + or `.stamp` when no hash is supplied) is touched once the download + and SHA verification succeed. The target's `Inputs`/`Outputs` then + lets MSBuild skip re-running it - and re-hashing the cached file - + on no-op builds. The expected SHA is encoded in the stamp file + name so changing `_DownloadSha256` in a caller invalidates the + cached stamp and forces re-verification. Self-heal for a missing + cached file is preserved by `_PrepareDownloadOneFileWithRetry`, + which always runs and drops the stamp if the cached file is gone - + so this target's `Outputs` becomes incomplete and MSBuild forces + it to re-run. Only the stamp is listed in `Outputs`: including the + cached file there would defeat the gate, because cache files + restored from CI caches keep their original old timestamps and + would always look out of date relative to this targets file. + Usage pattern. The `_DownloadFile` item group must be built inside the caller's target body (so the items are visible to ``). Each item carries its per-file parameters as `AdditionalProperties` metadata, @@ -81,13 +98,20 @@ $(MSBuildThisFileFullPath) <_DownloadRetries>5 <_DownloadRetryDelayMilliseconds>5000 + + <_DownloadPath>$(_DownloadFolder)\$(_DownloadFileName) + <_DownloadStamp Condition=" '$(_DownloadSha256)' != '' ">$(_DownloadPath).$(_DownloadSha256).stamp + <_DownloadStamp Condition=" '$(_DownloadSha256)' == '' ">$(_DownloadPath).stamp - - - <_DownloadPath>$(_DownloadFolder)\$(_DownloadFileName) - - + + + + + + +