|
| 1 | +#!/usr/bin/env lua |
| 2 | +--[[ |
| 3 | + Helper script to list all registered engines. |
| 4 | + Outputs engine IDs as JSON array for use in CI matrix. |
| 5 | + |
| 6 | + Usage: |
| 7 | + lua bin/engines.lua -- outputs JSON array: ["engine1","engine2"] |
| 8 | + lua bin/engines.lua --check -- exits 0 if engines found, 1 otherwise |
| 9 | +]] |
| 10 | + |
| 11 | +-- Get script directory and set up paths |
| 12 | +local scriptPath = debug.getinfo(1, "S").source:match("^@?(.*)[/\\]") |
| 13 | +if not scriptPath or scriptPath == "" then scriptPath = "." end |
| 14 | +scriptPath = scriptPath:gsub("/", package.config:sub(1, 1)) |
| 15 | + |
| 16 | +local sep = package.config:sub(1, 1) |
| 17 | +local projectRoot = scriptPath .. sep .. ".." .. sep |
| 18 | + |
| 19 | +-- Set up package paths |
| 20 | +package.path = projectRoot .. "lib" .. sep .. "?.lua;" .. |
| 21 | + projectRoot .. "src/?.lua;" .. |
| 22 | + projectRoot .. "tests/?.lua;" .. |
| 23 | + package.path |
| 24 | + |
| 25 | +-- Load DeltaChess modules |
| 26 | +require("init") |
| 27 | + |
| 28 | +-- Check command line arguments |
| 29 | +local checkMode = false |
| 30 | +for _, a in ipairs(arg) do |
| 31 | + if a == "--check" then |
| 32 | + checkMode = true |
| 33 | + end |
| 34 | +end |
| 35 | + |
| 36 | +-- Get engine list |
| 37 | +local engines = {} |
| 38 | +if DeltaChess and DeltaChess.Engines then |
| 39 | + local list = DeltaChess.Engines:GetEngineList() |
| 40 | + if list then |
| 41 | + for _, engine in ipairs(list) do |
| 42 | + if engine.id then |
| 43 | + table.insert(engines, engine.id) |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | +end |
| 48 | + |
| 49 | +-- Sort engines alphabetically |
| 50 | +table.sort(engines) |
| 51 | + |
| 52 | +if checkMode then |
| 53 | + -- Check mode: exit 0 if engines found, 1 otherwise |
| 54 | + if #engines > 0 then |
| 55 | + io.stderr:write("Found " .. #engines .. " engine(s): " .. table.concat(engines, ", ") .. "\n") |
| 56 | + os.exit(0) |
| 57 | + else |
| 58 | + io.stderr:write("No engines found\n") |
| 59 | + os.exit(1) |
| 60 | + end |
| 61 | +end |
| 62 | + |
| 63 | +-- Output JSON array |
| 64 | +io.write("[") |
| 65 | +for i, engineId in ipairs(engines) do |
| 66 | + if i > 1 then io.write(",") end |
| 67 | + -- Escape quotes in engine ID (though unlikely to have them) |
| 68 | + local escaped = engineId:gsub('"', '\\"') |
| 69 | + io.write('"' .. escaped .. '"') |
| 70 | +end |
| 71 | +io.write("]") |
| 72 | +io.write("\n") |
0 commit comments