From 26fbe2f219a6c28fa42f481267b3c2c6c9d0107b Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 26 Jun 2019 16:51:40 +0200 Subject: [PATCH] Use proper logging --- Cargo.toml | 2 ++ src/main.rs | 19 ++++++------------- src/static_libs.rs | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a403ed55..5ed2f698 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,8 @@ name = "cargo-cbuild" path = "src/main.rs" [dependencies] +log = "0.4" +pretty_env_logger = "0.3.0" cargo_metadata = "0.7" structopt = "0.2" regex = "1" diff --git a/src/main.rs b/src/main.rs index b7984aef..2e678fce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; use cargo_metadata::{MetadataCommand, Package}; use structopt::StructOpt; +use log::*; mod pkg_config_gen; mod static_libs; @@ -278,11 +279,9 @@ impl Config { f.read_to_end(&mut s).ok()?; - println!("bi {}", std::str::from_utf8(&s).unwrap()); - let t = toml::from_slice::(&s).unwrap(); - println!("{}", t.hash); + info!("saved build hash {}", t.hash); Some(t) } @@ -412,7 +411,7 @@ impl Config { for line in self.shared_object_link_args() { cmd.arg("-C").arg(&format!("link-arg={}", line)); } - println!("{:?}", cmd); + info!("build_library {:?}", cmd); let out = cmd.output()?; @@ -435,7 +434,7 @@ impl Config { .map(|cap| cap.get(1).unwrap().as_str()).unwrap() .to_owned(); - println!("{}", hash); + info!("parsed hash {}", hash); Ok(Some(BuildInfo { hash })) } else { @@ -487,8 +486,6 @@ impl Config { let name = &self.name; let ver = &self.pkg.version; - println!("destdir {}", self.destdir.display()); - let install_path_lib = append_to_destdir(&self.destdir, &self.libdir); let install_path_pc = install_path_lib.join("pkg-config"); let install_path_include = append_to_destdir(&self.destdir, &self.includedir).join(name); @@ -497,14 +494,9 @@ impl Config { fs::create_dir_all(&install_path_pc)?; fs::create_dir_all(&install_path_include)?; - println!("{:?}", install_path_pc); - fs::copy(&build_targets.pc, install_path_pc.join(&format!("{}.pc", name)))?; fs::copy(&build_targets.include, install_path_include.join(&format!("{}.h", name)))?; - println!("{:?}", build_targets.include); - fs::copy(&build_targets.static_lib, install_path_lib.join(&format!("lib{}.a", name)))?; - println!("{:?}", build_targets.static_lib); let link_libs = |lib: &str, lib_with_major_ver: &str, lib_with_full_ver: &str| { @@ -549,6 +541,7 @@ impl Config { } fn main() -> Result<(), std::io::Error> { + pretty_env_logger::init(); let opts = Opt::from_args(); match opts.cmd { @@ -562,7 +555,7 @@ fn main() -> Result<(), std::io::Error> { let info = cfg.build()?; let build_targets = BuildTargets::new(&cfg, &info.hash); - println!("{:?}", build_targets); + info!("{:?}", build_targets); cfg.install(build_targets)?; } diff --git a/src/static_libs.rs b/src/static_libs.rs index f1043a18..6fb31476 100644 --- a/src/static_libs.rs +++ b/src/static_libs.rs @@ -27,7 +27,7 @@ pub fn get_static_libs_for_target>(target: Option, let out = cmd.output()?; - println!("{:?} {:?}", cmd, out); + log::info!("native-static-libs check {:?} {:?}", cmd, out); if out.status.success() { let re = Regex::new(r"note: native-static-libs: (.+)").unwrap();