Build Jeannie launchers from their checkout
This commit is contained in:
parent
c452eafc3e
commit
3de82a9f6b
|
|
@ -3,6 +3,7 @@ set -euo pipefail
|
|||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
CORE_BIN="${JEANNIE_CORE_BIN:-${REPO_ROOT}/.lab/bin/jeannie-core}"
|
||||
[[ "${CORE_BIN}" == /* ]] || CORE_BIN="${PWD}/${CORE_BIN}"
|
||||
|
||||
core_sources_newer() {
|
||||
local source
|
||||
|
|
@ -21,7 +22,10 @@ if [[ ! -x "${CORE_BIN}" || "${REPO_ROOT}/go.mod" -nt "${CORE_BIN}" ]] || core_s
|
|||
exit 1
|
||||
fi
|
||||
mkdir -p "$(dirname "${CORE_BIN}")"
|
||||
GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${CORE_BIN}" "${REPO_ROOT}/cmd/jeannie-core"
|
||||
(
|
||||
cd "${REPO_ROOT}"
|
||||
GOWORK=off GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${CORE_BIN}" ./cmd/jeannie-core
|
||||
)
|
||||
fi
|
||||
|
||||
exec "${CORE_BIN}" "$@"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
set -euo pipefail
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
SERVER_BIN="${JEANNIE_SERVER_BIN:-${REPO_ROOT}/.lab/bin/jeannie-server}"
|
||||
[[ "${SERVER_BIN}" == /* ]] || SERVER_BIN="${PWD}/${SERVER_BIN}"
|
||||
server_sources_newer() {
|
||||
local source
|
||||
while IFS= read -r source; do
|
||||
|
|
@ -12,6 +13,9 @@ server_sources_newer() {
|
|||
if [[ ! -x "${SERVER_BIN}" || "${REPO_ROOT}/go.mod" -nt "${SERVER_BIN}" ]] || server_sources_newer; then
|
||||
command -v go >/dev/null 2>&1 || { echo "go is required to build ${SERVER_BIN}" >&2; exit 1; }
|
||||
mkdir -p "$(dirname "${SERVER_BIN}")"
|
||||
GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${SERVER_BIN}" "${REPO_ROOT}/cmd/jeannie-server"
|
||||
(
|
||||
cd "${REPO_ROOT}"
|
||||
GOWORK=off GOCACHE="${GOCACHE:-${REPO_ROOT}/.lab/go-build-cache}" go build -o "${SERVER_BIN}" ./cmd/jeannie-server
|
||||
)
|
||||
fi
|
||||
exec "${SERVER_BIN}" "$@"
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ validate_unit_tests() {
|
|||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_ai_lab_suite.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_status_focus.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_status_app_snapshot.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_go_launchers.py'
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
"""Launcher builds must use their own checkout, even from another Go module."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class GoLauncherTests(unittest.TestCase):
|
||||
def test_builds_from_launcher_checkout_not_caller(self):
|
||||
for name in ("jeannie-core", "jeannie-server"):
|
||||
with self.subTest(name=name), tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp) / "checkout"
|
||||
(root / "scripts").mkdir(parents=True)
|
||||
(root / "cmd" / name).mkdir(parents=True)
|
||||
(root / "go.mod").write_text("module example.test/jeannie\n")
|
||||
shutil.copy(ROOT / "scripts" / name, root / "scripts" / name)
|
||||
caller = Path(tmp) / "other-module"
|
||||
caller.mkdir()
|
||||
(caller / "go.mod").write_text("module example.test/other\n")
|
||||
bindir = Path(tmp) / "bin"
|
||||
bindir.mkdir()
|
||||
fake_go = bindir / "go"
|
||||
fake_go.write_text(
|
||||
'#!/bin/sh\n'
|
||||
'printf "%s\\n%s\\n%s\\n" "$PWD" "$GOWORK" "$4" > "$RECORD"\n'
|
||||
'printf "#!/bin/sh\\nexit 0\\n" > "$3"\n'
|
||||
'chmod +x "$3"\n'
|
||||
)
|
||||
fake_go.chmod(0o755)
|
||||
record = Path(tmp) / "record"
|
||||
env = os.environ.copy()
|
||||
env.update(PATH=f"{bindir}:{env['PATH']}", RECORD=str(record),
|
||||
GOWORK="/unrelated/go.work")
|
||||
env.pop("JEANNIE_CORE_BIN", None)
|
||||
env.pop("JEANNIE_SERVER_BIN", None)
|
||||
subprocess.run(["bash", str(root / "scripts" / name)], cwd=caller,
|
||||
env=env, capture_output=True, text=True, check=True)
|
||||
self.assertEqual(record.read_text().splitlines(),
|
||||
[str(root), "off", f"./cmd/{name}"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue