mirror of https://github.com/rust-lang/cargo
Up to date with master (StrBuf->String)
This commit is contained in:
parent
12f49111cd
commit
2f57617559
|
@ -1 +1 @@
|
|||
Subproject commit c305bcb84ed51d7bd808bc20c09c00a1beb1b087
|
||||
Subproject commit 5fbc58a5f2251c427f405234a52a4bb54241b19a
|
|
@ -1 +1 @@
|
|||
Subproject commit 0de103ed19997884f2766456f7a003b94f1daa42
|
||||
Subproject commit ca130156b599a8f48e0edee3e782e8de93e00c34
|
|
@ -18,7 +18,7 @@ use cargo::util::ToCLI;
|
|||
|
||||
#[deriving(Eq,Clone,Decodable,Encodable)]
|
||||
pub struct Options {
|
||||
manifest_path: Option<StrBuf>
|
||||
manifest_path: Option<String>
|
||||
}
|
||||
|
||||
impl FlagConfig for Options {}
|
||||
|
@ -32,7 +32,7 @@ fn execute(options: Options) -> CLIResult<Option<()>> {
|
|||
|
||||
let root = match options.manifest_path {
|
||||
Some(path) => Path::new(path),
|
||||
None => try!(find_project(os::getcwd(), "Cargo.toml".to_owned())
|
||||
None => try!(find_project(os::getcwd(), "Cargo.toml")
|
||||
.map(|path| path.join("Cargo.toml"))
|
||||
.to_result(|err|
|
||||
CLIError::new("Could not find Cargo.toml in this directory or any parent directory", Some(err), 102)))
|
||||
|
|
|
@ -7,16 +7,15 @@ extern crate url;
|
|||
|
||||
use hammer::FlagConfig;
|
||||
use cargo::{execute_main_without_stdin,CLIResult,CLIError,ToResult};
|
||||
use cargo::core::Package;
|
||||
use cargo::util::{Require,ToCLI,simple_human};
|
||||
use cargo::util::ToCLI;
|
||||
use cargo::sources::git::{GitCommand,GitRepo};
|
||||
use url::Url;
|
||||
|
||||
#[deriving(Eq,Clone,Decodable)]
|
||||
struct Options {
|
||||
directory: StrBuf,
|
||||
url: StrBuf,
|
||||
reference: StrBuf
|
||||
directory: String,
|
||||
url: String,
|
||||
reference: String
|
||||
}
|
||||
|
||||
impl FlagConfig for Options {}
|
||||
|
|
|
@ -12,7 +12,7 @@ use cargo::ops;
|
|||
|
||||
#[deriving(Eq,Clone,Decodable)]
|
||||
struct Options {
|
||||
manifest_path: StrBuf
|
||||
manifest_path: String
|
||||
}
|
||||
|
||||
impl FlagConfig for Options {}
|
||||
|
@ -23,9 +23,5 @@ fn main() {
|
|||
|
||||
fn execute(options: Options) -> CLIResult<Option<Package>> {
|
||||
ops::read_manifest(options.manifest_path.as_slice()).map(|m| Some(m))
|
||||
.map_err(|err| CLIError {
|
||||
msg: err.get_desc().to_strbuf(),
|
||||
detail: err.get_detail().map(|s| s.to_strbuf()),
|
||||
exit_code: 1
|
||||
})
|
||||
.map_err(|err| CLIError::new(err.get_desc(), Some(err.get_detail()), 1))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use getopts::{reqopt,getopts};
|
|||
*/
|
||||
|
||||
fn main() {
|
||||
let arguments: Vec<StrBuf> = args().iter().map(|a| a.to_strbuf()).collect();
|
||||
let arguments = args();
|
||||
|
||||
let opts = vec!(
|
||||
reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
|
||||
|
|
|
@ -22,7 +22,7 @@ fn main() {
|
|||
|
||||
#[deriving(Encodable)]
|
||||
struct ProjectLocation {
|
||||
root: StrBuf
|
||||
root: String
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,15 +38,15 @@ fn execute() {
|
|||
Err(err) => return handle_error(err)
|
||||
};
|
||||
|
||||
if cmd == "config-for-key".to_strbuf() {
|
||||
if cmd == "config-for-key".to_str() {
|
||||
log!(4, "cmd == config-for-key");
|
||||
execute_main_without_stdin(config_for_key)
|
||||
}
|
||||
else if cmd == "config-list".to_strbuf() {
|
||||
else if cmd == "config-list".to_str() {
|
||||
log!(4, "cmd == config-list");
|
||||
execute_main_without_stdin(config_list)
|
||||
}
|
||||
else if cmd == "locate-project".to_strbuf() {
|
||||
else if cmd == "locate-project".to_str() {
|
||||
log!(4, "cmd == locate-project");
|
||||
execute_main_without_stdin(locate_project)
|
||||
}
|
||||
|
@ -57,22 +57,22 @@ fn execute() {
|
|||
}
|
||||
}
|
||||
|
||||
fn process(args: Vec<~str>) -> CLIResult<(StrBuf, Vec<StrBuf>)> {
|
||||
let args: Vec<StrBuf> = args.tail().iter().map(|a| a.to_strbuf()).collect();
|
||||
fn process(args: Vec<String>) -> CLIResult<(String, Vec<String>)> {
|
||||
let args: Vec<String> = Vec::from_slice(args.tail());
|
||||
let head = try!(args.iter().nth(0).to_result(|_| CLIError::new("No subcommand found", None::<&str>, 1))).to_owned();
|
||||
let tail = Vec::from_slice(args.tail());
|
||||
|
||||
Ok((head.to_strbuf(), tail))
|
||||
Ok((head, tail))
|
||||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
struct ConfigOut {
|
||||
values: collections::HashMap<StrBuf, config::ConfigValue>
|
||||
values: collections::HashMap<String, config::ConfigValue>
|
||||
}
|
||||
|
||||
#[deriving(Decodable)]
|
||||
struct ConfigForKeyFlags {
|
||||
key: StrBuf,
|
||||
key: String,
|
||||
human: bool
|
||||
}
|
||||
|
||||
|
@ -128,5 +128,5 @@ fn locate_project(_: NoFlags) -> CLIResult<Option<ProjectLocation>> {
|
|||
let string = try!(root.as_str().to_result(|_|
|
||||
CLIError::new(format!("Your project path contains characters not representable in Unicode: {}", os::getcwd().display()), None::<&str>, 1)));
|
||||
|
||||
Ok(Some(ProjectLocation { root: string.to_strbuf() }))
|
||||
Ok(Some(ProjectLocation { root: string.to_str() }))
|
||||
}
|
||||
|
|
|
@ -4,28 +4,28 @@ use util::CargoResult;
|
|||
|
||||
#[deriving(Eq,Clone,Show)]
|
||||
pub struct Dependency {
|
||||
name: StrBuf,
|
||||
name: String,
|
||||
req: VersionReq
|
||||
}
|
||||
|
||||
impl Dependency {
|
||||
pub fn new(name: &str, req: &VersionReq) -> Dependency {
|
||||
Dependency {
|
||||
name: name.to_strbuf(),
|
||||
name: name.to_str(),
|
||||
req: req.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(name: &str, version: &str) -> CargoResult<Dependency> {
|
||||
Ok(Dependency {
|
||||
name: name.to_strbuf(),
|
||||
name: name.to_str(),
|
||||
req: try!(VersionReq::parse(version))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn exact(name: &str, version: &Version) -> Dependency {
|
||||
Dependency {
|
||||
name: name.to_strbuf(),
|
||||
name: name.to_str(),
|
||||
req: VersionReq::exact(version)
|
||||
}
|
||||
}
|
||||
|
@ -41,15 +41,15 @@ impl Dependency {
|
|||
|
||||
#[deriving(Eq,Clone,Encodable)]
|
||||
pub struct SerializedDependency {
|
||||
name: StrBuf,
|
||||
req: StrBuf
|
||||
name: String,
|
||||
req: String
|
||||
}
|
||||
|
||||
impl SerializedDependency {
|
||||
pub fn from_dependency(dep: &Dependency) -> SerializedDependency {
|
||||
SerializedDependency {
|
||||
name: dep.get_name().to_strbuf(),
|
||||
req: format_strbuf!("{}", dep.get_version_req())
|
||||
name: dep.get_name().to_str(),
|
||||
req: dep.get_version_req().to_str()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,15 +24,15 @@ impl Show for CargoError {
|
|||
}
|
||||
|
||||
pub struct CLIError {
|
||||
pub msg: StrBuf,
|
||||
pub detail: Option<StrBuf>,
|
||||
pub msg: String,
|
||||
pub detail: Option<String>,
|
||||
pub exit_code: uint
|
||||
}
|
||||
|
||||
impl CLIError {
|
||||
pub fn new<T: Show, U: Show>(msg: T, detail: Option<U>, exit_code: uint) -> CLIError {
|
||||
let detail = detail.map(|d| format_strbuf!("{}", d));
|
||||
CLIError { msg: format_strbuf!("{}", msg), detail: detail, exit_code: exit_code }
|
||||
let detail = detail.map(|d| d.to_str());
|
||||
CLIError { msg: msg.to_str(), detail: detail, exit_code: exit_code }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,11 +43,11 @@ impl Show for CLIError {
|
|||
}
|
||||
|
||||
pub enum InternalError {
|
||||
StringConversionError(StrBuf, &'static str),
|
||||
MissingManifest(Path, StrBuf),
|
||||
StringConversionError(String, &'static str),
|
||||
MissingManifest(Path, String),
|
||||
WrappedIoError(IoError),
|
||||
PathError(StrBuf),
|
||||
Described(StrBuf),
|
||||
PathError(String),
|
||||
Described(String),
|
||||
Other
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ impl Show for InternalError {
|
|||
}
|
||||
|
||||
impl CargoError {
|
||||
pub fn cli(msg: StrBuf, detail: Option<StrBuf>, exit_code: uint) -> CargoError {
|
||||
pub fn cli(msg: String, detail: Option<String>, exit_code: uint) -> CargoError {
|
||||
CargoCLIError(CLIError::new(msg, detail, exit_code))
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ impl CargoError {
|
|||
}
|
||||
|
||||
pub fn described<T: Show>(description: T) -> CargoError {
|
||||
CargoInternalError(Described(format_strbuf!("{}", description)))
|
||||
CargoInternalError(Described(description.to_str()))
|
||||
}
|
||||
|
||||
pub fn other() -> CargoError {
|
||||
|
|
|
@ -15,7 +15,7 @@ use util::CargoResult;
|
|||
#[deriving(Eq,Clone)]
|
||||
pub struct Manifest {
|
||||
summary: Summary,
|
||||
authors: Vec<StrBuf>,
|
||||
authors: Vec<String>,
|
||||
targets: Vec<Target>,
|
||||
target_dir: Path,
|
||||
}
|
||||
|
@ -28,23 +28,23 @@ impl Show for Manifest {
|
|||
|
||||
#[deriving(Eq,Clone,Encodable)]
|
||||
pub struct SerializedManifest {
|
||||
name: StrBuf,
|
||||
version: StrBuf,
|
||||
name: String,
|
||||
version: String,
|
||||
dependencies: Vec<SerializedDependency>,
|
||||
authors: Vec<StrBuf>,
|
||||
authors: Vec<String>,
|
||||
targets: Vec<Target>,
|
||||
target_dir: StrBuf
|
||||
target_dir: String
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>> Encodable<S, E> for Manifest {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
SerializedManifest {
|
||||
name: self.summary.get_name().to_strbuf(),
|
||||
version: format_strbuf!("{}", self.summary.get_version()),
|
||||
name: self.summary.get_name().to_str(),
|
||||
version: self.summary.get_version().to_str(),
|
||||
dependencies: self.summary.get_dependencies().iter().map(|d| SerializedDependency::from_dependency(d)).collect(),
|
||||
authors: self.authors.clone(),
|
||||
targets: self.targets.clone(),
|
||||
target_dir: self.target_dir.as_str().unwrap().to_strbuf()
|
||||
target_dir: self.target_dir.display().to_str()
|
||||
}.encode(s)
|
||||
}
|
||||
}
|
||||
|
@ -58,15 +58,15 @@ pub enum TargetKind {
|
|||
#[deriving(Clone,Eq)]
|
||||
pub struct Target {
|
||||
kind: TargetKind,
|
||||
name: StrBuf,
|
||||
name: String,
|
||||
path: Path
|
||||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct SerializedTarget {
|
||||
kind: &'static str,
|
||||
name: StrBuf,
|
||||
path: StrBuf
|
||||
name: String,
|
||||
path: String
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>> Encodable<S, E> for Target {
|
||||
|
@ -79,7 +79,7 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Target {
|
|||
SerializedTarget {
|
||||
kind: kind,
|
||||
name: self.name.clone(),
|
||||
path: self.path.as_str().unwrap().to_strbuf()
|
||||
path: self.path.display().to_str()
|
||||
}.encode(s)
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ impl Manifest {
|
|||
self.get_summary().get_name_ver().get_version()
|
||||
}
|
||||
|
||||
pub fn get_authors<'a>(&'a self) -> &'a [StrBuf] {
|
||||
pub fn get_authors<'a>(&'a self) -> &'a [String] {
|
||||
self.authors.as_slice()
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ impl Target {
|
|||
pub fn lib_target(name: &str, path: &Path) -> Target {
|
||||
Target {
|
||||
kind: LibTarget,
|
||||
name: name.to_strbuf(),
|
||||
name: name.to_str(),
|
||||
path: path.clone()
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ impl Target {
|
|||
pub fn bin_target(name: &str, path: &Path) -> Target {
|
||||
Target {
|
||||
kind: BinTarget,
|
||||
name: name.to_strbuf(),
|
||||
name: name.to_str(),
|
||||
path: path.clone()
|
||||
}
|
||||
}
|
||||
|
@ -169,9 +169,9 @@ type TomlExecTarget = TomlTarget;
|
|||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Show)]
|
||||
pub struct Project {
|
||||
pub name: StrBuf,
|
||||
pub version: StrBuf,
|
||||
pub authors: Vec<StrBuf>
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub authors: Vec<String>
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -183,7 +183,7 @@ pub struct TomlManifest {
|
|||
project: Box<Project>,
|
||||
lib: Option<~[TomlLibTarget]>,
|
||||
bin: Option<~[TomlExecTarget]>,
|
||||
dependencies: Option<HashMap<StrBuf, StrBuf>>
|
||||
dependencies: Option<HashMap<String, String>>
|
||||
}
|
||||
|
||||
impl TomlManifest {
|
||||
|
@ -226,18 +226,18 @@ impl Project {
|
|||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone)]
|
||||
struct TomlTarget {
|
||||
name: StrBuf,
|
||||
path: Option<StrBuf>
|
||||
name: String,
|
||||
path: Option<String>
|
||||
}
|
||||
|
||||
fn normalize(lib: &Option<~[TomlLibTarget]>, bin: &Option<~[TomlExecTarget]>) -> Vec<Target> {
|
||||
fn lib_targets(dst: &mut Vec<Target>, libs: &[TomlLibTarget]) {
|
||||
let l = &libs[0];
|
||||
let path = l.path.clone().unwrap_or_else(|| format_strbuf!("src/{}.rs", l.name));
|
||||
let path = l.path.clone().unwrap_or_else(|| format!("src/{}.rs", l.name));
|
||||
dst.push(Target::lib_target(l.name.as_slice(), &Path::new(path)));
|
||||
}
|
||||
|
||||
fn bin_targets(dst: &mut Vec<Target>, bins: &[TomlExecTarget], default: |&TomlExecTarget| -> StrBuf) {
|
||||
fn bin_targets(dst: &mut Vec<Target>, bins: &[TomlExecTarget], default: |&TomlExecTarget| -> String) {
|
||||
for bin in bins.iter() {
|
||||
let path = bin.path.clone().unwrap_or_else(|| default(bin));
|
||||
dst.push(Target::bin_target(bin.name.as_slice(), &Path::new(path)));
|
||||
|
@ -249,13 +249,13 @@ fn normalize(lib: &Option<~[TomlLibTarget]>, bin: &Option<~[TomlExecTarget]>) ->
|
|||
match (lib, bin) {
|
||||
(&Some(ref libs), &Some(ref bins)) => {
|
||||
lib_targets(&mut ret, libs.as_slice());
|
||||
bin_targets(&mut ret, bins.as_slice(), |bin| format_strbuf!("src/bin/{}.rs", bin.name));
|
||||
bin_targets(&mut ret, bins.as_slice(), |bin| format!("src/bin/{}.rs", bin.name));
|
||||
},
|
||||
(&Some(ref libs), &None) => {
|
||||
lib_targets(&mut ret, libs.as_slice());
|
||||
},
|
||||
(&None, &Some(ref bins)) => {
|
||||
bin_targets(&mut ret, bins.as_slice(), |bin| format_strbuf!("src/{}.rs", bin.name));
|
||||
bin_targets(&mut ret, bins.as_slice(), |bin| format!("src/{}.rs", bin.name));
|
||||
},
|
||||
(&None, &None) => ()
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ use serialize::{
|
|||
|
||||
#[deriving(Clone,Eq,Ord)]
|
||||
pub struct NameVer {
|
||||
name: StrBuf,
|
||||
name: String,
|
||||
version: semver::Version
|
||||
}
|
||||
|
||||
impl NameVer {
|
||||
pub fn new(name: &str, version: &str) -> NameVer {
|
||||
NameVer { name: name.to_strbuf(), version: semver::parse(version.to_owned()).unwrap() }
|
||||
NameVer { name: name.to_str(), version: semver::parse(version.as_slice()).unwrap() }
|
||||
}
|
||||
|
||||
pub fn get_name<'a>(&'a self) -> &'a str {
|
||||
|
@ -36,13 +36,13 @@ impl Show for NameVer {
|
|||
|
||||
impl<E, D: Decoder<E>> Decodable<D,E> for NameVer {
|
||||
fn decode(d: &mut D) -> Result<NameVer, E> {
|
||||
let vector: Vec<StrBuf> = try!(Decodable::decode(d));
|
||||
let vector: Vec<String> = try!(Decodable::decode(d));
|
||||
Ok(NameVer { name: vector.get(0).clone(), version: semver::parse(vector.get(1).as_slice()).unwrap() })
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>> Encodable<S,E> for NameVer {
|
||||
fn encode(&self, e: &mut S) -> Result<(), E> {
|
||||
(vec!(self.name.clone(), format_strbuf!("{}", self.version))).encode(e)
|
||||
(vec!(self.name.clone(), self.version.to_str())).encode(e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ pub struct Package {
|
|||
|
||||
#[deriving(Encodable)]
|
||||
struct SerializedPackage {
|
||||
name: StrBuf,
|
||||
version: StrBuf,
|
||||
name: String,
|
||||
version: String,
|
||||
dependencies: Vec<SerializedDependency>,
|
||||
authors: Vec<StrBuf>,
|
||||
authors: Vec<String>,
|
||||
targets: Vec<Target>,
|
||||
root: StrBuf
|
||||
root: String
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>> Encodable<S, E> for Package {
|
||||
|
@ -38,12 +38,12 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Package {
|
|||
let name_ver = summary.get_name_ver();
|
||||
|
||||
SerializedPackage {
|
||||
name: name_ver.get_name().to_strbuf(),
|
||||
version: format_strbuf!("{}", name_ver.get_version()),
|
||||
name: name_ver.get_name().to_str(),
|
||||
version: name_ver.get_version().to_str(),
|
||||
dependencies: summary.get_dependencies().iter().map(|d| SerializedDependency::from_dependency(d)).collect(),
|
||||
authors: Vec::from_slice(manifest.get_authors()),
|
||||
targets: Vec::from_slice(manifest.get_targets()),
|
||||
root: self.root.as_str().unwrap().to_strbuf()
|
||||
root: self.root.display().to_str()
|
||||
}.encode(s)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,14 +36,14 @@ impl Summary {
|
|||
}
|
||||
|
||||
pub trait SummaryVec {
|
||||
fn names(&self) -> Vec<StrBuf>;
|
||||
fn names(&self) -> Vec<String>;
|
||||
fn deps(&self) -> Vec<Dependency>;
|
||||
}
|
||||
|
||||
impl SummaryVec for Vec<Summary> {
|
||||
// TODO: Move to Registery
|
||||
fn names(&self) -> Vec<StrBuf> {
|
||||
self.iter().map(|summary| summary.name_ver.get_name().to_strbuf()).collect()
|
||||
// TODO: Move to Registry
|
||||
fn names(&self) -> Vec<String> {
|
||||
self.iter().map(|summary| summary.name_ver.get_name().to_str()).collect()
|
||||
}
|
||||
|
||||
// TODO: Delete
|
||||
|
|
|
@ -89,8 +89,8 @@ pub fn handle_error(err: CLIError) {
|
|||
std::os::set_exit_status(exit_code as int);
|
||||
}
|
||||
|
||||
fn args() -> Vec<StrBuf> {
|
||||
std::os::args().iter().map(|a| a.to_strbuf()).collect()
|
||||
fn args() -> Vec<String> {
|
||||
std::os::args()
|
||||
}
|
||||
|
||||
fn flags_from_args<T: RepresentsFlags>() -> CLIResult<T> {
|
||||
|
@ -102,7 +102,7 @@ fn json_from_stdin<T: RepresentsJSON>() -> CLIResult<T> {
|
|||
let mut reader = io::stdin();
|
||||
let input = try!(reader.read_to_str().to_result(|_| CLIError::new("Standard in did not exist or was not UTF-8", None::<&str>, 1)));
|
||||
|
||||
let json = try!(json::from_str(input).to_result(|_| CLIError::new("Could not parse standard in as JSON", Some(input.to_strbuf()), 1)));
|
||||
let json = try!(json::from_str(input.as_slice()).to_result(|_| CLIError::new("Could not parse standard in as JSON", Some(input.clone()), 1)));
|
||||
let mut decoder = json::Decoder::new(json);
|
||||
|
||||
Decodable::decode(&mut decoder).to_result(|e: json::DecoderError| CLIError::new("Could not process standard in as input", Some(e), 1))
|
||||
|
|
|
@ -30,7 +30,7 @@ pub fn compile(manifest_path: &str) -> CargoResult<()> {
|
|||
|
||||
let configs = try!(config::all_configs(os::getcwd()));
|
||||
|
||||
let config_paths = configs.find(&"paths".to_strbuf()).map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
|
||||
let config_paths = configs.find_equiv(&"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
|
||||
|
||||
let mut paths: Vec<Path> = match config_paths.get_value() {
|
||||
&config::String(_) => return Err(other_error("The path was configured as a String instead of a List")),
|
||||
|
|
|
@ -6,10 +6,10 @@ use util::{toml_error,human_error,CargoResult,CargoError};
|
|||
|
||||
pub fn read_manifest(path: &str) -> CargoResult<Package> {
|
||||
let root = try!(parse_from_file(path).map_err(|err: CargoError|
|
||||
human_error("Cargo.toml is not valid Toml".to_strbuf(), format_strbuf!("path={}", path), err)));
|
||||
human_error("Cargo.toml is not valid Toml".to_str(), format!("path={}", path), err)));
|
||||
|
||||
let toml = try!(load_toml(root).map_err(|err: CargoError|
|
||||
human_error("Cargo.toml is not a valid Cargo manifest".to_strbuf(), format_strbuf!("path={}", path), err)));
|
||||
human_error("Cargo.toml is not a valid Cargo manifest".to_str(), format!("path={}", path), err)));
|
||||
|
||||
toml.to_package(path)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use util;
|
|||
use util::{other_error,human_error,CargoResult,CargoError,ProcessBuilder};
|
||||
use util::result::ProcessError;
|
||||
|
||||
type Args = Vec<StrBuf>;
|
||||
type Args = Vec<String>;
|
||||
|
||||
pub fn compile_packages(pkgs: &core::PackageSet) -> CargoResult<()> {
|
||||
let mut sorted = match pkgs.sort() {
|
||||
|
@ -69,33 +69,39 @@ fn prepare_rustc(root: &Path, target: &core::Target, dest: &Path, deps: &[core::
|
|||
}
|
||||
|
||||
fn build_base_args(into: &mut Args, target: &core::Target, dest: &Path) {
|
||||
into.push(target.get_path().as_str().unwrap().to_strbuf());
|
||||
into.push("--crate-type".to_strbuf());
|
||||
into.push(target.rustc_crate_type().to_strbuf());
|
||||
into.push("--out-dir".to_strbuf());
|
||||
into.push(dest.as_str().unwrap().to_strbuf());
|
||||
// TODO: Handle errors in converting paths into args
|
||||
into.push(target.get_path().display().to_str());
|
||||
into.push("--crate-type".to_str());
|
||||
into.push(target.rustc_crate_type().to_str());
|
||||
into.push("--out-dir".to_str());
|
||||
into.push(dest.display().to_str());
|
||||
}
|
||||
|
||||
fn build_deps_args(dst: &mut Args, deps: &[core::Package]) {
|
||||
for dep in deps.iter() {
|
||||
let dir = dep.get_absolute_target_dir();
|
||||
|
||||
dst.push("-L".to_strbuf());
|
||||
dst.push(dir.as_str().unwrap().to_strbuf());
|
||||
dst.push("-L".to_str());
|
||||
dst.push(dir.display().to_str());
|
||||
}
|
||||
}
|
||||
|
||||
fn rustc_to_cargo_err(args: &[StrBuf], cwd: &Path, err: CargoError) -> CargoError {
|
||||
fn rustc_to_cargo_err(args: &[String], cwd: &Path, err: CargoError) -> CargoError {
|
||||
let msg = {
|
||||
let output = match err {
|
||||
CargoError { kind: ProcessError(_, ref output), .. } => output,
|
||||
_ => fail!("Bug! exec() returned an error other than a ProcessError")
|
||||
};
|
||||
|
||||
let mut msg = StrBuf::from_str(format!("failed to execute: `rustc {}`", args.connect(" ")));
|
||||
output.as_ref().map(|o| msg.push_str(format!("; Error:\n{}", str::from_utf8_lossy(o.error.as_slice()))));
|
||||
let mut msg = format!("failed to execute: `rustc {}`", args.connect(" "));
|
||||
|
||||
output.as_ref().map(|o| {
|
||||
let second = format!("; Error:\n{}", str::from_utf8_lossy(o.error.as_slice()));
|
||||
msg.push_str(second.as_slice());
|
||||
});
|
||||
|
||||
msg
|
||||
};
|
||||
|
||||
human_error(msg, format_strbuf!("root={}", cwd.display()), err)
|
||||
human_error(msg, format!("root={}", cwd.display()), err)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
use url::Url;
|
||||
use util::{CargoResult,ProcessBuilder,io_error,human_error,process};
|
||||
use std::str;
|
||||
|
@ -7,21 +9,21 @@ use serialize::{Encodable,Encoder};
|
|||
|
||||
macro_rules! git(
|
||||
($config:expr, $str:expr, $($rest:expr),*) => (
|
||||
try!(git_inherit(&$config, format_strbuf!($str, $($rest),*)))
|
||||
try!(git_inherit(&$config, format!($str, $($rest),*)))
|
||||
);
|
||||
|
||||
($config:expr, $str:expr) => (
|
||||
try!(git_inherit(&$config, format_strbuf!($str)))
|
||||
try!(git_inherit(&$config, format!($str)))
|
||||
);
|
||||
)
|
||||
|
||||
macro_rules! git_output(
|
||||
($config:expr, $str:expr, $($rest:expr),*) => (
|
||||
try!(git_output(&$config, format_strbuf!($str, $($rest),*)))
|
||||
try!(git_output(&$config, format!($str, $($rest),*)))
|
||||
);
|
||||
|
||||
($config:expr, $str:expr) => (
|
||||
try!(git_output(&$config, format_strbuf!($str)))
|
||||
try!(git_output(&$config, format!($str)))
|
||||
);
|
||||
)
|
||||
|
||||
|
@ -29,21 +31,21 @@ macro_rules! git_output(
|
|||
struct GitConfig {
|
||||
path: Path,
|
||||
uri: Url,
|
||||
reference: StrBuf
|
||||
reference: String
|
||||
}
|
||||
|
||||
#[deriving(Eq,Clone,Encodable)]
|
||||
struct EncodableGitConfig {
|
||||
path: StrBuf,
|
||||
uri: StrBuf,
|
||||
reference: StrBuf
|
||||
path: String,
|
||||
uri: String,
|
||||
reference: String
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>> Encodable<S, E> for GitConfig {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
EncodableGitConfig {
|
||||
path: format_strbuf!("{}", self.path.display()),
|
||||
uri: format_strbuf!("{}", self.uri),
|
||||
path: self.path.display().to_str(),
|
||||
uri: self.uri.to_str(),
|
||||
reference: self.reference.clone()
|
||||
}.encode(s)
|
||||
}
|
||||
|
@ -57,11 +59,11 @@ pub struct GitCommand {
|
|||
#[deriving(Eq,Clone,Encodable)]
|
||||
pub struct GitRepo {
|
||||
config: GitConfig,
|
||||
revision: StrBuf
|
||||
revision: String
|
||||
}
|
||||
|
||||
impl GitCommand {
|
||||
pub fn new(path: Path, uri: Url, reference: StrBuf) -> GitCommand {
|
||||
pub fn new(path: Path, uri: Url, reference: String) -> GitCommand {
|
||||
GitCommand { config: GitConfig { path: path, uri: uri, reference: reference } }
|
||||
}
|
||||
|
||||
|
@ -76,7 +78,7 @@ impl GitCommand {
|
|||
checkout_config.path = dirname;
|
||||
|
||||
try!(mkdir_recursive(&checkout_config.path, UserDir).map_err(|err|
|
||||
human_error(format_strbuf!("Couldn't recursively create `{}`", checkout_config.path.display()), format_strbuf!("path={}", checkout_config.path.display()), io_error(err))));
|
||||
human_error(format!("Couldn't recursively create `{}`", checkout_config.path.display()), format!("path={}", checkout_config.path.display()), io_error(err))));
|
||||
|
||||
git!(checkout_config, "clone {} {} --bare --no-hardlinks --quiet", config.uri, config.path.display());
|
||||
}
|
||||
|
@ -86,6 +88,7 @@ impl GitCommand {
|
|||
}
|
||||
|
||||
impl GitRepo {
|
||||
#[allow(unused_variable)]
|
||||
fn copy_to(destination: &Path) -> CargoResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -107,7 +110,7 @@ impl GitRepo {
|
|||
}
|
||||
}
|
||||
|
||||
fn rev_for(config: &GitConfig) -> CargoResult<StrBuf> {
|
||||
fn rev_for(config: &GitConfig) -> CargoResult<String> {
|
||||
Ok(git_output!(*config, "rev-parse {}", config.reference))
|
||||
}
|
||||
|
||||
|
@ -116,18 +119,18 @@ fn git(config: &GitConfig, str: &str) -> ProcessBuilder {
|
|||
process("git").args(str.split(' ').collect::<Vec<&str>>().as_slice()).cwd(config.path.clone())
|
||||
}
|
||||
|
||||
fn git_inherit(config: &GitConfig, str: StrBuf) -> CargoResult<()> {
|
||||
fn git_inherit(config: &GitConfig, str: String) -> CargoResult<()> {
|
||||
git(config, str.as_slice()).exec().map_err(|err|
|
||||
human_error(format_strbuf!("Couldn't execute `git {}`: {}", str, err), None::<&str>, err))
|
||||
human_error(format!("Couldn't execute `git {}`: {}", str, err), None::<&str>, err))
|
||||
}
|
||||
|
||||
fn git_output(config: &GitConfig, str: StrBuf) -> CargoResult<StrBuf> {
|
||||
fn git_output(config: &GitConfig, str: String) -> CargoResult<String> {
|
||||
let output = try!(git(config, str.as_slice()).exec_with_output().map_err(|err|
|
||||
human_error(format_strbuf!("Couldn't execute `git {}`", str), None::<&str>, err)));
|
||||
human_error(format!("Couldn't execute `git {}`", str), None::<&str>, err)));
|
||||
|
||||
Ok(to_str(output.output.as_slice()))
|
||||
}
|
||||
|
||||
fn to_str(vec: &[u8]) -> StrBuf {
|
||||
format_strbuf!("{}", str::from_utf8_lossy(vec))
|
||||
fn to_str(vec: &[u8]) -> String {
|
||||
str::from_utf8_lossy(vec).to_str()
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ pub enum Location {
|
|||
|
||||
#[deriving(Eq,TotalEq,Clone,Decodable)]
|
||||
pub enum ConfigValueValue {
|
||||
String(StrBuf),
|
||||
List(Vec<StrBuf>)
|
||||
String(String),
|
||||
List(Vec<String>)
|
||||
}
|
||||
|
||||
impl fmt::Show for ConfigValueValue {
|
||||
|
@ -68,7 +68,7 @@ impl<E, S: Encoder<E>> Encodable<S, E> for ConfigValue {
|
|||
|
||||
impl fmt::Show for ConfigValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let paths: Vec<StrBuf> = self.path.iter().map(|p| format_strbuf!("{}", p.display())).collect();
|
||||
let paths: Vec<String> = self.path.iter().map(|p| p.display().to_str()).collect();
|
||||
write!(f, "{} (from {})", self.value, paths)
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ pub fn get_config(pwd: Path, key: &str) -> CargoResult<ConfigValue> {
|
|||
.map_err(|_| other_error("config key not found").with_detail(format!("key={}", key)))
|
||||
}
|
||||
|
||||
pub fn all_configs(pwd: Path) -> CargoResult<HashMap<StrBuf, ConfigValue>> {
|
||||
pub fn all_configs(pwd: Path) -> CargoResult<HashMap<String, ConfigValue>> {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
try!(walk_tree(&pwd, |file| {
|
||||
|
@ -89,7 +89,7 @@ pub fn all_configs(pwd: Path) -> CargoResult<HashMap<StrBuf, ConfigValue>> {
|
|||
}
|
||||
|
||||
#[allow(unused_variable)]
|
||||
pub fn set_config(key: StrBuf, value: StrBuf, location: Location) -> CargoResult<()> {
|
||||
pub fn set_config(key: String, value: String, location: Location) -> CargoResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -141,14 +141,14 @@ fn extract_config(file: io::fs::File, key: &str) -> CargoResult<ConfigValue> {
|
|||
|
||||
let v = match val {
|
||||
&toml::String(ref val) => String(val.clone()),
|
||||
&toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| format_strbuf!("{}", s)).collect()),
|
||||
&toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| s.to_str()).collect()),
|
||||
_ => return Err(other_error(""))
|
||||
};
|
||||
|
||||
Ok(ConfigValue{ value: v, path: vec!(path) })
|
||||
}
|
||||
|
||||
fn extract_all_configs(file: io::fs::File, map: &mut HashMap<StrBuf, ConfigValue>) -> CargoResult<()> {
|
||||
fn extract_all_configs(file: io::fs::File, map: &mut HashMap<String, ConfigValue>) -> CargoResult<()> {
|
||||
let path = file.path().clone();
|
||||
let mut buf = io::BufferedReader::new(file);
|
||||
let root = try!(toml::parse_from_buffer(&mut buf).map_err(|err|
|
||||
|
@ -179,11 +179,11 @@ fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &Path) ->
|
|||
match existing.value {
|
||||
String(_) => return Err(other_error("should be an Array, but it was a String")),
|
||||
List(ref mut list) => {
|
||||
let new_list: Vec<CargoResult<StrBuf>> = val.iter().map(|s: &toml::Value| toml_string(s)).collect();
|
||||
let new_list: Vec<CargoResult<String>> = val.iter().map(|s: &toml::Value| toml_string(s)).collect();
|
||||
if new_list.iter().any(|v| v.is_err()) {
|
||||
return Err(other_error("should be an Array of Strings, but was an Array of other values"));
|
||||
} else {
|
||||
let new_list: Vec<StrBuf> = new_list.move_iter().map(|v| v.unwrap()).collect();
|
||||
let new_list: Vec<String> = new_list.move_iter().map(|v| v.unwrap()).collect();
|
||||
list.push_all(new_list.as_slice());
|
||||
existing.path.push(path.clone());
|
||||
Ok(())
|
||||
|
@ -192,7 +192,7 @@ fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &Path) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn toml_string(val: &toml::Value) -> CargoResult<StrBuf> {
|
||||
fn toml_string(val: &toml::Value) -> CargoResult<String> {
|
||||
match val {
|
||||
&toml::String(ref str) => Ok(str.clone()),
|
||||
_ => Err(other_error(""))
|
||||
|
|
|
@ -8,10 +8,10 @@ use collections::HashMap;
|
|||
|
||||
#[deriving(Clone,Eq)]
|
||||
pub struct ProcessBuilder {
|
||||
program: StrBuf,
|
||||
args: Vec<StrBuf>,
|
||||
path: Vec<StrBuf>,
|
||||
env: HashMap<StrBuf, StrBuf>,
|
||||
program: String,
|
||||
args: Vec<String>,
|
||||
path: Vec<String>,
|
||||
env: HashMap<String, String>,
|
||||
cwd: Path
|
||||
}
|
||||
|
||||
|
@ -32,17 +32,17 @@ static PATH_SEP : &'static str = ":";
|
|||
|
||||
impl ProcessBuilder {
|
||||
pub fn args<T: Show>(mut self, arguments: &[T]) -> ProcessBuilder {
|
||||
self.args = arguments.iter().map(|a| format_strbuf!("{}", a)).collect();
|
||||
self.args = arguments.iter().map(|a| a.to_str()).collect();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_args<'a>(&'a self) -> &'a [StrBuf] {
|
||||
pub fn get_args<'a>(&'a self) -> &'a [String] {
|
||||
self.args.as_slice()
|
||||
}
|
||||
|
||||
pub fn extra_path(mut self, path: Path) -> ProcessBuilder {
|
||||
// For now, just convert to a string, but we should do something better
|
||||
self.path.push(format_strbuf!("{}", path.display()));
|
||||
self.path.push(path.display().to_str());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ impl ProcessBuilder {
|
|||
if exit.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
let msg = format_strbuf!("Could not execute process `{}`", self.debug_string());
|
||||
let msg = format!("Could not execute process `{}`", self.debug_string());
|
||||
Err(process_error(msg, exit, None))
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ impl ProcessBuilder {
|
|||
if output.status.success() {
|
||||
Ok(output)
|
||||
} else {
|
||||
let msg = format_strbuf!("Could not execute process `{}`", self.debug_string());
|
||||
let msg = format!("Could not execute process `{}`", self.debug_string());
|
||||
Err(process_error(msg, output.status.clone(), Some(output)))
|
||||
}
|
||||
}
|
||||
|
@ -89,11 +89,11 @@ impl ProcessBuilder {
|
|||
command
|
||||
}
|
||||
|
||||
fn debug_string(&self) -> StrBuf {
|
||||
format_strbuf!("{} {}", self.program, self.args.connect(" "))
|
||||
fn debug_string(&self) -> String {
|
||||
format!("{} {}", self.program, self.args.connect(" "))
|
||||
}
|
||||
|
||||
fn build_env(&self) -> ~[(StrBuf, StrBuf)] {
|
||||
fn build_env(&self) -> ~[(String, String)] {
|
||||
let mut ret = Vec::new();
|
||||
|
||||
for (key, val) in self.env.iter() {
|
||||
|
@ -104,14 +104,14 @@ impl ProcessBuilder {
|
|||
}
|
||||
|
||||
match self.build_path() {
|
||||
Some(path) => ret.push(("PATH".to_strbuf(), path)),
|
||||
Some(path) => ret.push(("PATH".to_str(), path)),
|
||||
_ => ()
|
||||
}
|
||||
|
||||
ret.as_slice().to_owned()
|
||||
}
|
||||
|
||||
fn build_path(&self) -> Option<StrBuf> {
|
||||
fn build_path(&self) -> Option<String> {
|
||||
let path = self.path.connect(PATH_SEP);
|
||||
|
||||
match self.env.find_equiv(&("PATH")) {
|
||||
|
@ -119,14 +119,14 @@ impl ProcessBuilder {
|
|||
if self.path.is_empty() {
|
||||
Some(existing.clone())
|
||||
} else {
|
||||
Some(format_strbuf!("{}{}{}", existing, PATH_SEP, path))
|
||||
Some(format!("{}{}{}", existing, PATH_SEP, path))
|
||||
}
|
||||
},
|
||||
None => {
|
||||
if self.path.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(path.to_strbuf())
|
||||
Some(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ impl ProcessBuilder {
|
|||
|
||||
pub fn process(cmd: &str) -> ProcessBuilder {
|
||||
ProcessBuilder {
|
||||
program: cmd.to_strbuf(),
|
||||
program: cmd.to_str(),
|
||||
args: vec!(),
|
||||
path: vec!(),
|
||||
cwd: os::getcwd(),
|
||||
|
@ -143,11 +143,11 @@ pub fn process(cmd: &str) -> ProcessBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
fn system_env() -> HashMap<StrBuf, StrBuf> {
|
||||
fn system_env() -> HashMap<String, String> {
|
||||
let mut ret = HashMap::new();
|
||||
|
||||
for &(ref key, ref val) in os::env().iter() {
|
||||
ret.insert(key.to_strbuf(), val.to_strbuf());
|
||||
ret.insert(key.to_str(), val.to_str());
|
||||
}
|
||||
|
||||
ret
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn io_error(err: IoError) -> CargoError {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn process_error(detail: StrBuf, exit: ProcessExit, output: Option<ProcessOutput>) -> CargoError {
|
||||
pub fn process_error(detail: String, exit: ProcessExit, output: Option<ProcessOutput>) -> CargoError {
|
||||
CargoError {
|
||||
kind: ProcessError(exit, output),
|
||||
desc: BoxedDescription(detail),
|
||||
|
@ -45,8 +45,8 @@ pub fn process_error(detail: StrBuf, exit: ProcessExit, output: Option<ProcessOu
|
|||
pub fn human_error<T: ToStr, U: ToStr>(desc: T, detail: U, cause: CargoError) -> CargoError {
|
||||
CargoError {
|
||||
kind: HumanReadableError,
|
||||
desc: BoxedDescription(desc.to_str().to_strbuf()),
|
||||
detail: Some(detail.to_str().to_strbuf()),
|
||||
desc: BoxedDescription(desc.to_str()),
|
||||
detail: Some(detail.to_str()),
|
||||
cause: Some(box cause)
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ pub fn human_error<T: ToStr, U: ToStr>(desc: T, detail: U, cause: CargoError) ->
|
|||
pub fn simple_human<T: Show>(desc: T) -> CargoError {
|
||||
CargoError {
|
||||
kind: HumanReadableError,
|
||||
desc: BoxedDescription(format_strbuf!("{}", desc)),
|
||||
desc: BoxedDescription(desc.to_str()),
|
||||
detail: None,
|
||||
cause: None
|
||||
}
|
||||
|
@ -73,14 +73,14 @@ pub fn toml_error(desc: &'static str, error: toml::Error) -> CargoError {
|
|||
pub struct CargoError {
|
||||
pub kind: CargoErrorKind,
|
||||
desc: CargoErrorDescription,
|
||||
detail: Option<StrBuf>,
|
||||
detail: Option<String>,
|
||||
cause: Option<Box<CargoError>>
|
||||
}
|
||||
|
||||
#[deriving(Show,Clone)]
|
||||
enum CargoErrorDescription {
|
||||
StaticDescription(&'static str),
|
||||
BoxedDescription(StrBuf)
|
||||
BoxedDescription(String)
|
||||
}
|
||||
|
||||
impl CargoError {
|
||||
|
@ -96,20 +96,20 @@ impl CargoError {
|
|||
}
|
||||
|
||||
pub fn with_detail<T: Show>(mut self, detail: T) -> CargoError {
|
||||
self.detail = Some(format_strbuf!("{}", detail));
|
||||
self.detail = Some(detail.to_str());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn to_cli(self, exit_code: uint) -> CLIError {
|
||||
match self {
|
||||
CargoError { kind: HumanReadableError, desc: BoxedDescription(desc), detail: detail, .. } => {
|
||||
CLIError::new(desc, detail.map(|d| d.to_strbuf()), exit_code)
|
||||
CLIError::new(desc, detail, exit_code)
|
||||
},
|
||||
CargoError { kind: InternalError, desc: StaticDescription(desc), detail: None, .. } => {
|
||||
CLIError::new("An unexpected error occurred", Some(desc), exit_code)
|
||||
},
|
||||
CargoError { kind: InternalError, desc: StaticDescription(desc), detail: Some(detail), .. } => {
|
||||
CLIError::new("An unexpected error occurred", Some(format_strbuf!("{}\n{}", desc, detail)), exit_code)
|
||||
CLIError::new("An unexpected error occurred", Some(format!("{}\n{}", desc, detail)), exit_code)
|
||||
},
|
||||
_ => {
|
||||
CLIError::new("An unexpected error occurred", None::<&str>, exit_code)
|
||||
|
@ -164,7 +164,7 @@ pub struct CargoCliError {
|
|||
kind: CargoCliErrorKind,
|
||||
exit_status: uint,
|
||||
desc: &'static str,
|
||||
detail: Option<StrBuf>,
|
||||
detail: Option<String>,
|
||||
cause: Option<CargoError>
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue