worthant commited on
Commit
3ab87b6
·
1 Parent(s): 0eba5ab

refactor(tools): move clone.sh into tools and drop the hardcoded path

Browse files

The raw directory came from a literal /home/boris path, so the pool couldonly be harvested on one machine. It now takes the directory as anargument or from CALIB_RAW.Repositories stay unpinned on purpose: builds are reproducible from thecommitted pool, not from these clones, and fresher upstream code isbetter material. What was missing was the record, so clone-manifest.tsvnow carries the commit, its date and the licence for each repository.

Files changed (2) hide show
  1. clone.sh +0 -41
  2. tools/clone.sh +127 -0
clone.sh DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Shallow-clone permissively licensed source repos for the calibration corpus.
3
- RAW=/home/boris/.cache/calib-build/raw
4
- mkdir -p "$RAW"
5
-
6
- # name|url (licenses verified post-clone from each repo's LICENSE file)
7
- REPOS="
8
- three.js|https://github.com/mrdoob/three.js
9
- drei|https://github.com/pmndrs/drei
10
- react-three-fiber|https://github.com/pmndrs/react-three-fiber
11
- gl-matrix|https://github.com/toji/gl-matrix
12
- webgpu-samples|https://github.com/webgpu/webgpu-samples
13
- webgl-fundamentals|https://github.com/gfxfundamentals/webgl-fundamentals
14
- thebookofshaders|https://github.com/patriciogonzalezvivo/thebookofshaders
15
- webgl-noise|https://github.com/stegu/webgl-noise
16
- pixijs|https://github.com/pixijs/pixijs
17
- tween.js|https://github.com/tweenjs/tween.js
18
- glTF-Sample-Viewer|https://github.com/KhronosGroup/glTF-Sample-Viewer
19
- ripgrep|https://github.com/BurntSushi/ripgrep
20
- serde|https://github.com/serde-rs/serde
21
- fmt|https://github.com/fmtlib/fmt
22
- json-cpp|https://github.com/nlohmann/json
23
- requests|https://github.com/psf/requests
24
- flask|https://github.com/pallets/flask
25
- vite|https://github.com/vitejs/vite
26
- "
27
-
28
- echo "$REPOS" | grep -v '^$' | while IFS='|' read -r name url; do
29
- echo "$name $url"
30
- done | xargs -P 6 -n 2 bash -c '
31
- RAW=/home/boris/.cache/calib-build/raw
32
- if [ -d "$RAW/$0/.git" ]; then echo "SKIP $0"; exit 0; fi
33
- rm -rf "$RAW/$0"
34
- if git clone --depth 1 --single-branch --quiet "$1" "$RAW/$0" 2>/dev/null; then
35
- echo "OK $0 $(du -sh "$RAW/$0" | cut -f1)"
36
- else
37
- echo "FAIL $0 $1"
38
- fi
39
- '
40
- echo "=== DONE ==="
41
- du -sh "$RAW"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tools/clone.sh ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Shallow-clone the repositories the calibration pool is harvested from.
3
+ #
4
+ # bash tools/clone.sh # into $CALIB_RAW, or ./raw
5
+ # bash tools/clone.sh /path/to/raw
6
+ # JOBS=12 bash tools/clone.sh /mnt/big/raw
7
+ #
8
+ # Nothing is pinned. Repositories move forward and that is wanted: fresher
9
+ # upstream code is better calibration material. Builds are already reproducible
10
+ # from the committed pool, not from these clones, so freezing them would buy
11
+ # nothing and cost freshness.
12
+ #
13
+ # What does matter is knowing what you got. clone-manifest.tsv records the
14
+ # commit and its date for every repository, and harvest.py copies that into the
15
+ # provenance of each unit it creates.
16
+
17
+ set -u
18
+
19
+ RAW="${1:-${CALIB_RAW:-$PWD/raw}}"
20
+ JOBS="${JOBS:-6}"
21
+
22
+ # name | url | licence
23
+ #
24
+ # The licence column is not decoration. harvest.py reads this manifest and
25
+ # refuses to put anything into the pool whose licence is not permissive.
26
+ # thebookofshaders is all-rights-reserved: it is cloned so its structure can be
27
+ # inspected, and it must never reach pool/.
28
+ REPOS="
29
+ three.js|https://github.com/mrdoob/three.js|MIT
30
+ drei|https://github.com/pmndrs/drei|MIT
31
+ react-three-fiber|https://github.com/pmndrs/react-three-fiber|MIT
32
+ gl-matrix|https://github.com/toji/gl-matrix|MIT
33
+ webgpu-samples|https://github.com/webgpu/webgpu-samples|BSD-3-Clause
34
+ webgl-fundamentals|https://github.com/gfxfundamentals/webgl-fundamentals|BSD-3-Clause
35
+ thebookofshaders|https://github.com/patriciogonzalezvivo/thebookofshaders|ALL-RIGHTS-RESERVED
36
+ webgl-noise|https://github.com/stegu/webgl-noise|MIT
37
+ pixijs|https://github.com/pixijs/pixijs|MIT
38
+ tween.js|https://github.com/tweenjs/tween.js|MIT
39
+ glTF-Sample-Viewer|https://github.com/KhronosGroup/glTF-Sample-Viewer|Apache-2.0
40
+ ripgrep|https://github.com/BurntSushi/ripgrep|MIT
41
+ serde|https://github.com/serde-rs/serde|MIT
42
+ fmt|https://github.com/fmtlib/fmt|MIT
43
+ json-cpp|https://github.com/nlohmann/json|MIT
44
+ requests|https://github.com/psf/requests|Apache-2.0
45
+ flask|https://github.com/pallets/flask|BSD-3-Clause
46
+ vite|https://github.com/vitejs/vite|MIT
47
+ "
48
+
49
+ TOTAL=$(echo "$REPOS" | grep -c '|')
50
+ PARTS="$RAW/.manifest.d"
51
+
52
+ echo "target : $RAW"
53
+ echo "repos : $TOTAL"
54
+ echo "parallel : $JOBS"
55
+ echo
56
+
57
+ mkdir -p "$PARTS" || { echo "cannot write to $RAW"; exit 1; }
58
+ rm -f "$PARTS"/*.tsv
59
+
60
+ export RAW PARTS
61
+
62
+ # One repository. Clones it if absent, fast-forwards it if present, then writes
63
+ # a single manifest line. Each worker writes its own file, so parallel runs
64
+ # cannot interleave inside a line.
65
+ clone_one() {
66
+ name=$1
67
+ url=$2
68
+ lic=$3
69
+ dst="$RAW/$name"
70
+
71
+ if [ -d "$dst/.git" ]; then
72
+ if git -C "$dst" fetch --depth 1 -q origin 2>/dev/null \
73
+ && git -C "$dst" reset -q --hard FETCH_HEAD 2>/dev/null; then
74
+ state=updated
75
+ else
76
+ state=STALE
77
+ fi
78
+ else
79
+ rm -rf "$dst"
80
+ if git clone --depth 1 --single-branch -q "$url" "$dst" 2>/dev/null; then
81
+ state=cloned
82
+ else
83
+ state=FAILED
84
+ fi
85
+ fi
86
+
87
+ if [ "$state" = "FAILED" ]; then
88
+ printf '%-22s %-9s %s\n' "$name" "$state" "$url"
89
+ return
90
+ fi
91
+
92
+ sha=$(git -C "$dst" rev-parse HEAD 2>/dev/null)
93
+ when=$(git -C "$dst" log -1 --format=%cs 2>/dev/null)
94
+ size=$(du -sh "$dst" 2>/dev/null | cut -f1)
95
+
96
+ printf '%s\t%s\t%s\t%s\t%s\n' "$name" "$url" "$lic" "${sha:0:12}" "$when" \
97
+ > "$PARTS/$name.tsv"
98
+ printf '%-22s %-9s %-14s %-12s %s\n' "$name" "$state" "${sha:0:12}" "$when" "$size"
99
+ }
100
+ export -f clone_one
101
+
102
+ printf '%-22s %-9s %-14s %-12s %s\n' repo state commit date size
103
+ printf '%-22s %-9s %-14s %-12s %s\n' ---- ----- ------ ---- ----
104
+
105
+ echo "$REPOS" | grep '|' | tr '|' '\n' \
106
+ | xargs -P "$JOBS" -n 3 bash -c 'clone_one "$0" "$1" "$2"'
107
+
108
+ {
109
+ printf '# repo\turl\tlicence\tcommit\tcommit_date\n'
110
+ printf '# cloned %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
111
+ cat "$PARTS"/*.tsv 2>/dev/null | sort
112
+ } > "$RAW/clone-manifest.tsv"
113
+ rm -rf "$PARTS"
114
+
115
+ GOT=$(grep -vc '^#' "$RAW/clone-manifest.tsv")
116
+ echo
117
+ echo "$GOT of $TOTAL repositories on disk, $(du -sh "$RAW" 2>/dev/null | cut -f1)"
118
+ echo "manifest: $RAW/clone-manifest.tsv"
119
+
120
+ if [ "$GOT" -lt "$TOTAL" ]; then
121
+ echo
122
+ echo "Some repositories are missing. Rerun this script: the ones already"
123
+ echo "here are fast-forwarded rather than recloned, so a retry is cheap."
124
+ fi
125
+
126
+ echo
127
+ echo "next: python tools/harvest.py --raw $RAW --wiki <wiki-dir>"