skosukhin created this revision.
skosukhin added a reviewer: lawrence_danna.
Herald added a project: All.
skosukhin requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

It looks like f07ddbc6 
<https://reviews.llvm.org/rGf07ddbc620a0466ebbb41ccbc78f20a8591bed5a> broke the 
building when `sys.executable` is not a symlink itself but resides in a prefix 
that is one:

  $ readlink /sw
  /opt/zmaw/sw
  $ /sw/python-3.9.12/bin/python3.9 ./get-python-config.py 
LLDB_PYTHON_EXE_RELATIVE_PATH
  Could not find a relative path to sys.executable under sys.prefix
  tried: /sw/python-3.9.12/bin/python3.9
  realpath(sys.prefix): /opt/zmaw/sw/python-3.9.12
  sys.prefix: /sw/python-3.9.12

I think it makes sense to try `sys.prefix` and `sys.executable` first and only 
then try to resolve the real paths for **both** `sys.prefix` and 
`os.path.dirname(sys.executable)`.
I would remove the `elif os.path.islink(exe):` logic as it seems to be 
redundant but I cannot tell for sure that it is.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133513

Files:
  lldb/bindings/python/get-python-config.py


Index: lldb/bindings/python/get-python-config.py
===================================================================
--- lldb/bindings/python/get-python-config.py
+++ lldb/bindings/python/get-python-config.py
@@ -44,15 +44,21 @@
     elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
         tried = list()
         exe = sys.executable
-        prefix = os.path.realpath(sys.prefix)
+        prefix = sys.prefix
         while True:
             try:
                 print(relpath_nodots(exe, prefix))
                 break
             except ValueError:
                 tried.append(exe)
-                if os.path.islink(exe):
-                    exe = os.path.join(os.path.realpath(os.path.dirname(exe)), 
os.readlink(exe))
+                real_exe_dirname = os.path.realpath(os.path.dirname(exe))
+                real_prefix = os.path.realpath(prefix)
+                if prefix != real_prefix:
+                    prefix = real_prefix
+                    exe = os.path.join(real_exe_dirname, os.path.basename(exe))
+                    continue
+                elif os.path.islink(exe):
+                    exe = os.path.join(real_exe_dirname, os.readlink(exe))
                     continue
                 else:
                     print("Could not find a relative path to sys.executable 
under sys.prefix", file=sys.stderr)


Index: lldb/bindings/python/get-python-config.py
===================================================================
--- lldb/bindings/python/get-python-config.py
+++ lldb/bindings/python/get-python-config.py
@@ -44,15 +44,21 @@
     elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
         tried = list()
         exe = sys.executable
-        prefix = os.path.realpath(sys.prefix)
+        prefix = sys.prefix
         while True:
             try:
                 print(relpath_nodots(exe, prefix))
                 break
             except ValueError:
                 tried.append(exe)
-                if os.path.islink(exe):
-                    exe = os.path.join(os.path.realpath(os.path.dirname(exe)), os.readlink(exe))
+                real_exe_dirname = os.path.realpath(os.path.dirname(exe))
+                real_prefix = os.path.realpath(prefix)
+                if prefix != real_prefix:
+                    prefix = real_prefix
+                    exe = os.path.join(real_exe_dirname, os.path.basename(exe))
+                    continue
+                elif os.path.islink(exe):
+                    exe = os.path.join(real_exe_dirname, os.readlink(exe))
                     continue
                 else:
                     print("Could not find a relative path to sys.executable under sys.prefix", file=sys.stderr)
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to