Skip to content

Allow optional filename argument for --dep-info #11046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" "));
}
}

Expand Down Expand Up @@ -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 => ~[],
Expand Down Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down Expand Up @@ -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),
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/run-make/dep-info-custom/Makefile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/test/run-make/dep-info-custom/Makefile.foo
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/test/run-make/dep-info-custom/bar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn bar() {}
1 change: 1 addition & 0 deletions src/test/run-make/dep-info-custom/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn foo() {}
4 changes: 4 additions & 0 deletions src/test/run-make/dep-info-custom/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[crate_id="foo#0.1"];

pub mod foo;
pub mod bar;
5 changes: 3 additions & 2 deletions src/test/run-make/dep-info/Makefile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 2 additions & 6 deletions src/test/run-make/dep-info/Makefile.foo
Original file line number Diff line number Diff line change
@@ -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

Expand Down