Skip to content

Commit 7ce937f

Browse files
authored
Rollup merge of #95836 - workingjubilee:doctest-exe, r=notriddle
Use `rust_out{exe_suffix}` for doctests This was mentioned as an issue to me by ````@bruxisma.```` There are 3 separate instances where "rust_out" can become part of the name of a Rust executable, so I am mostly just hoping that this fixes the problem, given that the other sites which it can slip in seem to be well-behaved.
2 parents df04d28 + 47ddca6 commit 7ce937f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/librustdoc/doctest.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_span::edition::Edition;
1919
use rustc_span::source_map::SourceMap;
2020
use rustc_span::symbol::sym;
2121
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
22-
use rustc_target::spec::TargetTriple;
22+
use rustc_target::spec::{Target, TargetTriple};
2323
use tempfile::Builder as TempFileBuilder;
2424

2525
use std::env;
@@ -293,6 +293,16 @@ struct UnusedExterns {
293293
unused_extern_names: Vec<String>,
294294
}
295295

296+
fn add_exe_suffix(input: String, target: &TargetTriple) -> String {
297+
let exe_suffix = match target {
298+
TargetTriple::TargetTriple(_) => Target::expect_builtin(target).options.exe_suffix,
299+
TargetTriple::TargetJson { contents, .. } => {
300+
Target::from_json(contents.parse().unwrap()).unwrap().0.options.exe_suffix
301+
}
302+
};
303+
input + &exe_suffix
304+
}
305+
296306
fn run_test(
297307
test: &str,
298308
crate_name: &str,
@@ -313,7 +323,9 @@ fn run_test(
313323
let (test, line_offset, supports_color) =
314324
make_test(test, Some(crate_name), lang_string.test_harness, opts, edition, Some(test_id));
315325

316-
let output_file = outdir.path().join("rust_out");
326+
// Make sure we emit well-formed executable names for our target.
327+
let rust_out = add_exe_suffix("rust_out".to_owned(), &target);
328+
let output_file = outdir.path().join(rust_out);
317329

318330
let rustc_binary = rustdoc_options
319331
.test_builder

src/test/run-make/coverage-reports/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ include clear_expected_if_blessed
132132
--instr-profile="$(TMPDIR)"/[email protected] \
133133
$(call BIN,"$(TMPDIR)"/$@) \
134134
$$( \
135-
for file in $(TMPDIR)/rustdoc-$@/*/rust_out; do \
135+
for file in $(TMPDIR)/rustdoc-$@/*/rust_out*; do \
136136
[ -x "$$file" ] && printf "%s %s " -object $$file; \
137137
done \
138138
) \

0 commit comments

Comments
 (0)