Skip to content

Commit d760f99

Browse files
committed
auto merge of #11041 : cmr/rust/pkgid_changes, r=cmr,metajack
2 parents e86cdaf + b25a052 commit d760f99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+138
-69
lines changed

src/etc/combine-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def scrub(b):
4444
c.write(
4545
"""
4646
// AUTO-GENERATED FILE: DO NOT EDIT
47+
#[crate_id=\"run_pass_stage2#0.1\"];
4748
#[pkgid=\"run_pass_stage2#0.1\"];
4849
#[link(name=\"run_pass_stage2\", vers=\"0.1\")];
4950
#[feature(globs, macro_rules, struct_variant, managed_boxes)];

src/libextra/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ Rust extras are part of the standard Rust distribution.
2020
2121
*/
2222

23+
// NOTE: remove after snapshot
2324
#[pkgid = "extra#0.9-pre"];
25+
#[crate_id = "extra#0.9-pre"];
2426
#[comment = "Rust extras"];
2527
#[license = "MIT/ASL2"];
2628
#[crate_type = "rlib"];

src/librustc/back/link.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -751,14 +751,10 @@ fn is_writeable(p: &Path) -> bool {
751751
}
752752
}
753753

754-
fn link_binary_output(sess: Session,
755-
trans: &CrateTranslation,
756-
output: session::OutputStyle,
757-
obj_filename: &Path,
758-
out_filename: &Path,
759-
lm: &LinkMeta) -> Path {
754+
pub fn filename_for_input(sess: &Session, output: session::OutputStyle, lm: &LinkMeta,
755+
out_filename: &Path) -> Path {
760756
let libname = output_lib_filename(lm);
761-
let out_filename = match output {
757+
match output {
762758
session::OutputRlib => {
763759
out_filename.with_filename(format!("lib{}.rlib", libname))
764760
}
@@ -776,7 +772,17 @@ fn link_binary_output(sess: Session,
776772
out_filename.with_filename(format!("lib{}.a", libname))
777773
}
778774
session::OutputExecutable => out_filename.clone(),
779-
};
775+
}
776+
777+
}
778+
779+
fn link_binary_output(sess: Session,
780+
trans: &CrateTranslation,
781+
output: session::OutputStyle,
782+
obj_filename: &Path,
783+
out_filename: &Path,
784+
lm: &LinkMeta) -> Path {
785+
let out_filename = filename_for_input(&sess, output, lm, out_filename);
780786

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

src/librustc/driver/driver.rs

Lines changed: 46 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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/librustc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// NOTE: remove after snapshot
1112
#[pkgid = "rustc#0.9-pre"];
13+
#[crate_id = "rustc#0.9-pre"];
1214
#[comment = "The Rust compiler"];
1315
#[license = "MIT/ASL2"];
1416
#[crate_type = "dylib"];

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,13 +1499,13 @@ fn synthesize_crate_attrs(ecx: &EncodeContext,
14991499

15001500
attr::mk_attr(
15011501
attr::mk_name_value_item_str(
1502-
@"pkgid",
1502+
@"crate_id",
15031503
ecx.link_meta.pkgid.to_str().to_managed()))
15041504
}
15051505

15061506
let mut attrs = ~[];
15071507
for attr in crate.attrs.iter() {
1508-
if "pkgid" != attr.name() {
1508+
if "crate_id" != attr.name() {
15091509
attrs.push(*attr);
15101510
}
15111511
}

src/librustc/middle/lint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,8 @@ fn check_heap_item(cx: &Context, it: &ast::item) {
832832
}
833833

834834
static crate_attrs: &'static [&'static str] = &[
835-
"crate_type", "feature", "no_uv", "no_main", "no_std", "pkgid",
835+
// NOTE: remove pkgid after snapshot
836+
"crate_type", "feature", "no_uv", "no_main", "no_std", "pkgid", "crate_id",
836837
"desc", "comment", "license", "copyright", // not used in rustc now
837838
];
838839

src/librustdoc/clean.rs

Lines changed: 1 addition & 1 deletion
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/librustdoc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// NOTE: remove after snapshot
1112
#[pkgid = "rustdoc#0.9-pre"];
13+
#[crate_id = "rustdoc#0.9-pre"];
1214
#[desc = "rustdoc, the Rust documentation extractor"];
1315
#[license = "MIT/ASL2"];
1416
#[crate_type = "dylib"];

0 commit comments

Comments
 (0)