build_library/catalyst.sh: Fix and extend snapshot handling

- Fix the snapshot name, it is not "portage-${VERSION}", but rather
  "gentoo-${VERSION}".

- After building the snapshot, remove all the similar files from the
  snapshots directory - Catalyst gets easily confused by them and
  bails out.

- Extend the `build_snapshot` function to optionally accept the config
  path and the snapshot name, so SDK's stage1 code can use this
  function instead of duplicating parts of it.
This commit is contained in:
Krzesimir Nowak 2023-05-24 13:51:25 +02:00
parent 120a746c88
commit 60aded12f5
2 changed files with 35 additions and 11 deletions

View File

@ -201,11 +201,7 @@ build_stage1() {
sed -i "s:^portdir.*:portdir=\"$stage1_repos/gentoo\":" \ sed -i "s:^portdir.*:portdir=\"$stage1_repos/gentoo\":" \
"$TEMPDIR/catalyst-stage1.conf" "$TEMPDIR/catalyst-stage1.conf"
# take the "portage directory" (portage-stable copy) snapshot # take the "portage directory" (portage-stable copy) snapshot
catalyst \ build_snapshot "${TEMPDIR}/catalyst-stage1.conf" "${FLAGS_version}-stage1"
"${DEBUG[@]}" \
--verbose \
--config "$TEMPDIR/catalyst-stage1.conf" \
--snapshot "$FLAGS_version-stage1"
# Update the stage 1 spec to use the "known-good" portage-stable snapshot # Update the stage 1 spec to use the "known-good" portage-stable snapshot
# and coreos-overlay copy repository versions from above. # and coreos-overlay copy repository versions from above.

View File

@ -272,7 +272,7 @@ build_stage() {
--config "$TEMPDIR/catalyst.conf" \ --config "$TEMPDIR/catalyst.conf" \
--file "$TEMPDIR/${stage}.spec" \ --file "$TEMPDIR/${stage}.spec" \
--cli "source_subpath=$srcpath" --cli "source_subpath=$srcpath"
# Catalyst doesn't clean up after itself... # Catalyst does not clean up after itself...
rm -rf "$TEMPDIR/$stage-${ARCH}-${FLAGS_version}" rm -rf "$TEMPDIR/$stage-${ARCH}-${FLAGS_version}"
ln -sf "$stage-${ARCH}-${FLAGS_version}.tar.bz2" \ ln -sf "$stage-${ARCH}-${FLAGS_version}.tar.bz2" \
"$BUILDS/$stage-${ARCH}-latest.tar.bz2" "$BUILDS/$stage-${ARCH}-latest.tar.bz2"
@ -280,8 +280,13 @@ build_stage() {
} }
build_snapshot() { build_snapshot() {
local snapshot="portage-${FLAGS_version}.tar.bz2" local catalyst_conf snapshot snapshots_dir snapshot_base snapshot_path
local snapshot_path="$CATALYST_ROOT/snapshots/${snapshot}"
catalyst_conf=${1:-"${TEMPDIR}/catalyst.conf"}
snapshot=${2:-"${FLAGS_version}"}
snapshots_dir="${CATALYST_ROOT}/snapshots"
snapshot_base="${snapshots_dir}/gentoo-${snapshot}"
snapshot_path="${snapshot_base}.tar.bz2"
if [[ -f "${snapshot_path}" && $FLAGS_rebuild == $FLAGS_FALSE ]] if [[ -f "${snapshot_path}" && $FLAGS_rebuild == $FLAGS_FALSE ]]
then then
info "Skipping snapshot, ${snapshot_path} exists" info "Skipping snapshot, ${snapshot_path} exists"
@ -290,8 +295,31 @@ build_snapshot() {
catalyst \ catalyst \
"${DEBUG[@]}" \ "${DEBUG[@]}" \
--verbose \ --verbose \
--config "$TEMPDIR/catalyst.conf" \ --config "${catalyst_conf}" \
--snapshot "$FLAGS_version" --snapshot "${snapshot}"
fi
local f
local to_remove=()
# This will expand to at least our just built snapshot tarball, so
# no nullglob is needed here.
for f in "${snapshot_base}".*; do
case "${f}" in
"${snapshot_path}")
# Our snapshot, keep it as is.
:
;;
*.CONTENTS|*.CONTENTS.gz|*.DIGESTS)
# These can stay, catalyst is not bothered by those.
:
;;
*)
to_remove+=("${f}")
;;
esac
done
if [[ ${#to_remove[@]} -gt 0 ]]; then
info "$(printf '%s\n' 'Found spurious files in snapshots directory that may confuse Catalyst, removing them:' "${to_remove[@]}")"
rm -rf "${to_remove[@]}"
fi fi
} }
@ -336,5 +364,5 @@ catalyst_build() {
fi fi
# Cleanup snapshots, we don't use them # Cleanup snapshots, we don't use them
rm -rf "$CATALYST_ROOT/snapshots/portage-${FLAGS_version}.tar.bz2"* rm -rf "$CATALYST_ROOT/snapshots/gentoo-${FLAGS_version}.tar.bz2"*
} }