#!/bin/sh set -eu ROOT_DIR=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) THIRD_PARTY_DIR="${ROOT_DIR}/third_party" WASM3_URL="https://github.com/wasm3/wasm3.git" WASM3_DIR="${THIRD_PARTY_DIR}/wasm3" WAMR_URL="https://github.com/bytecodealliance/wasm-micro-runtime.git" WAMR_REF="0e47872fb4e57833dbeccf7c312a406fa2dac2bc" WAMR_DIR="${THIRD_PARTY_DIR}/wamr" OTEL_SDK_URL="https://github.com/zig-o11y/opentelemetry-sdk.git" # Pin the upstream commit that includes the Gauge OTLP data-point leak fix # until a newer release tag is available. OTEL_SDK_REF="e92f7652e5c639d52c8be3b6836429dfefaaed6d" OTEL_SDK_DIR="${THIRD_PARTY_DIR}/opentelemetry-sdk" clone_or_reset_repo() { name=$1 url=$2 ref=$3 dir=$4 if [ ! -d "${dir}/.git" ]; then rm -rf "${dir}" git clone "${url}" "${dir}" fi git -C "${dir}" remote set-url origin "${url}" git -C "${dir}" fetch --force --tags origin "+refs/heads/*:refs/remotes/origin/*" git -C "${dir}" reset --hard if [ "${ref}" = "main" ]; then if git -C "${dir}" show-ref --verify --quiet refs/remotes/origin/main; then branch=main elif git -C "${dir}" show-ref --verify --quiet refs/remotes/origin/master; then branch=master else branch=$(git -C "${dir}" symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##') if [ -z "${branch}" ]; then printf 'failed to resolve default branch for %s\n' "${name}" >&2 exit 1 fi fi git -C "${dir}" checkout -B "${branch}" "origin/${branch}" git -C "${dir}" reset --hard "origin/${branch}" else git -C "${dir}" checkout --detach "${ref}" git -C "${dir}" reset --hard "${ref}" fi git -C "${dir}" clean -fdx printf 'initialized %s at %s\n' "${name}" "$(git -C "${dir}" rev-parse HEAD)" } mkdir -p "${THIRD_PARTY_DIR}" clone_or_reset_repo "wasm3" "${WASM3_URL}" "main" "${WASM3_DIR}" clone_or_reset_repo "wamr" "${WAMR_URL}" "${WAMR_REF}" "${WAMR_DIR}" clone_or_reset_repo "opentelemetry-sdk" "${OTEL_SDK_URL}" "${OTEL_SDK_REF}" "${OTEL_SDK_DIR}" printf 'third_party setup complete\n'