From 34bba21afd8be681c1bd1d88d8dc349c79aca9f7 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Fri, 7 Aug 2015 13:08:19 -0700 Subject: [PATCH] coreos-kernel: make build ccache friendly across versions The absolute path to the source tree includes the kernel's version number and that path then lands in the kernel source code via the numerous __FILE__ macros in the kernel source. So if the kernel source version changes, even with a minor revision only, the entire cache can be invalidated. Reshuffle the build tree so that $S is a directory of symlinks to the source and a nested build directory, ensuring the entire build can use relative paths. A directory of symlinks instead of a single directory symlink is required to prevent make from resolving the source directory path to the original versioned path. --- .../eclass/coreos-kernel.eclass | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-kernel.eclass b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-kernel.eclass index 161424080f..b8ff160c9d 100644 --- a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-kernel.eclass +++ b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-kernel.eclass @@ -62,7 +62,7 @@ find_defconfig() { # As if using cpio isn't bad enough already. # If lib doesn't exist or isn't a symlink then nothing is returned. get_bootengine_lib() { - cpio -itv --quiet < bootengine.cpio | \ + cpio -itv --quiet < build/bootengine.cpio | \ awk '$1 ~ /^l/ && $9 == "lib" { print $11 }' assert } @@ -80,7 +80,7 @@ update_bootengine_cpio() { # squash file ownership to root for new files. --owner=root:root # append to our local copy of bootengine - -F "${S}/bootengine.cpio" + -F "${S}/build/bootengine.cpio" ) echo "Updating bootengine.cpio" @@ -93,10 +93,10 @@ kmake() { if gcc-specs-pie; then kernel_cflags="-nopie -fstack-check=no" fi - emake -C "${KERNEL_DIR}" \ + emake \ ARCH="${kernel_arch}" \ CROSS_COMPILE="${CHOST}-" \ - KBUILD_OUTPUT="${S}" \ + KBUILD_OUTPUT="build" \ KCFLAGS="${kernel_cflags}" \ LDFLAGS="" \ "$@" @@ -111,7 +111,8 @@ shred_keys() { } coreos-kernel_src_unpack() { - mkdir "${S}" || die + mkdir -p "${S}/build" || die + ln -s "${KERNEL_DIR}"/* "${S}/" || die } coreos-kernel_src_prepare() { @@ -120,25 +121,26 @@ coreos-kernel_src_prepare() { die "Source is not clean! Run make mrproper in ${KERNEL_DIR}" fi - restore_config .config - if [[ ! -f .config ]]; then + restore_config build/.config + if [[ ! -f build/.config ]]; then local config="$(find_defconfig)" elog "Building using default config ${config}" - cp "${config}" .config || die + cp "${config}" build/.config || die fi # copy the cpio initrd to the output build directory so we can tack it # onto the kernel image itself. - cp "${ROOT}"/usr/share/bootengine/bootengine.cpio bootengine.cpio || die + cp "${ROOT}"/usr/share/bootengine/bootengine.cpio build/bootengine.cpio \ + || die "cp bootengine.cpio failed, try emerge-\$BOARD bootengine" } coreos-kernel_src_configure() { if ! use audit; then - sed -i -e '/^CONFIG_CMDLINE=/s/"$/ audit=0"/' .config || die + sed -i -e '/^CONFIG_CMDLINE=/s/"$/ audit=0"/' build/.config || die fi if ! use selinux; then - sed -i -e '/CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE/d' .config || die - echo CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=0 >> .config || die + sed -i -e '/CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE/d' build/.config || die + echo CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=0 >> build/.config || die fi # Use default for any options not explitly set in defconfig @@ -197,22 +199,9 @@ coreos-kernel_src_install() { dosym "../../../../boot/config-${version}" \ "/usr/lib/modules/${version}/build/.config" - save_config defconfig + save_config build/defconfig shred_keys } -# TODO(marineam): remove this function once KBUILD_OUTPUT is removed -# from src/scripts/setup_board -coreos-kernel_pkg_postinst() { - [[ -n "${KBUILD_OUTPUT}" ]] || return 0 - # linux-info always expects to be able to find the current .config - # so copy it into the build tree if it isn't already there. - if ! cmp --quiet "${ROOT}/usr/boot/config" "${KBUILD_OUTPUT}/.config"; then - cp "${ROOT}/usr/boot/config" "${KBUILD_OUTPUT}/.config" - chown ${PORTAGE_USERNAME:-portage}:${PORTAGE_GRPNAME:-portage} \ - "${KBUILD_OUTPUT}/.config" - fi -} - -EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install pkg_postinst +EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install