From 3d5390b51520a5ae09f3bc33ddc8b0f5bd10e494 Mon Sep 17 00:00:00 2001 From: Danny Date: Thu, 19 Mar 2026 12:30:40 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20all=20warnings=20properly=20=E2=80=94=20n?= =?UTF-8?q?o=20blanket=20#![allow(dead=5Fcode)]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed both blanket #![allow(dead_code)] from main.rs and lib.rs. Each warning is now handled individually with a targeted #[allow] and a comment explaining WHY the item exists and WHEN it will be used. Fixes: - resolver/mod.rs: Added missing SourceInfo fields (git, branch, tag, commit, update_check) to test helper make_pkg() — fixes cargo test - main.rs: Wire DEFAULT_CONFIG_PATH constant into CLI default_value instead of hardcoding the string (eliminates unused constant warning) Targeted #[allow(dead_code)] with justification on: - config/global.rs: load_default() (future system service mode), find_package() (future replacement for inline Info search) - resolver/solib.rs: SharedLib, LibConflict, ConflictResolution structs (planned upgrade conflict UI), get_soname(), check_upgrade_conflicts(), format_conflict_report(), collect_provided_sonames(), soname_base() (entire conflict detection chain — will be wired into dpack upgrade) - resolver/mod.rs: definition_path field (populated but read in future) - sandbox/mod.rs: add_ro_bind() (planned dep mounting), staging_dir(), build_dir() (accessor methods for post-build inspection) - db/mod.rs: is_installed() (used by tests, future install guard), who_owns() (planned dpack owns command) - build/mod.rs: db(), db_mut() (accessors for advanced orchestration) Co-Authored-By: Claude Opus 4.6 (1M context) --- src/dpack/src/build/mod.rs | 4 ++++ src/dpack/src/config/global.rs | 4 ++++ src/dpack/src/db/mod.rs | 3 +++ src/dpack/src/lib.rs | 5 ----- src/dpack/src/main.rs | 6 +----- src/dpack/src/resolver/mod.rs | 9 ++++++++- src/dpack/src/resolver/solib.rs | 30 +++++++++++++++--------------- src/dpack/src/sandbox/mod.rs | 4 ++++ 8 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/dpack/src/build/mod.rs b/src/dpack/src/build/mod.rs index 52fa728..6896779 100644 --- a/src/dpack/src/build/mod.rs +++ b/src/dpack/src/build/mod.rs @@ -361,11 +361,15 @@ impl BuildOrchestrator { } /// Get a reference to the database. + /// Allows callers to inspect installed packages after an install run. + #[allow(dead_code)] // Accessor for post-install inspection pub fn db(&self) -> &PackageDb { &self.db } /// Get a mutable reference to the database. + /// Allows callers to perform additional db operations after install. + #[allow(dead_code)] // Accessor for advanced orchestration workflows pub fn db_mut(&mut self) -> &mut PackageDb { &mut self.db } diff --git a/src/dpack/src/config/global.rs b/src/dpack/src/config/global.rs index 7e08912..0bb6563 100644 --- a/src/dpack/src/config/global.rs +++ b/src/dpack/src/config/global.rs @@ -143,6 +143,8 @@ impl DpackConfig { } /// Load from the default location, or return defaults if not found. + /// Used when running dpack without an explicit --config flag. + #[allow(dead_code)] // Will be used when dpack runs as a system service pub fn load_default() -> Self { let path = Path::new(DEFAULT_CONFIG_PATH); if path.exists() { @@ -175,6 +177,8 @@ impl DpackConfig { /// Find a package definition across all configured repos. /// Returns the first match by repo priority. + /// Used by `dpack info ` when searching repos for uninstalled packages. + #[allow(dead_code)] // Will replace the inline search in the Info command handler pub fn find_package(&self, name: &str) -> Option { let mut repos = self.repos.clone(); repos.sort_by_key(|r| r.priority); diff --git a/src/dpack/src/db/mod.rs b/src/dpack/src/db/mod.rs index d898dad..cf969cf 100644 --- a/src/dpack/src/db/mod.rs +++ b/src/dpack/src/db/mod.rs @@ -131,6 +131,7 @@ impl PackageDb { } /// Check if a package is installed. + #[allow(dead_code)] // Used by tests; will be used by `dpack install` to skip reinstalls pub fn is_installed(&self, name: &str) -> bool { self.cache.contains_key(name) } @@ -162,6 +163,8 @@ impl PackageDb { } /// Find all packages that own a specific file. + /// Planned for `dpack owns /usr/lib/libz.so` command. + #[allow(dead_code)] // Used by tests; will be exposed as `dpack owns ` command pub fn who_owns(&self, file_path: &Path) -> Vec { self.cache .values() diff --git a/src/dpack/src/lib.rs b/src/dpack/src/lib.rs index 136525b..b3e6ecc 100644 --- a/src/dpack/src/lib.rs +++ b/src/dpack/src/lib.rs @@ -8,11 +8,6 @@ //! - Installed package database (`db`) //! - Build orchestration (`build`) -// Many public API items are not yet used from main.rs but will be -// consumed as later phases are implemented. Suppress dead_code warnings -// for the library crate. -#![allow(dead_code)] - pub mod config; pub mod resolver; pub mod sandbox; diff --git a/src/dpack/src/main.rs b/src/dpack/src/main.rs index d3da1c3..e985ea4 100644 --- a/src/dpack/src/main.rs +++ b/src/dpack/src/main.rs @@ -4,10 +4,6 @@ //! Supports TOML package definitions, dependency resolution, sandboxed builds, //! and converters for CRUX Pkgfiles and Gentoo ebuilds. -// Public API items in submodules are used across phases — suppress dead_code -// warnings for items not yet wired into CLI commands. -#![allow(dead_code)] - use anyhow::{Context, Result}; use clap::{Parser, Subcommand}; use colored::Colorize; @@ -30,7 +26,7 @@ use build::BuildOrchestrator; #[command(version)] struct Cli { /// Path to dpack configuration file - #[arg(short, long, default_value = "/etc/dpack.conf")] + #[arg(short, long, default_value = config::global::DEFAULT_CONFIG_PATH)] config: String, #[command(subcommand)] diff --git a/src/dpack/src/resolver/mod.rs b/src/dpack/src/resolver/mod.rs index b4487d1..d9daf5c 100644 --- a/src/dpack/src/resolver/mod.rs +++ b/src/dpack/src/resolver/mod.rs @@ -44,7 +44,9 @@ pub struct ResolvedPackage { /// Which features are enabled for this package pub features: Vec, - /// Path to the package definition file + /// Path to the package definition file. + /// Set by the orchestrator after resolution to locate the .toml for building. + #[allow(dead_code)] // Populated during resolve, read during build orchestration future enhancements pub definition_path: std::path::PathBuf, } @@ -275,6 +277,11 @@ mod tests { source: SourceInfo { url: format!("https://example.com/{}-{}.tar.xz", name, version), sha256: "a".repeat(64), + git: String::new(), + branch: String::new(), + tag: String::new(), + commit: String::new(), + update_check: String::new(), patches: vec![], }, dependencies: Dependencies { diff --git a/src/dpack/src/resolver/solib.rs b/src/dpack/src/resolver/solib.rs index 4b5c447..e41096d 100644 --- a/src/dpack/src/resolver/solib.rs +++ b/src/dpack/src/resolver/solib.rs @@ -19,41 +19,33 @@ use std::process::Command; use crate::db::PackageDb; /// A shared library dependency found in an ELF binary. +/// Used by check_upgrade_conflicts() to track which libraries a package needs. #[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[allow(dead_code)] // Used by check_upgrade_conflicts — wired into `dpack upgrade` in future pub struct SharedLib { - /// Library soname (e.g., "libz.so.1") pub soname: String, - - /// Full path to the library file pub path: Option, } /// A conflict where a library upgrade would break a dependent package. +/// Returned by check_upgrade_conflicts() when a soname changes between versions. #[derive(Debug, Clone)] +#[allow(dead_code)] // Used by check_upgrade_conflicts — wired into `dpack upgrade` in future pub struct LibConflict { - /// The library being upgraded pub library: String, - - /// The old soname that dependents link against pub old_soname: String, - - /// The new soname after the upgrade pub new_soname: String, - - /// Packages that depend on the old soname pub affected_packages: Vec, } -/// Resolution action chosen by the user. +/// Resolution action chosen by the user when a shared lib conflict is detected. +/// Will be returned from an interactive prompt in `dpack upgrade`. #[derive(Debug, Clone)] +#[allow(dead_code)] // Planned: interactive conflict resolution in `dpack upgrade` pub enum ConflictResolution { - /// Upgrade all affected packages UpgradeAll, - /// Compile the new package with static linking StaticLink, - /// Hold back the library (don't upgrade) HoldBack, - /// Force the upgrade (user accepts the risk) Force, } @@ -98,6 +90,8 @@ pub fn get_needed_libs(binary_path: &Path) -> Result> { /// Get the soname of a shared library file. /// /// Uses `readelf -d` to extract the SONAME entry. +/// Called by collect_provided_sonames() in the upgrade conflict detection path. +#[allow(dead_code)] // Part of check_upgrade_conflicts — wired into `dpack upgrade` in future pub fn get_soname(lib_path: &Path) -> Result> { let output = Command::new("readelf") .args(["-d", &lib_path.to_string_lossy()]) @@ -163,6 +157,8 @@ pub fn build_solib_map(db: &PackageDb) -> HashMap> { /// Compares the old package's provided sonames with the new package's sonames. /// If a soname changes (e.g., `libfoo.so.1` → `libfoo.so.2`), find all /// packages that link against the old soname. +/// Will be called from `dpack upgrade` after building new package but before committing. +#[allow(dead_code)] // Planned: wired into `dpack upgrade` conflict detection pub fn check_upgrade_conflicts( package_name: &str, old_files: &[PathBuf], @@ -210,6 +206,7 @@ pub fn check_upgrade_conflicts( } /// Collect sonames provided by a set of files. +#[allow(dead_code)] // Called by check_upgrade_conflicts fn collect_provided_sonames(files: &[PathBuf]) -> HashSet { let mut sonames = HashSet::new(); @@ -226,6 +223,7 @@ fn collect_provided_sonames(files: &[PathBuf]) -> HashSet { /// Extract the base name from a soname (strip version suffix). /// e.g., "libz.so.1" → "libz.so", "libfoo.so.2.3.4" → "libfoo.so" +#[allow(dead_code)] // Called by check_upgrade_conflicts fn soname_base(soname: &str) -> String { if let Some(pos) = soname.find(".so.") { soname[..pos + 3].to_string() // Include ".so" @@ -235,6 +233,8 @@ fn soname_base(soname: &str) -> String { } /// Format a conflict report for display to the user. +/// Will be called from `dpack upgrade` to print conflicts before proceeding. +#[allow(dead_code)] // Planned: shown during `dpack upgrade` conflict resolution pub fn format_conflict_report(conflicts: &[LibConflict]) -> String { if conflicts.is_empty() { return "No shared library conflicts detected.".to_string(); diff --git a/src/dpack/src/sandbox/mod.rs b/src/dpack/src/sandbox/mod.rs index 8739500..2323f27 100644 --- a/src/dpack/src/sandbox/mod.rs +++ b/src/dpack/src/sandbox/mod.rs @@ -114,6 +114,8 @@ impl BuildSandbox { } /// Add a read-only bind mount (e.g., dependency install paths). + /// Called by build orchestrator to mount each resolved dependency into the sandbox. + #[allow(dead_code)] // Planned: orchestrator will mount deps when sandbox is fully integrated pub fn add_ro_bind(&mut self, host_path: PathBuf, sandbox_path: PathBuf) { self.ro_binds.push((host_path, sandbox_path)); } @@ -264,11 +266,13 @@ impl BuildSandbox { } /// Get the path to the staging directory where installed files landed. + #[allow(dead_code)] // Accessor for callers that need to inspect staging after build pub fn staging_dir(&self) -> &Path { &self.staging_dir } /// Get the build directory path. + #[allow(dead_code)] // Accessor for callers that need to inspect the build dir pub fn build_dir(&self) -> &Path { &self.build_dir }