Skip to content

Add a default value for the 'package_id' meta attribute for library crates #10368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libextra/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Rust extras are part of the standard Rust distribution.
*/

#[link(name = "extra",
package_id = "extra",
vers = "0.9-pre",
uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297",
url = "https://github.com/mozilla/rust/tree/master/src/libextra")];
Expand Down
17 changes: 15 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,18 @@ pub fn build_link_meta(sess: Session,
}
}

fn crate_meta_pkgid(sess: Session, name: @str, opt_pkg_id: Option<@str>)
-> @str {
match opt_pkg_id {
Some(v) if !v.is_empty() => v,
_ => {
let pkg_id = name.clone();
warn_missing(sess, "package_id", pkg_id);
pkg_id
}
}
}

let ProvidedMetas {
name: opt_name,
vers: opt_vers,
Expand All @@ -642,15 +654,16 @@ pub fn build_link_meta(sess: Session,
} = provided_link_metas(sess, c);
let name = crate_meta_name(sess, output, opt_name);
let vers = crate_meta_vers(sess, opt_vers);
let pkg_id = crate_meta_pkgid(sess, name, opt_pkg_id);
let dep_hashes = cstore::get_dep_hashes(sess.cstore);
let extras_hash =
crate_meta_extras_hash(symbol_hasher, cmh_items,
dep_hashes, opt_pkg_id);
dep_hashes, Some(pkg_id));

LinkMeta {
name: name,
vers: vers,
package_id: opt_pkg_id,
package_id: Some(pkg_id),
extras_hash: extras_hash
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#[link(name = "rustc",
package_id = "rustc",
vers = "0.9-pre",
uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf",
url = "https://github.com/mozilla/rust/tree/master/src/rustc")];
Expand Down
19 changes: 15 additions & 4 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,8 +1487,8 @@ fn encode_attributes(ebml_w: &mut writer::Encoder, attrs: &[Attribute]) {

// So there's a special crate attribute called 'link' which defines the
// metadata that Rust cares about for linking crates. This attribute requires
// 'name' and 'vers' items, so if the user didn't provide them we will throw
// them in anyway with default values.
// 'name', 'vers' and 'package_id' items, so if the user didn't provide them we
// will throw them in anyway with default values.
fn synthesize_crate_attrs(ecx: &EncodeContext,
crate: &Crate) -> ~[Attribute] {

Expand All @@ -1505,9 +1505,20 @@ fn synthesize_crate_attrs(ecx: &EncodeContext,
attr::mk_name_value_item_str(@"vers",
ecx.link_meta.vers);

let mut meta_items = ~[name_item, vers_item];
let pkgid_item = match ecx.link_meta.package_id {
Some(pkg_id) => attr::mk_name_value_item_str(@"package_id",
pkg_id),
// uses package_id equal to name;
// this should never happen here but package_id is an Option
// FIXME (#10370): change package_id in LinkMeta to @str instead of Option<@str>
_ => attr::mk_name_value_item_str(@"package_id",
ecx.link_meta.name)
};

let mut meta_items = ~[name_item, vers_item, pkgid_item];

for &mi in items.iter().filter(|mi| "name" != mi.name() && "vers" != mi.name()) {
for &mi in items.iter().filter(|mi| "name" != mi.name() && "vers" != mi.name() &&
"package_id" != mi.name()) {
meta_items.push(mi);
}
let link_item = attr::mk_list_item(@"link", meta_items);
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#[link(name = "rustdoc",
package_id = "rustdoc",
vers = "0.9-pre",
uuid = "8c6e4598-1596-4aa5-a24c-b811914bbbc6",
url = "https://github.com/mozilla/rust/tree/master/src/librustdoc")];
Expand Down
1 change: 1 addition & 0 deletions src/librustpkg/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// rustpkg - a package manager and build system for Rust

#[link(name = "rustpkg",
package_id = "rustpkg",
vers = "0.9-pre",
uuid = "25de5e6e-279e-4a20-845c-4cabae92daaf",
url = "https://github.com/mozilla/rust/tree/master/src/librustpkg")];
Expand Down
1 change: 1 addition & 0 deletions src/librustuv/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ via `close` and `delete` methods.
*/

#[link(name = "rustuv",
package_id = "rustuv",
vers = "0.9-pre",
uuid = "f3719011-0459-9b86-b11c-29265c0d0864",
url = "https://github.com/mozilla/rust/tree/master/src/librustuv")];
Expand Down
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
//! use std::prelude::*;

#[link(name = "std",
package_id = "std",
vers = "0.9-pre",
uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8",
url = "https://github.com/mozilla/rust/tree/master/src/libstd")];
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#[link(name = "syntax",
package_id = "syntax",
vers = "0.9-pre",
uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")];

Expand Down
17 changes: 17 additions & 0 deletions src/test/auxiliary/crateresolve8-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// default link meta for 'package_id' will be equal to filestem
#[link(name = "crateresolve8",
vers = "0.1")];

#[crate_type = "lib"];

pub fn f() -> int { 20 }
19 changes: 19 additions & 0 deletions src/test/run-pass/crateresolve8.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-fast
// aux-build:crateresolve8-1.rs

extern mod crateresolve8(vers = "0.1", package_id="crateresolve8");
//extern mod crateresolve8(vers = "0.1");

pub fn main() {
assert_eq!(crateresolve8::f(), 20);
}