$(RUSTC) --test --crate-type=lib $(TEST_DEPS) -Ltarget --out-dir tests tests/tests.rs
test-integration: tests/tests
- tests/tests
+ CARGO_BIN_PATH=$(PWD)/target/ tests/tests
test: test-integration
#[crate_id="cargo-compile"];
+#[allow(deprecated_owned_vector)];
extern crate serialize;
extern crate hammer;
#[crate_id="cargo-read-manifest"];
+#[allow(deprecated_owned_vector)];
extern crate cargo;
extern crate hammer;
let b = b_ref.clone();
let mut path = b.path.clone();
if path.is_none() {
- path = Some(format!("src/bin/{}.rs", b.name.clone()));
+ path = Some(format!("src/{}.rs", b.name.clone()));
}
ExecTarget{ path: path.unwrap(), name: b.name }
});
#[crate_id="cargo-rustc"];
+#[allow(deprecated_owned_vector)];
extern crate toml;
extern crate serialize;
use serialize::json;
use serialize::Decodable;
use std::path::Path;
-use cargo::{Manifest,CargoResult,ToCargoError};
+use cargo::{Manifest,CargoResult,CargoError,ToCargoError};
/**
cargo-rustc -- ...args
fn main() {
match execute() {
Err(e) => {
- println!("{}", e.message);
+ write!(&mut std::io::stderr(), "{}", e.message);
// TODO: Exit with error code
},
_ => return
let mut decoder = json::Decoder::new(json);
let manifest: Manifest = Decodable::decode(&mut decoder);
- let Manifest{ root, lib, .. } = manifest;
+ let Manifest{ root, lib, bin, .. } = manifest;
+
+ let (crate_type, out_dir) = if lib.len() > 0 {
+ ( ~"lib", lib[0].path )
+ } else if bin.len() > 0 {
+ ( ~"bin", bin[0].path )
+ } else {
+ return Err(CargoError::new(~"bad manifest, no lib or bin specified", 1));
+ };
let root = Path::new(root);
- let out_dir = lib[0].path;
let target = join(&root, ~"target");
let args = [
join(&root, out_dir),
~"--out-dir", target,
- ~"--crate-type", ~"lib"
+ ~"--crate-type", crate_type
];
match io::fs::mkdir_recursive(&root.join("target"), io::UserRWX) {
fn join(path: &Path, part: ~str) -> ~str {
format!("{}", path.join(part).display())
}
+
+fn vec_idx<T>(v: ~[T], idx: uint) -> Option<T> {
+ if idx < v.len() {
+ Some(v[idx])
+ } else {
+ None
+ }
+}
#[crate_id="cargo-verify-project"];
+#[allow(deprecated_owned_vector)];
extern crate toml;
extern crate getopts;
#[crate_id="cargo"];
#[crate_type="rlib"];
+#[allow(deprecated_owned_vector)];
+
extern crate serialize;
use serialize::{Decoder};
use std::fmt;
pub use self::process_builder::process;
-mod process_builder;
+pub mod process_builder;
use std;
use std::os;
-use std::io::process::{Process,ProcessConfig,InheritFd};
+use std::path::Path;
+use std::io::IoResult;
+use std::io::process::{Process,ProcessConfig,ProcessOutput};
+use ToCargoError;
+use CargoResult;
pub struct ProcessBuilder {
program: ~str,
args: ~[~str],
- path: ~[~str]
+ path: ~[~str],
+ cwd: Path
}
+// TODO: Upstream a Windows/Posix branch to Rust proper
+static PATH_SEP : &'static str = ":";
+
impl ProcessBuilder {
pub fn args(mut self, arguments: &[~str]) -> ProcessBuilder {
self.args = arguments.to_owned();
self
}
-}
-pub fn process(cmd: &str) -> ProcessBuilder {
- ProcessBuilder { program: cmd.to_owned(), args: ~[], path: get_curr_path() }
+ pub fn extra_path(mut self, path: &str) -> ProcessBuilder {
+ self.path.push(path.to_owned());
+ self
+ }
+
+ pub fn cwd(mut self, path: Path) -> ProcessBuilder {
+ self.cwd = path;
+ self
+ }
+
+ pub fn exec_with_output(self) -> CargoResult<ProcessOutput> {
+ let mut config = ProcessConfig::new();
+
+ println!("cwd: {}", self.cwd.display());
+
+ config.program = self.program.as_slice();
+ config.args = self.args.as_slice();
+ config.cwd = Some(&self.cwd);
+
+ let os_path = try!(os::getenv("PATH").to_cargo_error(~"Could not find the PATH environment variable", 1));
+ let path = os_path + PATH_SEP + self.path.connect(PATH_SEP);
+
+ let path = [(~"PATH", path)];
+ config.env = Some(path.as_slice());
+
+ println!("{:?}", config);
+
+ Process::configure(config).map(|mut ok| ok.wait_with_output()).to_cargo_error(~"Could not spawn process", 1)
+ }
}
-pub fn get_curr_path() -> ~[~str] {
- os::getenv("PATH").map(|path| {
- path.split(std::path::SEP).map(|seg| seg.to_owned()).collect()
- }).unwrap_or(~[])
+pub fn process(cmd: &str) -> ProcessBuilder {
+ ProcessBuilder {
+ program: cmd.to_owned(),
+ args: ~[],
+ path: ~[],
+ cwd: os::getcwd()
+ }
}
}
}
+ pub fn root(&self) -> Path {
+ self.root.clone()
+ }
+
pub fn file(mut self, path: &str, body: &str) -> ProjectBuilder {
self.files.push(FileBuilder::new(self.root.join(path), body));
self
}
- pub fn build(self) {
+ // TODO: return something different than a ProjectBuilder
+ pub fn build(self) -> ProjectBuilder {
match self.build_with_result() {
Err(e) => fail!(e),
- _ => return
+ _ => return self
}
}
- pub fn build_with_result(self) -> Result<(), ~str> {
+ pub fn build_with_result(&self) -> Result<(), ~str> {
// First, clean the directory if it already exists
try!(self.rm_root());
+use std;
use support::project;
use cargo;
}
test!(cargo_compile_with_explicit_manifest_path {
- project("foo")
+ let p = project("foo")
.file("Cargo.toml", r#"
[project]
}"#)
.build();
- cargo::util::process("cargo-compile")
- .args([]);
- // //.extra_path("target/")
- // //.cwd("/foo/bar")
- // //.exec_with_output()
+ let output = cargo::util::process("cargo-compile")
+ .args([~"--manifest-path", ~"Cargo.toml"])
+ .extra_path(target_path())
+ .cwd(p.root())
+ .exec_with_output();
+
+ match output {
+ Ok(out) => {
+ println!("out:\n{}\n", std::str::from_utf8(out.output));
+ println!("err:\n{}\n", std::str::from_utf8(out.error));
+ },
+ Err(e) => println!("err: {}", e)
+ }
+
+ assert!(p.root().join("target/foo").exists(), "the executable exists");
+
+ let o = cargo::util::process("foo")
+ .extra_path(format!("{}", p.root().join("target").display()))
+ .exec_with_output()
+ .unwrap();
+
+ assert_eq!(std::str::from_utf8(o.output).unwrap(), "i am foo\n");
- fail!("not implemented");
// 1) Setup project
// 2) Run cargo-compile --manifest-path /tmp/bar/zomg
// 3) assertThat(target/foo) exists assertThat("target/foo", isCompiledBin())
})
// test!(compiling_project_with_invalid_manifest)
+
+fn target_path() -> ~str {
+ std::os::getenv("CARGO_BIN_PATH").unwrap_or_else(|| {
+ fail!("CARGO_BIN_PATH wasn't set. Cannot continue running test")
+ })
+}
#[feature(macro_rules)];
+#[allow(deprecated_owned_vector)];
extern crate cargo;