Skip to content

Commit 1741962

Browse files
committed
rustc: Emit phony targets for inputs in dep-info
This helps protect against files being deleted to ensure that `make` won't emit errors. Closes #28735
1 parent 8c963c0 commit 1741962

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/librustc_driver/driver.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,16 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, id: &str) {
881881
.collect();
882882
let mut file = try!(fs::File::create(&deps_filename));
883883
for path in &out_filenames {
884-
try!(write!(&mut file,
884+
try!(write!(file,
885885
"{}: {}\n\n", path.display(), files.join(" ")));
886886
}
887+
888+
// Emit a fake target for each input file to the compilation. This
889+
// prevents `make` from spitting out an error if a file is later
890+
// deleted. For more info see #28735
891+
for path in files {
892+
try!(writeln!(file, "{}:", path));
893+
}
887894
Ok(())
888895
})();
889896

src/test/run-make/dep-info/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
ifneq ($(shell uname),FreeBSD)
88
ifndef IS_WINDOWS
99
all:
10-
$(RUSTC) --emit dep-info,link --crate-type=lib lib.rs
10+
cp *.rs $(TMPDIR)
11+
$(RUSTC) --emit dep-info,link --crate-type=lib $(TMPDIR)/lib.rs
1112
sleep 2
12-
touch foo.rs
13+
touch $(TMPDIR)/foo.rs
1314
-rm -f $(TMPDIR)/done
1415
$(MAKE) -drf Makefile.foo
1516
sleep 2
1617
rm $(TMPDIR)/done
1718
pwd
1819
$(MAKE) -drf Makefile.foo
1920
rm $(TMPDIR)/done && exit 1 || exit 0
21+
22+
# When a source file is deleted `make` should still work
23+
rm $(TMPDIR)/bar.rs
24+
cp $(TMPDIR)/lib2.rs $(TMPDIR)/lib.rs
25+
$(MAKE) -drf Makefile.foo
2026
else
2127
all:
2228

src/test/run-make/dep-info/lib2.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
pub mod foo;

0 commit comments

Comments
 (0)