diff options
Diffstat (limited to 'src/shims')
| -rw-r--r-- | src/shims/mod.rs | 114 |
1 files changed, 88 insertions, 26 deletions
diff --git a/src/shims/mod.rs b/src/shims/mod.rs index c1b169c..d0c253d 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -1,10 +1,13 @@ //! Toolchain shims (§16a). //! -//! The pipeline shells out to `mkarchroot`, `makechrootpkg`, `makepkg`, -//! `repo-add`, `gpg` and `pacman`. In test mode the harness prepends a directory -//! of fakes to `PATH`; each fake records its invocation, obeys a scripted -//! outcome from the fixture manifest, and emits plausible -//! `.PKGINFO`/`.BUILDINFO`/`.sig` output. +//! The pipeline shells out to `makepkg`, `pacman`, `repo-add` and `gpg` inside +//! a sandbox, and `git` outside it. In test mode the harness prepends a +//! directory of fakes to `PATH`; each fake records its invocation, obeys a +//! scripted outcome from the fixture manifest, and emits plausible +//! `.PKGINFO`/`.BUILDINFO`/`.sig` output. The `mkarchroot` and `makechrootpkg` +//! fakes remain as stand-ins for the real devtools — the pipeline stopped +//! calling them when builds moved to the provisioning model — so the shim +//! protocol itself stays exercised end to end. //! //! That is what makes the full step machine, checkpointing, lease/reaper //! recovery, publishing and index regeneration runnable in milliseconds on any @@ -208,7 +211,7 @@ pub fn run(tool: &str) -> i32 { "makepkg" => makepkg(&args, &m), "repo-add" => repo_add(&args, &m), "gpg" => gpg(&args), - "pacman" => Ok(0), + "pacman" => pacman(&args), other => Err(format!("no shim named {other}")), }; match r { @@ -247,15 +250,31 @@ pub fn mkarchroot(args: &[String]) -> Result<i32, String> { Ok(0) } -/// `makechrootpkg -c -r <chroot> -- -f`, run with cwd = the build dir. -/// -/// Emits one `.pkg.tar.zst` per package in the manifest into the current -/// directory, exactly where the real tool leaves them. +/// `makechrootpkg -c -r <chroot> -- ...`: the real tool's contract, kept as a +/// stand-in for direct shim tests. The pipeline no longer calls it — the build +/// step runs `makepkg` in the provisioned sandbox — so the package-emitting +/// logic lives in [`emit_packages`], shared with the `makepkg` shim. pub fn makechrootpkg(args: &[String], m: &Manifest) -> Result<i32, String> { + // The real tool reads a chroot root; asserting it keeps the fake honest + // about the real tool's contract. + if !args.iter().any(|a| a == "-r") { + return Err("makechrootpkg: expected -r <chroot>".into()); + } + // Sign only when the caller asked for it, like the real tool: signing is + // `-si<key>`/`-i`, and the pipeline stopped passing it when signing moved + // hub-side to ingest. A shim that signed anyway would hide that move from + // every test in the suite. + let wants_sig = args.iter().any(|a| a.starts_with("-si") || a == "-i" || a == "--sign"); + emit_packages(m, "makechrootpkg", wants_sig) +} + +/// The shared build emulation: emit one `.pkg.tar.zst` per manifest package +/// into the current directory, exactly where the real tools leave them. +pub fn emit_packages(m: &Manifest, tool: &str, wants_sig: bool) -> Result<i32, String> { for l in &m.log_lines { println!("{l}"); } - if forced_fail("makechrootpkg") || m.build == "fail" { + if forced_fail(tool) || m.build == "fail" { eprintln!("==> ERROR: A build function returned error."); return Ok(1); } @@ -263,29 +282,19 @@ pub fn makechrootpkg(args: &[String], m: &Manifest) -> Result<i32, String> { eprintln!("==> ERROR: A failure occurred in check()."); return Ok(1); } - // The pipeline always passes a chroot root; asserting it keeps the fake - // honest about the real tool's contract. - if !args.iter().any(|a| a == "-r") { - return Err("makechrootpkg: expected -r <chroot>".into()); - } let startdir = std::env::current_dir().map_err(|e| e.to_string())?; - // The real tool reads the PKGBUILD it was handed; we assert it is there so a - // broken materialize step cannot pass silently. + // The real tool reads the PKGBUILD it was handed; we assert it is there so + // a broken materialize step cannot pass silently. if !startdir.join("PKGBUILD").exists() { let found = std::fs::read_dir(&startdir) .map(|rd| rd.filter_map(|e| e.ok()).map(|e| e.file_name().to_string_lossy().into_owned()).collect::<Vec<_>>()) .unwrap_or_default(); return Err(format!( - "makechrootpkg: no PKGBUILD in {} (contains {found:?})", + "{tool}: no PKGBUILD in {} (contains {found:?})", startdir.display() )); } let pkgs = packages_to_emit(m, &startdir); - // Sign only when the caller asked for it, like the real tool: signing is - // `-si<key>`/`-i`, and the pipeline stopped passing it when signing moved - // hub-side to ingest. A shim that signed anyway would hide that move from - // every test in the suite. - let wants_sig = args.iter().any(|a| a.starts_with("-si") || a == "-i" || a == "--sign"); for p in &pkgs { let path = write_package(&startdir, p, m)?; println!("==> Creating package '{}'", path.file_name().unwrap().to_string_lossy()); @@ -489,11 +498,64 @@ pub fn makepkg(args: &[String], m: &Manifest) -> Result<i32, String> { } } } else { - // `makepkg -si` style: behave like a local build. - makechrootpkg(args, m) + // `makepkg -c -f` style: the pipeline's build step, running in the + // provisioned sandbox. No `-s` and no `-si` reach this shim, and the + // emulation does not care: dependencies and signatures are the hub's + // business now. + emit_packages(m, "makepkg", false) } } +/// `pacman -U <blobs...>` / `pacman -Q`: a fake installed database living in +/// the shim dir, so the provisioning step's world check runs against something +/// that behaves. +/// +/// `-U` refuses any file that does not hash to the digest its filename claims +/// — the same trust posture as the real signature check — and records each +/// package from its `.PKGINFO`. `-Q` then reports exactly what was installed, +/// which is what makes the pipeline's fail-closed world assertion a real test +/// rather than a no-op. +pub fn pacman(args: &[String]) -> Result<i32, String> { + if args.iter().any(|a| a == "-U") { + for path in args.iter().filter(|a| !a.starts_with('-')) { + let p = std::path::Path::new(path); + let claimed = p + .file_name() + .and_then(|s| s.to_str()) + .ok_or_else(|| format!("pacman: bad blob path {path}"))?; + let bytes = std::fs::read(p).map_err(|e| format!("pacman: {path}: {e}"))?; + if crate::hash::hex(&bytes) != claimed { + return Err(format!( + "pacman: {claimed} does not hash to the digest its name claims" + )); + } + let pkginfo = crate::pkginfo::pkginfo_text(&bytes)?; + let info = crate::pkginfo::parse_pkginfo(&pkginfo); + if let Some(db) = installed_db() { + use std::io::Write; + if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(db) { + let _ = writeln!(f, "{} {}", info.name, info.version); + } + } + println!(":: installing {}-{}", info.name, info.version); + } + return Ok(0); + } + if args.iter().any(|a| a == "-Q") { + if let Some(db) = installed_db() { + if let Ok(text) = std::fs::read_to_string(db) { + print!("{text}"); + } + } + return Ok(0); + } + Ok(0) +} + +fn installed_db() -> Option<std::path::PathBuf> { + std::env::var("AUR_SHIM_DIR").ok().map(|d| std::path::Path::new(&d).join("installed.txt")) +} + /// `repo-add [-s -p key -R] <db.tar.{gz,zst}> <pkg...>`: rebuild the database /// from the packages handed to it. /// |
