Skip to content

Commit 363fa51

Browse files
committed
Use the libsyntax PkgId parser in Rustpkg, but keep Rustpkg's version smarts.
This fixes a bug where new syntax crate IDs would cause rustpkg to fail to build crates.
1 parent 4098327 commit 363fa51

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/librustpkg/crate_id.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
// except according to those terms.
1010

1111
use version::{try_getting_version, try_getting_local_version,
12-
Version, NoVersion, split_version};
12+
Version, NoVersion, ExactRevision};
1313
use std::hash::Streaming;
1414
use std::hash;
15+
use syntax::crateid;
1516

1617
/// Path-fragment identifier of a package such as
1718
/// 'github.com/graydon/test'; path must be a relative
@@ -45,27 +46,14 @@ impl CrateId {
4546
pub fn new(s: &str) -> CrateId {
4647
use conditions::bad_pkg_id::cond;
4748

48-
let mut given_version = None;
49-
50-
// Did the user request a specific version?
51-
let s = match split_version(s) {
52-
Some((path, v)) => {
53-
given_version = Some(v);
54-
path
55-
}
56-
None => {
57-
s
58-
}
59-
};
60-
61-
let path = Path::new(s);
62-
if !path.is_relative() {
63-
return cond.raise((path, ~"absolute crate_id"));
64-
}
65-
if path.filename().is_none() {
66-
return cond.raise((path, ~"0-length crate_id"));
49+
let raw_crateid: Option<crateid::CrateId> = from_str(s);
50+
if raw_crateid.is_none() {
51+
return cond.raise((Path::new(s), ~"bad crateid"))
6752
}
68-
let short_name = path.filestem_str().expect(format!("Strange path! {}", s));
53+
let raw_crateid = raw_crateid.unwrap();
54+
let crateid::CrateId { path, name, version } = raw_crateid;
55+
let path = Path::new(path);
56+
let given_version = version.map(|v| ExactRevision(v));
6957

7058
let version = match given_version {
7159
Some(v) => v,
@@ -79,8 +67,8 @@ impl CrateId {
7967
};
8068

8169
CrateId {
82-
path: path.clone(),
83-
short_name: short_name.to_owned(),
70+
path: path,
71+
short_name: name,
8472
version: version
8573
}
8674
}

src/librustpkg/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,8 @@ fn test_crate_ids_must_be_relative_path_like() {
746746
CrateId::new("github.com/catamorphism/test-pkg").to_str());
747747
748748
cond.trap(|(p, e)| {
749-
assert!(p.filename().is_none())
750-
assert!("0-length crate_id" == e);
749+
assert!(p.filename().is_none());
750+
assert!("bad crateid" == e);
751751
whatever.clone()
752752
}).inside(|| {
753753
let x = CrateId::new("");
@@ -757,7 +757,7 @@ fn test_crate_ids_must_be_relative_path_like() {
757757
cond.trap(|(p, e)| {
758758
let abs = os::make_absolute(&Path::new("foo/bar/quux"));
759759
assert_eq!(p, abs);
760-
assert!("absolute crate_id" == e);
760+
assert!("bad crateid" == e);
761761
whatever.clone()
762762
}).inside(|| {
763763
let zp = os::make_absolute(&Path::new("foo/bar/quux"));

0 commit comments

Comments
 (0)