Skip to content

Rename pkgid and PkgId to crateid and CrateId #11182

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 4 commits into from
Dec 30, 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
12 changes: 6 additions & 6 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ the behavior of the compiler.

~~~~
// Package ID
#[ pkgid = "projx#2.5" ];
#[ crate_id = "projx#2.5" ];

// Additional metadata attributes
#[ desc = "Project X" ];
Expand Down Expand Up @@ -776,9 +776,9 @@ as the `ident` provided in the `extern_mod_decl`.
The external crate is resolved to a specific `soname` at compile time, and a
runtime linkage requirement to that `soname` is passed to the linker for
loading at runtime. The `soname` is resolved at compile time by scanning the
compiler's library path and matching the optional `pkgid` provided as a string literal
against the `pkgid` attributes that were declared on the external crate when
it was compiled. If no `pkgid` is provided, a default `name` attribute is
compiler's library path and matching the optional `crateid` provided as a string literal
against the `crateid` attributes that were declared on the external crate when
it was compiled. If no `crateid` is provided, a default `name` attribute is
assumed, equal to the `ident` given in the `extern_mod_decl`.

Four examples of `extern mod` declarations:
Expand Down Expand Up @@ -1729,7 +1729,7 @@ names are effectively reserved. Some significant attributes include:
* The `cfg` attribute, for conditional-compilation by build-configuration.
* The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
* The `link` attribute, for describing linkage metadata for a extern blocks.
* The `pkgid` attribute, for describing the package ID of a crate.
* The `crate_id` attribute, for describing the package ID of a crate.
* The `test` attribute, for marking functions as unit tests.
* The `allow`, `warn`, `forbid`, and `deny` attributes, for
controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
Expand Down Expand Up @@ -3792,7 +3792,7 @@ specified then log level 4 is assumed. Debug messages can be omitted
by passing `--cfg ndebug` to `rustc`.

As an example, to see all the logs generated by the compiler, you would set
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `pkgid`
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `crate_id`
[attribute](#attributes)). To narrow down the logs to just crate resolution,
you would set it to `rustc::metadata::creader`. To see just error logging
use `rustc=0`.
Expand Down
2 changes: 1 addition & 1 deletion doc/rustdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ comments":
~~~
// the "link" crate attribute is currently required for rustdoc, but normally
// isn't needed.
#[pkgid = "universe"];
#[crate_id = "universe"];
#[crate_type="lib"];

//! Tools for dealing with universes (this is a doc comment, and is shown on
Expand Down
2 changes: 1 addition & 1 deletion doc/rustpkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ then both `bar` and `bar/extras/baz` are valid package identifiers
in the workspace `foo`.

Because rustpkg uses generic source file names as the main inputs, you will
need to specify the package identifier in them using the `pkgid` attribute
need to specify the package identifier in them using the `crate_id` attribute
on the crate.

## Source files
Expand Down
2 changes: 1 addition & 1 deletion src/etc/combine-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def scrub(b):
"""
// AUTO-GENERATED FILE: DO NOT EDIT
#[crate_id=\"run_pass_stage2#0.1\"];
#[pkgid=\"run_pass_stage2#0.1\"];
#[crate_id=\"run_pass_stage2#0.1\"];
#[feature(globs, macro_rules, struct_variant, managed_boxes)];
#[allow(warnings)];
"""
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use syntax::ast;
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 {
Expand Down Expand Up @@ -444,13 +444,13 @@ pub mod write {
*
* 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.
*
Expand All @@ -469,13 +469,13 @@ pub fn build_link_meta(sess: Session,
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()
}

let pkgid = match attr::find_pkgid(attrs) {
let crateid = match attr::find_crateid(attrs) {
None => {
let stem = session::expect(
sess,
Expand All @@ -487,10 +487,10 @@ pub fn build_link_meta(sess: Session,
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,
}
}
Expand All @@ -509,7 +509,7 @@ pub fn symbol_hash(tcx: ty::ctxt,
// 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("-");
Expand Down Expand Up @@ -669,7 +669,7 @@ pub fn mangle_exported_name(ccx: &CrateContext,
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,
Expand Down Expand Up @@ -710,9 +710,9 @@ pub fn mangle_internal_name_by_path(ccx: &CrateContext, path: path) -> ~str {

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 {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,12 @@ pub fn build_output_filenames(input: &input,
str_input(_) => @"rust_out"
};

// If a pkgid is present, we use it as the link name
let pkgid = attr::find_pkgid(attrs);
match pkgid {
// If a crateid is present, we use it as the link name
let crateid = attr::find_crateid(attrs);
match crateid {
None => {}
Some(pkgid) => {
stem = pkgid.name.to_managed()
Some(crateid) => {
stem = crateid.name.to_managed()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item {
}

fn is_extra(crate: &ast::Crate) -> bool {
match attr::find_pkgid(crate.attrs) {
match attr::find_crateid(crate.attrs) {
Some(ref s) if "extra" == s.name => true,
_ => false
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,18 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
let t_outputs = d::build_output_filenames(&input, &odir, &ofile,
attrs, sess);
if crate_id || crate_name {
let pkgid = match attr::find_pkgid(attrs) {
Some(pkgid) => pkgid,
let crateid = match attr::find_crateid(attrs) {
Some(crateid) => crateid,
None => {
sess.fatal("No crate_id and --crate-id or \
--crate-name requested")
}
};
if crate_id {
println(pkgid.to_str());
println(crateid.to_str());
}
if crate_name {
println(pkgid.name);
println(crateid.name);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// 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

Expand Down Expand Up @@ -206,6 +206,6 @@ pub static tag_native_libraries_kind: uint = 0x106;

#[deriving(Clone)]
pub struct LinkMeta {
pkgid: PkgId,
crateid: CrateId,
crate_hash: @str,
}
30 changes: 15 additions & 15 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use syntax::codemap::{Span, dummy_sp};
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
Expand Down Expand Up @@ -73,7 +73,7 @@ struct cache_entry {
cnum: ast::CrateNum,
span: Span,
hash: @str,
pkgid: PkgId,
crateid: CrateId,
}

fn dump_crates(crate_cache: &[cache_entry]) {
Expand All @@ -89,10 +89,10 @@ fn warn_if_multiple_versions(e: &mut Env,
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());

Expand All @@ -101,7 +101,7 @@ fn warn_if_multiple_versions(e: &mut Env,
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);
}
}

Expand Down Expand Up @@ -138,15 +138,15 @@ fn visit_view_item(e: &mut Env, i: &ast::view_item) {
ident, path_opt);
let (name, version) = match path_opt {
Some((path_str, _)) => {
let pkgid: Option<PkgId> = from_str(path_str);
match pkgid {
let crateid: Option<CrateId> = from_str(path_str);
match crateid {
None => (@"", @""),
Some(pkgid) => {
let version = match pkgid.version {
Some(crateid) => {
let version = match crateid.version {
None => @"",
Some(ref ver) => ver.to_managed(),
};
(pkgid.name.to_managed(), version)
(crateid.name.to_managed(), version)
}
}
}
Expand Down Expand Up @@ -245,12 +245,12 @@ fn visit_item(e: &Env, i: @ast::item) {
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);
}
Expand Down Expand Up @@ -282,7 +282,7 @@ fn resolve_crate(e: &mut Env,
} = load_ctxt.load_library_crate();

let attrs = decoder::get_crate_attributes(metadata.as_slice());
let pkgid = attr::find_pkgid(attrs).unwrap();
let crateid = attr::find_crateid(attrs).unwrap();
let hash = decoder::get_crate_hash(metadata.as_slice());

// Claim this crate number and cache it
Expand All @@ -293,7 +293,7 @@ fn resolve_crate(e: &mut Env,
cnum: cnum,
span: span,
hash: hash,
pkgid: pkgid,
crateid: crateid,
});
}
e.next_crate_num += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,9 +1173,9 @@ pub fn get_crate_hash(data: &[u8]) -> @str {

pub fn get_crate_vers(data: &[u8]) -> @str {
let attrs = decoder::get_crate_attributes(data);
match attr::find_pkgid(attrs) {
match attr::find_crateid(attrs) {
None => @"0.0",
Some(pkgid) => pkgid.version_or_default().to_managed(),
Some(crateid) => crateid.version_or_default().to_managed(),
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,19 +1559,19 @@ fn encode_attributes(ebml_w: &mut writer::Encoder, attrs: &[Attribute]) {
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 = ~[];
Expand All @@ -1580,7 +1580,7 @@ fn synthesize_crate_attrs(ecx: &EncodeContext,
attrs.push(*attr);
}
}
attrs.push(synthesize_pkgid_attr(ecx));
attrs.push(synthesize_crateid_attr(ecx));

attrs
}
Expand Down
Loading