Skip to content

Commit 0f8c29f

Browse files
committed
auto merge of #11086 : metajack/rust/rustpkg-new-crateid-syntax, r=cmr
...arts. This fixes a bug where new syntax crate IDs would cause rustpkg to fail to build crates.
2 parents c58d2ba + 7fb712e commit 0f8c29f

File tree

2 files changed

+20
-45
lines changed

2 files changed

+20
-45
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: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use extra::getopts::groups::getopts;
2626
use std::run::ProcessOutput;
2727
use installed_packages::list_installed_packages;
2828
use crate_id::{CrateId};
29-
use version::{ExactRevision, NoVersion, Version, Tagged};
29+
use version::{ExactRevision, NoVersion, Version};
3030
use path_util::{target_executable_in_workspace, target_test_in_workspace,
3131
target_bench_in_workspace, make_dir_rwx,
3232
library_in_workspace, installed_library_in_workspace,
@@ -35,7 +35,6 @@ use path_util::{target_executable_in_workspace, target_test_in_workspace,
3535
chmod_read_only, platform_library_name};
3636
use rustc::back::link::get_cc_prog;
3737
use rustc::metadata::filesearch::{rust_path, libdir, rustlibdir};
38-
use rustc::driver::session;
3938
use rustc::driver::driver::{build_session, build_session_options, host_triple, optgroups};
4039
use syntax::diagnostic;
4140
use target::*;
@@ -76,14 +75,6 @@ fn git_repo_pkg() -> CrateId {
7675
}
7776
}
7877

79-
fn git_repo_pkg_with_tag(a_tag: ~str) -> CrateId {
80-
CrateId {
81-
path: Path::new("mockgithub.com/catamorphism/test-pkg"),
82-
short_name: ~"test-pkg",
83-
version: Tagged(a_tag)
84-
}
85-
}
86-
8778
fn writeFile(file_path: &Path, contents: &str) {
8879
let mut out = File::create(file_path);
8980
out.write(contents.as_bytes());
@@ -487,12 +478,6 @@ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path {
487478
&NoVersion).expect("lib_output_file_name")
488479
}
489480

490-
fn output_file_name(workspace: &Path, short_name: ~str) -> Path {
491-
target_build_dir(workspace).join(short_name.as_slice())
492-
.join(format!("{}{}", short_name,
493-
os::consts::EXE_SUFFIX))
494-
}
495-
496481
#[cfg(target_os = "linux")]
497482
fn touch_source_file(workspace: &Path, crateid: &CrateId) {
498483
use conditions::bad_path::cond;
@@ -746,8 +731,8 @@ fn test_crate_ids_must_be_relative_path_like() {
746731
CrateId::new("github.com/catamorphism/test-pkg").to_str());
747732
748733
cond.trap(|(p, e)| {
749-
assert!(p.filename().is_none())
750-
assert!("0-length crate_id" == e);
734+
assert!(p.filename().is_none());
735+
assert!("bad crateid" == e);
751736
whatever.clone()
752737
}).inside(|| {
753738
let x = CrateId::new("");
@@ -757,7 +742,7 @@ fn test_crate_ids_must_be_relative_path_like() {
757742
cond.trap(|(p, e)| {
758743
let abs = os::make_absolute(&Path::new("foo/bar/quux"));
759744
assert_eq!(p, abs);
760-
assert!("absolute crate_id" == e);
745+
assert!("bad crateid" == e);
761746
whatever.clone()
762747
}).inside(|| {
763748
let zp = os::make_absolute(&Path::new("foo/bar/quux"));
@@ -1894,9 +1879,11 @@ fn crateid_pointing_to_subdir() {
18941879
fs::mkdir_recursive(&foo_dir, io::UserRWX);
18951880
fs::mkdir_recursive(&bar_dir, io::UserRWX);
18961881
writeFile(&foo_dir.join("lib.rs"),
1897-
"#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/foo\"]; pub fn f() {}");
1882+
"#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/rust-foo#foo:0.0\"];" +
1883+
"pub fn f() {}");
18981884
writeFile(&bar_dir.join("lib.rs"),
1899-
"#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/bar\"]; pub fn g() {}");
1885+
"#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/rust-bar#bar:0.0\"];" +
1886+
"pub fn g() {}");
19001887

19011888
debug!("Creating a file in {}", workspace.display());
19021889
let testpkg_dir = workspace.join_many(["src", "testpkg-0.0"]);
@@ -2318,7 +2305,7 @@ fn find_sources_in_cwd() {
23182305
let source_dir = temp_dir.join("foo");
23192306
fs::mkdir_recursive(&source_dir, io::UserRWX);
23202307
writeFile(&source_dir.join("main.rs"),
2321-
r#"#[crate_id="foo"]; fn main() { let _x = (); }"#);
2308+
r#"#[crate_id="rust-foo#foo:0.0"]; fn main() { let _x = (); }"#);
23222309
command_line_test([~"install", ~"foo"], &source_dir);
23232310
assert_executable_exists(&source_dir.join(".rust"), "foo");
23242311
}

0 commit comments

Comments
 (0)