From 6cee93dd2dfbd59682a4efd13eca378c0d6b5f26 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Tue, 25 Aug 2020 02:29:44 +0800 Subject: [PATCH] add PKG_VERSION --- Cargo.toml | 2 +- README.md | 1 + example_shadow/src/main.rs | 1 + src/env.rs | 12 ++++++++++++ src/lib.rs | 37 +++++++++++++++++++------------------ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f79b8a7..4fe947a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shadow-rs" -version = "0.3.13" +version = "0.3.14" authors = ["baoyachi "] edition = "2018" description = "A tool record compiled project much information,version info,dependence info.Like shadow,if compiled,never change.forever follow your project." diff --git a/README.md b/README.md index d33a2e2..8a9effb 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ fn main() { println!("{}",shadow::RUST_VERSION);//rustc 1.45.0 (5c1f21c3b 2020-07-13) println!("{}",shadow::RUST_CHANNEL);//stable-x86_64-apple-darwin (default) println!("{}",shadow::CARGO_VERSION);//cargo 1.45.0 (744bd1fbb 2020-06-15) + println!("{}",shadow::PKG_VERSION);//0.3.13 println!("{}",shadow::CARGO_LOCK); println!("{}",shadow::PROJECT_NAME);//shadow-rs diff --git a/example_shadow/src/main.rs b/example_shadow/src/main.rs index d2367bd..17a13c2 100644 --- a/example_shadow/src/main.rs +++ b/example_shadow/src/main.rs @@ -14,6 +14,7 @@ fn main() { println!("rust_version:{}", shadow::RUST_VERSION); println!("rust_channel:{}", shadow::RUST_CHANNEL); println!("cargo_version:{}", shadow::CARGO_VERSION); + println!("pkg_version:{}", shadow::PKG_VERSION); println!("cargo_lock:{}", shadow::CARGO_LOCK); println!("project_name:{}", shadow::PROJECT_NAME); diff --git a/src/env.rs b/src/env.rs index c4001cb..ac026d6 100644 --- a/src/env.rs +++ b/src/env.rs @@ -19,6 +19,7 @@ const RUST_VERSION: ShadowConst = "RUST_VERSION"; const RUST_CHANNEL: ShadowConst = "RUST_CHANNEL"; const CARGO_VERSION: ShadowConst = "CARGO_VERSION"; const CARGO_LOCK: ShadowConst = "CARGO_LOCK"; +const PKG_VERSION: ShadowConst = "PKG_VERSION"; // const CARGO_TREE: &str = "CARGO_TREE"; impl SystemEnv { @@ -50,6 +51,11 @@ impl SystemEnv { String::from_utf8(out.stdout)?.trim().to_string(), ); } + + if let Some(v) = option_env!("CARGO_PKG_VERSION") { + update_val(PKG_VERSION, v.to_string()); + } + Ok(()) } } @@ -77,6 +83,12 @@ pub fn new_system_env() -> HashMap> { CARGO_VERSION, ConstVal::new("display build system cargo version"), ); + + env.map.insert( + PKG_VERSION, + ConstVal::new("display build current project version"), + ); + env.map.insert( CARGO_LOCK, ConstVal::new("display build project dependence cargo lock detail"), diff --git a/src/lib.rs b/src/lib.rs index 66100c2..b96ba63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,25 @@ const SHADOW_RS: &str = "shadow.rs"; /// record compiled project much information. /// version info,dependence info.Like shadow,if compiled,never change.forever follow your project. +/// generated rust const by exec:`cargo build` +/// +///```rust +/// pub const RUST_VERSION :&str = "rustc 1.45.0 (5c1f21c3b 2020-07-13)"; +/// pub const BUILD_RUST_CHANNEL :&str = "debug"; +/// pub const COMMIT_AUTHOR :&str = "baoyachi"; +/// pub const BUILD_TIME :&str = "2020-08-16 13:48:52"; +/// pub const COMMIT_DATE :&str = "2020-08-16 13:12:52"; +/// pub const COMMIT_EMAIL :&str = "xxx@gmail.com"; +/// pub const PROJECT_NAME :&str = "shadow-rs"; +/// pub const RUST_CHANNEL :&str = "stable-x86_64-apple-darwin (default)"; +/// pub const BRANCH :&str = "master"; +/// pub const CARGO_LOCK :&str = ""; +/// pub const CARGO_VERSION :&str = "cargo 1.45.0 (744bd1fbb 2020-06-15)"; +/// pub const BUILD_OS :&str = "macos-x86_64"; +/// pub const COMMIT_HASH :&str = "386741540d73c194a3028b96b92fdeb53ca2788a"; +/// pub const PKG_VERSION :&str = "0.3.13"; +/// +/// ``` #[derive(Debug)] pub struct Shadow { f: File, @@ -50,24 +69,6 @@ impl Shadow { CIType::None } - /// generated rust const by exec:`cargo build` - /// - ///```rust - /// pub const RUST_VERSION :&str = "rustc 1.45.0 (5c1f21c3b 2020-07-13)"; - /// pub const BUILD_RUST_CHANNEL :&str = "debug"; - /// pub const COMMIT_AUTHOR :&str = "baoyachi"; - /// pub const BUILD_TIME :&str = "2020-08-16 13:48:52"; - /// pub const COMMIT_DATE :&str = "2020-08-16 13:12:52"; - /// pub const COMMIT_EMAIL :&str = "xxx@gmail.com"; - /// pub const PROJECT_NAME :&str = "shadow-rs"; - /// pub const RUST_CHANNEL :&str = "stable-x86_64-apple-darwin (default)"; - /// pub const BRANCH :&str = "master"; - /// pub const CARGO_LOCK :&str = ""; - /// pub const CARGO_VERSION :&str = "cargo 1.45.0 (744bd1fbb 2020-06-15)"; - /// pub const BUILD_OS :&str = "macos-x86_64"; - /// pub const COMMIT_HASH :&str = "386741540d73c194a3028b96b92fdeb53ca2788a"; - /// - /// ``` pub fn build(src_path: String, out_path: String) -> SdResult<()> { let ci_type = Self::try_ci(); let src_path = Path::new(src_path.as_str());