Harden GRUB recipe with error guards and host-tool verification
Add || exit 1 to all critical build steps (mkdir, cd, touch, configure, make, grub-mkimage) so failures surface immediately instead of silently continuing. Verify gcc/make/bison/flex are present before starting the build. Update grub.cfg help text to reference fat_tool.py instead of unavailable mtools.
This commit is contained in:
@@ -26,12 +26,20 @@ script = """
|
||||
unset CC CXX CPP LD AR NM RANLIB OBJCOPY STRIP PKG_CONFIG
|
||||
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
|
||||
|
||||
# Verify host tools are available before starting the build.
|
||||
for tool in gcc make bison flex; do
|
||||
if ! command -v "${tool}" &>/dev/null; then
|
||||
echo "ERROR: Required host tool '${tool}' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Out-of-tree build (GRUB requires this for some configurations)
|
||||
mkdir -p "${COOKBOOK_BUILD}/grub-build"
|
||||
cd "${COOKBOOK_BUILD}/grub-build"
|
||||
mkdir -p "${COOKBOOK_BUILD}/grub-build" || exit 1
|
||||
cd "${COOKBOOK_BUILD}/grub-build" || exit 1
|
||||
|
||||
# GRUB release tarballs miss extra_deps.lst (normally generated by autogen.sh)
|
||||
touch "${COOKBOOK_SOURCE}/grub-core/extra_deps.lst"
|
||||
touch "${COOKBOOK_SOURCE}/grub-core/extra_deps.lst" || exit 1
|
||||
|
||||
# Configure for host, targeting x86_64 EFI platform output.
|
||||
# --target=x86_64 means "produce boot images for x86_64"
|
||||
@@ -48,10 +56,10 @@ echo "Configuring GRUB for x86_64 EFI..."
|
||||
--disable-grub-mount \
|
||||
--disable-device-mapper \
|
||||
--disable-libzfs \
|
||||
--prefix="${COOKBOOK_STAGE}/usr"
|
||||
--prefix="${COOKBOOK_STAGE}/usr" || exit 1
|
||||
|
||||
echo "Building GRUB..."
|
||||
make -j "${COOKBOOK_MAKE_JOBS}"
|
||||
make -j "${COOKBOOK_MAKE_JOBS}" || exit 1
|
||||
|
||||
# Create output directory
|
||||
mkdir -p "${COOKBOOK_STAGE}/usr/lib/boot"
|
||||
@@ -101,7 +109,7 @@ echo "Creating standalone GRUB EFI image..."
|
||||
ls \
|
||||
cat \
|
||||
halt \
|
||||
reboot
|
||||
reboot || exit 1
|
||||
|
||||
# Verify output
|
||||
if [ ! -f "${COOKBOOK_STAGE}/usr/lib/boot/grub.efi" ]; then
|
||||
|
||||
Reference in New Issue
Block a user