Skip to content

Commit

Permalink
do not display message to enable debuginfo when it's already enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Jan 31, 2023
1 parent 9d9b7fe commit 7ccda69
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
let targets_fresh = targets.clone();

let env_profile_name = unit.profile.name.to_uppercase();
let built_with_debuginfo = cx
.bcx
.unit_graph
.get(unit)
.and_then(|deps| deps.iter().find(|dep| dep.unit.target == unit.target))
.map(|dep| dep.unit.profile.debuginfo.is_turned_on())
.unwrap_or(false);

// Prepare the unit of "dirty work" which will actually run the custom build
// command.
Expand Down Expand Up @@ -412,9 +419,10 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
format!("failed to run custom build command for `{}`", pkg_descr);

// If we're opting into backtraces, mention that build dependencies' backtraces can
// be improved by setting a higher debuginfo level.
// be improved by requesting debuginfo to be built, if we're not building with
// debuginfo already.
if let Ok(show_backtraces) = std::env::var("RUST_BACKTRACE") {
if show_backtraces != "0" {
if !built_with_debuginfo && show_backtraces != "0" {
build_error_context.push_str(&format!(
"\n\
note: To improve backtraces for build dependencies, set the \
Expand Down
37 changes: 37 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,43 @@ Caused by:
.run();
}

#[cargo_test]
fn custom_build_script_failed_backtraces_message_with_debuginfo() {
// This is the same test as `custom_build_script_failed_backtraces_message` above, this time
// ensuring that the message dedicated to improving backtraces by requesting debuginfo is not
// shown when debuginfo is already turned on.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.5.0"
authors = ["wycats@example.com"]
build = "build.rs"
"#,
)
.file("src/main.rs", "fn main() {}")
.file("build.rs", "fn main() { std::process::exit(101); }")
.build();
p.cargo("build -v")
.env("RUST_BACKTRACE", "1")
.env("CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG", "true")
.with_status(101)
.with_stderr(
"\
[COMPILING] foo v0.5.0 ([CWD])
[RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin [..]`
[RUNNING] `[..]/build-script-build`
[ERROR] failed to run custom build command for `foo v0.5.0 ([CWD])`
Caused by:
process didn't exit successfully: `[..]/build-script-build` (exit [..]: 101)",
)
.run();
}

#[cargo_test]
fn custom_build_env_vars() {
let p = project()
Expand Down

0 comments on commit 7ccda69

Please sign in to comment.