Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb] fix -print-script-interpreter-info on windows
Apparently "{sys.prefix}/bin/python3" isn't where you find the python interpreter on windows, so the test I wrote for -print-script-interpreter-info is failing. We can't rely on sys.executable at runtime, because that will point to lldb.exe not python.exe. We can't just record sys.executable from build time, because python could have been moved to a different location. But it should be OK to apply relative path from sys.prefix to sys.executable from build-time to the sys.prefix at runtime. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D113650
- Loading branch information
1 parent
913d78c
commit 4c2cf3a
Showing
5 changed files
with
95 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
import argparse | ||
import sysconfig | ||
import distutils.sysconfig | ||
|
||
|
||
def relpath_nodots(path, base): | ||
rel = os.path.normpath(os.path.relpath(path, base)) | ||
assert not os.path.isabs(rel) | ||
parts = rel.split(os.path.sep) | ||
if parts and parts[0] == '..': | ||
raise ValueError(f"{path} is not under {base}") | ||
return rel | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="extract cmake variables from python") | ||
parser.add_argument("variable_name") | ||
args = parser.parse_args() | ||
if args.variable_name == "LLDB_PYTHON_RELATIVE_PATH": | ||
print(distutils.sysconfig.get_python_lib(True, False, '')) | ||
elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH": | ||
tried = list() | ||
exe = sys.executable | ||
while True: | ||
try: | ||
print(relpath_nodots(exe, sys.prefix)) | ||
break | ||
except ValueError: | ||
tried.append(exe) | ||
if os.path.islink(exe): | ||
exe = os.path.join(os.path.dirname(exe), os.readlink(exe)) | ||
continue | ||
else: | ||
print("Could not find a relative path to sys.executable under sys.prefix", file=sys.stderr) | ||
for e in tried: | ||
print("tried:", e, file=sys.stderr) | ||
print("sys.prefix:", sys.prefix, file=sys.stderr) | ||
sys.exit(1) | ||
|
||
else: | ||
parser.error(f"unknown variable {args.variable_name}") | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters