Skip to content

Commit

Permalink
add nanoseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
andreineculau committed Jun 25, 2022
1 parent 65bcf27 commit ce99a25
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CONST.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ YP_ALPINE_PKG_GLIBC_VSN=2.32-r0

# https://github.com/mikefarah/yq
YP_YQ_VSN=4.16.2

# https://github.com/ysoftwareab/nanoseconds
YP_NANOSECONDS_VSN=0.0.1
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ YP_VENDOR_FILES_IGNORE += \
-e "^bin/aws-cfviz$$" \
-e "^bin/esh$$" \
-e "^bin/git-archive-all$$" \
-e "^bin/nanoseconds-" \
-e "^bin/retry$$" \
-e "^bin/transcrypt$$" \
-e "^bin/travis-wait$$" \
Expand Down
7 changes: 7 additions & 0 deletions bin/.nanoseconds/nanoseconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

# can't symlink to ../nanoseconds or else YP_DIR detection in ../nanoseconds fails

YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null && pwd)"
${YP_DIR}/bin/nanoseconds "$@"
13 changes: 13 additions & 0 deletions bin/.nanoseconds/yp-nanoseconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail

# NOTE since this folder is meant to be appended to $PATH as
# PATH=${PATH}:path/to/yplatform/bin/.nanoseconds
# calling 'nanoseconds' might call the system executable 'nanoseconds'.
# This scripts assumes that there's no system executable 'yp-nanoseconds',
# so it will always call our 'bin/nanoseconds' script.

# can't symlink to ../nanoseconds or else YP_DIR detection in ../nanoseconds fails

YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." >/dev/null && pwd)"
${YP_DIR}/bin/nanoseconds "$@"
42 changes: 42 additions & 0 deletions bin/nanoseconds
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail

YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)"
source ${YP_DIR}/sh/common.inc.sh

# shellcheck disable=SC1091
VSN=$(source ${YP_DIR}/CONST.inc && echo "${YP_NANOSECONDS_VSN}")
NANOSECONDS_URL=https://github.com/ysoftwareab/nanoseconds/releases/download

case ${OS_SHORT}-${ARCH} in
darwin-amd64|darwin-arm64)
BINARY=nanoseconds_${VSN}_${OS_SHORT}_${ARCH}
;;
linux-amd64|linux-arm64)
BINARY=nanoseconds_${VSN}_${OS_SHORT}_${ARCH}
;;
*)
echo_err "nanoseconds: ${OS_SHORT}-${ARCH} is an unsupported OS-ARCH."
exit 1
;;
esac
ASSET_LOCAL=${YP_DIR}/bin/nanoseconds-${VSN}/${BINARY}
ASSET_REMOTE=${NANOSECONDS_URL}/v${VSN}/${BINARY}
BINARY_LOCAL=${ASSET_LOCAL}

[[ -f ${BINARY_LOCAL} ]] || {
ASSET_LOCAL=${HOME}/.cache/yplatform/nanoseconds-${VSN}/${BINARY}
BINARY_LOCAL=${ASSET_LOCAL}
}

[[ -f ${BINARY_LOCAL} ]] || {
echo_info "Fetching ${ASSET_REMOTE}..."
mkdir -p $(dirname ${ASSET_LOCAL})
curl -qfsSL \
-o ${ASSET_LOCAL} \
${ASSET_REMOTE}
chmod +x ${BINARY_LOCAL}
}

echo_info "Proxying to 'nanoseconds' as ${BINARY_LOCAL}."
${BINARY_LOCAL} "$@"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions bin/yp-env
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ yp::path_append ${YP_ENV_DIR}/bin/.jq
# NOTE if needed to bypass system's jd, call yp-jd
yp::path_append ${YP_ENV_DIR}/bin/.jd

# nanoseconds becomes always available
# NOTE if needed to bypass system's nanoseconds, call yp-nanoseconds
yp::path_append ${YP_ENV_DIR}/bin/.nanoseconds

# yq becomes always available
# NOTE if needed to bypass system's yq, call yp-yq
yp::path_append ${YP_ENV_DIR}/bin/.yq
Expand Down
1 change: 1 addition & 0 deletions bootstrap/brew-install-core.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ${YP_DIR}/bin/editorconfig-checker -version >/dev/null
${YP_DIR}/bin/gitleaks -h >/dev/null
${YP_DIR}/bin/jq -h >/dev/null
${YP_DIR}/bin/jd -h >/dev/null
${YP_DIR}/bin/nanoseconds >/dev/null
${YP_DIR}/bin/yq -h >/dev/null

brew_install_one_unless curl "curl --version | head -1" "^curl 7\."
Expand Down

0 comments on commit ce99a25

Please sign in to comment.