49 lines
2.1 KiB
Nu
49 lines
2.1 KiB
Nu
#!/usr/bin/env nu
|
|
# Verify the packaged host's toolchain and namespace builder outside the Nix sandbox.
|
|
def main [host: path = 'result/bin/sausage'] {
|
|
let host = ($host | path expand)
|
|
let temporary = (^mktemp -d -t sausage-packaged.XXXXXX | str trim)
|
|
let world = ($temporary | path join world)
|
|
print $'Fresh world: ($world)'
|
|
let initialized = (^$host init $world | complete)
|
|
print --no-newline $initialized.stdout
|
|
print --stderr --no-newline $initialized.stderr
|
|
if $initialized.exit_code != 0 { error make {msg: 'packaged host init failed'} }
|
|
let script = r#'set -e
|
|
/bin/printf 'coreutils OK\n'
|
|
printf 'same\n' > /same
|
|
cmp /same /same
|
|
diff /same /same
|
|
ps | grep -q PID
|
|
sh -c 'echo sh OK'
|
|
bash -c 'echo bash OK'
|
|
qjs -e 'console.log("qjs source OK")'
|
|
mkdir -p /src/projects
|
|
cd /src/projects
|
|
cargo new packaged-probe --vcs none
|
|
printf 'fn main() { println!("packaged builder OK"); }\n' > packaged-probe/src/main.rs
|
|
cd packaged-probe
|
|
cargo run --release
|
|
'#
|
|
let result = (^$host sh $world -c $script | complete)
|
|
print --no-newline $result.stdout
|
|
print --stderr --no-newline $result.stderr
|
|
if $result.exit_code != 0 { error make {msg: 'packaged builder failed'} }
|
|
for expected in ['coreutils OK' 'sh OK' 'bash OK' 'qjs source OK' 'packaged builder OK'] {
|
|
if not ($result.stdout | lines | any {|line| $line == $expected }) {
|
|
error make {msg: $'packaged check did not print: ($expected)'}
|
|
}
|
|
}
|
|
# Native run starts init. A bare command must retain argv[0] through its PATH symlink.
|
|
"[Service]\nType=oneshot\nExecStart=touch /init-PATH-ok\n" | save --force ($world | path join world etc systemd system web.service)
|
|
let supervised = (^timeout --signal INT 15s $host run $world | complete)
|
|
print --no-newline $supervised.stdout
|
|
print --stderr --no-newline $supervised.stderr
|
|
if $supervised.exit_code not-in [0 124] or not ($world | path join world init-PATH-ok | path exists) {
|
|
error make {msg: 'init did not resolve the bare command through its PATH symlink'}
|
|
}
|
|
print 'init PATH OK'
|
|
rm --recursive --force $temporary
|
|
print 'Packaged builder check passed.'
|
|
}
|