Skip to content

Commit 1b676fb

Browse files
committed
don't leave unwanted temporary files with --emit=ir/asm
1 parent b5a0b70 commit 1b676fb

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/librustc/back/write.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,15 @@ pub fn run_passes(sess: &Session,
588588
// to copy `foo.0.x` to `foo.x`.
589589
fs::copy(&crate_output.with_extension(ext),
590590
&crate_output.path(output_type)).unwrap();
591+
if !sess.opts.cg.save_temps {
592+
// The user just wants `foo.x`, not `foo.0.x`.
593+
remove(sess, &crate_output.with_extension(ext));
594+
}
591595
} else {
592596
if crate_output.single_output_file.is_some() {
593597
// 2) Multiple codegen units, with `-o some_name`. We have
594598
// no good solution for this case, so warn the user.
595-
sess.warn(format!("ignoring specified output filename \
596-
because multiple .{} files were produced",
599+
sess.warn(format!("ignoring -o because multiple .{} files were produced",
597600
ext).as_slice());
598601
} else {
599602
// 3) Multiple codegen units, but no `-o some_name`. We
@@ -670,7 +673,7 @@ pub fn run_passes(sess: &Session,
670673
// - crate.metadata.bc
671674
// - crate.metadata.o
672675
// - crate.o (linked from crate.##.o)
673-
// - crate.bc (copied from crate.0.bc, or an empty bitcode file)
676+
// - crate.bc (copied from crate.0.bc)
674677
// We may create additional files if requested by the user (through
675678
// `-C save-temps` or `--emit=` flags).
676679

src/test/run-make/output-type-permutations/Makefile

+34-5
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,69 @@ all:
55
$(call REMOVE_RLIBS,bar)
66
$(call REMOVE_DYLIBS,bar)
77
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
8+
# Check that $(TMPDIR) is empty.
9+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
10+
811
$(RUSTC) foo.rs --crate-type=bin
912
rm $(TMPDIR)/$(call BIN,bar)
13+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
14+
1015
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link
1116
rm $(TMPDIR)/bar.ll
1217
rm $(TMPDIR)/bar.bc
1318
rm $(TMPDIR)/bar.s
1419
rm $(TMPDIR)/bar.o
1520
rm $(TMPDIR)/$(call BIN,bar)
16-
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link --crate-type=staticlib
17-
rm $(TMPDIR)/bar.ll
18-
rm $(TMPDIR)/bar.s
19-
rm $(TMPDIR)/bar.o
20-
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
21+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
22+
2123
$(RUSTC) foo.rs --emit=asm -o $(TMPDIR)/foo
2224
rm $(TMPDIR)/foo
25+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
26+
2327
$(RUSTC) foo.rs --emit=bc -o $(TMPDIR)/foo
2428
rm $(TMPDIR)/foo
29+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
30+
2531
$(RUSTC) foo.rs --emit=ir -o $(TMPDIR)/foo
2632
rm $(TMPDIR)/foo
33+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
34+
2735
$(RUSTC) foo.rs --emit=obj -o $(TMPDIR)/foo
2836
rm $(TMPDIR)/foo
37+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
38+
2939
$(RUSTC) foo.rs --emit=link -o $(TMPDIR)/foo
3040
rm $(TMPDIR)/$(call BIN,foo)
41+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
42+
3143
$(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo
3244
rm $(TMPDIR)/foo
45+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
46+
3347
$(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/foo
3448
rm $(TMPDIR)/$(call BIN,foo) # FIXME 13794
49+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
50+
3551
$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
3652
rm $(TMPDIR)/foo
53+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
54+
3755
$(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/foo
3856
rm $(TMPDIR)/$(call BIN,foo)
57+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
58+
59+
$(RUSTC) foo.rs --emit=asm,ir,bc,obj,link --crate-type=staticlib
60+
rm $(TMPDIR)/bar.ll
61+
rm $(TMPDIR)/bar.s
62+
rm $(TMPDIR)/bar.o
63+
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
3964
mv $(TMPDIR)/bar.bc $(TMPDIR)/foo.bc
65+
# Don't check that the $(TMPDIR) is empty - we left `foo.bc` for later
66+
# comparison.
67+
4068
$(RUSTC) foo.rs --emit=bc,link --crate-type=rlib
4169
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
4270
rm $(TMPDIR)/bar.bc
4371
rm $(TMPDIR)/foo.bc
4472
$(call REMOVE_RLIBS,bar)
73+
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]

0 commit comments

Comments
 (0)