Skip to content

Commit

Permalink
Don't use repo snapshots for stage1 by updating seed the new way
Browse files Browse the repository at this point in the history
This is what upstream Gentoo does. They would previously update the
entire seed, but this took a long time. Our seeds are much bigger, so we
kept repo snapshots to build stage1 against these instead. The new
method of only rebuilding packages with changed sub-slots is a good
compromise and removes the need to write stage1 hooks that selectively
catch the repository up.

This also avoids some conflicts by adding the `--ignore-world` option.
Gentoo seeds have nothing in @world. We have much more, but none of that
is needed for stage1.

This continues to exclude cross-*-cros-linux-gnu/* as that is not needed
for stage1. It now also excludes dev-lang/rust, because it is never a
DEPEND, so it would not break other packages in this way. It may fail to
run due to a sub-slot change in one of its own dependencies, but it is
also unlikely to be needed in stage1 and it is not configured to use the
system LLVM. If needs be, we could improve the behaviour of Portage's
@changed-subslot to respect `--with-bdeps`.

In my testing, it was unable to handle an SDK from 17 months ago, but
one from 7 months ago did work. In practise, we will always use a much
more recent one, which is far more likely to work.

Signed-off-by: James Le Cuirot <[email protected]>
  • Loading branch information
chewi committed Jul 11, 2024
1 parent 7c18802 commit da41dfe
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 248 deletions.
90 changes: 0 additions & 90 deletions bootstrap_sdk
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ TYPE="flatcar-sdk"
. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1


DEFINE_string stage1_portage_path "" \
"Path to custom portage ebuilds tree to use in stage 1 (DANGEROUS; USE WITH CAUTION)"
DEFINE_string stage1_overlay_path "" \
"Path to custom overlay ebuilds tree to use in stage 1 (DANGEROUS; USE WITH CAUTION)"


## Define the stage4 config template
catalyst_stage4() {
cat <<EOF
Expand Down Expand Up @@ -142,90 +136,6 @@ cp "${BUILD_LIBRARY_DIR}/toolchain_util.sh" "${ROOT_OVERLAY}/tmp"
# by stage one. Therefore, these binaries will cease to work in stage 2 when linked against
# outdated "seed tarball" libraries which have been updated to newer versions in stage 1.

stage_repo() {
local repo=${1}
local path=${2}
local dest=${3}
local update_seed_file=${4}

mkdir "$dest/$repo"

if [ -z "$path" ]; then
case "$repo" in
portage-stable) path=gentoo ;;
*) path=${repo} ;;
esac
cp -R --reflink=auto "/var/gentoo/repos/${path}/"* "$dest/${repo}/"
info "Using local SDK's ebuild repo '$repo' in stage 1."
else
cp -R --reflink=auto "${path}/"* "$dest/${repo}/"
info "Using custom path '$path' for ebuild repo '$repo' in stage 1."
info "This may break stage 2. YOU HAVE BEEN WARNED. You break it, you keep it."
fi
(
set -euo pipefail
local repo_var hook name

# FLAGS_coreos_overlay for coreos-overlay
repo_var="FLAGS_${repo//-/_}"
shopt -s nullglob
for hook in "${FLAGS_coreos_overlay}/coreos/stage1_hooks/"*"-${repo}.sh"; do
name=${hook##*/}
name=${name%"-${repo}.sh"}
info "Invoking stage1 ${repo} hook ${name} on ${dest}/${repo}"
"${hook}" "${dest}/${repo}" "${!repo_var}" "${update_seed_file}"
done
)
}

build_stage1() {
# First, write out the default catalyst configuration files
write_configs

# Prepare local copies of both the "known-good" portage-stable and the
# "known-good" coreos-overlay ebuild repos
local stage1_repos="$TEMPDIR/stage1-ebuild-repos"
info "Creating stage 1 ebuild repos and stage 1 snapshot in '$stage1_repos'"
rm -rf "$stage1_repos"
mkdir "$stage1_repos"

# If the file exists and is not empty, seed will be updated.
# Stage1 hooks may decide that the seed SDK needs updating.
local update_seed_file="${TEMPDIR}/update_seed"

# prepare ebuild repos for stage 1, either from the local SDK (default)
# or from custom paths specified via command line flags
stage_repo "portage-stable" "${FLAGS_stage1_portage_path}" "$stage1_repos" "${update_seed_file}"
stage_repo "coreos-overlay" "${FLAGS_stage1_overlay_path}" "$stage1_repos" "${update_seed_file}"

# take the "portage directory" (portage-stable copy) snapshot
build_snapshot "$stage1_repos/portage-stable" "${FLAGS_version}-stage1"

# Update the stage 1 spec to use the "known-good" portage-stable snapshot
# and coreos-overlay copy repository versions from above.
sed -i -e "s/^snapshot_treeish:.*/snapshot_treeish: $FLAGS_version-stage1/" \
-e "s,^repos:.*,repos: $stage1_repos/coreos-overlay," \
"$TEMPDIR/stage1.spec"

# If we are to use a custom path for either ebuild repo we want to update the stage1 seed SDK
if [[ -n ${FLAGS_stage1_portage_path} ]] || [[ -n ${FLAGS_stage1_overlay_path} ]] || [[ -s ${update_seed_file} ]]; then
sed -i 's/^update_seed: no/update_seed: yes/' "$TEMPDIR/stage1.spec"
echo "update_seed_command: --update --deep --newuse --complete-graph --rebuild-if-new-ver --rebuild-exclude cross-*-cros-linux-gnu/* sys-devel/gcc " \
>>"$TEMPDIR/stage1.spec"
fi

rm -f "${update_seed_file}"

# Finally, build stage 1
build_stage stage1
}

if [[ "$STAGES" =~ stage1 ]]; then
build_stage1
STAGES="${STAGES/stage1/}"
SEED="${TYPE}/stage1-${ARCH}-latest"
fi

catalyst_build

if [[ "$STAGES" =~ stage4 ]]; then
Expand Down
3 changes: 1 addition & 2 deletions build_library/build_image_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ get_metadata() {
local mirror="$(echo "${v}" | grep mirror:// | cut -d '/' -f 3)"
if [ -n "${mirror}" ]; then
# Take only first mirror, those not working should be removed
local location="$(grep "^${mirror}"$'\t' /var/gentoo/repos/gentoo/profiles/thirdpartymirrors | cut -d $'\t' -f 2- | cut -d ' ' -f 1 | tr -d $'\t')"
local location="$(grep "^${mirror}"$'\t' /mnt/host/source/src/third_party/portage-stable/profiles/thirdpartymirrors | cut -d $'\t' -f 2- | cut -d ' ' -f 1 | tr -d $'\t')"
v="$(echo "${v}" | sed "s#mirror://${mirror}/#${location}#g")"
fi
new_val+="${v} "
Expand Down Expand Up @@ -491,7 +491,6 @@ EOF
local license_dirs=(
"/mnt/host/source/src/third_party/coreos-overlay/licenses/"
"/mnt/host/source/src/third_party/portage-stable/"
"/var/gentoo/repos/gentoo/licenses/"
"none"
)
for license_file in ${license_list}; do
Expand Down
5 changes: 3 additions & 2 deletions build_library/catalyst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ catalyst_stage1() {
cat <<EOF
# stage1 packages aren't published, save in tmp
pkgcache_path: ${TEMPDIR}/stage1-${ARCH}-packages
update_seed: no
update_seed: yes
update_seed_command: --exclude cross-*-cros-linux-gnu/* --exclude dev-lang/rust --ignore-world y --ignore-built-slot-operator-deps y @changed-subslot
EOF
catalyst_stage_default 1
}
Expand Down Expand Up @@ -225,7 +226,7 @@ write_configs() {
info "Configuring Portage..."
cp -r "${BUILD_LIBRARY_DIR}"/portage/ "${TEMPDIR}/"

ln -sfT '/var/gentoo/repos/coreos-overlay/coreos/user-patches' \
ln -sfT '/mnt/host/source/src/third_party/coreos-overlay/coreos/user-patches' \
"${TEMPDIR}"/portage/patches
}

Expand Down
9 changes: 0 additions & 9 deletions build_library/catalyst_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,3 @@ for cross_chost in $(get_chost_list); do
PKGDIR="$(portageq envvar PKGDIR)/crossdev" \
install_cross_rust "${cross_chost}" ${clst_myemergeopts}
done

echo "Saving snapshot of repos for future SDK bootstraps"
# Copy portage-stable and coreos-overlay, which are under
# /mnt/host/source/src/third_party, into a local directory because they are
# removed before archiving and we want to keep snapshots. These snapshots are
# used by stage 1 in future bootstraps.
mkdir -p /var/gentoo/repos/{gentoo,coreos-overlay}
cp -R /mnt/host/source/src/third_party/portage-stable/* /var/gentoo/repos/gentoo/
cp -R /mnt/host/source/src/third_party/coreos-overlay/* /var/gentoo/repos/coreos-overlay/

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit da41dfe

Please sign in to comment.