ReviewOS

also looking at this

stacks/drone

fix: separate native runtime builds from test deadlines

#69
Merged chris wants to merge codex/runtime-cold-build-setup into main
10 files +399 -14
resources/functions/drone/runtime/build.tsmodified+8-8
Changes to resources/functions/drone/runtime/build.ts
@@ -3,9 +3,9 @@ import { runBoundedHostProcess } from '../../host/process'
33
44export const picoSdkRevision = '079c6f39023649b154152db30f1d781e884879bc'
55export interface RuntimeBuildOptions { project?: string, target?: 'host' | 'pico2', sdk?: string, toolchain?: string, watchdogTest?: boolean, sensors?: boolean }
6async function run(args: string[], cwd: string, env = process.env) {
7 const result = await runBoundedHostProcess(args, { cwd, env, timeoutMs: 120000, stdoutBytes: 2_000_000, stderrBytes: 2_000_000, label: `Runtime build ${args[0]}` })
8 if (result.exitCode !== 0) throw new Error(`${args[0]} exited ${result.exitCode}:\n${(result.stdout + result.stderr).slice(-8000)}`, { cause: result })
6async function run(stage: string, args: string[], cwd: string, env = process.env) {
7 const result = await runBoundedHostProcess(args, { cwd, env, timeoutMs: 120000, stdoutBytes: 2_000_000, stderrBytes: 2_000_000, label: `Runtime build ${stage}` })
8 if (result.exitCode !== 0) throw new Error(`Runtime build ${stage}: ${args[0]} exited ${result.exitCode}:\n${(result.stdout + result.stderr).slice(-8000)}`, { cause: result })
99 return result.stdout.trim()
1010}
1111/** Local tools only; no shell interpolation, SDK download, firmware flashing or device access. */
@@ -20,14 +20,14 @@ export async function buildRuntime(options: RuntimeBuildOptions = {}) {
2020 const sdk = options.sdk ?? env.PICO_SDK_PATH
2121 if (!sdk) throw new Error('Provide --sdk or PICO_SDK_PATH with the pinned Pico SDK 2.3.1 checkout')
2222 env.PICO_SDK_PATH = resolve(sdk)
23 if (await run(['git', 'rev-parse', 'HEAD'], env.PICO_SDK_PATH) !== picoSdkRevision) throw new Error('Pico SDK revision does not match the retained build pin')
23 if (await run('SDK revision', ['git', 'rev-parse', 'HEAD'], env.PICO_SDK_PATH) !== picoSdkRevision) throw new Error('Pico SDK revision does not match the retained build pin')
2424 // A dirty SDK is not a reproducible input.
25 if (await run(['git', 'status', '--porcelain', '--untracked-files=no'], env.PICO_SDK_PATH)) throw new Error('Pico SDK tracked files must be clean')
25 if (await run('SDK worktree', ['git', 'status', '--porcelain', '--untracked-files=no'], env.PICO_SDK_PATH)) throw new Error('Pico SDK tracked files must be clean')
2626 if (options.toolchain) env.PICO_TOOLCHAIN_PATH = resolve(options.toolchain)
2727 }
2828 else if (options.watchdogTest || options.sensors) throw new Error('Sensor and watchdog firmware profiles are only available for pico2')
29 await run(['cmake', '-S', join(project, 'firmware/runtime'), '-B', directory, '-DCMAKE_BUILD_TYPE=Release', `-DDRONE_PICO2=${target === 'pico2' ? 'ON' : 'OFF'}`, `-DDRONE_WATCHDOG_TEST=${options.watchdogTest ? 'ON' : 'OFF'}`, `-DDRONE_SENSOR_BENCH=${options.sensors ? 'ON' : 'OFF'}`], project, env)
30 await run(['cmake', '--build', directory, '--parallel', '2'], project, env)
31 if (target === 'host') await run(['ctest', '--test-dir', directory, '--output-on-failure'], project, env)
29 await run(`${target} configure`, ['cmake', '-S', join(project, 'firmware/runtime'), '-B', directory, '-DCMAKE_BUILD_TYPE=Release', `-DDRONE_PICO2=${target === 'pico2' ? 'ON' : 'OFF'}`, `-DDRONE_WATCHDOG_TEST=${options.watchdogTest ? 'ON' : 'OFF'}`, `-DDRONE_SENSOR_BENCH=${options.sensors ? 'ON' : 'OFF'}`], project, env)
30 await run(`${target} compile`, ['cmake', '--build', directory, '--parallel', '2'], project, env)
31 if (target === 'host') await run('host contracts', ['ctest', '--test-dir', directory, '--output-on-failure'], project, env)
3232 return { target, directory, artifact: join(directory, target === 'host' ? `drone_runtime_host${process.platform === 'win32' ? '.exe' : ''}` : 'drone_runtime.uf2'), physicalFlightEnabled: false as const }
3333}