openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / tools / fetch.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # tools/fetch.sh [all|omega|pocl|hip] |
| 4 | # Fetch the toolchain pinned in toolchain.lock into .oal/ and refuse anything whose sha256 or |
| 5 | # commit id differs. Sources are GitHub only. Writes nothing outside .oal/. |
| 6 | # Exit 0, 1 on a refused or missing file, 2 on a usage error. |
| 7 | # INTERIM host glue (POSIX sh + curl + git). Successor: an Omega fetch-and-verify unit once seeded |
| 8 | # Omega has an HTTPS client word; curl moves bytes, sha256sum decides what is accepted. |
| 9 | set -eu |
| 10 | cd "$(dirname "$0")/.." |
| 11 | . ./toolchain.lock |
| 12 | what=${1:-all} |
| 13 | case $what in all|omega|pocl|hip) ;; *) echo "usage: tools/fetch.sh [all|omega|pocl|hip]" >&2; exit 2;; esac |
| 14 | D=.oal |
| 15 | mkdir -p "$D/tools" |
| 16 | |
| 17 | get() { |
| 18 | url=$1; out=$2; want=$3 |
| 19 | if [ -f "$out" ] && [ "$(sha256sum "$out" | cut -d ' ' -f 1)" = "$want" ]; then |
| 20 | echo "fetch: cached $want $out" >&2 |
| 21 | return 0 |
| 22 | fi |
| 23 | curl -fsSL --retry 3 -o "$out.part" "$url" |
| 24 | got=$(sha256sum "$out.part" | cut -d ' ' -f 1) |
| 25 | if [ "$got" != "$want" ]; then |
| 26 | rm -f "$out.part" |
| 27 | echo "fetch: REFUSED $url sha256 $got, pinned $want" >&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | mv "$out.part" "$out" |
| 31 | echo "fetch: OK $want $out" >&2 |
| 32 | } |
| 33 | |
| 34 | checkout() { |
| 35 | repo=$1; commit=$2; dir=$3 |
| 36 | if [ -d "$dir/.git" ] && [ "$(git -C "$dir" rev-parse HEAD)" = "$commit" ]; then |
| 37 | echo "fetch: cached $repo@$commit" >&2 |
| 38 | return 0 |
| 39 | fi |
| 40 | rm -rf "$dir" |
| 41 | git init -q "$dir" |
| 42 | git -C "$dir" fetch -q --depth 1 "https://github.com/$repo.git" "$commit" |
| 43 | git -C "$dir" checkout -q FETCH_HEAD |
| 44 | got=$(git -C "$dir" rev-parse HEAD) |
| 45 | [ "$got" = "$commit" ] || { echo "fetch: REFUSED $repo at $got, pinned $commit" >&2; exit 1; } |
| 46 | echo "fetch: OK $repo@$commit" >&2 |
| 47 | } |
| 48 | |
| 49 | if [ "$what" = all ] || [ "$what" = omega ]; then |
| 50 | get "https://raw.githubusercontent.com/$OMEGA_MV_REPO/$OMEGA_MV_COMMIT/seed/out/omc" "$D/tools/omc" "$OMC_SHA256" |
| 51 | chmod +x "$D/tools/omc" |
| 52 | fi |
| 53 | |
| 54 | if [ "$what" = all ] || [ "$what" = pocl ]; then |
| 55 | get "https://github.com/$POCL_REPO/releases/download/$POCL_TAG/$POCL_ASSET" "$D/$POCL_ASSET" "$POCL_SHA256" |
| 56 | rm -rf "$D/pocl" "$D/icd" |
| 57 | mkdir -p "$D/pocl" "$D/icd" |
| 58 | tar -xzf "$D/$POCL_ASSET" -C "$D/pocl" --strip-components=1 |
| 59 | [ -f "$D/pocl/$POCL_LIB" ] || { echo "fetch: $POCL_LIB missing from $POCL_ASSET" >&2; exit 1; } |
| 60 | echo "$(pwd)/$D/pocl/$POCL_LIB" > "$D/icd/pocl.icd" |
| 61 | echo "fetch: PoCL at $D/pocl; export OCL_ICD_VENDORS=$(pwd)/$D/icd" >&2 |
| 62 | fi |
| 63 | |
| 64 | if [ "$what" = all ] || [ "$what" = hip ]; then |
| 65 | checkout "$HIPCPU_REPO" "$HIPCPU_COMMIT" "$D/hip-cpu" |
| 66 | get "https://raw.githubusercontent.com/$HIPIFY_REPO/$HIPIFY_COMMIT/bin/hipify-perl" "$D/tools/hipify-perl" "$HIPIFY_PERL_SHA256" |
| 67 | fi |