#!/usr/bin/env bash # Clone pinned revisions of permissively-licensed open-source RTL into a # local corpus directory, for tools/corpus_check.sh to run lucisv over. # # Every repo is pinned to an exact commit and fetched shallow (--depth 1); # nothing here ever tracks a moving branch, so corpus numbers recorded in # docs/features/corpus-check/README.md stay reproducible. # # Usage: tools/corpus_fetch.sh [corpus-dir] (default: ./corpus) set -eu corpus_dir=${1:-corpus} # name|url|commit|sparse paths (space separated, empty = whole repo) # # Licenses: picorv32 ISC, ibex Apache-2.0, common_cells SHL-0.51, # opentitan Apache-2.0. All permissive; nothing is redistributed by this # repo -- corpus/ is gitignored and only ever read. repos=$( cat <<'EOF' picorv32|https://github.com/YosysHQ/picorv32.git|a473fc8fca393771d83b0ffcf0b14db3393339d8| ibex|https://github.com/lowRISC/ibex.git|7b5df75a041affe56e8c235260f98a09b3319008| common_cells|https://github.com/pulp-platform/common_cells.git|1281545696eb3fcba50ec5b4275993476a3c710e| opentitan|https://github.com/lowRISC/opentitan.git|bc1910f4505346dbef000155530fd5a68c60e889|hw/ip/uart hw/ip/gpio EOF ) fetch_one() { name=$1 url=$2 commit=$3 sparse=$4 dest="$corpus_dir/$name" stamp="$dest/.lucisv-corpus-rev" if [ -f "$stamp" ] && [ "$(cat "$stamp")" = "$commit" ]; then echo "== $name: already at $commit, skipping" return 0 fi echo "== $name: fetching $commit from $url" rm -rf "$dest" mkdir -p "$dest" git -C "$dest" init --quiet git -C "$dest" remote add origin "$url" if [ -n "$sparse" ]; then # Big repo (opentitan): blobless partial clone + sparse checkout of # just the subdirectories we care about. git -C "$dest" config core.sparseCheckout true git -C "$dest" sparse-checkout init --cone # shellcheck disable=SC2086 # $sparse is an intentional path list git -C "$dest" sparse-checkout set $sparse git -C "$dest" fetch --quiet --depth 1 --filter=blob:none origin "$commit" else git -C "$dest" fetch --quiet --depth 1 origin "$commit" fi git -C "$dest" checkout --quiet FETCH_HEAD echo "$commit" >"$stamp" } mkdir -p "$corpus_dir" echo "$repos" | while IFS='|' read -r name url commit sparse; do [ -n "$name" ] || continue fetch_one "$name" "$url" "$commit" "$sparse" done echo echo "corpus in $corpus_dir:" for d in "$corpus_dir"/*/; do [ -d "$d" ] || continue n=$(find "$d" -type f \( -name '*.v' -o -name '*.sv' \) -not -path '*/.git/*' | wc -l | tr -d ' ') printf ' %-16s %5s .v/.sv files\n' "$(basename "$d")" "$n" done