Skip to content

Commit

Permalink
Replace slog with log
Browse files Browse the repository at this point in the history
This commit replaces the `slog` family of crates used by `wasm-pack`
with the `log` crate plus `env_logger`. This also means that by default
`wasm-pack` also won't create a `wasm-pack.log` file in the current
directory. Enabling logging will now be done through
`RUST_LOG=wasm_pack` instead of `-v` flags.

Closes rustwasm#425
  • Loading branch information
alexcrichton committed Nov 5, 2018
1 parent 91e3de3 commit 95aaf87
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 399 deletions.
153 changes: 63 additions & 90 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ cargo_metadata = "0.6.0"
console = "0.6.1"
curl = "0.4.13"
dirs = "1.0.4"
env_logger = { version = "0.5.13", default-features = false }
failure = "0.1.2"
flate2 = "1.0.2"
hex = "0.3"
human-panic = "1.0.1"
indicatif = "0.9.0"
lazy_static = "1.1.0"
log = "0.4.6"
openssl = { version = '0.10.11', optional = true }
parking_lot = "0.6"
serde = "1.0.74"
serde_derive = "1.0.74"
serde_json = "1.0.26"
siphasher = "0.2.3"
slog = "2.3"
slog-term = "2.4"
slog-async = "2.3"
structopt = "0.2"
tar = "0.4.16"
toml = "0.4"
Expand Down
24 changes: 9 additions & 15 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use cargo_metadata;
use child;
use emoji;
use failure::{self, ResultExt};
use log::{info, warn};
use progressbar::Step;
use slog::Logger;
use log::debug;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand All @@ -25,7 +26,6 @@ pub fn install_wasm_bindgen(
version: &str,
install_permitted: bool,
step: &Step,
log: &Logger,
) -> Result<Download, failure::Error> {
// If `wasm-bindgen` is installed globally and it has the right version, use
// that. Assume that other tools are installed next to it.
Expand All @@ -34,11 +34,10 @@ pub fn install_wasm_bindgen(
// `cargo install`, for example.
if let Ok(path) = which("wasm-bindgen") {
debug!(
log,
"found global wasm-bindgen binary at: {}",
path.display()
);
if wasm_bindgen_version_check(&path, version, log) {
if wasm_bindgen_version_check(&path, version) {
return Ok(Download::at(path.parent().unwrap()));
}
}
Expand All @@ -51,14 +50,13 @@ pub fn install_wasm_bindgen(
Ok(dl) => return Ok(dl),
Err(e) => {
warn!(
log,
"could not download pre-built `wasm-bindgen`: {}. Falling back to `cargo install`.",
e
);
}
}

cargo_install_wasm_bindgen(log, &cache, version, install_permitted)
cargo_install_wasm_bindgen(&cache, version, install_permitted)
}

/// Downloads a precompiled copy of wasm-bindgen, if available.
Expand Down Expand Up @@ -101,7 +99,6 @@ fn prebuilt_url(version: &str) -> Option<String> {
/// Use `cargo install` to install the `wasm-bindgen` CLI locally into the given
/// crate.
pub fn cargo_install_wasm_bindgen(
logger: &Logger,
cache: &Cache,
version: &str,
install_permitted: bool,
Expand Down Expand Up @@ -131,7 +128,7 @@ pub fn cargo_install_wasm_bindgen(
.arg("--root")
.arg(&tmp);

child::run(logger, cmd, "cargo install").context("Installing wasm-bindgen with cargo")?;
child::run(cmd, "cargo install").context("Installing wasm-bindgen with cargo")?;

fs::rename(&tmp, &destination)?;
Ok(Download::at(&destination))
Expand All @@ -148,7 +145,6 @@ pub fn wasm_bindgen_build(
target: &str,
debug: bool,
step: &Step,
log: &Logger,
) -> Result<(), failure::Error> {
let msg = format!("{}Running WASM-bindgen...", emoji::RUNNER);
PBAR.step(step, &msg);
Expand Down Expand Up @@ -192,26 +188,24 @@ pub fn wasm_bindgen_build(
cmd.arg("--debug");
}

child::run(log, cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?;
child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?;
Ok(())
}

/// Check if the `wasm-bindgen` dependency is locally satisfied.
fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str, log: &Logger) -> bool {
fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str) -> bool {
let mut cmd = Command::new(bindgen_path);
cmd.arg("--version");
child::run(log, cmd, "wasm-bindgen")
child::run(cmd, "wasm-bindgen")
.map(|stdout| {
stdout
.trim()
.split_whitespace()
.nth(1)
.map(|v| {
info!(
log,
"Checking installed `wasm-bindgen` version == expected version: {} == {}",
v,
dep_version
v, dep_version
);
v == dep_version
})
Expand Down
23 changes: 6 additions & 17 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use emoji;
use error::Error;
use failure::ResultExt;
use progressbar::Step;
use slog::Logger;
use std::path::Path;
use std::process::Command;
use std::str;
Expand Down Expand Up @@ -57,23 +56,17 @@ fn rustc_minor_version() -> Option<u32> {

/// Ensure that `rustup` has the `wasm32-unknown-unknown` target installed for
/// current toolchain
pub fn rustup_add_wasm_target(log: &Logger, step: &Step) -> Result<(), failure::Error> {
pub fn rustup_add_wasm_target(step: &Step) -> Result<(), failure::Error> {
let msg = format!("{}Adding WASM target...", emoji::TARGET);
PBAR.step(step, &msg);
let mut cmd = Command::new("rustup");
cmd.arg("target").arg("add").arg("wasm32-unknown-unknown");
child::run(log, cmd, "rustup")
.context("Adding the wasm32-unknown-unknown target with rustup")?;
child::run(cmd, "rustup").context("Adding the wasm32-unknown-unknown target with rustup")?;
Ok(())
}

/// Run `cargo build` targetting `wasm32-unknown-unknown`.
pub fn cargo_build_wasm(
log: &Logger,
path: &Path,
debug: bool,
step: &Step,
) -> Result<(), failure::Error> {
pub fn cargo_build_wasm(path: &Path, debug: bool, step: &Step) -> Result<(), failure::Error> {
let msg = format!("{}Compiling to WASM...", emoji::CYCLONE);
PBAR.step(step, &msg);
let mut cmd = Command::new("cargo");
Expand All @@ -82,22 +75,18 @@ pub fn cargo_build_wasm(
cmd.arg("--release");
}
cmd.arg("--target").arg("wasm32-unknown-unknown");
child::run(log, cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?;
child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?;
Ok(())
}

/// Run `cargo build --tests` targetting `wasm32-unknown-unknown`.
pub fn cargo_build_wasm_tests(
log: &Logger,
path: &Path,
debug: bool,
) -> Result<(), failure::Error> {
pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), failure::Error> {
let mut cmd = Command::new("cargo");
cmd.current_dir(path).arg("build").arg("--tests");
if !debug {
cmd.arg("--release");
}
cmd.arg("--target").arg("wasm32-unknown-unknown");
child::run(log, cmd, "cargo build").context("Compilation of your program failed")?;
child::run(cmd, "cargo build").context("Compilation of your program failed")?;
Ok(())
}
14 changes: 5 additions & 9 deletions src/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use error::Error;
use failure;
use slog::Logger;
use log::info;
use std::{
io::{self, Read},
mem, process, string,
Expand Down Expand Up @@ -116,12 +116,8 @@ where
}

/// Run the given command and return its stdout.
pub fn run(
logger: &Logger,
mut command: process::Command,
command_name: &str,
) -> Result<String, failure::Error> {
info!(logger, "Running {:?}", command);
pub fn run(mut command: process::Command, command_name: &str) -> Result<String, failure::Error> {
info!("Running {:?}", command);

let mut child = command
.stdout(process::Stdio::piped())
Expand All @@ -145,11 +141,11 @@ pub fn run(
thread::spawn(move || read_and_send(stderr, stderr_send, OutputFragment::Stderr));

let mut stdout = OutputAccumulator::new(|line| {
info!(logger, "{} (stdout): {}", command_name, line);
info!("{} (stdout): {}", command_name, line);
PBAR.message(line)
});
let mut stderr = OutputAccumulator::new(|line| {
info!(logger, "{} (stderr): {}", command_name, line);
info!("{} (stderr): {}", command_name, line);
PBAR.message(line)
});

Expand Down
Loading

0 comments on commit 95aaf87

Please sign in to comment.