9 def relpath_nodots(path
, base
):
10 rel
= os
.path
.normpath(os
.path
.relpath(path
, base
))
11 assert not os
.path
.isabs(rel
)
12 parts
= rel
.split(os
.path
.sep
)
13 if parts
and parts
[0] == "..":
14 raise ValueError(f
"{path} is not under {base}")
19 parser
= argparse
.ArgumentParser(description
="extract cmake variables from python")
20 parser
.add_argument("variable_name")
21 args
= parser
.parse_args()
22 if args
.variable_name
== "LLDB_PYTHON_RELATIVE_PATH":
23 # LLDB_PYTHON_RELATIVE_PATH is the relative path from lldb's prefix
24 # to where lldb's python libraries will be installed.
26 # The way we're going to compute this is to take the relative path from
27 # PYTHON'S prefix to where python libraries are supposed to be
30 # The result is if LLDB and python are give the same prefix, then
31 # lldb's python lib will be put in the correct place for python to find it.
32 # If not, you'll have to use lldb -P or lldb -print-script-interpreter-info
33 # to figure out where it is.
35 print(relpath_nodots(sysconfig
.get_path("platlib"), sys
.prefix
))
37 # Try to fall back to something reasonable if sysconfig's platlib
38 # is outside of sys.prefix
39 if os
.name
== "posix":
40 print("lib/python%d.%d/site-packages" % sys
.version_info
[:2])
42 print("Lib\\site-packages")
45 elif args
.variable_name
== "LLDB_PYTHON_EXE_RELATIVE_PATH":
48 prefix
= os
.path
.realpath(sys
.prefix
)
51 print(relpath_nodots(exe
, prefix
))
55 # Retry if the executable is symlinked or similar.
56 # This is roughly equal to os.path.islink, except it also works for junctions on Windows.
57 if os
.path
.realpath(exe
) != exe
:
58 exe
= os
.path
.realpath(exe
)
62 "Could not find a relative path to sys.executable under sys.prefix",
66 print("tried:", e
, file=sys
.stderr
)
67 print("realpath(sys.prefix):", prefix
, file=sys
.stderr
)
68 print("sys.prefix:", sys
.prefix
, file=sys
.stderr
)
70 elif args
.variable_name
== "LLDB_PYTHON_EXT_SUFFIX":
71 print(sysconfig
.get_config_var("EXT_SUFFIX"))
73 parser
.error(f
"unknown variable {args.variable_name}")
76 if __name__
== "__main__":