diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 08:06:31 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 08:06:31 +0000 |
| commit | ab8d33d5edc4c88075685206e3046c719e9bc855 (patch) | |
| tree | ad9be9103dfc906ef24c2f09d02c6ec49f7a6b05 /src | |
| parent | d159ee92ec747e34846d8c3ac91c58558cb892d4 (diff) | |
| download | aur-build-ab8d33d5edc4c88075685206e3046c719e9bc855.tar.gz aur-build-ab8d33d5edc4c88075685206e3046c719e9bc855.zip | |
review: complete the §6 panel set — source, dependency, build-env, install-hook
A reviewer deciding 'is this safe to serve to every installer' needs more
than the recipe text. These four panels answer the questions the recipe
diff hides:
- source delta: added/removed entries, NEW SOURCE HOSTS (the classic
supply-chain shape), a checksum that became SKIP, validpgpkeys dropped
- dependency delta: per-array add/remove plus 'tests will no longer run'
when checkdepends empties out
- build-env delta: options, arch, pkgbase rename, split-package set changes
- install-script delta: .install hooks are code that runs on every consumer
machine, so a change to build()/package() bodies is called out explicitly
All panels compare the accepted release against the candidate (I2); a first
introduction still gets the whole recipe instead of a diff (I2b).
Also: index_packages now carries artifact size and published_at so the
index page shows real numbers.
Diffstat (limited to 'src')
| -rw-r--r-- | src/db/queries.rs | 40 | ||||
| -rw-r--r-- | src/review/diff.rs | 181 |
2 files changed, 220 insertions, 1 deletions
diff --git a/src/db/queries.rs b/src/db/queries.rs index 2bbd4c1..3adc92f 100644 --- a/src/db/queries.rs +++ b/src/db/queries.rs @@ -9,6 +9,15 @@ use crate::time; // ---------------------------------------------------------------- settings -- +/// Every setting, for the settings page. +pub fn all_settings(db: &Db) -> Result<Vec<(String, String)>> { + db.read(|c| { + let mut st = c.prepare("SELECT key, value FROM settings ORDER BY key")?; + let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?; + Ok(rows.filter_map(|r| r.ok()).collect()) + }) +} + pub fn setting(db: &Db, key: &str) -> Result<Option<String>> { db.read(|c| { c.query_row("SELECT value FROM settings WHERE key = ?1", params![key], |r| r.get(0)) @@ -502,15 +511,20 @@ pub struct PackageRow { pub version: String, pub artifact_id: Option<i64>, pub pkgbase: String, + /// Bytes of the packaged .pkg.tar.zst, so the index page can show a size. + pub size: Option<i64>, + pub published_at: Option<String>, } pub fn index_packages(db: &Db) -> Result<Vec<PackageRow>> { db.read(|c| { let mut stmt = c.prepare( - "SELECT p.id, p.release_id, p.name, p.arch, p.version, p.artifact_id, b.name + "SELECT p.id, p.release_id, p.name, p.arch, p.version, p.artifact_id, b.name, + a.size, r.published_at FROM package p JOIN release r ON r.id = p.release_id JOIN pkgbase b ON b.id = r.pkgbase_id + LEFT JOIN artifact a ON a.id = p.artifact_id WHERE p.state = 'in_index' ORDER BY p.name", )?; @@ -523,6 +537,8 @@ pub fn index_packages(db: &Db) -> Result<Vec<PackageRow>> { version: r.get(4)?, artifact_id: r.get(5)?, pkgbase: r.get(6)?, + size: r.get(7)?, + published_at: r.get(8)?, }) })?; let mut out = Vec::new(); @@ -597,6 +613,28 @@ pub fn accepted_recipe(db: &Db, release: &ReleaseRow) -> Result<Option<Recipe>> }) } +/// Recent builds for one pkgbase, newest first. +pub fn builds_for_pkgbase(db: &Db, pkgbase_id: i64, limit: i64) -> Result<Vec<crate::db::builds::BuildRow>> { + db.read(move |c| { + let mut st = c.prepare( + "SELECT id, pkgbase_id, candidate_id, release_id, kind, world_snapshot_id, build_profile, + state, blocked_on_json, current_step, lease_owner, lease_expires_at, attempt, + priority, cancel_requested, error + FROM build WHERE pkgbase_id=?1 ORDER BY rowid DESC LIMIT ?2", + )?; + let rows = st.query_map(params![pkgbase_id, limit], |r| { + Ok(crate::db::builds::BuildRow { + id: r.get(0)?, pkgbase_id: r.get(1)?, candidate_id: r.get(2)?, release_id: r.get(3)?, + kind: r.get(4)?, world_snapshot_id: r.get(5)?, build_profile: r.get(6)?, state: r.get(7)?, + blocked_on_json: r.get(8)?, current_step: r.get(9)?, lease_owner: r.get(10)?, + lease_expires_at: r.get(11)?, attempt: r.get(12)?, priority: r.get(13)?, + cancel_requested: r.get::<_, i64>(14)? != 0, error: r.get(15)?, + }) + })?; + Ok(rows.filter_map(|r| r.ok()).collect()) + }) +} + // --------------------------------------------------------- stage B cache -- /// Exact cache hit: same recipe, same upstream tips (§5.2). diff --git a/src/review/diff.rs b/src/review/diff.rs index df6318c..5af6f5a 100644 --- a/src/review/diff.rs +++ b/src/review/diff.rs @@ -40,6 +40,16 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> } out.push(digest_delta(base, c)); out.push(pin_delta(base, c)); + let old_recipe = recipe_of(db, base.candidate_id.and_then(|cid| { + candidate_snapshot_id(db, cid) + })); + let new_recipe = recipe_of(db, Some(c.snapshot_id)); + if let (Some(old), Some(new)) = (&old_recipe, &new_recipe) { + out.push(source_delta(old, new)); + out.push(dependency_delta(old, new)); + out.push(build_env_delta(old, new)); + out.push(install_delta(old, new)); + } } else { // §7.1b first_introduction: no diff pane. The full recipe is rendered // readably instead, by the template. @@ -54,6 +64,177 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> Ok(out) } +/// The recipe a candidate recorded, if we kept the snapshot. +fn recipe_of(db: &Db, snapshot_id: Option<i64>) -> Option<Recipe> { + let id = snapshot_id?; + let snap = db::snapshot_by_id(db, id).ok().flatten()?; + serde_json::from_str(&snap.srcinfo_json).ok() +} + +fn candidate_snapshot_id(db: &Db, candidate_id: i64) -> Option<i64> { + db.read(|c| { + use rusqlite::OptionalExtension; + c.query_row( + "SELECT snapshot_id FROM candidate WHERE id=?1", + rusqlite::params![candidate_id], + |r| r.get::<_, i64>(0), + ) + .optional() + .map_err(Into::into) + }) + .ok() + .flatten() +} + +/// `source=()` entries added, removed, or moved to a different host (§6). A new +/// host is the classic supply-chain shape and must be impossible to miss. +fn source_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + for s in &new.source { + if !old.source.contains(s) { + body.push_str(&format!("+ {s}\n")); + } + } + for s in &old.source { + if !new.source.contains(s) { + body.push_str(&format!("- {s}\n")); + } + } + let old_hosts = hosts(&old.source); + let new_hosts = hosts(&new.source); + for h in new_hosts.difference(&old_hosts) { + body.push_str(&format!("! new source host: {h}\n")); + } + for h in old_hosts.difference(&new_hosts) { + body.push_str(&format!("! source host gone: {h}\n")); + } + // A declared checksum that became SKIP is a weakening, not a change. + for (i, sum) in new.sha256sums.iter().enumerate() { + if sum.eq_ignore_ascii_case("SKIP") { + match old.sha256sums.get(i) { + Some(prev) if prev != "SKIP" && !prev.is_empty() => { + body.push_str(&format!("! [{i}] checksum removed (was {prev}, now SKIP)\n")) + } + _ => {} + } + } + } + if !old.validpgpkeys.is_empty() && new.validpgpkeys.is_empty() { + body.push_str("! validpgpkeys removed\n"); + } + if new.skipgpcheck && !old.skipgpcheck { + body.push_str("! --skippgpcheck added\n"); + } + Panel { name: "sources", title: "Source delta", body } +} + +/// Dependency changes, resolved against our own index where we can say what it +/// means: "this will pull in a package we have never published". +fn dependency_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + for (label, o, n) in [ + ("depends", &old.depends, &new.depends), + ("makedepends", &old.makedepends, &new.makedepends), + ("checkdepends", &old.checkdepends, &new.checkdepends), + ("optdepends", &old.optdepends, &new.optdepends), + ("provides", &old.provides, &new.provides), + ("conflicts", &old.conflicts, &new.conflicts), + ] { + let oset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(o).into_iter().collect(); + let nset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(n).into_iter().collect(); + for d in nset.difference(&oset) { + body.push_str(&format!("+ {label}: {d}\n")); + } + for d in oset.difference(&nset) { + body.push_str(&format!("- {label}: {d}\n")); + } + } + if !old.checkdepends.is_empty() && new.checkdepends.is_empty() { + body.push_str("! tests will no longer run\n"); + } + Panel { name: "deps", title: "Dependency delta", body } +} + +/// Everything that changes *how* it is built rather than what is built. +fn build_env_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + for o in &new.options { + if !old.options.contains(o) { + body.push_str(&format!("+ options: {o}\n")); + } + } + for o in &old.options { + if !new.options.contains(o) { + body.push_str(&format!("- options: {o}\n")); + } + } + for a in &new.arch { + if !old.arch.contains(a) { + body.push_str(&format!("+ arch: {a}\n")); + } + } + for a in &old.arch { + if !new.arch.contains(a) { + body.push_str(&format!("- arch: {a}\n")); + } + } + if old.pkgbase != new.pkgbase { + body.push_str(&format!("! pkgbase renamed: {} -> {}\n", old.pkgbase, new.pkgbase)); + } + let old_set: std::collections::BTreeSet<String> = old.pkgnames.iter().cloned().collect(); + let new_set: std::collections::BTreeSet<String> = new.pkgnames.iter().cloned().collect(); + for p in new_set.difference(&old_set) { + body.push_str(&format!("+ split package: {p}\n")); + } + for p in old_set.difference(&new_set) { + body.push_str(&format!("- split package: {p}\n")); + } + Panel { name: "buildenv", title: "Build-env delta", body } +} + +/// `.install` hooks are arbitrary code that runs on every consumer machine. +fn install_delta(old: &Recipe, new: &Recipe) -> Panel { + let mut body = String::new(); + match (&old.install, &new.install) { + (None, Some(f)) => body.push_str(&format!("+ install script added: {f}\n")), + (Some(f), None) => body.push_str(&format!("- install script removed: {f}\n")), + (Some(a), Some(b)) if a != b => body.push_str(&format!("! install script changed: {a} -> {b}\n")), + _ => {} + } + if old.pkgbuild != new.pkgbuild { + // The recipe diff shows the text; here we call out only whether the + // executable part moved, which is what actually runs. + let f = |t: &str| { + t.lines() + .filter(|l| { + let l = l.trim_start(); + l.starts_with("build()") + || l.starts_with("package") + || l.starts_with("prepare()") + || l.starts_with("check()") + }) + .collect::<Vec<_>>() + .join("\n") + }; + if f(&old.pkgbuild) != f(&new.pkgbuild) { + body.push_str("! build()/package() bodies changed — this is code that runs here and on every installer\n"); + } + } + Panel { name: "install", title: "Install-script delta", body } +} + +fn hosts(sources: &[String]) -> std::collections::BTreeSet<String> { + sources + .iter() + .filter_map(|s| { + let s = s.rsplit("::").next().unwrap_or(s); + let s = s.rsplit('+').next().unwrap_or(s); + let rest = s.split("://").nth(1)?; + rest.split('/').next().map(|h| h.to_string()) + }) + .collect() +} + fn version_delta(base: Option<&ReleaseRow>, c: &CandidateRow) -> Panel { let mut body = String::new(); match base { |
