about summary refs log tree commit diff
path: root/src/cargo
diff options
context:
space:
mode:
authorElly Jones <elly@leptoquark.net>2011-12-01 22:37:56 -0500
committerBrian Anderson <banderson@mozilla.com>2011-12-01 19:49:17 -0800
commitb8fcf0ab0ec5993981cc07fdb110f5a3db988a2b (patch)
tree5c828952469c7b40a3abc2d4277b6a63d81b1852 /src/cargo
parent3e5b314c0b342d893e2937321000b55376fdbaa4 (diff)
cargo: support build-from-source
No install yet.
Diffstat (limited to 'src/cargo')
-rw-r--r--src/cargo/cargo.rs43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs
index 7da29ab88a0..813b5d13516 100644
--- a/src/cargo/cargo.rs
+++ b/src/cargo/cargo.rs
@@ -3,6 +3,7 @@
 import rustc::syntax::{ast, codemap, visit};
 import rustc::syntax::parse::parser;
 
+import std::fs;
 import std::io;
 import std::option;
 import std::option::{none, some};
@@ -95,9 +96,38 @@ fn rest(s: str, start: uint) -> str {
     }
 }
 
-fn install_file(_path: str) -> option::t<str> {
+fn install_source(path: str) {
+    log #fmt["source: %s", path];
+    fs::change_dir(path);
+    let contents = fs::list_dir(".");
+
+    log #fmt["contents: %s", str::connect(contents, ", ")];
+
+    let cratefile = vec::find::<str>({ |n| str::ends_with(n, ".rc") }, contents);
+
+    // First, try a configure script:
+    if vec::member("./configure", contents) {
+        run::run_program("./configure", []);
+    }
+
+    // Makefile?
+    if vec::member("./Makefile", contents) {
+        run::run_program("make", ["RUSTC=rustc"]);
+    } else if option::is_some::<str>(cratefile) {
+        run::run_program("rustc", [option::get(cratefile)]);
+    }
+}
+
+fn install_file(_path: str) {
     let wd = tempfile::mkdtemp("/tmp/cargo-work-", "");
-    ret wd;
+    alt wd {
+        some(p) {
+            run::run_program("tar", ["-x", "--strip-components=1",
+                                     "-C", p, "-f", _path]);
+            install_source(p);
+        }
+        _ { }
+    }
 }
 
 fn cmd_install(argv: [str]) {
@@ -107,12 +137,10 @@ fn cmd_install(argv: [str]) {
         ret;
     }
 
-    let _wd = if str::starts_with(argv[2], "file:") {
+    if str::starts_with(argv[2], "file:") {
         let path = rest(argv[2], 5u);
-        install_file(path)
-    } else {
-        none
-    };
+        install_file(path);
+    }
 }
 
 fn cmd_usage() {
@@ -125,6 +153,7 @@ fn main(argv: [str]) {
         ret;
     }
     alt argv[1] {
+        "install" { cmd_install(argv); }
         "usage" { cmd_usage(); }
         _ { cmd_usage(); }
     }