diff options
| author | aur-build <aur-build@localhost> | 2026-11-20 23:38:01 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-20 23:38:01 +0000 |
| commit | c295510e2bb0ee61234536c832dad87a45977fc8 (patch) | |
| tree | d9e73e141da7eb2b09e553998a1435ad023cc0ac /src/pipeline/dispatch.rs | |
| parent | 92ecaabd7c62d029eba239e95cc8a7d2520fe4a9 (diff) | |
| download | aur-build-c295510e2bb0ee61234536c832dad87a45977fc8.tar.gz aur-build-c295510e2bb0ee61234536c832dad87a45977fc8.zip | |
sandbox: keep `Exit` out of the release build
`Exit` is the result of running a command in a sandbox. `pipeline` consumes it
through `Sandbox::run` — `.success()`, `.stderr` — without ever writing the name,
which is why the census called it dead outside `sandbox`.
The type now lives in a private `mod exit` and reaches the world through an
alias that is `pub` only under `test-support` and `pub(crate)` otherwise. A
`pub` definition inside a private module is not a nameable path from outside,
but it is visible enough to appear in a public trait signature, which is what
makes this possible where a plain `pub(crate) struct` is not.
Verified with an external crate: naming `aur_build::sandbox::Exit` in a release
build is `error[E0603]: struct Exit is private`; with `test-support` it compiles.
Diffstat (limited to 'src/pipeline/dispatch.rs')
| -rw-r--r-- | src/pipeline/dispatch.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/pipeline/dispatch.rs b/src/pipeline/dispatch.rs index 89a8788..aea934e 100644 --- a/src/pipeline/dispatch.rs +++ b/src/pipeline/dispatch.rs @@ -68,7 +68,21 @@ fn dispatcher(cfg: Arc<Config>, db: Db, stop: Arc<AtomicBool>, tx: Sender<String } } +/// The scheduler loop calls it; a test drives single ticks and needs it directly. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> { + dispatch_once_impl(cfg, db, tx) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> { + dispatch_once_impl(cfg, db, tx) +} + +fn dispatch_once_impl(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> { let reaped = builds::reap_expired(db).unwrap_or(0); if reaped > 0 { db::audit_system( @@ -97,7 +111,21 @@ pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> ids } +/// Production reaches this through `dispatch_once`, which is the only thing that acts on the answer. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +fn admissible_impl(cfg: &Config, db: &Db) -> usize { let in_flight = builds::in_flight(db).unwrap_or(0) as usize; let slots = cfg.max_concurrent_builds.saturating_sub(in_flight); if slots == 0 { @@ -110,7 +138,21 @@ pub fn admissible(cfg: &Config, db: &Db) -> usize { slots } +/// Production reaches this through `admissible`, which is the only thing that acts on the number. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +fn free_disk_mb_impl(path: &std::path::Path) -> u64 { use std::ffi::CString; let c = match CString::new(path.as_os_str().to_string_lossy().as_bytes()) { Ok(c) => c, |
