Skip to content

Commit

Permalink
scripts/bootstrap-prefix: fix endless loop with Gentoo bootstrap
Browse files Browse the repository at this point in the history
When we try to use turbo-boost bootstrap, we end up in an endless loop.
Reason is the code that was added to ensure individual stage calls would
have a properly inited environment.  However that contained not just a
bug, but also would cause stage_host_gentoo to be called over and over
again.

Now just exit from bootstrap_interactive once we set all the vars we
need.  Ensure we don't run any bootstrapping code before that point.

Thanks Leonardo Hernández Hernández for pointing this out.

Closes: https://bugs.gentoo.org/914261
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
  • Loading branch information
grobian committed Sep 16, 2023
1 parent ac4c67f commit d2ade9a
Showing 1 changed file with 29 additions and 39 deletions.
68 changes: 29 additions & 39 deletions scripts/bootstrap-prefix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2811,8 +2811,7 @@ EOF
done
export PATH="$EPREFIX/usr/bin:$EPREFIX/bin:$EPREFIX/tmp/usr/bin:$EPREFIX/tmp/bin:$EPREFIX/tmp/usr/local/bin:${PATH}"

if [[ -z ${PARTIAL_BOOTSTRAP} ]]; then
cat << EOF
cat << EOF
OK! I'm going to give it a try, this is what I have collected sofar:
EPREFIX=${EPREFIX}
Expand All @@ -2826,15 +2825,23 @@ Prefix. In short, I'm going to run stage1, stage2, stage3, followed by
emerge -e system. If any of these stages fail, both you and me are in
deep trouble. So let's hope that doesn't happen.
EOF
echo
[[ ${TODO} == 'noninteractive' ]] && ans="" ||
read -p "Type here what you want to wish me [luck] " ans
if [[ -n ${ans} && ${ans} != "luck" ]] ; then
echo "Huh? You're not serious, are you?"
sleep 3
fi
echo
fi
echo
[[ ${TODO} == 'noninteractive' ]] && ans="" ||
read -p "Type here what you want to wish me [luck] " ans
if [[ -n ${ans} && ${ans} != "luck" ]] ; then
echo "Huh? You're not serious, are you?"
sleep 3
fi
echo

# because we unset ROOT from environment above, and we didn't set
# ROOT as argument in the script, we set ROOT here to the EPREFIX we
# just harvested
ROOT="${EPREFIX}"
set_helper_vars

# stop here if all we wanted was the env to be setup correctly
[[ -n ${SETUP_ENV_ONLY} ]] && return 0

if [[ -d ${HOST_GENTOO_EROOT} ]]; then
if ! [[ -x ${EPREFIX}/tmp/usr/lib/portage/bin/emerge ]] && ! ${BASH} ${BASH_SOURCE[0]} "${EPREFIX}" stage_host_gentoo ; then
Expand All @@ -2855,25 +2862,6 @@ EOF
fi
fi

# because we unset ROOT from environment above, and we didn't set
# ROOT as argument in the script, we set ROOT here to the EPREFIX we
# just harvested
ROOT="${EPREFIX}"
set_helper_vars

if [[ -n ${PARTIAL_BOOTSTRAP} ]]; then
cat << EOF
OK! All necessary tools and ENV variables were installed:
EPREFIX=${EPREFIX}
CHOST=${CHOST}
PATH=${PATH}
MAKEOPTS=${MAKEOPTS}
Now I'm going to run an <action> you asked me to.
EOF
return 0;
fi

if ! [[ -e ${EPREFIX}/.stage1-finished ]] && ! bootstrap_stage1_log ; then
# stage 1 fail
cat << EOF
Expand Down Expand Up @@ -3308,17 +3296,19 @@ fi

einfo "ready to bootstrap ${TODO}"

# part of bootstrap_interactive should be executed before any bootstrap_${TODO}
# to properly setup environment variables and guarantee that bootstrap_${TODO}
# executes inside a prefix
if [[ ${TODO} != "noninteractive" && $(type -t bootstrap_${TODO} == "function") ]]; then
PARTIAL_BOOTSTRAP=true
TODO='noninteractive' bootstrap_interactive || exit 1
bootstrap_${TODO} || exit 1
exit 0
# When we call individual stages separately (e.g. not from
# bootstrap_interactive) we might need some env to be setup in order to
# function properly. Basically do a non-interactive call for each stage
# that will only set whatever needs to be set.
if [[ ${TODO} != "interactive" && ${TODO} != "noninteractive" ]] ; then
# squelch the output, we've seen it already when running from
# interactive proper
SETUP_ENV_ONLY=true TODO=noninteractive \
bootstrap_interactive > /dev/null || exit 1
fi

# bootstrap_interactive proceeds with guessed defaults when TODO=noninteractive
# call the appropriate function,
# beware noninteractive is just a mode of interactive
bootstrap_${TODO#non} || exit 1

# Local Variables:
Expand Down

0 comments on commit d2ade9a

Please sign in to comment.