Selfhost: prefer BuildBox for emit-only (opt-in) and fix selfhost smokes root detection

- selfhost_build.sh: HAKO_USE_BUILDBOX=1 uses BuildBox.emit_program_json_v0 for emit-only paths
- Fix ROOT detection in selfhost and bridge negative smokes
- All selfhost smokes pass (opt-in)
This commit is contained in:
nyash-codex
2025-11-02 18:22:15 +09:00
parent 981555261d
commit 0eeae54434
3 changed files with 45 additions and 18 deletions

View File

@ -42,10 +42,28 @@ if [ ! -f "$IN" ]; then echo "[selfhost] input not found: $IN" >&2; exit 2; fi
tmp_json="${JSON_OUT:-/tmp/hako_stageb_$$.json}"
# StageB emit (Program JSON v0; single line)
# Emit Program(JSON v0; prefer BuildBox for emit-only when HAKO_USE_BUILDBOX=1)
RAW="/tmp/hako_stageb_raw_$$.txt"
SRC_CONTENT="$(cat "$IN")"
(
if [ "${HAKO_USE_BUILDBOX:-0}" = "1" ] && [ "$DO_RUN" = "0" ] && [ -z "$EXE_OUT" ]; then
WRAP="/tmp/hako_buildbox_wrap_$$.hako"
cat > "$WRAP" <<'HAKO'
include "lang/src/compiler/build/build_box.hako"
static box Main { method main(args) {
local src = env.get("HAKO_SRC");
local j = BuildBox.emit_program_json_v0(src, null);
print(j);
return 0;
} }
HAKO
(
export HAKO_SRC="$SRC_CONTENT"
export NYASH_QUIET=0 HAKO_QUIET=0 NYASH_CLI_VERBOSE=0
cd "$ROOT" && "$BIN" --backend vm "$WRAP"
) > "$RAW" 2>&1 || true
rm -f "$WRAP" 2>/dev/null || true
else
(
export NYASH_PARSER_ALLOW_SEMICOLON=1
export NYASH_ALLOW_USING_FILE=0
export HAKO_ALLOW_USING_FILE=0
@ -59,7 +77,8 @@ SRC_CONTENT="$(cat "$IN")"
"$BIN" --backend vm \
"$ROOT/lang/src/compiler/entry/compiler_stageb.hako" -- \
--source "$SRC_CONTENT"
) > "$RAW" 2>&1 || true
) > "$RAW" 2>&1 || true
fi
if ! awk '(/"version":0/ && /"kind":"Program"/){print;found=1;exit} END{exit(found?0:1)}' "$RAW" > "$tmp_json"; then
echo "[selfhost] StageB emit failed" >&2

View File

@ -7,7 +7,11 @@ if [ "${SMOKES_ENABLE_SELFHOST:-0}" != "1" ]; then
exit 0
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null || cd "$SCRIPT_DIR/../../../../../../.." && pwd)"
if ROOT_GIT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null); then
ROOT="$ROOT_GIT"
else
ROOT="$(cd "$SCRIPT_DIR/../../../../../../../../.." && pwd)"
fi
source "$ROOT/tools/smokes/v2/lib/test_runner.sh"
require_env || exit 2

View File

@ -7,7 +7,11 @@ if [ "${SMOKES_ENABLE_SELFHOST:-0}" != "1" ]; then
exit 0
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null || cd "$SCRIPT_DIR/../../../../../../.." && pwd)"
if ROOT_GIT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null); then
ROOT="$ROOT_GIT"
else
ROOT="$(cd "$SCRIPT_DIR/../../../../../../../../.." && pwd)"
fi
source "$ROOT/tools/smokes/v2/lib/test_runner.sh"
require_env || exit 2