Improve error output of wasm-builder when wasm ins't installed (#7105)

This improves the error message of wasm-builder when the wasm toolchain
isn't installed. Currently we print that the wasm toolchain is not
installed, but the actual problem is that there is a bug in the
packaging in rust. This will now be much easier to debug, by printing
the full error message of the compiler.
This commit is contained in:
Bastian Köcher
2020-09-15 11:42:23 +02:00
committed by GitHub
parent 3d94d80309
commit 9dd5812eaf
5 changed files with 46 additions and 12 deletions
+1
View File
@@ -8858,6 +8858,7 @@ dependencies = [
name = "substrate-wasm-builder"
version = "2.0.0"
dependencies = [
"ansi_term 0.12.1",
"atty",
"build-helper",
"cargo_metadata",
+1
View File
@@ -22,3 +22,4 @@ fs2 = "0.4.3"
wasm-gc-api = "0.1.11"
atty = "0.2.13"
itertools = "0.8.2"
ansi_term = "0.12.1"
+6 -1
View File
@@ -179,7 +179,7 @@ pub fn build_project_with_default_rustflags(
bloaty.wasm_binary_bloaty_path_escaped(),
)
};
write_file_if_changed(
file_name.into(),
format!(
@@ -309,3 +309,8 @@ impl CargoCommand {
.contains("-nightly")
}
}
/// Returns `true` when color output is enabled.
fn color_output_enabled() -> bool {
env::var(crate::WASM_BUILD_NO_COLOR).is_err()
}
@@ -18,14 +18,24 @@
use std::fs;
use tempfile::tempdir;
use ansi_term::Color;
/// Print an error message.
fn print_error_message(message: &str) -> String {
if super::color_output_enabled() {
Color::Red.bold().paint(message).to_string()
} else {
message.into()
}
}
/// Checks that all prerequisites are installed.
///
/// # Returns
/// Returns `None` if everything was found and `Some(ERR_MSG)` if something could not be found.
pub fn check() -> Option<&'static str> {
pub fn check() -> Option<String> {
if !check_nightly_installed(){
return Some("Rust nightly not installed, please install it!")
return Some(print_error_message("Rust nightly not installed, please install it!"))
}
check_wasm_toolchain_installed()
@@ -35,7 +45,7 @@ fn check_nightly_installed() -> bool {
crate::get_nightly_cargo().is_nightly()
}
fn check_wasm_toolchain_installed() -> Option<&'static str> {
fn check_wasm_toolchain_installed() -> Option<String> {
let temp = tempdir().expect("Creating temp dir does not fail; qed");
fs::create_dir_all(temp.path().join("src")).expect("Creating src dir does not fail; qed");
@@ -59,22 +69,39 @@ fn check_wasm_toolchain_installed() -> Option<&'static str> {
fs::write(&test_file, "pub fn test() {}")
.expect("Writing to the test file does not fail; qed");
let err_msg = "Rust WASM toolchain not installed, please install it!";
let err_msg = print_error_message("Rust WASM toolchain not installed, please install it!");
let manifest_path = manifest_path.display().to_string();
crate::get_nightly_cargo()
.command()
.args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path])
let mut build_cmd = crate::get_nightly_cargo().command();
build_cmd.args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path]);
if super::color_output_enabled() {
build_cmd.arg("--color=always");
}
build_cmd
.output()
.map_err(|_| err_msg)
.map_err(|_| err_msg.clone())
.and_then(|s|
if s.status.success() {
Ok(())
} else {
match String::from_utf8(s.stderr) {
Ok(ref err) if err.contains("linker `rust-lld` not found") => {
Err("`rust-lld` not found, please install it!")
Err(print_error_message("`rust-lld` not found, please install it!"))
},
_ => Err(err_msg)
Ok(ref err) => Err(
format!(
"{}\n\n{}\n{}\n{}{}\n",
err_msg,
Color::Yellow.bold().paint("Further error information:"),
Color::Yellow.bold().paint("-".repeat(60)),
err,
Color::Yellow.bold().paint("-".repeat(60)),
)
),
Err(_) => Err(err_msg),
}
}
)
@@ -449,7 +449,7 @@ fn build_project(project: &Path, default_rustflags: &str) {
// We don't want to call ourselves recursively
.env(crate::SKIP_BUILD_ENV, "");
if env::var(crate::WASM_BUILD_NO_COLOR).is_err() {
if super::color_output_enabled() {
build_cmd.arg("--color=always");
}