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

+1
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

+2
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

+14-8
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

+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/librustc/lib.rs

+2
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

+2-2
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

+2-1
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

+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/librustdoc/lib.rs

+2
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"];

src/librustpkg/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
// rustpkg - a package manager and build system for Rust
1212

13+
// NOTE: remove after snapshot
1314
#[pkgid = "rustpkg#0.9-pre"];
15+
#[crate_id = "rustpkg#0.9-pre"];
1416
#[license = "MIT/ASL2"];
1517
#[crate_type = "dylib"];
1618

src/librustpkg/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1892,9 +1892,9 @@ fn pkgid_pointing_to_subdir() {
18921892
fs::mkdir_recursive(&foo_dir, io::UserRWX);
18931893
fs::mkdir_recursive(&bar_dir, io::UserRWX);
18941894
writeFile(&foo_dir.join("lib.rs"),
1895-
"#[pkgid=\"mockgh.loli.garden/mozilla/some_repo/extras/foo\"]; pub fn f() {}");
1895+
"#[crate_id=\"mockgh.loli.garden/mozilla/some_repo/extras/foo\"]; pub fn f() {}");
18961896
writeFile(&bar_dir.join("lib.rs"),
1897-
"#[pkgid=\"mockgh.loli.garden/mozilla/some_repo/extras/bar\"]; pub fn g() {}");
1897+
"#[crate_id=\"mockgh.loli.garden/mozilla/some_repo/extras/bar\"]; pub fn g() {}");
18981898

18991899
debug!("Creating a file in {}", workspace.display());
19001900
let testpkg_dir = workspace.join_many(["src", "testpkg-0.0"]);
@@ -2316,7 +2316,7 @@ fn find_sources_in_cwd() {
23162316
let source_dir = temp_dir.join("foo");
23172317
fs::mkdir_recursive(&source_dir, io::UserRWX);
23182318
writeFile(&source_dir.join("main.rs"),
2319-
"fn main() { let _x = (); }");
2319+
r#"#[crate_id="foo"]; fn main() { let _x = (); }"#);
23202320
command_line_test([~"install", ~"foo"], &source_dir);
23212321
assert_executable_exists(&source_dir.join(".rust"), "foo");
23222322
}

src/librustpkg/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ pub fn compile_input(context: &BuildContext,
291291
});
292292

293293
// Inject the pkgid attribute so we get the right package name and version
294-
if !attr::contains_name(crate.attrs, "pkgid") {
294+
if !attr::contains_name(crate.attrs, "crate_id") {
295295
// FIXME (#9639): This needs to handle non-utf8 paths
296296
let pkgid_attr =
297-
attr::mk_name_value_item_str(@"pkgid",
297+
attr::mk_name_value_item_str(@"crate_id",
298298
format!("{}\\#{}",
299299
pkg_id.path.as_str().unwrap(),
300300
pkg_id.version.to_str()).to_managed());

src/librustuv/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ via `close` and `delete` methods.
3434
3535
*/
3636

37+
// NOTE: remove after snapshot
3738
#[pkgid = "rustuv#0.9-pre"];
39+
#[crate_id = "rustuv#0.9-pre"];
3840
#[license = "MIT/ASL2"];
3941
#[crate_type = "rlib"];
4042
#[crate_type = "dylib"];

src/libstd/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
//!
4444
//! use std::prelude::*;
4545
46+
// NOTE: remove after snapshot
4647
#[pkgid = "std#0.9-pre"];
48+
#[crate_id = "std#0.9-pre"];
4749
#[comment = "The Rust standard library"];
4850
#[license = "MIT/ASL2"];
4951
#[crate_type = "rlib"];

src/libsyntax/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn find_linkage_metas(attrs: &[Attribute]) -> ~[@MetaItem] {
237237
}
238238

239239
pub fn find_pkgid(attrs: &[Attribute]) -> Option<PkgId> {
240-
match first_attr_value_str_by_name(attrs, "pkgid") {
240+
match first_attr_value_str_by_name(attrs, "crate_id") {
241241
None => None,
242242
Some(id) => from_str::<PkgId>(id),
243243
}

src/libsyntax/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* macros.
1414
*/
1515

16+
// NOTE: remove pkgid after snapshot
1617
#[pkgid = "syntax#0.9-pre"];
18+
#[crate_id = "syntax#0.9-pre"];
1719
#[license = "MIT/ASL2"];
1820
#[crate_type = "dylib"];
1921
#[crate_type = "rlib"];

src/test/auxiliary/anon-extern-mod-cross-crate-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="anonexternmod#0.1"];
11+
#[crate_id="anonexternmod#0.1"];
1212

1313
use std::libc;
1414

src/test/auxiliary/cci_impl_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="cci_impl_lib"];
11+
#[crate_id="cci_impl_lib"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name="cci_impl_lib", vers="0.0")];
1414

src/test/auxiliary/cci_iter_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="cci_iter_lib"];
11+
#[crate_id="cci_iter_lib"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name="cci_iter_lib", vers="0.0")];
1414

src/test/auxiliary/cci_no_inline_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="cci_no_inline_lib"];
11+
#[crate_id="cci_no_inline_lib"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name="cci_no_inline_lib", vers="0.0")];
1414

src/test/auxiliary/crate-method-reexport-grrrrrrr2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
#[feature(managed_boxes)];
12-
#[pkgid="crate_method_reexport_grrrrrrr2"];
12+
#[crate_id="crate_method_reexport_grrrrrrr2"];
1313
// NOTE: remove after the next snapshot
1414
#[link(name = "crate_method_reexport_grrrrrrr2")];
1515

src/test/auxiliary/crateresolve1-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="crateresolve1#0.1"];
11+
#[crate_id="crateresolve1#0.1"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name = "crateresolve1",
1414
vers = "0.1")];

src/test/auxiliary/crateresolve1-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="crateresolve1#0.2"];
11+
#[crate_id="crateresolve1#0.2"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name = "crateresolve1",
1414
vers = "0.2")];

src/test/auxiliary/crateresolve1-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="crateresolve1#0.3"];
11+
#[crate_id="crateresolve1#0.3"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name = "crateresolve1",
1414
vers = "0.3")];

src/test/auxiliary/crateresolve2-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="crateresolve2#0.1"];
11+
#[crate_id="crateresolve2#0.1"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name = "crateresolve2",
1414
vers = "0.1")];

src/test/auxiliary/crateresolve2-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="crateresolve2#0.2"];
11+
#[crate_id="crateresolve2#0.2"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name = "crateresolve2",
1414
vers = "0.2")];

src/test/auxiliary/crateresolve2-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="crateresolve2#0.3"];
11+
#[crate_id="crateresolve2#0.3"];
1212
// NOTE: remove after the next snapshot
1313
#[link(name = "crateresolve2",
1414
vers = "0.3")];

0 commit comments

Comments
 (0)