"""Language profiles (tools/eval/languages/*.json). A profile says how to invoke a toolchain and where its pinned local documentation is. It MUST NOT contain solution hints (protocol §5). Fields: name language id used in task directories and records display human name toolchain {"binaries": [...], "version": [argv, ...], "bind": [paths]} binaries are resolved on the host and bound read-only into the sandbox; "version" commands are recorded (§28) docs {"env": VAR, "default": path}: directory or file mounted at /docs (read-only) instructions text appended to the shared system prompt classify {"check": [prefix, ...], "build": [...], "test": [...]}: command prefixes counted as verifier/compiler and test runs for the repair metrics (§14, §15) """ import glob import os import shutil import subprocess from . import util HERE = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "languages") def available(): return sorted(os.path.splitext(os.path.basename(p))[0] for p in glob.glob(os.path.join(HERE, "*.json"))) def load(name): path = os.path.join(HERE, name + ".json") if not os.path.exists(path): raise SystemExit(f"unknown language profile {name!r}; available: {', '.join(available())}") prof = util.read_json(path) prof["profile_hash"] = util.sha256_path(path) return prof def expand(s): return os.path.expandvars(os.path.expanduser(s.replace("${REPO}", util.REPO))) def resolve_binaries(prof): """Host paths of the toolchain binaries and the directories to bind.""" found, binds = {}, set() cmd = prof["toolchain"].get("bind_command") if cmd: r = subprocess.run(cmd, capture_output=True, text=True) if r.returncode != 0 or not os.path.isdir(r.stdout.strip()): raise SystemExit(f"{prof['name']}: {' '.join(cmd)} did not print a directory") binds.add(os.path.realpath(r.stdout.strip())) for b in prof["toolchain"].get("binaries", []): path = shutil.which(expand(b)) if os.sep not in b else expand(b) if path is None or not os.path.exists(path): raise SystemExit(f"{prof['name']}: toolchain binary {b!r} not found") real = os.path.realpath(path) found[os.path.basename(b)] = real binds.add(os.path.dirname(real)) for extra in prof["toolchain"].get("bind", []): for p in glob.glob(expand(extra)): binds.add(os.path.realpath(p)) # A rustc sysroot or a zig installation is self-contained: bind the # directory above `bin` so libraries and the standard library resolve. out = set() for d in binds: out.add(os.path.dirname(d) if os.path.basename(d) == "bin" else d) return found, sorted(out) def sandbox_path(binds): """PATH inside the sandbox: `