Trying to shell out
authorCarl Lerche <me@carllerche.com>
Wed, 19 Mar 2014 18:44:43 +0000 (11:44 -0700)
committerCarl Lerche <me@carllerche.com>
Wed, 19 Mar 2014 18:44:43 +0000 (11:44 -0700)
Makefile
libs/rust-toml
src/cargo.rs [deleted file]
src/cargo/mod.rs [new file with mode: 0644]
src/cargo/util/mod.rs [new file with mode: 0644]
src/cargo/util/process.rs [new file with mode: 0644]
tests/test_cargo_compile.rs

index 663e314de1b0faf7e5eb8877ebf832285b869b57..71c621d3e8f97ee1832383f2265efb02f63257fb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,8 @@ BINS = cargo-compile \
           cargo-rustc \
           cargo-verify-project
 
-SRC = $(wildcard src/*.rs)
+SRC = $(shell find src -name '*.rs')
+
 DEPS = -L libs/hammer.rs/target -L libs/rust-toml/lib
 TOML = libs/rust-toml/lib/$(shell rustc --crate-file-name libs/rust-toml/src/toml/lib.rs)
 HAMMER = libs/hammer.rs/target/$(shell rustc --crate-type=lib --crate-file-name libs/hammer.rs/src/hammer.rs)
@@ -32,7 +33,7 @@ $(HAMCREST): $(wildcard libs/hamcrest-rust/src/*.rs)
 
 $(LIBCARGO): $(SRC)
        mkdir -p target
-       $(RUSTC) $(RUSTC_FLAGS) --out-dir target src/cargo.rs
+       $(RUSTC) $(RUSTC_FLAGS) --out-dir target src/cargo/mod.rs
        touch $(LIBCARGO)
 
 libcargo: $(LIBCARGO)
index 894fdd9db6c50b9a70d1fc7d4e49c76e86921016..1389ceb42b2ae04dac40c8b2d4af8fe21823ecbc 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 894fdd9db6c50b9a70d1fc7d4e49c76e86921016
+Subproject commit 1389ceb42b2ae04dac40c8b2d4af8fe21823ecbc
diff --git a/src/cargo.rs b/src/cargo.rs
deleted file mode 100644 (file)
index 13a2ea5..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-#[crate_type="rlib"];
-
-extern crate serialize;
-use serialize::{Decoder};
-use std::fmt;
-use std::fmt::{Show,Formatter};
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct Manifest {
-    project: ~Project,
-    root: ~str,
-    lib: ~[LibTarget],
-    bin: ~[ExecTarget]
-}
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct ExecTarget {
-    name: ~str,
-    path: ~str
-}
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct LibTarget {
-    name: ~str,
-    path: ~str
-}
-
-//pub type LibTarget = Target;
-//pub type ExecTarget = Target;
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-pub struct Project {
-    name: ~str,
-    version: ~str,
-    authors: ~[~str]
-}
-
-pub type CargoResult<T> = Result<T, CargoError>;
-
-pub struct CargoError {
-    message: ~str,
-    exit_code: uint
-}
-
-impl CargoError {
-    pub fn new(message: ~str, exit_code: uint) -> CargoError {
-        CargoError { message: message, exit_code: exit_code }
-    }
-}
-
-impl Show for CargoError {
-    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        write!(f.buf, "{}", self.message)
-    }
-}
-
-pub trait ToCargoError<T> {
-    fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError>;
-}
-
-impl<T,U> ToCargoError<T> for Result<T,U> {
-    fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError> {
-        match self {
-            Err(_) => Err(CargoError{ message: message, exit_code: exit_code }),
-            Ok(val) => Ok(val)
-        }
-    }
-}
-
-impl<T> ToCargoError<T> for Option<T> {
-    fn to_cargo_error(self, message: ~str, exit_code: uint) -> CargoResult<T> {
-        match self {
-            None => Err(CargoError{ message: message, exit_code: exit_code }),
-            Some(val) => Ok(val)
-        }
-    }
-}
diff --git a/src/cargo/mod.rs b/src/cargo/mod.rs
new file mode 100644 (file)
index 0000000..c33c7fd
--- /dev/null
@@ -0,0 +1,78 @@
+#[crate_id="cargo"];
+#[crate_type="rlib"];
+
+extern crate serialize;
+use serialize::{Decoder};
+use std::fmt;
+use std::fmt::{Show,Formatter};
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct Manifest {
+    project: ~Project,
+    root: ~str,
+    lib: ~[LibTarget],
+    bin: ~[ExecTarget]
+}
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct ExecTarget {
+    name: ~str,
+    path: ~str
+}
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct LibTarget {
+    name: ~str,
+    path: ~str
+}
+
+//pub type LibTarget = Target;
+//pub type ExecTarget = Target;
+
+#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
+pub struct Project {
+    name: ~str,
+    version: ~str,
+    authors: ~[~str]
+}
+
+pub type CargoResult<T> = Result<T, CargoError>;
+
+pub struct CargoError {
+    message: ~str,
+    exit_code: uint
+}
+
+impl CargoError {
+    pub fn new(message: ~str, exit_code: uint) -> CargoError {
+        CargoError { message: message, exit_code: exit_code }
+    }
+}
+
+impl Show for CargoError {
+    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+        write!(f.buf, "{}", self.message)
+    }
+}
+
+pub trait ToCargoError<T> {
+    fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError>;
+}
+
+impl<T,U> ToCargoError<T> for Result<T,U> {
+    fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError> {
+        match self {
+            Err(_) => Err(CargoError{ message: message, exit_code: exit_code }),
+            Ok(val) => Ok(val)
+        }
+    }
+}
+
+impl<T> ToCargoError<T> for Option<T> {
+    fn to_cargo_error(self, message: ~str, exit_code: uint) -> CargoResult<T> {
+        match self {
+            None => Err(CargoError{ message: message, exit_code: exit_code }),
+            Some(val) => Ok(val)
+        }
+    }
+}
diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs
new file mode 100644 (file)
index 0000000..5d5d996
--- /dev/null
@@ -0,0 +1 @@
+pub use self::process::process;
diff --git a/src/cargo/util/process.rs b/src/cargo/util/process.rs
new file mode 100644 (file)
index 0000000..c62907e
--- /dev/null
@@ -0,0 +1,25 @@
+use std::os;
+use std::io::process::{Process,ProcessConfig,InheritFd};
+
+pub struct ProcessBuilder {
+  program: ~str,
+  args: ~[~str],
+  path: ~[~str]
+}
+
+impl ProcessBuilder {
+  fn args(mut self, arguments: &[~str]) -> ProcessBuilder {
+    self.args = arguments.clone();
+    self
+  }
+}
+
+pub fn process(cmd: &str) -> ProcessBuilder {
+  ProcessBuilder { program: cmd.to_owned(), args: ~[], path: get_curr_path() }
+}
+
+fn get_curr_path() -> ~[~str] {
+  os::getenv("PATH").map(|path| {
+    path.split(std::path::SEP).collect()
+  }).or(~[])
+}
index 70ff5425240185b56c40bd625e3a1aded04cad76..8594d320cb4f96b1c18ef7054897eb6a35cca475 100644 (file)
@@ -13,7 +13,7 @@ test!(cargo_compile_with_explicit_manifest_path {
             version = "0.5.0"
             authors = ["wycats@example.com"]
 
-            [[lib]]
+            [[bin]]
 
             name = "foo"
         "#)
@@ -23,6 +23,12 @@ test!(cargo_compile_with_explicit_manifest_path {
             }"#)
         .build();
 
+     cargo::util::process("cargo-compile")
+       .args([]);
+     //   //.extra_path("target/")
+     //   //.cwd("/foo/bar")
+     //   //.exec_with_output()
+
     fail!("not implemented");
     // 1) Setup project
     // 2) Run cargo-compile --manifest-path /tmp/bar/zomg