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

Recognize curl as a downloading tool #335

Merged
merged 3 commits into from
Oct 15, 2021
Merged
Changes from 2 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
43 changes: 29 additions & 14 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ function get_host_os {
esac
}

_machineHasCurl=

function validate_url {
if wget -S --spider $1 2>&1 | grep -e "HTTP/1.1 200 OK";
then
if (( _machineHasCurl == 1 )); then
status="$(curl -sLIo /dev/null "$1" -w '%{http_code}\n')"
else
response=($(wget -S --spider "$1" 2>&1 | grep "HTTP/"))
status="${response[1]}"
fi

if (( status >= 200 || status < 400 )); then
Copy link
Contributor

Choose a reason for hiding this comment

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

What statuses other than 200 and 301 can indicate that the url is valid?

Copy link
Member Author

Choose a reason for hiding this comment

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

2xx and 3xx classes indicate the success-like cases.

However, I just noticed that I am missing --location (or -L) below at curl invocations to indicate "follow redirect" in case of 301, 308 etc. (wget follows redirects by default, but curl requires -L).

return 0;
else
return 1;
Expand All @@ -53,13 +61,12 @@ function validate_url {

function download_tools {

# Do we have wget?
# Do we have wget or curl?

if ! hash wget 2>/dev/null; then
echo "Error: wget not found; not downloading clang-format and clang-tidy."
if [ "$__HostOS" == "OSX" ]; then
echo "On OSX, install wget using Homebrew (https://brew.sh/) using 'brew install wget'."
fi
if command -v curl 2>/dev/null; then
_machineHasCurl=1
elif ! command -v wget 2>/dev/null; then
echo "Error: curl or wget not found; not downloading clang-format and clang-tidy."
return 1
fi

Expand All @@ -72,24 +79,32 @@ function download_tools {

clangFormatUrl=https://clrjit.blob.core.windows.net/clang-tools/${info}/clang-format

if validate_url ${clangFormatUrl} > /dev/null; then
if validate_url "$clangFormatUrl" > /dev/null; then
echo "Downloading clang-format to bin directory"
# download appropriate version of clang-format
wget --tries 4 --progress=dot:giga ${clangFormatUrl} -O bin/clang-format
if (( _machineHasCurl == 1 )); then
curl --retry 4 --progress-bar --fail "$clangFormatUrl" -o bin/clang-format
am11 marked this conversation as resolved.
Show resolved Hide resolved
else
wget --tries 4 --progress=dot:giga "$clangFormatUrl" -O bin/clang-format
fi
chmod 751 bin/clang-format
else
echo "clang-format not found here: ${clangFormatUrl}"
echo "clang-format not found here: $clangFormatUrl"
fi

clangTidyUrl=https://clrjit.blob.core.windows.net/clang-tools/${info}/clang-tidy

if validate_url ${clangTidyUrl} > /dev/null; then
if validate_url "$clangTidyUrl" > /dev/null; then
echo "Downloading clang-tidy to bin directory"
# download appropriate version of clang-tidy
wget --tries 4 --progress=dot:giga ${clangTidyUrl} -O bin/clang-tidy
if (( _machineHasCurl == 1 )); then
curl --retry 4 --progress-bar --fail "$clangTidyUrl" -o bin/clang-tidy
am11 marked this conversation as resolved.
Show resolved Hide resolved
else
wget --tries 4 --progress=dot:giga "$clangTidyUrl" -O bin/clang-tidy
fi
chmod 751 bin/clang-tidy
else
echo "clang-tidy not found here: ${clangTidyUrl}"
echo "clang-tidy not found here: $clangTidyUrl"
fi

if [ ! -f bin/clang-format -o ! -f bin/clang-tidy ]; then
Expand Down