Skip to content

Commit efac10b

Browse files
committed
fix: allow run_all_testdata to be run from anywhere
1 parent 222c198 commit efac10b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

script/run_all_testdata.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Generate uniast for all testdata. Must be run from repo root
2+
# Generate uniast for all testdata.
33
#
44
# USAGE:
55
# 1. Save the uniast to out/
@@ -11,7 +11,10 @@
1111
# 3. Use a custom abcoder executable
1212
# OUTDIR=out/ ABCEXE="./other_abcoder" ./script/run_testdata.sh
1313

14-
ABCEXE=${ABCEXE:-./abcoder}
14+
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
15+
REPO_ROOT=$(realpath --relative-to=$(pwd) "$SCRIPT_DIR/..")
16+
17+
ABCEXE=${ABCEXE:-"$REPO_ROOT/abcoder"}
1518
OUTDIR=${OUTDIR:?Error: OUTDIR is a mandatory environment variable}
1619
PARALLEL_FLAGS=${PARALLEL_FLAGS:---tag}
1720

@@ -20,18 +23,19 @@ LANGS=(go rust python cxx)
2023
detect_jobs() {
2124
local ABCEXE=${1:-$ABCEXE}
2225
for lang in ${LANGS[@]}; do
23-
for repo in testdata/$lang/*; do
24-
outname=$(echo $repo | sed 's/^testdata\///; s/[/:? ]/_/g')
26+
for repo in "$REPO_ROOT/testdata/$lang"/*; do
27+
local rel_path=$(realpath --relative-to="$REPO_ROOT/testdata" "$repo")
28+
local outname=$(echo "$rel_path" | sed 's/[/:? ]/_/g')
2529
echo $ABCEXE parse $lang $repo -o $OUTDIR/$outname.json
2630
done
2731
done
2832
}
2933

3034
if [[ ! -x "$ABCEXE" ]]; then
31-
echo "Error: The specified abcoder executable '$ABCEXE' does not exist or is not executable." >&2
32-
exit 1
35+
echo "Error: The specified abcoder executable '$ABCEXE' does not exist or is not executable." >&2
36+
exit 1
3337
fi
3438
mkdir -pv "$OUTDIR"
35-
detect_jobs | parallel $PARALLEL_FLAGS echo {}
39+
detect_jobs
3640
echo
3741
detect_jobs | parallel $PARALLEL_FLAGS -j$(nproc --all) --jobs 0 "eval {}" 2>&1

0 commit comments

Comments
 (0)