-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from skinner-m-c/feature/remove-dependencies
Remove curl perl and coreutils as required dependencies
- Loading branch information
Showing
20 changed files
with
449 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,72 @@ | ||
#!/bin/bash | ||
|
||
function clock::now() { | ||
if perl -MTime::HiRes -e "" > /dev/null 2>&1; then | ||
perl -MTime::HiRes -e 'printf("%.0f\n", Time::HiRes::time() * 1000)' | ||
elif [[ "${_OS:-}" != "OSX" ]]; then | ||
date +%s%N | ||
else | ||
echo "" | ||
if dependencies::has_perl && perl -MTime::HiRes -e "" > /dev/null 2>&1; then | ||
if perl -MTime::HiRes -e 'printf("%.0f\n",Time::HiRes::time()*1000000000)'; then | ||
return 0 | ||
fi | ||
fi | ||
|
||
if check_os::is_windows && dependencies::has_powershell; then | ||
powershell -Command " | ||
\$unixEpoch = [DateTime]'1970-01-01 00:00:00'; | ||
\$now = [DateTime]::UtcNow; | ||
\$ticksSinceEpoch = (\$now - \$unixEpoch).Ticks; | ||
\$nanosecondsSinceEpoch = \$ticksSinceEpoch * 100; | ||
Write-Output \$nanosecondsSinceEpoch | ||
" | ||
return 0 | ||
fi | ||
|
||
if ! check_os::is_macos && ! check_os::is_alpine; then | ||
local result | ||
result=$(date +%s%N) | ||
if [[ "$result" != *N ]] && [[ "$result" -gt 0 ]]; then | ||
echo "$result" | ||
return 0 | ||
fi | ||
fi | ||
|
||
local shell_time has_shell_time | ||
shell_time="$(clock::shell_time)" | ||
has_shell_time="$?" | ||
if [[ "$has_shell_time" -eq 0 ]]; then | ||
local seconds microseconds | ||
seconds=$(echo "$shell_time" | cut -f 1 -d '.') | ||
microseconds=$(echo "$shell_time" | cut -f 2 -d '.') | ||
|
||
math::calculate "($seconds * 1000000000) + ($microseconds * 1000)" | ||
return 0 | ||
fi | ||
|
||
echo "" | ||
return 1 | ||
} | ||
|
||
function clock::shell_time() { | ||
# Get time directly from the shell rather than a program. | ||
[[ -n ${EPOCHREALTIME+x} && -n "$EPOCHREALTIME" ]] && LC_ALL=C echo "$EPOCHREALTIME" | ||
} | ||
|
||
_START_TIME=$(clock::now) | ||
|
||
function clock::total_runtime_in_milliseconds() { | ||
end_time=$(clock::now) | ||
if [[ -n $end_time ]]; then | ||
echo $(( end_time - _START_TIME )) | ||
math::calculate "($end_time-$_START_TIME)/1000000" | ||
else | ||
echo "" | ||
fi | ||
} | ||
|
||
function clock::total_runtime_in_nanoseconds() { | ||
end_time=$(clock::now) | ||
if [[ -n $end_time ]]; then | ||
math::calculate "($end_time-$_START_TIME)" | ||
else | ||
echo "" | ||
fi | ||
} | ||
|
||
function clock::init() { | ||
_START_TIME=$(clock::now) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
function dependencies::has_perl() { | ||
command -v perl >/dev/null 2>&1 | ||
} | ||
|
||
function dependencies::has_powershell() { | ||
command -v powershell > /dev/null 2>&1 | ||
} | ||
|
||
function dependencies::has_adjtimex() { | ||
command -v adjtimex >/dev/null 2>&1 | ||
} | ||
|
||
function dependencies::has_bc() { | ||
command -v bc >/dev/null 2>&1 | ||
} | ||
|
||
function dependencies::has_awk() { | ||
command -v awk >/dev/null 2>&1 | ||
} | ||
|
||
function dependencies::has_git() { | ||
command -v git >/dev/null 2>&1 | ||
} | ||
|
||
function dependencies::has_curl() { | ||
command -v curl >/dev/null 2>&1 | ||
} | ||
|
||
function dependencies::has_wget() { | ||
command -v wget >/dev/null 2>&1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
function io::download_to() { | ||
local url="$1" | ||
local output="$2" | ||
if dependencies::has_curl; then | ||
curl -L -J -o "$output" "$url" 2>/dev/null | ||
elif dependencies::has_wget; then | ||
wget -q -O "$output" "$url" 2>/dev/null | ||
else | ||
return 1 | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
if dependencies::has_bc; then | ||
# bc is better than awk because bc has no integer limits. | ||
function math::calculate() { | ||
echo "$*" | bc | ||
} | ||
elif dependencies::has_awk; then | ||
function math::calculate() { | ||
awk "BEGIN { print ""$*"" }" | ||
} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.