Compile all deps into the root projects target dir
authorCarl Lerche <me@carllerche.com>
Thu, 29 May 2014 00:31:23 +0000 (17:31 -0700)
committerCarl Lerche <me@carllerche.com>
Thu, 29 May 2014 00:31:23 +0000 (17:31 -0700)
Makefile
src/cargo/core/manifest.rs
src/cargo/ops/cargo_rustc.rs
tests/support.rs
tests/tests.rs

index 0a7fc14217ff1fa8c6a9372c00b105485a7450b3..0a44bd9f136157e393e1d6466370526a2997a1c4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -50,10 +50,10 @@ $(BIN_TARGETS): target/%: src/bin/%.rs $(HAMMER) $(TOML) $(LIBCARGO)
 TEST_SRC = $(wildcard tests/*.rs)
 TEST_DEPS = $(DEPS) -L libs/hamcrest-rust/target
 
-target/tests/test-integration: $(BIN_TARGETS) $(HAMCREST) $(TEST_SRC)
+target/tests/test-integration: $(HAMCREST) $(TEST_SRC) $(BIN_TARGETS)
        $(RUSTC) --test --crate-type=lib $(TEST_DEPS) -Ltarget -o $@  tests/tests.rs
 
-target/tests/test-unit: $(HAMCREST) $(SRC) $(HAMMER) $(TOML)
+target/tests/test-unit: $(TOML) $(HAMCREST) $(SRC) $(HAMMER)
        mkdir -p target/tests
        $(RUSTC) --test $(RUSTC_FLAGS) $(TEST_DEPS) -o $@ src/cargo/lib.rs
 
index 4ee193dcf903c7ec7f155095ea96cfb5648ca68f..00ac9ce71543f315be9460bb1ad24d077a76a56e 100644 (file)
@@ -150,6 +150,20 @@ impl Target {
         &self.path
     }
 
+    pub fn is_lib(&self) -> bool {
+        match self.kind {
+            LibTarget => true,
+            _ => false
+        }
+    }
+
+    pub fn is_bin(&self) -> bool {
+        match self.kind {
+            BinTarget => true,
+            _ => false
+        }
+    }
+
     pub fn rustc_crate_type(&self) -> &'static str {
         match self.kind {
             LibTarget => "lib",
index bd1c280329a79b69b284efc028f8176749769d9a..907a6ca96f61f05e1746e4c0b94677f4d2fa7b5f 100644 (file)
@@ -1,3 +1,4 @@
+use std::os;
 use std::os::args;
 use std::io;
 use std::path::Path;
@@ -12,42 +13,46 @@ type Args = Vec<String>;
 pub fn compile_packages(pkg: &Package, deps: &PackageSet) -> CargoResult<()> {
     debug!("compiling; pkg={}; deps={}", pkg, deps);
 
+    let target_dir = pkg.get_absolute_target_dir();
+    let deps_target_dir = target_dir.join("deps");
+
+    // First ensure that the destination directory exists
+    debug!("creating target dir; path={}", target_dir.display());
+    try!(mk_target(&target_dir));
+    try!(mk_target(&deps_target_dir));
+
     // Traverse the dependencies in topological order
     for dep in try!(topsort(deps)).iter() {
         println!("Compiling {}", pkg);
-        try!(compile_pkg(dep, deps, false));
+        try!(compile_pkg(dep, &deps_target_dir, &deps_target_dir, false));
     }
 
     println!("Compiling {}", pkg);
-    try!(compile_pkg(pkg, deps, true));
+    try!(compile_pkg(pkg, &target_dir, &deps_target_dir, true));
 
     Ok(())
 }
 
-fn compile_pkg(pkg: &Package, pkgs: &PackageSet, verbose: bool) -> CargoResult<()> {
-    debug!("compiling; pkg={}; targets={}; deps={}", pkg, pkg.get_targets(), pkg.get_dependencies());
-    // Build up the destination
-    // let src = pkg.get_root().join(Path::new(pkg.get_source().path.as_slice()));
-    let target_dir = pkg.get_absolute_target_dir();
-
-    debug!("creating target dir; path={}", target_dir.display());
-
-    // First ensure that the directory exists
-    try!(mk_target(&target_dir).map_err(|_| other_error("could not create target directory")));
+fn compile_pkg(pkg: &Package, dest: &Path, deps_dir: &Path, primary: bool) -> CargoResult<()> {
+    debug!("compiling; pkg={}; targets={}", pkg, pkg.get_targets());
 
     // compile
     for target in pkg.get_targets().iter() {
-        try!(rustc(pkg.get_root(), target, &target_dir, pkgs.get_packages(), verbose))
+        // Only compile lib targets for dependencies
+        if primary || target.is_lib() {
+            try!(rustc(pkg.get_root(), target, dest, deps_dir, primary))
+        }
     }
 
     Ok(())
 }
 
-fn mk_target(target: &Path) -> io::IoResult<()> {
+fn mk_target(target: &Path) -> CargoResult<()> {
     io::fs::mkdir_recursive(target, io::UserRWX)
+      .map_err(|_| other_error("could not create target directory"))
 }
 
-fn rustc(root: &Path, target: &Target, dest: &Path, deps: &[Package], verbose: bool) -> CargoResult<()> {
+fn rustc(root: &Path, target: &Target, dest: &Path, deps: &Path, verbose: bool) -> CargoResult<()> {
     let rustc = prepare_rustc(root, target, dest, deps);
 
     try!((if verbose {
@@ -59,7 +64,7 @@ fn rustc(root: &Path, target: &Target, dest: &Path, deps: &[Package], verbose: b
     Ok(())
 }
 
-fn prepare_rustc(root: &Path, target: &Target, dest: &Path, deps: &[Package]) -> ProcessBuilder {
+fn prepare_rustc(root: &Path, target: &Target, dest: &Path, deps: &Path) -> ProcessBuilder {
     let mut args = Vec::new();
 
     build_base_args(&mut args, target, dest);
@@ -80,13 +85,9 @@ fn build_base_args(into: &mut Args, target: &Target, dest: &Path) {
     into.push(dest.display().to_str());
 }
 
-fn build_deps_args(dst: &mut Args, deps: &[Package]) {
-    for dep in deps.iter() {
-        let dir = dep.get_absolute_target_dir();
-
-        dst.push("-L".to_str());
-        dst.push(dir.display().to_str());
-    }
+fn build_deps_args(dst: &mut Args, deps: &Path) {
+    dst.push("-L".to_str());
+    dst.push(deps.display().to_str());
 }
 
 fn rustc_to_cargo_err(args: &[String], cwd: &Path, err: CargoError) -> CargoError {
index 131bf989179d7a654fd23f55ecf23e2cc5fbc681..456a3a11284588f6fa7a8a3863d38ff1deceb8b6 100644 (file)
@@ -183,8 +183,8 @@ impl Execs {
 
   fn match_output(&self, actual: &ProcessOutput) -> ham::MatchResult {
     self.match_status(actual.status)
-      .and(self.match_stdout(&actual.output))
-      .and(self.match_stderr(&actual.error))
+      .and(self.match_stdout(actual))
+      .and(self.match_stderr(actual))
   }
 
   fn match_status(&self, actual: ProcessExit) -> ham::MatchResult {
@@ -198,22 +198,22 @@ impl Execs {
     }
   }
 
-  fn match_stdout(&self, actual: &Vec<u8>) -> ham::MatchResult {
-      self.match_std(&self.expect_stdout, actual, "stdout")
+  fn match_stdout(&self, actual: &ProcessOutput) -> ham::MatchResult {
+      self.match_std(self.expect_stdout.as_ref(), actual.output.as_slice(), "stdout", actual.error.as_slice())
   }
 
-  fn match_stderr(&self, actual: &Vec<u8>) -> ham::MatchResult {
-      self.match_std(&self.expect_stderr, actual, "stderr")
+  fn match_stderr(&self, actual: &ProcessOutput) -> ham::MatchResult {
+      self.match_std(self.expect_stderr.as_ref(), actual.error.as_slice(), "stderr", actual.output.as_slice())
   }
 
-  fn match_std(&self, expected: &Option<String>, actual: &Vec<u8>, description: &str) -> ham::MatchResult {
+  fn match_std(&self, expected: Option<&String>, actual: &[u8], description: &str, extra: &[u8]) -> ham::MatchResult {
     match expected.as_ref().map(|s| s.as_slice()) {
       None => ham::success(),
       Some(out) => {
-        match str::from_utf8(actual.as_slice()) {
+        match str::from_utf8(actual) {
           None => Err(format!("{} was not utf8 encoded", description)),
           Some(actual) => {
-            ham::expect(actual == out, format!("{} was `{}`", description, actual))
+            ham::expect(actual == out, format!("{} was `{}`\n other output:\n{}", description, actual, str::from_utf8(extra)))
           }
         }
       }
index 495adba1e1d6bad907b87b962a90c426c3206330..d432077085a7415fa820cefd3c115db3cfea4bd8 100644 (file)
@@ -1,10 +1,14 @@
 #![feature(macro_rules)]
 #![allow(deprecated_owned_vector)]
+#![feature(phase)]
 
 extern crate term;
 extern crate cargo;
 extern crate hamcrest;
 
+#[phase(syntax, link)]
+extern crate log;
+
 macro_rules! test(
     ($name:ident $expr:expr) => (
         #[test]