mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
Start extracting core types
This commit is contained in:
parent
db92e67c87
commit
4b9fbcb264
@ -9,12 +9,13 @@ extern crate toml;
|
||||
use hammer::FlagConfig;
|
||||
use serialize::Decoder;
|
||||
use toml::from_toml;
|
||||
use cargo::{Manifest,LibTarget,ExecTarget,Project,CargoResult,ToCargoError,execute_main_without_stdin};
|
||||
use cargo::core;
|
||||
use cargo::{CargoResult,ToCargoError,execute_main_without_stdin};
|
||||
use std::path::Path;
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
struct SerializedManifest {
|
||||
project: ~Project,
|
||||
project: ~core::Project,
|
||||
lib: Option<~[SerializedLibTarget]>,
|
||||
bin: Option<~[SerializedExecTarget]>
|
||||
}
|
||||
@ -37,10 +38,10 @@ struct ReadManifestFlags {
|
||||
impl FlagConfig for ReadManifestFlags {}
|
||||
|
||||
fn main() {
|
||||
execute_main_without_stdin::<ReadManifestFlags, Manifest>(execute);
|
||||
execute_main_without_stdin(execute);
|
||||
}
|
||||
|
||||
fn execute(flags: ReadManifestFlags) -> CargoResult<Option<Manifest>> {
|
||||
fn execute(flags: ReadManifestFlags) -> CargoResult<Option<core::Manifest>> {
|
||||
let manifest_path = flags.manifest_path;
|
||||
let root = try!(toml::parse_from_file(manifest_path.clone()).to_cargo_error(format!("Couldn't parse Toml file: {}", manifest_path), 1));
|
||||
|
||||
@ -48,7 +49,7 @@ fn execute(flags: ReadManifestFlags) -> CargoResult<Option<Manifest>> {
|
||||
|
||||
let (lib, bin) = normalize(&toml_manifest.lib, &toml_manifest.bin);
|
||||
|
||||
Ok(Some(Manifest {
|
||||
Ok(Some(core::Manifest {
|
||||
root: try!(Path::new(manifest_path.clone()).dirname_str().to_cargo_error(format!("Could not get dirname from {}", manifest_path), 1)).to_owned(),
|
||||
project: toml_manifest.project,
|
||||
lib: lib,
|
||||
@ -56,17 +57,17 @@ fn execute(flags: ReadManifestFlags) -> CargoResult<Option<Manifest>> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn normalize(lib: &Option<~[SerializedLibTarget]>, bin: &Option<~[SerializedExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) {
|
||||
fn lib_targets(libs: &[SerializedLibTarget]) -> ~[LibTarget] {
|
||||
fn normalize(lib: &Option<~[SerializedLibTarget]>, bin: &Option<~[SerializedExecTarget]>) -> (~[core::LibTarget], ~[core::ExecTarget]) {
|
||||
fn lib_targets(libs: &[SerializedLibTarget]) -> ~[core::LibTarget] {
|
||||
let l = &libs[0];
|
||||
let path = l.path.clone().unwrap_or_else(|| format!("src/{}.rs", l.name));
|
||||
~[LibTarget{ path: path, name: l.name.clone() }]
|
||||
~[core::LibTarget { path: path, name: l.name.clone() }]
|
||||
}
|
||||
|
||||
fn bin_targets(bins: &[SerializedExecTarget], default: |&SerializedExecTarget| -> ~str) -> ~[ExecTarget] {
|
||||
fn bin_targets(bins: &[SerializedExecTarget], default: |&SerializedExecTarget| -> ~str) -> ~[core::ExecTarget] {
|
||||
bins.iter().map(|bin| {
|
||||
let path = bin.path.clone().unwrap_or_else(|| default(bin));
|
||||
ExecTarget{ path: path, name: bin.name.clone() }
|
||||
core::ExecTarget { path: path, name: bin.name.clone() }
|
||||
}).collect()
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,8 @@ use std::os::args;
|
||||
use std::io;
|
||||
use std::io::process::{Process,ProcessConfig,InheritFd};
|
||||
use std::path::Path;
|
||||
use cargo::{Manifest,CargoResult,CargoError,ToCargoError,NoFlags,execute_main};
|
||||
use cargo::{CargoResult,CargoError,ToCargoError,NoFlags,execute_main};
|
||||
use cargo::core;
|
||||
|
||||
/**
|
||||
cargo-rustc -- ...args
|
||||
@ -19,11 +20,11 @@ use cargo::{Manifest,CargoResult,CargoError,ToCargoError,NoFlags,execute_main};
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
execute_main::<NoFlags, Manifest, Manifest>(execute);
|
||||
execute_main(execute);
|
||||
}
|
||||
|
||||
fn execute(_: NoFlags, manifest: Manifest) -> CargoResult<Option<Manifest>> {
|
||||
let Manifest{ root, lib, bin, .. } = manifest;
|
||||
fn execute(_: NoFlags, manifest: core::Manifest) -> CargoResult<Option<core::Manifest>> {
|
||||
let core::Manifest { root, lib, bin, .. } = manifest;
|
||||
|
||||
let (crate_type, out_dir) = if lib.len() > 0 {
|
||||
( ~"lib", lib[0].path )
|
||||
|
31
src/cargo/core/manifest.rs
Normal file
31
src/cargo/core/manifest.rs
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
/*
|
||||
* TODO: Make all struct fields private
|
||||
*/
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct Manifest {
|
||||
pub project: ~Project,
|
||||
pub root: ~str,
|
||||
pub lib: ~[LibTarget],
|
||||
pub bin: ~[ExecTarget]
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct ExecTarget {
|
||||
pub name: ~str,
|
||||
pub path: ~str
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct LibTarget {
|
||||
pub name: ~str,
|
||||
pub path: ~str
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct Project {
|
||||
pub name: ~str,
|
||||
pub version: ~str,
|
||||
pub authors: ~[~str]
|
||||
}
|
8
src/cargo/core/mod.rs
Normal file
8
src/cargo/core/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
pub use self::manifest::{
|
||||
Manifest,
|
||||
Project,
|
||||
LibTarget,
|
||||
ExecTarget};
|
||||
|
||||
mod manifest;
|
@ -12,38 +12,9 @@ use std::fmt;
|
||||
use std::fmt::{Show,Formatter};
|
||||
use hammer::{FlagDecoder,FlagConfig,HammerError};
|
||||
|
||||
pub mod core;
|
||||
pub mod util;
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct Manifest {
|
||||
pub project: ~Project,
|
||||
pub root: ~str,
|
||||
pub lib: ~[LibTarget],
|
||||
pub bin: ~[ExecTarget]
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct ExecTarget {
|
||||
pub name: ~str,
|
||||
pub path: ~str
|
||||
}
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct LibTarget {
|
||||
pub name: ~str,
|
||||
pub path: ~str
|
||||
}
|
||||
|
||||
//pub type LibTarget = Target;
|
||||
//pub type ExecTarget = Target;
|
||||
|
||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||
pub struct Project {
|
||||
pub name: ~str,
|
||||
pub version: ~str,
|
||||
pub authors: ~[~str]
|
||||
}
|
||||
|
||||
pub type CargoResult<T> = Result<T, CargoError>;
|
||||
|
||||
pub struct CargoError {
|
||||
|
Loading…
x
Reference in New Issue
Block a user