Skip to content

Commit

Permalink
ci: use temporary directory for s2n_head build (#4771)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstewart authored Sep 25, 2024
1 parent a001e27 commit cd9eaa5
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions codebuild/bin/install_s2n_head.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ if [ "$#" -ne "1" ]; then
usage
fi

clone(){
# Path differences for internal builds mean we always need to go back to GitHub for head.
git clone --branch main --single-branch "$CLONE_SRC" "$SRC_ROOT"/s2n_head
}

# CMake(nix) and Make are using different directory structures.
set +u
if [[ "$IN_NIX_SHELL" ]]; then
Expand All @@ -46,24 +41,27 @@ else
fi
set -u

# Cleanup any stale s2n_head clones.
if [[ -d "$SRC_ROOT/s2n_head" ]]; then
s2nc_head="$DEST_DIR/s2nc_head"
if [[ -f "$s2nc_head" ]]; then
now=$(date +%s)
last_modified=$(stat -c %Y s2n_head)
last_modified=$(stat -c %Y "$s2nc_head")
days_old=$(( (now - last_modified) / 86400))
if ((days_old > 1 )); then
echo "s2n_head is $days_old days old, removing and cloning again."
rm -rf s2n_head
clone
else
echo "s2n_head already exists and is $days_old days old."
if ((days_old <= 1)); then
echo "Reusing s2n_head: s2nc_head exists and is $days_old days old."
exit 0
fi
else
clone
fi
cmake "$SRC_ROOT"/s2n_head -B"$BUILD_DIR" "$EXTRA_BUILD_FLAGS" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=on -DBUILD_TESTING=on
cmake --build "$BUILD_DIR" -- -j "$(nproc)"
cp -f "$BUILD_DIR"/bin/s2nc "$DEST_DIR"/s2nc_head
cp -f "$BUILD_DIR"/bin/s2nd "$DEST_DIR"/s2nd_head

git clone --branch main --single-branch "$CLONE_SRC" "$BUILD_DIR"

cmake "$BUILD_DIR" -B"$BUILD_DIR"/build "$EXTRA_BUILD_FLAGS" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_SHARED_LIBS=on \
-DBUILD_TESTING=on
cmake --build "$BUILD_DIR"/build --target s2nc -- -j $(nproc)
cmake --build "$BUILD_DIR"/build --target s2nd -- -j $(nproc)

cp -f "$BUILD_DIR"/build/bin/s2nc "$s2nc_head"
cp -f "$BUILD_DIR"/build/bin/s2nd "$DEST_DIR"/s2nd_head

exit 0

0 comments on commit cd9eaa5

Please sign in to comment.