forked from lei.chen/myxce
Both meson-build.sh (venv creation) and meson-install.sh (wrapper
shebang) resolved python3 independently at run time (bare `python3 -m
venv` / `command -v python3`) -- correct as long as invoked inside
nix develop/build, but nothing prevented a stray non-nix system
python3 earlier on PATH from shadowing it.
meson.build now resolves python3 once via import('python').
find_installation('python3') -- same mechanism as find_program('go')/
capnp/packcc elsewhere in this build, printed at `meson setup` time
as "Program python3 found: YES (/nix/store/...)" -- and threads that
exact resolved path into both scripts as an explicit argument instead
of a fresh lookup.
Verified: meson setup prints the pinned python3, xceadmin target
rebuilds clean (165/165 passed), and the built venv's own python3
resolves through to that exact nix store path.
44 lines
2 KiB
Bash
Executable file
44 lines
2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# meson install-time script (meson.add_install_script) -- runs after the
|
|
# xceadmin custom_target (build_by_default) has already installed+tested
|
|
# into its own build-dir venv (meson-build.sh). This script does NOT copy
|
|
# that venv wholesale: pip's generated console_scripts wrapper hardcodes
|
|
# the *build-directory* absolute path in its shebang, which stops existing
|
|
# once the build dir is cleaned up -- copying it verbatim into $out would
|
|
# ship a binary with a shebang pointing at nowhere.
|
|
#
|
|
# Instead: copy just the xceadmin/xcecommon package dirs (pure files, no
|
|
# shebang) into $out, and hand-write a wrapper whose shebang and PYTHONPATH
|
|
# are resolved against *this* install script's own environment (python3 --
|
|
# passed in as $1, meson's own resolved interpreter (import('python').
|
|
# find_installation()) from meson.build, not a fresh `command -v python3`
|
|
# lookup here -- and the nix-provided pycapnp/pyyaml/jsonschema/click
|
|
# site-packages come from nativeBuildInputs, same as every other phase of
|
|
# this derivation) -- every path baked in below is a real /nix/store path,
|
|
# so nix's reference scanner picks each one up as a proper runtime
|
|
# dependency of $out.
|
|
set -euo pipefail
|
|
|
|
PYTHON="$1"
|
|
DESTDIR_PREFIX="$MESON_INSTALL_DESTDIR_PREFIX"
|
|
|
|
VENV_SITE_GLOB=("$MESON_BUILD_ROOT"/xceadmin/.venv/lib/python3.*/site-packages)
|
|
VENV_SITE="${VENV_SITE_GLOB[0]}"
|
|
if [ ! -d "$VENV_SITE/xceadmin" ]; then
|
|
echo "meson-install.sh: expected $VENV_SITE/xceadmin from the xceadmin build step, not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
SITE_DIR="$DESTDIR_PREFIX/lib/xceadmin-site"
|
|
mkdir -p "$SITE_DIR" "$DESTDIR_PREFIX/bin"
|
|
rm -rf "$SITE_DIR/xceadmin" "$SITE_DIR/xcecommon"
|
|
cp -r "$VENV_SITE/xceadmin" "$VENV_SITE/xcecommon" "$SITE_DIR/"
|
|
|
|
cat > "$DESTDIR_PREFIX/bin/xceadmin" <<WRAPPER
|
|
#!/usr/bin/env bash
|
|
export PYTHONPATH="$SITE_DIR:${PYTHONPATH:-}"
|
|
exec "$PYTHON" -m xceadmin.cli "\$@"
|
|
WRAPPER
|
|
chmod +x "$DESTDIR_PREFIX/bin/xceadmin"
|
|
|
|
echo "=== xceadmin (meson install): wrapper installed at $DESTDIR_PREFIX/bin/xceadmin ==="
|