"docopt_macros 0.6.0 (git+https://github.com/burntsushi/docopt.rs#fd2377d1c36b2671136cd36566aad5d54c2fb17e)",
"hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git#c23b8769f20f306c59a96b22532bb09b33faa764)",
"semver 0.0.1 (git+https://github.com/rust-lang/semver#e17191f51d543529a6f07e6731802b77977fcef8)",
- "toml 0.1.0 (git+https://github.com/alexcrichton/toml-rs#7e1c1e127d952066bda5fbc94e3cbdb40e912119)",
- "url 0.1.0 (git+https://github.com/servo/rust-url#3d54552e06062835edf8b8e3a8664272e2fdab61)",
+ "toml 0.1.0 (git+https://github.com/alexcrichton/toml-rs#934e093047ae15432fcc772d4e01fdf5fd56d2fb)",
+ "url 0.1.0 (git+https://github.com/servo/rust-url#ad61773abc56d812f8abe4bc78833f422a5f6a94)",
]
[[package]]
[[package]]
name = "encoding"
version = "0.1.0"
-source = "git+https://github.com/lifthrasiir/rust-encoding#12b6610adff6eddc060691888c36017cd3ad57f7"
+source = "git+https://github.com/lifthrasiir/rust-encoding#eae7c261f50cfbdc699e9b234d2b13d4d255fd42"
[[package]]
name = "hamcrest"
[[package]]
name = "toml"
version = "0.1.0"
-source = "git+https://github.com/alexcrichton/toml-rs#7e1c1e127d952066bda5fbc94e3cbdb40e912119"
+source = "git+https://github.com/alexcrichton/toml-rs#934e093047ae15432fcc772d4e01fdf5fd56d2fb"
[[package]]
name = "url"
version = "0.1.0"
-source = "git+https://github.com/servo/rust-url#3d54552e06062835edf8b8e3a8664272e2fdab61"
+source = "git+https://github.com/servo/rust-url#ad61773abc56d812f8abe4bc78833f422a5f6a94"
dependencies = [
- "encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#12b6610adff6eddc060691888c36017cd3ad57f7)",
+ "encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#eae7c261f50cfbdc699e9b234d2b13d4d255fd42)",
]
use cargo::core::MultiShell;
use cargo::core::source::{Source, SourceId};
use cargo::sources::git::{GitSource};
-use cargo::util::{Config, CliResult, CliError, human};
-use url::Url;
+use cargo::util::{Config, CliResult, CliError, human, ToUrl};
docopt!(Options, "
Usage:
fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
let Options { flag_url: url, flag_reference: reference, .. } = options;
- let url: Url = try!(Url::parse(url.as_slice()).map_err(|e| {
- human(format!("The URL `{}` you passed was \
- not a valid URL: {}", url, e))
- })
- .map_err(|e| CliError::from_boxed(e, 1)));
+ let url = try!(url.as_slice().to_url().map_err(|e| {
+ human(format!("The URL `{}` you passed was \
+ not a valid URL: {}", url, e))
+ })
+ .map_err(|e| CliError::from_boxed(e, 1)));
let source_id = SourceId::for_git(&url, reference.as_slice(), None);
fn execute(options: Options, _: &mut MultiShell) -> CliResult<Option<Package>> {
let path = Path::new(options.flag_manifest_path.as_slice());
- let mut source = PathSource::for_path(&path);
+ let mut source = try!(PathSource::for_path(&path).map_err(|e| {
+ CliError::new(e.description(), 1)
+ }));
try!(source.update().map_err(|err| CliError::new(err.description(), 1)));
}
}
-//impl<D: Decoder<Box<CargoError + Send>>>
- //Decodable<D,Box<CargoError + Send>>
- //for PackageId
-//{
- //fn decode(d: &mut D) -> CargoResult<PackageId> {
- //let (name, version, source_id): (String, String, SourceId) = try!(Decodable::decode(d));
-
- //PackageId::new(name.as_slice(), version.as_slice(), &source_id)
- //}
-//}
-
-//impl<E, S: Encoder<E>> Encodable<S,E> for PackageId {
- //fn encode(&self, e: &mut S) -> Result<(), E> {
- //(self.name.clone(), self.version.to_string(), self.source_id.clone()).encode(e)
- //}
-//}
-
#[cfg(test)]
mod tests {
use super::{PackageId, central_repo};
- use core::source::{Location, RegistryKind, SourceId};
+ use core::source::{RegistryKind, SourceId};
+ use util::ToUrl;
#[test]
fn invalid_version_handled_nicely() {
- let loc = Location::parse(central_repo).unwrap();
+ let loc = central_repo.to_url().unwrap();
let repo = SourceId::new(RegistryKind, loc);
assert!(PackageId::new("foo", "1.0", &repo).is_err());
mod test {
use hamcrest::{assert_that, equal_to, contains};
- use core::source::{SourceId, RegistryKind, GitKind, Location, Remote};
+ use core::source::{SourceId, RegistryKind, GitKind};
use core::{Dependency, PackageId, Summary, Registry};
use util::{CargoResult, ToUrl};
impl ToDep for &'static str {
fn to_dep(self) -> Dependency {
let url = "http://example.com".to_url().unwrap();
- let source_id = SourceId::new(RegistryKind, Remote(url));
+ let source_id = SourceId::new(RegistryKind, url);
Dependency::parse(self, Some("1.0.0"), &source_id).unwrap()
}
}
)
fn registry_loc() -> SourceId {
- let remote = Location::parse("http://example.com").unwrap();
+ let remote = "http://example.com".to_url().unwrap();
SourceId::new(RegistryKind, remote)
}
}
fn pkg_id_loc(name: &str, loc: &str) -> PackageId {
- let remote = Location::parse(loc);
+ let remote = loc.to_url();
let source_id = SourceId::new(GitKind("master".to_string()),
remote.unwrap());
fn dep(name: &str) -> Dependency {
let url = "http://example.com".to_url().unwrap();
- let source_id = SourceId::new(RegistryKind, Remote(url));
+ let source_id = SourceId::new(RegistryKind, url);
Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
}
fn dep_loc(name: &str, location: &str) -> Dependency {
let url = location.to_url().unwrap();
- let source_id = SourceId::new(GitKind("master".to_string()), Remote(url));
+ let source_id = SourceId::new(GitKind("master".to_string()), url);
Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
}
-use std::c_str::CString;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::collections::hashmap::{Values, MutEntries};
RegistryKind
}
-#[deriving(Clone, PartialEq, Eq, Hash)]
-pub enum Location {
- Local(Path),
- Remote(Url),
-}
-
type Error = Box<CargoError + Send>;
-impl<E, D: Decoder<E>> Decodable<D, E> for Location {
- fn decode(d: &mut D) -> Result<Location, E> {
- let url: String = raw_try!(Decodable::decode(d));
- Ok(Location::parse(url.as_slice()).unwrap())
- }
-}
-
-impl<E, S: Encoder<E>> Encodable<S, E> for Location {
- fn encode(&self, e: &mut S) -> Result<(), E> {
- self.to_string().encode(e)
- }
-}
-
#[deriving(Clone, Eq)]
pub struct SourceId {
- pub location: Location,
+ pub url: Url,
pub kind: SourceKind,
// e.g. the exact git revision of the specified branch for a Git Source
pub precise: Option<String>
}
-impl Show for Location {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match *self {
- Local(ref p) => write!(f, "file:{}", p.display()),
- Remote(ref u) => write!(f, "{}", u),
- }
- }
-}
-
impl PartialOrd for SourceId {
fn partial_cmp(&self, other: &SourceId) -> Option<Ordering> {
self.to_string().partial_cmp(&other.to_string())
}
}
-impl Location {
- pub fn parse(s: &str) -> CargoResult<Location> {
- if s.starts_with("file:") {
- Ok(Local(Path::new(s.slice_from(5))))
- } else {
- s.to_url().map(Remote).map_err(|e| {
- human(format!("invalid url `{}`: `{}", s, e))
- })
- }
- }
-}
-
-impl<'a> ToCStr for &'a Location {
- fn to_c_str(&self) -> CString {
- match **self {
- Local(ref p) => p.to_c_str(),
- Remote(ref u) => u.to_string().to_c_str(),
- }
- }
-
- unsafe fn to_c_str_unchecked(&self) -> CString { self.to_c_str() }
-}
-
impl<E, S: Encoder<E>> Encodable<S, E> for SourceId {
fn encode(&self, s: &mut S) -> Result<(), E> {
if self.is_path() {
impl Show for SourceId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
- SourceId { kind: PathKind, ref location, .. } => {
- try!(write!(f, "{}", location))
- },
- SourceId { kind: GitKind(ref reference), ref location, ref precise, .. } => {
- try!(write!(f, "{}", location));
+ SourceId { kind: PathKind, ref url, .. } => url.fmt(f),
+ SourceId { kind: GitKind(ref reference), ref url, ref precise, .. } => {
+ try!(write!(f, "{}", url));
if reference.as_slice() != "master" {
try!(write!(f, "?ref={}", reference));
}
}
None => {}
}
+ Ok(())
},
SourceId { kind: RegistryKind, .. } => {
// TODO: Central registry vs. alternates
- try!(write!(f, "the package registry"));
+ write!(f, "the package registry")
}
}
-
- Ok(())
}
}
impl PartialEq for SourceId {
fn eq(&self, other: &SourceId) -> bool {
if self.kind != other.kind { return false }
- if self.location == other.location { return true }
+ if self.url == other.url { return true }
- match (&self.kind, &other.kind, &self.location, &other.location) {
- (&GitKind(ref ref1), &GitKind(ref ref2),
- &Remote(ref u1), &Remote(ref u2)) => {
+ match (&self.kind, &other.kind, &self.url, &other.url) {
+ (&GitKind(ref ref1), &GitKind(ref ref2), u1, u2) => {
ref1 == ref2 &&
- git::canonicalize_url(u1.to_string().as_slice()) ==
- git::canonicalize_url(u2.to_string().as_slice())
+ git::canonicalize_url(u1) == git::canonicalize_url(u2)
}
_ => false,
}
impl<S: hash::Writer> hash::Hash<S> for SourceId {
fn hash(&self, into: &mut S) {
+ self.kind.hash(into);
match *self {
- SourceId {
- kind: ref kind @ GitKind(..),
- location: Remote(ref url),
- precise: _,
- } => {
- kind.hash(into);
- git::canonicalize_url(url.to_string().as_slice()).hash(into);
- }
- _ => {
- self.kind.hash(into);
- self.location.hash(into);
+ SourceId { kind: GitKind(..), ref url, .. } => {
+ git::canonicalize_url(url).hash(into)
}
+ _ => self.url.hash(into),
}
}
}
impl SourceId {
- pub fn new(kind: SourceKind, location: Location) -> SourceId {
- SourceId { kind: kind, location: location, precise: None }
+ pub fn new(kind: SourceKind, url: Url) -> SourceId {
+ SourceId { kind: kind, url: url, precise: None }
}
pub fn from_url(string: String) -> SourceId {
let url = parts.next().unwrap();
match kind {
- "git" if url.starts_with("file:") => {
- let url = url.slice_from(5);
- let (url, precise) = match url.rfind('#') {
- Some(pos) => {
- (url.slice_to(pos), Some(url.slice_from(pos + 1)))
- }
- None => (url, None)
- };
- let (url, reference) = match url.find_str("?ref=") {
- Some(pos) => {
- (url.slice_to(pos), Some(url.slice_from(pos + 5)))
- }
- None => (url, None)
- };
- let reference = reference.unwrap_or("master");
- let id = SourceId::new(GitKind(reference.to_string()),
- Local(Path::new(url)));
- match precise {
- Some(p) => id.with_precise(p.to_string()),
- None => id,
- }
- }
"git" => {
let mut url = url.to_url().unwrap();
let mut reference = "master".to_string();
SourceId::for_git(&url, reference.as_slice(), precise)
},
"registry" => SourceId::for_central(),
- "path" => SourceId::for_path(&Path::new(url.slice_from(5))),
+ "path" => SourceId::for_path(&Path::new(url.slice_from(5))).unwrap(),
_ => fail!("Unsupported serialized SourceId")
}
}
so this is unimplemented")
},
SourceId {
- kind: GitKind(ref reference), ref location, ref precise, ..
+ kind: GitKind(ref reference), ref url, ref precise, ..
} => {
let ref_str = if reference.as_slice() != "master" {
format!("?ref={}", reference)
"".to_string()
};
- format!("git+{}{}{}", location, ref_str, precise_str)
+ format!("git+{}{}{}", url, ref_str, precise_str)
},
SourceId { kind: RegistryKind, .. } => {
// TODO: Central registry vs. alternates
}
// Pass absolute path
- pub fn for_path(path: &Path) -> SourceId {
- SourceId::new(PathKind, Local(path.clone()))
+ pub fn for_path(path: &Path) -> CargoResult<SourceId> {
+ let url = try!(Url::from_file_path(path).map_err(|()| {
+ human(format!("not a valid path for a URL: {}", path.display()))
+ }));
+ Ok(SourceId::new(PathKind, url))
}
pub fn for_git(url: &Url, reference: &str, precise: Option<String>) -> SourceId {
- let mut id = SourceId::new(GitKind(reference.to_string()), Remote(url.clone()));
+ let mut id = SourceId::new(GitKind(reference.to_string()), url.clone());
if precise.is_some() {
id = id.with_precise(precise.unwrap());
}
pub fn for_central() -> SourceId {
SourceId::new(RegistryKind,
- Remote("https://example.com".to_url().unwrap()))
+ "https://example.com".to_url().unwrap())
}
- pub fn get_location(&self) -> &Location {
- &self.location
+ pub fn get_url(&self) -> &Url {
+ &self.url
}
pub fn is_path(&self) -> bool {
match self.kind {
GitKind(..) => box GitSource::new(self, config) as Box<Source>,
PathKind => {
- let path = match self.location {
- Local(ref p) => p,
- Remote(..) => fail!("path sources cannot be remote"),
+ let path = match self.url.to_file_path() {
+ Ok(p) => p,
+ Err(()) => fail!("path sources cannot be remote"),
};
- box PathSource::new(path, self) as Box<Source>
+ box PathSource::new(&path, self) as Box<Source>
},
RegistryKind => box DummyRegistrySource::new(self) as Box<Source>,
}
#[cfg(test)]
mod tests {
- use super::{SourceId, Remote, GitKind};
+ use super::{SourceId, GitKind};
use util::ToUrl;
#[test]
fn github_sources_equal() {
- let loc = Remote("https://github.com/foo/bar".to_url().unwrap());
+ let loc = "https://github.com/foo/bar".to_url().unwrap();
let s1 = SourceId::new(GitKind("master".to_string()), loc);
- let loc = Remote("git://github.com/foo/bar".to_url().unwrap());
+ let loc = "git://github.com/foo/bar".to_url().unwrap();
let mut s2 = SourceId::new(GitKind("master".to_string()), loc);
assert_eq!(s1, s2);
/// Cleans the project from build artifacts.
pub fn clean(manifest_path: &Path) -> CargoResult<()> {
- let mut src = PathSource::for_path(&manifest_path.dir_path());
+ let mut src = try!(PathSource::for_path(&manifest_path.dir_path()));
try!(src.update());
let root = try!(src.get_root_package());
let manifest = root.get_manifest();
use std::os;
use std::collections::{HashMap, HashSet};
+use std::result;
use core::registry::PackageRegistry;
use core::{MultiShell, Source, SourceId, PackageSet, Target, PackageId};
`cargo update` command instead"));
}
- let mut source = PathSource::for_path(&manifest_path.dir_path());
-
+ let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
try!(source.update());
// TODO: Move this into PathSource
// Make sure we don't override the local package, even if it's in the list
// of override paths
- Ok(paths.iter().filter(|p| {
+ result::collect(paths.iter().filter(|p| {
cur_path != os::make_absolute(&Path::new(p.as_slice()))
- }).map(|p| {
- SourceId::for_path(&Path::new(p.as_slice()))
- }).collect())
+ }).map(|p| SourceId::for_path(&Path::new(p.as_slice()))))
}
fn scrape_target_config(config: &mut Config,
pub fn doc(manifest_path: &Path,
options: &mut DocOptions) -> CargoResult<()> {
- let mut source = PathSource::for_path(&manifest_path.dir_path());
+ let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
try!(source.update());
let package = try!(source.get_root_package());
log!(4, "compile; manifest-path={}", manifest_path.display());
- let mut source = PathSource::for_path(&manifest_path.dir_path());
+ let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
try!(source.update());
// TODO: Move this into PathSource
pub fn update_lockfile(manifest_path: &Path,
shell: &mut MultiShell,
to_update: Option<String>) -> CargoResult<()> {
- let mut source = PathSource::for_path(&manifest_path.dir_path());
+ let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
try!(source.update());
let package = try!(source.get_root_package());
return Err(human("`src/main.rs` must be present for `cargo run`"))
}
- let mut src = PathSource::for_path(&manifest_path.dir_path());
+ let mut src = try!(PathSource::for_path(&manifest_path.dir_path()));
try!(src.update());
let root = try!(src.get_root_package());
use std::fmt;
use std::hash::Hasher;
use std::hash::sip::SipHasher;
-use std::str;
+use std::mem;
+use url::{mod, Url};
-use core::source::{Source, SourceId, GitKind, Location, Remote, Local};
+use core::source::{Source, SourceId, GitKind};
use core::{Package, PackageId, Summary, Registry, Dependency};
use util::{CargoResult, Config, to_hex};
use sources::PathSource;
_ => fail!("Not a git source; id={}", source_id)
};
- let remote = GitRemote::new(source_id.get_location());
- let ident = ident(source_id.get_location());
+ let remote = GitRemote::new(source_id.get_url());
+ let ident = ident(source_id.get_url());
let db_path = config.git_db_path()
.join(ident.as_slice());
}
}
- pub fn get_location(&self) -> &Location {
- self.remote.get_location()
+ pub fn get_url(&self) -> &Url {
+ self.remote.get_url()
}
}
-fn ident(location: &Location) -> String {
+fn ident(url: &Url) -> String {
let hasher = SipHasher::new_with_keys(0,0);
// FIXME: this really should be able to not use to_str() everywhere, but the
// compiler seems to currently ask for static lifetimes spuriously.
// Perhaps related to rust-lang/rust#15144
- let ident = match *location {
- Local(ref path) => {
- let last = path.components().last().unwrap();
- str::from_utf8(last).unwrap().to_string()
- }
- Remote(ref url) => {
- let path = url.path().unwrap().connect("/");
- let path = canonicalize_url(path.as_slice());
- path.as_slice().split('/').last().unwrap().to_string()
- }
- };
+ let url = canonicalize_url(url);
+ let ident = url.path().unwrap_or(&[])
+ .last().map(|a| a.clone()).unwrap_or(String::new());
let ident = if ident.as_slice() == "" {
"_empty".to_string()
ident
};
- let location = canonicalize_url(location.to_string().as_slice());
-
- format!("{}-{}", ident, to_hex(hasher.hash(&location.as_slice())))
-}
-
-fn strip_trailing_slash(path: &str) -> &str {
- // Remove the trailing '/' so that 'split' doesn't give us
- // an empty string, making '../foo/' and '../foo' both
- // result in the name 'foo' (#84)
- if path.as_bytes().last() != Some(&('/' as u8)) {
- path.clone()
- } else {
- path.slice(0, path.len() - 1)
- }
+ format!("{}-{}", ident, to_hex(hasher.hash(&url)))
}
// Some hacks and heuristics for making equivalent URLs hash the same
-pub fn canonicalize_url(url: &str) -> String {
- let url = strip_trailing_slash(url);
+pub fn canonicalize_url(url: &Url) -> Url {
+ let mut url = url.clone();
+
+ // Strip a trailing slash
+ match url.scheme_data {
+ url::RelativeSchemeData(ref mut rel) => {
+ if rel.path.last().map(|s| s.is_empty()).unwrap_or(false) {
+ rel.path.pop();
+ }
+ }
+ _ => {}
+ }
// HACKHACK: For github URL's specifically just lowercase
- // everything. GitHub traits both the same, but they hash
+ // everything. GitHub treats both the same, but they hash
// differently, and we're gonna be hashing them. This wants a more
// general solution, and also we're almost certainly not using the
// same case conversion rules that GitHub does. (#84)
-
- let lower_url = url.chars().map(|c|c.to_lowercase()).collect::<String>();
- let url = if lower_url.as_slice().contains("github.com") {
- if lower_url.as_slice().starts_with("https") {
- lower_url
- } else {
- let pos = lower_url.as_slice().find_str("://").unwrap_or(0);
- "https".to_string() + lower_url.as_slice().slice_from(pos)
+ if url.domain() == Some("github.com") {
+ url.scheme = "https".to_string();
+ match url.scheme_data {
+ url::RelativeSchemeData(ref mut rel) => {
+ rel.port = "443".to_string();
+ let path = mem::replace(&mut rel.path, Vec::new());
+ rel.path = path.move_iter().map(|s| {
+ s.as_slice().chars().map(|c| c.to_lowercase()).collect()
+ }).collect();
+ }
+ _ => {}
}
- } else {
- url.to_string()
- };
+ }
// Repos generally can be accessed with or w/o '.git'
- let url = if !url.as_slice().ends_with(".git") {
- url
- } else {
- url.as_slice().slice(0, url.len() - 4).to_string()
- };
+ match url.scheme_data {
+ url::RelativeSchemeData(ref mut rel) => {
+ let needs_chopping = {
+ let last = rel.path.last().map(|s| s.as_slice()).unwrap_or("");
+ last.ends_with(".git")
+ };
+ if needs_chopping {
+ let last = rel.path.pop().unwrap();
+ let last = last.as_slice();
+ rel.path.push(last.slice_to(last.len() - 4).to_string())
+ }
+ }
+ _ => {}
+ }
return url;
}
impl<'a, 'b> Show for GitSource<'a, 'b> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- try!(write!(f, "git repo at {}", self.remote.get_location()));
+ try!(write!(f, "git repo at {}", self.remote.get_url()));
match self.reference {
Master => Ok(()),
let (repo, actual_rev) = if should_update {
try!(self.config.shell().status("Updating",
- format!("git repository `{}`", self.remote.get_location())));
+ format!("git repository `{}`", self.remote.get_url())));
log!(5, "updating git source `{}`", self.remote);
let repo = try!(self.remote.checkout(&self.db_path));
#[cfg(test)]
mod test {
use url::Url;
- use core::source::Remote;
use super::ident;
use util::ToUrl;
#[test]
pub fn test_url_to_path_ident_with_path() {
- let ident = ident(&Remote(url("https://github.com/carlhuda/cargo")));
- assert_eq!(ident.as_slice(), "cargo-0eed735c8ffd7c88");
+ let ident = ident(&url("https://github.com/carlhuda/cargo"));
+ assert_eq!(ident.as_slice(), "cargo-51d6ede913e3e1d5");
}
#[test]
pub fn test_url_to_path_ident_without_path() {
- let ident = ident(&Remote(url("https://github.com")));
- assert_eq!(ident.as_slice(), "_empty-fc065c9b6b16fc00");
+ let ident = ident(&url("https://github.com"));
+ assert_eq!(ident.as_slice(), "_empty-eba8a1ec0f6907fb");
}
#[test]
fn test_canonicalize_idents_by_stripping_trailing_url_slash() {
- let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston/")));
- let ident2 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
+ let ident1 = ident(&url("https://github.com/PistonDevelopers/piston/"));
+ let ident2 = ident(&url("https://github.com/PistonDevelopers/piston"));
assert_eq!(ident1, ident2);
}
#[test]
fn test_canonicalize_idents_by_lowercasing_github_urls() {
- let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
- let ident2 = ident(&Remote(url("https://github.com/pistondevelopers/piston")));
+ let ident1 = ident(&url("https://github.com/PistonDevelopers/piston"));
+ let ident2 = ident(&url("https://github.com/pistondevelopers/piston"));
assert_eq!(ident1, ident2);
}
#[test]
fn test_canonicalize_idents_by_stripping_dot_git() {
- let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
- let ident2 = ident(&Remote(url("https://github.com/PistonDevelopers/piston.git")));
+ let ident1 = ident(&url("https://github.com/PistonDevelopers/piston"));
+ let ident2 = ident(&url("https://github.com/PistonDevelopers/piston.git"));
assert_eq!(ident1, ident2);
}
#[test]
fn test_canonicalize_idents_different_protocls() {
- let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
- let ident2 = ident(&Remote(url("git://github.com/PistonDevelopers/piston")));
+ let ident1 = ident(&url("https://github.com/PistonDevelopers/piston"));
+ let ident2 = ident(&url("git://github.com/PistonDevelopers/piston"));
assert_eq!(ident1, ident2);
}
use std::io::{UserDir};
use std::io::fs::{mkdir_recursive,rmdir_recursive};
use serialize::{Encodable,Encoder};
+use url::Url;
-use core::source::Location;
use util::{CargoResult, ChainError, ProcessBuilder, process, human};
#[deriving(PartialEq,Clone,Encodable)]
/// GitDatabase.
#[deriving(PartialEq,Clone,Show)]
pub struct GitRemote {
- location: Location,
+ url: Url,
}
#[deriving(PartialEq,Clone,Encodable)]
struct EncodableGitRemote {
- location: String,
+ url: String,
}
impl<E, S: Encoder<E>> Encodable<S, E> for GitRemote {
fn encode(&self, s: &mut S) -> Result<(), E> {
EncodableGitRemote {
- location: self.location.to_string()
+ url: self.url.to_string()
}.encode(s)
}
}
// Implementations
impl GitRemote {
- pub fn new(location: &Location) -> GitRemote {
- GitRemote { location: location.clone() }
+ pub fn new(url: &Url) -> GitRemote {
+ GitRemote { url: url.clone() }
}
- pub fn get_location(&self) -> &Location {
- &self.location
+ pub fn get_url(&self) -> &Url {
+ &self.url
}
pub fn rev_for<S: Str>(&self, path: &Path, reference: S)
fn fetch_into(&self, path: &Path) -> CargoResult<()> {
Ok(git!(*path, "fetch", "--force", "--quiet", "--tags",
- &self.location, "refs/heads/*:refs/heads/*"))
+ self.url.to_string(), "refs/heads/*:refs/heads/*"))
}
fn clone_into(&self, path: &Path) -> CargoResult<()> {
try!(mkdir_recursive(path, UserDir));
- Ok(git!(dirname, "clone", &self.location, path, "--bare",
+ Ok(git!(dirname, "clone", self.url.to_string(), path, "--bare",
"--no-hardlinks", "--quiet"))
}
}
// mut and packages are discovered in update
impl PathSource {
- pub fn for_path(path: &Path) -> PathSource {
+ pub fn for_path(path: &Path) -> CargoResult<PathSource> {
log!(5, "PathSource::for_path; path={}", path.display());
- PathSource::new(path, &SourceId::for_path(path))
+ Ok(PathSource::new(path, &try!(SourceId::for_path(path))))
}
/// Invoked with an absolute path to a directory that contains a Cargo.toml.
use docopt;
use TomlError = toml::Error;
+use url;
pub trait CargoError: Send {
fn description(&self) -> String;
from_error!(docopt::Error)
+impl CargoError for url::ParseError {
+ fn description(&self) -> String { self.to_string() }
+}
+
+from_error!(url::ParseError)
+
impl CliError {
pub fn new<S: Str>(error: S, code: uint) -> CliError {
let error = human(error.as_slice().to_string());
impl<'a> ToUrl for &'a str {
fn to_url(self) -> Result<Url, String> {
UrlParser::new().scheme_type_mapper(mapper).parse(self).map_err(|s| {
- s.to_string()
+ format!("invalid url `{}`: {}", self, s)
})
}
}
use core::manifest::{LibKind, Lib, Dylib, Profile};
use core::{Summary, Manifest, Target, Dependency, PackageId};
use core::package_id::Metadata;
-use core::source::Location;
-use util::{CargoResult, Require, human};
+use util::{CargoResult, Require, human, ToUrl};
/// Representation of the projects file layout.
///
let new_source_id = match details.git {
Some(ref git) => {
let kind = GitKind(reference.clone());
- let loc = try!(Location::parse(git.as_slice()));
+ let loc = try!(git.as_slice().to_url().map_err(|e| {
+ human(e)
+ }));
let source_id = SourceId::new(kind, loc);
// TODO: Don't do this for path
cx.source_ids.push(source_id.clone());
use std::str;
use std::vec::Vec;
use std::fmt::Show;
+use url::Url;
use ham = hamcrest;
use cargo::util::{process,ProcessBuilder};
use cargo::util::ProcessError;
self.root.clone()
}
+ pub fn url(&self) -> Url { path2url(self.root()) }
+
pub fn bin(&self, b: &str) -> Path {
self.build_dir().join(format!("{}{}", b, os::consts::EXE_SUFFIX))
}
"#, name, name)
}
+pub fn path2url(p: Path) -> Url {
+ Url::from_file_path(&p).unwrap()
+}
+
pub static RUNNING: &'static str = " Running";
pub static COMPILING: &'static str = " Compiling";
pub static FRESH: &'static str = " Fresh";
use std::path;
use support::{ResultTest, project, execs, main_file, basic_bin_manifest};
-use support::{COMPILING, RUNNING, cargo_dir, ProjectBuilder};
+use support::{COMPILING, RUNNING, cargo_dir, ProjectBuilder, path2url};
use hamcrest::{assert_that, existing_file};
use cargo;
use cargo::util::{process, realpath};
assert_that(p.cargo_process("cargo-build"),
execs()
- .with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, bar.display(),
- COMPILING, main.display()))
+ .with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, path2url(bar),
+ COMPILING, path2url(main)))
.with_stderr(""));
assert_that(&p.bin("foo"), existing_file());
assert_that(p.cargo_process("cargo-build"),
execs().with_status(101).with_stderr(format!(
r#"No package named `notquitebar` found (required by `foo`).
-Location searched: file:{proj_dir}
+Location searched: {proj_dir}
Version required: *
-"#, proj_dir = p.root().display())));
+"#, proj_dir = p.url())));
})
// test!(compiling_project_with_invalid_manifest)
"#);
assert_that(p.cargo_process("cargo-build"),
execs().with_status(0)
- .with_stdout(format!(" Compiling foo v0.5.0 (file:{})\n",
- p.root().display()))
+ .with_stdout(format!(" Compiling foo v0.5.0 ({})\n",
+ p.url()))
.with_stderr(""));
})
"#);
assert_that(p.cargo_process("cargo-build"),
execs().with_status(0)
- .with_stdout(format!(" Compiling foo v0.5.0 (file:{})\n",
- p.root().display()))
+ .with_stdout(format!(" Compiling foo v0.5.0 ({})\n",
+ p.url()))
.with_stderr(""));
})
--dep-info [..] \
-L {dir}{sep}target \
-L {dir}{sep}target{sep}deps`
-{compiling} test v0.0.0 (file:{dir})\n",
+{compiling} test v0.0.0 ({url})\n",
running = RUNNING, compiling = COMPILING, sep = path::SEP,
-dir = p.root().display()
+dir = p.root().display(),
+url = p.url(),
)));
})
--dep-info [..] \
-L {dir}{sep}target{sep}release \
-L {dir}{sep}target{sep}release{sep}deps`
-{compiling} test v0.0.0 (file:{dir})\n",
+{compiling} test v0.0.0 ({url})\n",
running = RUNNING, compiling = COMPILING, sep = path::SEP,
-dir = p.root().display()
+dir = p.root().display(),
+url = p.url(),
)));
})
--extern foo={dir}{sep}target{sep}release{sep}deps/\
{prefix}foo-[..]{suffix} \
--extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
-{compiling} foo v0.0.0 (file:{dir})
-{compiling} test v0.0.0 (file:{dir})\n",
+{compiling} foo v0.0.0 ({url})
+{compiling} test v0.0.0 ({url})\n",
running = RUNNING,
compiling = COMPILING,
dir = p.root().display(),
+ url = p.url(),
sep = path::SEP,
prefix = os::consts::DLL_PREFIX,
suffix = os::consts::DLL_SUFFIX).as_slice()));
assert_that(p.cargo_process("cargo-build"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} syntax v0.0.1 (file:{dir})
+{compiling} syntax v0.0.1 ({dir})
",
compiling = COMPILING,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
})
test!(simple_staticlib {
use std::io::File;
use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths};
-use support::{cargo_dir};
+use support::{cargo_dir, path2url};
use support::{COMPILING, FRESH, UPDATING};
use support::paths::PathExt;
use hamcrest::{assert_that,existing_file};
[dependencies.dep1]
- git = 'file:{}'
+ git = '{}'
[[bin]]
name = "foo"
- "#, git_project.root().display()))
+ "#, git_project.url()))
.file("src/foo.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]));
let root = project.root();
assert_that(project.cargo_process("cargo-build"),
execs()
- .with_stdout(format!("{} git repository `file:{}`\n\
- {} dep1 v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- UPDATING, git_root.display(),
- COMPILING, git_root.display(),
- COMPILING, root.display()))
+ .with_stdout(format!("{} git repository `{}`\n\
+ {} dep1 v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ UPDATING, path2url(git_root.clone()),
+ COMPILING, path2url(git_root),
+ COMPILING, path2url(root)))
.with_stderr(""));
assert_that(&project.bin("foo"), existing_file());
[dependencies.dep1]
- git = 'file:{}'
+ git = '{}'
branch = "branchy"
[[bin]]
name = "foo"
- "#, git_project.root().display()))
+ "#, git_project.url()))
.file("src/foo.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]));
let root = project.root();
assert_that(project.cargo_process("cargo-build"),
execs()
- .with_stdout(format!("{} git repository `file:{}`\n\
- {} dep1 v0.5.0 (file:{}?ref=branchy#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- UPDATING, git_root.display(),
- COMPILING, git_root.display(),
- COMPILING, root.display()))
+ .with_stdout(format!("{} git repository `{}`\n\
+ {} dep1 v0.5.0 ({}?ref=branchy#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ UPDATING, path2url(git_root.clone()),
+ COMPILING, path2url(git_root),
+ COMPILING, path2url(root)))
.with_stderr(""));
assert_that(&project.bin("foo"), existing_file());
[dependencies.dep1]
- git = 'file:{}'
+ git = '{}'
tag = "v0.1.0"
[[bin]]
name = "foo"
- "#, git_project.root().display()))
+ "#, git_project.url()))
.file("src/foo.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]));
let root = project.root();
assert_that(project.cargo_process("cargo-build"),
execs()
- .with_stdout(format!("{} git repository `file:{}`\n\
- {} dep1 v0.5.0 (file:{}?ref=v0.1.0#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- UPDATING, git_root.display(),
- COMPILING, git_root.display(),
- COMPILING, root.display()))
+ .with_stdout(format!("{} git repository `{}`\n\
+ {} dep1 v0.5.0 ({}?ref=v0.1.0#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ UPDATING, path2url(git_root.clone()),
+ COMPILING, path2url(git_root),
+ COMPILING, path2url(root)))
.with_stderr(""));
assert_that(&project.bin("foo"), existing_file());
[dependencies.dep1]
version = "0.5.0"
- git = 'file:{}'
+ git = '{}'
[[bin]]
name = "parent"
- "#, git_project.root().display()))
+ "#, git_project.url()))
.file("src/parent.rs",
main_file(r#""{}", dep1::hello()"#, ["dep1"]).as_slice());
[dependencies.dep1]
version = "0.5.0"
- git = 'file:{}'
+ git = '{}'
[dependencies.dep2]
version = "0.5.0"
- git = 'file:{}'
+ git = '{}'
[[bin]]
name = "parent"
- "#, git_project.root().display(), git_project.root().display()))
+ "#, git_project.url(), git_project.url()))
.file("src/parent.rs",
main_file(r#""{} {}", dep1::hello(), dep2::hello()"#, ["dep1", "dep2"]).as_slice());
execs()
.with_stdout("")
.with_stderr(format!("Cargo.toml is not a valid manifest\n\n\
- invalid url `{}`: `Relative URL without a base\n", url)));
+ invalid url `{}`: Relative URL without a base\n", url)));
})
test!(two_revs_same_deps {
authors = []
[dependencies.bar]
- git = 'file:{}'
+ git = '{}'
rev = "{}"
[dependencies.baz]
path = "../baz"
- "#, bar.root().display(), rev1.as_slice().trim()).as_slice())
+ "#, bar.url(), rev1.as_slice().trim()).as_slice())
.file("src/main.rs", r#"
extern crate bar;
extern crate baz;
authors = []
[dependencies.bar]
- git = 'file:{}'
+ git = '{}'
rev = "{}"
- "#, bar.root().display(), rev2.as_slice().trim()).as_slice())
+ "#, bar.url(), rev2.as_slice().trim()).as_slice())
.file("src/lib.rs", r#"
extern crate bar;
pub fn baz() -> int { bar::bar() }
[dependencies.bar]
version = "0.5.0"
- git = 'file:{}'
+ git = '{}'
[[bin]]
name = "foo"
- "#, git_project.root().display()))
+ "#, git_project.url()))
.file("src/foo.rs",
main_file(r#""{}", bar::bar()"#, ["bar"]).as_slice());
// First time around we should compile both foo and bar
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} git repository `file:{}`\n\
- {} bar v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- UPDATING, git_project.root().display(),
- COMPILING, git_project.root().display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} git repository `{}`\n\
+ {} bar v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ UPDATING, git_project.url(),
+ COMPILING, git_project.url(),
+ COMPILING, p.url())));
// Don't recompile the second time
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, git_project.root().display(),
- FRESH, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, git_project.url(),
+ FRESH, p.url())));
// Modify a file manually, shouldn't trigger a recompile
File::create(&git_project.root().join("src/bar.rs")).write_str(r#"
"#).assert();
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, git_project.root().display(),
- FRESH, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, git_project.url(),
+ FRESH, p.url())));
assert_that(p.process(cargo_dir().join("cargo-update")),
- execs().with_stdout(format!("{} git repository `file:{}`",
+ execs().with_stdout(format!("{} git repository `{}`",
UPDATING,
- git_project.root().display())));
+ git_project.url())));
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, git_project.root().display(),
- FRESH, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, git_project.url(),
+ FRESH, p.url())));
// Commit the changes and make sure we don't trigger a recompile because the
// lockfile says not to change
println!("compile after commit");
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, git_project.root().display(),
- FRESH, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, git_project.url(),
+ FRESH, p.url())));
p.root().move_into_the_past().assert();
// Update the dependency and carry on!
assert_that(p.process(cargo_dir().join("cargo-update")),
- execs().with_stdout(format!("{} git repository `file:{}`",
+ execs().with_stdout(format!("{} git repository `{}`",
UPDATING,
- git_project.root().display())));
+ git_project.url())));
println!("going for the last compile");
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, git_project.root().display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, git_project.url(),
+ COMPILING, p.url())));
})
test!(update_with_shared_deps {
[dependencies.bar]
version = "0.5.0"
- git = 'file:{}'
- "#, git_project.root().display()))
+ git = '{}'
+ "#, git_project.url()))
.file("dep1/src/lib.rs", "")
.file("dep2/Cargo.toml", format!(r#"
[package]
[dependencies.bar]
version = "0.5.0"
- git = 'file:{}'
- "#, git_project.root().display()))
+ git = '{}'
+ "#, git_project.url()))
.file("dep2/src/lib.rs", "");
// First time around we should compile both foo and bar
assert_that(p.cargo_process("cargo-build"),
execs().with_stdout(format!("\
-{updating} git repository `file:{git}`
-{compiling} bar v0.5.0 (file:{git}#[..])
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} foo v0.5.0 (file:{dir})\n",
- updating = UPDATING, git = git_project.root().display(),
- compiling = COMPILING, dir = p.root().display())));
+{updating} git repository `{git}`
+{compiling} bar v0.5.0 ({git}#[..])
+{compiling} [..] v0.5.0 ({dir})
+{compiling} [..] v0.5.0 ({dir})
+{compiling} foo v0.5.0 ({dir})\n",
+ updating = UPDATING, git = git_project.url(),
+ compiling = COMPILING, dir = p.url())));
// Modify a file manually, and commit it
File::create(&git_project.root().join("src/bar.rs")).write_str(r#"
git_project.process("git").args(["commit", "-m", "test"]).exec_with_output()
.assert();
assert_that(p.process(cargo_dir().join("cargo-update")).arg("dep1"),
- execs().with_stdout(format!("{} git repository `file:{}`",
+ execs().with_stdout(format!("{} git repository `{}`",
UPDATING,
- git_project.root().display())));
+ git_project.url())));
// Make sure we still only compile one version of the git repo
assert_that(p.cargo_process("cargo-build"),
execs().with_stdout(format!("\
-{compiling} bar v0.5.0 (file:{git}#[..])
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} foo v0.5.0 (file:{dir})\n",
- git = git_project.root().display(),
- compiling = COMPILING, dir = p.root().display())));
+{compiling} bar v0.5.0 ({git}#[..])
+{compiling} [..] v0.5.0 ({dir})
+{compiling} [..] v0.5.0 ({dir})
+{compiling} foo v0.5.0 ({dir})\n",
+ git = git_project.url(),
+ compiling = COMPILING, dir = p.url())));
})
test!(dep_with_submodule {
[dependencies.dep1]
- git = 'file:{}'
- "#, git_project.root().display()))
+ git = '{}'
+ "#, git_project.url()))
.file("src/lib.rs", "
extern crate dep1;
pub fn foo() { dep1::dep() }
");
- let root = project.root();
- let git_root = git_project.root();
+ let root = project.url();
+ let git_root = git_project.url();
assert_that(project.cargo_process("cargo-build"),
execs()
- .with_stdout(format!("{} git repository `file:{}`\n\
- {} dep1 v0.5.0 (file:{}#[..])\n\
- {} foo v0.5.0 (file:{})\n",
- UPDATING, git_root.display(),
- COMPILING, git_root.display(),
- COMPILING, root.display()))
+ .with_stdout(format!("{} git repository `{}`\n\
+ {} dep1 v0.5.0 ({}#[..])\n\
+ {} foo v0.5.0 ({})\n",
+ UPDATING, git_root,
+ COMPILING, git_root,
+ COMPILING, root))
.with_stderr(""));
})
use std::io::File;
-use support::{ResultTest, project, execs, main_file, cargo_dir};
+use support::{ResultTest, project, execs, main_file, cargo_dir, path2url};
use support::{COMPILING, FRESH};
use support::paths::PathExt;
use hamcrest::{assert_that, existing_file};
"#);
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
- {} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, p.root().display(),
- COMPILING, p.root().display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+ {} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, p.url(),
+ COMPILING, p.url(),
+ COMPILING, p.url())));
assert_that(&p.bin("foo"), existing_file());
p2.build();
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, p.root().display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, p.url(),
+ COMPILING, p.url())));
assert_that(&p.bin("foo"), existing_file());
"#);
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, p.root().display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, p.url(),
+ COMPILING, p.url())));
assert_that(&p.bin("foo"), existing_file());
.file("bar/src/bar.rs", r#"
pub fn bar() {}
"#);
+ let bar = path2url(bar);
// First time around we should compile both foo and bar
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, bar,
+ COMPILING, p.url())));
// This time we shouldn't compile bar
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, bar.display(),
- FRESH, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, bar,
+ FRESH, p.url())));
p.root().move_into_the_past().assert();
p.build(); // rebuild the files (rewriting them in the process)
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, bar,
+ COMPILING, p.url())));
})
test!(deep_dependencies_trigger_rebuild {
.file("baz/src/baz.rs", r#"
pub fn baz() {}
"#);
+ let baz = path2url(baz);
+ let bar = path2url(bar);
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
- {} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, baz.display(),
- COMPILING, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+ {} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, baz,
+ COMPILING, bar,
+ COMPILING, p.url())));
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
- {} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, baz.display(),
- FRESH, bar.display(),
- FRESH, p.root().display())));
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+ {} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, baz,
+ FRESH, bar,
+ FRESH, p.url())));
// Make sure an update to baz triggers a rebuild of bar
//
pub fn baz() { println!("hello!"); }
"#).assert();
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
- {} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, baz.display(),
- COMPILING, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+ {} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, baz,
+ COMPILING, bar,
+ COMPILING, p.url())));
// Make sure an update to bar doesn't trigger baz
p.root().move_into_the_past().assert();
pub fn bar() { println!("hello!"); baz::baz(); }
"#).assert();
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
- {} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, baz.display(),
- COMPILING, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+ {} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, baz,
+ COMPILING, bar,
+ COMPILING, p.url())));
})
test!(no_rebuild_two_deps {
.file("baz/src/baz.rs", r#"
pub fn baz() {}
"#);
+ let baz = path2url(baz);
+ let bar = path2url(bar);
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
- {} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, baz.display(),
- COMPILING, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+ {} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, baz,
+ COMPILING, bar,
+ COMPILING, p.url())));
assert_that(&p.bin("foo"), existing_file());
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
- {} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, baz.display(),
- FRESH, bar.display(),
- FRESH, p.root().display())));
+ execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+ {} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, baz,
+ FRESH, bar,
+ FRESH, p.url())));
assert_that(&p.bin("foo"), existing_file());
})
name = "bar"
"#)
.file("src/bar/src/bar.rs", "pub fn gimme() {}");
- let bar = p.root();
+ let bar = p.url();
assert_that(p.cargo_process("cargo-build"),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- COMPILING, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ COMPILING, bar,
+ COMPILING, p.url())));
p.root().move_into_the_past().assert();
File::create(&p.root().join("src/foo.rs")).write_str(r#"
// This shouldn't recompile `bar`
assert_that(p.process(cargo_dir().join("cargo-build")),
- execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
- {} foo v0.5.0 (file:{})\n",
- FRESH, bar.display(),
- COMPILING, p.root().display())));
+ execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+ {} foo v0.5.0 ({})\n",
+ FRESH, bar,
+ COMPILING, p.url())));
})
test!(error_message_for_missing_manifest {
-C ar=my-ar-tool -C linker=my-linker-tool \
-L {dir}{sep}target{sep}{target} \
-L {dir}{sep}target{sep}{target}{sep}deps`
-{compiling} foo v0.5.0 (file:{dir})
+{compiling} foo v0.5.0 ({url})
",
running = RUNNING,
compiling = COMPILING,
dir = p.root().display(),
+ url = p.url(),
target = target,
sep = path::SEP,
).as_slice()));
-use support::{project, execs, cargo_dir};
+use support::{project, execs, cargo_dir, path2url};
use support::{COMPILING, FRESH};
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
assert_that(p.cargo_process("cargo-doc"),
execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
",
compiling = COMPILING,
- dir = p.root().display()).as_slice()));
+ dir = path2url(p.root())).as_slice()));
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
})
assert_that(p.cargo_process("cargo-doc"),
execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
",
compiling = COMPILING,
- dir = p.root().display()).as_slice()));
+ dir = path2url(p.root())).as_slice()));
assert_that(p.process(cargo_dir().join("cargo-doc")),
execs().with_status(0).with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} foo v0.0.1 ({dir})
",
fresh = FRESH,
- dir = p.root().display()).as_slice()));
+ dir = path2url(p.root())).as_slice()));
})
test!(doc_deps {
assert_that(p.cargo_process("cargo-doc"),
execs().with_status(0).with_stdout(format!("\
-{compiling} bar v0.0.1 (file:{dir})
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} bar v0.0.1 ({dir})
+{compiling} foo v0.0.1 ({dir})
",
compiling = COMPILING,
- dir = p.root().display()).as_slice()));
+ dir = path2url(p.root())).as_slice()));
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
assert_that(p.process(cargo_dir().join("cargo-doc"))
.env("RUST_LOG", Some("cargo::ops::cargo_rustc::fingerprint")),
execs().with_status(0).with_stdout(format!("\
-{fresh} bar v0.0.1 (file:{dir})
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} bar v0.0.1 ({dir})
+{fresh} foo v0.0.1 ({dir})
",
fresh = FRESH,
- dir = p.root().display()).as_slice()));
+ dir = path2url(p.root())).as_slice()));
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
assert_that(p.cargo_process("cargo-doc").arg("--no-deps"),
execs().with_status(0).with_stdout(format!("\
-{compiling} bar v0.0.1 (file:{dir})
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} bar v0.0.1 ({dir})
+{compiling} foo v0.0.1 ({dir})
",
compiling = COMPILING,
- dir = p.root().display()).as_slice()));
+ dir = path2url(p.root())).as_slice()));
assert_that(&p.root().join("target/doc"), existing_dir());
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
use std::io::{fs, File};
-use support::{project, execs};
+use support::{project, execs, path2url};
use support::{COMPILING, cargo_dir, ResultTest, FRESH};
use support::paths::PathExt;
use hamcrest::{assert_that, existing_file};
assert_that(p.cargo_process("cargo-build"),
execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
assert_that(p.process(cargo_dir().join("cargo-build")),
execs().with_status(0).with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
-", fresh = FRESH, dir = p.root().display())));
+{fresh} foo v0.0.1 ({dir})
+", fresh = FRESH, dir = path2url(p.root()))));
p.root().move_into_the_past().assert();
File::create(&p.root().join("src/a.rs")).write_str("fn main() {}").assert();
assert_that(p.process(cargo_dir().join("cargo-build")),
execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
fs::rename(&p.root().join("src/a.rs"), &p.root().join("src/b.rs")).assert();
assert_that(p.process(cargo_dir().join("cargo-build")),
assert_that(p.cargo_process("cargo-build"),
execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
assert_that(p.process(cargo_dir().join("cargo-test")),
execs().with_status(0));
assert_that(p.process(cargo_dir().join("cargo-build"))
.env("RUST_LOG", Some("cargo::ops::cargo_rustc::fingerprint")),
execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
assert_that(&p.bin("foo"), existing_file());
})
use std::path;
-use support::{project, execs};
+use support::{project, execs, path2url};
use support::{COMPILING, RUNNING};
use hamcrest::{assert_that, existing_file};
assert_that(p.cargo_process("cargo-run"),
execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
{running} `target{sep}foo`
hello
",
compiling = COMPILING,
running = RUNNING,
- dir = p.root().display(),
+ dir = path2url(p.root()),
sep = path::SEP).as_slice()));
assert_that(&p.bin("foo"), existing_file());
})
assert_that(p.process(cargo_dir().join("cargo-test")),
execs().with_stdout(format!("\
-{} foo v0.5.0 (file:{})
+{} foo v0.5.0 ({})
{} target[..]test[..]foo
running 1 test
test test_hello ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n",
- COMPILING, p.root().display(),
+ COMPILING, p.url(),
RUNNING)));
})
assert_that(p.process(cargo_dir().join("cargo-test")),
execs().with_stdout(format!("\
-{} foo v0.5.0 (file:{})
+{} foo v0.5.0 ({})
{} target[..]test[..]foo
running 1 test
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
",
- COMPILING, p.root().display(), RUNNING,
+ COMPILING, p.url(), RUNNING,
sep = path::SEP))
.with_stderr(format!("\
task '<main>' failed at 'Some tests failed', [..]
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
{running} target[..]test[..]baz-[..]
running 1 test
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
",
- COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+ COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
})
test!(test_with_deep_lib_dep {
assert_that(p.cargo_process("cargo-test"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-{compiling} bar v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
+{compiling} bar v0.0.1 ({dir})
{running} target[..]
running 1 test
",
compiling = COMPILING, running = RUNNING,
doctest = DOCTEST,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
})
test!(external_test_explicit {
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
{running} target[..]test[..]foo-[..]
running 1 test
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
",
- COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+ COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
})
test!(external_test_implicit {
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
{running} target[..]test[..]external-[..]
running 1 test
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
",
- COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+ COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
})
test!(dont_run_examples {
assert_that(p.cargo_process("cargo-test").arg("bar"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
{running} target[..]test[..]foo
running 1 test
",
compiling = COMPILING, running = RUNNING,
doctest = DOCTEST,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
assert_that(p.cargo_process("cargo-test").arg("foo"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
{running} target[..]test[..]foo
running 1 test
",
compiling = COMPILING, running = RUNNING,
doctest = DOCTEST,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
})
// Regression test for running cargo-test twice with
assert_that(p.cargo_process("cargo-test"),
execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
{running} target[..]test[..]foo-[..]
running 1 test
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
",
- COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+ COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
})
test!(lib_with_standard_name {
assert_that(p.cargo_process("cargo-test"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} syntax v0.0.1 (file:{dir})
+{compiling} syntax v0.0.1 ({dir})
{running} target[..]test[..]test-[..]
running 1 test
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
",
compiling = COMPILING, running = RUNNING,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
})
test!(lib_with_standard_name2 {
assert_that(p.cargo_process("cargo-test"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} syntax v0.0.1 (file:{dir})
+{compiling} syntax v0.0.1 ({dir})
{running} target[..]test[..]syntax-[..]
running 1 test
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
",
compiling = COMPILING, running = RUNNING,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
})
test!(bin_there_for_integration {
assert_that(p.cargo_process("cargo-test"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
{running} target[..]test[..]foo-[..]
running 1 test
",
compiling = COMPILING, running = RUNNING,
doctest = DOCTEST,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
p.root().move_into_the_past().assert();
assert_that(p.process(cargo_dir().join("cargo-test")),
execs().with_status(0)
.with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} foo v0.0.1 ({dir})
{running} target[..]test[..]foo-[..]
running 1 test
",
fresh = FRESH, running = RUNNING,
doctest = DOCTEST,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
})
test!(test_twice_with_build_cmd {
assert_that(p.cargo_process("cargo-test"),
execs().with_status(0)
.with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
{running} target[..]test[..]foo-[..]
running 1 test
",
compiling = COMPILING, running = RUNNING,
doctest = DOCTEST,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
assert_that(p.process(cargo_dir().join("cargo-test")),
execs().with_status(0)
.with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} foo v0.0.1 ({dir})
{running} target[..]test[..]foo-[..]
running 1 test
",
fresh = FRESH, running = RUNNING,
doctest = DOCTEST,
- dir = p.root().display()).as_slice()));
+ dir = p.url()).as_slice()));
})
extern crate term;
extern crate cargo;
extern crate hamcrest;
+extern crate url;
#[phase(plugin, link)]
extern crate log;