Splux Linux

source-based Linux using SPS

SPS · log · files · refs · tags · releases · people · languages · GitHub · commit

90cb9b1


Keep live setup on the host python so Node can configure.

Date
Commit90cb9b193c5ef655c45183b56914357372f1641a
GitHubmirror

Parents

Stat

 PACKAGE-MAINTAINER.md |  4 +++-
 bin/mkpkg             | 32 ++++++++++++++++++++++++++++++--
 tests/test_build.sh   | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 3 deletions(-)

Diff

diff --git a/PACKAGE-MAINTAINER.md b/PACKAGE-MAINTAINER.md
index 3f3f590..8495cd3 100644
--- a/PACKAGE-MAINTAINER.md
+++ b/PACKAGE-MAINTAINER.md
@@ -178,7 +178,9 @@ dies on `sharedinstall`. Host `gcc`, `python3`, `meson`, and `git` wrappers
 restore the previous `LD_LIBRARY_PATH` so those tools do not load a
 half-installed libc from the disk. Shared libraries belong in `lib64` on
 this architecture; pass `--libdir=/usr/lib64` (or Meson's `--libdir=lib64`)
-instead of relying on Autoconf's `/usr/lib` default.
+instead of relying on Autoconf's `/usr/lib` default. CPython also needs
+`--with-platlibdir=lib64` so `lib-dynload` matches `getpath`; otherwise a
+build under `SPS_ROOT` dies with `No module named '_posixsubprocess'`.
 
 ## Local files and patches
 
diff --git a/bin/mkpkg b/bin/mkpkg
index 73455ae..1bc1720 100755
--- a/bin/mkpkg
+++ b/bin/mkpkg
@@ -749,6 +749,11 @@ write_host_tool_wrapper()
 	{
 		printf '%s\n' '#!/bin/sh'
 		write_host_ld_restore
+		case ${wrapper_path##*/} in
+			python|python3)
+				printf '%s\n' 'unset PYTHONHOME PYTHONPATH'
+				;;
+		esac
 		printf 'exec %s "$@"\n' "$(shell_quote "$real_tool")"
 	} >"$wrapper_path"
 	chmod 755 "$wrapper_path"
@@ -855,10 +860,33 @@ if [ -n "${SPS_ROOT:-}" ] && [ "$SPS_ROOT" != / ]; then
 	export ACLOCAL_PATH
 
 	mkdir -p "$build_dir/run"
-	host_path=$PATH
+	# Host gcc/python must be the live disc's, not a copy just unpacked
+	# into SPS_ROOT. Node's configure imports subprocess; a relocated
+	# target python3 without platlibdir cannot find _posixsubprocess.
+	host_path=
+	host_path_rest=$PATH
+	while [ -n "$host_path_rest" ]
+	do
+		host_dir=${host_path_rest%%:*}
+		if [ "$host_path_rest" = "$host_dir" ]; then
+			host_path_rest=
+		else
+			host_path_rest=${host_path_rest#*:}
+		fi
+		[ -n "$host_dir" ] || continue
+		case $host_dir in
+			"$target_root"|"$target_root"/*) continue ;;
+		esac
+		if [ -n "$host_path" ]; then
+			host_path=$host_path:$host_dir
+		else
+			host_path=$host_dir
+		fi
+	done
 	if [ -n "$build_root" ]; then
-		host_path=$build_root/usr/bin:$build_root/bin:$PATH
+		host_path=$build_root/usr/bin:$build_root/bin${host_path:+:$host_path}
 	fi
+	[ -n "$host_path" ] || host_path=/usr/bin:/bin
 	host_cc=$(PATH=$host_path command -v gcc 2>/dev/null) || host_cc=
 	host_cxx=$(PATH=$host_path command -v g++ 2>/dev/null) || host_cxx=
 	host_cc_alt=$(PATH=$host_path command -v cc 2>/dev/null) || host_cc_alt=
diff --git a/tests/test_build.sh b/tests/test_build.sh
index 0009fe4..5e65efc 100755
--- a/tests/test_build.sh
+++ b/tests/test_build.sh
@@ -348,4 +348,42 @@ case "$(cat "$tmp/m4-extract/usr/share/target-m4-path-probe/path")" in
 	*) fail "SPS_ROOT/usr/bin was not on PATH ahead of the host" ;;
 esac
 
+# Node's configure imports subprocess through python3. The wrapper must
+# be the live interpreter, not python just installed into SPS_ROOT.
+if command -v python3 >/dev/null 2>&1; then
+	mkdir -p "$tmp/root/usr/bin" "$tmp/py-recipe" "$tmp/py-out"
+	printf '%s\n' '#!/bin/sh' 'printf TARGET\n' >"$tmp/root/usr/bin/python3"
+	chmod 755 "$tmp/root/usr/bin/python3"
+	cat >"$tmp/py-recipe/recipe" <<'EOF'
+name        host-python-wrapper-probe
+version     1.0
+release     1
+arch        any
+description Confirms PATH python3 is the live interpreter, not SPS_ROOT
+configure   command -v python3 >"$WORK/which"
+configure   python3 -c 'import os,sys; open("exe","w").write(sys.executable+"\n"); open("home","w").write((os.environ.get("PYTHONHOME") or "")+"\n")'
+install     mkdir -p "$PKG/usr/share/host-python-wrapper-probe"
+install     cp "$WORK/which" "$WORK/exe" "$WORK/home" "$PKG/usr/share/host-python-wrapper-probe/"
+install     sed -n '1,20p' "$(cat "$WORK/which")" >"$PKG/usr/share/host-python-wrapper-probe/wrap"
+EOF
+	py_artifact=$(run_mkpkg --no-download --output "$tmp/py-out" \
+		"$tmp/py-recipe/recipe") ||
+		fail "host python3 wrapper probe failed"
+	mkdir "$tmp/py-extract"
+	tar -xf "$py_artifact" -C "$tmp/py-extract"
+	py_which=$(cat "$tmp/py-extract/usr/share/host-python-wrapper-probe/which")
+	py_exe=$(cat "$tmp/py-extract/usr/share/host-python-wrapper-probe/exe")
+	py_home=$(cat "$tmp/py-extract/usr/share/host-python-wrapper-probe/home")
+	case $py_which in
+		"$tmp/root"/*) fail "python3 on PATH was the target copy ($py_which)" ;;
+	esac
+	case $py_exe in
+		"$tmp/root"/*) fail "python3 executed the target copy ($py_exe)" ;;
+	esac
+	[ -z "$py_home" ] || fail "PYTHONHOME leaked into host python3 ($py_home)"
+	grep -q 'unset PYTHONHOME PYTHONPATH' \
+		"$tmp/py-extract/usr/share/host-python-wrapper-probe/wrap" ||
+		fail "python3 wrapper must unset PYTHONHOME"
+fi
+
 printf '%s\n' 'test_build: ok'