Skip to content

Commit a490498

Browse files
committed
Auto merge of #11694 - weihanglo:issue-11623, r=epage
`-Zrustdoc-scrape-example` must fail with bad build script
2 parents 389c03d + 0da332c commit a490498

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/cargo/core/compiler/rustdoc.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,24 @@ impl RustdocScrapeExamples {
211211
}
212212

213213
impl BuildContext<'_, '_> {
214-
/// Returns the set of Docscrape units that have a direct dependency on `unit`
214+
/// Returns the set of [`Docscrape`] units that have a direct dependency on `unit`.
215+
///
216+
/// [`RunCustomBuild`] units are excluded because we allow failures
217+
/// from type checks but not build script executions.
218+
/// A plain old `cargo doc` would just die if a build script execution fails,
219+
/// there is no reason for `-Zrustdoc-scrape-examples` to keep going.
220+
///
221+
/// [`Docscrape`]: crate::core::compiler::CompileMode::Docscrape
222+
/// [`RunCustomBuild`]: crate::core::compiler::CompileMode::Docscrape
215223
pub fn scrape_units_have_dep_on<'a>(&'a self, unit: &'a Unit) -> Vec<&'a Unit> {
216224
self.scrape_units
217225
.iter()
218226
.filter(|scrape_unit| {
219227
self.unit_graph[scrape_unit]
220228
.iter()
221-
.any(|dep| &dep.unit == unit)
229+
.any(|dep| &dep.unit == unit && !dep.unit.mode.is_run_custom_build())
222230
})
223-
.collect::<Vec<_>>()
231+
.collect()
224232
}
225233

226234
/// Returns true if this unit is needed for doing doc-scraping and is also

tests/testsuite/docscrape.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,37 @@ warning: `foo` (example \"ex2\") generated 1 warning
366366
.run();
367367
}
368368

369+
#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
370+
fn fail_bad_build_script() {
371+
// See rust-lang/cargo#11623
372+
let p = project()
373+
.file(
374+
"Cargo.toml",
375+
r#"
376+
[package]
377+
name = "foo"
378+
version = "0.0.1"
379+
"#,
380+
)
381+
.file("src/lib.rs", "")
382+
.file("build.rs", "fn main() { panic!(\"You shall not pass\")}")
383+
.file("examples/ex.rs", "fn main() {}")
384+
.build();
385+
386+
// `cargo doc` fails
387+
p.cargo("doc")
388+
.with_status(101)
389+
.with_stderr_contains("[..]You shall not pass[..]")
390+
.run();
391+
392+
// scrape examples should fail whenever `cargo doc` fails.
393+
p.cargo("doc -Zunstable-options -Z rustdoc-scrape-examples")
394+
.masquerade_as_nightly_cargo(&["rustdoc-scrape-examples"])
395+
.with_status(101)
396+
.with_stderr_contains("[..]You shall not pass[..]")
397+
.run();
398+
}
399+
369400
#[cargo_test(nightly, reason = "rustdoc scrape examples flags are unstable")]
370401
fn no_fail_bad_example() {
371402
let p = project()

0 commit comments

Comments
 (0)