about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJack Moffitt <jack@metajack.im>2013-12-20 10:22:10 -0700
committerJack Moffitt <jack@metajack.im>2014-01-17 14:45:07 -0700
commit363fa51c66a5cffc5e29a59dcfafc4222b07189c (patch)
tree1b5f4400cdc82e4cb8e66ad48b003d9ad8864140
parent4098327b1fe1112ddf661b587be9eeec1d80adde (diff)
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.
-rw-r--r--src/librustpkg/crate_id.rs34
-rw-r--r--src/librustpkg/tests.rs6
2 files changed, 14 insertions, 26 deletions
diff --git a/src/librustpkg/crate_id.rs b/src/librustpkg/crate_id.rs
index 7ff8417f23c..9a3c47823e0 100644
--- a/src/librustpkg/crate_id.rs
+++ b/src/librustpkg/crate_id.rs
@@ -9,9 +9,10 @@
 // except according to those terms.
 
 use version::{try_getting_version, try_getting_local_version,
-              Version, NoVersion, split_version};
+              Version, NoVersion, ExactRevision};
 use std::hash::Streaming;
 use std::hash;
+use syntax::crateid;
 
 /// Path-fragment identifier of a package such as
 /// 'github.com/graydon/test'; path must be a relative
@@ -45,27 +46,14 @@ impl CrateId {
     pub fn new(s: &str) -> CrateId {
         use conditions::bad_pkg_id::cond;
 
-        let mut given_version = None;
-
-        // Did the user request a specific version?
-        let s = match split_version(s) {
-            Some((path, v)) => {
-                given_version = Some(v);
-                path
-            }
-            None => {
-                s
-            }
-        };
-
-        let path = Path::new(s);
-        if !path.is_relative() {
-            return cond.raise((path, ~"absolute crate_id"));
-        }
-        if path.filename().is_none() {
-            return cond.raise((path, ~"0-length crate_id"));
+        let raw_crateid: Option<crateid::CrateId> = from_str(s);
+        if raw_crateid.is_none() {
+            return cond.raise((Path::new(s), ~"bad crateid"))
         }
-        let short_name = path.filestem_str().expect(format!("Strange path! {}", s));
+        let raw_crateid = raw_crateid.unwrap();
+        let crateid::CrateId { path, name, version } = raw_crateid;
+        let path = Path::new(path);
+        let given_version = version.map(|v| ExactRevision(v));
 
         let version = match given_version {
             Some(v) => v,
@@ -79,8 +67,8 @@ impl CrateId {
         };
 
         CrateId {
-            path: path.clone(),
-            short_name: short_name.to_owned(),
+            path: path,
+            short_name: name,
             version: version
         }
     }
diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs
index 86b323609d3..8e3e6357181 100644
--- a/src/librustpkg/tests.rs
+++ b/src/librustpkg/tests.rs
@@ -746,8 +746,8 @@ fn test_crate_ids_must_be_relative_path_like() {
             CrateId::new("github.com/catamorphism/test-pkg").to_str());
 
     cond.trap(|(p, e)| {
-        assert!(p.filename().is_none())
-        assert!("0-length crate_id" == e);
+        assert!(p.filename().is_none());
+        assert!("bad crateid" == e);
         whatever.clone()
     }).inside(|| {
         let x = CrateId::new("");
@@ -757,7 +757,7 @@ fn test_crate_ids_must_be_relative_path_like() {
     cond.trap(|(p, e)| {
         let abs = os::make_absolute(&Path::new("foo/bar/quux"));
         assert_eq!(p, abs);
-        assert!("absolute crate_id" == e);
+        assert!("bad crateid" == e);
         whatever.clone()
     }).inside(|| {
         let zp = os::make_absolute(&Path::new("foo/bar/quux"));