Skip to content

Commit

Permalink
Auto merge of #124753 - GuillaumeGomez:migrate-rustdoc-determinism, r…
Browse files Browse the repository at this point in the history
…=jieyouxu

Migrate `run-make/rustdoc-error-lines` to new `rmake.rs`

Part of #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 #124711. Some weird things happened recently pparently. ^^'

r? `@jieyouxu`
  • Loading branch information
bors committed May 6, 2024
2 parents 8cef37d + 34fe217 commit 25e3949
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Cc {
}

/// Get the [`Output`][::std::process::Output] of the finished process.
pub fn output(&mut self) -> ::std::process::Output {
pub fn command_output(&mut self) -> ::std::process::Output {
self.cmd.output().expect("failed to get output of finished process")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Clang {
}

/// Get the [`Output`][::std::process::Output] of the finished process.
pub fn output(&mut self) -> ::std::process::Output {
pub fn command_output(&mut self) -> ::std::process::Output {
self.cmd.output().expect("failed to get output of finished process")
}
}
6 changes: 3 additions & 3 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn set_host_rpath(cmd: &mut Command) {
///
/// impl CommandWrapper {
/// /// Get the [`Output`][::std::process::Output] of the finished process.
/// pub fn output(&mut self) -> Output { /* ... */ } // <- required `output()` method
/// pub fn command_output(&mut self) -> Output { /* ... */ } // <- required `command_output()` method
/// }
///
/// crate::impl_common_helpers!(CommandWrapper);
Expand Down Expand Up @@ -242,7 +242,7 @@ macro_rules! impl_common_helpers {
let caller_location = ::std::panic::Location::caller();
let caller_line_number = caller_location.line();

let output = self.output();
let output = self.command_output();
if !output.status.success() {
handle_failed_output(&self.cmd, output, caller_line_number);
}
Expand All @@ -255,7 +255,7 @@ macro_rules! impl_common_helpers {
let caller_location = ::std::panic::Location::caller();
let caller_line_number = caller_location.line();

let output = self.output();
let output = self.command_output();
if output.status.success() {
handle_failed_output(&self.cmd, output, caller_line_number);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/llvm_readobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl LlvmReadobj {

/// Get the [`Output`][::std::process::Output] of the finished process.
#[track_caller]
pub fn output(&mut self) -> ::std::process::Output {
pub fn command_output(&mut self) -> ::std::process::Output {
self.cmd.output().expect("failed to get output of finished process")
}
}
11 changes: 9 additions & 2 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ impl Rustc {
self
}

/// Specify path to the output file.
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("-o");
self.cmd.arg(path.as_ref());
self
}

/// This flag defers LTO optimizations to the linker.
pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self {
self.cmd.arg(format!("-Clinker-plugin-lto={option}"));
Expand Down Expand Up @@ -171,7 +178,7 @@ impl Rustc {

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

let output = self.output();
let output = self.command_output();
if output.status.code().unwrap() != code {
handle_failed_output(&self.cmd, output, caller_line_number);
}
Expand Down
18 changes: 16 additions & 2 deletions src/tools/run-make-support/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ impl Rustdoc {
self
}

/// Specify path to the output folder.
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("-o");
self.cmd.arg(path.as_ref());
self
}

/// Specify output directory.
pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("--out-dir").arg(path.as_ref());
Expand All @@ -73,7 +80,7 @@ impl Rustdoc {

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

/// Specify the edition year.
pub fn edition(&mut self, edition: &str) -> &mut Self {
self.cmd.arg("--edition");
self.cmd.arg(edition);
self
}

#[track_caller]
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();

let output = self.output();
let output = self.command_output();
if output.status.code().unwrap() != code {
handle_failed_output(&self.cmd, output, caller_line_number);
}
Expand Down
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ run-make/dep-graph/Makefile
run-make/dep-info-doesnt-run-much/Makefile
run-make/dep-info-spaces/Makefile
run-make/dep-info/Makefile
run-make/doctests-runtool/Makefile
run-make/dump-ice-to-disk/Makefile
run-make/dump-mono-stats/Makefile
run-make/duplicate-output-flavors/Makefile
Expand Down Expand Up @@ -245,7 +244,6 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/rmeta-preferred/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/rustdoc-error-lines/Makefile
run-make/rustdoc-io-error/Makefile
run-make/rustdoc-map-file/Makefile
run-make/rustdoc-output-path/Makefile
Expand Down
3 changes: 2 additions & 1 deletion tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fn main() {
let mut stable_path = PathBuf::from(env!("TMPDIR"));
stable_path.push("libstable.rmeta");

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

let stderr = String::from_utf8_lossy(&output.stderr);
let version = include_str!(concat!(env!("S"), "/src/version"));
Expand Down
20 changes: 0 additions & 20 deletions tests/run-make/doctests-runtool/Makefile

This file was deleted.

39 changes: 39 additions & 0 deletions tests/run-make/doctests-runtool/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Tests behavior of rustdoc `--runtool`.

use run_make_support::{rustc, rustdoc, tmp_dir};
use std::env::current_dir;
use std::fs::{create_dir, remove_dir_all};
use std::path::PathBuf;

fn mkdir(name: &str) -> PathBuf {
let dir = tmp_dir().join(name);
create_dir(&dir).expect("failed to create doctests folder");
dir
}

// Behavior with --runtool with relative paths and --test-run-directory.
fn main() {
let run_dir_name = "rundir";
let run_dir = mkdir(run_dir_name);
let run_tool = mkdir("runtool");
let run_tool_binary = run_tool.join("runtool");

rustc().input("t.rs").crate_type("rlib").run();
rustc().input("runtool.rs").output(&run_tool_binary).run();

rustdoc()
.input(current_dir().unwrap().join("t.rs"))
.arg("-Zunstable-options")
.arg("--test")
.arg("--test-run-directory")
.arg(run_dir_name)
.arg("--runtool")
.arg(&run_tool_binary)
.arg("--extern")
.arg("t=libt.rlib")
.current_dir(tmp_dir())
.run();

remove_dir_all(run_dir);
remove_dir_all(run_tool);
}
2 changes: 1 addition & 1 deletion tests/run-make/exit-code/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
.arg("compile-error.rs")
.run_fail_assert_exit_code(101);

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/repr128-dwarf/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::rc::Rc;

fn main() {
let output = tmp_dir().join("repr128");
rustc().input("main.rs").arg("-o").arg(&output).arg("-Cdebuginfo=2").run();
rustc().input("main.rs").output(&output).arg("-Cdebuginfo=2").run();
// Mach-O uses packed debug info
let dsym_location = output
.with_extension("dSYM")
Expand Down
23 changes: 12 additions & 11 deletions tests/run-make/rustdoc-determinism/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use run_make_support::{diff, rustc, rustdoc, tmp_dir};
// Assert that the search index is generated deterministically, regardless of the
// order that crates are documented in.

use run_make_support::{diff, rustdoc, tmp_dir};

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

let dir_second = tmp_dir().join("second");
rustdoc().out_dir(&dir_second).input("bar.rs").run();
rustdoc().out_dir(&dir_second).input("foo.rs").run();
let bar_first = tmp_dir().join("bar_first");
rustdoc().input("bar.rs").output(&bar_first).run();
rustdoc().input("foo.rs").output(&bar_first).run();

diff()
.expected_file(dir_first.join("search-index.js"))
.actual_file(dir_second.join("search-index.js"))
.expected_file(foo_first.join("search-index.js"))
.actual_file(bar_first.join("search-index.js"))
.run();
}
13 changes: 0 additions & 13 deletions tests/run-make/rustdoc-error-lines/Makefile

This file was deleted.

22 changes: 22 additions & 0 deletions tests/run-make/rustdoc-error-lines/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Assert that the search index is generated deterministically, regardless of the
// order that crates are documented in.

use run_make_support::rustdoc;

fn main() {
let output =
String::from_utf8(rustdoc().input("input.rs").arg("--test").command_output().stdout)
.unwrap();

let should_contain = &[
"input.rs - foo (line 5)",
"input.rs:7:15",
"input.rs - bar (line 15)",
"input.rs:17:15",
"input.rs - bar (line 24)",
"input.rs:26:15",
];
for text in should_contain {
assert!(output.contains(text), "output doesn't contains {:?}", text);
}
}

0 comments on commit 25e3949

Please sign in to comment.