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
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
#[crate_id="cargo-read-manifest"];
+extern crate cargo;
extern crate hammer;
extern crate serialize;
extern crate toml;
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 {
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 {
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
});