srcinfo/lib.rs
1//! # Srcinfo
2//!
3//! Srcinfo is a parser for makepkg's .SRCINFO file format.
4//!
5//! Srcinfo focuses on correctness of parsing, especially
6//! with split packages and architecture specific fields.
7//!
8//! Srcinfo only aims to parse. This crate does not attempt to
9//! perform any version comparison, dependency checking or any other
10//! extra functionality.
11//!
12//! ## Quickstart
13//!
14//! [`Srcinfo`] is the main type for this crate.
15//!
16//! ```
17//! # use srcinfo::Error;
18//! use srcinfo::{Srcinfo, ArchVec};
19//!
20//! # fn test() -> Result<(), Error> {
21//! // Create a srcinfo from a string
22//! let srcinfo: Srcinfo = "
23//! pkgbase = example
24//! pkgver = 1.5.0
25//! pkgrel = 5
26//!
27//! pkgname = example".parse()?;
28//!
29//! // Or a file
30//! # let srcinfo = Srcinfo::from_path("tests/srcinfo/libc++")?;
31//! let srcinfo = Srcinfo::from_path(".SRCINFO")?;
32//!
33//! // Reading global fields
34//! // These fields were declared at the top of the PKGBUILD but may be overridden per package
35//! println!("srcinfo {}-{}:", srcinfo.pkgbase(), srcinfo.version());
36//!
37//! // Print header comment
38//! for comment in srcinfo.comment().lines() {
39//! println!("comment: {}", comment);
40//! }
41//!
42//! println!("url: {}", srcinfo.url().unwrap_or("none"));
43//! for arch in srcinfo.arch() {
44//! println!("arch: {}", arch);
45//! }
46//!
47//! // reading makedepends and makedepends_$ARCH fields
48//! for depends_arch in srcinfo.makedepends() {
49//! for depend in depends_arch {
50//! match depends_arch.arch() {
51//! Some(arch) => println!("depend_{}: {}", arch, depend),
52//! None => println!("depend: {}", depend),
53//! }
54//! }
55//! }
56//!
57//! // Iterate through all the packages in this srcinfo
58//! for pkg in srcinfo.pkgs() {
59//! println!("pkg: {}", pkg.pkgname());
60//! }
61//!
62//! // Get a specific package from the .SRCINFO
63//! let pkg = srcinfo.pkg("libc++").unwrap();
64//! println!("pkg: {}", pkg.pkgname());
65//!
66//! // Get the architectures of the package (may differ from the global architecture)
67//! for arch in pkg.arch() {
68//! println!("{} arch: {}", pkg.pkgname(), arch);
69//! }
70//!
71//! // Get the depends of an x86_64 system
72//! // This includes the `depends` and `depends_x86_64` fields
73//! for depend in pkg.depends().arch("x86_64") {
74//! println!("depend: {}", depend);
75//! }
76//!
77//! // Convert the .SRCINFO back into a string
78//! // the new sring will semanticly match the original .SRCINFO
79//! // but field order and whitespace will change, comments will be removed
80//! let srcinfo = srcinfo.to_string();
81//! # Ok(())
82//! # }
83//! ```
84
85#![warn(missing_docs)]
86mod archvec;
87mod error;
88mod fmt;
89mod parse;
90mod srcinfo;
91
92pub use crate::archvec::*;
93pub use crate::error::*;
94pub use crate::srcinfo::*;