Skip to content

Commit 4146be0

Browse files
kalyazinclaude
andcommitted
refactor: reset kernel source to tag between build iterations
Four folded changes, all aimed at making the build loop safe to run when source files have been mutated by a previous iteration and producing clear errors when tag resolution fails: * Replace `git checkout <tag>` with `git reset --hard <tag>` followed by `git clean -fdx` (extracting the tag into a local variable). * Bail with a clear error if `get_tag` finds no matching tag, so the build doesn't fall through to `git reset --hard ""`. * Move the config copy to after the reset so it isn't clobbered by `git clean`. * Drop the now-redundant `make distclean || true` at the top of the script — `git clean -fdx` inside `build_version` strictly subsumes it. Behavior is identical for the no-patches case (the tag tree is unchanged so reset is a no-op). Prep work for applying out-of-tree patches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Nikita Kalyazin <nikita.kalyazin@e2b.dev>
1 parent f371098 commit 4146be0

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

build.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,20 @@ function build_version {
4545
local version=$1
4646
echo "Starting build for kernel version: $version (${TARGET_ARCH})"
4747

48+
local tag
49+
tag="$(get_tag "$version")"
50+
if [ -z "$tag" ]; then
51+
echo "ERROR: no Amazon Linux kernel tag matches version '$version'" \
52+
"(looked for microvm-kernel-${version}-*.amzn2 or kernel-${version}-*.amzn2)" >&2
53+
exit 1
54+
fi
55+
echo "Resetting kernel source to tag: $tag"
56+
git reset --hard "$tag"
57+
git clean -fdx
58+
4859
# Configs live in configs/{arch}/
4960
cp ../configs/"${TARGET_ARCH}/${version}.config" .config
5061

51-
echo "Checking out repo for kernel at version: $version"
52-
git checkout "$(get_tag "$version")"
53-
5462
# Set up cross-compilation if building arm64 on x86_64
5563
local make_opts=""
5664
if [[ "$TARGET_ARCH" == "arm64" ]]; then
@@ -92,8 +100,6 @@ install_dependencies
92100
[ -d linux ] || git clone --no-checkout --filter=tree:0 https://github.com/amazonlinux/linux
93101
pushd linux
94102

95-
make distclean || true
96-
97103
grep -v '^ *#' <../kernel_versions.txt | while IFS= read -r version; do
98104
build_version "$version"
99105
done

0 commit comments

Comments
 (0)