File size: 4,410 Bytes
3ab87b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
# Shallow-clone the repositories the calibration pool is harvested from.
#
#   bash tools/clone.sh                  # into $CALIB_RAW, or ./raw
#   bash tools/clone.sh /path/to/raw
#   JOBS=12 bash tools/clone.sh /mnt/big/raw
#
# Nothing is pinned. Repositories move forward and that is wanted: fresher
# upstream code is better calibration material. Builds are already reproducible
# from the committed pool, not from these clones, so freezing them would buy
# nothing and cost freshness.
#
# What does matter is knowing what you got. clone-manifest.tsv records the
# commit and its date for every repository, and harvest.py copies that into the
# provenance of each unit it creates.

set -u

RAW="${1:-${CALIB_RAW:-$PWD/raw}}"
JOBS="${JOBS:-6}"

# name | url | licence
#
# The licence column is not decoration. harvest.py reads this manifest and
# refuses to put anything into the pool whose licence is not permissive.
# thebookofshaders is all-rights-reserved: it is cloned so its structure can be
# inspected, and it must never reach pool/.
REPOS="
three.js|https://github.com/mrdoob/three.js|MIT
drei|https://github.com/pmndrs/drei|MIT
react-three-fiber|https://github.com/pmndrs/react-three-fiber|MIT
gl-matrix|https://github.com/toji/gl-matrix|MIT
webgpu-samples|https://github.com/webgpu/webgpu-samples|BSD-3-Clause
webgl-fundamentals|https://github.com/gfxfundamentals/webgl-fundamentals|BSD-3-Clause
thebookofshaders|https://github.com/patriciogonzalezvivo/thebookofshaders|ALL-RIGHTS-RESERVED
webgl-noise|https://github.com/stegu/webgl-noise|MIT
pixijs|https://github.com/pixijs/pixijs|MIT
tween.js|https://github.com/tweenjs/tween.js|MIT
glTF-Sample-Viewer|https://github.com/KhronosGroup/glTF-Sample-Viewer|Apache-2.0
ripgrep|https://github.com/BurntSushi/ripgrep|MIT
serde|https://github.com/serde-rs/serde|MIT
fmt|https://github.com/fmtlib/fmt|MIT
json-cpp|https://github.com/nlohmann/json|MIT
requests|https://github.com/psf/requests|Apache-2.0
flask|https://github.com/pallets/flask|BSD-3-Clause
vite|https://github.com/vitejs/vite|MIT
"

TOTAL=$(echo "$REPOS" | grep -c '|')
PARTS="$RAW/.manifest.d"

echo "target    : $RAW"
echo "repos     : $TOTAL"
echo "parallel  : $JOBS"
echo

mkdir -p "$PARTS" || { echo "cannot write to $RAW"; exit 1; }
rm -f "$PARTS"/*.tsv

export RAW PARTS

# One repository. Clones it if absent, fast-forwards it if present, then writes
# a single manifest line. Each worker writes its own file, so parallel runs
# cannot interleave inside a line.
clone_one() {
    name=$1
    url=$2
    lic=$3
    dst="$RAW/$name"

    if [ -d "$dst/.git" ]; then
        if git -C "$dst" fetch --depth 1 -q origin 2>/dev/null \
        && git -C "$dst" reset -q --hard FETCH_HEAD 2>/dev/null; then
            state=updated
        else
            state=STALE
        fi
    else
        rm -rf "$dst"
        if git clone --depth 1 --single-branch -q "$url" "$dst" 2>/dev/null; then
            state=cloned
        else
            state=FAILED
        fi
    fi

    if [ "$state" = "FAILED" ]; then
        printf '%-22s %-9s %s\n' "$name" "$state" "$url"
        return
    fi

    sha=$(git -C "$dst" rev-parse HEAD 2>/dev/null)
    when=$(git -C "$dst" log -1 --format=%cs 2>/dev/null)
    size=$(du -sh "$dst" 2>/dev/null | cut -f1)

    printf '%s\t%s\t%s\t%s\t%s\n' "$name" "$url" "$lic" "${sha:0:12}" "$when" \
        > "$PARTS/$name.tsv"
    printf '%-22s %-9s %-14s %-12s %s\n' "$name" "$state" "${sha:0:12}" "$when" "$size"
}
export -f clone_one

printf '%-22s %-9s %-14s %-12s %s\n' repo state commit date size
printf '%-22s %-9s %-14s %-12s %s\n' ---- ----- ------ ---- ----

echo "$REPOS" | grep '|' | tr '|' '\n' \
    | xargs -P "$JOBS" -n 3 bash -c 'clone_one "$0" "$1" "$2"'

{
    printf '# repo\turl\tlicence\tcommit\tcommit_date\n'
    printf '# cloned %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
    cat "$PARTS"/*.tsv 2>/dev/null | sort
} > "$RAW/clone-manifest.tsv"
rm -rf "$PARTS"

GOT=$(grep -vc '^#' "$RAW/clone-manifest.tsv")
echo
echo "$GOT of $TOTAL repositories on disk, $(du -sh "$RAW" 2>/dev/null | cut -f1)"
echo "manifest: $RAW/clone-manifest.tsv"

if [ "$GOT" -lt "$TOTAL" ]; then
    echo
    echo "Some repositories are missing. Rerun this script: the ones already"
    echo "here are fast-forwarded rather than recloned, so a retry is cheap."
fi

echo
echo "next:  python tools/harvest.py --raw $RAW --wiki <wiki-dir>"