From fa84593fc3098c4631be0887b772f0665b731a31 Mon Sep 17 00:00:00 2001 From: klutzy Date: Tue, 7 Jan 2014 14:39:13 +0900 Subject: [PATCH 1/4] rustpkg: Do not guess version if not given rustpkg accessed git repo to read tags and guess package version, but it's not quite useful: version can be given explicitly by user, and implicit guess may cause confusions. --- src/librustpkg/crate_id.rs | 17 ++----- src/librustpkg/tests.rs | 44 +----------------- src/librustpkg/version.rs | 95 +------------------------------------- 3 files changed, 7 insertions(+), 149 deletions(-) diff --git a/src/librustpkg/crate_id.rs b/src/librustpkg/crate_id.rs index 239abbe546ff0..bd9a75bad6975 100644 --- a/src/librustpkg/crate_id.rs +++ b/src/librustpkg/crate_id.rs @@ -8,8 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use version::{try_getting_version, try_getting_local_version, - Version, NoVersion, ExactRevision}; +use version::{Version, NoVersion, ExactRevision}; use std::hash::Streaming; use std::hash; use syntax::crateid; @@ -53,17 +52,9 @@ impl CrateId { 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, - None => match try_getting_local_version(&path) { - Some(v) => v, - None => match try_getting_version(&path) { - Some(v) => v, - None => NoVersion - } - } + let version = match version { + Some(v) => ExactRevision(v), + None => NoVersion, }; CrateId { diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index c0b4a246d35d7..f2efcadea7854 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -752,46 +752,6 @@ fn test_crate_ids_must_be_relative_path_like() { }) } -#[test] -fn test_package_version() { - let local_path = "mockgithub.com/catamorphism/test_pkg_version"; - let repo = init_git_repo(&Path::new(local_path)); - let repo = repo.path(); - let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]); - debug!("Writing files in: {}", repo_subdir.display()); - fs::mkdir_recursive(&repo_subdir, io::UserRWX); - writeFile(&repo_subdir.join("main.rs"), - "fn main() { let _x = (); }"); - writeFile(&repo_subdir.join("lib.rs"), - "pub fn f() { let _x = (); }"); - writeFile(&repo_subdir.join("test.rs"), - "#[test] pub fn f() { (); }"); - writeFile(&repo_subdir.join("bench.rs"), - "#[bench] pub fn f() { (); }"); - add_git_tag(&repo_subdir, ~"0.4"); - - // It won't pick up the 0.4 version because the dir isn't in the RUST_PATH, but... - let temp_pkg_id = CrateId::new("mockgithub.com/catamorphism/test_pkg_version"); - // This should look at the prefix, clone into a workspace, then build. - command_line_test([~"install", ~"mockgithub.com/catamorphism/test_pkg_version"], - repo); - let ws = repo.join(".rust"); - // we can still match on the filename to make sure it contains the 0.4 version - assert!(match built_library_in_workspace(&temp_pkg_id, - &ws) { - Some(p) => { - let suffix = format!("0.4{}", os::consts::DLL_SUFFIX); - p.as_vec().ends_with(suffix.as_bytes()) - } - None => false - }); - assert!(built_executable_in_workspace(&temp_pkg_id, &ws) - == Some(target_build_dir(&ws).join_many(["mockgithub.com", - "catamorphism", - "test_pkg_version", - "test_pkg_version"]))); -} - #[test] fn test_package_request_version() { let local_path = "mockgithub.com/catamorphism/test_pkg_version"; @@ -2183,9 +2143,9 @@ fn test_installed_read_only() { "fn main() { let _x = (); }"); writeFile(&repo_subdir.join("lib.rs"), "pub fn f() { let _x = (); }"); - add_git_tag(&repo_subdir, ~"0.1"); // this has the effect of committing the files + add_git_tag(&repo_subdir, ~"0.0"); // this has the effect of committing the files // update crateid to what will be auto-detected - temp_pkg_id.version = ExactRevision(~"0.1"); + temp_pkg_id.version = ExactRevision(~"0.0"); // FIXME (#9639): This needs to handle non-utf8 paths command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo); diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index 77dbb33551808..5da5b4fece974 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -14,9 +14,7 @@ extern mod std; use extra::semver; -use std::{char, result, run, str}; -use extra::tempfile::TempDir; -use path_util::rust_path; +use std::{char, result}; #[deriving(Clone)] pub enum Version { @@ -93,91 +91,6 @@ pub fn parse_vers(vers: ~str) -> result::Result { } } -/// If `local_path` is a git repo in the RUST_PATH, and the most recent tag -/// in that repo denotes a version, return it; otherwise, `None` -pub fn try_getting_local_version(local_path: &Path) -> Option { - let rustpath = rust_path(); - for rp in rustpath.iter() { - let local_path = rp.join(local_path); - let git_dir = local_path.join(".git"); - if !git_dir.is_dir() { - continue; - } - // FIXME (#9639): This needs to handle non-utf8 paths - let opt_outp = run::process_output("git", - ["--git-dir=" + git_dir.as_str().unwrap(), ~"tag", ~"-l"]); - let outp = opt_outp.expect("Failed to exec `git`"); - - debug!("git --git-dir={} tag -l ~~~> {:?}", git_dir.display(), outp.status); - - if !outp.status.success() { - continue; - } - - let mut output = None; - let output_text = str::from_utf8(outp.output).unwrap(); - for l in output_text.lines() { - if !l.is_whitespace() { - output = Some(l); - } - match output.and_then(try_parsing_version) { - Some(v) => return Some(v), - None => () - } - } - } - None -} - -/// If `remote_path` refers to a git repo that can be downloaded, -/// and the most recent tag in that repo denotes a version, return it; -/// otherwise, `None` -pub fn try_getting_version(remote_path: &Path) -> Option { - if is_url_like(remote_path) { - let tmp_dir = TempDir::new("test"); - let tmp_dir = tmp_dir.expect("try_getting_version: couldn't create temp dir"); - let tmp_dir = tmp_dir.path(); - debug!("(to get version) executing \\{git clone https://{} {}\\}", - remote_path.display(), - tmp_dir.display()); - // FIXME (#9639): This needs to handle non-utf8 paths - let opt_outp = run::process_output("git", [~"clone", format!("https://{}", - remote_path.as_str().unwrap()), - tmp_dir.as_str().unwrap().to_owned()]); - let outp = opt_outp.expect("Failed to exec `git`"); - if outp.status.success() { - debug!("Cloned it... ( {}, {} )", - str::from_utf8(outp.output).unwrap(), - str::from_utf8(outp.error).unwrap()); - let mut output = None; - let git_dir = tmp_dir.join(".git"); - debug!("(getting version, now getting tags) executing \\{git --git-dir={} tag -l\\}", - git_dir.display()); - // FIXME (#9639): This needs to handle non-utf8 paths - let opt_outp = run::process_output("git", - ["--git-dir=" + git_dir.as_str().unwrap(), - ~"tag", ~"-l"]); - let outp = opt_outp.expect("Failed to exec `git`"); - let output_text = str::from_utf8(outp.output).unwrap(); - debug!("Full output: ( {} ) [{:?}]", output_text, outp.status); - for l in output_text.lines() { - debug!("A line of output: {}", l); - if !l.is_whitespace() { - output = Some(l); - } - } - - output.and_then(try_parsing_version) - } - else { - None - } - } - else { - None - } -} - // Being lazy since we don't have a regexp library now #[deriving(Eq)] enum ParseState { @@ -207,12 +120,6 @@ pub fn try_parsing_version(s: &str) -> Option { } } -/// Just an approximation -fn is_url_like(p: &Path) -> bool { - // check if there are more than 2 /-separated components - p.as_vec().split(|b| *b == '/' as u8).nth(2).is_some() -} - /// If s is of the form foo#bar, where bar is a valid version /// number, return the prefix before the # and the version. /// Otherwise, return None. From 655433e3343ab6f91ef8db9a7ce19345eb0a6a9c Mon Sep 17 00:00:00 2001 From: klutzy Date: Wed, 8 Jan 2014 14:09:48 +0900 Subject: [PATCH 2/4] rustpkg::version: Remove enum Version Currently rustpkg doesn't use SemanticVersion or Tagged, so they are removed. Remaining variants are replaced by `Option<~str>`. --- src/librustpkg/api.rs | 11 +- src/librustpkg/crate_id.rs | 20 ++-- src/librustpkg/lib.rs | 4 +- src/librustpkg/package_source.rs | 6 +- src/librustpkg/path_util.rs | 23 ++-- src/librustpkg/source_control.rs | 11 +- src/librustpkg/tests.rs | 101 +++++++++--------- .../testsuite/pass/src/c-dependencies/pkg.rs | 4 +- .../testsuite/pass/src/fancy-lib/pkg.rs | 4 +- src/librustpkg/util.rs | 2 +- src/librustpkg/version.rs | 94 ++-------------- 11 files changed, 100 insertions(+), 180 deletions(-) diff --git a/src/librustpkg/api.rs b/src/librustpkg/api.rs index 19586ac48b078..27dfc3cae41c4 100644 --- a/src/librustpkg/api.rs +++ b/src/librustpkg/api.rs @@ -15,7 +15,6 @@ use crate_id::*; use package_source::*; use path_util::{platform_library_name, target_build_dir}; use target::*; -use version::Version; use workspace::pkg_parent_workspaces; use workcache_support::*; pub use path_util::default_workspace; @@ -79,13 +78,13 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context { workcache::Context::new_with_freshness(db, cfg, Arc::new(freshness)) } -pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version, +pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Option<~str>, lib: Path) { build_lib_with_cfgs(sysroot, root, name, version, lib, ~[]) } pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str, - version: Version, lib: Path, cfgs: ~[~str]) { + version: Option<~str>, lib: Path, cfgs: ~[~str]) { let cx = default_context(sysroot, root.clone()); let pkg_src = PkgSrc { source_workspace: root.clone(), @@ -102,13 +101,13 @@ pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str, pkg_src.build(&cx, cfgs, []); } -pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version, +pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Option<~str>, main: Path) { build_exe_with_cfgs(sysroot, root, name, version, main, ~[]) } pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str, - version: Version, main: Path, cfgs: ~[~str]) { + version: Option<~str>, main: Path, cfgs: ~[~str]) { let cx = default_context(sysroot, root.clone()); let pkg_src = PkgSrc { source_workspace: root.clone(), @@ -129,7 +128,7 @@ pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str, pub fn install_pkg(cx: &BuildContext, workspace: Path, name: ~str, - version: Version, + version: Option<~str>, // For now, these inputs are assumed to be inputs to each of the crates more_inputs: ~[(~str, Path)]) { // pairs of Kind and Path let crateid = CrateId{ version: version, ..CrateId::new(name)}; diff --git a/src/librustpkg/crate_id.rs b/src/librustpkg/crate_id.rs index bd9a75bad6975..9415e850e98ed 100644 --- a/src/librustpkg/crate_id.rs +++ b/src/librustpkg/crate_id.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use version::{Version, NoVersion, ExactRevision}; use std::hash::Streaming; use std::hash; use syntax::crateid; @@ -32,7 +31,7 @@ pub struct CrateId { /// of package IDs whose short names aren't valid Rust identifiers. short_name: ~str, /// The requested package version. - version: Version + version: Option<~str> } impl Eq for CrateId { @@ -42,6 +41,13 @@ impl Eq for CrateId { } impl CrateId { + pub fn get_version<'a>(&'a self) -> &'a str { + match self.version { + Some(ref ver) => ver.as_slice(), + None => "0.0" + } + } + pub fn new(s: &str) -> CrateId { use conditions::bad_pkg_id::cond; @@ -52,10 +58,6 @@ impl CrateId { let raw_crateid = raw_crateid.unwrap(); let crateid::CrateId { path, name, version } = raw_crateid; let path = Path::new(path); - let version = match version { - Some(v) => ExactRevision(v), - None => NoVersion, - }; CrateId { path: path, @@ -67,13 +69,13 @@ impl CrateId { pub fn hash(&self) -> ~str { // FIXME (#9639): hash should take a &[u8] so we can hash the real path self.path.display().with_str(|s| { - let vers = self.version.to_str(); + let vers = self.get_version(); format!("{}-{}-{}", s, hash(s + vers), vers) }) } pub fn short_name_with_version(&self) -> ~str { - format!("{}{}", self.short_name, self.version.to_str()) + format!("{}-{}", self.short_name, self.get_version()) } /// True if the ID has multiple components @@ -124,7 +126,7 @@ impl Iterator<(Path, Path)> for Prefixes { impl ToStr for CrateId { fn to_str(&self) -> ~str { // should probably use the filestem and not the whole path - format!("{}-{}", self.path.as_str().unwrap(), self.version.to_str()) + format!("{}-{}", self.path.as_str().unwrap(), self.get_version()) } } diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index c9db8af0b8a9c..22871179a6e3b 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -163,7 +163,6 @@ impl<'a> PkgScript<'a> { exe.as_str().unwrap().to_owned() } - /// Run the contents of this package script, where /// is the command to pass to it (e.g., "build", "clean", "install") /// Returns a pair of an exit code and list of configs (obtained by @@ -243,7 +242,7 @@ impl CtxMethods for BuildContext { if args.len() < 1 { match cwd_to_workspace() { - None if dir_has_crate_file(&cwd) => { + None if dir_has_crate_file(&cwd) => { // FIXME (#9639): This needs to handle non-utf8 paths let crateid = CrateId::new(cwd.filename_str().unwrap()); let mut pkg_src = PkgSrc::new(cwd, default_workspace(), true, crateid); @@ -289,6 +288,7 @@ impl CtxMethods for BuildContext { Some((crateid, dest_ws)) } } + fn run(&self, cmd: Command, args: ~[~str]) { let cwd = os::getcwd(); match cmd { diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 651d64aa9d32f..fce2f9e4d0c6b 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -100,7 +100,7 @@ impl PkgSrc { // automatically-checked-out sources go. let mut result = source_workspace.join("src"); result.push(&id.path.dir_path()); - result.push(format!("{}-{}", id.short_name, id.version.to_str())); + result.push(id.short_name_with_version()); to_try.push(result); let mut result = source_workspace.join("src"); result.push(&id.path); @@ -108,7 +108,7 @@ impl PkgSrc { let mut result = build_dir.join("src"); result.push(&id.path.dir_path()); - result.push(format!("{}-{}", id.short_name, id.version.to_str())); + result.push(id.short_name_with_version()); to_try.push(result.clone()); output_names.push(result); let mut other_result = build_dir.join("src"); @@ -287,7 +287,7 @@ impl PkgSrc { // FIXME (#9639): This needs to handle non-utf8 paths let url = format!("https://{}", crateid.path.as_str().unwrap()); debug!("Fetching package: git clone {} {} [version={}]", - url, clone_target.display(), crateid.version.to_str()); + url, clone_target.display(), crateid.get_version()); let mut failed = false; diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index 3c91e6607849a..d8dee82d09e8a 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -14,7 +14,7 @@ pub use crate_id::CrateId; pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install}; -pub use version::{Version, ExactRevision, NoVersion, split_version, split_version_general, +pub use version::{Version, split_version, split_version_general, try_parsing_version}; pub use rustc::metadata::filesearch::rust_path; use rustc::metadata::filesearch::{libdir, relative_target_lib_path}; @@ -85,7 +85,7 @@ pub fn workspace_contains_crate_id_(crateid: &CrateId, workspace: &Path, None => false, Some((ref might_match, ref vers)) => { *might_match == crateid.short_name - && (crateid.version == *vers || crateid.version == NoVersion) + && (crateid.version == *vers || crateid.version == None) } } }) @@ -188,7 +188,7 @@ pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Opti Install, workspace, libdir(), - &NoVersion) + &None) } } @@ -261,7 +261,8 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti Some(i) => { debug!("Maybe {} is a version", f_name.slice(i + 1, f_name.len())); match try_parsing_version(f_name.slice(i + 1, f_name.len())) { - Some(ref found_vers) if version == found_vers => { + Some(ref found_vers) if version == &Some(found_vers.to_owned()) || + version == &None => { match f_name.slice(0, i).rfind('-') { Some(j) => { let lib_prefix = match p_path.extension_str() { @@ -276,7 +277,6 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti } None => break } - } _ => { f_name = f_name.slice(0, i); } } @@ -306,13 +306,13 @@ fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) { match split_version(crate_id) { Some((name, vers)) => match vers { - ExactRevision(ref v) => match v.find('-') { - Some(pos) => (name, ExactRevision(v.slice(0, pos).to_owned())), - None => (name, ExactRevision(v.to_owned())) + Some(ref v) => match v.find('-') { + Some(pos) => (name, Some(v.slice(0, pos).to_owned())), + None => (name, Some(v.to_owned())) }, _ => (name, vers) }, - None => (crate_id, NoVersion) + None => (crate_id, None) } } @@ -393,8 +393,7 @@ pub fn build_pkg_id_in_workspace(crateid: &CrateId, workspace: &Path) -> Path { /// given whether we're building a library and whether we're building tests pub fn mk_output_path(what: OutputType, where: Target, pkg_id: &CrateId, workspace: Path) -> Path { - let short_name_with_version = format!("{}-{}", pkg_id.short_name, - pkg_id.version.to_str()); + let short_name_with_version = pkg_id.short_name_with_version(); // Not local_path.dir_path()! For package foo/bar/blat/, we want // the executable blat-0.5 to live under blat/ let dir = match where { @@ -487,7 +486,7 @@ pub fn versionize(p: &Path, v: &Version) -> Path { let q = p.filename().expect("path is a directory"); let mut q = q.to_owned(); q.push('-' as u8); - let vs = v.to_str(); + let vs = match v { &Some(ref s) => s.to_owned(), &None => ~"0.0" }; q.push_all(vs.as_bytes()); p.with_filename(q) } diff --git a/src/librustpkg/source_control.rs b/src/librustpkg/source_control.rs index 4b7aaf7e340d9..2346749feb53a 100644 --- a/src/librustpkg/source_control.rs +++ b/src/librustpkg/source_control.rs @@ -14,7 +14,6 @@ use std::{run, str}; use std::run::{ProcessOutput, ProcessOptions, Process}; use std::io::fs; use extra::tempfile::TempDir; -use version::*; use path_util::chmod_read_only; /// Attempts to clone `source`, a local git repository, into `target`, a local @@ -22,7 +21,7 @@ use path_util::chmod_read_only; /// Returns `DirToUse(p)` if the clone fails, where `p` is a newly created temporary /// directory (that the callee may use, for example, to check out remote sources into). /// Returns `CheckedOutSources` if the clone succeeded. -pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult { +pub fn safe_git_clone(source: &Path, v: &Option<~str>, target: &Path) -> CloneResult { if source.exists() { debug!("{} exists locally! Cloning it into {}", source.display(), target.display()); @@ -44,7 +43,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult } else { match v { - &ExactRevision(ref s) => { + &Some(ref s) => { let git_dir = target.join(".git"); debug!("`Running: git --work-tree={} --git-dir={} checkout {}", *s, target.display(), git_dir.display()); @@ -65,7 +64,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult } else { // Check that no version was specified. There's no reason to not handle the // case where a version was requested, but I haven't implemented it. - assert!(*v == NoVersion); + assert!(*v == None); let git_dir = target.join(".git"); debug!("Running: git --work-tree={} --git-dir={} pull --no-edit {}", target.display(), git_dir.display(), source.display()); @@ -106,7 +105,7 @@ pub fn make_read_only(target: &Path) { } /// Source can be either a URL or a local file path. -pub fn git_clone_url(source: &str, target: &Path, v: &Version) { +pub fn git_clone_url(source: &str, target: &Path, v: &Option<~str>) { use conditions::git_checkout_failed::cond; // FIXME (#9639): This needs to handle non-utf8 paths @@ -120,7 +119,7 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) { } else { match v { - &ExactRevision(ref s) | &Tagged(ref s) => { + &Some(ref s) => { let opt_outp = process_output_in_cwd("git", [~"checkout", s.to_owned()], target); let outp = opt_outp.expect("Failed to exec `git`"); diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index f2efcadea7854..be5b6859c74e4 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -25,8 +25,7 @@ use extra::treemap::TreeMap; use extra::getopts::groups::getopts; use std::run::ProcessOutput; use installed_packages::list_installed_packages; -use crate_id::{CrateId}; -use version::{ExactRevision, NoVersion, Version}; +use crate_id::CrateId; use path_util::{target_executable_in_workspace, target_test_in_workspace, target_bench_in_workspace, make_dir_rwx, library_in_workspace, installed_library_in_workspace, @@ -63,7 +62,7 @@ fn fake_pkg() -> CrateId { CrateId { path: Path::new(sn.as_slice()), short_name: sn, - version: NoVersion + version: None } } @@ -71,7 +70,7 @@ fn git_repo_pkg() -> CrateId { CrateId { path: Path::new("mockgithub.com/catamorphism/test-pkg"), short_name: ~"test-pkg", - version: NoVersion + version: None } } @@ -88,28 +87,24 @@ fn mk_emptier_workspace(tag: &str) -> TempDir { workspace } -fn mk_empty_workspace(short_name: &Path, version: &Version, tag: &str) -> TempDir { +fn mk_empty_workspace(crate_id: &CrateId, tag: &str) -> TempDir { let workspace_dir = TempDir::new(tag).expect("couldn't create temp dir"); - mk_workspace(workspace_dir.path(), short_name, version); + mk_workspace(workspace_dir.path(), crate_id); workspace_dir } -fn mk_workspace(workspace: &Path, short_name: &Path, version: &Version) -> Path { +fn mk_workspace(workspace: &Path, crate_id: &CrateId) -> Path { // include version number in directory name // FIXME (#9639): This needs to handle non-utf8 paths - let package_dir = workspace.join_many([~"src", format!("{}-{}", - short_name.as_str().unwrap(), version.to_str())]); + let package_dir = workspace.join_many([~"src", crate_id.short_name_with_version()]); fs::mkdir_recursive(&package_dir, io::UserRWX); package_dir } -fn mk_temp_workspace(short_name: &Path, version: &Version) -> (TempDir, Path) { - let workspace_dir = mk_empty_workspace(short_name, version, "temp_workspace"); +fn mk_temp_workspace(crate_id: &CrateId) -> (TempDir, Path) { + let workspace_dir = mk_empty_workspace(crate_id, "temp_workspace"); // FIXME (#9639): This needs to handle non-utf8 paths - let package_dir = workspace_dir.path().join_many([~"src", - format!("{}-{}", - short_name.as_str().unwrap(), - version.to_str())]); + let package_dir = workspace_dir.path().join_many([~"src", crate_id.short_name_with_version()]); debug!("Created {} and does it exist? {:?}", package_dir.display(), package_dir.is_dir()); @@ -294,7 +289,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s } fn create_local_package(crateid: &CrateId) -> TempDir { - let (workspace, parent_dir) = mk_temp_workspace(&crateid.path, &crateid.version); + let (workspace, parent_dir) = mk_temp_workspace(crateid); debug!("Created empty package dir for {}, returning {}", crateid.to_str(), parent_dir.display()); workspace @@ -348,11 +343,11 @@ fn create_local_package_with_custom_build_hook(crateid: &CrateId, } -fn assert_lib_exists(repo: &Path, pkg_path: &Path, v: Version) { +fn assert_lib_exists(repo: &Path, pkg_path: &Path, v: Option<~str>) { assert!(lib_exists(repo, pkg_path, v)); } -fn lib_exists(repo: &Path, pkg_path: &Path, _v: Version) -> bool { // ??? version? +fn lib_exists(repo: &Path, pkg_path: &Path, _v: Option<~str>) -> bool { // ??? version? debug!("assert_lib_exists: repo = {}, pkg_path = {}", repo.display(), pkg_path.display()); let lib = installed_library_in_workspace(pkg_path, repo); debug!("assert_lib_exists: checking whether {:?} exists", lib); @@ -475,7 +470,7 @@ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path { Build, workspace, "build", - &NoVersion).expect("lib_output_file_name") + &None).expect("lib_output_file_name") } #[cfg(target_os = "linux")] @@ -567,7 +562,7 @@ fn test_install_valid() { let sysroot = test_sysroot(); debug!("sysroot = {}", sysroot.display()); let temp_pkg_id = fake_pkg(); - let (temp_workspace, _pkg_dir) = mk_temp_workspace(&temp_pkg_id.path, &NoVersion); + let (temp_workspace, _pkg_dir) = mk_temp_workspace(&temp_pkg_id); let temp_workspace = temp_workspace.path(); let ctxt = fake_ctxt(sysroot, temp_workspace); debug!("temp_workspace = {}", temp_workspace.display()); @@ -624,8 +619,7 @@ fn test_install_invalid() { #[test] fn test_install_valid_external() { let temp_pkg_id = CrateId::new("foo"); - let (tempdir, _) = mk_temp_workspace(&temp_pkg_id.path, - &temp_pkg_id.version); + let (tempdir, _) = mk_temp_workspace(&temp_pkg_id); let temp_workspace = tempdir.path(); command_line_test([~"install", ~"foo"], temp_workspace); @@ -821,7 +815,7 @@ fn rustpkg_library_target() { add_git_tag(&package_dir, ~"1.0"); command_line_test([~"install", ~"foo"], foo_repo); - assert_lib_exists(&foo_repo.join(".rust"), &Path::new("foo"), ExactRevision(~"1.0")); + assert_lib_exists(&foo_repo.join(".rust"), &Path::new("foo"), Some(~"1.0")); } #[test] @@ -844,7 +838,7 @@ fn package_script_with_default_build() { debug!("package_script_with_default_build: {}", source.display()); fs::copy(&source, &dir.join_many(["src", "fancy-lib-0.0", "pkg.rs"])); command_line_test([~"install", ~"fancy-lib"], dir); - assert_lib_exists(dir, &Path::new("fancy-lib"), NoVersion); + assert_lib_exists(dir, &Path::new("fancy-lib"), None); assert!(target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]).exists()); let generated_path = target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]); debug!("generated path = {}", generated_path.display()); @@ -875,7 +869,7 @@ fn rustpkg_install_no_arg() { "fn main() { let _x = (); }"); debug!("install_no_arg: dir = {}", package_dir.display()); command_line_test([~"install"], &package_dir); - assert_lib_exists(&tmp, &Path::new("foo"), NoVersion); + assert_lib_exists(&tmp, &Path::new("foo"), None); } #[test] @@ -898,7 +892,7 @@ fn rustpkg_clean_no_arg() { #[test] fn rust_path_test() { let dir_for_path = TempDir::new("more_rust").expect("rust_path_test failed"); - let dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion); + let dir = mk_workspace(dir_for_path.path(), &CrateId::new("foo")); debug!("dir = {}", dir.display()); writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }"); @@ -1322,8 +1316,9 @@ fn multiple_workspaces() { // Copy the exact same package into directory B and install it // Set the RUST_PATH to A:B // Make a third package that uses foo, make sure we can build/install it - let (a_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion); - let (b_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion); + let p_id = CrateId::new("foo"); + let (a_loc, _pkg_dir) = mk_temp_workspace(&p_id); + let (b_loc, _pkg_dir) = mk_temp_workspace(&p_id); let (a_loc, b_loc) = (a_loc.path(), b_loc.path()); debug!("Trying to install foo in {}", a_loc.display()); command_line_test([~"install", ~"foo"], a_loc); @@ -1348,7 +1343,7 @@ fn rust_path_hack_test(hack_flag: bool) { let p_id = CrateId::new("foo"); let workspace = create_local_package(&p_id); let workspace = workspace.path(); - let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); let dest_workspace = dest_workspace.path(); let foo_path = workspace.join_many(["src", "foo-0.0"]); let rust_path = Some(~[(~"RUST_PATH", @@ -1357,11 +1352,11 @@ fn rust_path_hack_test(hack_flag: bool) { foo_path.as_str().unwrap()))]); command_line_test_with_env(~[~"install"] + if hack_flag { ~[~"--rust-path-hack"] } else { ~[] } + ~[~"foo"], dest_workspace, rust_path); - assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("foo"), None); assert_executable_exists(dest_workspace, "foo"); assert_built_library_exists(dest_workspace, "foo"); assert_built_executable_exists(dest_workspace, "foo"); - assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion)); + assert!(!lib_exists(workspace, &Path::new("foo"), None)); assert!(!executable_exists(workspace, "foo")); assert!(!built_library_exists(workspace, "foo")); assert!(!built_executable_exists(workspace, "foo")); @@ -1396,15 +1391,15 @@ fn rust_path_hack_cwd() { fs::mkdir_recursive(&cwd, io::UserRWX); writeFile(&cwd.join("lib.rs"), "pub fn f() { }"); - let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack", ~"foo"], &cwd, rust_path); debug!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("foo"), None); assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&cwd, &Path::new("foo"), NoVersion)); + assert!(!lib_exists(&cwd, &Path::new("foo"), None)); assert!(!built_library_exists(&cwd, "foo")); } @@ -1417,15 +1412,15 @@ fn rust_path_hack_multi_path() { writeFile(&subdir.join("lib.rs"), "pub fn f() { }"); let name = ~"foo/bar/quux"; - let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack", name.clone()], &subdir, rust_path); debug!("Checking that {} exists in {}", name, dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::new("quux"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("quux"), None); assert_built_library_exists(dest_workspace, name); - assert!(!lib_exists(&subdir, &Path::new("quux"), NoVersion)); + assert!(!lib_exists(&subdir, &Path::new("quux"), None)); assert!(!built_library_exists(&subdir, name)); } @@ -1438,15 +1433,15 @@ fn rust_path_hack_install_no_arg() { assert!(make_dir_rwx(&source_dir)); writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); - let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack"], &source_dir, rust_path); debug!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion); + assert_lib_exists(dest_workspace, &Path::new("foo"), None); assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&source_dir, &Path::new("foo"), NoVersion)); + assert!(!lib_exists(&source_dir, &Path::new("foo"), None)); assert!(!built_library_exists(cwd, "foo")); } @@ -1458,7 +1453,7 @@ fn rust_path_hack_build_no_arg() { assert!(make_dir_rwx(&source_dir)); writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); - let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); @@ -1496,7 +1491,7 @@ fn rust_path_hack_build_with_dependency() { fn rust_path_install_target() { let dir_for_path = TempDir::new( "source_workspace").expect("rust_path_install_target failed"); - let mut dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion); + let mut dir = mk_workspace(dir_for_path.path(), &CrateId::new("foo")); debug!("dir = {}", dir.display()); writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }"); let dir_to_install_to = TempDir::new( @@ -1608,7 +1603,7 @@ fn notrans_flag_fail() { workspace, None, BAD_FLAG_CODE); assert!(!built_executable_exists(workspace, "foo")); assert!(!object_file_exists(workspace, "foo")); - assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion)); + assert!(!lib_exists(workspace, &Path::new("foo"), None)); } } @@ -1880,9 +1875,9 @@ fn test_recursive_deps() { command_line_test_with_env([~"install", ~"a"], a_workspace, environment); - assert_lib_exists(a_workspace, &Path::new("a"), NoVersion); - assert_lib_exists(b_workspace, &Path::new("b"), NoVersion); - assert_lib_exists(b_workspace, &Path::new("c"), NoVersion); + assert_lib_exists(a_workspace, &Path::new("a"), None); + assert_lib_exists(b_workspace, &Path::new("b"), None); + assert_lib_exists(b_workspace, &Path::new("c"), None); } #[test] @@ -1890,7 +1885,7 @@ fn test_install_to_rust_path() { let p_id = CrateId::new("foo"); let second_workspace = create_local_package(&p_id); let second_workspace = second_workspace.path(); - let first_workspace = mk_empty_workspace(&Path::new("p"), &NoVersion, "dest"); + let first_workspace = mk_empty_workspace(&CrateId::new("p"), "dest"); let first_workspace = first_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", @@ -1937,7 +1932,7 @@ fn test_target_specific_install_dir() { ~"foo"], workspace); assert!(workspace.join_many([~"lib", host_triple()]).is_dir()); - assert_lib_exists(workspace, &Path::new("foo"), NoVersion); + assert_lib_exists(workspace, &Path::new("foo"), None); assert!(fs::readdir(&workspace.join("lib")).len() == 1); assert!(workspace.join("bin").is_dir()); assert_executable_exists(workspace, "foo"); @@ -1965,7 +1960,7 @@ fn install_after_build() { command_line_test([~"build", ~"b"], workspace); command_line_test([~"install", ~"b"], workspace); assert_executable_exists(workspace, b_id.short_name); - assert_lib_exists(workspace, &b_id.path, NoVersion); + assert_lib_exists(workspace, &b_id.path, None); } #[test] @@ -1977,7 +1972,7 @@ fn reinstall() { // and make sure executable was re-installed command_line_test([~"install", ~"b"], workspace); assert_executable_exists(workspace, b.short_name); - assert_lib_exists(workspace, &b.path, NoVersion); + assert_lib_exists(workspace, &b.path, None); remove_executable_file(&b, workspace); command_line_test([~"install", ~"b"], workspace); assert_executable_exists(workspace, b.short_name); @@ -2013,7 +2008,7 @@ fn correct_package_name_with_rust_path_hack() { let bar_id = CrateId::new("bar"); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); - let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace"); + let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); let dest_workspace = dest_workspace.path(); writeFile(&dest_workspace.join_many(["src", "bar-0.0", "main.rs"]), @@ -2145,7 +2140,7 @@ fn test_installed_read_only() { "pub fn f() { let _x = (); }"); add_git_tag(&repo_subdir, ~"0.0"); // this has the effect of committing the files // update crateid to what will be auto-detected - temp_pkg_id.version = ExactRevision(~"0.0"); + temp_pkg_id.version = Some(~"0.0"); // FIXME (#9639): This needs to handle non-utf8 paths command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo); @@ -2202,7 +2197,7 @@ fn test_installed_local_changes() { "test-pkg-0.0"]); debug!("---- git clone {} {}", repo_subdir.display(), target_dir.display()); - let c_res = safe_git_clone(&repo_subdir, &NoVersion, &target_dir); + let c_res = safe_git_clone(&repo_subdir, &None, &target_dir); match c_res { DirToUse(_) => fail!("test_installed_local_changes failed"), diff --git a/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs b/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs index b6c5e15c09a5f..b6dba40ebd46a 100644 --- a/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs +++ b/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs @@ -13,7 +13,7 @@ extern mod rustc; use std::{os, task}; use rustpkg::api; -use rustpkg::version::NoVersion; +use rustpkg::version::None; use rustpkg::workcache_support::digest_file_with_date; use rustpkg::exit_codes::COPY_FAILED_CODE; @@ -73,7 +73,7 @@ pub fn main() { api::install_pkg(&mut cc, os::getcwd(), ~"cdep", - NoVersion, + None, ~[(~"binary", out_lib_path.clone()), (~"file", foo_c_name.clone())]); }; diff --git a/src/librustpkg/testsuite/pass/src/fancy-lib/pkg.rs b/src/librustpkg/testsuite/pass/src/fancy-lib/pkg.rs index 4a107de55a59f..7b1291025e40b 100644 --- a/src/librustpkg/testsuite/pass/src/fancy-lib/pkg.rs +++ b/src/librustpkg/testsuite/pass/src/fancy-lib/pkg.rs @@ -14,7 +14,7 @@ extern mod rustc; use std::os; use std::io::File; use rustpkg::api; -use rustpkg::version::NoVersion; +use rustpkg::version::None; pub fn main() { let args = os::args(); @@ -48,5 +48,5 @@ pub fn main() { for _ in xs.iter() { assert!(true); } }".as_bytes()); let context = api::default_context(sysroot, api::default_workspace()); - api::install_pkg(&context, os::getcwd(), ~"fancy-lib", NoVersion, ~[]); + api::install_pkg(&context, os::getcwd(), ~"fancy-lib", None, ~[]); } diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 4d8f5c668b74f..18e773d5f15a8 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -315,7 +315,7 @@ pub fn compile_input(context: &BuildContext, attr::mk_name_value_item_str(@"crate_id", format!("{}\\#{}", pkg_id.path.as_str().unwrap(), - pkg_id.version.to_str()).to_managed()); + pkg_id.get_version()).to_managed()); debug!("crateid attr: {:?}", crateid_attr); crate.attrs.push(attr::mk_attr(crateid_attr)); diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index 5da5b4fece974..93e7a052efa06 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -13,83 +13,9 @@ extern mod std; -use extra::semver; -use std::{char, result}; +use std::char; -#[deriving(Clone)] -pub enum Version { - ExactRevision(~str), // Should look like a m.n.(...).x - SemanticVersion(semver::Version), - Tagged(~str), // String that can't be parsed as a version. - // Requirements get interpreted exactly - NoVersion // user didn't specify a version -- prints as 0.0 -} - -// Equality on versions is non-symmetric: if self is NoVersion, it's equal to -// anything; but if self is a precise version, it's not equal to NoVersion. -// We should probably make equality symmetric, and use less-than and greater-than -// where we currently use eq -impl Eq for Version { - fn eq(&self, other: &Version) -> bool { - match (self, other) { - (&ExactRevision(ref s1), &ExactRevision(ref s2)) => *s1 == *s2, - (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => *v1 == *v2, - (&NoVersion, _) => true, - _ => false - } - } -} - -impl Ord for Version { - fn lt(&self, other: &Version) -> bool { - match (self, other) { - (&NoVersion, _) => true, - (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 < f2, - (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 < v2, - _ => false // incomparable, really - } - } - fn le(&self, other: &Version) -> bool { - match (self, other) { - (&NoVersion, _) => true, - (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 <= f2, - (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 <= v2, - _ => false // incomparable, really - } - } - fn ge(&self, other: &Version) -> bool { - match (self, other) { - (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 > f2, - (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 > v2, - _ => false // incomparable, really - } - } - fn gt(&self, other: &Version) -> bool { - match (self, other) { - (&ExactRevision(ref f1), &ExactRevision(ref f2)) => f1 >= f2, - (&SemanticVersion(ref v1), &SemanticVersion(ref v2)) => v1 >= v2, - _ => false // incomparable, really - } - } - -} - -impl ToStr for Version { - fn to_str(&self) -> ~str { - match *self { - ExactRevision(ref n) | Tagged(ref n) => format!("{}", n.to_str()), - SemanticVersion(ref v) => format!("{}", v.to_str()), - NoVersion => ~"0.0" - } - } -} - -pub fn parse_vers(vers: ~str) -> result::Result { - match semver::parse(vers) { - Some(vers) => result::Ok(vers), - None => result::Err(~"could not parse version: invalid") - } -} +pub type Version = Option<~str>; // Being lazy since we don't have a regexp library now #[deriving(Eq)] @@ -99,7 +25,7 @@ enum ParseState { SawDot } -pub fn try_parsing_version(s: &str) -> Option { +pub fn try_parsing_version(s: &str) -> Option<~str> { let s = s.trim(); debug!("Attempting to parse: {}", s); let mut parse_state = Start; @@ -115,7 +41,7 @@ pub fn try_parsing_version(s: &str) -> Option { } } match parse_state { - SawDigit => Some(ExactRevision(s.to_owned())), + SawDigit => Some(s.to_owned()), _ => None } } @@ -136,7 +62,7 @@ pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, Vers Some(i) => { let path = s.slice(0, i); // n.b. for now, assuming an exact revision is intended, not a SemVer - Some((path, ExactRevision(s.slice(i + 1, s.len()).to_owned()))) + Some((path, Some(s.slice(i + 1, s.len()).to_owned()))) } None => { None @@ -146,11 +72,11 @@ pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, Vers #[test] fn test_parse_version() { - assert!(try_parsing_version("1.2") == Some(ExactRevision(~"1.2"))); - assert!(try_parsing_version("1.0.17") == Some(ExactRevision(~"1.0.17"))); + assert!(try_parsing_version("1.2") == Some(~"1.2")); + assert!(try_parsing_version("1.0.17") == Some(~"1.0.17")); assert!(try_parsing_version("you're_a_kitty") == None); assert!(try_parsing_version("42..1") == None); - assert!(try_parsing_version("17") == Some(ExactRevision(~"17"))); + assert!(try_parsing_version("17") == Some(~"17")); assert!(try_parsing_version(".1.2.3") == None); assert!(try_parsing_version("2.3.") == None); } @@ -159,9 +85,9 @@ fn test_parse_version() { fn test_split_version() { let s = "a/b/c#0.1"; debug!("== {:?} ==", split_version(s)); - assert!(split_version(s) == Some((s.slice(0, 5), ExactRevision(~"0.1")))); + assert!(split_version(s) == Some((s.slice(0, 5), Some(~"0.1")))); assert!(split_version("a/b/c") == None); let s = "a#1.2"; - assert!(split_version(s) == Some((s.slice(0, 1), ExactRevision(~"1.2")))); + assert!(split_version(s) == Some((s.slice(0, 1), Some(~"1.2")))); assert!(split_version("a#a#3.4") == None); } From df9067cd1597ba31b640a7ae6457aa04920f2631 Mon Sep 17 00:00:00 2001 From: klutzy Date: Fri, 10 Jan 2014 13:12:59 +0900 Subject: [PATCH 3/4] rustpkg: Compute hash to find crate Previously rustpkg tried to parse filenames to find crate. Now ue use deterministic hashes, so it becomes possible to directly construct filename and check if the file exists. --- src/librustpkg/crate_id.rs | 35 +++---- src/librustpkg/package_source.rs | 2 +- src/librustpkg/path_util.rs | 155 ++++++------------------------- src/librustpkg/tests.rs | 77 ++++++++------- src/librustpkg/util.rs | 29 +++--- 5 files changed, 99 insertions(+), 199 deletions(-) diff --git a/src/librustpkg/crate_id.rs b/src/librustpkg/crate_id.rs index 9415e850e98ed..4a87bcb70f50a 100644 --- a/src/librustpkg/crate_id.rs +++ b/src/librustpkg/crate_id.rs @@ -9,8 +9,9 @@ // except according to those terms. use std::hash::Streaming; -use std::hash; use syntax::crateid; +use extra::hex::ToHex; +use rustc::util::sha2::{Digest, Sha256}; /// Path-fragment identifier of a package such as /// 'github.com/graydon/test'; path must be a relative @@ -41,7 +42,7 @@ impl Eq for CrateId { } impl CrateId { - pub fn get_version<'a>(&'a self) -> &'a str { + pub fn version_or_default<'a>(&'a self) -> &'a str { match self.version { Some(ref ver) => ver.as_slice(), None => "0.0" @@ -66,16 +67,24 @@ impl CrateId { } } + pub fn to_crate_id_str(&self) -> ~str { + format!("{}\\#{}", self.path.as_str().unwrap(), self.version_or_default()) + } + + pub fn to_lib_name(&self) -> ~str { + format!("{}-{}-{}", self.short_name, self.hash(), self.version_or_default()) + } + pub fn hash(&self) -> ~str { - // FIXME (#9639): hash should take a &[u8] so we can hash the real path - self.path.display().with_str(|s| { - let vers = self.get_version(); - format!("{}-{}-{}", s, hash(s + vers), vers) - }) + let mut hasher = Sha256::new(); + hasher.reset(); + hasher.input_str(self.to_crate_id_str()); + let hash = hasher.result_bytes().to_hex(); + hash.slice_chars(0, 8).to_owned() } pub fn short_name_with_version(&self) -> ~str { - format!("{}-{}", self.short_name, self.get_version()) + format!("{}-{}", self.short_name, self.version_or_default()) } /// True if the ID has multiple components @@ -126,18 +135,10 @@ impl Iterator<(Path, Path)> for Prefixes { impl ToStr for CrateId { fn to_str(&self) -> ~str { // should probably use the filestem and not the whole path - format!("{}-{}", self.path.as_str().unwrap(), self.get_version()) + format!("{}-{}", self.path.as_str().unwrap(), self.version_or_default()) } } - pub fn write(writer: &mut W, string: &str) { writer.write(string.as_bytes()); } - -pub fn hash(data: ~str) -> ~str { - let hasher = &mut hash::default_state(); - write(hasher, data); - hasher.result_str() -} - diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index fce2f9e4d0c6b..2bc1966bff0e4 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -287,7 +287,7 @@ impl PkgSrc { // FIXME (#9639): This needs to handle non-utf8 paths let url = format!("https://{}", crateid.path.as_str().unwrap()); debug!("Fetching package: git clone {} {} [version={}]", - url, clone_target.display(), crateid.get_version()); + url, clone_target.display(), crateid.version_or_default()); let mut failed = false; diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index d8dee82d09e8a..1412b99d285f1 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -14,17 +14,16 @@ pub use crate_id::CrateId; pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install}; -pub use version::{Version, split_version, split_version_general, - try_parsing_version}; +pub use version::{Version, split_version, split_version_general, try_parsing_version}; pub use rustc::metadata::filesearch::rust_path; -use rustc::metadata::filesearch::{libdir, relative_target_lib_path}; -use rustc::driver::driver::host_triple; use std::libc; use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; use std::os; use std::io; use std::io::fs; +use rustc::metadata::filesearch::{libdir, relative_target_lib_path}; +use rustc::driver::driver::host_triple; use messages::*; pub fn default_workspace() -> Path { @@ -173,151 +172,57 @@ fn output_in_workspace(crateid: &CrateId, workspace: &Path, what: OutputType) -> /// Figure out what the library name for in 's build /// directory is, and if the file exists, return it. pub fn built_library_in_workspace(crateid: &CrateId, workspace: &Path) -> Option { - library_in_workspace(&crateid.path, crateid.short_name, Build, workspace, "build", - &crateid.version) + library_in_workspace(crateid, Build, workspace) } /// Does the actual searching stuff -pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Option { +pub fn installed_library_in_workspace(crate_id: &CrateId, workspace: &Path) -> Option { // This could break once we're handling multiple versions better -- I should add a test for it // FIXME (#9639): This needs to handle non-utf8 paths - match pkg_path.filename_str() { + match crate_id.path.filename_str() { None => None, - Some(short_name) => library_in_workspace(pkg_path, - short_name, - Install, - workspace, - libdir(), - &None) + Some(_short_name) => library_in_workspace(crate_id, Install, workspace) } } /// `workspace` is used to figure out the directory to search. /// `short_name` is taken as the link name of the library. -pub fn library_in_workspace(path: &Path, short_name: &str, where: Target, - workspace: &Path, prefix: &str, version: &Version) -> Option { +pub fn library_in_workspace(crate_id: &CrateId, where: Target, workspace: &Path) -> Option { debug!("library_in_workspace: checking whether a library named {} exists", - short_name); - - // We don't know what the hash is, so we have to search through the directory - // contents - - debug!("short_name = {} where = {:?} workspace = {} \ - prefix = {}", short_name, where, workspace.display(), prefix); + crate_id.short_name); let dir_to_search = match where { - Build => target_build_dir(workspace).join(path), + Build => target_build_dir(workspace).join(&crate_id.path), Install => target_lib_dir(workspace) }; - library_in(short_name, version, &dir_to_search) + library_in(crate_id, &dir_to_search) } pub fn system_library(sysroot: &Path, crate_id: &str) -> Option { - let (lib_name, version) = split_crate_id(crate_id); - library_in(lib_name, &version, &sysroot.join(relative_target_lib_path(host_triple()))) -} - -fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option { - debug!("Listing directory {}", dir_to_search.display()); - let dir_contents = { - let _guard = io::ignore_io_error(); - fs::readdir(dir_to_search) - }; - debug!("dir has {:?} entries", dir_contents.len()); - - let dll_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name); - let dll_filetype = os::consts::DLL_EXTENSION; - let rlib_prefix = format!("{}{}", "lib", short_name); - let rlib_filetype = "rlib"; - - debug!("dll_prefix = {} and dll_filetype = {}", dll_prefix, dll_filetype); - debug!("rlib_prefix = {} and rlib_filetype = {}", rlib_prefix, rlib_filetype); - - // Find a filename that matches the pattern: - // (lib_prefix)-hash-(version)(lib_suffix) - let mut libraries = dir_contents.iter().filter(|p| { - let extension = p.extension_str(); - debug!("p = {}, p's extension is {:?}", p.display(), extension); - match extension { - None => false, - Some(ref s) => dll_filetype == *s || rlib_filetype == *s, + library_in(&CrateId::new(crate_id), &sysroot.join(relative_target_lib_path(host_triple()))) +} + +fn library_in(crate_id: &CrateId, dir_to_search: &Path) -> Option { + let lib_name = crate_id.to_lib_name(); + let filenames = [ + format!("{}{}.{}", "lib", lib_name, "rlib"), + format!("{}{}{}", os::consts::DLL_PREFIX, lib_name, os::consts::DLL_SUFFIX), + ]; + + for filename in filenames.iter() { + debug!("filename = {}", filename.as_slice()); + let path = dir_to_search.join(filename.as_slice()); + if path.exists() { + debug!("found: {}", path.display()); + return Some(path); } - }); - - let mut result_filename = None; - for p_path in libraries { - // Find a filename that matches the pattern: (lib_prefix)-hash-(version)(lib_suffix) - // and remember what the hash was - let mut f_name = match p_path.filestem_str() { - Some(s) => s, None => continue - }; - // Already checked the filetype above - - // This is complicated because library names and versions can both contain dashes - loop { - if f_name.is_empty() { break; } - match f_name.rfind('-') { - Some(i) => { - debug!("Maybe {} is a version", f_name.slice(i + 1, f_name.len())); - match try_parsing_version(f_name.slice(i + 1, f_name.len())) { - Some(ref found_vers) if version == &Some(found_vers.to_owned()) || - version == &None => { - match f_name.slice(0, i).rfind('-') { - Some(j) => { - let lib_prefix = match p_path.extension_str() { - Some(ref s) if dll_filetype == *s => &dll_prefix, - _ => &rlib_prefix, - }; - debug!("Maybe {} equals {}", f_name.slice(0, j), *lib_prefix); - if f_name.slice(0, j) == *lib_prefix { - result_filename = Some(p_path.clone()); - } - break; - } - None => break - } - } - _ => { f_name = f_name.slice(0, i); } - } - } - None => break - } // match - } // loop - } // for - - if result_filename.is_none() { - debug!("warning: library_in_workspace didn't find a library in {} for {}", - dir_to_search.display(), short_name); - } - - // Return the filename that matches, which we now know exists - // (if result_filename != None) - let abs_path = result_filename.map(|result_filename| { - let absolute_path = dir_to_search.join(&result_filename); - debug!("result_filename = {}", absolute_path.display()); - absolute_path - }); - - abs_path -} - -fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) { - match split_version(crate_id) { - Some((name, vers)) => - match vers { - Some(ref v) => match v.find('-') { - Some(pos) => (name, Some(v.slice(0, pos).to_owned())), - None => (name, Some(v.to_owned())) - }, - _ => (name, vers) - }, - None => (crate_id, None) } + debug!("warning: library_in_workspace didn't find a library in {} for {}", + dir_to_search.display(), crate_id.short_name); + return None; } - - /// Returns the executable that would be installed for /// in /// As a side effect, creates the bin-dir if it doesn't exist diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index be5b6859c74e4..4bc9714fa2ac2 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -343,13 +343,13 @@ fn create_local_package_with_custom_build_hook(crateid: &CrateId, } -fn assert_lib_exists(repo: &Path, pkg_path: &Path, v: Option<~str>) { - assert!(lib_exists(repo, pkg_path, v)); +fn assert_lib_exists(repo: &Path, crate_id: &CrateId) { + assert!(lib_exists(repo, crate_id)); } -fn lib_exists(repo: &Path, pkg_path: &Path, _v: Option<~str>) -> bool { // ??? version? - debug!("assert_lib_exists: repo = {}, pkg_path = {}", repo.display(), pkg_path.display()); - let lib = installed_library_in_workspace(pkg_path, repo); +fn lib_exists(repo: &Path, crate_id: &CrateId) -> bool { + debug!("assert_lib_exists: repo = {}, crate_id = {}", repo.display(), crate_id.to_str()); + let lib = installed_library_in_workspace(crate_id, repo); debug!("assert_lib_exists: checking whether {:?} exists", lib); lib.is_some() && { let libname = lib.get_ref(); @@ -465,12 +465,9 @@ fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path { debug!("lib_output_file_name: given {} and short name {}", workspace.display(), short_name); - library_in_workspace(&Path::new(short_name), - short_name, + library_in_workspace(&CrateId::new(short_name), Build, - workspace, - "build", - &None).expect("lib_output_file_name") + workspace).expect("lib_output_file_name") } #[cfg(target_os = "linux")] @@ -578,7 +575,7 @@ fn test_install_valid() { assert!(exec.exists()); assert!(is_rwx(&exec)); - let lib = installed_library_in_workspace(&temp_pkg_id.path, temp_workspace); + let lib = installed_library_in_workspace(&temp_pkg_id, temp_workspace); debug!("lib = {:?}", lib); assert!(lib.as_ref().map_or(false, |l| l.exists())); assert!(lib.as_ref().map_or(false, |l| is_rwx(l))); @@ -629,7 +626,7 @@ fn test_install_valid_external() { assert!(exec.exists()); assert!(is_rwx(&exec)); - let lib = installed_library_in_workspace(&temp_pkg_id.path, temp_workspace); + let lib = installed_library_in_workspace(&temp_pkg_id, temp_workspace); debug!("lib = {:?}", lib); assert!(lib.as_ref().map_or(false, |l| l.exists())); assert!(lib.as_ref().map_or(false, |l| is_rwx(l))); @@ -687,7 +684,7 @@ fn test_install_git() { let _built_lib = built_library_in_workspace(&temp_pkg_id, &ws).expect("test_install_git: built lib should exist"); - assert_lib_exists(&ws, &temp_pkg_id.path, temp_pkg_id.version.clone()); + assert_lib_exists(&ws, &temp_pkg_id); let built_test = built_test_in_workspace(&temp_pkg_id, &ws).expect("test_install_git: built test should exist"); assert!(built_test.exists()); @@ -768,7 +765,7 @@ fn test_package_request_version() { command_line_test([~"install", format!("{}\\#0.3", local_path)], repo); - assert!(match installed_library_in_workspace(&Path::new("test_pkg_version"), + assert!(match installed_library_in_workspace(&CrateId::new(format!("{}\\#0.3", local_path)), &repo.join(".rust")) { Some(p) => { debug!("installed: {}", p.display()); @@ -812,10 +809,10 @@ fn rustpkg_library_target() { "#[test] pub fn f() { (); }"); writeFile(&package_dir.join("bench.rs"), "#[bench] pub fn f() { (); }"); + add_git_tag(&package_dir, ~"0.0"); - add_git_tag(&package_dir, ~"1.0"); command_line_test([~"install", ~"foo"], foo_repo); - assert_lib_exists(&foo_repo.join(".rust"), &Path::new("foo"), Some(~"1.0")); + assert_lib_exists(&foo_repo.join(".rust"), &CrateId::new("foo")); } #[test] @@ -838,7 +835,7 @@ fn package_script_with_default_build() { debug!("package_script_with_default_build: {}", source.display()); fs::copy(&source, &dir.join_many(["src", "fancy-lib-0.0", "pkg.rs"])); command_line_test([~"install", ~"fancy-lib"], dir); - assert_lib_exists(dir, &Path::new("fancy-lib"), None); + assert_lib_exists(dir, &CrateId::new("fancy-lib")); assert!(target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]).exists()); let generated_path = target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]); debug!("generated path = {}", generated_path.display()); @@ -869,7 +866,7 @@ fn rustpkg_install_no_arg() { "fn main() { let _x = (); }"); debug!("install_no_arg: dir = {}", package_dir.display()); command_line_test([~"install"], &package_dir); - assert_lib_exists(&tmp, &Path::new("foo"), None); + assert_lib_exists(&tmp, &CrateId::new("foo")); } #[test] @@ -1047,7 +1044,7 @@ fn no_recopying() { let workspace = create_local_package(&p_id); let workspace = workspace.path(); command_line_test([~"install", ~"foo"], workspace); - let foo_lib = installed_library_in_workspace(&p_id.path, workspace); + let foo_lib = installed_library_in_workspace(&p_id, workspace); assert!(foo_lib.is_some()); // Now make `foo` read-only so that subsequent attempts to copy to it will fail assert!(chmod_read_only(&foo_lib.unwrap())); @@ -1352,11 +1349,11 @@ fn rust_path_hack_test(hack_flag: bool) { foo_path.as_str().unwrap()))]); command_line_test_with_env(~[~"install"] + if hack_flag { ~[~"--rust-path-hack"] } else { ~[] } + ~[~"foo"], dest_workspace, rust_path); - assert_lib_exists(dest_workspace, &Path::new("foo"), None); + assert_lib_exists(dest_workspace, &CrateId::new("foo")); assert_executable_exists(dest_workspace, "foo"); assert_built_library_exists(dest_workspace, "foo"); assert_built_executable_exists(dest_workspace, "foo"); - assert!(!lib_exists(workspace, &Path::new("foo"), None)); + assert!(!lib_exists(workspace, &CrateId::new("foo"))); assert!(!executable_exists(workspace, "foo")); assert!(!built_library_exists(workspace, "foo")); assert!(!built_executable_exists(workspace, "foo")); @@ -1397,9 +1394,9 @@ fn rust_path_hack_cwd() { let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack", ~"foo"], &cwd, rust_path); debug!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::new("foo"), None); + assert_lib_exists(dest_workspace, &CrateId::new("foo")); assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&cwd, &Path::new("foo"), None)); + assert!(!lib_exists(&cwd, &CrateId::new("foo"))); assert!(!built_library_exists(&cwd, "foo")); } @@ -1418,9 +1415,9 @@ fn rust_path_hack_multi_path() { let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack", name.clone()], &subdir, rust_path); debug!("Checking that {} exists in {}", name, dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::new("quux"), None); + assert_lib_exists(dest_workspace, &CrateId::new("foo/bar/quux")); assert_built_library_exists(dest_workspace, name); - assert!(!lib_exists(&subdir, &Path::new("quux"), None)); + assert!(!lib_exists(&subdir, &CrateId::new("foo/bar/quux"))); assert!(!built_library_exists(&subdir, name)); } @@ -1439,9 +1436,9 @@ fn rust_path_hack_install_no_arg() { let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); command_line_test_with_env([~"install", ~"--rust-path-hack"], &source_dir, rust_path); debug!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &Path::new("foo"), None); + assert_lib_exists(dest_workspace, &CrateId::new("foo")); assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&source_dir, &Path::new("foo"), None)); + assert!(!lib_exists(&source_dir, &CrateId::new("foo"))); assert!(!built_library_exists(cwd, "foo")); } @@ -1603,7 +1600,7 @@ fn notrans_flag_fail() { workspace, None, BAD_FLAG_CODE); assert!(!built_executable_exists(workspace, "foo")); assert!(!object_file_exists(workspace, "foo")); - assert!(!lib_exists(workspace, &Path::new("foo"), None)); + assert!(!lib_exists(workspace, &CrateId::new("foo"))); } } @@ -1834,10 +1831,10 @@ fn crateid_pointing_to_subdir() { fs::mkdir_recursive(&foo_dir, io::UserRWX); fs::mkdir_recursive(&bar_dir, io::UserRWX); writeFile(&foo_dir.join("lib.rs"), - "#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/rust-foo#foo:0.0\"];" + + "#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/foo\"];" + "pub fn f() {}"); writeFile(&bar_dir.join("lib.rs"), - "#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/rust-bar#bar:0.0\"];" + + "#[crate_id=\"mockgithub.com/mozilla/some_repo/extras/bar\"];" + "pub fn g() {}"); debug!("Creating a file in {}", workspace.display()); @@ -1875,9 +1872,9 @@ fn test_recursive_deps() { command_line_test_with_env([~"install", ~"a"], a_workspace, environment); - assert_lib_exists(a_workspace, &Path::new("a"), None); - assert_lib_exists(b_workspace, &Path::new("b"), None); - assert_lib_exists(b_workspace, &Path::new("c"), None); + assert_lib_exists(a_workspace, &CrateId::new("a")); + assert_lib_exists(b_workspace, &CrateId::new("b")); + assert_lib_exists(b_workspace, &CrateId::new("c")); } #[test] @@ -1932,7 +1929,7 @@ fn test_target_specific_install_dir() { ~"foo"], workspace); assert!(workspace.join_many([~"lib", host_triple()]).is_dir()); - assert_lib_exists(workspace, &Path::new("foo"), None); + assert_lib_exists(workspace, &CrateId::new("foo")); assert!(fs::readdir(&workspace.join("lib")).len() == 1); assert!(workspace.join("bin").is_dir()); assert_executable_exists(workspace, "foo"); @@ -1960,7 +1957,7 @@ fn install_after_build() { command_line_test([~"build", ~"b"], workspace); command_line_test([~"install", ~"b"], workspace); assert_executable_exists(workspace, b_id.short_name); - assert_lib_exists(workspace, &b_id.path, None); + assert_lib_exists(workspace, &b_id); } #[test] @@ -1972,7 +1969,7 @@ fn reinstall() { // and make sure executable was re-installed command_line_test([~"install", ~"b"], workspace); assert_executable_exists(workspace, b.short_name); - assert_lib_exists(workspace, &b.path, None); + assert_lib_exists(workspace, &b); remove_executable_file(&b, workspace); command_line_test([~"install", ~"b"], workspace); assert_executable_exists(workspace, b.short_name); @@ -2023,13 +2020,13 @@ fn correct_package_name_with_rust_path_hack() { // FIXME #3408: Should be NONEXISTENT_PACKAGE_CODE dest_workspace, rust_path, COPY_FAILED_CODE); assert!(!executable_exists(dest_workspace, "bar")); - assert!(!lib_exists(dest_workspace, &bar_id.path.clone(), bar_id.version.clone())); + assert!(!lib_exists(dest_workspace, &bar_id)); assert!(!executable_exists(dest_workspace, "foo")); - assert!(!lib_exists(dest_workspace, &foo_id.path.clone(), foo_id.version.clone())); + assert!(!lib_exists(dest_workspace, &foo_id)); assert!(!executable_exists(foo_workspace, "bar")); - assert!(!lib_exists(foo_workspace, &bar_id.path.clone(), bar_id.version.clone())); + assert!(!lib_exists(foo_workspace, &bar_id)); assert!(!executable_exists(foo_workspace, "foo")); - assert!(!lib_exists(foo_workspace, &foo_id.path.clone(), foo_id.version.clone())); + assert!(!lib_exists(foo_workspace, &foo_id)); } #[test] diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 18e773d5f15a8..4c2fc98a305a9 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -135,7 +135,7 @@ struct CrateSetup<'a> { ctx: &'a mut ReadyCtx<'a>, } -impl<'a> fold::Folder for CrateSetup<'a> { +impl<'a> Folder for CrateSetup<'a> { fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> { fold_item(item, self) } @@ -162,7 +162,7 @@ pub fn ready_crate(sess: session::Session, pub fn compile_input(context: &BuildContext, exec: &mut workcache::Exec, - pkg_id: &CrateId, + crate_id: &CrateId, in_file: &Path, workspace: &Path, deps: &mut DepMap, @@ -177,7 +177,7 @@ pub fn compile_input(context: &BuildContext, // not sure if we should support anything else let mut out_dir = target_build_dir(workspace); - out_dir.push(&pkg_id.path); + out_dir.push(&crate_id.path); // Make the output directory if it doesn't exist already fs::mkdir_recursive(&out_dir, io::UserRWX); @@ -276,7 +276,7 @@ pub fn compile_input(context: &BuildContext, let (mut crate, ast_map) = { let installer = CrateInstaller { context: context, - parent: pkg_id, + parent: crate_id, parent_crate: in_file, sess: sess, exec: exec, @@ -312,10 +312,7 @@ pub fn compile_input(context: &BuildContext, if !attr::contains_name(crate.attrs, "crate_id") { // FIXME (#9639): This needs to handle non-utf8 paths let crateid_attr = - attr::mk_name_value_item_str(@"crate_id", - format!("{}\\#{}", - pkg_id.path.as_str().unwrap(), - pkg_id.get_version()).to_managed()); + attr::mk_name_value_item_str(@"crate_id", crate_id.to_crate_id_str().to_managed()); debug!("crateid attr: {:?}", crateid_attr); crate.attrs.push(attr::mk_attr(crateid_attr)); @@ -333,7 +330,7 @@ pub fn compile_input(context: &BuildContext, what); // Discover the output let discovered_output = if what == Lib { - built_library_in_workspace(pkg_id, workspace) // Huh??? + built_library_in_workspace(crate_id, workspace) // Huh??? } else { result @@ -435,7 +432,7 @@ pub fn exe_suffix() -> ~str { ~"" } // Called by build_crates pub fn compile_crate(ctxt: &BuildContext, exec: &mut workcache::Exec, - pkg_id: &CrateId, + crate_id: &CrateId, crate: &Path, workspace: &Path, deps: &mut DepMap, @@ -444,11 +441,11 @@ pub fn compile_crate(ctxt: &BuildContext, opt: session::OptLevel, what: OutputType) -> Option { debug!("compile_crate: crate={}, workspace={}", crate.display(), workspace.display()); - debug!("compile_crate: short_name = {}, flags =...", pkg_id.to_str()); + debug!("compile_crate: short_name = {}, flags =...", crate_id.to_str()); for fl in flags.iter() { debug!("+++ {}", *fl); } - compile_input(ctxt, exec, pkg_id, crate, workspace, deps, flags, cfgs, opt, what) + compile_input(ctxt, exec, crate_id, crate, workspace, deps, flags, cfgs, opt, what) } struct CrateInstaller<'a> { @@ -497,10 +494,10 @@ impl<'a> CrateInstaller<'a> { debug!("Trying to install library {}, rebuilding it", lib_name.to_str()); // Try to install it - let pkg_id = CrateId::new(lib_name); + let crate_id = CrateId::new(lib_name); // Find all the workspaces in the RUST_PATH that contain this package. let workspaces = pkg_parent_workspaces(&self.context.context, - &pkg_id); + &crate_id); // Three cases: // (a) `workspaces` is empty. That means there's no local source // for this package. In that case, we pass the default workspace @@ -530,7 +527,7 @@ impl<'a> CrateInstaller<'a> { error(format!("Package {} depends on {}, but I don't know \ how to find it", self.parent.path.display(), - pkg_id.path.display())); + crate_id.path.display())); fail!() }).inside(|| { PkgSrc::new(source_workspace.clone(), @@ -538,7 +535,7 @@ impl<'a> CrateInstaller<'a> { // Use the rust_path_hack to search for dependencies iff // we were already using it self.context.context.use_rust_path_hack, - pkg_id.clone()) + crate_id.clone()) }); let (outputs_disc, inputs_disc) = self.context.install( From a6a31ecb0481af3bd5f8ba3655dda0dde9df7116 Mon Sep 17 00:00:00 2001 From: klutzy Date: Sat, 11 Jan 2014 00:22:06 +0900 Subject: [PATCH 4/4] rustpkg::crate_id: Remove CrateId There is no significant difference between `rustpkg::crate_id::CrateId` and `syntax::crateid::CrateId`. rustpkg's one is replaced by syntax's one. --- src/librustpkg/api.rs | 35 +- src/librustpkg/conditions.rs | 2 +- src/librustpkg/crate_id.rs | 144 -------- src/librustpkg/installed_packages.rs | 8 +- src/librustpkg/lib.rs | 34 +- src/librustpkg/package_source.rs | 74 ++-- src/librustpkg/path_util.rs | 56 +-- src/librustpkg/tests.rs | 509 ++++++++++++++------------- src/librustpkg/util.rs | 32 +- src/librustpkg/workspace.rs | 8 +- src/libsyntax/crateid.rs | 10 +- 11 files changed, 413 insertions(+), 499 deletions(-) delete mode 100644 src/librustpkg/crate_id.rs diff --git a/src/librustpkg/api.rs b/src/librustpkg/api.rs index 27dfc3cae41c4..13d5a1177049b 100644 --- a/src/librustpkg/api.rs +++ b/src/librustpkg/api.rs @@ -11,7 +11,6 @@ use CtxMethods; use context::*; use crate::*; -use crate_id::*; use package_source::*; use path_util::{platform_library_name, target_build_dir}; use target::*; @@ -26,6 +25,7 @@ use extra::arc::{Arc,RWArc}; use extra::workcache; use extra::workcache::{Database, FreshnessMap}; use extra::treemap::TreeMap; +use syntax::crateid::CrateId; // A little sad -- duplicated from rustc::back::* #[cfg(target_arch = "arm")] @@ -78,20 +78,19 @@ pub fn new_workcache_context(p: &Path) -> workcache::Context { workcache::Context::new_with_freshness(db, cfg, Arc::new(freshness)) } -pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Option<~str>, - lib: Path) { - build_lib_with_cfgs(sysroot, root, name, version, lib, ~[]) +pub fn build_lib(sysroot: Path, root: Path, name: ~str, lib: Path) { + build_lib_with_cfgs(sysroot, root, name, lib, ~[]) } -pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str, - version: Option<~str>, lib: Path, cfgs: ~[~str]) { +pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str, lib: Path, cfgs: ~[~str]) { let cx = default_context(sysroot, root.clone()); + let crate_id: CrateId = from_str(name).expect("valid crate id"); let pkg_src = PkgSrc { source_workspace: root.clone(), build_in_destination: false, destination_workspace: root.clone(), start_dir: root.join_many(["src", name.as_slice()]), - id: CrateId{ version: version, ..CrateId::new(name)}, + id: crate_id, // n.b. This assumes the package only has one crate libs: ~[mk_crate(lib)], mains: ~[], @@ -101,20 +100,19 @@ pub fn build_lib_with_cfgs(sysroot: Path, root: Path, name: ~str, pkg_src.build(&cx, cfgs, []); } -pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Option<~str>, - main: Path) { - build_exe_with_cfgs(sysroot, root, name, version, main, ~[]) +pub fn build_exe(sysroot: Path, root: Path, name: ~str, main: Path) { + build_exe_with_cfgs(sysroot, root, name, main, ~[]) } -pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str, - version: Option<~str>, main: Path, cfgs: ~[~str]) { +pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str, main: Path, cfgs: ~[~str]) { let cx = default_context(sysroot, root.clone()); + let crate_id: CrateId = from_str(name).expect("valid crate id"); let pkg_src = PkgSrc { source_workspace: root.clone(), build_in_destination: false, destination_workspace: root.clone(), start_dir: root.join_many(["src", name.as_slice()]), - id: CrateId{ version: version, ..CrateId::new(name)}, + id: crate_id, libs: ~[], // n.b. This assumes the package only has one crate mains: ~[mk_crate(main)], @@ -128,11 +126,10 @@ pub fn build_exe_with_cfgs(sysroot: Path, root: Path, name: ~str, pub fn install_pkg(cx: &BuildContext, workspace: Path, name: ~str, - version: Option<~str>, // For now, these inputs are assumed to be inputs to each of the crates more_inputs: ~[(~str, Path)]) { // pairs of Kind and Path - let crateid = CrateId{ version: version, ..CrateId::new(name)}; - cx.install(PkgSrc::new(workspace.clone(), workspace, false, crateid), + let crate_id: CrateId = from_str(name).expect("valid crate id"); + cx.install(PkgSrc::new(workspace.clone(), workspace, false, crate_id), &WhatToBuild{ build_type: Inferred, inputs_to_discover: more_inputs, sources: Everything }); @@ -156,10 +153,10 @@ pub fn build_library_in_workspace(exec: &mut workcache::Exec, let out_name = workspace_build_dir.join_many([package_name.to_str(), platform_library_name(output)]); // make paths absolute - let crateid = CrateId::new(package_name); + let crateid: CrateId = from_str(package_name).expect("valid crate id"); let absolute_paths = paths.map(|s| { let whatever = workspace.join_many([~"src", - crateid.to_str(), + crateid.short_name_with_version(), s.to_owned()]); whatever.as_str().unwrap().to_owned() }); @@ -189,7 +186,7 @@ pub fn my_workspace(context: &Context, package_name: &str) -> Path { use bad_pkg_id = conditions::bad_pkg_id::cond; // (this assumes no particular version is requested) - let crateid = CrateId::new(package_name); + let crateid = from_str(package_name).expect("valid crate id"); let workspaces = pkg_parent_workspaces(context, &crateid); if workspaces.is_empty() { bad_pkg_id.raise((Path::new(package_name), package_name.to_owned())); diff --git a/src/librustpkg/conditions.rs b/src/librustpkg/conditions.rs index 6c38d63a51801..d18161d7c4a37 100644 --- a/src/librustpkg/conditions.rs +++ b/src/librustpkg/conditions.rs @@ -10,7 +10,7 @@ // Useful conditions -pub use crate_id::CrateId; +pub use syntax::crateid::CrateId; pub use std::io::FileStat; pub use std::io::process::ProcessExit; pub use std::path::Path; diff --git a/src/librustpkg/crate_id.rs b/src/librustpkg/crate_id.rs deleted file mode 100644 index 4a87bcb70f50a..0000000000000 --- a/src/librustpkg/crate_id.rs +++ /dev/null @@ -1,144 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::hash::Streaming; -use syntax::crateid; -use extra::hex::ToHex; -use rustc::util::sha2::{Digest, Sha256}; - -/// Path-fragment identifier of a package such as -/// 'github.com/graydon/test'; path must be a relative -/// path with >=1 component. -#[deriving(Clone)] -pub struct CrateId { - /// This is a path, on the local filesystem, referring to where the - /// files for this package live. For example: - /// github.com/mozilla/quux-whatever (it's assumed that if we're - /// working with a package ID of this form, rustpkg has already cloned - /// the sources into a local directory in the RUST_PATH). - path: Path, - /// Short name. This is the path's filestem, but we store it - /// redundantly so as to not call get() everywhere (filestem() returns an - /// option) - /// The short name does not need to be a valid Rust identifier. - /// Users can write: `extern mod foo = "...";` to get around the issue - /// of package IDs whose short names aren't valid Rust identifiers. - short_name: ~str, - /// The requested package version. - version: Option<~str> -} - -impl Eq for CrateId { - fn eq(&self, other: &CrateId) -> bool { - self.path == other.path && self.version == other.version - } -} - -impl CrateId { - pub fn version_or_default<'a>(&'a self) -> &'a str { - match self.version { - Some(ref ver) => ver.as_slice(), - None => "0.0" - } - } - - pub fn new(s: &str) -> CrateId { - use conditions::bad_pkg_id::cond; - - let raw_crateid: Option = from_str(s); - if raw_crateid.is_none() { - return cond.raise((Path::new(s), ~"bad crateid")) - } - let raw_crateid = raw_crateid.unwrap(); - let crateid::CrateId { path, name, version } = raw_crateid; - let path = Path::new(path); - - CrateId { - path: path, - short_name: name, - version: version - } - } - - pub fn to_crate_id_str(&self) -> ~str { - format!("{}\\#{}", self.path.as_str().unwrap(), self.version_or_default()) - } - - pub fn to_lib_name(&self) -> ~str { - format!("{}-{}-{}", self.short_name, self.hash(), self.version_or_default()) - } - - pub fn hash(&self) -> ~str { - let mut hasher = Sha256::new(); - hasher.reset(); - hasher.input_str(self.to_crate_id_str()); - let hash = hasher.result_bytes().to_hex(); - hash.slice_chars(0, 8).to_owned() - } - - pub fn short_name_with_version(&self) -> ~str { - format!("{}-{}", self.short_name, self.version_or_default()) - } - - /// True if the ID has multiple components - pub fn is_complex(&self) -> bool { - self.short_name.as_bytes() != self.path.as_vec() - } - - pub fn prefixes(&self) -> Prefixes { - prefixes(&self.path) - } - - // This is the workcache function name for the *installed* - // binaries for this package (as opposed to the built ones, - // which are per-crate). - pub fn install_tag(&self) -> ~str { - format!("install({})", self.to_str()) - } -} - -pub fn prefixes(p: &Path) -> Prefixes { - Prefixes { - components: p.str_components().map(|x|x.unwrap().to_owned()).to_owned_vec(), - remaining: ~[] - } -} - -struct Prefixes { - priv components: ~[~str], - priv remaining: ~[~str] -} - -impl Iterator<(Path, Path)> for Prefixes { - #[inline] - fn next(&mut self) -> Option<(Path, Path)> { - if self.components.len() <= 1 { - None - } - else { - let last = self.components.pop().unwrap(); - self.remaining.unshift(last); - // converting to str and then back is a little unfortunate - Some((Path::new(self.components.connect("/")), - Path::new(self.remaining.connect("/")))) - } - } -} - -impl ToStr for CrateId { - fn to_str(&self) -> ~str { - // should probably use the filestem and not the whole path - format!("{}-{}", self.path.as_str().unwrap(), self.version_or_default()) - } -} - -pub fn write(writer: &mut W, string: &str) { - writer.write(string.as_bytes()); -} diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs index 67ba5d2b8e83f..c7900181a77d1 100644 --- a/src/librustpkg/installed_packages.rs +++ b/src/librustpkg/installed_packages.rs @@ -11,10 +11,10 @@ // Listing installed packages use rustc::metadata::filesearch::rust_path; -use path_util::*; use std::os; use std::io; use std::io::fs; +use syntax::crateid::CrateId; pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool { let workspaces = rust_path(); @@ -28,7 +28,8 @@ pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool { match exec.filestem_str() { None => (), Some(exec_path) => { - if !f(&CrateId::new(exec_path)) { + let crate_id = from_str(exec_path).expect("valid crate id"); + if !f(&crate_id) { return false; } } @@ -50,7 +51,8 @@ pub fn list_installed_packages(f: |&CrateId| -> bool) -> bool { let rel_path = rel_p.join(basename); rel_path.display().with_str(|s| { debug!("Rel name: {}", s); - f(&CrateId::new(s)); + let crate_id = from_str(s).expect("valid crate id"); + f(&crate_id); }); } None => () diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index 22871179a6e3b..e5e494e9b5f0c 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -33,6 +33,7 @@ use rustc::metadata::filesearch; use rustc::metadata::filesearch::rust_path; use rustc::util::sha2; use syntax::{ast, diagnostic}; +use syntax::crateid::CrateId; use messages::{error, warn, note}; use parse_args::{ParseResult, parse_args}; use path_util::{build_pkg_id_in_workspace, built_test_in_workspace}; @@ -46,7 +47,6 @@ use context::{BuildContext, Trans, Nothing, Pretty, Analysis, LLVMAssemble, LLVMCompileBitcode}; use context::{Command, BuildCmd, CleanCmd, DoCmd, HelpCmd, InfoCmd, InstallCmd, ListCmd, PreferCmd, TestCmd, InitCmd, UninstallCmd, UnpreferCmd}; -use crate_id::CrateId; use package_source::PkgSrc; use target::{WhatToBuild, Everything, is_lib, is_main, is_test, is_bench}; use target::{Main, Tests, MaybeCustom, Inferred, JustOne}; @@ -60,7 +60,6 @@ mod crate; pub mod exit_codes; mod installed_packages; mod messages; -pub mod crate_id; pub mod package_source; mod parse_args; mod path_util; @@ -103,7 +102,7 @@ impl<'a> PkgScript<'a> { workspace: &Path, id: &'a CrateId) -> PkgScript<'a> { // Get the executable name that was invoked - let binary = os::args()[0].to_owned(); + let binary = os::args()[0]; // Build the rustc session data structures to pass // to the compiler debug!("pkgscript parse: {}", sysroot.display()); @@ -244,7 +243,7 @@ impl CtxMethods for BuildContext { match cwd_to_workspace() { None if dir_has_crate_file(&cwd) => { // FIXME (#9639): This needs to handle non-utf8 paths - let crateid = CrateId::new(cwd.filename_str().unwrap()); + let crateid = from_str(cwd.filename_str().unwrap()).expect("valid crate id"); let mut pkg_src = PkgSrc::new(cwd, default_workspace(), true, crateid); self.build(&mut pkg_src, what); match pkg_src { @@ -269,7 +268,7 @@ impl CtxMethods for BuildContext { } else { // The package id is presumed to be the first command-line // argument - let crateid = CrateId::new(args[0].clone()); + let crateid = from_str(args[0]).expect("valid crate id"); let mut dest_ws = default_workspace(); each_pkg_parent_workspace(&self.context, &crateid, |workspace| { debug!("found pkg {} in workspace {}, trying to build", @@ -308,7 +307,7 @@ impl CtxMethods for BuildContext { else { // The package id is presumed to be the first command-line // argument - let crateid = CrateId::new(args[0].clone()); + let crateid = from_str(args[0]).expect("valid crate id"); self.clean(&cwd, &crateid); // tjc: should use workspace, not cwd } } @@ -341,7 +340,7 @@ impl CtxMethods for BuildContext { // FIXME (#9639): This needs to handle non-utf8 paths let inferred_crateid = - CrateId::new(cwd.filename_str().unwrap()); + from_str(cwd.filename_str().unwrap()).expect("valid crate id"); self.install(PkgSrc::new(cwd, default_workspace(), true, inferred_crateid), &WhatToBuild::new(MaybeCustom, Everything)); @@ -357,7 +356,7 @@ impl CtxMethods for BuildContext { else { // The package id is presumed to be the first command-line // argument - let crateid = CrateId::new(args[0]); + let crateid = from_str(args[0]).expect("valid crate id"); let workspaces = pkg_parent_workspaces(&self.context, &crateid); debug!("package ID = {}, found it in {:?} workspaces", crateid.to_str(), workspaces.len()); @@ -383,7 +382,7 @@ impl CtxMethods for BuildContext { ListCmd => { println!("Installed packages:"); installed_packages::list_installed_packages(|pkg_id| { - pkg_id.path.display().with_str(|s| println!("{}", s)); + println!("{}", pkg_id.path); true }); } @@ -420,7 +419,7 @@ impl CtxMethods for BuildContext { return usage::uninstall(); } - let crateid = CrateId::new(args[0]); + let crateid = from_str(args[0]).expect("valid crate id"); if !installed_packages::package_is_installed(&crateid) { warn(format!("Package {} doesn't seem to be installed! \ Doing nothing.", args[0])); @@ -458,24 +457,24 @@ impl CtxMethods for BuildContext { let workspace = pkg_src.source_workspace.clone(); let crateid = pkg_src.id.clone(); + let path = crateid.path.as_slice(); debug!("build: workspace = {} (in Rust path? {:?} is git dir? {:?} \ crateid = {} pkgsrc start_dir = {}", workspace.display(), - in_rust_path(&workspace), is_git_dir(&workspace.join(&crateid.path)), + in_rust_path(&workspace), is_git_dir(&workspace.join(path)), crateid.to_str(), pkg_src.start_dir.display()); debug!("build: what to build = {:?}", what_to_build); // If workspace isn't in the RUST_PATH, and it's a git repo, // then clone it into the first entry in RUST_PATH, and repeat - if !in_rust_path(&workspace) && is_git_dir(&workspace.join(&crateid.path)) { + if !in_rust_path(&workspace) && is_git_dir(&workspace.join(path)) { let mut out_dir = default_workspace().join("src"); - out_dir.push(&crateid.path); - let git_result = source_control::safe_git_clone(&workspace.join(&crateid.path), + out_dir.push(path); + let git_result = source_control::safe_git_clone(&workspace.join(path), &crateid.version, &out_dir); match git_result { CheckedOutSources => make_read_only(&out_dir), - // FIXME (#9639): This needs to handle non-utf8 paths - _ => cond.raise((crateid.path.as_str().unwrap().to_owned(), out_dir.clone())) + _ => cond.raise((path.to_owned(), out_dir.clone())) }; let default_ws = default_workspace(); debug!("Calling build recursively with {:?} and {:?}", default_ws.display(), @@ -652,7 +651,8 @@ impl CtxMethods for BuildContext { target_exec.display(), target_lib, maybe_executable, maybe_library); - self.workcache_context.with_prep(id.install_tag(), |prep| { + let install_tag = format!("install({}-{})", id.path, id.version_or_default()); + self.workcache_context.with_prep(install_tag, |prep| { for ee in maybe_executable.iter() { // FIXME (#9639): This needs to handle non-utf8 paths prep.declare_input("binary", diff --git a/src/librustpkg/package_source.rs b/src/librustpkg/package_source.rs index 2bc1966bff0e4..5ac62c5284e08 100644 --- a/src/librustpkg/package_source.rs +++ b/src/librustpkg/package_source.rs @@ -11,7 +11,6 @@ extern mod extra; use target::*; -use crate_id::CrateId; use std::io; use std::io::fs; use std::os; @@ -27,7 +26,7 @@ use workcache_support; use workcache_support::{digest_only_date, digest_file_with_date, crate_tag}; use extra::workcache; use extra::treemap::TreeMap; - +use syntax::crateid::CrateId; use rustc::driver::session; // An enumeration of the unpacked source of a package workspace. @@ -68,12 +67,38 @@ impl ToStr for PkgSrc { } } condition! { - // #6009: should this be pub or not, when #8215 is fixed? build_err: (~str) -> ~str; } -impl PkgSrc { +fn prefixes(p: &Path) -> Prefixes { + Prefixes { + components: p.str_components().map(|x|x.unwrap().to_owned()).to_owned_vec(), + remaining: ~[] + } +} + +struct Prefixes { + priv components: ~[~str], + priv remaining: ~[~str] +} + +impl Iterator<(Path, Path)> for Prefixes { + #[inline] + fn next(&mut self) -> Option<(Path, Path)> { + if self.components.len() <= 1 { + None + } + else { + let last = self.components.pop().unwrap(); + self.remaining.unshift(last); + // converting to str and then back is a little unfortunate + Some((Path::new(self.components.connect("/")), + Path::new(self.remaining.connect("/")))) + } + } +} +impl PkgSrc { pub fn new(mut source_workspace: Path, destination_workspace: Path, use_rust_path_hack: bool, @@ -98,21 +123,22 @@ impl PkgSrc { } else { // We search for sources under both src/ and build/ , because build/ is where // automatically-checked-out sources go. + let path = Path::new(id.path.as_slice()); let mut result = source_workspace.join("src"); - result.push(&id.path.dir_path()); + result.push(&path.dir_path()); result.push(id.short_name_with_version()); to_try.push(result); let mut result = source_workspace.join("src"); - result.push(&id.path); + result.push(&path); to_try.push(result); let mut result = build_dir.join("src"); - result.push(&id.path.dir_path()); + result.push(&path.dir_path()); result.push(id.short_name_with_version()); to_try.push(result.clone()); output_names.push(result); let mut other_result = build_dir.join("src"); - other_result.push(&id.path); + other_result.push(&path); to_try.push(other_result.clone()); output_names.push(other_result); @@ -132,9 +158,10 @@ impl PkgSrc { None => { // See if any of the prefixes of this package ID form a valid package ID // That is, is this a package ID that points into the middle of a workspace? - for (prefix, suffix) in id.prefixes() { - let crate_id = CrateId::new(prefix.as_str().unwrap()); - let path = build_dir.join(&crate_id.path); + for (prefix, suffix) in prefixes(&Path::new(id.path.as_slice())) { + let crate_id: Option = from_str(prefix.as_str().unwrap()); + let crate_id = crate_id.expect("valid crate id"); + let path = build_dir.join(crate_id.path.as_slice()); debug!("in loop: checking if {} is a directory", path.display()); if path.is_dir() { let ps = PkgSrc::new(source_workspace, @@ -163,7 +190,7 @@ impl PkgSrc { } } - }; + } } // Ok, no prefixes work, so try fetching from git @@ -179,11 +206,12 @@ impl PkgSrc { } match ok_d { Some(ref d) => { - if d.is_ancestor_of(&id.path) - || d.is_ancestor_of(&versionize(&id.path, &id.version)) { + let path = Path::new(id.path.as_slice()); + if d.is_ancestor_of(&path) + || d.is_ancestor_of(&versionize(id.path, &id.version)) { // Strip off the package ID source_workspace = d.clone(); - for _ in id.path.components() { + for _ in path.components() { source_workspace.pop(); } // Strip off the src/ part @@ -226,8 +254,7 @@ impl PkgSrc { exist, and couldn't interpret it as a URL fragment")) } } - } - else { + } else { cond.raise((id.clone(), ~"supplied path for package dir does not \ exist, and couldn't interpret it as a URL fragment")) @@ -268,24 +295,25 @@ impl PkgSrc { use conditions::git_checkout_failed::cond; let cwd = os::getcwd(); + let path = Path::new(crateid.path.as_slice()); debug!("Checking whether {} (path = {}) exists locally. Cwd = {}, does it? {:?}", - crateid.to_str(), crateid.path.display(), + crateid.to_str(), crateid.path, cwd.display(), - crateid.path.exists()); + path.exists()); - match safe_git_clone(&crateid.path, &crateid.version, local) { + match safe_git_clone(&path, &crateid.version, local) { CheckedOutSources => { make_read_only(local); Some(local.clone()) } DirToUse(clone_target) => { - if crateid.path.components().nth(1).is_none() { + if path.components().nth(1).is_none() { // If a non-URL, don't bother trying to fetch return None; } // FIXME (#9639): This needs to handle non-utf8 paths - let url = format!("https://{}", crateid.path.as_str().unwrap()); + let url = format!("https://{}", path.as_str().unwrap()); debug!("Fetching package: git clone {} {} [version={}]", url, clone_target.display(), crateid.version_or_default()); @@ -345,7 +373,7 @@ impl PkgSrc { use conditions::missing_pkg_files::cond; let prefix = self.start_dir.components().len(); - debug!("Matching against {}", self.id.short_name); + debug!("Matching against {}", self.id.name); for pth in fs::walk_dir(&self.start_dir) { let maybe_known_crate_set = match pth.filename_str() { Some(filename) if filter(filename) => match filename { diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index 1412b99d285f1..a0d49e7565f18 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -12,9 +12,8 @@ #[allow(dead_code)]; -pub use crate_id::CrateId; pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install}; -pub use version::{Version, split_version, split_version_general, try_parsing_version}; +pub use version::{Version, split_version_general}; pub use rustc::metadata::filesearch::rust_path; use std::libc; @@ -22,6 +21,9 @@ use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; use std::os; use std::io; use std::io::fs; +use extra::hex::ToHex; +use syntax::crateid::CrateId; +use rustc::util::sha2::{Digest, Sha256}; use rustc::metadata::filesearch::{libdir, relative_target_lib_path}; use rustc::driver::driver::host_triple; use messages::*; @@ -77,13 +79,13 @@ pub fn workspace_contains_crate_id_(crateid: &CrateId, workspace: &Path, let mut found = None; for p in fs::walk_dir(&src_dir) { if p.is_dir() { - if p == src_dir.join(&crateid.path) || { + if p == src_dir.join(crateid.path.as_slice()) || { let pf = p.filename_str(); pf.iter().any(|&g| { match split_version_general(g, '-') { None => false, Some((ref might_match, ref vers)) => { - *might_match == crateid.short_name + *might_match == crateid.name && (crateid.version == *vers || crateid.version == None) } } @@ -178,33 +180,39 @@ pub fn built_library_in_workspace(crateid: &CrateId, workspace: &Path) -> Option /// Does the actual searching stuff pub fn installed_library_in_workspace(crate_id: &CrateId, workspace: &Path) -> Option { // This could break once we're handling multiple versions better -- I should add a test for it - // FIXME (#9639): This needs to handle non-utf8 paths - match crate_id.path.filename_str() { + let path = Path::new(crate_id.path.as_slice()); + match path.filename_str() { None => None, Some(_short_name) => library_in_workspace(crate_id, Install, workspace) } } /// `workspace` is used to figure out the directory to search. -/// `short_name` is taken as the link name of the library. +/// `name` is taken as the link name of the library. pub fn library_in_workspace(crate_id: &CrateId, where: Target, workspace: &Path) -> Option { debug!("library_in_workspace: checking whether a library named {} exists", - crate_id.short_name); + crate_id.name); let dir_to_search = match where { - Build => target_build_dir(workspace).join(&crate_id.path), + Build => target_build_dir(workspace).join(crate_id.path.as_slice()), Install => target_lib_dir(workspace) }; library_in(crate_id, &dir_to_search) } -pub fn system_library(sysroot: &Path, crate_id: &str) -> Option { - library_in(&CrateId::new(crate_id), &sysroot.join(relative_target_lib_path(host_triple()))) +pub fn system_library(sysroot: &Path, crate_id: &CrateId) -> Option { + library_in(crate_id, &sysroot.join(relative_target_lib_path(host_triple()))) } fn library_in(crate_id: &CrateId, dir_to_search: &Path) -> Option { - let lib_name = crate_id.to_lib_name(); + let mut hasher = Sha256::new(); + hasher.reset(); + hasher.input_str(crate_id.to_str()); + let hash = hasher.result_bytes().to_hex(); + let hash = hash.slice_chars(0, 8); + + let lib_name = format!("{}-{}-{}", crate_id.name, hash, crate_id.version_or_default()); let filenames = [ format!("{}{}.{}", "lib", lib_name, "rlib"), format!("{}{}{}", os::consts::DLL_PREFIX, lib_name, os::consts::DLL_SUFFIX), @@ -219,7 +227,7 @@ fn library_in(crate_id: &CrateId, dir_to_search: &Path) -> Option { } } debug!("warning: library_in_workspace didn't find a library in {} for {}", - dir_to_search.display(), crate_id.short_name); + dir_to_search.display(), crate_id.to_str()); return None; } @@ -271,7 +279,7 @@ fn target_file_in_workspace(crateid: &CrateId, workspace: &Path, // Artifacts in the build directory live in a package-ID-specific subdirectory, // but installed ones don't. let result = match (where, what) { - (Build, _) => target_build_dir(workspace).join(&crateid.path), + (Build, _) => target_build_dir(workspace).join(crateid.path.as_slice()), (Install, Lib) => target_lib_dir(workspace), (Install, _) => target_bin_dir(workspace) }; @@ -287,7 +295,7 @@ fn target_file_in_workspace(crateid: &CrateId, workspace: &Path, /// Creates it if it doesn't exist. pub fn build_pkg_id_in_workspace(crateid: &CrateId, workspace: &Path) -> Path { let mut result = target_build_dir(workspace); - result.push(&crateid.path); + result.push(crateid.path.as_slice()); debug!("Creating build dir {} for package id {}", result.display(), crateid.to_str()); fs::mkdir_recursive(&result, io::UserRWX); @@ -297,24 +305,24 @@ pub fn build_pkg_id_in_workspace(crateid: &CrateId, workspace: &Path) -> Path { /// Return the output file for a given directory name, /// given whether we're building a library and whether we're building tests pub fn mk_output_path(what: OutputType, where: Target, - pkg_id: &CrateId, workspace: Path) -> Path { - let short_name_with_version = pkg_id.short_name_with_version(); + crate_id: &CrateId, workspace: Path) -> Path { + let short_name_with_version = crate_id.short_name_with_version(); // Not local_path.dir_path()! For package foo/bar/blat/, we want // the executable blat-0.5 to live under blat/ let dir = match where { // If we're installing, it just goes under ... Install => workspace, // and if we're just building, it goes in a package-specific subdir - Build => workspace.join(&pkg_id.path) + Build => workspace.join(crate_id.path.as_slice()) }; - debug!("[{:?}:{:?}] mk_output_path: short_name = {}, path = {}", what, where, - if what == Lib { short_name_with_version.clone() } else { pkg_id.short_name.clone() }, + debug!("[{:?}:{:?}] mk_output_path: name = {}, path = {}", what, where, + if what == Lib { short_name_with_version.clone() } else { crate_id.name.clone() }, dir.display()); let mut output_path = match what { // this code is duplicated from elsewhere; fix this Lib => dir.join(os::dll_filename(short_name_with_version)), // executable names *aren't* versioned - _ => dir.join(format!("{}{}{}", pkg_id.short_name, + _ => dir.join(format!("{}{}{}", crate_id.name, match what { Test => "test", Bench => "bench", @@ -361,11 +369,12 @@ fn dir_has_file(dir: &Path, file: &str) -> bool { pub fn find_dir_using_rust_path_hack(p: &CrateId) -> Option { let rp = rust_path(); + let path = Path::new(p.path.as_slice()); for dir in rp.iter() { // Require that the parent directory match the package ID // Note that this only matches if the package ID being searched for // has a name that's a single component - if dir.ends_with_path(&p.path) || dir.ends_with_path(&versionize(&p.path, &p.version)) { + if dir.ends_with_path(&path) || dir.ends_with_path(&versionize(p.path, &p.version)) { debug!("In find_dir_using_rust_path_hack: checking dir {}", dir.display()); if dir_has_crate_file(dir) { debug!("Did find id {} in dir {}", p.to_str(), dir.display()); @@ -387,7 +396,8 @@ pub fn user_set_rust_path() -> bool { } /// Append the version string onto the end of the path's filename -pub fn versionize(p: &Path, v: &Version) -> Path { +pub fn versionize(p: &str, v: &Version) -> Path { + let p = Path::new(p); let q = p.filename().expect("path is a directory"); let mut q = q.to_owned(); q.push('-' as u8); diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 4bc9714fa2ac2..bf8ec1e738cab 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -20,12 +20,12 @@ use extra::arc::Arc; use extra::arc::RWArc; use extra::tempfile::TempDir; use extra::workcache; -use extra::workcache::{Database}; +use extra::workcache::Database; use extra::treemap::TreeMap; use extra::getopts::groups::getopts; use std::run::ProcessOutput; use installed_packages::list_installed_packages; -use crate_id::CrateId; +use syntax::crateid::CrateId; use path_util::{target_executable_in_workspace, target_test_in_workspace, target_bench_in_workspace, make_dir_rwx, library_in_workspace, installed_library_in_workspace, @@ -58,18 +58,17 @@ fn fake_ctxt(sysroot: Path, workspace: &Path) -> BuildContext { } fn fake_pkg() -> CrateId { - let sn = ~"bogus"; CrateId { - path: Path::new(sn.as_slice()), - short_name: sn, + path: ~"bogus", + name: ~"bogus", version: None } } fn git_repo_pkg() -> CrateId { CrateId { - path: Path::new("mockgithub.com/catamorphism/test-pkg"), - short_name: ~"test-pkg", + path: ~"mockgithub.com/catamorphism/test-pkg", + name: ~"test-pkg", version: None } } @@ -273,14 +272,11 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s err_fd: None }).expect(format!("failed to exec `{}`", cmd)); let output = prog.finish_with_output(); - debug!("Output from command {} with args {:?} was {} \\{{}\\}[{:?}]", + debug!("Output from command {} with args {:?} was --- {} \\{{}\\} --- [{:?}]", cmd, args, str::from_utf8(output.output).unwrap(), str::from_utf8(output.error).unwrap(), output.status); if !output.status.success() { - debug!("Command {} {:?} failed with exit code {:?}; its output was --- {} {} ---", - cmd, args, output.status, - str::from_utf8(output.output).unwrap(), str::from_utf8(output.error).unwrap()); Fail(output) } else { @@ -297,7 +293,7 @@ fn create_local_package(crateid: &CrateId) -> TempDir { fn create_local_package_in(crateid: &CrateId, pkgdir: &Path) -> Path { - let package_dir = pkgdir.join_many([~"src", crateid.to_str()]); + let package_dir = pkgdir.join_many([~"src", crateid.short_name_with_version()]); // Create main, lib, test, and bench files fs::mkdir_recursive(&package_dir, io::UserRWX); @@ -325,11 +321,15 @@ fn create_local_package_with_dep(crateid: &CrateId, subord_crateid: &CrateId) -> let package_dir = create_local_package(crateid); create_local_package_in(subord_crateid, package_dir.path()); // Write a main.rs file into crateid that references subord_crateid - writeFile(&package_dir.path().join_many([~"src", crateid.to_str(), ~"main.rs"]), + writeFile(&package_dir.path().join_many([~"src", + crateid.short_name_with_version(), + ~"main.rs"]), format!("extern mod {};\nfn main() \\{\\}", - subord_crateid.short_name)); + subord_crateid.name)); // Write a lib.rs file into subord_crateid that has something in it - writeFile(&package_dir.path().join_many([~"src", subord_crateid.to_str(), ~"lib.rs"]), + writeFile(&package_dir.path().join_many([~"src", + subord_crateid.short_name_with_version(), + ~"lib.rs"]), "pub fn f() {}"); package_dir } @@ -362,19 +362,21 @@ fn assert_executable_exists(repo: &Path, short_name: &str) { } fn executable_exists(repo: &Path, short_name: &str) -> bool { + let crate_id = from_str(short_name).expect("valid crate id"); debug!("executable_exists: repo = {}, short_name = {}", repo.display(), short_name); - let exec = target_executable_in_workspace(&CrateId::new(short_name), repo); + let exec = target_executable_in_workspace(&crate_id, repo); exec.exists() && is_rwx(&exec) } fn test_executable_exists(repo: &Path, short_name: &str) -> bool { + let crate_id = from_str(short_name).expect("valid crate id"); debug!("test_executable_exists: repo = {}, short_name = {}", repo.display(), short_name); - let exec = built_test_in_workspace(&CrateId::new(short_name), repo); + let exec = built_test_in_workspace(&crate_id, repo); exec.map_or(false, |exec| exec.exists() && is_rwx(&exec)) } fn remove_executable_file(p: &CrateId, workspace: &Path) { - let exec = target_executable_in_workspace(&CrateId::new(p.short_name), workspace); + let exec = target_executable_in_workspace(p, workspace); if exec.exists() { fs::unlink(&exec); } @@ -387,7 +389,8 @@ fn assert_built_executable_exists(repo: &Path, short_name: &str) { fn built_executable_exists(repo: &Path, short_name: &str) -> bool { debug!("assert_built_executable_exists: repo = {}, short_name = {}", repo.display(), short_name); - let exec = built_executable_in_workspace(&CrateId::new(short_name), repo); + let crate_id = from_str(short_name).expect("valid crate id"); + let exec = built_executable_in_workspace(&crate_id, repo); exec.is_some() && { let execname = exec.get_ref(); execname.exists() && is_rwx(execname) @@ -395,7 +398,7 @@ fn built_executable_exists(repo: &Path, short_name: &str) -> bool { } fn remove_built_executable_file(p: &CrateId, workspace: &Path) { - let exec = built_executable_in_workspace(&CrateId::new(p.short_name), workspace); + let exec = built_executable_in_workspace(p, workspace); match exec { Some(r) => fs::unlink(&r), None => () @@ -430,7 +433,8 @@ fn assert_built_library_exists(repo: &Path, short_name: &str) { fn built_library_exists(repo: &Path, short_name: &str) -> bool { debug!("assert_built_library_exists: repo = {}, short_name = {}", repo.display(), short_name); - let lib = built_library_in_workspace(&CrateId::new(short_name), repo); + let crate_id = from_str(short_name).expect("valid crate id"); + let lib = built_library_in_workspace(&crate_id, repo); lib.is_some() && { let libname = lib.get_ref(); libname.exists() && is_rwx(libname) @@ -465,7 +469,8 @@ fn command_line_test_output_with_env(args: &[~str], env: ~[(~str, ~str)]) -> ~[~ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path { debug!("lib_output_file_name: given {} and short name {}", workspace.display(), short_name); - library_in_workspace(&CrateId::new(short_name), + let crate_id = from_str(short_name).expect("valid crate id"); + library_in_workspace(&crate_id, Build, workspace).expect("lib_output_file_name") } @@ -473,7 +478,7 @@ fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path { #[cfg(target_os = "linux")] fn touch_source_file(workspace: &Path, crateid: &CrateId) { use conditions::bad_path::cond; - let pkg_src_dir = workspace.join_many([~"src", crateid.to_str()]); + let pkg_src_dir = workspace.join_many([~"src", crateid.short_name_with_version()]); let contents = fs::readdir(&pkg_src_dir); for p in contents.iter() { if p.extension_str() == Some("rs") { @@ -493,7 +498,7 @@ fn touch_source_file(workspace: &Path, crateid: &CrateId) { #[cfg(not(target_os = "linux"))] fn touch_source_file(workspace: &Path, crateid: &CrateId) { use conditions::bad_path::cond; - let pkg_src_dir = workspace.join_many([~"src", crateid.to_str()]); + let pkg_src_dir = workspace.join_many([~"src", crateid.short_name_with_version()]); let contents = fs::readdir(&pkg_src_dir); for p in contents.iter() { if p.extension_str() == Some("rs") { @@ -512,7 +517,7 @@ fn touch_source_file(workspace: &Path, crateid: &CrateId) { /// Add a comment at the end fn frob_source_file(workspace: &Path, crateid: &CrateId, filename: &str) { use conditions::bad_path::cond; - let pkg_src_dir = workspace.join_many([~"src", crateid.to_str()]); + let pkg_src_dir = workspace.join_many([~"src", crateid.short_name_with_version()]); let mut maybe_p = None; let maybe_file = pkg_src_dir.join(filename); debug!("Trying to frob {} -- {}", pkg_src_dir.display(), filename); @@ -615,7 +620,7 @@ fn test_install_invalid() { #[test] fn test_install_valid_external() { - let temp_pkg_id = CrateId::new("foo"); + let temp_pkg_id: CrateId = from_str("foo").unwrap(); let (tempdir, _) = mk_temp_workspace(&temp_pkg_id); let temp_workspace = tempdir.path(); command_line_test([~"install", ~"foo"], temp_workspace); @@ -653,7 +658,8 @@ fn test_install_invalid_external() { #[test] fn test_install_git() { let temp_pkg_id = git_repo_pkg(); - let repo = init_git_repo(&temp_pkg_id.path); + let path = Path::new(temp_pkg_id.path.as_slice()); + let repo = init_git_repo(&path); let repo = repo.path(); debug!("repo = {}", repo.display()); let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); @@ -670,10 +676,9 @@ fn test_install_git() { add_git_tag(&repo_subdir, ~"0.1"); // this has the effect of committing the files debug!("test_install_git: calling rustpkg install {} in {}", - temp_pkg_id.path.display(), repo.display()); + temp_pkg_id.path, repo.display()); // should have test, bench, lib, and main - // FIXME (#9639): This needs to handle non-utf8 paths - command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo); + command_line_test([~"install", temp_pkg_id.path.to_owned()], repo); let ws = repo.join(".rust"); // Check that all files exist debug!("Checking for files in {}", ws.display()); @@ -702,8 +707,6 @@ fn test_install_git() { #[test] fn test_crate_ids_must_be_relative_path_like() { - use conditions::bad_pkg_id::cond; - /* Okay: - One identifier, with no slashes @@ -715,32 +718,16 @@ fn test_crate_ids_must_be_relative_path_like() { */ - let whatever = CrateId::new("foo"); + let foo: CrateId = from_str("foo").unwrap(); + assert_eq!(~"foo#0.0", foo.to_str()); + let test_pkg: CrateId = from_str("github.com/catamorphism/test-pkg").unwrap(); + assert_eq!(~"github.com/catamorphism/test-pkg#0.0", test_pkg.to_str()); - assert_eq!(~"foo-0.0", whatever.to_str()); - assert!("github.com/catamorphism/test-pkg-0.0" == - CrateId::new("github.com/catamorphism/test-pkg").to_str()); - - cond.trap(|(p, e)| { - assert!(p.filename().is_none()); - assert!("bad crateid" == e); - whatever.clone() - }).inside(|| { - let x = CrateId::new(""); - assert_eq!(~"foo-0.0", x.to_str()); - }); + let x: Option = from_str(""); + assert_eq!(x, None); - cond.trap(|(p, e)| { - let abs = os::make_absolute(&Path::new("foo/bar/quux")); - assert_eq!(p, abs); - assert!("bad crateid" == e); - whatever.clone() - }).inside(|| { - let zp = os::make_absolute(&Path::new("foo/bar/quux")); - // FIXME (#9639): This needs to handle non-utf8 paths - let z = CrateId::new(zp.as_str().unwrap()); - assert_eq!(~"foo-0.0", z.to_str()); - }) + let z: Option = from_str("/foo/bar/quux"); + assert_eq!(z, None); } #[test] @@ -765,7 +752,8 @@ fn test_package_request_version() { command_line_test([~"install", format!("{}\\#0.3", local_path)], repo); - assert!(match installed_library_in_workspace(&CrateId::new(format!("{}\\#0.3", local_path)), + let crate_id = from_str(format!("{}\\#0.3", local_path)).unwrap(); + assert!(match installed_library_in_workspace(&crate_id, &repo.join(".rust")) { Some(p) => { debug!("installed: {}", p.display()); @@ -774,7 +762,7 @@ fn test_package_request_version() { } None => false }); - let temp_pkg_id = CrateId::new("mockgithub.com/catamorphism/test_pkg_version#0.3"); + let temp_pkg_id = from_str("mockgithub.com/catamorphism/test_pkg_version#0.3").unwrap(); assert!(target_executable_in_workspace(&temp_pkg_id, &repo.join(".rust")) == repo.join_many([".rust", "bin", "test_pkg_version"])); @@ -812,12 +800,14 @@ fn rustpkg_library_target() { add_git_tag(&package_dir, ~"0.0"); command_line_test([~"install", ~"foo"], foo_repo); - assert_lib_exists(&foo_repo.join(".rust"), &CrateId::new("foo")); + let crate_id: CrateId = from_str("foo").unwrap(); + assert_lib_exists(&foo_repo.join(".rust"), &crate_id); } #[test] fn rustpkg_local_pkg() { - let dir = create_local_package(&CrateId::new("foo")); + let crate_id: CrateId = from_str("foo").unwrap(); + let dir = create_local_package(&crate_id); command_line_test([~"install", ~"foo"], dir.path()); assert_executable_exists(dir.path(), "foo"); } @@ -825,7 +815,8 @@ fn rustpkg_local_pkg() { #[test] #[ignore(reason="busted")] fn package_script_with_default_build() { - let dir = create_local_package(&CrateId::new("fancy-lib")); + let crate_id: CrateId = from_str("fancy-lib").unwrap(); + let dir = create_local_package(&crate_id); let dir = dir.path(); debug!("dir = {}", dir.display()); let mut source = test_sysroot().dir_path(); @@ -835,7 +826,7 @@ fn package_script_with_default_build() { debug!("package_script_with_default_build: {}", source.display()); fs::copy(&source, &dir.join_many(["src", "fancy-lib-0.0", "pkg.rs"])); command_line_test([~"install", ~"fancy-lib"], dir); - assert_lib_exists(dir, &CrateId::new("fancy-lib")); + assert_lib_exists(dir, &crate_id); assert!(target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]).exists()); let generated_path = target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]); debug!("generated path = {}", generated_path.display()); @@ -866,7 +857,8 @@ fn rustpkg_install_no_arg() { "fn main() { let _x = (); }"); debug!("install_no_arg: dir = {}", package_dir.display()); command_line_test([~"install"], &package_dir); - assert_lib_exists(&tmp, &CrateId::new("foo")); + let crate_id: CrateId = from_str("foo").unwrap(); + assert_lib_exists(&tmp, &crate_id); } #[test] @@ -882,14 +874,16 @@ fn rustpkg_clean_no_arg() { command_line_test([~"build"], &package_dir); assert_built_executable_exists(&tmp, "foo"); command_line_test([~"clean"], &package_dir); - let res = built_executable_in_workspace(&CrateId::new("foo"), &tmp); + let crate_id: CrateId = from_str("foo").unwrap(); + let res = built_executable_in_workspace(&crate_id, &tmp); assert!(!res.as_ref().map_or(false, |m| m.exists())); } #[test] fn rust_path_test() { let dir_for_path = TempDir::new("more_rust").expect("rust_path_test failed"); - let dir = mk_workspace(dir_for_path.path(), &CrateId::new("foo")); + let crate_id: CrateId = from_str("foo").unwrap(); + let dir = mk_workspace(dir_for_path.path(), &crate_id); debug!("dir = {}", dir.display()); writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }"); @@ -940,11 +934,11 @@ fn rust_path_parse() { fn test_list() { let dir = TempDir::new("test_list").expect("test_list failed"); let dir = dir.path(); - let foo = CrateId::new("foo"); + let foo: CrateId = from_str("foo").unwrap(); create_local_package_in(&foo, dir); - let bar = CrateId::new("bar"); + let bar: CrateId = from_str("bar").unwrap(); create_local_package_in(&bar, dir); - let quux = CrateId::new("quux"); + let quux: CrateId = from_str("quux").unwrap(); create_local_package_in(&quux, dir); // list doesn't output very much right now... @@ -970,9 +964,9 @@ fn test_list() { fn install_remove() { let dir = TempDir::new("install_remove").expect("install_remove"); let dir = dir.path(); - let foo = CrateId::new("foo"); - let bar = CrateId::new("bar"); - let quux = CrateId::new("quux"); + let foo: CrateId = from_str("foo").unwrap(); + let bar: CrateId = from_str("bar").unwrap(); + let quux: CrateId = from_str("quux").unwrap(); create_local_package_in(&foo, dir); create_local_package_in(&bar, dir); create_local_package_in(&quux, dir); @@ -999,7 +993,7 @@ fn install_check_duplicates() { // check invariant that there are no dups in the pkg database let dir = TempDir::new("install_remove").expect("install_remove"); let dir = dir.path(); - let foo = CrateId::new("foo"); + let foo: CrateId = from_str("foo").unwrap(); create_local_package_in(&foo, dir); command_line_test([~"install", ~"foo"], dir); @@ -1007,7 +1001,7 @@ fn install_check_duplicates() { let mut contents = ~[]; let check_dups = |p: &CrateId| { if contents.contains(p) { - fail!("package {} appears in `list` output more than once", p.path.display()); + fail!("package {} appears in `list` output more than once", p.path); } else { contents.push((*p).clone()); @@ -1019,7 +1013,7 @@ fn install_check_duplicates() { #[test] fn no_rebuilding() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); command_line_test([~"build", ~"foo"], workspace); @@ -1040,7 +1034,7 @@ fn no_rebuilding() { #[test] #[ignore] fn no_recopying() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); command_line_test([~"install", ~"foo"], workspace); @@ -1059,8 +1053,8 @@ fn no_recopying() { #[test] fn no_rebuilding_dep() { - let p_id = CrateId::new("foo"); - let dep_id = CrateId::new("bar"); + let p_id: CrateId = from_str("foo").unwrap(); + let dep_id: CrateId = from_str("bar").unwrap(); let workspace = create_local_package_with_dep(&p_id, &dep_id); let workspace = workspace.path(); command_line_test([~"build", ~"foo"], workspace); @@ -1078,8 +1072,8 @@ fn no_rebuilding_dep() { #[test] fn do_rebuild_dep_dates_change() { - let p_id = CrateId::new("foo"); - let dep_id = CrateId::new("bar"); + let p_id: CrateId = from_str("foo").unwrap(); + let dep_id: CrateId = from_str("bar").unwrap(); let workspace = create_local_package_with_dep(&p_id, &dep_id); let workspace = workspace.path(); command_line_test([~"build", ~"foo"], workspace); @@ -1098,8 +1092,8 @@ fn do_rebuild_dep_dates_change() { #[test] fn do_rebuild_dep_only_contents_change() { - let p_id = CrateId::new("foo"); - let dep_id = CrateId::new("bar"); + let p_id: CrateId = from_str("foo").unwrap(); + let dep_id: CrateId = from_str("bar").unwrap(); let workspace = create_local_package_with_dep(&p_id, &dep_id); let workspace = workspace.path(); command_line_test([~"build", ~"foo"], workspace); @@ -1119,8 +1113,10 @@ fn do_rebuild_dep_only_contents_change() { #[test] fn test_versions() { - let workspace = create_local_package(&CrateId::new("foo#0.1")); - let _other_workspace = create_local_package(&CrateId::new("foo#0.2")); + let foo_01: CrateId = from_str("foo#0.1").unwrap(); + let foo_02: CrateId = from_str("foo#0.2").unwrap(); + let workspace = create_local_package(&foo_01); + let _other_workspace = create_local_package(&foo_02); command_line_test([~"install", ~"foo#0.1"], workspace.path()); let output = command_line_test_output([~"list"]); // make sure output includes versions @@ -1130,7 +1126,8 @@ fn test_versions() { #[test] #[ignore(reason = "do not yet implemented")] fn test_build_hooks() { - let workspace = create_local_package_with_custom_build_hook(&CrateId::new("foo"), + let crate_id: CrateId = from_str("foo").unwrap(); + let workspace = create_local_package_with_custom_build_hook(&crate_id, "frob"); command_line_test([~"do", ~"foo", ~"frob"], workspace.path()); } @@ -1140,14 +1137,16 @@ fn test_build_hooks() { #[ignore(reason = "info not yet implemented")] fn test_info() { let expected_info = ~"package foo"; // fill in - let workspace = create_local_package(&CrateId::new("foo")); + let crate_id: CrateId = from_str("foo").unwrap(); + let workspace = create_local_package(&crate_id); let output = command_line_test([~"info", ~"foo"], workspace.path()); assert_eq!(str::from_utf8_owned(output.output).unwrap(), expected_info); } #[test] fn test_uninstall() { - let workspace = create_local_package(&CrateId::new("foo")); + let crate_id: CrateId = from_str("foo").unwrap(); + let workspace = create_local_package(&crate_id); command_line_test([~"uninstall", ~"foo"], workspace.path()); let output = command_line_test([~"list"], workspace.path()); assert!(!str::from_utf8(output.output).unwrap().contains("foo")); @@ -1156,7 +1155,7 @@ fn test_uninstall() { #[test] fn test_non_numeric_tag() { let temp_pkg_id = git_repo_pkg(); - let repo = init_git_repo(&temp_pkg_id.path); + let repo = init_git_repo(&Path::new(temp_pkg_id.path.as_slice())); let repo = repo.path(); let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); writeFile(&repo_subdir.join("foo"), "foo"); @@ -1168,9 +1167,7 @@ fn test_non_numeric_tag() { writeFile(&repo_subdir.join("not_on_testbranch_only"), "bye bye"); add_all_and_commit(&repo_subdir); - // FIXME (#9639): This needs to handle non-utf8 paths - command_line_test([~"install", format!("{}\\#testbranch", - temp_pkg_id.path.as_str().unwrap())], repo); + command_line_test([~"install", format!("{}\\#testbranch", temp_pkg_id.path)], repo); let file1 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "testbranch_only"]); let file2 = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg", "master_only"]); assert!(file1.exists()); @@ -1283,7 +1280,7 @@ fn test_extern_mod_simpler() { #[test] fn test_import_rustpkg() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); writeFile(&workspace.join_many(["src", "foo-0.0", "pkg.rs"]), @@ -1296,7 +1293,7 @@ fn test_import_rustpkg() { #[test] fn test_macro_pkg_script() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); writeFile(&workspace.join_many(["src", "foo-0.0", "pkg.rs"]), @@ -1313,7 +1310,8 @@ fn multiple_workspaces() { // Copy the exact same package into directory B and install it // Set the RUST_PATH to A:B // Make a third package that uses foo, make sure we can build/install it - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); + let bar_p_id: CrateId = from_str("bar").unwrap(); let (a_loc, _pkg_dir) = mk_temp_workspace(&p_id); let (b_loc, _pkg_dir) = mk_temp_workspace(&p_id); let (a_loc, b_loc) = (a_loc.path(), b_loc.path()); @@ -1324,7 +1322,7 @@ fn multiple_workspaces() { // FIXME (#9639): This needs to handle non-utf8 paths let env = Some(~[(~"RUST_PATH", format!("{}:{}", a_loc.as_str().unwrap(), b_loc.as_str().unwrap()))]); - let c_loc = create_local_package_with_dep(&CrateId::new("bar"), &CrateId::new("foo")); + let c_loc = create_local_package_with_dep(&bar_p_id, &p_id); command_line_test_with_env([~"install", ~"bar"], c_loc.path(), env); } @@ -1337,26 +1335,28 @@ fn rust_path_hack_test(hack_flag: bool) { make sure built files for foo are in B make sure nothing gets built into A or A/../build[lib,bin] */ - let p_id = CrateId::new("foo"); - let workspace = create_local_package(&p_id); - let workspace = workspace.path(); - let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); - let dest_workspace = dest_workspace.path(); - let foo_path = workspace.join_many(["src", "foo-0.0"]); - let rust_path = Some(~[(~"RUST_PATH", - format!("{}:{}", - dest_workspace.as_str().unwrap(), - foo_path.as_str().unwrap()))]); - command_line_test_with_env(~[~"install"] + if hack_flag { ~[~"--rust-path-hack"] } else { ~[] } + - ~[~"foo"], dest_workspace, rust_path); - assert_lib_exists(dest_workspace, &CrateId::new("foo")); - assert_executable_exists(dest_workspace, "foo"); - assert_built_library_exists(dest_workspace, "foo"); - assert_built_executable_exists(dest_workspace, "foo"); - assert!(!lib_exists(workspace, &CrateId::new("foo"))); - assert!(!executable_exists(workspace, "foo")); - assert!(!built_library_exists(workspace, "foo")); - assert!(!built_executable_exists(workspace, "foo")); + let p_id: CrateId = from_str("foo").unwrap(); + let bar_p_id: CrateId = from_str("bar").unwrap(); + let workspace = create_local_package(&p_id); + let workspace = workspace.path(); + let dest_workspace = mk_empty_workspace(&bar_p_id, "dest_workspace"); + let dest_workspace = dest_workspace.path(); + let foo_path = workspace.join_many(["src", "foo-0.0"]); + let rust_path = Some(~[(~"RUST_PATH", + format!("{}:{}", + dest_workspace.as_str().unwrap(), + foo_path.as_str().unwrap()))]); + command_line_test_with_env(~[~"install"] + + if hack_flag { ~[~"--rust-path-hack"] } else { ~[] } + ~[~"foo"], + dest_workspace, rust_path); + assert_lib_exists(dest_workspace, &p_id); + assert_executable_exists(dest_workspace, "foo"); + assert_built_library_exists(dest_workspace, "foo"); + assert_built_executable_exists(dest_workspace, "foo"); + assert!(!lib_exists(workspace, &p_id)); + assert!(!executable_exists(workspace, "foo")); + assert!(!built_library_exists(workspace, "foo")); + assert!(!built_executable_exists(workspace, "foo")); } // Notice that this is the only test case where the --rust-path-hack @@ -1382,88 +1382,95 @@ fn test_rust_path_can_contain_package_dirs_without_flag() { #[test] fn rust_path_hack_cwd() { - // Same as rust_path_hack_test, but the CWD is the dir to build out of - let cwd = TempDir::new("foo").expect("rust_path_hack_cwd"); - let cwd = cwd.path().join("foo"); - fs::mkdir_recursive(&cwd, io::UserRWX); - writeFile(&cwd.join("lib.rs"), "pub fn f() { }"); - - let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); - let dest_workspace = dest_workspace.path(); - // FIXME (#9639): This needs to handle non-utf8 paths - let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); - command_line_test_with_env([~"install", ~"--rust-path-hack", ~"foo"], &cwd, rust_path); - debug!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &CrateId::new("foo")); - assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&cwd, &CrateId::new("foo"))); - assert!(!built_library_exists(&cwd, "foo")); + // Same as rust_path_hack_test, but the CWD is the dir to build out of + let cwd = TempDir::new("foo").expect("rust_path_hack_cwd"); + let cwd = cwd.path().join("foo"); + fs::mkdir_recursive(&cwd, io::UserRWX); + writeFile(&cwd.join("lib.rs"), "pub fn f() { }"); + let foo_id: CrateId = from_str("foo").unwrap(); + let bar_id: CrateId = from_str("bar").unwrap(); + + let dest_workspace = mk_empty_workspace(&bar_id, "dest_workspace"); + let dest_workspace = dest_workspace.path(); + // FIXME (#9639): This needs to handle non-utf8 paths + let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); + command_line_test_with_env([~"install", ~"--rust-path-hack", ~"foo"], &cwd, rust_path); + debug!("Checking that foo exists in {}", dest_workspace.display()); + assert_lib_exists(dest_workspace, &foo_id); + assert_built_library_exists(dest_workspace, "foo"); + assert!(!lib_exists(&cwd, &foo_id)); + assert!(!built_library_exists(&cwd, "foo")); } #[test] fn rust_path_hack_multi_path() { - // Same as rust_path_hack_test, but with a more complex package ID - let cwd = TempDir::new("pkg_files").expect("rust_path_hack_cwd"); - let subdir = cwd.path().join_many(["foo", "bar", "quux"]); - fs::mkdir_recursive(&subdir, io::UserRWX); - writeFile(&subdir.join("lib.rs"), "pub fn f() { }"); - let name = ~"foo/bar/quux"; - - let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); - let dest_workspace = dest_workspace.path(); - // FIXME (#9639): This needs to handle non-utf8 paths - let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); - command_line_test_with_env([~"install", ~"--rust-path-hack", name.clone()], &subdir, rust_path); - debug!("Checking that {} exists in {}", name, dest_workspace.display()); - assert_lib_exists(dest_workspace, &CrateId::new("foo/bar/quux")); - assert_built_library_exists(dest_workspace, name); - assert!(!lib_exists(&subdir, &CrateId::new("foo/bar/quux"))); - assert!(!built_library_exists(&subdir, name)); + // Same as rust_path_hack_test, but with a more complex package ID + let cwd = TempDir::new("pkg_files").expect("rust_path_hack_cwd"); + let subdir = cwd.path().join_many(["foo", "bar", "quux"]); + fs::mkdir_recursive(&subdir, io::UserRWX); + writeFile(&subdir.join("lib.rs"), "pub fn f() { }"); + let name = ~"foo/bar/quux"; + let foo_id: CrateId = from_str("foo/bar/quux").unwrap(); + let bar_id: CrateId = from_str("bar").unwrap(); + + let dest_workspace = mk_empty_workspace(&bar_id, "dest_workspace"); + let dest_workspace = dest_workspace.path(); + // FIXME (#9639): This needs to handle non-utf8 paths + let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); + command_line_test_with_env([~"install", ~"--rust-path-hack", name.clone()], &subdir, rust_path); + debug!("Checking that {} exists in {}", name, dest_workspace.display()); + assert_lib_exists(dest_workspace, &foo_id); + assert_built_library_exists(dest_workspace, name); + assert!(!lib_exists(&subdir, &foo_id)); + assert!(!built_library_exists(&subdir, name)); } #[test] fn rust_path_hack_install_no_arg() { - // Same as rust_path_hack_cwd, but making rustpkg infer the pkg id - let cwd = TempDir::new("pkg_files").expect("rust_path_hack_install_no_arg"); - let cwd = cwd.path(); - let source_dir = cwd.join("foo"); - assert!(make_dir_rwx(&source_dir)); - writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); - - let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); - let dest_workspace = dest_workspace.path(); - // FIXME (#9639): This needs to handle non-utf8 paths - let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); - command_line_test_with_env([~"install", ~"--rust-path-hack"], &source_dir, rust_path); - debug!("Checking that foo exists in {}", dest_workspace.display()); - assert_lib_exists(dest_workspace, &CrateId::new("foo")); - assert_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&source_dir, &CrateId::new("foo"))); - assert!(!built_library_exists(cwd, "foo")); + // Same as rust_path_hack_cwd, but making rustpkg infer the pkg id + let cwd = TempDir::new("pkg_files").expect("rust_path_hack_install_no_arg"); + let cwd = cwd.path(); + let source_dir = cwd.join("foo"); + assert!(make_dir_rwx(&source_dir)); + writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); + + let foo_id: CrateId = from_str("foo").unwrap(); + let bar_id: CrateId = from_str("bar").unwrap(); + let dest_workspace = mk_empty_workspace(&bar_id, "dest_workspace"); + let dest_workspace = dest_workspace.path(); + // FIXME (#9639): This needs to handle non-utf8 paths + let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); + command_line_test_with_env([~"install", ~"--rust-path-hack"], &source_dir, rust_path); + debug!("Checking that foo exists in {}", dest_workspace.display()); + assert_lib_exists(dest_workspace, &foo_id); + assert_built_library_exists(dest_workspace, "foo"); + assert!(!lib_exists(&source_dir, &foo_id)); + assert!(!built_library_exists(cwd, "foo")); } #[test] fn rust_path_hack_build_no_arg() { - // Same as rust_path_hack_install_no_arg, but building instead of installing - let cwd = TempDir::new("pkg_files").expect("rust_path_hack_build_no_arg"); - let source_dir = cwd.path().join("foo"); - assert!(make_dir_rwx(&source_dir)); - writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); - - let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); - let dest_workspace = dest_workspace.path(); - // FIXME (#9639): This needs to handle non-utf8 paths - let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); - command_line_test_with_env([~"build", ~"--rust-path-hack"], &source_dir, rust_path); - debug!("Checking that foo exists in {}", dest_workspace.display()); - assert_built_library_exists(dest_workspace, "foo"); - assert!(!built_library_exists(&source_dir, "foo")); + // Same as rust_path_hack_install_no_arg, but building instead of installing + let cwd = TempDir::new("pkg_files").expect("rust_path_hack_build_no_arg"); + let source_dir = cwd.path().join("foo"); + assert!(make_dir_rwx(&source_dir)); + writeFile(&source_dir.join("lib.rs"), "pub fn f() { }"); + + let bar_id: CrateId = from_str("bar").unwrap(); + let dest_workspace = mk_empty_workspace(&bar_id, "dest_workspace"); + let dest_workspace = dest_workspace.path(); + // FIXME (#9639): This needs to handle non-utf8 paths + let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]); + command_line_test_with_env([~"build", ~"--rust-path-hack"], &source_dir, rust_path); + debug!("Checking that foo exists in {}", dest_workspace.display()); + assert_built_library_exists(dest_workspace, "foo"); + assert!(!built_library_exists(&source_dir, "foo")); } #[test] fn rust_path_hack_build_with_dependency() { - let foo_id = CrateId::new("foo"); - let dep_id = CrateId::new("dep"); + let foo_id: CrateId = from_str("foo").unwrap(); + let dep_id: CrateId = from_str("dep").unwrap(); // Tests that when --rust-path-hack is in effect, dependencies get built // into the destination workspace and not the source directory let work_dir = create_local_package(&foo_id); @@ -1488,7 +1495,8 @@ fn rust_path_hack_build_with_dependency() { fn rust_path_install_target() { let dir_for_path = TempDir::new( "source_workspace").expect("rust_path_install_target failed"); - let mut dir = mk_workspace(dir_for_path.path(), &CrateId::new("foo")); + let foo_id: CrateId = from_str("foo").unwrap(); + let mut dir = mk_workspace(dir_for_path.path(), &foo_id); debug!("dir = {}", dir.display()); writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }"); let dir_to_install_to = TempDir::new( @@ -1511,7 +1519,7 @@ fn rust_path_install_target() { #[test] fn sysroot_flag() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); // no-op sysroot setting; I'm not sure how else to test this @@ -1527,7 +1535,7 @@ fn sysroot_flag() { #[test] fn compile_flag_build() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1544,7 +1552,7 @@ fn compile_flag_build() { #[test] fn compile_flag_fail() { // --no-link shouldn't be accepted for install - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1560,7 +1568,7 @@ fn compile_flag_fail() { #[test] fn notrans_flag_build() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let flags_to_test = [~"--no-trans", ~"--parse-only", @@ -1585,7 +1593,7 @@ fn notrans_flag_build() { #[test] fn notrans_flag_fail() { // --no-trans shouldn't be accepted for install - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let flags_to_test = [~"--no-trans", ~"--parse-only", @@ -1600,13 +1608,13 @@ fn notrans_flag_fail() { workspace, None, BAD_FLAG_CODE); assert!(!built_executable_exists(workspace, "foo")); assert!(!object_file_exists(workspace, "foo")); - assert!(!lib_exists(workspace, &CrateId::new("foo"))); + assert!(!lib_exists(workspace, &p_id)); } } #[test] fn dash_S() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1623,7 +1631,7 @@ fn dash_S() { #[test] fn dash_S_fail() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1640,7 +1648,7 @@ fn dash_S_fail() { #[test] fn test_cfg_build() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); // If the cfg flag gets messed up, this won't compile @@ -1659,7 +1667,7 @@ fn test_cfg_build() { #[test] fn test_cfg_fail() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); writeFile(&workspace.join_many(["src", "foo-0.0", "main.rs"]), @@ -1678,7 +1686,7 @@ fn test_cfg_fail() { #[test] fn test_emit_llvm_S_build() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1696,7 +1704,7 @@ fn test_emit_llvm_S_build() { #[test] fn test_emit_llvm_S_fail() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1716,7 +1724,7 @@ fn test_emit_llvm_S_fail() { #[test] fn test_emit_llvm_build() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1735,7 +1743,7 @@ fn test_emit_llvm_build() { #[test] fn test_emit_llvm_fail() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1756,7 +1764,7 @@ fn test_emit_llvm_fail() { #[test] fn test_linker_build() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let matches = getopts([], optgroups()); @@ -1801,7 +1809,7 @@ fn test_build_install_flags_fail() { #[test] fn test_optimized_build() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1842,8 +1850,8 @@ fn crateid_pointing_to_subdir() { fs::mkdir_recursive(&testpkg_dir, io::UserRWX); writeFile(&testpkg_dir.join("main.rs"), - "extern mod foo = \"mockgithub.com/mozilla/some_repo/extras/foo\";\n - extern mod bar = \"mockgithub.com/mozilla/some_repo/extras/bar\";\n + "extern mod foo = \"mockgithub.com/mozilla/some_repo/extras/foo#foo:0.0\";\n + extern mod bar = \"mockgithub.com/mozilla/some_repo/extras/bar#bar:0.0\";\n use foo::f; use bar::g; \n fn main() { f(); g(); }"); @@ -1853,9 +1861,9 @@ fn crateid_pointing_to_subdir() { #[test] fn test_recursive_deps() { - let a_id = CrateId::new("a"); - let b_id = CrateId::new("b"); - let c_id = CrateId::new("c"); + let a_id: CrateId = from_str("a").unwrap(); + let b_id: CrateId = from_str("b").unwrap(); + let c_id: CrateId = from_str("c").unwrap(); let b_workspace = create_local_package_with_dep(&b_id, &c_id); let b_workspace = b_workspace.path(); writeFile(&b_workspace.join_many(["src", "c-0.0", "lib.rs"]), @@ -1872,17 +1880,18 @@ fn test_recursive_deps() { command_line_test_with_env([~"install", ~"a"], a_workspace, environment); - assert_lib_exists(a_workspace, &CrateId::new("a")); - assert_lib_exists(b_workspace, &CrateId::new("b")); - assert_lib_exists(b_workspace, &CrateId::new("c")); + assert_lib_exists(a_workspace, &a_id); + assert_lib_exists(b_workspace, &b_id); + assert_lib_exists(b_workspace, &c_id); } #[test] fn test_install_to_rust_path() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let second_workspace = create_local_package(&p_id); let second_workspace = second_workspace.path(); - let first_workspace = mk_empty_workspace(&CrateId::new("p"), "dest"); + let none_id: CrateId = from_str("p").unwrap(); + let first_workspace = mk_empty_workspace(&none_id, "dest"); let first_workspace = first_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths let rust_path = Some(~[(~"RUST_PATH", @@ -1903,7 +1912,7 @@ fn test_install_to_rust_path() { #[test] fn test_target_specific_build_dir() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1919,7 +1928,7 @@ fn test_target_specific_build_dir() { #[test] fn test_target_specific_install_dir() { - let p_id = CrateId::new("foo"); + let p_id: CrateId = from_str("foo").unwrap(); let workspace = create_local_package(&p_id); let workspace = workspace.path(); let test_sys = test_sysroot(); @@ -1929,7 +1938,7 @@ fn test_target_specific_install_dir() { ~"foo"], workspace); assert!(workspace.join_many([~"lib", host_triple()]).is_dir()); - assert_lib_exists(workspace, &CrateId::new("foo")); + assert_lib_exists(workspace, &p_id); assert!(fs::readdir(&workspace.join("lib")).len() == 1); assert!(workspace.join("bin").is_dir()); assert_executable_exists(workspace, "foo"); @@ -1938,7 +1947,7 @@ fn test_target_specific_install_dir() { #[test] #[ignore(reason = "See #7240")] fn test_dependencies_terminate() { - let b_id = CrateId::new("b"); + let b_id: CrateId = from_str("b").unwrap(); let workspace = create_local_package(&b_id); let workspace = workspace.path(); let b_dir = workspace.join_many(["src", "b-0.0"]); @@ -1951,42 +1960,42 @@ fn test_dependencies_terminate() { #[test] fn install_after_build() { - let b_id = CrateId::new("b"); + let b_id: CrateId = from_str("b").unwrap(); let workspace = create_local_package(&b_id); let workspace = workspace.path(); command_line_test([~"build", ~"b"], workspace); command_line_test([~"install", ~"b"], workspace); - assert_executable_exists(workspace, b_id.short_name); + assert_executable_exists(workspace, b_id.name); assert_lib_exists(workspace, &b_id); } #[test] fn reinstall() { - let b = CrateId::new("b"); + let b: CrateId = from_str("b").unwrap(); let workspace = create_local_package(&b); let workspace = workspace.path(); // 1. Install, then remove executable file, then install again, // and make sure executable was re-installed command_line_test([~"install", ~"b"], workspace); - assert_executable_exists(workspace, b.short_name); + assert_executable_exists(workspace, b.name); assert_lib_exists(workspace, &b); remove_executable_file(&b, workspace); command_line_test([~"install", ~"b"], workspace); - assert_executable_exists(workspace, b.short_name); + assert_executable_exists(workspace, b.name); // 2. Build, then remove build executable file, then build again, // and make sure executable was re-built. command_line_test([~"build", ~"b"], workspace); remove_built_executable_file(&b, workspace); command_line_test([~"build", ~"b"], workspace); - assert_built_executable_exists(workspace, b.short_name); + assert_built_executable_exists(workspace, b.name); // 3. Install, then remove both executable and built executable, // then install again, make sure both were recreated command_line_test([~"install", ~"b"], workspace); remove_executable_file(&b, workspace); remove_built_executable_file(&b, workspace); command_line_test([~"install", ~"b"], workspace); - assert_executable_exists(workspace, b.short_name); - assert_built_executable_exists(workspace, b.short_name); + assert_executable_exists(workspace, b.name); + assert_built_executable_exists(workspace, b.name); } #[test] @@ -2001,11 +2010,11 @@ fn correct_package_name_with_rust_path_hack() { */ // Set RUST_PATH to something containing only the sources for foo - let foo_id = CrateId::new("foo"); - let bar_id = CrateId::new("bar"); + let foo_id: CrateId = from_str("foo").unwrap(); + let bar_id: CrateId = from_str("bar").unwrap(); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); - let dest_workspace = mk_empty_workspace(&CrateId::new("bar"), "dest_workspace"); + let dest_workspace = mk_empty_workspace(&bar_id, "dest_workspace"); let dest_workspace = dest_workspace.path(); writeFile(&dest_workspace.join_many(["src", "bar-0.0", "main.rs"]), @@ -2031,7 +2040,7 @@ fn correct_package_name_with_rust_path_hack() { #[test] fn test_rustpkg_test_creates_exec() { - let foo_id = CrateId::new("foo"); + let foo_id: CrateId = from_str("foo").unwrap(); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); writeFile(&foo_workspace.join_many(["src", "foo-0.0", "test.rs"]), @@ -2042,7 +2051,8 @@ fn test_rustpkg_test_creates_exec() { #[test] fn test_rustpkg_test_output() { - let workspace = create_local_package_with_test(&CrateId::new("foo")); + let foo_id: CrateId = from_str("foo").unwrap(); + let workspace = create_local_package_with_test(&foo_id); let output = command_line_test([~"test", ~"foo"], workspace.path()); let output_str = str::from_utf8(output.output).unwrap(); // The first two assertions are separate because test output may @@ -2054,7 +2064,7 @@ fn test_rustpkg_test_output() { #[test] fn test_rustpkg_test_failure_exit_status() { - let foo_id = CrateId::new("foo"); + let foo_id: CrateId = from_str("foo").unwrap(); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); writeFile(&foo_workspace.join_many(["src", "foo-0.0", "test.rs"]), @@ -2068,7 +2078,7 @@ fn test_rustpkg_test_failure_exit_status() { #[test] fn test_rustpkg_test_cfg() { - let foo_id = CrateId::new("foo"); + let foo_id: CrateId = from_str("foo").unwrap(); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); writeFile(&foo_workspace.join_many(["src", "foo-0.0", "test.rs"]), @@ -2081,7 +2091,7 @@ fn test_rustpkg_test_cfg() { #[test] fn test_rebuild_when_needed() { - let foo_id = CrateId::new("foo"); + let foo_id: CrateId = from_str("foo").unwrap(); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); let test_crate = foo_workspace.join_many(["src", "foo-0.0", "test.rs"]); @@ -2102,7 +2112,7 @@ fn test_rebuild_when_needed() { #[test] #[ignore] // FIXME (#10257): This doesn't work as is since a read only file can't execute fn test_no_rebuilding() { - let foo_id = CrateId::new("foo"); + let foo_id: CrateId = from_str("foo").unwrap(); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); let test_crate = foo_workspace.join_many(["src", "foo-0.0", "test.rs"]); @@ -2124,8 +2134,9 @@ fn test_no_rebuilding() { fn test_installed_read_only() { // Install sources from a "remote" (actually a local github repo) // Check that afterward, sources are read-only and installed under build/ - let mut temp_pkg_id = git_repo_pkg(); - let repo = init_git_repo(&temp_pkg_id.path); + let temp_pkg_id = git_repo_pkg(); + let path = Path::new(temp_pkg_id.path.as_slice()); + let repo = init_git_repo(&path); let repo = repo.path(); debug!("repo = {}", repo.display()); let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); @@ -2137,10 +2148,9 @@ fn test_installed_read_only() { "pub fn f() { let _x = (); }"); add_git_tag(&repo_subdir, ~"0.0"); // this has the effect of committing the files // update crateid to what will be auto-detected - temp_pkg_id.version = Some(~"0.0"); // FIXME (#9639): This needs to handle non-utf8 paths - command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo); + command_line_test([~"install", temp_pkg_id.to_str()], repo); let ws = repo.join(".rust"); // Check that all files exist @@ -2156,8 +2166,10 @@ fn test_installed_read_only() { assert!(is_rwx(&built_lib)); // Make sure sources are (a) under "build" and (b) read-only - let src1 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"main.rs"]); - let src2 = target_build_dir(&ws).join_many([~"src", temp_pkg_id.to_str(), ~"lib.rs"]); + let temp_dir = format!("{}-{}", temp_pkg_id.path, temp_pkg_id.version_or_default()); + let src1 = target_build_dir(&ws).join_many([~"src", temp_dir.clone(), ~"main.rs"]); + let src2 = target_build_dir(&ws).join_many([~"src", temp_dir.clone(), ~"lib.rs"]); + debug!("src1: {}", src1.display()); assert!(src1.exists()); assert!(src2.exists()); assert!(is_read_only(&src1)); @@ -2167,7 +2179,7 @@ fn test_installed_read_only() { #[test] fn test_installed_local_changes() { let temp_pkg_id = git_repo_pkg(); - let repo = init_git_repo(&temp_pkg_id.path); + let repo = init_git_repo(&Path::new(temp_pkg_id.path.as_slice())); let repo = repo.path(); debug!("repo = {}", repo.display()); let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test-pkg"]); @@ -2180,9 +2192,7 @@ fn test_installed_local_changes() { "pub fn f() { let _x = (); }"); add_git_tag(&repo_subdir, ~"0.1"); // this has the effect of committing the files - // FIXME (#9639): This needs to handle non-utf8 paths - command_line_test([~"install", temp_pkg_id.path.as_str().unwrap().to_owned()], repo); - + command_line_test([~"install", temp_pkg_id.path.to_owned()], repo); // We installed the dependency. // Now start a new workspace and clone it into it @@ -2214,14 +2224,13 @@ fn test_installed_local_changes() { fn main() { g(); }"); // And make sure we can build it - // FIXME (#9639): This needs to handle non-utf8 paths - command_line_test([~"build", importer_pkg_id.path.as_str().unwrap().to_owned()], - hacking_workspace); + command_line_test([~"build", importer_pkg_id.path.to_owned()], hacking_workspace); } #[test] fn test_7402() { - let dir = create_local_package(&CrateId::new("foo")); + let foo_id: CrateId = from_str("foo").unwrap(); + let dir = create_local_package(&foo_id); let dest_workspace = TempDir::new("more_rust").expect("test_7402"); let dest_workspace = dest_workspace.path(); // FIXME (#9639): This needs to handle non-utf8 paths @@ -2235,7 +2244,7 @@ fn test_7402() { #[test] fn test_compile_error() { - let foo_id = CrateId::new("foo"); + let foo_id: CrateId = from_str("foo").unwrap(); let foo_workspace = create_local_package(&foo_id); let foo_workspace = foo_workspace.path(); let main_crate = foo_workspace.join_many(["src", "foo-0.0", "main.rs"]); @@ -2269,7 +2278,8 @@ fn test_c_dependency_ok() { // registers a hook to build it if it's not fresh // After running `build`, test that the C library built - let dir = create_local_package(&CrateId::new("cdep")); + let cdep_id: CrateId = from_str("cdep").unwrap(); + let dir = create_local_package(&cdep_id); let dir = dir.path(); writeFile(&dir.join_many(["src", "cdep-0.0", "main.rs"]), "#[link_args = \"-lfoo\"]\nextern { fn f(); } \ @@ -2292,7 +2302,8 @@ fn test_c_dependency_ok() { #[test] #[ignore(reason="busted")] fn test_c_dependency_no_rebuilding() { - let dir = create_local_package(&CrateId::new("cdep")); + let cdep_id: CrateId = from_str("cdep").unwrap(); + let dir = create_local_package(&cdep_id); let dir = dir.path(); writeFile(&dir.join_many(["src", "cdep-0.0", "main.rs"]), "#[link_args = \"-lfoo\"]\nextern { fn f(); } \ @@ -2326,7 +2337,8 @@ fn test_c_dependency_no_rebuilding() { #[test] #[ignore(reason="busted")] fn test_c_dependency_yes_rebuilding() { - let dir = create_local_package(&CrateId::new("cdep")); + let cdep_id: CrateId = from_str("cdep").unwrap(); + let dir = create_local_package(&cdep_id); let dir = dir.path(); writeFile(&dir.join_many(["src", "cdep-0.0", "main.rs"]), "#[link_args = \"-lfoo\"]\nextern { fn f(); } \ @@ -2347,7 +2359,7 @@ fn test_c_dependency_yes_rebuilding() { assert!(c_library_path.exists()); // Now, make the Rust library read-only so rebuilding will fail - match built_library_in_workspace(&CrateId::new("cdep"), dir) { + match built_library_in_workspace(&cdep_id, dir) { Some(ref pth) => assert!(chmod_read_only(pth)), None => assert_built_library_exists(dir, "cdep") } @@ -2365,7 +2377,8 @@ fn test_c_dependency_yes_rebuilding() { fn correct_error_dependency() { // Supposing a package we're trying to install via a dependency doesn't // exist, we should throw a condition, and not ICE - let workspace_dir = create_local_package(&CrateId::new("badpkg")); + let crate_id: CrateId = from_str("badpkg").unwrap(); + let workspace_dir = create_local_package(&crate_id); let dir = workspace_dir.path(); let main_rs = dir.join_many(["src", "badpkg-0.0", "main.rs"]); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 4c2fc98a305a9..9042dfea2562e 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -10,6 +10,10 @@ #[allow(dead_code)]; +pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename}; +pub use target::{Target, Build, Install}; +pub use target::{lib_name_of, lib_crate_filename, WhatToBuild, MaybeCustom, Inferred}; + use std::cell::RefCell; use std::libc; use std::os; @@ -17,7 +21,7 @@ use std::io; use std::io::fs; use extra::workcache; use rustc::metadata::creader::Loader; -use rustc::driver::{driver, session}; +use extra::treemap::TreeMap; use extra::getopts::groups::getopts; use syntax; use syntax::codemap::{DUMMY_SP, Spanned}; @@ -28,19 +32,16 @@ use syntax::attr::AttrMetaMethods; use syntax::fold::Folder; use syntax::visit::Visitor; use syntax::util::small_vector::SmallVector; +use syntax::crateid::CrateId; use rustc::back::link::OutputTypeExe; use rustc::back::link; +use rustc::driver::{driver, session}; use CtxMethods; use context::{in_target, StopBefore, Link, Assemble, BuildContext}; -use crate_id::CrateId; use package_source::PkgSrc; use workspace::pkg_parent_workspaces; use path_util::{system_library, target_build_dir}; use path_util::{default_workspace, built_library_in_workspace}; -pub use target::{OutputType, Main, Lib, Bench, Test, JustOne, lib_name_of, lib_crate_filename}; -pub use target::{Target, Build, Install}; -use extra::treemap::TreeMap; -pub use target::{lib_name_of, lib_crate_filename, WhatToBuild, MaybeCustom, Inferred}; use workcache_support::{digest_file_with_date, digest_only_date}; use messages::error; @@ -177,11 +178,11 @@ pub fn compile_input(context: &BuildContext, // not sure if we should support anything else let mut out_dir = target_build_dir(workspace); - out_dir.push(&crate_id.path); + out_dir.push(crate_id.path.as_slice()); // Make the output directory if it doesn't exist already fs::mkdir_recursive(&out_dir, io::UserRWX); - let binary = os::args()[0].to_owned(); + let binary = os::args()[0]; debug!("flags: {}", flags.connect(" ")); debug!("cfgs: {}", cfgs.connect(" ")); @@ -312,7 +313,7 @@ pub fn compile_input(context: &BuildContext, if !attr::contains_name(crate.attrs, "crate_id") { // FIXME (#9639): This needs to handle non-utf8 paths let crateid_attr = - attr::mk_name_value_item_str(@"crate_id", crate_id.to_crate_id_str().to_managed()); + attr::mk_name_value_item_str(@"crate_id", crate_id.to_str().to_managed()); debug!("crateid attr: {:?}", crateid_attr); crate.attrs.push(attr::mk_attr(crateid_attr)); @@ -441,7 +442,7 @@ pub fn compile_crate(ctxt: &BuildContext, opt: session::OptLevel, what: OutputType) -> Option { debug!("compile_crate: crate={}, workspace={}", crate.display(), workspace.display()); - debug!("compile_crate: short_name = {}, flags =...", crate_id.to_str()); + debug!("compile_crate: name = {}, flags =...", crate_id.to_str()); for fl in flags.iter() { debug!("+++ {}", *fl); } @@ -470,8 +471,9 @@ impl<'a> CrateInstaller<'a> { None => self.sess.str_of(lib_ident) }; debug!("Finding and installing... {}", lib_name); + let crate_id: CrateId = from_str(lib_name).expect("valid crate id"); // Check standard Rust library path first - let whatever = system_library(&self.context.sysroot_to_use(), lib_name); + let whatever = system_library(&self.context.sysroot_to_use(), &crate_id); debug!("system library returned {:?}", whatever); match whatever { Some(ref installed_path) => { @@ -491,10 +493,8 @@ impl<'a> CrateInstaller<'a> { } None => { // FIXME #8711: need to parse version out of path_opt - debug!("Trying to install library {}, rebuilding it", - lib_name.to_str()); + debug!("Trying to install library {}, rebuilding it", crate_id.to_str()); // Try to install it - let crate_id = CrateId::new(lib_name); // Find all the workspaces in the RUST_PATH that contain this package. let workspaces = pkg_parent_workspaces(&self.context.context, &crate_id); @@ -526,8 +526,8 @@ impl<'a> CrateInstaller<'a> { // Nonexistent package? Then print a better error error(format!("Package {} depends on {}, but I don't know \ how to find it", - self.parent.path.display(), - crate_id.path.display())); + self.parent.path, + crate_id.path)); fail!() }).inside(|| { PkgSrc::new(source_workspace.clone(), diff --git a/src/librustpkg/workspace.rs b/src/librustpkg/workspace.rs index d6e617d2d5071..e19a19dc8ab6a 100644 --- a/src/librustpkg/workspace.rs +++ b/src/librustpkg/workspace.rs @@ -11,12 +11,11 @@ // rustpkg utilities having to do with workspaces use std::os; -use std::path::Path; use context::Context; use path_util::{workspace_contains_crate_id, find_dir_using_rust_path_hack, default_workspace}; use path_util::rust_path; use util::option_to_vec; -use crate_id::CrateId; +use syntax::crateid::CrateId; pub fn each_pkg_parent_workspace(cx: &Context, crateid: &CrateId, @@ -29,7 +28,7 @@ pub fn each_pkg_parent_workspace(cx: &Context, // tjc: make this a condition fail!("Package {} not found in any of \ the following workspaces: {}", - crateid.path.display(), + crateid.path, rust_path().map(|p| p.display().to_str()).to_str()); } for ws in workspaces.iter() { @@ -64,7 +63,8 @@ pub fn cwd_to_workspace() -> Option<(Path, CrateId)> { let rel = cwd.path_relative_from(&srcpath); let rel_s = rel.as_ref().and_then(|p|p.as_str()); if rel_s.is_some() { - return Some((path, CrateId::new(rel_s.unwrap()))); + let crate_id = from_str(rel_s.unwrap()).expect("valid crate id"); + return Some((path, crate_id)); } } } diff --git a/src/libsyntax/crateid.rs b/src/libsyntax/crateid.rs index 0bb1eec512bf7..0831f319ce7b9 100644 --- a/src/libsyntax/crateid.rs +++ b/src/libsyntax/crateid.rs @@ -70,7 +70,11 @@ impl FromStr for CrateId { }; let version = if !hash_version.is_empty() { - Some(hash_version.to_owned()) + if hash_version == "0.0" { + None + } else { + Some(hash_version.to_owned()) + } } else { None }; @@ -93,6 +97,10 @@ impl CrateId { Some(ref version) => version.as_slice(), } } + + pub fn short_name_with_version(&self) -> ~str { + format!("{}-{}", self.name, self.version_or_default()) + } } #[test]