portage-atom
A Rust library for parsing Portage package atoms, based on the Package Manager Specification (PMS) 9.
Warning: This codebase was largely AI-generated (slop-coded) and has not yet been thoroughly audited. It may contain bugs, incomplete PMS coverage, or surprising edge-case behaviour. Use at your own risk and please report issues.
Overview
portage-atom provides types and parsing for Gentoo/Portage package atoms
using the winnow parser combinator
library.
Features
- Parses atoms according to PMS (versions, slots, USE deps, blockers, repos)
- PMS version ordering (Algorithm 3.1)
- winnow 0.7 parser combinators
What is a Portage Atom?
A Portage atom is a string that specifies a package or set of packages in Gentoo/Portage package managers. The full syntax:
[!|!!][<|<=|=|~|>=|>]<category>/<package>[-<version>][:slot][::repository][use-deps]
Examples
dev-lang/rust # Simple unversioned atom
>=dev-lang/rust-1.75.0 # Version constraint
dev-lang/rust:0/1.75 # With slot/subslot
dev-lang/rust[llvm_targets_AMDGPU] # With USE flag
!dev-lang/rust # Weak blocker
=dev-lang/rust-1.75.0* # Glob version match
~dev-lang/rust-1.75.0 # Approximate version
dev-lang/rust::gentoo # From specific repository
Installation
Add to your Cargo.toml:
[]
= "0.1"
Usage
Parse Unversioned Atoms (Cpn)
use Cpn;
let cpn = parse?;
assert_eq!;
assert_eq!;
println!; // dev-lang/rust
Parse Versioned Atoms (Cpv)
use Cpv;
let cpv = parse?;
assert_eq!;
assert_eq!;
assert_eq!;
Parse Full Dependencies (Dep)
use ;
let dep = parse?;
// Access components
assert!;
assert_eq!;
assert!;
assert!;
assert_eq!;
// Display
println!;
Version Comparison
Versions implement Ord according to PMS rules:
use Version;
let v1 = parse?;
let v2 = parse?;
assert!;
let v3 = parse?;
assert!; // RC versions are less than release
Core Types
Cpn: Category/Package Name (e.g.,dev-lang/rust)Cpv: Category/Package/Version (e.g.,dev-lang/rust-1.75.0)Dep: Full dependency atom with all optional componentsVersion: Version with operator, numbers, letter, suffixes, and revisionSlot/SlotDep: Slot dependencies (:0,:=,:*, etc.)UseDep: USE flag dependencies ([flag],[-flag],[flag?], etc.)Blocker: Weak (!) or strong (!!) blockersOperator: Version operators (<,<=,=,~,>=,>,=*)
Package Manager Specification (PMS)
This library implements:
Version Specification (PMS Chapter 3)
- Version syntax:
1.2.3a_alpha4_beta5_pre6_rc7_p8-r9 - Version operators and comparison (Algorithm 3.1)
- Revision handling
Dependency Specification (PMS Chapter 8)
- Package dependency atoms
- Blockers (weak
!and strong!!) - Slot dependencies (
:slot,:slot/subslot,:=,:*) - USE dependencies with all variants
- Repository IDs (
::repo)
Design
The library uses winnow 0.7 for parsing:
- Parser Combinators: Composable, type-safe parsing
- Zero-Copy: Minimizes allocations where possible
- Error Handling: Clear error messages with context
- Extensible: Easy to add new features or customize parsing
Key design principles:
- Minimal Dependencies: Only essential crates
- PMS Compliance: Strict adherence to specification
- Type Safety: Rust's type system prevents invalid atoms
- Performance: Efficient parsing with minimal overhead
Testing
Run the test suite:
Run the example:
Related Projects
- PMS - Package Manager Specification
- Portage - Reference Gentoo package manager
- pkgcraft - Full-featured Gentoo package manager library
License
Contributing
Contributions welcome! Please ensure:
- Tests pass (
cargo test) - Code is formatted (
cargo fmt) - No clippy warnings (
cargo clippy) - PMS compliance is maintained
Conventional Commits
This project uses Conventional Commits. Prefix your commit messages with a type:
feat:— new functionalityfix:— bug fixrefactor:— code restructuring without behaviour changedocs:— documentation onlytest:— adding or updating testschore:— maintenance (CI, dependencies, tooling)
Author
Luca Barbato lu_zero@gentoo.org