Skip to content

Commit b25a052

Browse files
committed
Add some things to inspect crate-id's
1 parent dee1107 commit b25a052

File tree

5 files changed

+66
-13
lines changed

5 files changed

+66
-13
lines changed

src/librustc/back/link.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -753,14 +753,10 @@ fn is_writeable(p: &Path) -> bool {
753753
}
754754
}
755755

756-
fn link_binary_output(sess: Session,
757-
trans: &CrateTranslation,
758-
output: session::OutputStyle,
759-
obj_filename: &Path,
760-
out_filename: &Path,
761-
lm: &LinkMeta) -> Path {
756+
pub fn filename_for_input(sess: &Session, output: session::OutputStyle, lm: &LinkMeta,
757+
out_filename: &Path) -> Path {
762758
let libname = output_lib_filename(lm);
763-
let out_filename = match output {
759+
match output {
764760
session::OutputRlib => {
765761
out_filename.with_filename(format!("lib{}.rlib", libname))
766762
}
@@ -778,7 +774,17 @@ fn link_binary_output(sess: Session,
778774
out_filename.with_filename(format!("lib{}.a", libname))
779775
}
780776
session::OutputExecutable => out_filename.clone(),
781-
};
777+
}
778+
779+
}
780+
781+
fn link_binary_output(sess: Session,
782+
trans: &CrateTranslation,
783+
output: session::OutputStyle,
784+
obj_filename: &Path,
785+
out_filename: &Path,
786+
lm: &LinkMeta) -> Path {
787+
let out_filename = filename_for_input(&sess, output, lm, out_filename);
782788

783789
// Make sure the output and obj_filename are both writeable.
784790
// Mac, FreeBSD, and Windows system linkers check this already --

src/librustc/driver/driver.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,49 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
446446
let (outputs, trans) = {
447447
let expanded_crate = {
448448
let crate = phase_1_parse_input(sess, cfg.clone(), input);
449+
let (crate_id, crate_name, crate_file_name) = sess.opts.print_metas;
450+
// these nasty nested conditions are to avoid doing extra work
451+
if crate_id || crate_name || crate_file_name {
452+
let t_outputs = build_output_filenames(input, outdir, output, crate.attrs, sess);
453+
if crate_id || crate_name {
454+
let pkgid = match attr::find_pkgid(crate.attrs) {
455+
Some(pkgid) => pkgid,
456+
None => fail!("No crate_id and --crate-id or --crate-name requested")
457+
};
458+
if crate_id {
459+
println(pkgid.to_str());
460+
}
461+
if crate_name {
462+
println(pkgid.name);
463+
}
464+
}
465+
466+
if crate_file_name {
467+
let lm = link::build_link_meta(sess, &crate, &t_outputs.obj_filename,
468+
&mut ::util::sha2::Sha256::new());
469+
// if the vector is empty we default to OutputExecutable.
470+
let style = sess.opts.outputs.get_opt(0).unwrap_or(&OutputExecutable);
471+
let fname = link::filename_for_input(&sess, *style, &lm,
472+
&t_outputs.out_filename);
473+
println!("{}", fname.display());
474+
475+
// we already maybe printed the first one, so skip it
476+
for style in sess.opts.outputs.iter().skip(1) {
477+
let fname = link::filename_for_input(&sess, *style, &lm,
478+
&t_outputs.out_filename);
479+
println!("{}", fname.display());
480+
}
481+
}
482+
483+
return;
484+
}
449485
if stop_after_phase_1(sess) { return; }
450486
phase_2_configure_and_expand(sess, cfg, crate)
451487
};
452-
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate);
453-
if stop_after_phase_3(sess) { return; }
454488
let outputs = build_output_filenames(input, outdir, output,
455489
expanded_crate.attrs, sess);
490+
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate);
491+
if stop_after_phase_3(sess) { return; }
456492
let trans = phase_4_translate_to_llvm(sess, expanded_crate,
457493
&analysis, outputs);
458494
(outputs, trans)
@@ -789,6 +825,9 @@ pub fn build_session_options(binary: @str,
789825
}).collect()
790826
}
791827
};
828+
let print_metas = (matches.opt_present("crate-id"),
829+
matches.opt_present("crate-name"),
830+
matches.opt_present("crate-file-name"));
792831

793832
let sopts = @session::options {
794833
outputs: outputs,
@@ -817,6 +856,7 @@ pub fn build_session_options(binary: @str,
817856
debugging_opts: debugging_opts,
818857
android_cross_path: android_cross_path,
819858
write_dependency_info: write_dependency_info,
859+
print_metas: print_metas,
820860
};
821861
return sopts;
822862
}
@@ -897,6 +937,10 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
897937
optflag("", "dylib", "Compile a dynamic library crate"),
898938
optopt("", "linker", "Program to use for linking instead of the default.", "LINKER"),
899939
optopt("", "ar", "Program to use for managing archives instead of the default.", "AR"),
940+
optflag("", "crate-id", "Output the crate id and exit"),
941+
optflag("", "crate-name", "Output the crate name and exit"),
942+
optflag("", "crate-file-name", "Output the file(s) that would be written if compilation \
943+
continued and exit"),
900944
optmulti("", "link-args", "FLAGS is a space-separated list of flags
901945
passed to the linker", "FLAGS"),
902946
optflag("", "ls", "List the symbols defined by a library crate"),

src/librustc/driver/session.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ pub struct options {
168168
no_trans: bool,
169169
debugging_opts: uint,
170170
android_cross_path: Option<~str>,
171-
// Whether to write .d dependency files
171+
/// Whether to write .d dependency files
172172
write_dependency_info: bool,
173+
/// Crate id-related things to maybe print. It's (crate_id, crate_name, crate_file_name).
174+
print_metas: (bool, bool, bool),
173175
}
174176

175177
pub struct crate_metadata {
@@ -396,6 +398,7 @@ pub fn basic_options() -> @options {
396398
debugging_opts: 0u,
397399
android_cross_path: None,
398400
write_dependency_info: false,
401+
print_metas: (false, false, false),
399402
}
400403
}
401404

src/librustdoc/clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Clean<Crate> for visit_ast::RustdocVisitor {
8484
Crate {
8585
name: match find_pkgid(self.attrs) {
8686
Some(n) => n.name,
87-
None => fail!("rustdoc requires a `pkgid` crate attribute"),
87+
None => fail!("rustdoc requires a `crate_id` crate attribute"),
8888
},
8989
module: Some(self.module.clean()),
9090
externs: externs,

src/test/run-make/rustdoc-smoke/foo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[pkgid = "foo#0.1"];
1+
#[crate_id = "foo#0.1"];
22

33
//! Very docs
44

0 commit comments

Comments
 (0)