commit:     d2ade9a39e38c2e62117794b46b90a7c14237ce1
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Sep 16 13:35:35 2023 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Sep 16 13:35:35 2023 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=d2ade9a3

scripts/bootstrap-prefix: fix endless loop with Gentoo bootstrap

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 <AT> gentoo.org>

 scripts/bootstrap-prefix.sh | 68 +++++++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 39 deletions(-)

diff --git a/scripts/bootstrap-prefix.sh b/scripts/bootstrap-prefix.sh
index 39ad15b6bf..21b012bf1d 100755
--- a/scripts/bootstrap-prefix.sh
+++ b/scripts/bootstrap-prefix.sh
@@ -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}
@@ -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
@@ -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
@@ -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:

Reply via email to