name: bq2-iterate description: Automate bootstrap-qcow2 sysroot iteration when the user says "iterate" or "resume iteration"; detect Alpine seed/BQ2 seed/inner rootfs, run sysroot-runner in the background, apply overrides, and back-annotate fixes into SysrootBuilder with a clean commit.
BQ2 iteration autopilot
Use this when the user says "iterate" or "resume iteration". The goal is to run sysroot-runner until the current phase completes, then back-annotate overrides and commit.
Detect rootfs context and paths
Find the rootfs prefix (do not assume
/var/libmeans inner rootfs; Alpine seed also has it):- If
/workspace/rootfs/var/lib/sysroot-build-plan.jsonexists, you are outside the workspace rootfs. Userootfs_prefix="/workspace/rootfs"androotfs_root="/workspace/rootfs". - Else if
/work/bootstrap-qcow2/data/sysroot/rootfs/var/lib/sysroot-build-plan.jsonexists, userootfs_prefix="/work/bootstrap-qcow2/data/sysroot/rootfs". - Else if
/var/lib/sysroot-build-plan.jsonexists, you are operating in-place. Userootfs_prefix=""androotfs_root="/".- Classify the seed:
- If
/usr/bin/clangexists, treat as inner rootfs (system-from-sysroot). - If
/opt/sysroot/bin/clangexists and/usr/bin/clangdoes not, treat as Alpine seed (sysroot-from-alpine).
- If
- Classify the seed:
- Otherwise, stop and ask for the rootfs location.
- If
Define canonical paths (prefix with
rootfs_prefix):plan=/var/lib/sysroot-build-plan.jsonoverrides=/var/lib/sysroot-build-overrides.jsonstate=/var/lib/sysroot-build-state.jsonreports=/var/lib/sysroot-build-reportslogs=/var/lib/sysroot-build-logs
Locate the repo root (first match wins):
/work/bootstrap-qcow2/workspace/bootstrap-qcow2/workspace/bootstrap-qcow2-*/home/ubuntu/workspace/bootstrap-qcow2
Ensure
bq2entrypoints exist:- If
bin/bq2is missing, runshards build(useCRYSTAL_CACHE_DIR=/tmp/crystal_cacheif needed) and./bin/bq2 --install. - If
shardsis missing, try/opt/sysroot/bin/shardsand keep PATH consistent. If it is still missing, report and stop.
- If
Determine the current phase
- Prefer
bin/sysroot-statusif available. If not, usebin/bq2 sysroot-status. - If you are outside the rootfs, pass
--rootfs="${rootfs_root}"(or-w /workspacefor the default workspace rootfs). - Parse
next_phase=and use that as the target phase. Always iterate until that phase completes.
Run the runner in the background
- Always launch with explicit paths and log capture. Use
nohupand record PID + log path. - Example (fill variables):
log_dir="${rootfs_prefix}/var/lib/sysroot-build-logs"
mkdir -p "$log_dir"
log="$log_dir/sysroot-runner-$(date -u +%Y%m%dT%H%M%SZ)-${phase}.log"
nohup "${repo}/bin/sysroot-runner" \
--plan "${rootfs_prefix}${plan}" \
--state-path "${rootfs_prefix}${state}" \
--overrides "${rootfs_prefix}${overrides}" \
--report-dir "${rootfs_prefix}${reports}" \
--phase "${phase}" \
> "$log" 2>&1 &
- If the runner fails due to namespace restrictions, rerun with escalated permissions.
Observe, override, and relaunch
- Tail the log to find the failure point.
- Read the newest failure report:
latest=$(ls -t "${rootfs_prefix}${reports}"/*.json | head -n 1)- Inspect
error,step,phase,command, andconfigure_flags.
- Update
${rootfs_prefix}${overrides}with the smallest change that fixes the error. - Rerun the runner for the same phase. Repeat until the phase completes.
Phase completion check
- Re-run
sysroot-statusand verifynext_phasechanges away from the phase you targeted. - If it has not advanced, continue iterating.
Back-annotate and commit
Once the phase completes with overrides in place:
- Translate overrides into
src/sysroot_builder.crand related helpers. - Add/remove patches in
patches/as needed. - Remove overrides/state in the rootfs and rerun from scratch when feasible.
- Run:
crystal tool formatshards buildcrystal spec
- Commit with a message describing the behavior change and affected arch.
Keep all changes Crystal-native and avoid new shell scripts.