-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_dart_test_data2.sh
executable file
·48 lines (40 loc) · 1.2 KB
/
gen_dart_test_data2.sh
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
#!/bin/bash
set -e && cd "${0%/*}"
realpath() {
# needed for macOS
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo "$REALPATH"
}
# rebuilds the test/data/generated2.dart file
# creating temp dir and planning to remove it
temp_build_dir=$(mktemp -d -t c99build-XXXXXXX)
trap 'echo "Removing temp dir $temp_build_dir" && rm -rf $temp_build_dir' EXIT
# compiling and running
g++ "../../../c/randomref/main.cpp" --std=c++2a -o "$temp_build_dir/compiled.exe"
# running
json="$($temp_build_dir/compiled.exe)"
# replacing double quotes to single quotes
# shellcheck disable=SC2001
json_but_single_quotes=$(sed 's/"/'\''/g' <<< "$json")
# transforming JSON into a dart file
outfile="$(realpath data/generated2.dart)"
{
echo "// reference data for github.com/rtmigo/xrandom"
echo "// SPDX-FileCopyrightText: (c) 2021 Art Galkin <ortemeo@gmail.com>"
echo "// SPDX-License-Identifier: CC-BY-4.0"
echo ""
echo "// $(date)"
echo ""
echo "final referenceData = "
echo "$json_but_single_quotes"
echo ";"
} > "$outfile"
echo "Done."