diff --git a/codebuild/bin/install_s2n_head.sh b/codebuild/bin/install_s2n_head.sh index ebad50d12b2..3fbb3f609be 100755 --- a/codebuild/bin/install_s2n_head.sh +++ b/codebuild/bin/install_s2n_head.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). @@ -12,31 +12,53 @@ # express or implied. See the License for the specific language governing # permissions and limitations under the License. -set -ex -pushd "$(pwd)" +set -eu usage() { echo "install_s2n_head.sh build_dir" exit 1 } +BUILD_DIR=$1 +SRC_ROOT=${SRC_ROOT:-$(pwd)} + if [ "$#" -ne "1" ]; then usage fi -BUILD_DIR=$1 -source codebuild/bin/jobs.sh -cd "$BUILD_DIR" - -# Clone the most recent s2n commit -git clone --depth=1 https://github.com/aws/s2n-tls s2n_head -cmake ./s2n_head -Bbuild -DCMAKE_PREFIX_PATH="$LIBCRYPTO_ROOT" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=on -DBUILD_TESTING=on -cmake --build ./build -- -j $JOBS +clone(){ + git clone --branch main --single-branch . "$SRC_ROOT"/s2n_head +} -# Copy new executables to bin directory -cp -f "$BUILD_DIR"/build/bin/s2nc "$BASE_S2N_DIR"/bin/s2nc_head -cp -f "$BUILD_DIR"/build/bin/s2nd "$BASE_S2N_DIR"/bin/s2nd_head +# CMake(nix) and Make are using different directory structures. +set +u +if [[ "$IN_NIX_SHELL" ]]; then + export DEST_DIR="$SRC_ROOT"/build/bin + export EXTRA_BUILD_FLAGS="" +else + export DEST_DIR="$SRC_ROOT"/bin + export EXTRA_BUILD_FLAGS="-DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT" +fi +set -u -popd +# Cleanup any stale s2n_head clones. +if [[ -d "$SRC_ROOT/s2n_head" ]]; then + now=$(date +%s) + last_modified=$(stat -c %Y s2n_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." + 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 exit 0 diff --git a/nix/shell.sh b/nix/shell.sh index bed64de1d4c..75072d244cd 100644 --- a/nix/shell.sh +++ b/nix/shell.sh @@ -28,7 +28,7 @@ libcrypto_alias libressl "${LIBRESSL_INSTALL_DIR}/bin/openssl" function clean { banner "Cleanup ./build" - rm -rf ./build + rm -rf ./build ./s2n_head } function configure { @@ -47,6 +47,10 @@ function build { banner "Running Build" javac tests/integrationv2/bin/SSLSocketClient.java cmake --build ./build -j $(nproc) + # Build s2n from HEAD + if [[ -z "${S2N_KTLS_TESTING_EXPECTED}" ]]; then + $SRC_ROOT/codebuild/bin/install_s2n_head.sh $(mktemp -d) + fi } function unit { @@ -60,21 +64,16 @@ function unit { function integ { if [ "$1" == "help" ]; then echo "The following tests are not supported:" - echo " - cross_compatibility" - echo " This test depends on s2nc_head and s2nd_head. To run" - echo " the test build s2n-tls from the main branch on github." - echo " Change the names of s2n[cd] to s2n[cd]_head and add those" - echo " binaries to \$PATH." echo "- renegotiate_apache" echo " This test requires apache to be running. See codebuild/bin/s2n_apache.sh" echo " for more info." return fi if [[ -z "$1" ]]; then - banner "Running all integ tests except cross_compatibility, renegotiate_apache." + banner "Running all integ tests except renegotiate_apache." (cd $SRC_ROOT/build; ctest -L integrationv2 -E "(integrationv2_cross_compatibility|integrationv2_renegotiate_apache)" --verbose) else - banner "Warning: cross_compatibility & renegotiate_apache are not supported in nix for various reasons integ help for more info." + banner "Warning: renegotiate_apache is not supported in nix for various reasons integ help for more info." for test in $@; do ctest --test-dir ./build -L integrationv2 --no-tests=error --output-on-failure -R "$test" --verbose if [ "$?" -ne 0 ]; then