cmake: Fix dependency download logic #13078
Open
+7
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Previously, if download failure occurred or interrupted by Ctrl-C, the broken file is not removed. This is true for the first case because "message(FATAL_ERROR ..." stops cmake and "file(REMOVE ..." is never reached. After that, if cmake is run second time, SHA256 verification is skipped and the broken file will be used.
This patch fixes this by always checking SHA256 of the downloaded file, using a if clause. Although "file(DOWNLOAD ... EXPECTED_HASH ..." already provides same functionality, using it makes status printing harder.
Error checking of download status is also improved. The if clause now checks equality, according to cmake's documentation.
The redundant "file(REMOVE ..." is also removed.
Motivation and Context
Before applying this patch: first run, download failure
Second run, broken downloaded file is used and boom
How Has This Been Tested?
Win10 x64, Visual C++ 2022 Community, Git-2.52.0, CMake 4.2.3
Manually run
cmakefew times, it now correctly redownload broken dependency files.Types of changes
Tweak (non-breaking change to improve existing functionality)
Checklist: