Skip to content

Commit

Permalink
build(agd): rely on checksums, not timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jan 7, 2024
1 parent f598470 commit 94c6cbf
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions bin/agd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fi

NEED_NODEJS=$BUILD_ONLY
case $@ in
*" start" | *" start "*)
start | *" start" | *" start "*)
# We're starting the daemon, so we need Node.js.
NEED_NODEJS=true
;;
Expand Down Expand Up @@ -110,14 +110,8 @@ fi
yarn "$@"
}

# Check if any package.json is newer than the installation stamp.
stamp=$STAMPS/yarn-installed
if test -e "$stamp"; then
print=( -newer "$stamp" )
else
print=()
fi
print+=( -print )
# Check if any package.json sums are different.
sum=$STAMPS/yarn-installed.sum

# Find the current list of package.jsons.
files=( package.json )
Expand All @@ -126,14 +120,14 @@ fi
done < <(lazy_yarn -s workspaces info |
sed -ne '/"location":/{ s/.*": "//; s!",.*!/package.json!; p; }')

src=$(find "${files[@]}" "${print[@]}" | head -1 || true)
test -z "$src" || {
echo "At least $src is newer than $stamp"
ls -l "$src" "$stamp" || true
rm -f "$STAMPS/yarn-built"
find "${files[@]}" -print0 | xargs -0 sha1sum | sort +1 > "${sum}T" || true
diff -u "$sum" "${sum}T" || {
echo "$sum has changed"
rm -f "$sum" "$STAMPS/yarn-built"
lazy_yarn install
date > "$stamp"
mv "${sum}T" "$sum"
}
rm -f "${sum}T"

stamp=$STAMPS/yarn-built
test -e "$stamp" || {
Expand All @@ -143,18 +137,15 @@ fi
}
fi

stamp=$GOLANG_DAEMON
if test -e "$stamp"; then
print=( -newer "$stamp" )
else
print=()
fi
print+=( -print )
src=$(find "$GOLANG_DIR" \( ! -name '*_test.go' -name '*.go' -o -name '*.cc' -o -name 'go.*' \) "${print[@]}" | head -1 || true)
test -z "$src" || {
echo "At least $src is newer than $stamp"
ls -l "$src" "$stamp" || true

sum=$STAMPS/golang-built.sum
find "$GOLANG_DIR" \( \
! -name '*_test.go' -name '*.go' \
-o -name '*.cc' \
-o -name 'go.*' \) \
-print0 | xargs -0 sha1sum | sort +1 > "${sum}T" || true
diff -u "$sum" "${sum}T" || {
echo "$GOLANG_DIR $sum has changed"
rm -f "$sum"
(
# Run this build in another subshell in case we had to modify the path.
case $(go version 2>/dev/null) in
Expand Down Expand Up @@ -184,7 +175,9 @@ fi
cd "$GOLANG_DIR"
make
)
mv "${sum}T" "$sum"
}
rm -f "${sum}T"
)

# the xsnap binary lives in a platform-specific directory
Expand Down

0 comments on commit 94c6cbf

Please sign in to comment.