Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg_from_sourceforge] Determine sourceforge status #13176

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions scripts/cmake/vcpkg_download_distfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ function(vcpkg_download_distfile VAR)
message(FATAL_ERROR "vcpkg_download_distfile requires a FILENAME argument.")
endif()
if(NOT _VCPKG_INTERNAL_NO_HASH_CHECK)
if(vcpkg_download_distfile_SKIP_SHA512 AND NOT VCPKG_USE_HEAD_VERSION)
message(FATAL_ERROR "vcpkg_download_distfile only allows SKIP_SHA512 when building with --head")
endif()
Comment on lines -62 to -64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    vcpkg_download_distfile(ARCHIVE
        URLS "${DOWNLOAD_URL}"
        SHA512 "${_vdus_SHA512}"
        SKIP_SHA512
        FILENAME "${_vdus_FILENAME}"
        SILENT_EXIT
    )

Here, since the file returned from sourceforge may be a web page in this case, it causes the inconsistency of SHA512, so we must skip the hash detection. This behavior was affected here, so it was deleted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. @ras0219 @strega-nil @dan-shaw @vicroms Do you agree?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this since it's causing other PR validations to fail e.g. #11290 if folks don't want this change please let me know afterwards.

if(NOT vcpkg_download_distfile_SKIP_SHA512 AND NOT DEFINED vcpkg_download_distfile_SHA512)
message(FATAL_ERROR "vcpkg_download_distfile requires a SHA512 argument. If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.")
endif()
Expand Down
46 changes: 41 additions & 5 deletions scripts/cmake/vcpkg_from_sourceforge.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@
## * [tinyfiledialogs](https://github.com/Microsoft/vcpkg/blob/master/ports/tinyfiledialogs/portfile.cmake)

function(vcpkg_from_sourceforge)
macro(check_file_content)
if (EXISTS ${ARCHIVE})
file(SIZE ${ARCHIVE} DOWNLOAD_FILE_SIZE)
if (DOWNLOAD_FILE_SIZE LESS_EQUAL 1024)
file(READ ${ARCHIVE} _FILE_CONTENT_)
string(FIND "${_FILE_CONTENT_}" "the Sourceforge site is currently in Disaster Recovery mode." OUT_CONTENT)
message("OUT_CONTENT: ${OUT_CONTENT}")
if (OUT_CONTENT EQUAL -1)
set(download_success 1)
else()
file(REMOVE ${ARCHIVE})
endif()
endif()
endif()
endmacro()

macro(check_file_sha512)
file(SHA512 ${ARCHIVE} FILE_HASH)
if(NOT FILE_HASH STREQUAL _vdus_SHA512)
message(FATAL_ERROR
"\nFile does not have expected hash:\n"
" File path: [ ${ARCHIVE} ]\n"
" Expected hash: [ ${_vdus_SHA512} ]\n"
" Actual hash: [ ${FILE_HASH} ]\n"
"${CUSTOM_ERROR_ADVICE}\n")
endif()
endmacro()

set(booleanValueArgs DISABLE_SSL NO_REMOVE_ONE_LEVEL)
set(oneValueArgs OUT_SOURCE_PATH REPO REF SHA512 FILENAME WORKING_DIRECTORY)
set(multipleValuesArgs PATCHES)
Expand Down Expand Up @@ -151,13 +179,15 @@ function(vcpkg_from_sourceforge)
message(STATUS "Trying auto-select mirror...")
vcpkg_download_distfile(ARCHIVE
URLS "${DOWNLOAD_URL}"
SHA512 "${_vdus_SHA512}"
SKIP_SHA512
FILENAME "${_vdus_FILENAME}"
SILENT_EXIT
)

if (EXISTS ${ARCHIVE})
set(download_success 1)
check_file_content()
if (download_success)
check_file_sha512()
else()
message(STATUS "The default mirror is in Disaster Recovery mode, trying other mirrors...")
endif()

if (NOT download_success EQUAL 1)
Expand All @@ -166,13 +196,19 @@ function(vcpkg_from_sourceforge)
message(STATUS "Trying mirror ${SOURCEFORGE_MIRROR}...")
vcpkg_download_distfile(ARCHIVE
URLS "${DOWNLOAD_URL}"
SHA512 "${_vdus_SHA512}"
SKIP_SHA512
FILENAME "${_vdus_FILENAME}"
SILENT_EXIT
)

if (EXISTS ${ARCHIVE})
set(download_success 1)
check_file_content()
if (download_success)
check_file_sha512()
else()
message(STATUS "Mirror ${SOURCEFORGE_MIRROR} is in Disaster Recovery mode, trying other mirrors...")
endif()
break()
endif()
endforeach()
Expand Down