From d142a1a556cde9119ecf1b5ca4aa57d1fc6a3549 Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Thu, 26 Jul 2018 21:32:25 +0700 Subject: [PATCH] Problem: `cfg` module doesn't really belong to sit-core The main thought here is that `cfg` defines structures that are used by code outside of `sit-core` (namely, `sit` crate). Solution: move `cfg` to the `sit` crate --- Cargo.lock | 1 - Cargo.toml | 3 +++ sit-core/Cargo.toml | 2 -- sit-core/src/lib.rs | 1 - sit/Cargo.toml | 6 ++++-- {sit-core => sit}/src/cfg.rs | 1 + sit/src/command_items.rs | 3 ++- sit/src/command_record.rs | 2 +- sit/src/command_records.rs | 3 ++- sit/src/command_reduce.rs | 4 ++-- sit/src/command_web.rs | 8 +++++--- sit/src/lib.rs | 5 ++++- sit/src/main.rs | 8 ++++---- 13 files changed, 28 insertions(+), 19 deletions(-) rename {sit-core => sit}/src/cfg.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 64dc8661..2ac74533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1168,7 +1168,6 @@ dependencies = [ "derive-error 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "dunce 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "include_dir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index dfa78702..3cd0c713 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ [workspace] members = ["sit-core", "sit"] + +[profile.release] +lto = true diff --git a/sit-core/Cargo.toml b/sit-core/Cargo.toml index 65af5bc7..9f1141c7 100644 --- a/sit-core/Cargo.toml +++ b/sit-core/Cargo.toml @@ -26,7 +26,6 @@ sha-1 = { version = "0.7", optional = true } uuid = { version = "0.5", features = ["v4"], optional = true } memmap = { version = "0.6", optional = true} cesu8 = { version = "1.1", optional = true } -git2 = { version = "0.7", optional = true, default-features = false } relative-path = "0.3" [dev-dependencies] @@ -45,5 +44,4 @@ duktape-reducers = ["duktape", "cesu8"] duktape = [] duktape-mmap = ["memmap"] windows7 = [] -git = ["git2"] deprecated-item-api = [] diff --git a/sit-core/src/lib.rs b/sit-core/src/lib.rs index 7b47a6bf..cf0532ad 100644 --- a/sit-core/src/lib.rs +++ b/sit-core/src/lib.rs @@ -63,4 +63,3 @@ pub mod reducers; pub use reducers::Reducer; #[cfg(feature = "duktape")] pub mod duktape; -pub mod cfg; diff --git a/sit/Cargo.toml b/sit/Cargo.toml index 5fc8b91b..307a28e9 100644 --- a/sit/Cargo.toml +++ b/sit/Cargo.toml @@ -35,7 +35,8 @@ blake2 = { version = "0.7", optional = true } hex = { version = "0.3", optional = true } lazy_static = { version = "1.0", optional = true } serde_derive = { version = "1.0", optional = true } -sit-core = { path = "../sit-core", version = "0.5.0-pre", features = ["git"] } +git2 = { version = "0.7", optional = true, default-features = false } +sit-core = { path = "../sit-core", version = "0.5.0-pre" } [dev-dependencies] cli_test_dir = "0.1.5" @@ -47,7 +48,8 @@ include_dir = "0.1" fs_extra = "1.1" [features] -default = ["deprecated-items", "web"] +default = ["deprecated-items", "web", "git"] windows7 = ["sit-core/windows7"] deprecated-items = ["sit-core/deprecated-item-api"] web = ["rouille", "mime_guess", "digest", "blake2", "hex", "lazy_static", "serde_derive" ] +git = ["git2"] diff --git a/sit-core/src/cfg.rs b/sit/src/cfg.rs similarity index 99% rename from sit-core/src/cfg.rs rename to sit/src/cfg.rs index 7ee0b756..252ee7c1 100644 --- a/sit-core/src/cfg.rs +++ b/sit/src/cfg.rs @@ -1,4 +1,5 @@ //! Client configuration +#[cfg(feature = "git")] use std::path::PathBuf; #[derive(Clone, Serialize, Deserialize)] diff --git a/sit/src/command_items.rs b/sit/src/command_items.rs index 66cdf80c..11b53640 100644 --- a/sit/src/command_items.rs +++ b/sit/src/command_items.rs @@ -1,5 +1,6 @@ use clap::ArgMatches; -use sit_core::{self, reducers::duktape::DuktapeReducer, Repository, record::RecordContainerReduction, cfg::Configuration}; +use sit_core::{self, reducers::duktape::DuktapeReducer, Repository, record::RecordContainerReduction}; +use cfg::Configuration; use serde_json; use rayon::prelude::*; use super::get_named_expression; diff --git a/sit/src/command_record.rs b/sit/src/command_record.rs index 2573cafa..4096dab9 100644 --- a/sit/src/command_record.rs +++ b/sit/src/command_record.rs @@ -3,7 +3,7 @@ use chrono::prelude::*; use clap::{self, ArgMatches}; use dunce; use serde_json; -use sit_core::cfg::{self, Configuration}; +use cfg::{self, Configuration}; use sit_core::{ record::{BoxedOrderedFiles, OrderedFiles, RecordOwningContainer}, Record, Repository diff --git a/sit/src/command_records.rs b/sit/src/command_records.rs index 7fe3fd07..ef3780eb 100644 --- a/sit/src/command_records.rs +++ b/sit/src/command_records.rs @@ -1,5 +1,6 @@ use clap::ArgMatches; -use sit_core::{Repository, Record, cfg::Configuration, record::RecordContainer, record::OrderedFiles, path::HasPath}; +use sit_core::{Repository, Record, record::RecordContainer, record::OrderedFiles, path::HasPath}; +use cfg::Configuration; use serde_json; use super::get_named_expression; use jmespath; diff --git a/sit/src/command_reduce.rs b/sit/src/command_reduce.rs index 9f88aca4..9eb7bdc2 100644 --- a/sit/src/command_reduce.rs +++ b/sit/src/command_reduce.rs @@ -1,7 +1,7 @@ use clap::{ArgMatches, Values}; -use sit_core::{self, Repository, record::RecordContainerReduction, repository, cfg::Configuration, +use sit_core::{self, Repository, record::RecordContainerReduction, repository, reducers::duktape, path::{HasPath, ResolvePath}}; - +use cfg::Configuration; use serde_json; use super::get_named_expression; use jmespath; diff --git a/sit/src/command_web.rs b/sit/src/command_web.rs index 32f7b7eb..452485e6 100644 --- a/sit/src/command_web.rs +++ b/sit/src/command_web.rs @@ -1,5 +1,6 @@ use clap::{self, ArgMatches}; -use sit_core::{Repository, cfg::Configuration, repository}; +use sit_core::{Repository, repository}; +use cfg::Configuration; use std::path::PathBuf; pub fn command(repo: Repository, matches: &ArgMatches, main_matches: ArgMatches<'static>, config: Configuration) -> i32 @@ -13,6 +14,7 @@ pub fn command(repo: Repository, matches: &ArgMa } mod webapp { + use cfg; #[allow(dead_code)] mod assets { include!(concat!(env!("OUT_DIR"), "/web_assets.rs")); @@ -140,7 +142,7 @@ mod webapp { } - fn new_record(container: &C, request: &Request, repo: &Repository, config: &sit_core::cfg::Configuration, matches: &ArgMatches) -> Result { + fn new_record(container: &C, request: &Request, repo: &Repository, config: &cfg::Configuration, matches: &ArgMatches) -> Result { let mut multipart = get_multipart_input(request).expect("multipart request"); let mut link = true; let mut used_files = vec![]; @@ -274,7 +276,7 @@ mod webapp { } - pub fn start(addr: A, config: sit_core::cfg::Configuration, repo: Repository, readonly: bool, overlays: Vec<&str>, matches: ArgMatches<'static>) + pub fn start(addr: A, config: cfg::Configuration, repo: Repository, readonly: bool, overlays: Vec<&str>, matches: ArgMatches<'static>) where MI: sit_core::repository::ModuleIterator { let mut overlays: Vec<_> = overlays.iter().map(|o| PathBuf::from(o)).collect(); let assets: PathBuf = repo.path().join("web").into(); diff --git a/sit/src/lib.rs b/sit/src/lib.rs index c401068a..0efc9b21 100644 --- a/sit/src/lib.rs +++ b/sit/src/lib.rs @@ -1,7 +1,10 @@ extern crate sit_core; extern crate which; +#[cfg(feature = "git")] extern crate git2; +#[macro_use] extern crate serde_derive; +extern crate serde_json; #[macro_use] extern crate derive_error; mod cli; mod module_iter; - +pub mod cfg; pub use module_iter::{ScriptModuleIterator, ScriptModule}; diff --git a/sit/src/main.rs b/sit/src/main.rs index 8fd17315..e4c277ce 100644 --- a/sit/src/main.rs +++ b/sit/src/main.rs @@ -17,8 +17,8 @@ extern crate walkdir; extern crate yaml_rust; extern crate config; -use sit_core::cfg; +mod cfg; mod rebuild; use rebuild::rebuild_repository; mod command_config; @@ -75,9 +75,9 @@ extern crate hex; #[cfg(feature="web")] #[macro_use] extern crate lazy_static; -#[cfg(feature="web")] -#[macro_use] -extern crate serde_derive; + +#[cfg(feature = "git")] extern crate git2; +#[macro_use] extern crate serde_derive; use std::collections::HashMap; pub fn get_named_expression, MI>(name: S, repo: &sit_core::Repository,