Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better pre build errors #2586

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use rustwide::logging::{self, LogStorage};
use rustwide::toolchain::ToolchainError;
use rustwide::{AlternativeRegistry, Build, Crate, Toolchain, Workspace, WorkspaceBuilder};
use std::collections::{HashMap, HashSet};
use std::fmt::Display;
use std::fs;
use std::path::Path;
use std::sync::Arc;
Expand All @@ -36,6 +37,28 @@ const COMPONENTS: &[&str] = &["llvm-tools-preview", "rustc-dev", "rustfmt"];
const DUMMY_CRATE_NAME: &str = "empty-library";
const DUMMY_CRATE_VERSION: &str = "1.0.0";

#[derive(thiserror::Error, Debug)]
struct CommandErrorWithOutput {
#[source]
err: CommandError,
output: String,
}

impl Display for CommandErrorWithOutput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}\nCaptured output: {}", self.err, self.output)
}
}

fn capture_error_output(cmd: Command) -> Result<(), CommandErrorWithOutput> {
let storage = LogStorage::new(log::LevelFilter::Info);
let result = logging::capture(&storage, || cmd.log_output(true).run());
result.map_err(|err| CommandErrorWithOutput {
err,
output: storage.to_string(),
})
}

fn get_configured_toolchain(conn: &mut Client) -> Result<Toolchain> {
let name: String = get_config(conn, ConfigName::Toolchain)?.unwrap_or_else(|| "nightly".into());

Expand Down Expand Up @@ -482,17 +505,19 @@ impl RustwideBuilder {
std::fs::remove_file(cargo_lock)?;
{
let _span = info_span!("cargo_generate_lockfile").entered();
Command::new(&self.workspace, self.toolchain.cargo())
.cd(build.host_source_dir())
.args(&["generate-lockfile"])
.run()?;
capture_error_output(
Command::new(&self.workspace, self.toolchain.cargo())
.cd(build.host_source_dir())
.args(&["generate-lockfile"]),
)?;
}
{
let _span = info_span!("cargo fetch --locked").entered();
Command::new(&self.workspace, self.toolchain.cargo())
.cd(build.host_source_dir())
.args(&["fetch", "--locked"])
.run()?;
capture_error_output(
Command::new(&self.workspace, self.toolchain.cargo())
.cd(build.host_source_dir())
.args(&["fetch", "--locked"]),
)?;
}
res =
self.execute_build(default_target, true, build, &limits, &metadata, false)?;
Expand Down
Loading