summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-15 11:51:38 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-15 11:53:08 +0200
commit8a3114b773372bd5f2ddce8af516006d567441a0 (patch)
treee7b2e914eaade02c96023faefd6c1d17d086b5d5
parentbb9c31f30ded4c886659331ad6afe1dab5a8bd06 (diff)
Add more debug information for Package type
This patch adds a possibility to print the Package object with more detailed information. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/package/package.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/package/package.rs b/src/package/package.rs
index 5343d21..69a2e1c 100644
--- a/src/package/package.rs
+++ b/src/package/package.rs
@@ -128,6 +128,13 @@ impl Package {
.chain(runtime_iter)
.unique_by(|res| res.as_ref().ok().cloned())
}
+
+ /// Get a wrapper object around self which implements a debug interface with all details about
+ /// the Package object
+ #[cfg(debug_assertions)]
+ pub fn debug_details<'a>(&'a self) -> DebugPackage<'a> {
+ DebugPackage(self)
+ }
}
impl std::fmt::Debug for Package {
@@ -145,6 +152,65 @@ impl std::fmt::Debug for Package {
}
}
+/// Helper type for printing debug information about a package with much more details than the
+/// Debug impl for Package provides.
+#[cfg(debug_assertions)]
+pub struct DebugPackage<'a>(&'a Package);
+
+#[cfg(debug_assertions)]
+impl<'a> std::fmt::Debug for DebugPackage<'a> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
+ writeln!(f, "Package({name} {version} ({semver}))",
+ name = self.0.name,
+ version = self.0.version,
+ semver = if self.0.version_is_semver { "is semver" } else { "not semver" })?;
+
+ writeln!(f, "\tSources = ")?;
+ self.0.sources.iter().try_for_each(|(k, v)| writeln!(f, "\t\t{name} = (Url = {url}, Hash = {hash} ({hasht}), {dl})",
+ name = k,
+ url = v.url(),
+ hash = v.hash().value(),
+ hasht = v.hash().hashtype(),
+ dl = if *v.download_manually() { "manual download" } else { "automatic download" },
+ ))?;
+
+ writeln!(f, "\tBuild Dependencies = ")?;
+ self.0.dependencies.build.iter().try_for_each(|d| writeln!(f, "\t\t{:?}", d))?;
+
+ writeln!(f, "\tRuntime Dependencies = ")?;
+ self.0.dependencies.runtime.iter().try_for_each(|r| writeln!(f, "\t\t{:?}", r))?;
+
+ writeln!(f, "\tPatches = ")?;
+ self.0.patches.iter().try_for_each(|p| writeln!(f, "\t\t{}", p.display()))?;
+
+ writeln!(f, "\tEnvironment = ")?;
+ self.0.environment
+ .as_ref()
+ .map(|hm| hm.iter().try_for_each(|(k, v)| writeln!(f, "\t\t{:?} = {}", k, v)))
+ .transpose()?;
+
+ writeln!(f, "\tAllowed Images = ")?;
+
+ self.0.allowed_images
+ .as_ref()
+ .map(|v| v.iter().try_for_each(|i| writeln!(f, "\t\t{:?}", i)))
+ .transpose()?;
+
+ writeln!(f, "\tDenied Images = ")?;
+ self.0.denied_images
+ .as_ref()
+ .map(|v| v.iter().try_for_each(|i| writeln!(f, "\t\t{:?}", i)))
+ .transpose()?;
+
+ writeln!(f, "\tPhases = ")?;
+ self.0.phases
+ .iter()
+ .try_for_each(|(k, _)| writeln!(f, "\t\t{:?} = ...", k))?;
+
+ Ok(())
+ }
+}
+
impl PartialEq for Package {
fn eq(&self, other: &Package) -> bool {
(self.name(), self.version()).eq(&(other.name(), other.version()))