Files
2026-09-24 14:51:56 +08:00

47 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Install the actual Arch package into a disposable pacman root, without host writes."""
from pathlib import Path
import json
import os
import subprocess
import tempfile
project=Path(__file__).resolve().parents[2]
package=Path((project/'out/workstation/package-path.txt').read_text().strip())
work=Path(tempfile.mkdtemp(prefix='arch-package-test.',dir=project/'out'))
root=work/'root';root.mkdir()
(root/'var/lib/pacman').mkdir(parents=True)
(root/'var/cache/pacman/pkg').mkdir(parents=True)
config=work/'pacman.conf'
config.write_text('[options]\nArchitecture = auto\nSigLevel = Never\nDownloadUser = root\n')
wrapper=work/'bin';wrapper.mkdir()
# Run the actual installer. In this private namespace it is already uid 0;
# redirect only pacman's installation root and disable dependency resolution.
(wrapper/'pacman').write_text('#!/bin/bash\nexec /usr/bin/pacman --config '+str(config)+' --root '+str(root)+' --dbpath '+str(root/'var/lib/pacman')+' --cachedir '+str(root/'var/cache/pacman/pkg')+' --logfile '+str(work/'pacman.log')+' --nodeps --nodeps --noconfirm "$@"\n')
(wrapper/'pacman').chmod(0o755)
command=['bwrap','--unshare-user','--uid','0','--gid','0','--ro-bind','/','/','--bind',str(work),str(work),'--dev','/dev','--proc','/proc','--setenv','PATH',str(wrapper)+':'+os.environ['PATH'],str(project/'tools/install-workstation')]
result=subprocess.run(command,capture_output=True,text=True)
(work/'install.log').write_text(result.stdout+result.stderr)
assert result.returncode==0,(result.stdout,result.stderr)
version=subprocess.check_output([str(project/'tools/version')],text=True).strip()
for tool in ['fds-cartridge','fds-emulator','fds-flash']:
output=subprocess.check_output([str(root/'usr/bin'/tool),'--version'],text=True).strip()
assert output==f'{tool} {version}',output
subprocess.run([str(root/'usr/bin'/tool),'--help'],check=True,stdout=subprocess.DEVNULL)
assert (root/'usr/share/doc/fds-tools/fds-os.wiki/Workstation.md').is_file()
manual = root/'usr/share/doc/fds-tools/fds-os.wiki'
for source in (project/'fds-os.wiki').iterdir():
if source.suffix in ('.md', '.png'):
assert (manual/source.name).read_bytes() == source.read_bytes(), source
assert not (manual/'.git').exists()
assert (root/'usr/share/licenses/fds-tools/RUST-NOTICES.txt').stat().st_size>0
installed=subprocess.check_output(['pacman','--config',str(config),'--root',str(root),'--dbpath',str(root/'var/lib/pacman'),'-Q','fds-tools'],text=True).strip()
assert installed==f'fds-tools {version}-1',installed
# makepkg may set different compiler flags from a direct Cargo build. Exercise
# the installed flasher itself against disposable files, not just its version.
subprocess.run(['python3',str(project/'tests/integration/workstation-flash.py'),
'--cli',str(root/'usr/bin/fds-flash')],check=True)
(work/'acceptance.json').write_text(json.dumps(dict(status='passed',package=str(package),installed=installed,installer='tools/install-workstation',installed_flash_verified=True,host_install=False),indent=2)+'\n')
(project/'out/arch-package-current.txt').write_text(str(work)+'\n')
print('PASS: real pacman installation and all three installed commands:',work)