use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
use syntax::attr;
use syntax::attr::AttrMetaMethods;
-use syntax::pkgid::PkgId;
+use syntax::crateid::CrateId;
#[deriving(Clone, Eq)]
pub enum output_type {
*
* So here is what we do:
*
- * - Consider the package id; every crate has one (specified with pkgid
+ * - Consider the package id; every crate has one (specified with crate_id
* attribute). If a package id isn't provided explicitly, we infer a
* versionless one from the output name. The version will end up being 0.0
* in this case. CNAME and CVERS are taken from this package id. For
* example, github.com/mozilla/CNAME#CVERS.
*
- * - Define CMH as SHA256(pkgid).
+ * - Define CMH as SHA256(crateid).
*
* - Define CMH8 as the first 8 characters of CMH.
*
symbol_hasher: &mut Sha256)
-> LinkMeta {
// This calculates CMH as defined above
- fn crate_hash(symbol_hasher: &mut Sha256, pkgid: &PkgId) -> @str {
+ fn crate_hash(symbol_hasher: &mut Sha256, crateid: &CrateId) -> @str {
symbol_hasher.reset();
- symbol_hasher.input_str(pkgid.to_str());
+ symbol_hasher.input_str(crateid.to_str());
truncated_hash_result(symbol_hasher).to_managed()
}
Some(s) => s,
};
- let hash = crate_hash(symbol_hasher, &pkgid);
+ let hash = crate_hash(symbol_hasher, &crateid);
LinkMeta {
- pkgid: pkgid,
+ crateid: crateid,
crate_hash: hash,
}
}
// to be independent of one another in the crate.
symbol_hasher.reset();
- symbol_hasher.input_str(link_meta.pkgid.name);
+ symbol_hasher.input_str(link_meta.crateid.name);
symbol_hasher.input_str("-");
symbol_hasher.input_str(link_meta.crate_hash);
symbol_hasher.input_str("-");
let hash = get_symbol_hash(ccx, t);
return exported_name(ccx.sess, path,
hash,
- ccx.link_meta.pkgid.version_or_default());
+ ccx.link_meta.crateid.version_or_default());
}
pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
pub fn output_lib_filename(lm: &LinkMeta) -> ~str {
format!("{}-{}-{}",
- lm.pkgid.name,
+ lm.crateid.name,
lm.crate_hash.slice_chars(0, 8),
- lm.pkgid.version_or_default())
+ lm.crateid.version_or_default())
}
pub fn get_cc_prog(sess: Session) -> ~str {
// except according to those terms.
use std::cast;
-use syntax::pkgid::PkgId;
+use syntax::crateid::CrateId;
// EBML enum definitions and utils shared by the encoder and decoder
#[deriving(Clone)]
pub struct LinkMeta {
- pkgid: PkgId,
+ crateid: CrateId,
crate_hash: @str,
}
use syntax::diagnostic::span_handler;
use syntax::parse::token;
use syntax::parse::token::ident_interner;
-use syntax::pkgid::PkgId;
+use syntax::crateid::CrateId;
use syntax::visit;
// Traverses an AST, reading all the information about use'd crates and extern
cnum: ast::CrateNum,
span: Span,
hash: @str,
- pkgid: PkgId,
+ crateid: CrateId,
}
fn dump_crates(crate_cache: &[cache_entry]) {
diag: @mut span_handler,
crate_cache: &[cache_entry]) {
if crate_cache.len() != 0u {
- let name = crate_cache[crate_cache.len() - 1].pkgid.name.clone();
+ let name = crate_cache[crate_cache.len() - 1].crateid.name.clone();
let (matches, non_matches) = crate_cache.partitioned(|entry|
- name == entry.pkgid.name);
+ name == entry.crateid.name);
assert!(!matches.is_empty());
format!("using multiple versions of crate `{}`", name));
for match_ in matches.iter() {
diag.span_note(match_.span, "used here");
- loader::note_pkgid_attr(diag, &match_.pkgid);
+ loader::note_crateid_attr(diag, &match_.crateid);
}
}
ident, path_opt);
let (name, version) = match path_opt {
Some((path_str, _)) => {
- let crateid: Option<PkgId> = from_str(path_str);
+ let crateid: Option<CrateId> = from_str(path_str);
match crateid {
None => (@"", @""),
Some(crateid) => {
fn existing_match(e: &Env, name: @str, version: @str, hash: &str) -> Option<ast::CrateNum> {
let crate_cache = e.crate_cache.borrow();
for c in crate_cache.get().iter() {
- let pkgid_version = match c.pkgid.version {
+ let crateid_version = match c.crateid.version {
None => @"0.0",
Some(ref ver) => ver.to_managed(),
};
- if (name.is_empty() || c.pkgid.name.to_managed() == name) &&
- (version.is_empty() || pkgid_version == version) &&
+ if (name.is_empty() || c.crateid.name.to_managed() == name) &&
+ (version.is_empty() || crateid_version == version) &&
(hash.is_empty() || c.hash.as_slice() == hash) {
return Some(c.cnum);
}
cnum: cnum,
span: span,
hash: hash,
- pkgid: pkgid,
+ crateid: crateid,
});
}
e.next_crate_num += 1;
let attrs = decoder::get_crate_attributes(data);
match attr::find_crateid(attrs) {
None => @"0.0",
- Some(pkgid) => pkgid.version_or_default().to_managed(),
+ Some(crateid) => crateid.version_or_default().to_managed(),
}
}
ebml_w.end_tag();
}
-// So there's a special crate attribute called 'pkgid' which defines the
+// So there's a special crate attribute called 'crate_id' which defines the
// metadata that Rust cares about for linking crates. If the user didn't
// provide it we will throw it in anyway with a default value.
fn synthesize_crate_attrs(ecx: &EncodeContext,
crate: &Crate) -> ~[Attribute] {
- fn synthesize_pkgid_attr(ecx: &EncodeContext) -> Attribute {
- assert!(!ecx.link_meta.pkgid.name.is_empty());
+ fn synthesize_crateid_attr(ecx: &EncodeContext) -> Attribute {
+ assert!(!ecx.link_meta.crateid.name.is_empty());
attr::mk_attr(
attr::mk_name_value_item_str(
@"crate_id",
- ecx.link_meta.pkgid.to_str().to_managed()))
+ ecx.link_meta.crateid.to_str().to_managed()))
}
let mut attrs = ~[];
attrs.push(*attr);
}
}
- attrs.push(synthesize_pkgid_attr(ecx));
+ attrs.push(synthesize_crateid_attr(ecx));
attrs
}
use syntax::codemap::Span;
use syntax::diagnostic::span_handler;
use syntax::parse::token::ident_interner;
-use syntax::pkgid::PkgId;
+use syntax::crateid::CrateId;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
Some(cvec) =>
if crate_matches(cvec.as_slice(), self.name,
self.version, self.hash) {
- debug!("found {} with matching pkgid",
+ debug!("found {} with matching crate_id",
path.display());
let (rlib, dylib) = if file.ends_with(".rlib") {
(Some(path.clone()), None)
});
FileMatches
} else {
- debug!("skipping {}, pkgid doesn't match",
+ debug!("skipping {}, crate_id doesn't match",
path.display());
FileDoesntMatch
},
let attrs = decoder::get_crate_attributes(data);
match attr::find_crateid(attrs) {
None => {}
- Some(pkgid) => {
- note_pkgid_attr(self.sess.diagnostic(), &pkgid);
+ Some(crateid) => {
+ note_crateid_attr(self.sess.diagnostic(), &crateid);
}
}
}
}
}
-pub fn note_pkgid_attr(diag: @mut span_handler,
- pkgid: &PkgId) {
- diag.handler().note(format!("pkgid: {}", pkgid.to_str()));
+pub fn note_crateid_attr(diag: @mut span_handler,
+ crateid: &CrateId) {
+ diag.handler().note(format!("crate_id: {}", crateid.to_str()));
}
fn crate_matches(crate_data: &[u8],
let attrs = decoder::get_crate_attributes(crate_data);
match attr::find_crateid(attrs) {
None => false,
- Some(pkgid) => {
+ Some(crateid) => {
if !hash.is_empty() {
let chash = decoder::get_crate_hash(crate_data);
if chash != hash { return false; }
}
- name == pkgid.name.to_managed() &&
- (version.is_empty() || version == pkgid.version_or_default().to_managed())
+ name == crateid.name.to_managed() &&
+ (version.is_empty() || version == crateid.version_or_default().to_managed())
}
}
}
let sym_name = if is_top {
~"_rust_crate_map_toplevel"
} else {
- symname(sess, "_rust_crate_map_" + mapmeta.pkgid.name, mapmeta.crate_hash,
- mapmeta.pkgid.version_or_default())
+ symname(sess, "_rust_crate_map_" + mapmeta.crateid.name, mapmeta.crate_hash,
+ mapmeta.crateid.version_or_default())
};
let slicetype = Type::struct_([int_type, int_type], false);
flate::deflate_bytes(metadata);
let llmeta = C_bytes(compressed);
let llconst = C_struct([llmeta], false);
- let name = format!("rust_metadata_{}_{}_{}", cx.link_meta.pkgid.name,
- cx.link_meta.pkgid.version_or_default(), cx.link_meta.crate_hash);
+ let name = format!("rust_metadata_{}_{}_{}", cx.link_meta.crateid.name,
+ cx.link_meta.crateid.version_or_default(), cx.link_meta.crate_hash);
let llglobal = name.with_c_str(|buf| {
unsafe {
llvm::LLVMAddGlobal(cx.metadata_llmod, val_ty(llconst).to_ref(), buf)
// crashes if the module identifer is same as other symbols
// such as a function name in the module.
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
- let llmod_id = link_meta.pkgid.name.clone() + ".rc";
+ let llmod_id = link_meta.crateid.name.clone() + ".rc";
let ccx = @CrateContext::new(sess,
llmod_id,
if def_id.crate == ast::LOCAL_CRATE {
// prepend crate name if not already present
- let crate_namespace_ident = token::str_to_ident(cx.link_meta.pkgid.name);
+ let crate_namespace_ident = token::str_to_ident(cx.link_meta.crateid.name);
item_path.insert(0, ast_map::path_mod(crate_namespace_ident));
}
Some(&src) => {
ccx.sess.cstore.get_crate_data(src.crate).name
}
- None => ccx.link_meta.pkgid.name.to_managed(),
+ None => ccx.link_meta.crateid.name.to_managed(),
};
};
let mut modpath = ~[path_mod(ccx.sess.ident_of(srccrate))];
use codemap::BytePos;
use diagnostic::span_handler;
use parse::comments::{doc_comment_style, strip_doc_comment_decoration};
-use pkgid::PkgId;
+use crateid::CrateId;
use std::hashmap::HashSet;
--- /dev/null
+// Copyright 2013 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.
+
+/// CrateIds identify crates and include the crate name and optionally a path
+/// and version. In the full form, they look like relative URLs. Example:
+/// `github.com/mozilla/rust#std:1.0` would be a package ID with a path of
+/// `gitub.com/mozilla/rust` and a crate name of `std` with a version of
+/// `1.0`. If no crate name is given after the hash, the name is inferred to
+/// be the last component of the path. If no version is given, it is inferred
+/// to be `0.0`.
+#[deriving(Clone, Eq)]
+pub struct CrateId {
+ /// A path which represents the codes origin. By convention this is the
+ /// URL, without `http://` or `https://` prefix, to the crate's repository
+ path: ~str,
+ /// The name of the crate.
+ name: ~str,
+ /// The version of the crate.
+ version: Option<~str>,
+}
+
+impl ToStr for CrateId {
+ fn to_str(&self) -> ~str {
+ let version = match self.version {
+ None => "0.0",
+ Some(ref version) => version.as_slice(),
+ };
+ if self.path == self.name || self.path.ends_with(format!("/{}", self.name)) {
+ format!("{}\\#{}", self.path, version)
+ } else {
+ format!("{}\\#{}:{}", self.path, self.name, version)
+ }
+ }
+}
+
+impl FromStr for CrateId {
+ fn from_str(s: &str) -> Option<CrateId> {
+ let pieces: ~[&str] = s.splitn('#', 1).collect();
+ let path = pieces[0].to_owned();
+
+ if path.starts_with("/") || path.ends_with("/") ||
+ path.starts_with(".") || path.is_empty() {
+ return None;
+ }
+
+ let path_pieces: ~[&str] = path.rsplitn('/', 1).collect();
+ let inferred_name = path_pieces[0];
+
+ let (name, version) = if pieces.len() == 1 {
+ (inferred_name.to_owned(), None)
+ } else {
+ let hash_pieces: ~[&str] = pieces[1].splitn(':', 1).collect();
+ let (hash_name, hash_version) = if hash_pieces.len() == 1 {
+ ("", hash_pieces[0])
+ } else {
+ (hash_pieces[0], hash_pieces[1])
+ };
+
+ let name = if !hash_name.is_empty() {
+ hash_name.to_owned()
+ } else {
+ inferred_name.to_owned()
+ };
+
+ let version = if !hash_version.is_empty() {
+ Some(hash_version.to_owned())
+ } else {
+ None
+ };
+
+ (name, version)
+ };
+
+ Some(CrateId {
+ path: path,
+ name: name,
+ version: version,
+ })
+ }
+}
+
+impl CrateId {
+ pub fn version_or_default<'a>(&'a self) -> &'a str {
+ match self.version {
+ None => "0.0",
+ Some(ref version) => version.as_slice(),
+ }
+ }
+}
+
+#[test]
+fn bare_name() {
+ let crateid: CrateId = from_str("foo").expect("valid crateid");
+ assert_eq!(crateid.name, ~"foo");
+ assert_eq!(crateid.version, None);
+ assert_eq!(crateid.path, ~"foo");
+}
+
+#[test]
+fn bare_name_single_char() {
+ let crateid: CrateId = from_str("f").expect("valid crateid");
+ assert_eq!(crateid.name, ~"f");
+ assert_eq!(crateid.version, None);
+ assert_eq!(crateid.path, ~"f");
+}
+
+#[test]
+fn empty_crateid() {
+ let crateid: Option<CrateId> = from_str("");
+ assert!(crateid.is_none());
+}
+
+#[test]
+fn simple_path() {
+ let crateid: CrateId = from_str("example.com/foo/bar").expect("valid crateid");
+ assert_eq!(crateid.name, ~"bar");
+ assert_eq!(crateid.version, None);
+ assert_eq!(crateid.path, ~"example.com/foo/bar");
+}
+
+#[test]
+fn simple_version() {
+ let crateid: CrateId = from_str("foo#1.0").expect("valid crateid");
+ assert_eq!(crateid.name, ~"foo");
+ assert_eq!(crateid.version, Some(~"1.0"));
+ assert_eq!(crateid.path, ~"foo");
+}
+
+#[test]
+fn absolute_path() {
+ let crateid: Option<CrateId> = from_str("/foo/bar");
+ assert!(crateid.is_none());
+}
+
+#[test]
+fn path_ends_with_slash() {
+ let crateid: Option<CrateId> = from_str("foo/bar/");
+ assert!(crateid.is_none());
+}
+
+#[test]
+fn path_and_version() {
+ let crateid: CrateId = from_str("example.com/foo/bar#1.0").expect("valid crateid");
+ assert_eq!(crateid.name, ~"bar");
+ assert_eq!(crateid.version, Some(~"1.0"));
+ assert_eq!(crateid.path, ~"example.com/foo/bar");
+}
+
+#[test]
+fn single_chars() {
+ let crateid: CrateId = from_str("a/b#1").expect("valid crateid");
+ assert_eq!(crateid.name, ~"b");
+ assert_eq!(crateid.version, Some(~"1"));
+ assert_eq!(crateid.path, ~"a/b");
+}
+
+#[test]
+fn missing_version() {
+ let crateid: CrateId = from_str("foo#").expect("valid crateid");
+ assert_eq!(crateid.name, ~"foo");
+ assert_eq!(crateid.version, None);
+ assert_eq!(crateid.path, ~"foo");
+}
+
+#[test]
+fn path_and_name() {
+ let crateid: CrateId = from_str("foo/rust-bar#bar:1.0").expect("valid crateid");
+ assert_eq!(crateid.name, ~"bar");
+ assert_eq!(crateid.version, Some(~"1.0"));
+ assert_eq!(crateid.path, ~"foo/rust-bar");
+}
+
+#[test]
+fn empty_name() {
+ let crateid: CrateId = from_str("foo/bar#:1.0").expect("valid crateid");
+ assert_eq!(crateid.name, ~"bar");
+ assert_eq!(crateid.version, Some(~"1.0"));
+ assert_eq!(crateid.path, ~"foo/bar");
+}
pub mod parse;
-pub mod pkgid;
+pub mod crateid;
pub mod print {
pub mod pp;
+++ /dev/null
-// Copyright 2013 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.
-
-/// PkgIds identify crates and include the crate name and optionall a path and
-/// version. In the full form, they look like relative URLs. Example:
-/// `github.com/mozilla/rust#std:1.0` would be a package ID with a path of
-/// `gitub.com/mozilla/rust` and a crate name of `std` with a version of
-/// `1.0`. If no crate name is given after the hash, the name is inferred to
-/// be the last component of the path. If no version is given, it is inferred
-/// to be `0.0`.
-#[deriving(Clone, Eq)]
-pub struct PkgId {
- /// A path which represents the codes origin. By convention this is the
- /// URL, without `http://` or `https://` prefix, to the crate's repository
- path: ~str,
- /// The name of the crate.
- name: ~str,
- /// The version of the crate.
- version: Option<~str>,
-}
-
-impl ToStr for PkgId {
- fn to_str(&self) -> ~str {
- let version = match self.version {
- None => "0.0",
- Some(ref version) => version.as_slice(),
- };
- if self.path == self.name || self.path.ends_with(format!("/{}", self.name)) {
- format!("{}\\#{}", self.path, version)
- } else {
- format!("{}\\#{}:{}", self.path, self.name, version)
- }
- }
-}
-
-impl FromStr for PkgId {
- fn from_str(s: &str) -> Option<PkgId> {
- let pieces: ~[&str] = s.splitn('#', 1).collect();
- let path = pieces[0].to_owned();
-
- if path.starts_with("/") || path.ends_with("/") ||
- path.starts_with(".") || path.is_empty() {
- return None;
- }
-
- let path_pieces: ~[&str] = path.rsplitn('/', 1).collect();
- let inferred_name = path_pieces[0];
-
- let (name, version) = if pieces.len() == 1 {
- (inferred_name.to_owned(), None)
- } else {
- let hash_pieces: ~[&str] = pieces[1].splitn(':', 1).collect();
- let (hash_name, hash_version) = if hash_pieces.len() == 1 {
- ("", hash_pieces[0])
- } else {
- (hash_pieces[0], hash_pieces[1])
- };
-
- let name = if !hash_name.is_empty() {
- hash_name.to_owned()
- } else {
- inferred_name.to_owned()
- };
-
- let version = if !hash_version.is_empty() {
- Some(hash_version.to_owned())
- } else {
- None
- };
-
- (name, version)
- };
-
- Some(PkgId {
- path: path,
- name: name,
- version: version,
- })
- }
-}
-
-impl PkgId {
- pub fn version_or_default<'a>(&'a self) -> &'a str {
- match self.version {
- None => "0.0",
- Some(ref version) => version.as_slice(),
- }
- }
-}
-
-#[test]
-fn bare_name() {
- let pkgid: PkgId = from_str("foo").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"foo");
- assert_eq!(pkgid.version, None);
- assert_eq!(pkgid.path, ~"foo");
-}
-
-#[test]
-fn bare_name_single_char() {
- let pkgid: PkgId = from_str("f").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"f");
- assert_eq!(pkgid.version, None);
- assert_eq!(pkgid.path, ~"f");
-}
-
-#[test]
-fn empty_pkgid() {
- let pkgid: Option<PkgId> = from_str("");
- assert!(pkgid.is_none());
-}
-
-#[test]
-fn simple_path() {
- let pkgid: PkgId = from_str("example.com/foo/bar").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"bar");
- assert_eq!(pkgid.version, None);
- assert_eq!(pkgid.path, ~"example.com/foo/bar");
-}
-
-#[test]
-fn simple_version() {
- let pkgid: PkgId = from_str("foo#1.0").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"foo");
- assert_eq!(pkgid.version, Some(~"1.0"));
- assert_eq!(pkgid.path, ~"foo");
-}
-
-#[test]
-fn absolute_path() {
- let pkgid: Option<PkgId> = from_str("/foo/bar");
- assert!(pkgid.is_none());
-}
-
-#[test]
-fn path_ends_with_slash() {
- let pkgid: Option<PkgId> = from_str("foo/bar/");
- assert!(pkgid.is_none());
-}
-
-#[test]
-fn path_and_version() {
- let pkgid: PkgId = from_str("example.com/foo/bar#1.0").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"bar");
- assert_eq!(pkgid.version, Some(~"1.0"));
- assert_eq!(pkgid.path, ~"example.com/foo/bar");
-}
-
-#[test]
-fn single_chars() {
- let pkgid: PkgId = from_str("a/b#1").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"b");
- assert_eq!(pkgid.version, Some(~"1"));
- assert_eq!(pkgid.path, ~"a/b");
-}
-
-#[test]
-fn missing_version() {
- let pkgid: PkgId = from_str("foo#").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"foo");
- assert_eq!(pkgid.version, None);
- assert_eq!(pkgid.path, ~"foo");
-}
-
-#[test]
-fn path_and_name() {
- let pkgid: PkgId = from_str("foo/rust-bar#bar:1.0").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"bar");
- assert_eq!(pkgid.version, Some(~"1.0"));
- assert_eq!(pkgid.path, ~"foo/rust-bar");
-}
-
-#[test]
-fn empty_name() {
- let pkgid: PkgId = from_str("foo/bar#:1.0").expect("valid pkgid");
- assert_eq!(pkgid.name, ~"bar");
- assert_eq!(pkgid.version, Some(~"1.0"));
- assert_eq!(pkgid.path, ~"foo/bar");
-}