Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions firmware/build-schedules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ done
# copy, so whatever state main.c was in - including the uncommitted net id it
# normally carries - comes back exactly.
ORIGINAL="$(mktemp)"
SCRATCH="$(mktemp)"
cp "$MAIN" "$ORIGINAL"
BUILT=()
restore() {
rm -f "$SCRATCH"
cp "$ORIGINAL" "$MAIN" 2>/dev/null || true
if cmp -s "$ORIGINAL" "$MAIN"; then
rm -f "$ORIGINAL"
Expand All @@ -67,6 +69,24 @@ restore() {
}
trap restore EXIT

# In-place sed is not portable: BSD sed (macOS) requires an argument to -i and
# GNU sed (Linux) refuses one. Filter through a scratch file instead, which both
# accept, and write back with cat so $MAIN keeps its inode and permissions.
edit_in_place() { # <sed-script> <file>
sed -E "$1" "$2" > "$SCRATCH"
cat "$SCRATCH" > "$2"
}

# sha256sum is coreutils (Linux); shasum is the perl tool macOS ships. Neither
# is present everywhere, so pick whichever exists.
sha256_list() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$@"
else
shasum -a 256 "$@"
fi
}

mkdir -p "$OUT_DIR"
echo "Building ${#SCHEDULES[@]} gateway net-core image(s) into $OUT_DIR"
echo
Expand All @@ -75,7 +95,7 @@ for sched in "${SCHEDULES[@]}"; do
echo "=== $sched ==="
# Only the schedule_app line: a blanket substitution would also rewrite the
# extern declaration on the line above it.
sed -i '' -E "s/^(schedule_t[[:space:]]+\*schedule_app[[:space:]]*=[[:space:]]*&)schedule_[a-z]+;/\1schedule_${sched};/" "$MAIN"
edit_in_place "s/^(schedule_t[[:space:]]+\*schedule_app[[:space:]]*=[[:space:]]*&)schedule_[a-z]+;/\1schedule_${sched};/" "$MAIN"
if ! grep -qE "^schedule_t[[:space:]]+\*schedule_app[[:space:]]*=[[:space:]]*&schedule_${sched};" "$MAIN"; then
echo "Error: could not point schedule_app at schedule_${sched}" >&2
exit 1
Expand All @@ -89,4 +109,4 @@ for sched in "${SCHEDULES[@]}"; do
done

echo "Done."
shasum -a 256 "$OUT_DIR"/*.hex | sed 's/^/ /'
sha256_list "$OUT_DIR"/*.hex | sed 's/^/ /'
Loading