auto merge of #11046 : zargony/rust/dep-info, r=alexcrichton

Using --dep-info writes Makefile-compatible dependency info to a file that is by default named based on the crate source filename. This adds an optional string argument to the --dep-info option which allows to write dependency info to an arbitrary filename.

cc #10698
This commit is contained in:
bors 2013-12-22 15:06:32 -08:00
commit 9e00272441
9 changed files with 62 additions and 30 deletions

View File

@ -393,25 +393,34 @@ 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 filestem = input_path.filestem().expect("input file must have stem");
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 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);
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(" "));
}
}
str_input(_) => {}
}
}
}
pub fn stop_after_phase_3(sess: Session) -> bool {
@ -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 <filename> after compiling", "FILENAME"),
optflag("", "save-temps",
"Write intermediate files (.bc, .opt.bc, .o)
in addition to normal output"),

View File

@ -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<Path>),
/// 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),
}
}

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
pub fn bar() {}

View File

@ -0,0 +1 @@
pub fn foo() {}

View File

@ -0,0 +1,4 @@
#[crate_id="foo#0.1"];
pub mod foo;
pub mod bar;

View File

@ -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

View File

@ -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