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 531eb51
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
15 changes: 14 additions & 1 deletion .github/actions/restore-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,21 @@ runs:
scripts/get-packed-versions.sh ~/endo | scripts/resolve-versions.sh
fi
yarn install
function findsha1() {
find ${1+"$@"} -print0 | xargs -0 sha1sum | sort +1 || true
}
# Find the current list of package.jsons.
files=( package.json )
while IFS= read -r line; do
files+=( "$line" )
done < <(yarn -s workspaces info |
sed -ne '/"location":/{ s/.*": "//; s!",.*!/package.json!; p; }')
mkdir -p node_modules/.cache/agoric
date > node_modules/.cache/agoric/yarn-installed
findsha1 "${files[@]}" > node_modules/.cache/agoric/yarn-installed.sum
if test -e ~/endo; then
# Stage the redirected `yarn install` consequences.
git add package.json yarn.lock
Expand Down
50 changes: 23 additions & 27 deletions bin/agd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function fatal() {
exit 1
}

function findsha1() {
find ${1+"$@"} -print0 | xargs -0 sha1sum | sort +1 || true
}

GVM_URL=${GVM_URL-https://github.com/devnw/gvm/releases/download/latest/gvm}
NVM_GIT_REPO=${NVM_GIT_REPO-https://github.com/nvm-sh/nvm.git}

Expand All @@ -45,7 +49,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 +114,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 +124,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"
findsha1 "${files[@]}" > "${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 +141,14 @@ 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
findsha1 "$GOLANG_DIR" \( \
! -name '*_test.go' -name '*.go' \
-o -name '*.cc' \
-o -name 'go.*' \) > "${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 +178,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 531eb51

Please sign in to comment.