Skip to content

Commit 66e3fbe

Browse files
committed
Allow optional filename argument for --dep-info
1 parent 5d0fea1 commit 66e3fbe

File tree

8 files changed

+59
-24
lines changed

8 files changed

+59
-24
lines changed

src/librustc/driver/driver.rs

+29-19
Original file line numberDiff line numberDiff line change
@@ -393,24 +393,33 @@ pub fn phase_6_link_output(sess: Session,
393393
&outputs.out_filename,
394394
&trans.link));
395395

396-
// Write out dependency rules to the .d file if requested
397-
if sess.opts.write_dependency_info {
398-
match *input {
396+
// Write out dependency rules to the dep-info file if requested with --dep-info
397+
let deps_filename = match sess.opts.write_dependency_info {
398+
// Use filename from --dep-file argument if given
399+
(true, Some(ref filename)) => filename.clone(),
400+
// Use default filename: crate source filename with extension replaced by ".d"
401+
(true, None) => match *input {
399402
file_input(ref input_path) => {
400-
let files: ~[@str] = sess.codemap.files.iter()
401-
.filter_map(|fmap| if fmap.is_real_file() { Some(fmap.name) } else { None })
402-
.collect();
403-
let mut output_path = outputs[0].dir_path();
404403
let filestem = input_path.filestem().expect("input file must have stem");
405-
output_path.push(Path::new(filestem).with_extension("d"));
406-
let mut file = io::File::create(&output_path);
407-
for output in outputs.iter() {
408-
write!(&mut file as &mut Writer,
409-
"{}: {}\n\n", output.display(), files.connect(" "));
410-
}
411-
}
412-
str_input(_) => {}
413-
}
404+
let filename = outputs[0].dir_path().join(filestem).with_extension("d");
405+
filename
406+
},
407+
str_input(..) => {
408+
sess.warn("can not write --dep-info without a filename when compiling stdin.");
409+
return;
410+
},
411+
},
412+
_ => return,
413+
};
414+
// Build a list of files used to compile the output and
415+
// write Makefile-compatible dependency rules
416+
let files: ~[@str] = sess.codemap.files.iter()
417+
.filter_map(|fmap| if fmap.is_real_file() { Some(fmap.name) } else { None })
418+
.collect();
419+
let mut file = io::File::create(&deps_filename);
420+
for output in outputs.iter() {
421+
write!(&mut file as &mut Writer,
422+
"{}: {}\n\n", output.display(), files.connect(" "));
414423
}
415424
}
416425

@@ -771,7 +780,8 @@ pub fn build_session_options(binary: @str,
771780
let cfg = parse_cfgspecs(matches.opt_strs("cfg"), demitter);
772781
let test = matches.opt_present("test");
773782
let android_cross_path = matches.opt_str("android-cross-path");
774-
let write_dependency_info = matches.opt_present("dep-info");
783+
let write_dependency_info = (matches.opt_present("dep-info"),
784+
matches.opt_str("dep-info").map(|p| Path::new(p)));
775785

776786
let custom_passes = match matches.opt_str("passes") {
777787
None => ~[],
@@ -933,8 +943,8 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
933943
or identified (fully parenthesized,
934944
AST nodes and blocks with IDs)", "TYPE"),
935945
optflag("S", "", "Compile only; do not assemble or link"),
936-
optflag("", "dep-info",
937-
"Output dependency info to .d file after compiling"),
946+
optflagopt("", "dep-info",
947+
"Output dependency info to <filename> after compiling", "FILENAME"),
938948
optflag("", "save-temps",
939949
"Write intermediate files (.bc, .opt.bc, .o)
940950
in addition to normal output"),

src/librustc/driver/session.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ pub struct options {
168168
no_trans: bool,
169169
debugging_opts: uint,
170170
android_cross_path: Option<~str>,
171-
/// Whether to write .d dependency files
172-
write_dependency_info: bool,
171+
/// Whether to write dependency files. It's (enabled, optional filename).
172+
write_dependency_info: (bool, Option<Path>),
173173
/// Crate id-related things to maybe print. It's (crate_id, crate_name, crate_file_name).
174174
print_metas: (bool, bool, bool),
175175
}
@@ -397,7 +397,7 @@ pub fn basic_options() -> @options {
397397
no_trans: false,
398398
debugging_opts: 0u,
399399
android_cross_path: None,
400-
write_dependency_info: false,
400+
write_dependency_info: (false, None),
401401
print_metas: (false, false, false),
402402
}
403403
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --lib lib.rs
5+
sleep 1
6+
touch foo.rs
7+
-rm -f $(TMPDIR)/done
8+
$(MAKE) -drf Makefile.foo
9+
rm $(TMPDIR)/done
10+
pwd
11+
$(MAKE) -drf Makefile.foo
12+
rm $(TMPDIR)/done && exit 1 || exit 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LIB := $(shell $(RUSTC) --crate-file-name --lib lib.rs)
2+
3+
$(TMPDIR)/$(LIB):
4+
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --lib lib.rs
5+
touch $(TMPDIR)/done
6+
7+
-include $(TMPDIR)/custom-deps-file.d
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn bar() {}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn foo() {}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[crate_id="foo#0.1"];
2+
3+
pub mod foo;
4+
pub mod bar;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ all:
55
sleep 1
66
touch foo.rs
77
-rm -f $(TMPDIR)/done
8-
$(MAKE) -f Makefile.foo
8+
$(MAKE) -drf Makefile.foo
99
rm $(TMPDIR)/done
1010
pwd
11-
$(MAKE) -df Makefile.foo
11+
$(MAKE) -drf Makefile.foo
1212
rm $(TMPDIR)/done && exit 1 || exit 0

0 commit comments

Comments
 (0)