Skip to content

Commit

Permalink
Allow for an arbitrary location of $KBUILD_OUTPUT in tar-artifacts.sh
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
theihor committed Sep 17, 2024
1 parent 33aca10 commit 545e6fe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
66 changes: 44 additions & 22 deletions .github/scripts/tar-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -39,6 +48,28 @@ 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}")
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
Expand All @@ -52,26 +83,17 @@ 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 - \
"${local_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}"
5 changes: 3 additions & 2 deletions .github/workflows/kernel-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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

0 comments on commit 545e6fe

Please sign in to comment.