From db66d596726d66ff236478e46faf562a9c6c8510 Mon Sep 17 00:00:00 2001 From: Ihor Solodrai Date: Tue, 17 Sep 2024 16:36:51 -0700 Subject: [PATCH] Allow for an arbitrary location of $KBUILD_OUTPUT in tar-artifacts.sh There are two distinct KBUILD_OUTPUTs across libbpf/ci: - $KBUILD_OUTPUT used by actions/cache (in prepare-incremental-build) - $REPO_ROOT/kbuild-output used by ./run-vmtest So far this difference wasn't important, because $KBUILD_OUTPUT always pointed to $(pwd)/kbuild-output. And $(pwd) happened to be a root of the linux source tree, also equal to github.workspace However we don't want prepare-incremental-build action to put any requirements on $KBUILD_OUTPUT path to allow for a convenient action API. With this, the difference becomes important, because only selected files are put from $KBUILD_OUTPUT into kernel-build output artifacts, while entire $KBUILD_OUTPUT has to be cached by prepare-incremental-build. --- .github/scripts/tar-artifact.sh | 68 +++++++++++++++++++++---------- .github/workflows/kernel-test.yml | 5 ++- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/.github/scripts/tar-artifact.sh b/.github/scripts/tar-artifact.sh index 43bff08..133151c 100644 --- a/.github/scripts/tar-artifact.sh +++ b/.github/scripts/tar-artifact.sh @@ -2,6 +2,15 @@ set -eux +# Assumptions: +# - $(pwd) is the root of kernel repo we're tarring +# - zstd is installed by default in the runner images + +if [ ! -d "${KBUILD_OUTPUT:-}" ]; then + echo "KBUILD_OUTPUT must be a directory" + exit 1 +fi + arch="${1}" toolchain="${2}" archive_make_helpers="${3:-0}" @@ -39,6 +48,31 @@ find selftests/ -name "*.o" -a ! -name "*.bpf.o" -print0 | \ # DWARF to symbolize stacktraces). "${arch}"-linux-gnu-strip --strip-debug "${KBUILD_OUTPUT}"/vmlinux +image_name=$(make ARCH="$(platform_to_kernel_arch "${arch}")" -s image_name) +kbuild_output_file_list=( + ".config" + "${image_name}" + "include/config/auto.conf" + "include/generated/autoconf.h" + "vmlinux" +) + +# While we are preparing the tarball, move $KBUILD_OUTPUT to a tmp +# location just in case it's inside the repo root +tmp=$(mktemp -d) +mv "${KBUILD_OUTPUT}" "${tmp}" +stashed_kbuild_output=${tmp}/$(basename "${KBUILD_OUTPUT}") + +# Note: ${local_kbuild_output} must point to ./kbuild-output because +# of the tar command at the bottom. +local_kbuild_output=$(realpath kbuild-output) +mkdir -p "${local_kbuild_output}" + +for file in "${kbuild_output_file_list[@]}"; do + mkdir -p "$(dirname "${local_kbuild_output}/${file}")" + cp -a "${stashed_kbuild_output}/${file}" "${local_kbuild_output}/${file}" +done + additional_file_list=() if [ $archive_make_helpers -ne 0 ]; then # Package up a bunch of additional infrastructure to support running @@ -52,26 +86,18 @@ if [ $archive_make_helpers -ne 0 ]; then ) fi -image_name=$(make ARCH="$(platform_to_kernel_arch "${arch}")" -s image_name) -kbuild_output_file_list=( - ".config" - "${image_name}" - "include/config/auto.conf" - "include/generated/autoconf.h" - "vmlinux" -) - -# Assumptions: -# - $(pwd) is the root of kernel repo we're tarring -# - zstd is installed by default in the runner images -tar -cf - \ - -C "$KBUILD_OUTPUT" \ - "${kbuild_output_file_list[@]}" \ - -C "$(pwd)" \ - "${additional_file_list[@]}" \ - --exclude '*.cmd' \ - --exclude '*.d' \ - --exclude '*.output' \ - selftests/bpf/ \ +tar -cf - \ + kbuild-output \ + "${additional_file_list[@]}" \ + --exclude '*.cmd' \ + --exclude '*.d' \ + --exclude '*.h' \ + --exclude '*.output' \ + selftests/bpf/ \ | zstd -T0 -19 -o "vmlinux-${arch}-${toolchain}.tar.zst" + +# Cleanup and restore the original KBUILD_OUTPUT +# We have to put KBUILD_OUTPUT back to its original location for actions/cache +rm -rf "${local_kbuild_output}" +mv "${stashed_kbuild_output}" "${KBUILD_OUTPUT}" diff --git a/.github/workflows/kernel-test.yml b/.github/workflows/kernel-test.yml index 4fbb2c7..21efc04 100644 --- a/.github/workflows/kernel-test.yml +++ b/.github/workflows/kernel-test.yml @@ -41,7 +41,6 @@ jobs: KERNEL: ${{ inputs.kernel }} REPO_ROOT: ${{ github.workspace }} REPO_PATH: "" - KBUILD_OUTPUT: ${{ github.workspace }}/kbuild-output # https://github.com/actions/runner/issues/1483#issuecomment-1031671517 # booleans are weird in GH. CONTINUE_ON_ERROR: ${{ inputs.continue_on_error }} @@ -67,4 +66,6 @@ jobs: kernel-root: ${{ env.REPO_ROOT }} max-cpu: 8 kernel-test: ${{ inputs.test }} - kbuild-output: ${{ env.KBUILD_OUTPUT }} + # Here we must use kbuild-output local to the repo, because + # it was extracted from the artifacts. + kbuild-output: ${{ env.REPO_ROOT }}/kbuild-output