about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStuart Pernsteiner <spernsteiner@mozilla.com>2014-08-27 14:49:17 -0700
committerStuart Pernsteiner <spernsteiner@mozilla.com>2014-09-05 09:18:57 -0700
commit1b676fb7603cd2aa4e0506cb5b67d48c9da1123f (patch)
tree3d0ed78979ca00ee66dce2b5aab6a1ab3c0a39ef
parentb5a0b700c64639043bce0a2ba0a8b40dd853d469 (diff)
downloadrust-1b676fb7603cd2aa4e0506cb5b67d48c9da1123f.tar.gz
rust-1b676fb7603cd2aa4e0506cb5b67d48c9da1123f.zip
don't leave unwanted temporary files with --emit=ir/asm
-rw-r--r--src/librustc/back/write.rs9
-rw-r--r--src/test/run-make/output-type-permutations/Makefile39
2 files changed, 40 insertions, 8 deletions
diff --git a/src/librustc/back/write.rs b/src/librustc/back/write.rs
index 2760ae80110..d87dd84bb32 100644
--- a/src/librustc/back/write.rs
+++ b/src/librustc/back/write.rs
@@ -588,12 +588,15 @@ pub fn run_passes(sess: &Session,
             //    to copy `foo.0.x` to `foo.x`.
             fs::copy(&crate_output.with_extension(ext),
                      &crate_output.path(output_type)).unwrap();
+            if !sess.opts.cg.save_temps {
+                // The user just wants `foo.x`, not `foo.0.x`.
+                remove(sess, &crate_output.with_extension(ext));
+            }
         } else {
             if crate_output.single_output_file.is_some() {
                 // 2) Multiple codegen units, with `-o some_name`.  We have
                 //    no good solution for this case, so warn the user.
-                sess.warn(format!("ignoring specified output filename \
-                                   because multiple .{} files were produced",
+                sess.warn(format!("ignoring -o because multiple .{} files were produced",
                                   ext).as_slice());
             } else {
                 // 3) Multiple codegen units, but no `-o some_name`.  We
@@ -670,7 +673,7 @@ pub fn run_passes(sess: &Session,
     //  - crate.metadata.bc
     //  - crate.metadata.o
     //  - crate.o (linked from crate.##.o)
-    //  - crate.bc (copied from crate.0.bc, or an empty bitcode file)
+    //  - crate.bc (copied from crate.0.bc)
     // We may create additional files if requested by the user (through
     // `-C save-temps` or `--emit=` flags).
 
diff --git a/src/test/run-make/output-type-permutations/Makefile b/src/test/run-make/output-type-permutations/Makefile
index c163a5bec08..fed071d1a43 100644
--- a/src/test/run-make/output-type-permutations/Makefile
+++ b/src/test/run-make/output-type-permutations/Makefile
@@ -5,40 +5,69 @@ all:
 	$(call REMOVE_RLIBS,bar)
 	$(call REMOVE_DYLIBS,bar)
 	rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
+	# Check that $(TMPDIR) is empty.
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --crate-type=bin
 	rm $(TMPDIR)/$(call BIN,bar)
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link
 	rm $(TMPDIR)/bar.ll
 	rm $(TMPDIR)/bar.bc
 	rm $(TMPDIR)/bar.s
 	rm $(TMPDIR)/bar.o
 	rm $(TMPDIR)/$(call BIN,bar)
-	$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link --crate-type=staticlib
-	rm $(TMPDIR)/bar.ll
-	rm $(TMPDIR)/bar.s
-	rm $(TMPDIR)/bar.o
-	rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --emit=asm -o $(TMPDIR)/foo
 	rm $(TMPDIR)/foo
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --emit=bc -o $(TMPDIR)/foo
 	rm $(TMPDIR)/foo
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --emit=ir -o $(TMPDIR)/foo
 	rm $(TMPDIR)/foo
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --emit=obj -o $(TMPDIR)/foo
 	rm $(TMPDIR)/foo
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --emit=link -o $(TMPDIR)/foo
 	rm $(TMPDIR)/$(call BIN,foo)
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo
 	rm $(TMPDIR)/foo
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/foo
 	rm $(TMPDIR)/$(call BIN,foo)  # FIXME 13794
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
 	rm $(TMPDIR)/foo
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
 	$(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/foo
 	rm $(TMPDIR)/$(call BIN,foo)
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
+
+	$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link --crate-type=staticlib
+	rm $(TMPDIR)/bar.ll
+	rm $(TMPDIR)/bar.s
+	rm $(TMPDIR)/bar.o
+	rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
 	mv $(TMPDIR)/bar.bc $(TMPDIR)/foo.bc
+	# Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later
+	# comparison.
+
 	$(RUSTC) foo.rs --emit=bc,link --crate-type=rlib
 	cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
 	rm $(TMPDIR)/bar.bc
 	rm $(TMPDIR)/foo.bc
 	$(call REMOVE_RLIBS,bar)
+	[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]