diff --git a/src/librustpkg/api.rs b/src/librustpkg/api.rs index 19586ac48b0..13d5a117704 100644 --- a/src/librustpkg/api.rs +++ b/src/librustpkg/api.rs @@ -11,11 +11,9 @@ use CtxMethods; use context::*; use crate::*; -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; @@ -27,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")] @@ -79,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: Version, - 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: Version, 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: ~[], @@ -102,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: Version, - 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: Version, 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)], @@ -129,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: Version, // 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 }); @@ -157,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() }); @@ -190,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 6c38d63a518..d18161d7c4a 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 239abbe546f..00000000000 --- a/src/librustpkg/crate_id.rs +++ /dev/null @@ -1,150 +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 version::{try_getting_version, try_getting_local_version, - Version, NoVersion, ExactRevision}; -use std::hash::Streaming; -use std::hash; -use syntax::crateid; - -/// Path-fragment identifier of a package such as -/// 'github.com/graydon/test'; path must be a relative -/// 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: Version -} - -impl Eq for CrateId { - fn eq(&self, other: &CrateId) -> bool { - self.path == other.path && self.version == other.version - } -} - -impl CrateId { - 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); - 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 - } - } - }; - - CrateId { - path: path, - short_name: name, - version: version - } - } - - 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(); - format!("{}-{}-{}", s, hash(s + vers), vers) - }) - } - - pub fn short_name_with_version(&self) -> ~str { - format!("{}{}", self.short_name, self.version.to_str()) - } - - /// 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.to_str()) - } -} - - -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/installed_packages.rs b/src/librustpkg/installed_packages.rs index 67ba5d2b8e8..c7900181a77 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 c9db8af0b8a..e5e494e9b5f 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()); @@ -163,7 +162,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,9 +241,9 @@ 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 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 { @@ -270,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", @@ -289,6 +287,7 @@ impl CtxMethods for BuildContext { Some((crateid, dest_ws)) } } + fn run(&self, cmd: Command, args: ~[~str]) { let cwd = os::getcwd(); match cmd { @@ -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 651d64aa9d3..5ac62c5284e 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(format!("{}-{}", id.short_name, id.version.to_str())); + 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(format!("{}-{}", id.short_name, id.version.to_str())); + 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,26 +295,27 @@ 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.to_str()); + url, clone_target.display(), crateid.version_or_default()); let mut failed = false; @@ -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 3c91e660784..a0d49e7565f 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -12,19 +12,20 @@ #[allow(dead_code)]; -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, - try_parsing_version}; +pub use version::{Version, split_version_general}; 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 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::*; pub fn default_workspace() -> Path { @@ -78,14 +79,14 @@ 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 - && (crateid.version == *vers || crateid.version == NoVersion) + *might_match == crateid.name + && (crateid.version == *vers || crateid.version == None) } } }) @@ -173,151 +174,63 @@ 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() { + let path = Path::new(crate_id.path.as_slice()); + match path.filename_str() { None => None, - Some(short_name) => library_in_workspace(pkg_path, - short_name, - Install, - workspace, - libdir(), - &NoVersion) + 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 { +/// `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", - 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.name); let dir_to_search = match where { - Build => target_build_dir(workspace).join(path), + Build => target_build_dir(workspace).join(crate_id.path.as_slice()), 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()))) +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(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()); +fn library_in(crate_id: &CrateId, dir_to_search: &Path) -> Option { + 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 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"; + 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), + ]; - 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, + 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 == found_vers => { - 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 + debug!("warning: library_in_workspace didn't find a library in {} for {}", + dir_to_search.display(), crate_id.to_str()); + return None; } -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())) - }, - _ => (name, vers) - }, - None => (crate_id, NoVersion) - } -} - - - /// Returns the executable that would be installed for /// in /// As a side effect, creates the bin-dir if it doesn't exist @@ -366,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) }; @@ -382,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); @@ -392,25 +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 = format!("{}-{}", pkg_id.short_name, - pkg_id.version.to_str()); + 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", @@ -457,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()); @@ -483,11 +396,12 @@ 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); - 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 4b7aaf7e340..2346749feb5 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 c0b4a246d35..bf8ec1e738c 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -20,13 +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 version::{ExactRevision, NoVersion, Version}; +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, @@ -59,19 +58,18 @@ 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, - version: NoVersion + path: ~"bogus", + name: ~"bogus", + version: None } } fn git_repo_pkg() -> CrateId { CrateId { - path: Path::new("mockgithub.com/catamorphism/test-pkg"), - short_name: ~"test-pkg", - version: NoVersion + path: ~"mockgithub.com/catamorphism/test-pkg", + name: ~"test-pkg", + version: None } } @@ -88,28 +86,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()); @@ -278,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 { @@ -294,7 +285,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 @@ -302,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); @@ -330,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 } @@ -348,13 +343,13 @@ fn create_local_package_with_custom_build_hook(crateid: &CrateId, } -fn assert_lib_exists(repo: &Path, pkg_path: &Path, v: Version) { - 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: Version) -> 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(); @@ -367,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); } @@ -392,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) @@ -400,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 => () @@ -435,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) @@ -470,18 +469,16 @@ 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, + let crate_id = from_str(short_name).expect("valid crate id"); + library_in_workspace(&crate_id, Build, - workspace, - "build", - &NoVersion).expect("lib_output_file_name") + workspace).expect("lib_output_file_name") } #[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") { @@ -501,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") { @@ -520,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); @@ -567,7 +564,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()); @@ -583,7 +580,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))); @@ -623,9 +620,8 @@ 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 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); @@ -635,7 +631,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))); @@ -662,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"]); @@ -679,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()); @@ -693,7 +689,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()); @@ -711,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 @@ -724,72 +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()); + let x: Option = from_str(""); + assert_eq!(x, None); - 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()); - }); - - 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()); - }) -} - -#[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"]))); + let z: Option = from_str("/foo/bar/quux"); + assert_eq!(z, None); } #[test] @@ -814,7 +752,8 @@ 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"), + 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()); @@ -823,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"])); @@ -858,15 +797,17 @@ 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"), ExactRevision(~"1.0")); + 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"); } @@ -874,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(); @@ -884,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, &Path::new("fancy-lib"), NoVersion); + 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()); @@ -915,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, &Path::new("foo"), NoVersion); + let crate_id: CrateId = from_str("foo").unwrap(); + assert_lib_exists(&tmp, &crate_id); } #[test] @@ -931,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(), &Path::new("foo"), &NoVersion); + 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 = (); }"); @@ -989,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... @@ -1019,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); @@ -1048,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); @@ -1056,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()); @@ -1068,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); @@ -1089,11 +1034,11 @@ 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); - 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())); @@ -1108,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); @@ -1127,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); @@ -1147,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); @@ -1168,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 @@ -1179,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()); } @@ -1189,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")); @@ -1205,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"); @@ -1217,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()); @@ -1332,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"]), @@ -1345,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"]), @@ -1362,8 +1310,10 @@ 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 = 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()); debug!("Trying to install foo in {}", a_loc.display()); command_line_test([~"install", ~"foo"], a_loc); @@ -1372,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); } @@ -1385,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(&Path::new("bar"), &NoVersion, "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, &Path::new("foo"), NoVersion); - 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!(!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 @@ -1430,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() { }"); + // 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(&Path::new("bar"), &NoVersion, "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_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&cwd, &Path::new("foo"), NoVersion)); - assert!(!built_library_exists(&cwd, "foo")); + 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"; + // 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(&Path::new("bar"), &NoVersion, "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_built_library_exists(dest_workspace, name); - assert!(!lib_exists(&subdir, &Path::new("quux"), NoVersion)); - assert!(!built_library_exists(&subdir, name)); + 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() { }"); + // 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(&Path::new("bar"), &NoVersion, "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_built_library_exists(dest_workspace, "foo"); - assert!(!lib_exists(&source_dir, &Path::new("foo"), NoVersion)); - assert!(!built_library_exists(cwd, "foo")); + 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() { }"); + // 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(&Path::new("bar"), &NoVersion, "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")); + 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); @@ -1536,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(), &Path::new("foo"), &NoVersion); + 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( @@ -1559,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 @@ -1575,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(); @@ -1592,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(); @@ -1608,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", @@ -1633,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", @@ -1648,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, &Path::new("foo"), NoVersion)); + 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(); @@ -1671,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(); @@ -1688,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 @@ -1707,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"]), @@ -1726,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(); @@ -1744,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(); @@ -1764,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(); @@ -1783,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(); @@ -1804,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()); @@ -1849,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(); @@ -1879,10 +1839,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()); @@ -1890,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(); }"); @@ -1901,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"]), @@ -1920,17 +1880,18 @@ 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, &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(&Path::new("p"), &NoVersion, "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", @@ -1951,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(); @@ -1967,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(); @@ -1977,7 +1938,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, &p_id); assert!(fs::readdir(&workspace.join("lib")).len() == 1); assert!(workspace.join("bin").is_dir()); assert_executable_exists(workspace, "foo"); @@ -1986,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"]); @@ -1999,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_lib_exists(workspace, &b_id.path, NoVersion); + 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_lib_exists(workspace, &b.path, NoVersion); + 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] @@ -2049,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(&Path::new("bar"), &NoVersion, "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"]), @@ -2068,18 +2029,18 @@ 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] 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"]), @@ -2090,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 @@ -2102,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"]), @@ -2116,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"]), @@ -2129,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"]); @@ -2150,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"]); @@ -2172,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"]); @@ -2183,12 +2146,11 @@ 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"); // 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 @@ -2204,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)); @@ -2215,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"]); @@ -2228,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 @@ -2242,7 +2204,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"), @@ -2262,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 @@ -2283,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"]); @@ -2317,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(); } \ @@ -2340,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(); } \ @@ -2374,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(); } \ @@ -2395,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") } @@ -2413,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/testsuite/pass/src/c-dependencies/pkg.rs b/src/librustpkg/testsuite/pass/src/c-dependencies/pkg.rs index b6c5e15c09a..b6dba40ebd4 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 4a107de55a5..7b1291025e4 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 4d8f5c668b7..9042dfea256 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; @@ -135,7 +136,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 +163,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,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(&pkg_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(" ")); @@ -276,7 +277,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 +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", - format!("{}\\#{}", - pkg_id.path.as_str().unwrap(), - pkg_id.version.to_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)); @@ -333,7 +331,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 +433,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 +442,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: 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> { @@ -473,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) => { @@ -494,13 +493,11 @@ 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 pkg_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 @@ -529,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(), - pkg_id.path.display())); + self.parent.path, + crate_id.path)); 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( diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index 77dbb335518..93e7a052efa 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -13,170 +13,9 @@ extern mod std; -use extra::semver; -use std::{char, result, run, str}; -use extra::tempfile::TempDir; -use path_util::rust_path; +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") - } -} - -/// 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 - } -} +pub type Version = Option<~str>; // Being lazy since we don't have a regexp library now #[deriving(Eq)] @@ -186,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; @@ -202,17 +41,11 @@ pub fn try_parsing_version(s: &str) -> Option { } } match parse_state { - SawDigit => Some(ExactRevision(s.to_owned())), + SawDigit => Some(s.to_owned()), _ => None } } -/// 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. @@ -229,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 @@ -239,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); } @@ -252,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); } diff --git a/src/librustpkg/workspace.rs b/src/librustpkg/workspace.rs index d6e617d2d50..e19a19dc8ab 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 0bb1eec512b..0831f319ce7 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]