From 17419622712af44311aa7a8730e4535dff3554f5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 30 Sep 2015 10:17:07 -0700 Subject: [PATCH] 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 --- src/librustc_driver/driver.rs | 9 ++++++++- src/test/run-make/dep-info/Makefile | 10 ++++++++-- src/test/run-make/dep-info/lib2.rs | 13 +++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/test/run-make/dep-info/lib2.rs diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index e2835ae8f0d..0ec3424b82d 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -881,9 +881,16 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, id: &str) { .collect(); let mut file = try!(fs::File::create(&deps_filename)); for path in &out_filenames { - try!(write!(&mut file, + try!(write!(file, "{}: {}\n\n", path.display(), files.join(" "))); } + + // Emit a fake target for each input file to the compilation. This + // prevents `make` from spitting out an error if a file is later + // deleted. For more info see #28735 + for path in files { + try!(writeln!(file, "{}:", path)); + } Ok(()) })(); diff --git a/src/test/run-make/dep-info/Makefile b/src/test/run-make/dep-info/Makefile index a1828cd1f5d..9b79d1af521 100644 --- a/src/test/run-make/dep-info/Makefile +++ b/src/test/run-make/dep-info/Makefile @@ -7,9 +7,10 @@ ifneq ($(shell uname),FreeBSD) ifndef IS_WINDOWS all: - $(RUSTC) --emit dep-info,link --crate-type=lib lib.rs + cp *.rs $(TMPDIR) + $(RUSTC) --emit dep-info,link --crate-type=lib $(TMPDIR)/lib.rs sleep 2 - touch foo.rs + touch $(TMPDIR)/foo.rs -rm -f $(TMPDIR)/done $(MAKE) -drf Makefile.foo sleep 2 @@ -17,6 +18,11 @@ all: pwd $(MAKE) -drf Makefile.foo rm $(TMPDIR)/done && exit 1 || exit 0 + + # When a source file is deleted `make` should still work + rm $(TMPDIR)/bar.rs + cp $(TMPDIR)/lib2.rs $(TMPDIR)/lib.rs + $(MAKE) -drf Makefile.foo else all: diff --git a/src/test/run-make/dep-info/lib2.rs b/src/test/run-make/dep-info/lib2.rs new file mode 100644 index 00000000000..1b70fb4eb4b --- /dev/null +++ b/src/test/run-make/dep-info/lib2.rs @@ -0,0 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "foo"] + +pub mod foo;