From 5ed6ea843c36ccb77a281b3a3fa04b382c87be3e Mon Sep 17 00:00:00 2001 From: baoyachi Date: Fri, 12 Nov 2021 10:29:44 +0800 Subject: [PATCH] use is_debug crate --- Cargo.toml | 3 ++- src/channel.rs | 27 --------------------------- src/env.rs | 2 +- src/lib.rs | 24 ++++++++++-------------- 4 files changed, 13 insertions(+), 43 deletions(-) delete mode 100644 src/channel.rs diff --git a/Cargo.toml b/Cargo.toml index bea9f9b..fe5d40e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadow-rs" -version = "0.7.2" +version = "0.7.3" authors = ["baoyachi "] edition = "2021" description = "A build-time information stored in your rust project" @@ -13,6 +13,7 @@ exclude = ["shadow-rs.png"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +is_debug = "1.0.1" chrono = "0.4.13" git2 = { version = "0.13.20", default-features = false, optional = true } diff --git a/src/channel.rs b/src/channel.rs deleted file mode 100644 index 60e5536..0000000 --- a/src/channel.rs +++ /dev/null @@ -1,27 +0,0 @@ -#[derive(Debug, PartialEq)] -pub enum BuildRustChannel { - Debug, - Release, -} - -impl Default for BuildRustChannel { - fn default() -> Self { - BuildRustChannel::Debug - } -} - -pub fn build_channel() -> BuildRustChannel { - if cfg!(debug_assertions) { - return BuildRustChannel::Debug; - } - BuildRustChannel::Release -} - -impl ToString for BuildRustChannel { - fn to_string(&self) -> String { - match self { - BuildRustChannel::Debug => "debug".to_string(), - BuildRustChannel::Release => "release".to_string(), - } - } -} diff --git a/src/env.rs b/src/env.rs index 7e33543..4b706da 100644 --- a/src/env.rs +++ b/src/env.rs @@ -1,5 +1,4 @@ use crate::build::*; -use crate::channel::*; use crate::err::SdResult; use chrono::SecondsFormat; @@ -9,6 +8,7 @@ use std::process::Command; use crate::env::dep_source_replace::filter_cargo_tree; use crate::time::now_data_time; use crate::Format; +use is_debug::build_channel; use std::collections::HashMap; #[derive(Default, Debug)] diff --git a/src/lib.rs b/src/lib.rs index d8cc346..0d29e71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,13 +143,22 @@ mod build; mod build_fn; -mod channel; mod ci; mod env; mod err; mod git; mod time; +/// Get current project build mode. +/// +/// It's very useful. Debug mode is usually used for debugging information. +/// For example, log printing, environment variable switch. +/// +/// The default value is `true`. +/// +/// If we compile with `cargo build --release`. It's return value is `false`. +pub use is_debug::*; + use build::*; use env::*; @@ -167,7 +176,6 @@ use crate::build_fn::{ clap_version_branch_fn, clap_version_tag_fn, version_branch_fn, version_tag_fn, BUILD_FN_CLAP_VERSION, BUILD_FN_VERSION, }; -pub use channel::BuildRustChannel; use chrono::Local; pub use err::{SdResult, ShadowError}; pub use git::{branch, git_clean, git_status_file, tag}; @@ -235,18 +243,6 @@ where shadow.hook(f) } -/// Get current project build mode. -/// -/// It's very useful. Debug mode is usually used for debugging information. -/// For example, log printing, environment variable switch. -/// -/// The default value is `true`. -/// -/// If we compile with `cargo build --release`. It's return value is `false`. -pub fn is_debug() -> bool { - channel::build_channel() == BuildRustChannel::Debug -} - /// get std::env:vars pub fn get_std_env() -> HashMap { let mut env_map = HashMap::new();