This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3485dcb14c75a3a52f13899802c3dc74f7b62f5b
Author: dechao_gong <[email protected]>
AuthorDate: Wed Aug 26 15:24:56 2026 +0800

    arch/arm/common/ameba: fix self-referential python shim symlink loop
    
    ameba_setup_env.sh resolved the system interpreter via `command -v
    python3`.  Once a previous run put $SHIMBIN at the front of PATH, that
    lookup returned $SHIMBIN/python3 and `ln -sf shim shim` created a
    self-referential symlink, breaking every subsequent cmake reconfigure
    with "Too many levels of symbolic links".
    
    Scan PATH for the first python3 that is not inside $SHIMBIN and
    canonicalise it with readlink -f, so the shim always points at a real
    interpreter.  Idempotent across reconfigures.
    
    Assisted-by: Claude <[email protected]>
    Signed-off-by: dechao_gong <[email protected]>
---
 arch/arm/src/common/ameba/tools/ameba_setup_env.sh | 31 +++++++++++++++++-----
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/arch/arm/src/common/ameba/tools/ameba_setup_env.sh 
b/arch/arm/src/common/ameba/tools/ameba_setup_env.sh
index 12c4ad26df8..0de01cd99cf 100755
--- a/arch/arm/src/common/ameba/tools/ameba_setup_env.sh
+++ b/arch/arm/src/common/ameba/tools/ameba_setup_env.sh
@@ -71,13 +71,30 @@ resolve_bindir() {
 
   # 2. system python3 -- expose it via a non-venv shim dir so a bare `python`
   #    exists and the system site-packages (with the deps) stay visible.
-  if command -v python3 >/dev/null 2>&1 && py_has_deps python3; then
-    sp=$(command -v python3)
-    mkdir -p "$SHIMBIN"
-    ln -sf "$sp" "$SHIMBIN/python"
-    ln -sf "$sp" "$SHIMBIN/python3"
-    printf '%s\n' "$SHIMBIN"
-    return 0
+  #
+  #    Resolve the REAL system interpreter, never our own shim: a previous run
+  #    put $SHIMBIN on PATH ahead of the system python3, so `command -v 
python3`
+  #    would return $SHIMBIN/python3 and `ln -sf shim shim` would create a
+  #    self-referential symlink loop ("Too many levels of symbolic links").
+  #    Scan PATH for the first python3 that is not inside $SHIMBIN, then
+  #    canonicalise it so the shim always points at a real interpreter.
+  sp=""
+  _oldifs=$IFS
+  IFS=:
+  for _d in $PATH; do
+    case "$_d" in "$SHIMBIN" | "$SHIMBIN"/) continue ;; esac
+    if [ -x "$_d/python3" ]; then sp="$_d/python3"; break; fi
+  done
+  IFS=$_oldifs
+  if [ -n "$sp" ]; then
+    sp=$(readlink -f "$sp" 2>/dev/null || printf '%s' "$sp")
+    if py_has_deps "$sp"; then
+      mkdir -p "$SHIMBIN"
+      ln -sf "$sp" "$SHIMBIN/python"
+      ln -sf "$sp" "$SHIMBIN/python3"
+      printf '%s\n' "$SHIMBIN"
+      return 0
+    fi
   fi
 
   return 1

Reply via email to