Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some refactorings #380

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resolver = "2"
[workspace.package]
version = "0.24.7"
edition = "2021"
rust-version = "1.78"
rust-version = "1.80"

[workspace.dependencies]
blsforme = { git = "https://github.com/serpent-os/blsforme.git", rev = "ca69d21d41bd437640614de432f47ddb152c05bf" }
Expand Down Expand Up @@ -45,7 +45,6 @@ rayon = "1.10.0"
regex = "1.10.5"
reqwest = { version = "0.12.5", default-features = false, features = ["brotli", "charset", "deflate", "gzip", "http2", "rustls-tls", "stream", "zstd"] }
serde = { version = "1.0.204", features = ["derive"] }
serde_derive = "1.0.204"
serde_json = "1.0.120"
serde_yaml = "0.9.34"
sha2 = "0.10.8"
Expand All @@ -61,6 +60,12 @@ zstd = { version = "0.13.2", features = ["zstdmt"] }
mailparse = "0.15.0"
zbus = "5.1.1"

[workspace.lints.rust]
rust_2018_idioms = { level = "warn", priority = -1 }
semicolon_in_expressions_from_macros = "warn"
unused_import_braces = "warn"
unused_qualifications = "warn"

[profile.release]
lto = "thin"

Expand Down
3 changes: 3 additions & 0 deletions boulder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ thread-priority.workspace = true
tokio.workspace = true
url.workspace = true
mailparse.workspace = true

[lints]
workspace = true
2 changes: 1 addition & 1 deletion boulder/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ fn logged(
is_pgo: bool,
command: &str,
f: impl FnOnce(&mut process::Command) -> &mut process::Command,
) -> Result<process::ExitStatus, io::Error> {
) -> io::Result<process::ExitStatus> {
let mut command = process::Command::new(command);

f(&mut command);
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/build/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn clean(builder: &Builder) -> Result<(), Error> {
}
}

Ok(()) as Result<_, io::Error>
Ok(()) as io::Result<_>
})?;

// Now we can safely recreate the rootfs
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use clap_complete::{
shells::{Bash, Fish, Zsh},
};
use clap_mangen::Man;
use std::fs::{self, File};
use fs_err::{self as fs, File};
use thiserror::Error;

mod build;
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/cli/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn handle(command: Command, env: Env) -> Result<(), Error> {

child.wait()?;

Ok(()) as Result<_, io::Error>
Ok(()) as io::Result<_>
})?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/cli/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn handle(command: Command, env: Env) -> Result<(), Error> {
}
}

pub fn list(manager: profile::Manager) -> Result<(), Error> {
pub fn list(manager: profile::Manager<'_>) -> Result<(), Error> {
if manager.profiles.is_empty() {
println!("No profiles have been configured yet");
return Ok(());
Expand Down
22 changes: 11 additions & 11 deletions boulder/src/cli/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,20 @@ fn macros(_macro: Option<String>, env: Env) -> Result<(), Error> {

match _macro {
Some(name) => {
if let Some(action) = items
let Some(action) = items
.into_iter()
.find(|a| a.name == format!("%{name}") || a.name == format!("%({name})"))
{
println!("{} - {}", action.name.bold(), action.description);

if let Some(example) = action.example {
println!("\n{}", "Example:".bold());
for line in example.lines() {
println!(" {line}");
}
}
} else {
else {
return Err(Error::MacroNotFound(name));
};

println!("{} - {}", action.name.bold(), action.description);

if let Some(example) = action.example {
println!("\n{}", "Example:".bold());
for line in example.lines() {
println!(" {line}");
}
}
}
None => {
Expand Down
4 changes: 2 additions & 2 deletions boulder/src/draft/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl System {
}
}

fn process(&self, state: &mut State, file: &File) -> Result<(), Error> {
fn process(&self, state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {
match self {
System::Autotools => autotools::process(state, file),
System::Cargo => cargo::process(state, file),
Expand Down Expand Up @@ -126,7 +126,7 @@ pub struct Analysis {

/// Analyze the provided paths to determine which build [`System`]
/// the project uses and any dependencies that are identified
pub fn analyze(files: &[File]) -> Result<Analysis, Error> {
pub fn analyze(files: &[File<'_>]) -> Result<Analysis, Error> {
let mut dependencies = BTreeSet::new();
let mut confidences = BTreeMap::new();

Expand Down
4 changes: 2 additions & 2 deletions boulder/src/draft/build/autotools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn phases() -> Phases {
}
}

pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
pub fn process(state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {
// Depth too great
if file.depth() > 0 {
return Ok(());
Expand All @@ -39,7 +39,7 @@ pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
Ok(())
}

fn scan_autotools(state: &mut State, path: &Path) -> Result<(), Error> {
fn scan_autotools(state: &mut State<'_>, path: &Path) -> Result<(), Error> {
let regex_pkgconfig =
Regex::new(r"PKG_CHECK_MODULES\s?\(\s?\[([A-Za-z_]+)\s?\]\s?,\s?\[\s?(\s?[A-Za-z0-9\-_+]+)\s?]")?;

Expand Down
2 changes: 1 addition & 1 deletion boulder/src/draft/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn phases() -> Phases {
}
}

pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
pub fn process(state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {
if file.file_name() == "Cargo.toml" {
state.increment_confidence(100);
}
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/draft/build/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn phases() -> Phases {
}
}

pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
pub fn process(state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {
// Depth too great
if file.depth() > 0 {
return Ok(());
Expand Down
4 changes: 2 additions & 2 deletions boulder/src/draft/build/meson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn phases() -> Phases {
}
}

pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
pub fn process(state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {
match file.file_name() {
"meson.build" if file.depth() == 0 => {
state.increment_confidence(100);
Expand All @@ -34,7 +34,7 @@ pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
Ok(())
}

fn scan_meson(state: &mut State, path: &Path) -> Result<(), Error> {
fn scan_meson(state: &mut State<'_>, path: &Path) -> Result<(), Error> {
let regex_dependency = Regex::new(r"dependency\s?\(\s?'\s?([A-Za-z0-9+-_]+)")?;
let regex_program = Regex::new(r"find_program\s?\(\s?'\s?([A-Za-z0-9+-_]+)")?;

Expand Down
4 changes: 2 additions & 2 deletions boulder/src/draft/build/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod pep517 {
}
}

pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
pub fn process(state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {
match file.file_name() {
"pyproject.toml" | "setup.cfg" => state.increment_confidence(100),
_ => {}
Expand All @@ -38,7 +38,7 @@ pub mod setup_tools {
}
}

pub fn process(state: &mut State, file: &File) -> Result<(), Error> {
pub fn process(state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {
if file.file_name() == "setup.py" {
state.increment_confidence(100);
}
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ fn resolve_packages(
Ok(packages)
}

pub fn sync_artefacts(paths: &Paths) -> Result<(), io::Error> {
pub fn sync_artefacts(paths: &Paths) -> io::Result<()> {
for path in util::enumerate_files(&paths.artefacts().host, |_| true)? {
let filename = path.file_name().and_then(|p| p.to_str()).unwrap_or_default();

Expand Down
12 changes: 6 additions & 6 deletions boulder/src/package/analysis/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ use super::{BoxError, BucketMut, Decision, Response};

mod elf;

pub fn include_any(_bucket: &mut BucketMut, _info: &mut PathInfo) -> Result<Response, BoxError> {
pub fn include_any(_bucket: &mut BucketMut<'_>, _info: &mut PathInfo) -> Result<Response, BoxError> {
Ok(Decision::IncludeFile.into())
}

pub fn ignore_blocked(_bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
pub fn ignore_blocked(_bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
// non-/usr = bad
if !info.target_path.starts_with("/usr") {
return Ok(Decision::IgnoreFile {
Expand All @@ -41,7 +41,7 @@ pub fn ignore_blocked(_bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Re
Ok(Decision::NextHandler.into())
}

pub fn binary(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
pub fn binary(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
if info.target_path.starts_with("/usr/bin") {
let provider = Provider {
kind: dependency::Kind::Binary,
Expand All @@ -59,7 +59,7 @@ pub fn binary(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, B
Ok(Decision::NextHandler.into())
}

pub fn pkg_config(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
pub fn pkg_config(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
let file_name = info.file_name();

if !info.has_component("pkgconfig") || !file_name.ends_with(".pc") {
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn pkg_config(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Respons
Ok(Decision::NextHandler.into())
}

pub fn python(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
pub fn python(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
let file_path = info.path.clone().into_os_string().into_string().unwrap_or_default();
let is_dist_info = file_path.contains(".dist-info") && info.file_name().ends_with("METADATA");
let is_egg_info = file_path.contains(".egg-info") && info.file_name().ends_with("PKG-INFO");
Expand Down Expand Up @@ -181,7 +181,7 @@ pub fn python(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, B
Ok(Decision::NextHandler.into())
}

pub fn cmake(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
pub fn cmake(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
let file_name = info.file_name();

if (!file_name.ends_with("Config.cmake") && !file_name.ends_with("-config.cmake"))
Expand Down
10 changes: 5 additions & 5 deletions boulder/src/package/analysis/handler/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ compile_error!(
"feature \"compat_dlang_emul_both\" and feature \"compat_dlang_emul_flush\" cannot be enabled at the same time"
);

pub fn elf(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
pub fn elf(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
let file_name = info.file_name();

if file_name.ends_with(".debug") && info.has_component("debug") {
Expand Down Expand Up @@ -91,7 +91,7 @@ fn parse_elf(path: &Path) -> Result<elf::ElfStream<AnyEndian, File>, BoxError> {

fn parse_dynamic_section(
elf: &mut elf::ElfStream<AnyEndian, File>,
bucket: &mut BucketMut,
bucket: &mut BucketMut<'_>,
machine_isa: &str,
bit_size: Class,
info: &PathInfo,
Expand Down Expand Up @@ -292,7 +292,7 @@ fn parse_dynamic_section(
}
}

fn parse_interp_section(elf: &mut elf::ElfStream<AnyEndian, File>, bucket: &mut BucketMut, machine_isa: &str) {
fn parse_interp_section(elf: &mut elf::ElfStream<AnyEndian, File>, bucket: &mut BucketMut<'_>, machine_isa: &str) {
let Some(section) = elf.section_header_by_name(".interp").ok().flatten().copied() else {
return;
};
Expand Down Expand Up @@ -330,7 +330,7 @@ fn parse_build_id(elf: &mut elf::ElfStream<AnyEndian, File>) -> Option<String> {
}

fn split_debug(
bucket: &BucketMut,
bucket: &BucketMut<'_>,
info: &PathInfo,
bit_size: Class,
build_id: &str,
Expand Down Expand Up @@ -381,7 +381,7 @@ fn split_debug(
Ok(Some(debug_info_path))
}

fn strip(bucket: &BucketMut, info: &PathInfo) -> Result<(), BoxError> {
fn strip(bucket: &BucketMut<'_>, info: &PathInfo) -> Result<(), BoxError> {
if !bucket.recipe.parsed.options.strip {
return Ok(());
}
Expand Down
4 changes: 2 additions & 2 deletions boulder/src/package/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Ord for Package<'_> {
}
}

pub fn emit(paths: &Paths, recipe: &Recipe, packages: &[Package]) -> Result<(), Error> {
pub fn emit(paths: &Paths, recipe: &Recipe, packages: &[Package<'_>]) -> Result<(), Error> {
let mut manifest = Manifest::new(paths, recipe, architecture::host());

println!("Packaging");
Expand All @@ -136,7 +136,7 @@ pub fn emit(paths: &Paths, recipe: &Recipe, packages: &[Package]) -> Result<(),
Ok(())
}

fn emit_package(paths: &Paths, package: &Package) -> Result<(), Error> {
fn emit_package(paths: &Paths, package: &Package<'_>) -> Result<(), Error> {
let filename = package.filename();

// Filter for all files -> dedupe by hash -> sort largest to smallest
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/package/emit/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a> Manifest<'a> {
}
}

pub fn add_package(&mut self, package: &'a Package) {
pub fn add_package(&mut self, package: &'a Package<'_>) {
self.packages.insert(package);
}

Expand Down
2 changes: 1 addition & 1 deletion boulder/src/package/emit/manifest/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use stone::{
use super::Error;
use crate::package::emit::Package;

pub fn write(path: &Path, packages: &BTreeSet<&Package>, build_deps: &BTreeSet<String>) -> Result<(), Error> {
pub fn write(path: &Path, packages: &BTreeSet<&Package<'_>>, build_deps: &BTreeSet<String>) -> Result<(), Error> {
let mut output = File::create(path)?;

let mut writer = stone::Writer::new(&mut output, FileType::BuildManifest)?;
Expand Down
2 changes: 1 addition & 1 deletion boulder/src/package/emit/manifest/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{package::emit, Recipe};
pub fn write(
path: &Path,
recipe: &Recipe,
packages: &BTreeSet<&emit::Package>,
packages: &BTreeSet<&emit::Package<'_>>,
build_deps: &BTreeSet<String>,
) -> Result<(), Error> {
let packages = packages
Expand Down
Loading
Loading