Fix OVMF 4m variant detection and Gentoo dep atom parsing

1. host.ovmf: Arch edk2-ovmf 202508+ uses OVMF_CODE.4m.fd (4MB variant)
   instead of OVMF_CODE.fd. Added .4m.fd paths to the search list and
   updated the find fallback to match OVMF_CODE*.fd glob.

2. test_parse_dep_atoms: The single-regex approach with lazy quantifiers
   failed on atoms like "sys-libs/zlib" at end-of-string. Rewrote
   parse_dep_atoms to split on whitespace first, strip [:slot] and [USE]
   suffixes, then match category/name with a simple anchored regex.
   This is more robust and easier to reason about.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 16:40:52 +01:00
parent 658289dc51
commit 4d8e27cd50
2 changed files with 50 additions and 18 deletions

View File

@@ -321,21 +321,49 @@ fn parse_use_flags(iuse: &str) -> HashMap<String, OptionalDep> {
/// Strips category prefixes and version constraints for dpack format. /// Strips category prefixes and version constraints for dpack format.
fn parse_dep_atoms(deps: &str, warnings: &mut ConversionWarnings) -> Vec<String> { fn parse_dep_atoms(deps: &str, warnings: &mut ConversionWarnings) -> Vec<String> {
let mut result = Vec::new(); let mut result = Vec::new();
// Regex to extract category/name from a single Gentoo atom token
// Strips: leading operator (>=, <=, ~, =), trailing version (-1.2.3),
// slot (:0=), and USE flags ([foo,bar])
let atom_re = Regex::new( let atom_re = Regex::new(
r"(?:>=|<=|~|=)?([a-zA-Z0-9_-]+/[a-zA-Z0-9_.+-]+?)(?:-\d[^\s\[\]:]*)?(?:\[.*?\])?(?::[\w/=*]*)?(?:\s|$)" r"^(?:>=|<=|~|=)?([a-zA-Z0-9_-]+/[a-zA-Z0-9_+-]+[a-zA-Z])"
).unwrap(); ).unwrap();
for caps in atom_re.captures_iter(deps) { // Process each whitespace-separated token, skipping non-atoms
for token in deps.split_whitespace() {
let clean = token.trim();
// Skip conditional operators and parens
if clean.is_empty()
|| clean.ends_with('?')
|| clean == "("
|| clean == ")"
|| clean == "||"
|| clean == "^^"
{
continue;
}
// Strip trailing [:slot] and [USE] before regex matching
let without_use = if let Some(bracket_pos) = clean.find('[') {
&clean[..bracket_pos]
} else {
clean
};
let without_slot = if let Some(colon_pos) = without_use.find(':') {
&without_use[..colon_pos]
} else {
without_use
};
if let Some(caps) = atom_re.captures(without_slot) {
if let Some(m) = caps.get(1) { if let Some(m) = caps.get(1) {
let full_atom = m.as_str(); let full_atom = m.as_str();
// Strip category prefix (e.g., "dev-libs/" -> "")
let pkg_name = full_atom let pkg_name = full_atom
.rsplit('/') .rsplit('/')
.next() .next()
.unwrap_or(full_atom) .unwrap_or(full_atom)
.to_string(); .to_string();
// Skip virtual packages and test-only deps
if full_atom.starts_with("virtual/") { if full_atom.starts_with("virtual/") {
continue; continue;
} }
@@ -345,6 +373,7 @@ fn parse_dep_atoms(deps: &str, warnings: &mut ConversionWarnings) -> Vec<String>
} }
} }
} }
}
// Detect complex constructs we can't fully parse // Detect complex constructs we can't fully parse
if deps.contains("^^") || deps.contains("||") { if deps.contains("^^") || deps.contains("||") {

View File

@@ -133,11 +133,14 @@ else
record "host.nested_virt" "skip" "No VMX/SVM — QEMU boot tests will be slower" record "host.nested_virt" "skip" "No VMX/SVM — QEMU boot tests will be slower"
fi fi
# Check OVMF — Arch uses split CODE/VARS files, others use a single OVMF.fd # Check OVMF — search all known paths including 4m variant (newer Arch)
OVMF="" OVMF=""
for p in \ for p in \
/usr/share/edk2/x64/OVMF_CODE.4m.fd \
/usr/share/edk2/x64/OVMF_CODE.fd \ /usr/share/edk2/x64/OVMF_CODE.fd \
/usr/share/edk2-ovmf/x64/OVMF_CODE.4m.fd \
/usr/share/edk2-ovmf/x64/OVMF_CODE.fd \ /usr/share/edk2-ovmf/x64/OVMF_CODE.fd \
/usr/share/OVMF/OVMF_CODE.4m.fd \
/usr/share/OVMF/OVMF_CODE.fd \ /usr/share/OVMF/OVMF_CODE.fd \
/usr/share/edk2/x64/OVMF.fd \ /usr/share/edk2/x64/OVMF.fd \
/usr/share/edk2-ovmf/x64/OVMF.fd \ /usr/share/edk2-ovmf/x64/OVMF.fd \
@@ -148,7 +151,7 @@ for p in \
done done
# Last resort: find it # Last resort: find it
if [ -z "$OVMF" ]; then if [ -z "$OVMF" ]; then
OVMF=$(find /usr/share -name "OVMF_CODE.fd" -o -name "OVMF.fd" 2>/dev/null | head -1) OVMF=$(find /usr/share -name "OVMF_CODE*.fd" -o -name "OVMF.fd" 2>/dev/null | head -1)
fi fi
[ -n "$OVMF" ] && record "host.ovmf" "pass" "$OVMF" || record "host.ovmf" "fail" "Not found — install edk2-ovmf" [ -n "$OVMF" ] && record "host.ovmf" "pass" "$OVMF" || record "host.ovmf" "fail" "Not found — install edk2-ovmf"