Add new output method to Rustc and Rustdoc types

This commit is contained in:
Guillaume Gomez 2024-05-05 16:26:35 +02:00
parent c04d09a76b
commit 823b423d4c
7 changed files with 30 additions and 15 deletions

View File

@ -91,6 +91,13 @@ pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
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}"));

View File

@ -51,6 +51,13 @@ pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
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());

View File

@ -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"))

View File

@ -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);

View File

@ -10,7 +10,7 @@
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")

View File

@ -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();
}

View File

@ -25,7 +25,7 @@ fn run(file: &Path, method: &str, expected_output: &str) {
.arg("--invoke")
.arg(method)
.arg(file)
.command_output()
.output()
.unwrap();
assert!(output.status.success());
assert_eq!(expected_output, String::from_utf8_lossy(&output.stdout));