Share manifest structs
authorCarl Lerche <me@carllerche.com>
Mon, 10 Mar 2014 23:30:20 +0000 (16:30 -0700)
committerCarl Lerche <me@carllerche.com>
Mon, 10 Mar 2014 23:30:20 +0000 (16:30 -0700)
Makefile
commands/cargo-read-manifest/main.rs

index b1639adb0a8d610915246b89c00c491eec358d78..eb644426442802c42d8320bf8ff8a0188aab585d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,23 +3,24 @@ RUSTC_FLAGS ?= --out-dir $(RUSTC_TARGET) -L $(RUSTC_TARGET)/libs
 
 TOML_LIB := $(shell rustc --crate-file-name libs/rust-toml/src/toml/lib.rs)
 HAMMER_LIB := $(shell rustc --crate-file-name libs/hammer.rs/src/lib.rs)
+LIBCARGO_LIB := $(shell rustc --crate-file-name libcargo/cargo.rs)
 
 default: dependencies commands
 
-dependencies: target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB)
+dependencies: target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) target/libs/$(LIBCARGO_LIB)
 
 commands: target/cargo-rustc target/cargo-verify-project target/cargo-read-manifest
 
 clean:
        rm -rf target
 
-target/cargo-rustc: target target/libs/$(TOML_LIB) commands/cargo-rustc/main.rs
+target/cargo-rustc: target dependencies target/libs/$(TOML_LIB) commands/cargo-rustc/main.rs
        rustc commands/cargo-rustc/main.rs $(RUSTC_FLAGS)
 
-target/cargo-verify-project: target target/libs/$(TOML_LIB) commands/cargo-verify-project/main.rs
+target/cargo-verify-project: target dependencies target/libs/$(TOML_LIB) commands/cargo-verify-project/main.rs
        rustc commands/cargo-verify-project/main.rs $(RUSTC_FLAGS)
 
-target/cargo-read-manifest: target target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) commands/cargo-read-manifest/main.rs
+target/cargo-read-manifest: target dependencies target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) commands/cargo-read-manifest/main.rs
        rustc commands/cargo-read-manifest/main.rs $(RUSTC_FLAGS)
 
 target/libs/$(TOML_LIB): target libs/rust-toml/src/toml/lib.rs
@@ -30,6 +31,10 @@ target/libs/$(HAMMER_LIB): target libs/hammer.rs/src/lib.rs
        cd libs/hammer.rs && make
        cp libs/hammer.rs/target/*.rlib target/libs
 
+target/libs/$(LIBCARGO_LIB): target libcargo/cargo.rs
+       cd libcargo && make
+       cp libcargo/target/*.rlib target/libs/
+
 target:
        mkdir -p $(RUSTC_TARGET)/libs
 
index 498a5c76f1839512f7bd988042426209fa9f0275..806d76020064030e2b74bcd3244eb4a6aa94886c 100644 (file)
@@ -1,5 +1,6 @@
 #[crate_id="cargo-read-manifest"];
 
+extern crate cargo;
 extern crate hammer;
 extern crate serialize;
 extern crate toml;
@@ -10,6 +11,7 @@ use serialize::{Decoder,Decodable};
 use serialize::json::Encoder;
 use toml::from_toml;
 use semver::Version;
+use cargo::{Manifest,LibTarget,ExecTarget,Project};
 
 #[deriving(Decodable,Encodable,Eq,Clone,Ord)]
 struct SerializedManifest {
@@ -18,28 +20,6 @@ struct SerializedManifest {
   bin: Option<~[ExecTarget]>
 }
 
-#[deriving(Encodable,Eq,Clone,Ord)]
-struct Manifest {
-  project: ~Project,
-  lib: ~[LibTarget],
-  bin: ~[ExecTarget]
-}
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-struct Target {
-  name: ~str,
-  path: Option<~str>
-}
-
-type LibTarget = Target;
-type ExecTarget = Target;
-
-#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
-struct Project {
-  name: ~str,
-  version: ~str,
-  authors: ~[~str]
-}
 
 #[deriving(Decodable,Eq,Clone,Ord)]
 struct ReadManifestFlags {
@@ -79,18 +59,30 @@ fn main() {
 
 fn normalize(lib: &Option<~[LibTarget]>, bin: &Option<~[ExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) {
   if lib.is_some() && bin.is_some() {
-    (~[], ~[])
+    let mut l = lib.clone().unwrap()[0]; // crashes if lib = [] is provided in the Toml file
+    if l.path.is_none() {
+      l.path = Some(format!("src/{}.rs", l.name));
+    }
+
+    let b = bin.get_ref().map(|b_ref| {
+      let mut b = b_ref.clone();
+      if b.path.is_none() {
+        b.path = Some(format!("src/bin/{}.rs", b.name));
+      }
+      b
+    });
+    (~[l.clone()], b)
   } else if lib.is_some() {
     let mut l = lib.clone().unwrap()[0]; // crashes if lib = [] is provided in the Toml file
     if l.path.is_none() {
-      l.path = Some(format!("{}.rs", l.name));
+      l.path = Some(format!("src/{}.rs", l.name));
     }
     (~[l.clone()], ~[])
   } else if bin.is_some() {
     let b = bin.get_ref().map(|b_ref| {
       let mut b = b_ref.clone();
       if b.path.is_none() {
-        b.path = Some(format!("{}.rs", b.name));
+        b.path = Some(format!("src/{}.rs", b.name));
       }
       b
     });