Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 41d163c

Browse files
authoredMay 6, 2024
Rollup merge of rust-lang#124753 - GuillaumeGomez:migrate-rustdoc-determinism, r=jieyouxu
Migrate `run-make/rustdoc-error-lines` to new `rmake.rs` Part of rust-lang#121876. There was a weird naming inconsistency with `input`/`output`. A few tests write `.arg("-o").arg(path)` and the `output` method was actually the command output. So instead, I renamed the original `output` into `command_output` so that I could create the `output` method with the expected effect (and updated the tests to use it too). EDIT: The first two commits come from rust-lang#124711. Some weird things happened recently pparently. ^^' r? ``@jieyouxu``
2 parents e7365d1 + bb474aa commit 41d163c

File tree

16 files changed

+109
-60
lines changed

16 files changed

+109
-60
lines changed
 

‎src/tools/run-make-support/src/cc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Cc {
7373
}
7474

7575
/// Get the [`Output`][::std::process::Output] of the finished process.
76-
pub fn output(&mut self) -> ::std::process::Output {
76+
pub fn command_output(&mut self) -> ::std::process::Output {
7777
self.cmd.output().expect("failed to get output of finished process")
7878
}
7979
}

‎src/tools/run-make-support/src/clang.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Clang {
7272
}
7373

7474
/// Get the [`Output`][::std::process::Output] of the finished process.
75-
pub fn output(&mut self) -> ::std::process::Output {
75+
pub fn command_output(&mut self) -> ::std::process::Output {
7676
self.cmd.output().expect("failed to get output of finished process")
7777
}
7878
}

‎src/tools/run-make-support/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn set_host_rpath(cmd: &mut Command) {
164164
///
165165
/// impl CommandWrapper {
166166
/// /// Get the [`Output`][::std::process::Output] of the finished process.
167-
/// pub fn output(&mut self) -> Output { /* ... */ } // <- required `output()` method
167+
/// pub fn command_output(&mut self) -> Output { /* ... */ } // <- required `command_output()` method
168168
/// }
169169
///
170170
/// crate::impl_common_helpers!(CommandWrapper);
@@ -242,7 +242,7 @@ macro_rules! impl_common_helpers {
242242
let caller_location = ::std::panic::Location::caller();
243243
let caller_line_number = caller_location.line();
244244

245-
let output = self.output();
245+
let output = self.command_output();
246246
if !output.status.success() {
247247
handle_failed_output(&self.cmd, output, caller_line_number);
248248
}
@@ -255,7 +255,7 @@ macro_rules! impl_common_helpers {
255255
let caller_location = ::std::panic::Location::caller();
256256
let caller_line_number = caller_location.line();
257257

258-
let output = self.output();
258+
let output = self.command_output();
259259
if output.status.success() {
260260
handle_failed_output(&self.cmd, output, caller_line_number);
261261
}

‎src/tools/run-make-support/src/llvm_readobj.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl LlvmReadobj {
4444

4545
/// Get the [`Output`][::std::process::Output] of the finished process.
4646
#[track_caller]
47-
pub fn output(&mut self) -> ::std::process::Output {
47+
pub fn command_output(&mut self) -> ::std::process::Output {
4848
self.cmd.output().expect("failed to get output of finished process")
4949
}
5050
}

‎src/tools/run-make-support/src/rustc.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ impl Rustc {
9191
self
9292
}
9393

94+
/// Specify path to the output file.
95+
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
96+
self.cmd.arg("-o");
97+
self.cmd.arg(path.as_ref());
98+
self
99+
}
100+
94101
/// This flag defers LTO optimizations to the linker.
95102
pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self {
96103
self.cmd.arg(format!("-Clinker-plugin-lto={option}"));
@@ -171,7 +178,7 @@ impl Rustc {
171178

172179
/// Get the [`Output`][::std::process::Output] of the finished process.
173180
#[track_caller]
174-
pub fn output(&mut self) -> ::std::process::Output {
181+
pub fn command_output(&mut self) -> ::std::process::Output {
175182
// let's make sure we piped all the input and outputs
176183
self.cmd.stdin(Stdio::piped());
177184
self.cmd.stdout(Stdio::piped());
@@ -196,7 +203,7 @@ impl Rustc {
196203
let caller_location = std::panic::Location::caller();
197204
let caller_line_number = caller_location.line();
198205

199-
let output = self.output();
206+
let output = self.command_output();
200207
if output.status.code().unwrap() != code {
201208
handle_failed_output(&self.cmd, output, caller_line_number);
202209
}

‎src/tools/run-make-support/src/rustdoc.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ impl Rustdoc {
5151
self
5252
}
5353

54+
/// Specify path to the output folder.
55+
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
56+
self.cmd.arg("-o");
57+
self.cmd.arg(path.as_ref());
58+
self
59+
}
60+
5461
/// Specify output directory.
5562
pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
5663
self.cmd.arg("--out-dir").arg(path.as_ref());
@@ -73,7 +80,7 @@ impl Rustdoc {
7380

7481
/// Get the [`Output`][::std::process::Output] of the finished process.
7582
#[track_caller]
76-
pub fn output(&mut self) -> ::std::process::Output {
83+
pub fn command_output(&mut self) -> ::std::process::Output {
7784
// let's make sure we piped all the input and outputs
7885
self.cmd.stdin(Stdio::piped());
7986
self.cmd.stdout(Stdio::piped());
@@ -93,12 +100,19 @@ impl Rustdoc {
93100
}
94101
}
95102

103+
/// Specify the edition year.
104+
pub fn edition(&mut self, edition: &str) -> &mut Self {
105+
self.cmd.arg("--edition");
106+
self.cmd.arg(edition);
107+
self
108+
}
109+
96110
#[track_caller]
97111
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
98112
let caller_location = std::panic::Location::caller();
99113
let caller_line_number = caller_location.line();
100114

101-
let output = self.output();
115+
let output = self.command_output();
102116
if output.status.code().unwrap() != code {
103117
handle_failed_output(&self.cmd, output, caller_line_number);
104118
}

‎src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ run-make/dep-graph/Makefile
4444
run-make/dep-info-doesnt-run-much/Makefile
4545
run-make/dep-info-spaces/Makefile
4646
run-make/dep-info/Makefile
47-
run-make/doctests-runtool/Makefile
4847
run-make/dump-ice-to-disk/Makefile
4948
run-make/dump-mono-stats/Makefile
5049
run-make/duplicate-output-flavors/Makefile
@@ -245,7 +244,6 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile
245244
run-make/rlib-format-packed-bundled-libs/Makefile
246245
run-make/rmeta-preferred/Makefile
247246
run-make/rustc-macro-dep-files/Makefile
248-
run-make/rustdoc-error-lines/Makefile
249247
run-make/rustdoc-io-error/Makefile
250248
run-make/rustdoc-map-file/Makefile
251249
run-make/rustdoc-output-path/Makefile

‎tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fn main() {
1313
let mut stable_path = PathBuf::from(env!("TMPDIR"));
1414
stable_path.push("libstable.rmeta");
1515

16-
let output = rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).output();
16+
let output =
17+
rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).command_output();
1718

1819
let stderr = String::from_utf8_lossy(&output.stderr);
1920
let version = include_str!(concat!(env!("S"), "/src/version"));

‎tests/run-make/doctests-runtool/Makefile

-20
This file was deleted.
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Tests behavior of rustdoc `--runtool`.
2+
3+
use run_make_support::{rustc, rustdoc, tmp_dir};
4+
use std::env::current_dir;
5+
use std::fs::{create_dir, remove_dir_all};
6+
use std::path::PathBuf;
7+
8+
fn mkdir(name: &str) -> PathBuf {
9+
let dir = tmp_dir().join(name);
10+
create_dir(&dir).expect("failed to create doctests folder");
11+
dir
12+
}
13+
14+
// Behavior with --runtool with relative paths and --test-run-directory.
15+
fn main() {
16+
let run_dir_name = "rundir";
17+
let run_dir = mkdir(run_dir_name);
18+
let run_tool = mkdir("runtool");
19+
let run_tool_binary = run_tool.join("runtool");
20+
21+
rustc().input("t.rs").crate_type("rlib").run();
22+
rustc().input("runtool.rs").output(&run_tool_binary).run();
23+
24+
rustdoc()
25+
.input(current_dir().unwrap().join("t.rs"))
26+
.arg("-Zunstable-options")
27+
.arg("--test")
28+
.arg("--test-run-directory")
29+
.arg(run_dir_name)
30+
.arg("--runtool")
31+
.arg(&run_tool_binary)
32+
.arg("--extern")
33+
.arg("t=libt.rlib")
34+
.current_dir(tmp_dir())
35+
.run();
36+
37+
remove_dir_all(run_dir);
38+
remove_dir_all(run_tool);
39+
}

‎tests/run-make/exit-code/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
.arg("compile-error.rs")
1616
.run_fail_assert_exit_code(101);
1717

18-
rustdoc().arg("success.rs").arg("-o").arg(tmp_dir().join("exit-code")).run();
18+
rustdoc().arg("success.rs").output(tmp_dir().join("exit-code")).run();
1919

2020
rustdoc().arg("--invalid-arg-foo").run_fail_assert_exit_code(1);
2121

‎tests/run-make/repr128-dwarf/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::rc::Rc;
1010

1111
fn main() {
1212
let output = tmp_dir().join("repr128");
13-
rustc().input("main.rs").arg("-o").arg(&output).arg("-Cdebuginfo=2").run();
13+
rustc().input("main.rs").output(&output).arg("-Cdebuginfo=2").run();
1414
// Mach-O uses packed debug info
1515
let dsym_location = output
1616
.with_extension("dSYM")
+12-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
use run_make_support::{diff, rustc, rustdoc, tmp_dir};
1+
// Assert that the search index is generated deterministically, regardless of the
2+
// order that crates are documented in.
3+
4+
use run_make_support::{diff, rustdoc, tmp_dir};
25

3-
/// Assert that the search index is generated deterministically, regardless of the
4-
/// order that crates are documented in.
56
fn main() {
6-
let dir_first = tmp_dir().join("first");
7-
rustdoc().out_dir(&dir_first).input("foo.rs").run();
8-
rustdoc().out_dir(&dir_first).input("bar.rs").run();
7+
let foo_first = tmp_dir().join("foo_first");
8+
rustdoc().input("foo.rs").output(&foo_first).run();
9+
rustdoc().input("bar.rs").output(&foo_first).run();
910

10-
let dir_second = tmp_dir().join("second");
11-
rustdoc().out_dir(&dir_second).input("bar.rs").run();
12-
rustdoc().out_dir(&dir_second).input("foo.rs").run();
11+
let bar_first = tmp_dir().join("bar_first");
12+
rustdoc().input("bar.rs").output(&bar_first).run();
13+
rustdoc().input("foo.rs").output(&bar_first).run();
1314

1415
diff()
15-
.expected_file(dir_first.join("search-index.js"))
16-
.actual_file(dir_second.join("search-index.js"))
16+
.expected_file(foo_first.join("search-index.js"))
17+
.actual_file(bar_first.join("search-index.js"))
1718
.run();
1819
}

‎tests/run-make/rustdoc-error-lines/Makefile

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Assert that the search index is generated deterministically, regardless of the
2+
// order that crates are documented in.
3+
4+
use run_make_support::rustdoc;
5+
6+
fn main() {
7+
let output =
8+
String::from_utf8(rustdoc().input("input.rs").arg("--test").command_output().stdout)
9+
.unwrap();
10+
11+
let should_contain = &[
12+
"input.rs - foo (line 5)",
13+
"input.rs:7:15",
14+
"input.rs - bar (line 15)",
15+
"input.rs:17:15",
16+
"input.rs - bar (line 24)",
17+
"input.rs:26:15",
18+
];
19+
for text in should_contain {
20+
assert!(output.contains(text), "output doesn't contains {:?}", text);
21+
}
22+
}

‎tests/run-make/wasm-abi/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn run(file: &Path, method: &str, expected_output: &str) {
2525
.arg("--invoke")
2626
.arg(method)
2727
.arg(file)
28-
.output()
28+
.command_output()
2929
.unwrap();
3030
assert!(output.status.success());
3131
assert_eq!(expected_output, String::from_utf8_lossy(&output.stdout));

0 commit comments

Comments
 (0)
Failed to load comments.