Skip to content

Commit

Permalink
rewrite output-type-permutations to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jul 2, 2024
1 parent 99f77a2 commit ef48ae8
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 148 deletions.
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ run-make/no-duplicate-libs/Makefile
run-make/obey-crate-type-flag/Makefile
run-make/optimization-remarks-dir-pgo/Makefile
run-make/optimization-remarks-dir/Makefile
run-make/output-type-permutations/Makefile
run-make/override-aliased-flags/Makefile
run-make/overwrite-input/Makefile
run-make/panic-abort-eh_frame/Makefile
Expand Down
147 changes: 0 additions & 147 deletions tests/run-make/output-type-permutations/Makefile

This file was deleted.

178 changes: 178 additions & 0 deletions tests/run-make/output-type-permutations/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// In 2014, rustc's output flags were reworked to be a lot more modular.
// This test uses these output flags in an expansive variety of combinations
// and syntax styles, checking that compilation is successful and that no unexpected
// files are created.
// The assert_eq! checks that "1 file remains" at the end of each part of the test,
// because foo.rs counts as a file, and should be the only remaining one.
// See https://github.com/rust-lang/rust/pull/12020

use run_make_support::{
bin_name, cwd, dynamic_lib_name, fs_wrapper, rust_lib_name, rustc, static_lib_name,
};

fn remove_artifacts() {
std::fs::remove_file("libbar.ddl.exp").unwrap_or_default();
std::fs::remove_file("libbar.dll.lib").unwrap_or_default();
std::fs::remove_file("libbar.pdb").unwrap_or_default();
std::fs::remove_file("libbar.dll.a").unwrap_or_default();
std::fs::remove_file("libbar.exe.a").unwrap_or_default();
std::fs::remove_file("bar.ddl.exp").unwrap_or_default();
std::fs::remove_file("bar.dll.lib").unwrap_or_default();
std::fs::remove_file("bar.pdb").unwrap_or_default();
std::fs::remove_file("bar.dll.a").unwrap_or_default();
std::fs::remove_file("bar.exe.a").unwrap_or_default();
}

fn main() {
rustc().input("foo.rs").crate_type("rlib,dylib,staticlib").run();
fs_wrapper::remove_file(rust_lib_name("bar"));
fs_wrapper::remove_file(dynamic_lib_name("bar"));
fs_wrapper::remove_file(static_lib_name("bar"));
remove_artifacts();
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").crate_type("bin").run();
fs_wrapper::remove_file(bin_name("bar"));
std::fs::remove_file("bar.pdb").unwrap_or_default();
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").run();
fs_wrapper::remove_file("bar.ll");
fs_wrapper::remove_file("bar.bc");
fs_wrapper::remove_file("bar.s");
fs_wrapper::remove_file("bar.o");
fs_wrapper::remove_file(bin_name("bar"));
std::fs::remove_file("bar.pdb").unwrap_or_default();
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").emit("asm").output("foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").emit("asm=foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").arg("--emit=asm=foo").run();
fs_wrapper::remove_file("foo");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").emit("llvm-bc").output("foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").emit("llvm-bc=foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").arg("--emit=llvm-bc=foo").run();
fs_wrapper::remove_file("foo");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").emit("llvm-ir").output("foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").emit("llvm-ir=foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").arg("--emit=llvm-ir=foo").run();
fs_wrapper::remove_file("foo");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").emit("obj").output("foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").emit("obj=foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").arg("--emit=obj=foo").run();
fs_wrapper::remove_file("foo");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

let bin_foo = bin_name("foo");
rustc().input("foo.rs").emit("link").output(&bin_foo).run();
fs_wrapper::remove_file(&bin_foo);
rustc().input("foo.rs").emit(&format!("link={bin_foo}")).run();
fs_wrapper::remove_file(&bin_foo);
rustc().input("foo.rs").arg(&format!("--emit=link={bin_foo}")).run();
fs_wrapper::remove_file(&bin_foo);
std::fs::remove_file("foo.pdb").unwrap_or_default();
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").crate_type("rlib").output("foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").crate_type("rlib").emit("link=foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").crate_type("rlib").arg("--emit=link=foo").run();
fs_wrapper::remove_file("foo");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").crate_type("dylib").output(&bin_foo).run();
fs_wrapper::remove_file(&bin_foo);
rustc().input("foo.rs").crate_type("dylib").emit(&format!("link={bin_foo}")).run();
fs_wrapper::remove_file(&bin_foo);
rustc().input("foo.rs").crate_type("dylib").arg(&format!("--emit=link={bin_foo}")).run();
fs_wrapper::remove_file(&bin_foo);
remove_artifacts();
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").crate_type("staticlib").emit("link").output("foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").crate_type("staticlib").emit("link=foo").run();
fs_wrapper::remove_file("foo");
rustc().input("foo.rs").crate_type("staticlib").arg("--emit=link=foo").run();
fs_wrapper::remove_file("foo");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").crate_type("bin").output(&bin_foo).run();
fs_wrapper::remove_file(&bin_foo);
rustc().input("foo.rs").crate_type("bin").emit(&format!("link={bin_foo}")).run();
fs_wrapper::remove_file(&bin_foo);
rustc().input("foo.rs").crate_type("bin").arg(&format!("--emit=link={bin_foo}")).run();
fs_wrapper::remove_file(&bin_foo);
std::fs::remove_file("foo.pdb").unwrap_or_default();
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").emit("llvm-ir=ir").emit("link").crate_type("rlib").run();
fs_wrapper::remove_file("ir");
fs_wrapper::remove_file(rust_lib_name("bar"));
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc()
.input("foo.rs")
.emit("asm=asm")
.emit("llvm-ir=ir")
.emit("llvm-bc=bc")
.emit("obj=obj")
.emit("link=link")
.crate_type("staticlib")
.run();
fs_wrapper::remove_file("asm");
fs_wrapper::remove_file("ir");
fs_wrapper::remove_file("bc");
fs_wrapper::remove_file("obj");
fs_wrapper::remove_file("link");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc()
.input("foo.rs")
.arg("--emit=asm=asm")
.arg("--emit")
.arg("llvm-ir=ir")
.arg("--emit=llvm-bc=bc")
.arg("--emit")
.arg("obj=obj")
.arg("--emit=link=link")
.crate_type("staticlib")
.run();
fs_wrapper::remove_file("asm");
fs_wrapper::remove_file("ir");
fs_wrapper::remove_file("bc");
fs_wrapper::remove_file("obj");
fs_wrapper::remove_file("link");
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);

rustc().input("foo.rs").emit("asm,llvm-ir,llvm-bc,obj,link").crate_type("staticlib").run();
fs_wrapper::remove_file("bar.ll");
fs_wrapper::remove_file("bar.s");
fs_wrapper::remove_file("bar.o");
fs_wrapper::remove_file(static_lib_name("bar"));
fs_wrapper::rename("bar.bc", "foo.bc");
// Don't check that no files except foo.rs remain - we left `foo.bc` for later
// comparison.

rustc().input("foo.rs").emit("llvm-bc,link").crate_type("rlib").run();
assert_eq!(fs_wrapper::read("foo.bc"), fs_wrapper::read("bar.bc"));
fs_wrapper::remove_file("bar.bc");
fs_wrapper::remove_file("foo.bc");
fs_wrapper::remove_file(rust_lib_name("bar"));
assert_eq!(fs_wrapper::read_dir(cwd()).count(), 1);
}

0 comments on commit ef48ae8

Please sign in to comment.