diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 22d1e93bf399a..65c12ff929fa1 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -1,6 +1,5 @@ run-make/branch-protection-check-IBT/Makefile run-make/cat-and-grep-sanity-check/Makefile -run-make/emit-to-stdout/Makefile run-make/extern-fn-reachable/Makefile run-make/incr-add-rust-src-component/Makefile run-make/issue-84395-lto-embed-bitcode/Makefile diff --git a/tests/run-make/emit-to-stdout/Makefile b/tests/run-make/emit-to-stdout/Makefile deleted file mode 100644 index 80e9b6a4ded67..0000000000000 --- a/tests/run-make/emit-to-stdout/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -include ../tools.mk - -SRC=test.rs -OUT=$(TMPDIR)/out - -all: asm llvm-ir dep-info mir llvm-bc obj metadata link multiple-types multiple-types-option-o - -asm: $(OUT) - $(RUSTC) --emit asm=$(OUT)/$@ $(SRC) - $(RUSTC) --emit asm=- $(SRC) | diff - $(OUT)/$@ -llvm-ir: $(OUT) - $(RUSTC) --emit llvm-ir=$(OUT)/$@ $(SRC) - $(RUSTC) --emit llvm-ir=- $(SRC) | diff - $(OUT)/$@ -dep-info: $(OUT) - $(RUSTC) -Z dep-info-omit-d-target=yes --emit dep-info=$(OUT)/$@ $(SRC) - $(RUSTC) --emit dep-info=- $(SRC) | diff - $(OUT)/$@ -mir: $(OUT) - $(RUSTC) --emit mir=$(OUT)/$@ $(SRC) - $(RUSTC) --emit mir=- $(SRC) | diff - $(OUT)/$@ - -llvm-bc: $(OUT) - $(RUSTC) --emit llvm-bc=- $(SRC) 1>/dev/ptmx 2>$(OUT)/$@ || true - diff $(OUT)/$@ emit-llvm-bc.stderr -obj: $(OUT) - $(RUSTC) --emit obj=- $(SRC) 1>/dev/ptmx 2>$(OUT)/$@ || true - diff $(OUT)/$@ emit-obj.stderr - -# For metadata output, a temporary directory will be created to hold the temporary -# metadata file. But when output is stdout, the temporary directory will be located -# in the same place as $(SRC), which is mounted as read-only in the tests. Thus as -# a workaround, $(SRC) is copied to the test output directory $(OUT) and we compile -# it there. -metadata: $(OUT) - cp $(SRC) $(OUT) - (cd $(OUT); $(RUSTC) --emit metadata=- $(SRC) 1>/dev/ptmx 2>$(OUT)/$@ || true) - diff $(OUT)/$@ emit-metadata.stderr - -link: $(OUT) - $(RUSTC) --emit link=- $(SRC) 1>/dev/ptmx 2>$(OUT)/$@ || true - diff $(OUT)/$@ emit-link.stderr - -multiple-types: $(OUT) - $(RUSTC) --emit asm=- --emit llvm-ir=- --emit dep-info=- --emit mir=- $(SRC) 2>$(OUT)/$@ || true - diff $(OUT)/$@ emit-multiple-types.stderr - -multiple-types-option-o: $(OUT) - $(RUSTC) -o - --emit asm,llvm-ir,dep-info,mir $(SRC) 2>$(OUT)/$@ || true - diff $(OUT)/$@ emit-multiple-types.stderr - -$(OUT): - mkdir -p $(OUT) diff --git a/tests/run-make/emit-to-stdout/rmake.rs b/tests/run-make/emit-to-stdout/rmake.rs new file mode 100644 index 0000000000000..cc29b7f605199 --- /dev/null +++ b/tests/run-make/emit-to-stdout/rmake.rs @@ -0,0 +1,107 @@ +// If `-o -` or `--emit KIND=-` is provided, output should be written +// to stdout instead. Binary output (`obj`, `llvm-bc`, `link` and +// `metadata`) being written this way will result in an error unless +// stdout is not a tty. Multiple output types going to stdout will +// trigger an error too, as they will all be mixed together. +// See https://github.com/rust-lang/rust/pull/111626 + +use run_make_support::{diff, rfs, rustc}; + +fn main() { + rfs::create_dir("out"); + test_asm(); + test_llvm_ir(); + test_dep_info(); + test_mir(); + test_llvm_bc(); + test_obj(); + test_metadata(); + test_link(); + test_multiple_types(); + test_multiple_types_option_o(); +} + +fn test_asm() { + rustc().emit("asm=out/asm").input("test.rs").run(); + let emit = rustc().emit("asm=-").input("test.rs").run().stdout_utf8(); + diff().expected_file("out/asm").actual_text("actual", &emit).run(); +} + +fn test_llvm_ir() { + rustc().emit("llvm-ir=out/llvm-ir").input("test.rs").run(); + let emit = rustc().emit("llvm-ir=-").input("test.rs").run().stdout_utf8(); + diff().expected_file("out/llvm-ir").actual_text("actual", &emit).run(); +} + +fn test_dep_info() { + rustc() + .emit("dep-info=out/dep-info") + .input("test.rs") + .arg("-Zdep-info-omit-d-target=yes") + .run(); + let emit = rustc().emit("dep-info=-").input("test.rs").run().stdout_utf8(); + diff().expected_file("out/dep-info").actual_text("actual", &emit).run(); +} + +fn test_mir() { + rustc().emit("mir=out/mir").input("test.rs").run(); + let emit = rustc().emit("mir=-").input("test.rs").run().stdout_utf8(); + diff().expected_file("out/mir").actual_text("actual", &emit).run(); +} + +// FIXME: ptmx +fn test_llvm_bc() { + let emit = rustc().emit("llvm-bc=-").input("test.rs").run().stderr_utf8(); + diff().expected_file("emit-llvm-bc.stderr").actual_text("actual", &emit).run(); +} + +// FIXME: ptmx +fn test_obj() { + let emit = rustc().emit("obj=-").input("test.rs").run().stderr_utf8(); + diff().expected_file("emit-obj.stderr").actual_text("actual", &emit).run(); +} + +// FIXME: ptmx +fn test_metadata() { + let emit = rustc().emit("metadata=-").input("test.rs").run().stderr_utf8(); + diff().expected_file("emit-metadata.stderr").actual_text("actual", &emit).run(); +} + +// FIXME: ptmx +fn test_link() { + let emit = rustc().emit("link=-").input("test.rs").run().stderr_utf8(); + diff().expected_file("emit-link.stderr").actual_text("actual", &emit).run(); +} + +fn test_multiple_types() { + diff() + .expected_file("emit-multiple-types.stderr") + .actual_text( + "actual", + rustc() + .output("-") + .emit("asm=-") + .emit("llvm-ir=-") + .emit("dep-info=-") + .emit("mir=-") + .input("test.rs") + .run_fail() + .stderr_utf8(), + ) + .run(); +} + +fn test_multiple_types_option_o() { + diff() + .expected_file("emit-multiple-types.stderr") + .actual_text( + "actual", + rustc() + .output("-") + .emit("asm,llvm-ir,dep-info,mir") + .input("test.rs") + .run_fail() + .stderr_utf8(), + ) + .run(); +}