Update to Rust master
authorYehuda Katz <wycats@gmail.com>
Tue, 20 May 2014 05:40:50 +0000 (22:40 -0700)
committerYehuda Katz <wycats@gmail.com>
Tue, 20 May 2014 05:40:50 +0000 (22:40 -0700)
19 files changed:
libs/hammer.rs
libs/rust-toml
src/bin/cargo-compile.rs
src/bin/cargo-read-manifest.rs
src/bin/cargo-verify-project.rs
src/bin/cargo.rs
src/cargo/core/dependency.rs
src/cargo/core/errors.rs
src/cargo/core/manifest.rs
src/cargo/core/namever.rs
src/cargo/core/package.rs
src/cargo/core/version_req.rs
src/cargo/lib.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc.rs
src/cargo/sources/path.rs
src/cargo/util/config.rs
src/cargo/util/process_builder.rs
src/cargo/util/result.rs

index da5c02546229eee6fb4305255333515bf8954fdd..c305bcb84ed51d7bd808bc20c09c00a1beb1b087 160000 (submodule)
@@ -1 +1 @@
-Subproject commit da5c02546229eee6fb4305255333515bf8954fdd
+Subproject commit c305bcb84ed51d7bd808bc20c09c00a1beb1b087
index a0f63ba56099404b4ac1db513ad4d4ffd2d1a7c3..0de103ed19997884f2766456f7a003b94f1daa42 160000 (submodule)
@@ -1 +1 @@
-Subproject commit a0f63ba56099404b4ac1db513ad4d4ffd2d1a7c3
+Subproject commit 0de103ed19997884f2766456f7a003b94f1daa42
index 269ec346bd8d9824b59f76fb1cd386b9455c3e8f..208b157920dfc54290b7b6b05d2004b7e8ad1300 100644 (file)
@@ -14,7 +14,7 @@ use std::os;
 
 #[deriving(Eq,Clone,Decodable,Encodable)]
 pub struct Options {
-    manifest_path: Option<~str>
+    manifest_path: Option<StrBuf>
 }
 
 impl FlagConfig for Options {}
index 7aeaa4e42dd6857ca658a42fe5f813c6bbe9267a..01c11dfdf4761f28a71d608a7f015c620f9826f1 100644 (file)
@@ -12,7 +12,7 @@ use cargo::ops::cargo_read_manifest::read_manifest;
 
 #[deriving(Eq,Clone,Decodable)]
 struct Options {
-    manifest_path: ~str
+    manifest_path: StrBuf
 }
 
 impl FlagConfig for Options {}
index d6fe21056a52a13a390025e54256c1233704b223..512ecc75126d7337e9c4244737fa90451f85e708 100644 (file)
@@ -12,7 +12,7 @@ use getopts::{reqopt,getopts};
 */
 
 fn main() {
-    let arguments = args();
+    let arguments: Vec<StrBuf> = args().iter().map(|a| a.to_strbuf()).collect();
 
     let opts = ~[
         reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
index 8c9cb52e12eb320b78661c5968c25fbb91fea5c4..d2e1c46e8fddffd661feae590c5e706556de0307 100644 (file)
@@ -47,12 +47,12 @@ fn process(mut args: Vec<~str>) -> CLIResult<(~str, Vec<~str>)> {
 
 #[deriving(Encodable)]
 struct ConfigOut {
-    values: collections::HashMap<~str, config::ConfigValue>
+    values: collections::HashMap<StrBuf, config::ConfigValue>
 }
 
 #[deriving(Decodable)]
 struct ConfigForKeyFlags {
-    key: ~str,
+    key: StrBuf,
     human: bool
 }
 
index fcffed66d3d7d1f819aff391edfdf7360d796628..c2ec45890ff0eb0f5baab5e62ebe15b124943aaf 100644 (file)
@@ -1,5 +1,5 @@
 use semver::Version;
-use core::{NameVer,VersionReq};
+use core::{VersionReq};
 use util::CargoResult;
 
 #[deriving(Eq,Clone,Show)]
index 2f8517f268a62cb09bc35a22945340449dd52131..a0c8ffe15cb6621fe58c72efe00d4d6c6236733b 100644 (file)
@@ -17,8 +17,8 @@ pub enum CargoError {
 impl Show for CargoError {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
         match self {
-            &CargoInternalError(ref err) => write!(f.buf, "{}", err),
-            &CargoCLIError(ref err) => write!(f.buf, "{}", err)
+            &CargoInternalError(ref err) => write!(f, "{}", err),
+            &CargoCLIError(ref err) => write!(f, "{}", err)
         }
     }
 }
@@ -37,7 +37,7 @@ impl CLIError {
 
 impl Show for CLIError {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        write!(f.buf, "{}", self.msg)
+        write!(f, "{}", self.msg)
     }
 }
 
@@ -54,18 +54,18 @@ impl Show for InternalError {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
         match self {
             &StringConversionError(ref string, ref type_name) => {
-                write!(f.buf, "Couldn't convert `{}` into {}", string, type_name)
+                write!(f, "Couldn't convert `{}` into {}", string, type_name)
             },
             &MissingManifest(ref path, ref file) => {
-                write!(f.buf, "Couldn't find a {} in the project (`{}` or any parent directory", file, path.display())
+                write!(f, "Couldn't find a {} in the project (`{}` or any parent directory", file, path.display())
             },
             &WrappedIoError(ref io_error) => {
-                write!(f.buf, "{}", io_error)
+                write!(f, "{}", io_error)
             },
             &PathError(ref s) | &Described(ref s) => {
-                write!(f.buf, "{}", s)
+                write!(f, "{}", s)
             },
-            &Other => write!(f.buf, "Other internal error")
+            &Other => write!(f, "Other internal error")
         }
     }
 }
index 159483fc2024bf14887974132e26e86b543cdbf6..d94c86c65f2d66d8c9e4668865d4304178bb64db 100644 (file)
@@ -15,36 +15,36 @@ use util::CargoResult;
 #[deriving(Eq,Clone)]
 pub struct Manifest {
     summary: Summary,
-    authors: Vec<~str>,
+    authors: Vec<StrBuf>,
     targets: Vec<Target>,
     target_dir: Path,
 }
 
 impl Show for Manifest {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        write!(f.buf, "Manifest({}, authors={}, targets={}, target_dir={})", self.summary, self.authors, self.targets, self.target_dir.display())
+        write!(f, "Manifest({}, authors={}, targets={}, target_dir={})", self.summary, self.authors, self.targets, self.target_dir.display())
     }
 }
 
 #[deriving(Eq,Clone,Encodable)]
 pub struct SerializedManifest {
-    name: ~str,
-    version: ~str,
+    name: StrBuf,
+    version: StrBuf,
     dependencies: Vec<SerializedDependency>,
-    authors: Vec<~str>,
+    authors: Vec<StrBuf>,
     targets: Vec<Target>,
-    target_dir: ~str
+    target_dir: StrBuf
 }
 
 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_owned(),
-            version: self.summary.get_version().to_str(),
+            name: self.summary.get_name().to_strbuf(),
+            version: format_strbuf!("{}", self.summary.get_version()),
             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_owned()
+            target_dir: self.target_dir.as_str().unwrap().to_strbuf()
         }.encode(s)
     }
 }
@@ -58,15 +58,15 @@ pub enum TargetKind {
 #[deriving(Clone,Eq)]
 pub struct Target {
     kind: TargetKind,
-    name: ~str,
+    name: StrBuf,
     path: Path
 }
 
 #[deriving(Encodable)]
 pub struct SerializedTarget {
     kind: &'static str,
-    name: ~str,
-    path: ~str
+    name: StrBuf,
+    path: StrBuf
 }
 
 impl<E, S: Encoder<E>> Encodable<S, E> for Target {
@@ -79,14 +79,14 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Target {
         SerializedTarget {
             kind: kind,
             name: self.name.clone(),
-            path: self.path.as_str().unwrap().to_owned()
+            path: self.path.as_str().unwrap().to_strbuf()
         }.encode(s)
     }
 }
 
 impl Show for Target {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        write!(f.buf, "{}(name={}, path={})", self.kind, self.name, self.path.display())
+        write!(f, "{}(name={}, path={})", self.kind, self.name, self.path.display())
     }
 }
 
@@ -112,7 +112,7 @@ impl Manifest {
         self.get_summary().get_name_ver().get_version()
     }
 
-    pub fn get_authors<'a>(&'a self) -> &'a [~str] {
+    pub fn get_authors<'a>(&'a self) -> &'a [StrBuf] {
         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_owned(),
+            name: name.to_strbuf(),
             path: path.clone()
         }
     }
@@ -141,7 +141,7 @@ impl Target {
     pub fn bin_target(name: &str, path: &Path) -> Target {
         Target {
             kind: BinTarget,
-            name: name.to_owned(),
+            name: name.to_strbuf(),
             path: path.clone()
         }
     }
@@ -169,9 +169,9 @@ type TomlExecTarget = TomlTarget;
 
 #[deriving(Decodable,Encodable,Eq,Clone,Show)]
 pub struct Project {
-    pub name: ~str,
-    pub version: ~str,
-    pub authors: ~[~str]
+    pub name: StrBuf,
+    pub version: StrBuf,
+    pub authors: Vec<StrBuf>
 }
 
 /*
@@ -183,7 +183,7 @@ pub struct TomlManifest {
     project: Box<Project>,
     lib: Option<~[TomlLibTarget]>,
     bin: Option<~[TomlExecTarget]>,
-    dependencies: Option<HashMap<~str, ~str>>
+    dependencies: Option<HashMap<StrBuf, StrBuf>>
 }
 
 impl TomlManifest {
@@ -200,7 +200,7 @@ impl TomlManifest {
         match self.dependencies {
             Some(ref dependencies) => {
                 for (n, v) in dependencies.iter() {
-                    deps.push(try!(Dependency::parse(*n, *v)));
+                    deps.push(try!(Dependency::parse(n.as_slice(), v.as_slice())));
                 }
             }
             None => ()
@@ -220,27 +220,27 @@ impl TomlManifest {
 
 impl Project {
     fn to_name_ver(&self) -> NameVer {
-        NameVer::new(self.name, self.version)
+        NameVer::new(self.name.as_slice(), self.version.as_slice())
     }
 }
 
 #[deriving(Decodable,Encodable,Eq,Clone)]
 struct TomlTarget {
-    name: ~str,
-    path: Option<~str>
+    name: StrBuf,
+    path: Option<StrBuf>
 }
 
 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!("src/{}.rs", l.name));
-        dst.push(Target::lib_target(l.name, &Path::new(path)));
+        let path = l.path.clone().unwrap_or_else(|| format_strbuf!("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| -> ~str) {
+    fn bin_targets(dst: &mut Vec<Target>, bins: &[TomlExecTarget], default: |&TomlExecTarget| -> StrBuf) {
         for bin in bins.iter() {
             let path = bin.path.clone().unwrap_or_else(|| default(bin));
-            dst.push(Target::bin_target(bin.name.clone(), &Path::new(path)));
+            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!("src/bin/{}.rs", bin.name));
+            bin_targets(&mut ret, bins.as_slice(), |bin| format_strbuf!("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!("src/{}.rs", bin.name));
+            bin_targets(&mut ret, bins.as_slice(), |bin| format_strbuf!("src/{}.rs", bin.name));
         },
         (&None, &None) => ()
     }
index 7f1b13f6978b0ad0c3f28f5b288b88657d24c96c..18b9757194b03d4bc424ba3c7ad685e3c957911f 100644 (file)
@@ -10,13 +10,13 @@ use serialize::{
 
 #[deriving(Clone,Eq,Ord)]
 pub struct NameVer {
-    name: ~str,
+    name: StrBuf,
     version: semver::Version
 }
 
 impl NameVer {
     pub fn new(name: &str, version: &str) -> NameVer {
-        NameVer { name: name.to_owned(), version: semver::parse(version.to_owned()).unwrap() }
+        NameVer { name: name.to_strbuf(), version: semver::parse(version.to_owned()).unwrap() }
     }
 
     pub fn get_name<'a>(&'a self) -> &'a str {
@@ -30,19 +30,19 @@ impl NameVer {
 
 impl Show for NameVer {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        write!(f.buf, "{} v{}", self.name, self.version)
+        write!(f, "{} v{}", self.name, self.version)
     }
 }
 
 impl<E, D: Decoder<E>> Decodable<D,E> for NameVer {
     fn decode(d: &mut D) -> Result<NameVer, E> {
-        let vector: Vec<~str> = try!(Decodable::decode(d));
-        Ok(NameVer { name: vector.get(0).clone(), version: semver::parse(vector.get(1).clone()).unwrap() })
+        let vector: Vec<StrBuf> = 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(), self.version.to_str())).encode(e)
+        (vec!(self.name.clone(), format_strbuf!("{}", self.version))).encode(e)
     }
 }
index 4e1834679b94b6a83814db71205db706c5ea98d3..25174c5b16de7fac5277cb64576534d55fcb4e97 100644 (file)
@@ -26,7 +26,7 @@ struct SerializedPackage {
     name: ~str,
     version: ~str,
     dependencies: Vec<SerializedDependency>,
-    authors: Vec<~str>,
+    authors: Vec<StrBuf>,
     targets: Vec<Target>,
     root: ~str
 }
@@ -95,7 +95,7 @@ impl Package {
 
 impl Show for Package {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        write!(f.buf, "{}", self.get_summary().get_name_ver())
+        write!(f, "{}", self.get_summary().get_name_ver())
     }
 }
 
index 11739a0c54c40d8a853d9a0d673f5043bb584f68..8dfb49ff2efabc8390d7c5cdd7183048a3d697d6 100644 (file)
@@ -420,15 +420,15 @@ fn is_sigil(c: char) -> bool {
 impl fmt::Show for VersionReq {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
         if self.predicates.is_empty() {
-            try!(write!(fmt.buf, "*"));
+            try!(write!(fmt, "*"));
         }
         else {
             for (i, ref pred) in self.predicates.iter().enumerate() {
                 if i == 0 {
-                    try!(write!(fmt.buf, "{}", pred));
+                    try!(write!(fmt, "{}", pred));
                 }
                 else {
-                    try!(write!(fmt.buf, ", {}", pred));
+                    try!(write!(fmt, ", {}", pred));
                 }
             }
         }
@@ -439,15 +439,15 @@ impl fmt::Show for VersionReq {
 
 impl fmt::Show for Predicate {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-        try!(write!(fmt.buf, "{} {}", self.op, self.major));
+        try!(write!(fmt, "{} {}", self.op, self.major));
 
         match self.minor {
-            Some(v) => try!(write!(fmt.buf, ".{}", v)),
+            Some(v) => try!(write!(fmt, ".{}", v)),
             None => ()
         }
 
         match self.patch {
-            Some(v) => try!(write!(fmt.buf, ".{}", v)),
+            Some(v) => try!(write!(fmt, ".{}", v)),
             None => ()
         }
 
@@ -458,11 +458,11 @@ impl fmt::Show for Predicate {
 impl fmt::Show for Op {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
         match *self {
-            Ex => try!(write!(fmt.buf, "=")),
-            Gt => try!(write!(fmt.buf, ">")),
-            GtEq => try!(write!(fmt.buf, ">=")),
-            Lt => try!(write!(fmt.buf, "<")),
-            LtEq => try!(write!(fmt.buf, "<="))
+            Ex => try!(write!(fmt, "=")),
+            Gt => try!(write!(fmt, ">")),
+            GtEq => try!(write!(fmt, ">=")),
+            Lt => try!(write!(fmt, "<")),
+            LtEq => try!(write!(fmt, "<="))
         }
         Ok(())
     }
index aaaa7f60e72292fc54ae92965693cd57e74fbe5e..44d26a9ac760839df15e5f624d01daed42ba43f9 100644 (file)
@@ -68,7 +68,7 @@ pub fn process_executed<'a, T: Encodable<json::Encoder<'a>, io::IoError>>(result
         Err(e) => handle_error(e),
         Ok(encodable) => {
             encodable.map(|encodable| {
-                let encoded: ~str = json::Encoder::str_encode(&encodable);
+                let encoded = json::Encoder::str_encode(&encodable);
                 println!("{}", encoded);
             });
         }
@@ -83,8 +83,12 @@ 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 flags_from_args<T: RepresentsFlags>() -> CLIResult<T> {
-    let mut decoder = FlagDecoder::new::<T>(std::os::args().tail());
+    let mut decoder = FlagDecoder::new::<T>(args().tail());
     Decodable::decode(&mut decoder).to_result(|e: HammerError| CLIError::new(e.message, None, 1))
 }
 
index 919a6b90b97a2859432e42e01f1371d94078a0c2..4febf1f7833863ef9769cf2170662a07e0aa93b0 100644 (file)
@@ -29,7 +29,7 @@ pub fn compile(manifest_path: &str) -> CargoResult<()> {
 
     let configs = try!(config::all_configs(os::getcwd()));
 
-    let config_paths = configs.find(&("paths".to_owned())).map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
+    let config_paths = configs.find(&"paths".to_strbuf()).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")),
index ab9e7acabcbd8f9db8c95023ea964f68bd0baab8..53344a28439dfd23fd9c84ad49f9304671e12624 100644 (file)
@@ -7,7 +7,7 @@ use util;
 use util::{other_error,human_error,CargoResult,CargoError,ProcessBuilder};
 use util::result::ProcessError;
 
-type Args = Vec<~str>;
+type Args = Vec<StrBuf>;
 
 pub fn compile(pkgs: &core::PackageSet) -> CargoResult<()> {
     let mut sorted = match pkgs.sort() {
@@ -52,7 +52,7 @@ fn rustc<T>(root: &Path, target: &core::Target, dest: &Path, deps: &[core::Packa
     let rustc = prepare_rustc(root, target, dest, deps);
 
     try!(exec(&rustc)
-        .map_err(|err| rustc_to_cargo_err(rustc.get_args(), root, err)));
+        .map_err(|err| rustc_to_cargo_err(rustc.get_args().as_slice(), root, err)));
 
     Ok(())
 }
@@ -69,23 +69,23 @@ 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_owned());
-    into.push("--crate-type".to_owned());
-    into.push(target.rustc_crate_type().to_owned());
-    into.push("--out-dir".to_owned());
-    into.push(dest.as_str().unwrap().to_owned());
+    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());
 }
 
 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_owned());
-        dst.push(dir.as_str().unwrap().to_owned());
+        dst.push("-L".to_strbuf());
+        dst.push(dir.as_str().unwrap().to_strbuf());
     }
 }
 
-fn rustc_to_cargo_err(args: &[~str], cwd: &Path, err: CargoError) -> CargoError {
+fn rustc_to_cargo_err(args: &[StrBuf], cwd: &Path, err: CargoError) -> CargoError {
     let msg = {
         let output = match err {
             CargoError { kind: ProcessError(_, ref output), .. } => output,
index 3a8737ce513054d500228081a465edf3bf6d9386..14266f2c0a98ac9495e2a013ae0cbd96a9c62e29 100644 (file)
@@ -17,7 +17,7 @@ impl PathSource {
 
 impl Show for PathSource {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        write!(f.buf, "the paths source")
+        write!(f, "the paths source")
     }
 }
 
index 3b0343a2690916e74d661563d97abe062bf2be45..83bf2f3426da112eb7954c864fb847bd82ffbe68 100644 (file)
@@ -12,15 +12,15 @@ pub enum Location {
 
 #[deriving(Eq,TotalEq,Clone,Decodable)]
 pub enum ConfigValueValue {
-    String(~str),
-    List(Vec<~str>)
+    String(StrBuf),
+    List(Vec<StrBuf>)
 }
 
 impl fmt::Show for ConfigValueValue {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
-            &String(ref string) => write!(f.buf, "{}", string),
-            &List(ref list) => write!(f.buf, "{}", list)
+            &String(ref string) => write!(f, "{}", string),
+            &List(ref list) => write!(f, "{}", list)
         }
     }
 }
@@ -68,8 +68,8 @@ 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<~str> = self.path.iter().map(|p| p.display().to_str()).collect();
-        write!(f.buf, "{} (from {})", self.value, paths)
+        let paths: Vec<StrBuf> = self.path.iter().map(|p| format_strbuf!("{}", p.display())).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<~str, ConfigValue>> {
+pub fn all_configs(pwd: Path) -> CargoResult<HashMap<StrBuf, ConfigValue>> {
     let mut map = HashMap::new();
 
     try!(walk_tree(&pwd, |file| {
@@ -89,7 +89,7 @@ pub fn all_configs(pwd: Path) -> CargoResult<HashMap<~str, ConfigValue>> {
 }
 
 #[allow(unused_variable)]
-pub fn set_config(key: ~str, value: ~str, location: Location) -> CargoResult<()> {
+pub fn set_config(key: StrBuf, value: StrBuf, location: Location) -> CargoResult<()> {
     Ok(())
 }
 
@@ -140,15 +140,15 @@ fn extract_config(file: io::fs::File, key: &str) -> CargoResult<ConfigValue> {
     let val = try!(root.lookup(key).require(other_error("")));
 
     let v = match val {
-        &toml::String(ref val) => String(val.to_owned()),
-        &toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| s.to_str()).collect()),
+        &toml::String(ref val) => String(val.clone()),
+        &toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| format_strbuf!("{}", s)).collect()),
         _ => return Err(other_error(""))
     };
 
     Ok(ConfigValue{ value: v, path: vec!(path) })
 }
 
-fn extract_all_configs(file: io::fs::File, map: &mut HashMap<~str, ConfigValue>) -> CargoResult<()> {
+fn extract_all_configs(file: io::fs::File, map: &mut HashMap<StrBuf, 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|
@@ -159,9 +159,9 @@ fn extract_all_configs(file: io::fs::File, map: &mut HashMap<~str, ConfigValue>)
 
     for (key, value) in table.iter() {
         match value {
-            &toml::String(ref val) => { map.insert(key.to_owned(), ConfigValue { value: String(val.to_owned()), path: vec!(path.clone()) }); }
+            &toml::String(ref val) => { map.insert(key.clone(), ConfigValue { value: String(val.clone()), path: vec!(path.clone()) }); }
             &toml::Array(ref val) => {
-                let config = map.find_or_insert_with(key.to_owned(), |_| {
+                let config = map.find_or_insert_with(key.clone(), |_| {
                     ConfigValue { path: vec!(), value: List(vec!()) }
                 });
 
@@ -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<~str>> = val.iter().map(|s: &toml::Value| toml_string(s)).collect();
+            let new_list: Vec<CargoResult<StrBuf>> = 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<~str> = new_list.move_iter().map(|v| v.unwrap()).collect();
+                let new_list: Vec<StrBuf> = new_list.move_iter().map(|v| v.unwrap()).collect();
                 list.push_all(new_list.as_slice());
                 existing.path.push(path.clone());
                 Ok(())
@@ -192,9 +192,9 @@ fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &Path) ->
     }
 }
 
-fn toml_string(val: &toml::Value) -> CargoResult<~str> {
+fn toml_string(val: &toml::Value) -> CargoResult<StrBuf> {
     match val {
-        &toml::String(ref str) => Ok(str.to_owned()),
+        &toml::String(ref str) => Ok(str.clone()),
         _ => Err(other_error(""))
     }
 }
index e8aea0e0ec90f08148509e3200c4350e5b67c800..5ba79f121b6a63a2f207514a58a47cf92526d35b 100644 (file)
@@ -2,28 +2,28 @@ use std::fmt;
 use std::fmt::{Show,Formatter};
 use std::os;
 use std::path::Path;
-use std::io::process::{Process,ProcessConfig,ProcessOutput,InheritFd};
+use std::io::process::{Command,ProcessOutput,InheritFd};
 use util::{CargoResult,io_error,process_error};
 use collections::HashMap;
 
 #[deriving(Clone,Eq)]
 pub struct ProcessBuilder {
-    program: ~str,
-    args: Vec<~str>,
-    path: Vec<~str>,
-    env: HashMap<~str, ~str>,
+    program: StrBuf,
+    args: Vec<StrBuf>,
+    path: Vec<StrBuf>,
+    env: HashMap<StrBuf, StrBuf>,
     cwd: Path
 }
 
 impl Show for ProcessBuilder {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        try!(write!(f.buf, "`{}", self.program));
+        try!(write!(f, "`{}", self.program));
 
         if self.args.len() > 0 {
-            try!(write!(f.buf, " {}", self.args.connect(" ")));
+            try!(write!(f, " {}", self.args.connect(" ")));
         }
 
-        write!(f.buf, "`")
+        write!(f, "`")
     }
 }
 
@@ -31,18 +31,18 @@ impl Show for ProcessBuilder {
 static PATH_SEP : &'static str = ":";
 
 impl ProcessBuilder {
-    pub fn args(mut self, arguments: &[~str]) -> ProcessBuilder {
+    pub fn args(mut self, arguments: &[StrBuf]) -> ProcessBuilder {
         self.args = Vec::from_slice(arguments);
         self
     }
 
-    pub fn get_args<'a>(&'a self) -> &'a [~str] {
+    pub fn get_args<'a>(&'a self) -> &'a [StrBuf] {
         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!("{}", path.display()));
+        self.path.push(format_strbuf!("{}", path.display()));
         self
     }
 
@@ -53,16 +53,13 @@ impl ProcessBuilder {
 
     // TODO: should InheritFd be hardcoded?
     pub fn exec(&self) -> CargoResult<()> {
-        let mut config = try!(self.build_config());
-        let env = self.build_env();
+        let mut command = self.build_command();
+        command
+            .env(self.build_env())
+            .stdout(InheritFd(1))
+            .stderr(InheritFd(2));
 
-        // Set where the output goes
-        config.env = Some(env.as_slice());
-        config.stdout = InheritFd(1);
-        config.stderr = InheritFd(2);
-
-        let mut process = try!(Process::configure(config).map_err(io_error));
-        let exit = process.wait();
+        let exit = try!(command.status().map_err(io_error));
 
         if exit.success() {
             Ok(())
@@ -73,12 +70,10 @@ impl ProcessBuilder {
     }
 
     pub fn exec_with_output(&self) -> CargoResult<ProcessOutput> {
-        let mut config = try!(self.build_config());
-        let env = self.build_env();
-
-        config.env = Some(env.as_slice());
+        let mut command = self.build_command();
+        command.env(self.build_env());
 
-        let output = try!(Process::configure(config).map(|mut ok| ok.wait_with_output()).map_err(io_error));
+        let output = try!(command.output().map_err(io_error));
 
         if output.status.success() {
             Ok(output)
@@ -88,21 +83,17 @@ impl ProcessBuilder {
         }
     }
 
-    fn build_config<'a>(&'a self) -> CargoResult<ProcessConfig<'a>> {
-        let mut config = ProcessConfig::new();
-
-        config.program = self.program.as_slice();
-        config.args = self.args.as_slice();
-        config.cwd = Some(&self.cwd);
-
-        Ok(config)
+    fn build_command(&self) -> Command {
+        let mut command = Command::new(self.program.as_slice());
+        command.args(self.args.as_slice()).cwd(&self.cwd);
+        command
     }
 
-    fn debug_string(&self) -> ~str {
-        format!("{} {}", self.program, self.args.connect(" "))
+    fn debug_string(&self) -> StrBuf {
+        format_strbuf!("{} {}", self.program, self.args.connect(" "))
     }
 
-    fn build_env(&self) -> ~[(~str, ~str)] {
+    fn build_env(&self) -> ~[(StrBuf, StrBuf)] {
         let mut ret = Vec::new();
 
         for (key, val) in self.env.iter() {
@@ -113,31 +104,29 @@ impl ProcessBuilder {
         }
 
         match self.build_path() {
-            Some(path) => ret.push(("PATH".to_owned(), path)),
+            Some(path) => ret.push(("PATH".to_strbuf(), path)),
             _ => ()
         }
 
         ret.as_slice().to_owned()
     }
 
-    fn build_path(&self) -> Option<~str> {
+    fn build_path(&self) -> Option<StrBuf> {
         let path = self.path.connect(PATH_SEP);
 
         match self.env.find_equiv(&("PATH")) {
             Some(existing) => {
                 if self.path.is_empty() {
-                    Some(existing.to_owned())
+                    Some(existing.clone())
+                } else {
+                    Some(format_strbuf!("{}{}{}", existing, PATH_SEP, path))
                 }
-                else {
-                    Some(existing.as_slice() + PATH_SEP + path)
-                }
-            }
+            },
             None => {
                 if self.path.is_empty() {
                     None
-                }
-                else {
-                    Some(path)
+                } else {
+                    Some(path.to_strbuf())
                 }
             }
         }
@@ -146,7 +135,7 @@ impl ProcessBuilder {
 
 pub fn process(cmd: &str) -> ProcessBuilder {
     ProcessBuilder {
-        program: cmd.to_owned(),
+        program: cmd.to_strbuf(),
         args: vec!(),
         path: vec!(),
         cwd: os::getcwd(),
@@ -154,11 +143,11 @@ pub fn process(cmd: &str) -> ProcessBuilder {
     }
 }
 
-fn system_env() -> HashMap<~str, ~str> {
+fn system_env() -> HashMap<StrBuf, StrBuf> {
     let mut ret = HashMap::new();
 
     for &(ref key, ref val) in os::env().iter() {
-        ret.insert(key.clone(), val.clone());
+        ret.insert(key.to_strbuf(), val.to_strbuf());
     }
 
     ret
index 1692e1ab83c69638599bcb1a9186f2e1f2b379ee..c57562fa5ae6e5f295f185efa325c303516a4606 100644 (file)
@@ -121,12 +121,12 @@ pub enum CargoErrorKind {
 impl Show for CargoErrorKind {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
         match self {
-            &ProcessError(ref exit, _) => write!(f.buf, "ProcessError({})", exit),
-            &HumanReadableError => write!(f.buf, "HumanReadableError"),
-            &InternalError => write!(f.buf, "InternalError"),
-            &IoError(ref err) => write!(f.buf, "IoError({})", err),
-            &TomlError(ref err) => write!(f.buf, "TomlError({})", err),
-            &OtherCargoError => write!(f.buf, "OtherCargoError")
+            &ProcessError(ref exit, _) => write!(f, "ProcessError({})", exit),
+            &HumanReadableError => write!(f, "HumanReadableError"),
+            &InternalError => write!(f, "InternalError"),
+            &IoError(ref err) => write!(f, "IoError({})", err),
+            &TomlError(ref err) => write!(f, "TomlError({})", err),
+            &OtherCargoError => write!(f, "OtherCargoError")
         }
     }
 }