Add some things to inspect crate-id's

This commit is contained in:
Corey Richardson 2013-12-19 10:18:37 -05:00
parent dee1107571
commit b25a0524dc
5 changed files with 66 additions and 13 deletions

View File

@ -753,14 +753,10 @@ fn is_writeable(p: &Path) -> bool {
}
}
fn link_binary_output(sess: Session,
trans: &CrateTranslation,
output: session::OutputStyle,
obj_filename: &Path,
out_filename: &Path,
lm: &LinkMeta) -> Path {
pub fn filename_for_input(sess: &Session, output: session::OutputStyle, lm: &LinkMeta,
out_filename: &Path) -> Path {
let libname = output_lib_filename(lm);
let out_filename = match output {
match output {
session::OutputRlib => {
out_filename.with_filename(format!("lib{}.rlib", libname))
}
@ -778,7 +774,17 @@ fn link_binary_output(sess: Session,
out_filename.with_filename(format!("lib{}.a", libname))
}
session::OutputExecutable => out_filename.clone(),
};
}
}
fn link_binary_output(sess: Session,
trans: &CrateTranslation,
output: session::OutputStyle,
obj_filename: &Path,
out_filename: &Path,
lm: &LinkMeta) -> Path {
let out_filename = filename_for_input(&sess, output, lm, out_filename);
// Make sure the output and obj_filename are both writeable.
// Mac, FreeBSD, and Windows system linkers check this already --

View File

@ -446,13 +446,49 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
let (outputs, trans) = {
let expanded_crate = {
let crate = phase_1_parse_input(sess, cfg.clone(), input);
let (crate_id, crate_name, crate_file_name) = sess.opts.print_metas;
// these nasty nested conditions are to avoid doing extra work
if crate_id || crate_name || crate_file_name {
let t_outputs = build_output_filenames(input, outdir, output, crate.attrs, sess);
if crate_id || crate_name {
let pkgid = match attr::find_pkgid(crate.attrs) {
Some(pkgid) => pkgid,
None => fail!("No crate_id and --crate-id or --crate-name requested")
};
if crate_id {
println(pkgid.to_str());
}
if crate_name {
println(pkgid.name);
}
}
if crate_file_name {
let lm = link::build_link_meta(sess, &crate, &t_outputs.obj_filename,
&mut ::util::sha2::Sha256::new());
// if the vector is empty we default to OutputExecutable.
let style = sess.opts.outputs.get_opt(0).unwrap_or(&OutputExecutable);
let fname = link::filename_for_input(&sess, *style, &lm,
&t_outputs.out_filename);
println!("{}", fname.display());
// we already maybe printed the first one, so skip it
for style in sess.opts.outputs.iter().skip(1) {
let fname = link::filename_for_input(&sess, *style, &lm,
&t_outputs.out_filename);
println!("{}", fname.display());
}
}
return;
}
if stop_after_phase_1(sess) { return; }
phase_2_configure_and_expand(sess, cfg, crate)
};
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate);
if stop_after_phase_3(sess) { return; }
let outputs = build_output_filenames(input, outdir, output,
expanded_crate.attrs, sess);
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate);
if stop_after_phase_3(sess) { return; }
let trans = phase_4_translate_to_llvm(sess, expanded_crate,
&analysis, outputs);
(outputs, trans)
@ -789,6 +825,9 @@ pub fn build_session_options(binary: @str,
}).collect()
}
};
let print_metas = (matches.opt_present("crate-id"),
matches.opt_present("crate-name"),
matches.opt_present("crate-file-name"));
let sopts = @session::options {
outputs: outputs,
@ -817,6 +856,7 @@ pub fn build_session_options(binary: @str,
debugging_opts: debugging_opts,
android_cross_path: android_cross_path,
write_dependency_info: write_dependency_info,
print_metas: print_metas,
};
return sopts;
}
@ -897,6 +937,10 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
optflag("", "dylib", "Compile a dynamic library crate"),
optopt("", "linker", "Program to use for linking instead of the default.", "LINKER"),
optopt("", "ar", "Program to use for managing archives instead of the default.", "AR"),
optflag("", "crate-id", "Output the crate id and exit"),
optflag("", "crate-name", "Output the crate name and exit"),
optflag("", "crate-file-name", "Output the file(s) that would be written if compilation \
continued and exit"),
optmulti("", "link-args", "FLAGS is a space-separated list of flags
passed to the linker", "FLAGS"),
optflag("", "ls", "List the symbols defined by a library crate"),

View File

@ -168,8 +168,10 @@ pub struct options {
no_trans: bool,
debugging_opts: uint,
android_cross_path: Option<~str>,
// Whether to write .d dependency files
/// Whether to write .d dependency files
write_dependency_info: bool,
/// Crate id-related things to maybe print. It's (crate_id, crate_name, crate_file_name).
print_metas: (bool, bool, bool),
}
pub struct crate_metadata {
@ -396,6 +398,7 @@ pub fn basic_options() -> @options {
debugging_opts: 0u,
android_cross_path: None,
write_dependency_info: false,
print_metas: (false, false, false),
}
}

View File

@ -84,7 +84,7 @@ impl Clean<Crate> for visit_ast::RustdocVisitor {
Crate {
name: match find_pkgid(self.attrs) {
Some(n) => n.name,
None => fail!("rustdoc requires a `pkgid` crate attribute"),
None => fail!("rustdoc requires a `crate_id` crate attribute"),
},
module: Some(self.module.clean()),
externs: externs,

View File

@ -1,4 +1,4 @@
#[pkgid = "foo#0.1"];
#[crate_id = "foo#0.1"];
//! Very docs