arch_toolkit/sandbox/mod.rs
1//! Sandbox module for build-preflight dependency and static PKGBUILD analysis.
2//!
3//! Given a package's PKGBUILD or .SRCINFO, this module compares its declared
4//! dependencies against the host's installed packages and reports, per
5//! category (`depends`, `makedepends`, `checkdepends`, `optdepends`):
6//!
7//! - whether each dependency is installed (or provided) on the host,
8//! - the installed version, and
9//! - whether the declared version constraint is satisfied.
10//!
11//! It answers "what would I need to install to build this AUR package?"
12//! before any build starts — ported from Pacsea's sandbox preflight. The
13//! optional security analysis reads PKGBUILD text only: it never executes,
14//! sources, expands, or builds that content, and it reports stable rule IDs and
15//! explicit limitations instead of an aggregate risk score.
16//!
17//! # Features
18//!
19//! This module requires the `sandbox` feature flag (which enables `deps` for
20//! parsing and querying):
21//!
22//! ```toml
23//! [dependencies]
24//! arch-toolkit = { version = "0.2", features = ["sandbox"] }
25//! ```
26//!
27//! # Examples
28//!
29//! ## Analyze a PKGBUILD Against the Host
30//!
31//! ```no_run
32//! use arch_toolkit::deps::{get_installed_packages, get_provided_packages};
33//! use arch_toolkit::sandbox::analyze_pkgbuild;
34//!
35//! let pkgbuild = std::fs::read_to_string("PKGBUILD")?;
36//! let installed = get_installed_packages().unwrap_or_default();
37//! let provided = get_provided_packages(&installed);
38//!
39//! let info = analyze_pkgbuild("my-package", &pkgbuild, &installed, &provided);
40//! if info.is_ready_to_build() {
41//! println!("All build dependencies present");
42//! } else {
43//! println!("Missing: {:?}", info.missing_packages());
44//! }
45//! # Ok::<(), std::io::Error>(())
46//! ```
47//!
48//! ## Analyze an AUR Package via .SRCINFO (with the `aur` feature)
49//!
50//! ```ignore
51//! use arch_toolkit::deps::{fetch_srcinfo, get_installed_packages, get_provided_packages};
52//! use arch_toolkit::sandbox::analyze_srcinfo;
53//!
54//! let client = reqwest::Client::new();
55//! let srcinfo = fetch_srcinfo(&client, "yay").await?;
56//! let installed = get_installed_packages().unwrap_or_default();
57//! let provided = get_provided_packages(&installed);
58//! let info = analyze_srcinfo("yay", &srcinfo, &installed, &provided);
59//! println!("{} missing dependencies", info.missing_packages().len());
60//! ```
61
62mod analyze;
63mod security;
64
65// Re-export types from types module
66pub use crate::types::sandbox::{
67 DependencyDelta, SandboxAnalysisLimitation, SandboxFinding, SandboxInfo, SandboxRuleId,
68 SandboxStaticAnalysis,
69};
70
71// Re-export analysis functions
72pub use analyze::{analyze_dependencies, analyze_pkgbuild, analyze_srcinfo, extract_package_name};
73pub use security::analyze_pkgbuild_security;