remove slog and slog_term

This commit is contained in:
tensor-programming 2019-08-07 18:27:37 -04:00
parent d049fd38bc
commit d775323b2c
6 changed files with 46 additions and 74 deletions

View File

@ -213,8 +213,6 @@ dependencies = [
"serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-term 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"target_build_utils 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1780,23 +1778,6 @@ name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "slog"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "slog-term"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "smallvec"
version = "0.6.10"
@ -1899,16 +1880,6 @@ dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "term"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -2586,8 +2557,6 @@ dependencies = [
"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d"
"checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum slog 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1cc9c640a4adbfbcc11ffb95efe5aa7af7309e002adab54b185507dbf2377b99"
"checksum slog-term 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cb9b3fd9a3c2c86580fce3558a98ed7c69039da0288b08a3f15b371635254e08"
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55"
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
@ -2601,7 +2570,6 @@ dependencies = [
"checksum target_build_utils 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "013d134ae4a25ee744ad6129db589018558f620ddfa44043887cdd45fa08e75c"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
"checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1"
"checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"

View File

@ -31,11 +31,9 @@ toml = "0.4"
uuid = { version = "0.5", features = ["v5"] }
walkdir = "2"
slog-term = "2.4.1"
sha2 = "0.8"
lazy_static = "1.3"
handlebars = "1.1"
slog = "2.5.2"
reqwest = "0.9.19"
hex = "0.3"
zip = "0.5"

View File

@ -189,6 +189,25 @@ pub fn print_warning(message: &str) -> crate::Result<()> {
}
}
/// Prints a Info message to stderr.
pub fn print_info(message: &str) -> crate::Result<()> {
if let Some(mut output) = term::stderr() {
safe_term_attr(&mut output, term::Attr::Bold)?;
output.fg(term::color::GREEN)?;
write!(output, "Info:")?;
output.reset()?;
write!(output, " {}\n", message)?;
output.flush()?;
Ok(())
} else {
let mut output = io::stderr();
write!(output, "Info:")?;
write!(output, " {}\n", message)?;
output.flush()?;
Ok(())
}
}
/// Prints an error to stderr, in the same format that `cargo` uses.
pub fn print_error(error: &crate::Error) -> crate::Result<()> {
if let Some(mut output) = term::stderr() {

View File

@ -3,9 +3,6 @@ use super::common;
use super::settings::Settings;
use super::wix;
use crate::ResultExt;
use slog::Drain;
use slog_term;
use std;
use std::collections::BTreeMap;
@ -44,17 +41,14 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
collect_resource_info(settings).chain_err(|| "Failed to collect resource file information")?;
let _directories = collect_directory_info(settings, &mut resources)
.chain_err(|| "Failed to collect resource directory information")?;
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::CompactFormat::new(decorator).build();
let drain = std::sync::Mutex::new(drain).fuse();
let logger = slog::Logger::root(drain, o!());
let wix_path = PathBuf::from("./WixTools");
if !wix_path.exists() {
wix::get_and_extract_wix(&logger, &wix_path)?;
wix::get_and_extract_wix(&wix_path)?;
}
let msi_path = wix::build_wix_app_installer(&logger, &settings, &wix_path)?;
let msi_path = wix::build_wix_app_installer(&settings, &wix_path)?;
Ok(vec![msi_path])
}

View File

@ -1,9 +1,9 @@
use super::common;
use super::settings::Settings;
use handlebars::Handlebars;
use lazy_static::lazy_static;
use sha2::Digest;
use slog::info;
use slog::Logger;
use std::collections::BTreeMap;
use std::fs::{create_dir_all, remove_dir_all, write, File};
use std::io::{BufRead, BufReader, Cursor, Read, Write};
@ -47,8 +47,8 @@ lazy_static! {
};
}
fn download_and_verify(logger: &Logger, url: &str, hash: &str) -> Result<Vec<u8>, String> {
info!(logger, "Downloading {}", url);
fn download_and_verify(url: &str, hash: &str) -> crate::Result<Vec<u8>> {
common::print_info(format!("Downloading {}", url).as_str())?;
let mut response = reqwest::get(url).or_else(|e| Err(e.to_string()))?;
@ -58,7 +58,7 @@ fn download_and_verify(logger: &Logger, url: &str, hash: &str) -> Result<Vec<u8>
.read_to_end(&mut data)
.or_else(|e| Err(e.to_string()))?;
info!(logger, "validating hash...");
common::print_info("validating hash")?;
let mut hasher = sha2::Sha256::new();
hasher.input(&data);
@ -69,7 +69,7 @@ fn download_and_verify(logger: &Logger, url: &str, hash: &str) -> Result<Vec<u8>
if expected_hash == url_hash {
Ok(data)
} else {
Err("hash mismatch of downloaded file".to_string())
Err(crate::Error::from("hash mismatch of downloaded file"))
}
}
@ -83,7 +83,7 @@ fn app_installer_dir(settings: &Settings) -> PathBuf {
))
}
fn extract_zip(data: &Vec<u8>, path: &Path) -> Result<(), String> {
fn extract_zip(data: &Vec<u8>, path: &Path) -> crate::Result<()> {
let cursor = Cursor::new(data);
let mut zipa = ZipArchive::new(cursor).or_else(|e| Err(e.to_string()))?;
@ -114,12 +114,12 @@ fn generate_package_guid(settings: &Settings) -> Uuid {
Uuid::new_v5(&namespace, &settings.bundle_identifier())
}
pub fn get_and_extract_wix(logger: &Logger, path: &Path) -> Result<(), String> {
info!(logger, "downloading WIX Toolkit...");
pub fn get_and_extract_wix(path: &Path) -> crate::Result<()> {
common::print_info("Verifying wix package")?;
let data = download_and_verify(logger, WIX_URL, WIX_SHA256)?;
let data = download_and_verify(WIX_URL, WIX_SHA256)?;
info!(logger, "extracting WIX");
common::print_info("extracting WIX")?;
extract_zip(&data, path)
}
@ -127,7 +127,6 @@ pub fn get_and_extract_wix(logger: &Logger, path: &Path) -> Result<(), String> {
// For if bundler needs DLL files.
// fn run_heat_exe(
// logger: &Logger,
// wix_toolset_path: &Path,
// build_path: &Path,
// harvest_dir: &Path,
@ -179,11 +178,10 @@ pub fn get_and_extract_wix(logger: &Logger, path: &Path) -> Result<(), String> {
fn run_candle(
settings: &Settings,
logger: &Logger,
wix_toolset_path: &Path,
build_path: &Path,
wxs_file_name: &str,
) -> Result<(), String> {
) -> crate::Result<()> {
let arch = "x64";
let args = vec![
@ -194,7 +192,7 @@ fn run_candle(
];
let candle_exe = wix_toolset_path.join("candle.exe");
info!(logger, "running candle for {}", wxs_file_name);
common::print_info(format!("running candle for {}", wxs_file_name).as_str())?;
let mut cmd = Command::new(&candle_exe)
.args(&args)
@ -207,7 +205,7 @@ fn run_candle(
let reader = BufReader::new(stdout);
for line in reader.lines() {
info!(logger, "{}", line.unwrap());
common::print_info(line.unwrap().as_str())?;
}
}
@ -215,17 +213,16 @@ fn run_candle(
if status.success() {
Ok(())
} else {
Err("error running candle.exe".to_string())
Err(crate::Error::from("error running candle.exe"))
}
}
fn run_light(
logger: &Logger,
wix_toolset_path: &Path,
build_path: &Path,
wixobjs: &[&str],
output_path: &Path,
) -> Result<PathBuf, String> {
) -> crate::Result<PathBuf> {
let light_exe = wix_toolset_path.join("light.exe");
let mut args: Vec<String> = vec!["-o".to_string(), output_path.display().to_string()];
@ -234,7 +231,7 @@ fn run_light(
args.push(p.to_string());
}
info!(logger, "running light to produce {}", output_path.display());
common::print_info(format!("running light to produce {}", output_path.display()).as_str())?;
let mut cmd = Command::new(&light_exe)
.args(&args)
@ -247,7 +244,7 @@ fn run_light(
let reader = BufReader::new(stdout);
for line in reader.lines() {
info!(logger, "{}", line.unwrap());
common::print_info(line.unwrap().as_str())?;
}
}
@ -255,18 +252,18 @@ fn run_light(
if status.success() {
Ok(output_path.to_path_buf())
} else {
Err("error running light.exe".to_string())
Err(crate::Error::from("error running light.exe"))
}
}
pub fn build_wix_app_installer(
logger: &Logger,
settings: &Settings,
wix_toolset_path: &Path,
) -> Result<PathBuf, String> {
) -> crate::Result<PathBuf> {
let arch = "x64";
info!(logger, "Target: {}", arch);
common::print_warning("Only x64 supported");
// target only supports x64.
// common::print_info(format!("Target: {}", arch).as_str());
let output_path = settings.project_out_directory().join("wix").join(arch);
@ -311,12 +308,11 @@ pub fn build_wix_app_installer(
for basename in &input_basenames {
let wxs = format!("{}.wxs", basename);
run_candle(settings, logger, &wix_toolset_path, &output_path, &wxs)?;
run_candle(settings, &wix_toolset_path, &output_path, &wxs)?;
}
let wixobjs = vec!["main.wixobj"];
let target = run_light(
logger,
&wix_toolset_path,
&output_path,
&wixobjs,

View File

@ -10,9 +10,6 @@ extern crate serde_derive;
#[cfg(test)]
extern crate tempfile;
#[macro_use]
extern crate slog;
mod bundle;
use crate::bundle::{bundle_project, BuildArtifact, PackageType, Settings};