diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index bcaaa9224d937..ad510b4407661 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -393,24 +393,33 @@ pub fn phase_6_link_output(sess: Session, &outputs.out_filename, &trans.link)); - // Write out dependency rules to the .d file if requested - if sess.opts.write_dependency_info { - match *input { + // Write out dependency rules to the dep-info file if requested with --dep-info + let deps_filename = match sess.opts.write_dependency_info { + // Use filename from --dep-file argument if given + (true, Some(ref filename)) => filename.clone(), + // Use default filename: crate source filename with extension replaced by ".d" + (true, None) => match *input { file_input(ref input_path) => { - let files: ~[@str] = sess.codemap.files.iter() - .filter_map(|fmap| if fmap.is_real_file() { Some(fmap.name) } else { None }) - .collect(); - let mut output_path = outputs[0].dir_path(); let filestem = input_path.filestem().expect("input file must have stem"); - output_path.push(Path::new(filestem).with_extension("d")); - let mut file = io::File::create(&output_path); - for output in outputs.iter() { - write!(&mut file as &mut Writer, - "{}: {}\n\n", output.display(), files.connect(" ")); - } - } - str_input(_) => {} - } + let filename = outputs[0].dir_path().join(filestem).with_extension("d"); + filename + }, + str_input(..) => { + sess.warn("can not write --dep-info without a filename when compiling stdin."); + return; + }, + }, + _ => return, + }; + // Build a list of files used to compile the output and + // write Makefile-compatible dependency rules + let files: ~[@str] = sess.codemap.files.iter() + .filter_map(|fmap| if fmap.is_real_file() { Some(fmap.name) } else { None }) + .collect(); + let mut file = io::File::create(&deps_filename); + for output in outputs.iter() { + write!(&mut file as &mut Writer, + "{}: {}\n\n", output.display(), files.connect(" ")); } } @@ -771,7 +780,8 @@ pub fn build_session_options(binary: @str, let cfg = parse_cfgspecs(matches.opt_strs("cfg"), demitter); let test = matches.opt_present("test"); let android_cross_path = matches.opt_str("android-cross-path"); - let write_dependency_info = matches.opt_present("dep-info"); + let write_dependency_info = (matches.opt_present("dep-info"), + matches.opt_str("dep-info").map(|p| Path::new(p))); let custom_passes = match matches.opt_str("passes") { None => ~[], @@ -933,8 +943,8 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] { or identified (fully parenthesized, AST nodes and blocks with IDs)", "TYPE"), optflag("S", "", "Compile only; do not assemble or link"), - optflag("", "dep-info", - "Output dependency info to .d file after compiling"), + optflagopt("", "dep-info", + "Output dependency info to after compiling", "FILENAME"), optflag("", "save-temps", "Write intermediate files (.bc, .opt.bc, .o) in addition to normal output"), diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index ba9ffe81a993e..9492e22921a18 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -168,8 +168,8 @@ pub struct options { no_trans: bool, debugging_opts: uint, android_cross_path: Option<~str>, - /// Whether to write .d dependency files - write_dependency_info: bool, + /// Whether to write dependency files. It's (enabled, optional filename). + write_dependency_info: (bool, Option), /// Crate id-related things to maybe print. It's (crate_id, crate_name, crate_file_name). print_metas: (bool, bool, bool), } @@ -397,7 +397,7 @@ pub fn basic_options() -> @options { no_trans: false, debugging_opts: 0u, android_cross_path: None, - write_dependency_info: false, + write_dependency_info: (false, None), print_metas: (false, false, false), } } diff --git a/src/test/run-make/dep-info-custom/Makefile b/src/test/run-make/dep-info-custom/Makefile new file mode 100644 index 0000000000000..7a1f99ac2d592 --- /dev/null +++ b/src/test/run-make/dep-info-custom/Makefile @@ -0,0 +1,12 @@ +-include ../tools.mk + +all: + $(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --lib lib.rs + sleep 1 + touch foo.rs + -rm -f $(TMPDIR)/done + $(MAKE) -drf Makefile.foo + rm $(TMPDIR)/done + pwd + $(MAKE) -drf Makefile.foo + rm $(TMPDIR)/done && exit 1 || exit 0 diff --git a/src/test/run-make/dep-info-custom/Makefile.foo b/src/test/run-make/dep-info-custom/Makefile.foo new file mode 100644 index 0000000000000..95e736deb41a1 --- /dev/null +++ b/src/test/run-make/dep-info-custom/Makefile.foo @@ -0,0 +1,7 @@ +LIB := $(shell $(RUSTC) --crate-file-name --lib lib.rs) + +$(TMPDIR)/$(LIB): + $(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --lib lib.rs + touch $(TMPDIR)/done + +-include $(TMPDIR)/custom-deps-file.d diff --git a/src/test/run-make/dep-info-custom/bar.rs b/src/test/run-make/dep-info-custom/bar.rs new file mode 100644 index 0000000000000..c5c0bc606cd69 --- /dev/null +++ b/src/test/run-make/dep-info-custom/bar.rs @@ -0,0 +1 @@ +pub fn bar() {} diff --git a/src/test/run-make/dep-info-custom/foo.rs b/src/test/run-make/dep-info-custom/foo.rs new file mode 100644 index 0000000000000..b76b4321d62aa --- /dev/null +++ b/src/test/run-make/dep-info-custom/foo.rs @@ -0,0 +1 @@ +pub fn foo() {} diff --git a/src/test/run-make/dep-info-custom/lib.rs b/src/test/run-make/dep-info-custom/lib.rs new file mode 100644 index 0000000000000..937118269a747 --- /dev/null +++ b/src/test/run-make/dep-info-custom/lib.rs @@ -0,0 +1,4 @@ +#[crate_id="foo#0.1"]; + +pub mod foo; +pub mod bar; diff --git a/src/test/run-make/dep-info/Makefile b/src/test/run-make/dep-info/Makefile index 535cda4d80b9e..36a43b4c45560 100644 --- a/src/test/run-make/dep-info/Makefile +++ b/src/test/run-make/dep-info/Makefile @@ -1,11 +1,12 @@ -include ../tools.mk + all: $(RUSTC) --dep-info --lib lib.rs sleep 1 touch foo.rs -rm -f $(TMPDIR)/done - $(MAKE) -f Makefile.foo + $(MAKE) -drf Makefile.foo rm $(TMPDIR)/done pwd - $(MAKE) -df Makefile.foo + $(MAKE) -drf Makefile.foo rm $(TMPDIR)/done && exit 1 || exit 0 diff --git a/src/test/run-make/dep-info/Makefile.foo b/src/test/run-make/dep-info/Makefile.foo index 3e009828c0c49..2a1ce715e280a 100644 --- a/src/test/run-make/dep-info/Makefile.foo +++ b/src/test/run-make/dep-info/Makefile.foo @@ -1,10 +1,6 @@ -ifeq ($(shell uname),Darwin) -LIBEXT=dylib -else -LIBEXT=so -endif +LIB := $(shell $(RUSTC) --crate-file-name --lib lib.rs) -$(TMPDIR)/libfoo-b517899a-0.1.$(LIBEXT): +$(TMPDIR)/$(LIB): $(RUSTC) --dep-info --lib lib.rs touch $(TMPDIR)/done