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

Add mirror support #83

Merged
merged 8 commits into from
Sep 26, 2016
Merged

Add mirror support #83

merged 8 commits into from
Sep 26, 2016

Conversation

Telokis
Copy link
Contributor

@Telokis Telokis commented Sep 24, 2016

Fixes #58
Updated vcpkg_download_distfile.cmake to handle MIRRORS url.

@msftclas
Copy link

Hi @Ninetainedo, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by Microsoft and real humans are currently evaluating your PR.

TTYL, MSBOT;

" '${FILE_HASH}' <> '${vcpkg_download_distfile_SHA512}'\n"
"Please delete the file and try again if this file should be downloaded again.")
"\nFile does not have expected hash:\n"
" File path: [${downloaded_file_path}]\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you leave spaces between the '[' and the hash? This enables double clicking to select in the default windows terminal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, no problem for that. I didn't put it because I tried to stick to the exact syntax of CMake but I have to admit that it's easier with those spaces.

@@ -1,20 +1,57 @@
# Usage: vcpkg_download_distfile(<VAR> URL <http://...> FILENAME <output.zip> SHA512 <5981de...>)
# Usage: vcpkg_download_distfile(<VAR> URL <http://...> FILENAME <output.zip> SHA512 <5981de...> MIRRORS <http://mirror1> <http://mirror2>)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's no benefit to separating the URL argument from the MIRRORS argument -- if we rename MIRRORS to URLS, in the future we could completely eliminate the URL argument (just need to move all the portfiles and the template over to using URLS).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are entirely right, I'll change it and update all portfiles accordingly.

file(DOWNLOAD ${url} ${downloaded_file_path} STATUS download_status)
list(GET download_status 0 status_code)
if (NOT "${status_code}" STREQUAL "0")
message(STATUS "Downloading ${url}... Failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

On failure, we should display the status code to the user for debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's done as well.

message(FATAL_ERROR
"\n"
" Failed to download file.\n"
" Add mirrors or submit an issue at https://github.com/Microsoft/vcpkg/issues/new\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Link to issues directly; it's possible there will be an existing issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

file(SHA512 ${downloaded_file_path} FILE_HASH)
if(NOT "${FILE_HASH}" STREQUAL "${vcpkg_download_distfile_SHA512}")
message(FATAL_ERROR
"\nFile does not have expected hash:\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd really prefer to avoid duplicating the bulk of this user output code. Perhaps an inner function that could be called in both places would be appropriate here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done as well. I used a parameter named FILE_KIND which is "cached file" or "downloaded file" to have more precise logs. (I couldn't find a better name for the variable)

@ras0219-msft
Copy link
Contributor

ras0219-msft commented Sep 24, 2016

Overall this looks great. I think performing the hash check and throwing a hard failure on mismatch is the right way to go (as you've done).

The one important comment I have is the MIRRORS argument; I think it would be great in the future to not distinguish between the URL and the MIRRORS (instead, have one named URLS), since the logic is basically the same (download each in the list until success).

file(DOWNLOAD ${url} ${downloaded_file_path} STATUS download_status)
list(GET download_status 0 status_code)
if (NOT "${status_code}" STREQUAL "0")
message(STATUS "Downloading ${url}... Failed. Status: ${download_status}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I print the whole download_status variable because it contains both the error code and a human-friendly message

@alexkaratarakis alexkaratarakis merged commit 2491a16 into microsoft:master Sep 26, 2016
@alexkaratarakis
Copy link
Contributor

Solid work, thank you!

@Telokis Telokis deleted the Add-mirror-support branch September 27, 2016 14:34
JoergAtGithub added a commit to JoergAtGithub/vcpkg that referenced this pull request Sep 26, 2023
Add gtest, to finally devendor it form the Mixxx folder 2.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants