10000 [3.14] GH-131769: fix detecting a pydebug build of the build Python w… · python/cpython@8f4bf15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f4bf15

Browse files
authored
[3.14] GH-131769: fix detecting a pydebug build of the build Python when building for WASI (GH-133219)
1 parent 15e26ee commit 8f4bf15

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix detecting when the build Python in a cross-build is a pydebug build.

Tools/wasm/wasi.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def call(command, *, quiet, **kwargs):
111111

112112
def build_platform():
113113
"""The name of the build/host platform."""
114-
# Can also be found via `config.guess`.`
114+
# Can also be found via `config.guess`.
115115
return sysconfig.get_config_var("BUILD_GNU_TYPE")
116116

117117

@@ -127,6 +127,15 @@ def build_python_path():
127127
return binary
128128

129129

130+
def build_python_is_pydebug():
131+
"""Find out if the build Python is a pydebug build."""
132+
test = "import sys, test.support; sys.exit(test.support.Py_DEBUG)"
133+
result = subprocess.run([build_python_path(), "-c", test],
134+
stdout=subprocess.PIPE,
135+
stderr=subprocess.PIPE)
136+
return bool(result.returncode)
137+
138+
130139
@subdir(BUILD_DIR, clean_ok=True)
131140
def configure_build_python(context, working_dir):
132141
"""Configure the build/host Python."""
@@ -213,18 +222,15 @@ def configure_wasi_python(context, working_dir):
213222
lib_dirs = list(python_build_dir.glob("lib.*"))
214223
assert len(lib_dirs) == 1, f"Expected a single lib.* directory in {python_build_dir}"
215224
lib_dir = os.fsdecode(lib_dirs[0])
216-
pydebug = lib_dir.endswith("-pydebug")
217-
python_version = lib_dir.removesuffix("-pydebug").rpartition("-")[-1]
218-
sysconfig_data = f"{wasi_build_dir}/build/lib.wasi-wasm32-{python_version}"
219-
if pydebug:
220-
sysconfig_data += "-pydebug"
225+
python_version = lib_dir.rpartition("-")[-1]
226+
sysconfig_data_dir = f"{wasi_build_dir}/build/lib.wasi-wasm32-{python_version}"
221227

222228
# Use PYTHONPATH to include sysconfig data which must be anchored to the
223229
# WASI guest's `/` directory.
224230
args = {"GUEST_DIR": "/",
225231
"HOST_DIR": CHECKOUT,
226232
"ENV_VAR_NAME": "PYTHONPATH",
227-
"ENV_VAR_VALUE": f"/{sysconfig_data}",
233+
"ENV_VAR_VALUE": f"/{sysconfig_data_dir}",
228234
"PYTHON_WASM": working_dir / "python.wasm"}
229235
# Check dynamically for wasmtime in case it was specified manually via
230236
# `--host-runner`.
@@ -244,7 +250,7 @@ def configure_wasi_python(context, working_dir):
244250
f"--host={context.host_triple}",
245251
f"--build={build_platform()}",
246252
f"--with-build-python={build_python}"]
247-
if pydebug:
253+
if build_python_is_pydebug():
248254
configure.append("--with-pydebug")
249255
if context.args:
250256
configure.extend(context.args)

0 commit comments

Comments
 (0)
0