Skip to content

Commit 7ccda69

Browse files
committed
do not display message to enable debuginfo when it's already enabled
1 parent 9d9b7fe commit 7ccda69

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
333333
let targets_fresh = targets.clone();
334334

335335
let env_profile_name = unit.profile.name.to_uppercase();
336+
let built_with_debuginfo = cx
337+
.bcx
338+
.unit_graph
339+
.get(unit)
340+
.and_then(|deps| deps.iter().find(|dep| dep.unit.target == unit.target))
341+
.map(|dep| dep.unit.profile.debuginfo.is_turned_on())
342+
.unwrap_or(false);
336343

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

414421
// If we're opting into backtraces, mention that build dependencies' backtraces can
415-
// be improved by setting a higher debuginfo level.
422+
// be improved by requesting debuginfo to be built, if we're not building with
423+
// debuginfo already.
416424
if let Ok(show_backtraces) = std::env::var("RUST_BACKTRACE") {
417-
if show_backtraces != "0" {
425+
if !built_with_debuginfo && show_backtraces != "0" {
418426
build_error_context.push_str(&format!(
419427
"\n\
420428
note: To improve backtraces for build dependencies, set the \

tests/testsuite/build_script.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,43 @@ Caused by:
102102
.run();
103103
}
104104

105+
#[cargo_test]
106+
fn custom_build_script_failed_backtraces_message_with_debuginfo() {
107+
// This is the same test as `custom_build_script_failed_backtraces_message` above, this time
108+
// ensuring that the message dedicated to improving backtraces by requesting debuginfo is not
109+
// shown when debuginfo is already turned on.
110+
let p = project()
111+
.file(
112+
"Cargo.toml",
113+
r#"
114+
[package]
115+
116+
name = "foo"
117+
version = "0.5.0"
118+
authors = ["[email protected]"]
119+
build = "build.rs"
120+
"#,
121+
)
122+
.file("src/main.rs", "fn main() {}")
123+
.file("build.rs", "fn main() { std::process::exit(101); }")
124+
.build();
125+
p.cargo("build -v")
126+
.env("RUST_BACKTRACE", "1")
127+
.env("CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG", "true")
128+
.with_status(101)
129+
.with_stderr(
130+
"\
131+
[COMPILING] foo v0.5.0 ([CWD])
132+
[RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin [..]`
133+
[RUNNING] `[..]/build-script-build`
134+
[ERROR] failed to run custom build command for `foo v0.5.0 ([CWD])`
135+
136+
Caused by:
137+
process didn't exit successfully: `[..]/build-script-build` (exit [..]: 101)",
138+
)
139+
.run();
140+
}
141+
105142
#[cargo_test]
106143
fn custom_build_env_vars() {
107144
let p = project()

0 commit comments

Comments
 (0)