diff --git a/man/rustc.1 b/man/rustc.1 index 68c3e01cb2171..768624fb7ace7 100644 --- a/man/rustc.1 +++ b/man/rustc.1 @@ -50,6 +50,10 @@ Pretty-print the input. Valid \fItype\fRs are: \fB--ls\fR: Lists symbols defined by the specified \fBcompiled\fR library. .TP +\fB--read-attr\fR \fIname\fR: +Print the named attribute of the specified \fBcompiled\fR library, or nothing +if no such attribute exists. +.TP \fB-L\fR \fIpath\fR: Adds \fIpath\fR to the library search path. .TP diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 74d13c9a4ca00..2d691abaa1378 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -251,6 +251,7 @@ options: --static use or produce static libraries --pretty [type] pretty-print the input instead of compiling --ls list the symbols defined by a crate file + --read-attr read a specific crate attribute -L add a directory to the library search path --noverify suppress LLVM verification step (slight speedup) --parse-only parse only; do not compile, assemble, or link @@ -448,7 +449,8 @@ fn opts() -> [getopts::opt] { optflag("no-typestate"), optflag("noverify"), optmulti("cfg"), optflag("test"), optflag("lib"), optflag("static"), optflag("gc"), - optflag("stack-growth"), optflag("check-unsafe")]; + optflag("stack-growth"), optflag("check-unsafe"), + optflagopt("read-attr")]; } fn build_output_filenames(ifile: str, ofile: option::t, @@ -546,6 +548,12 @@ fn main(args: [str]) { ret; } + if opt_present(match, "read-attr") { + let arg = getopts::opt_str(match, "read-attr"); + metadata::creader::read_attr(sess, ifile, io::stdout(), arg); + ret; + } + let stop_after_codegen = sopts.output_type != link::output_type_exe || sopts.static && sopts.library; diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 5946b337b489f..8e6a545f7ae75 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -17,6 +17,7 @@ import common::*; export read_crates; export list_file_metadata; +export read_attr; // Traverses an AST, reading all the information about use'd crates and native // libraries necessary for later resolving, typechecking, linking, etc. @@ -81,6 +82,15 @@ fn list_file_metadata(sess: session::session, path: str, out: io::writer) { } } +fn read_attr(sess: session::session, path: str, out: io::writer, name: str) { + alt get_metadata_section(sess, path) { + option::none. { } + option::some(bytes) { + decoder::print_crate_attr(bytes, out, name); + } + } +} + fn metadata_matches(crate_data: @[u8], metas: [@ast::meta_item]) -> bool { let attrs = decoder::get_crate_attributes(crate_data); let linkage_metas = attr::find_linkage_metas(attrs); diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs index 12ec6ed8860a4..b1f11d29c5e4e 100644 --- a/src/comp/metadata/decoder.rs +++ b/src/comp/metadata/decoder.rs @@ -22,6 +22,7 @@ export list_crate_metadata; export crate_dep; export get_crate_deps; export external_resolver; +export print_crate_attr; // A function that takes a def_id relative to the crate being searched and // returns a def_id relative to the compilation environment, i.e. if we hit a @@ -415,6 +416,18 @@ fn list_crate_metadata(bytes: @[u8], out: io::writer) { list_crate_items(bytes, md, out); } +fn print_crate_attr(bytes: @[u8], out: io::writer, name: str) { + let md = ebml::new_doc(bytes); + for attr: ast::attribute in get_attributes(md) { + alt attr.node.value.node { + ast::meta_name_value(mname, value) when mname == name { + out.write_str(#fmt["%s\n", pprust::attribute_to_str(attr)]); + } + _ { } + } + } +} + // Local Variables: // mode: rust // fill-column: 78;