-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunday
executable file
·41 lines (39 loc) · 1.07 KB
/
runday
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
#!/bin/zsh
# Copyright 2021 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# Run the AoC solution for a day on all of its input, saving logs to out/
# Run an each change with ./watch day1 or watchexec ./runday day1
YEAR="2021"
if [ $# -eq 0 ]; then
print -u 2 "Usage: runday day1"
exit 1
fi
BASEDIR="${0:h:a}"
DAYDIR="$BASEDIR/$1"
if [[ ! -d "$DAYDIR" ]]; then
print -u 2 "No such directory: $DAYDIR"
exit 1
fi
cd "$DAYDIR"
PROGRAM="$1.raku"
if [[ ! -f "$PROGRAM" ]]; then
print -u 2 "Missing file: $PROGRAM"
exit 1
fi
DATEFMT='%Y%m%d-%H%M%S'
mkdir -p out
OUTFILE="out/$(date +$DATEFMT).log"
if [[ -s "$BASEDIR/.cookie-jar" && ! -s input.actual.txt ]]; then
"$BASEDIR/fetchinput" "$YEAR" "$1" >| input.actual.txt
fi
CMD=(raku "$PROGRAM" input.example*.txt input.actual.txt)
TIMEFMT="$PROGRAM > $OUTFILE %U user %S system %P cpu %*E total"
print -u 2
print -u 2 "$CMD > $OUTFILE"
print -u 2
time ($CMD 2>&1 | tee "$OUTFILE" ; exit ${pipestatus[1]})
res=$?
exit $res