Skip to content

Commit

Permalink
Merge branch 'colin/rust-dep-resolution'
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed May 20, 2022
2 parents 7824e38 + 0df72eb commit 5b4e231
Show file tree
Hide file tree
Showing 23 changed files with 1,086 additions and 649 deletions.
701 changes: 488 additions & 213 deletions rust/Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ members = [
# Core libraries
"aura-core", "aura-arch", "aura-common",
# Ecosystem libraries
"raur-curl", "r2d2-alpm"
"r2d2-alpm"
]

[profile.release]
lto = true
panic = "abort"
# opt-level = "z" # Reduces final stripped size by ~20%.
strip = true
opt-level = "z" # Reduces final stripped size by ~20%.
5 changes: 3 additions & 2 deletions rust/aura-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ edition = "2021"

[dependencies]
alpm = "2.2"
alpm-utils = "1.1"
alpm-utils = "2.0"
aura-arch = { path = "../aura-arch" }
chrono = { version = "0.4", features = ["serde"] }
disown = "1.0"
from_variants = "1.0"
itertools = "0.10"
log = "0.4"
nonempty = "0.7"
petgraph = { version = "0.6", default-features = false }
r2d2 = "0.8"
rayon = "1.5"
raur-curl = { path = "../raur-curl" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
srcinfo = "1.0"
Expand Down
38 changes: 15 additions & 23 deletions rust/aura-core/src/aur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@
pub mod dependencies;

use log::debug;
use raur_curl::Raur;
use std::borrow::Cow;
use std::path::{Path, PathBuf};

/// The base path of the URL.
pub const AUR_BASE_URL: &str = "https://aur.archlinux.org/";

/// AUR package information.
pub fn info<S>(packages: &[S]) -> Result<Vec<raur_curl::Package>, raur_curl::Error>
where
S: AsRef<str>,
{
raur_curl::Handle::new().info(packages)
}

/// Search the AUR for packages matching a query.
pub fn search(query: &str) -> Result<Vec<raur_curl::Package>, raur_curl::Error> {
raur_curl::Handle::new().search(query)
}

/// The result of inspecting the existance status of a collection of package
/// names.
pub struct PkgPartition<'a> {
Expand All @@ -37,18 +23,20 @@ pub struct PkgPartition<'a> {
/// Given a [`Path`] to an expected directory of AUR package repo clones, check
/// it and the AUR to determine which of a given collection of packages are
/// actually real.
pub fn partition_aur_pkgs<'a, S>(
pub fn partition_aur_pkgs<'a, S, F, E>(
fetch: &F,
clone_dir: &Path,
packages: &'a [S],
) -> Result<PkgPartition<'a>, raur_curl::Error>
) -> Result<PkgPartition<'a>, E>
where
S: AsRef<str>,
F: Fn(&str) -> Result<Vec<crate::faur::Package>, E>,
{
let (cloned, fast_bads): (Vec<Cow<'a, str>>, Vec<Cow<'a, str>>) = packages
.iter()
.map(|p| Cow::Borrowed(p.as_ref()))
.partition(|p| is_aur_package_fast(clone_dir, p));
let mut part = partition_real_pkgs_via_aur(clone_dir, fast_bads)?;
.partition(|p| has_local_aur_clone(clone_dir, p));
let mut part = partition_real_pkgs_via_aur(fetch, clone_dir, fast_bads)?;

part.cloned.extend(cloned);
Ok(part)
Expand All @@ -59,7 +47,7 @@ where
///
/// This of course isn't fool proof, since it doesn't consult the AUR, and thus
/// the caller should follow up with an AUR call if this returns `false`.
fn is_aur_package_fast(clone_dir: &Path, package: &str) -> bool {
fn has_local_aur_clone(clone_dir: &Path, package: &str) -> bool {
let mut path = clone_dir.to_path_buf();
path.push(package);
path.is_dir()
Expand All @@ -69,13 +57,17 @@ fn is_aur_package_fast(clone_dir: &Path, package: &str) -> bool {
//
// If this is ever made `pub`, switch it to a generic `S: AsRef<str>`.
/// Performs an AUR `info` call to determine which packages are real or not.
fn partition_real_pkgs_via_aur<'a>(
fn partition_real_pkgs_via_aur<'a, F, E>(
fetch: &F,
clone_dir: &Path,
packages: Vec<Cow<'a, str>>,
) -> Result<PkgPartition<'a>, raur_curl::Error> {
) -> Result<PkgPartition<'a>, E>
where
F: Fn(&str) -> Result<Vec<crate::faur::Package>, E>,
{
debug!("AUR call to check for: {:?}", packages);

let info: Vec<_> = info(&packages)?;
let info: Vec<_> = crate::faur::info(packages.iter().map(|cow| cow.as_ref()), fetch)?;

// First we need to determine which of the AUR-returned packages were
// actually "split" packages (i.e. those built as a child of another, like
Expand All @@ -86,7 +78,7 @@ fn partition_real_pkgs_via_aur<'a>(
// clones, so we need to recheck those.
let (pkgbase_cloned, pkgbase_to_clone): (Vec<_>, _) = splits
.into_iter()
.partition(|p| is_aur_package_fast(clone_dir, &p.package_base));
.partition(|p| has_local_aur_clone(clone_dir, &p.package_base));

// Anything else must not really exist.
let not_real = packages
Expand Down
Loading

0 comments on commit 5b4e231

Please sign in to comment.