Skip to content

Commit

Permalink
add PKG_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed Aug 24, 2020
1 parent 9adaccb commit 6cee93d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shadow-rs"
version = "0.3.13"
version = "0.3.14"
authors = ["baoyachi <liaoymxsdl@gmail.com>"]
edition = "2018"
description = "A tool record compiled project much information,version info,dependence info.Like shadow,if compiled,never change.forever follow your project."
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions example_shadow/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}
}
Expand Down Expand Up @@ -77,6 +83,12 @@ pub fn new_system_env() -> HashMap<ShadowConst, RefCell<ConstVal>> {
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"),
Expand Down
37 changes: 19 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
Expand Down

0 comments on commit 6cee93d

Please sign in to comment.