Skip to content

Commit

Permalink
Add new output method to Rustc and Rustdoc types
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 5, 2024
1 parent c04d09a commit 27e6741
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
7 changes: 7 additions & 0 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
7 changes: 7 additions & 0 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 Down
2 changes: 1 addition & 1 deletion tests/run-make/doctests-runtool/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
let run_tool_binary = run_tool.join("runtool");

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

rustdoc()
.input(current_dir().unwrap().join("t.rs"))
Expand Down
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();
}

0 comments on commit 27e6741

Please sign in to comment.