diff --git a/scripts/run_integration_tests_aarch64.sh b/scripts/run_integration_tests_aarch64.sh index 627bb99d4..41ef3084e 100755 --- a/scripts/run_integration_tests_aarch64.sh +++ b/scripts/run_integration_tests_aarch64.sh @@ -12,6 +12,46 @@ EDK2_BUILD_DIR="$WORKLOADS_DIR/edk2_build" mkdir -p "$WORKLOADS_DIR" +# Checkout source code of a GIT repo with specified branch and commit +# Args: +# $1: Target directory +# $2: GIT URL of the repo +# $3: Required branch +# $4: Required commit (optional) +checkout_repo() { + SRC_DIR="$1" + GIT_URL="$2" + GIT_BRANCH="$3" + GIT_COMMIT="$4" + + # Check whether the local HEAD commit same as the requested commit or not. + # If commit is not specified, compare local HEAD and remote HEAD. + # Remove the folder if there is difference. + if [ -d "$SRC_DIR" ]; then + pushd $SRC_DIR + git fetch + SRC_LOCAL_COMMIT=$(git rev-parse HEAD) + if [ -z "$GIT_COMMIT" ]; then + GIT_COMMIT=$(git rev-parse remotes/origin/"$GIT_BRANCH") + fi + popd + if [ "$SRC_LOCAL_COMMIT" != "$GIT_COMMIT" ]; then + rm -rf "$SRC_DIR" + fi + fi + + # Checkout the specified branch and commit (if required) + if [ ! -d "$SRC_DIR" ]; then + git clone --depth 1 "$GIT_URL" -b "$GIT_BRANCH" "$SRC_DIR" + if [ "$GIT_COMMIT" ]; then + pushd "$SRC_DIR" + git fetch --depth 1 origin "$GIT_COMMIT" + git reset --hard FETCH_HEAD + popd + fi + fi +} + build_edk2() { EDK2_REPO="https://github.com/tianocore/edk2.git" EDK2_DIR="edk2"