From 02900c744b22a7b86a8652c349045494df7a8a77 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Thu, 22 Aug 2024 10:36:05 +0800 Subject: [PATCH] fix #151 --- src/gen_const.rs | 81 +++++++++++++++++++++++++----------------------- src/git.rs | 1 - 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/gen_const.rs b/src/gen_const.rs index 7982c92..301739b 100644 --- a/src/gen_const.rs +++ b/src/gen_const.rs @@ -1,84 +1,87 @@ macro_rules! gen_const { ($fn_name:ident, $fn_body:expr) => { pub fn $fn_name() -> String { - $fn_body.to_string() + let (doc, content) = $fn_body; + format!( + "{}\n{}\n{}\n{}\n", + doc, + "#[allow(dead_code,missing_docs)]", + $crate::CARGO_CLIPPY_ALLOW_ALL, + content + ) } }; } -const VERSION_BRANCH_CONST: &str = r##" -/// A long version string describing the project. +const VERSION_BRANCH_CONST: (&str, &str) = ( + r#"/// A long version string describing the project. /// The version string contains the package version, branch, commit hash, build time, and build environment on separate lines. -/// This constant is suitable for printing to the user. -#[allow(dead_code)] -#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] -pub const VERSION:&str = shadow_rs::formatcp!(r#" +/// This constant is suitable for printing to the user."#, + r##"pub const VERSION:&str = shadow_rs::formatcp!(r#" pkg_version:{} branch:{} commit_hash:{} build_time:{} build_env:{},{}"#,PKG_VERSION, BRANCH, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST_CHANNEL -);"##; +);"##, +); -const VERSION_TAG_CONST: &str = r##" -/// A long version string describing the project. +const VERSION_TAG_CONST: (&str, &str) = ( + r#"/// A long version string describing the project. /// The version string contains the package version, current Git tag, commit hash, build time, and build environment on separate lines. -/// This constant is suitable for printing to the user. -#[allow(dead_code)] -#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] -pub const VERSION:&str = shadow_rs::formatcp!(r#" +/// This constant is suitable for printing to the user."#, + r##"pub const VERSION:&str = shadow_rs::formatcp!(r#" pkg_version:{} tag:{} commit_hash:{} build_time:{} build_env:{},{}"#,PKG_VERSION, TAG, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST_CHANNEL -);"##; +);"##, +); -const CLAP_VERSION_BRANCH_CONST: &str = r##"#[allow(dead_code,missing_docs)] -#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] -#[deprecated = "Replaced with `CLAP_LONG_VERSION`"] -pub const CLAP_VERSION:&str = shadow_rs::formatcp!(r#"{} +const CLAP_VERSION_BRANCH_CONST: (&str, &str) = ( + r#"#[deprecated = "Replaced with `CLAP_LONG_VERSION`"]"#, + r##"pub const CLAP_VERSION:&str = shadow_rs::formatcp!(r#"{} branch:{} commit_hash:{} build_time:{} build_env:{},{}"#,PKG_VERSION, BRANCH, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST_CHANNEL -);"##; +);"##, +); -const CLAP_VERSION_TAG_CONST: &str = r##"#[allow(dead_code,missing_docs)] -#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] -#[deprecated = "Replaced with `CLAP_LONG_VERSION`"] -pub const CLAP_VERSION:&str = shadow_rs::formatcp!(r#"{} +const CLAP_VERSION_TAG_CONST: (&str, &str) = ( + r#"#[deprecated = "Replaced with `CLAP_LONG_VERSION`"]"#, + r##"pub const CLAP_VERSION:&str = shadow_rs::formatcp!(r#"{} tag:{} commit_hash:{} build_time:{} build_env:{},{}"#,PKG_VERSION, TAG, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST_CHANNEL -);"##; +);"##, +); -const CLAP_LONG_VERSION_BRANCH_CONST: &str = r##" -/// A long version string describing the project. +const CLAP_LONG_VERSION_BRANCH_CONST: (&str, &str) = ( + r#"/// A long version string describing the project. /// The version string contains the package version, branch, commit hash, build time, and build environment on separate lines. -/// This constant is intended to be used by clap or other CLI tools as a long version string. -#[allow(dead_code)] -#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] -pub const CLAP_LONG_VERSION:&str = shadow_rs::formatcp!(r#"{} +/// This constant is intended to be used by clap or other CLI tools as a long version string."#, + r##"pub const CLAP_LONG_VERSION:&str = shadow_rs::formatcp!(r#"{} branch:{} commit_hash:{} build_time:{} build_env:{},{}"#,PKG_VERSION, BRANCH, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST_CHANNEL -);"##; +);"##, +); -const CLAP_LONG_VERSION_TAG_CONST: &str = r##" -/// A long version string describing the project. +const CLAP_LONG_VERSION_TAG_CONST: (&str, &str) = ( + r#"/// A long version string describing the project. /// The version string contains the package version, current Git tag, commit hash, build time, and build environment on separate lines. -/// This constant is intended to be used by clap or other CLI tools as a long version string. -#[allow(dead_code)] -#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)] -pub const CLAP_LONG_VERSION:&str = shadow_rs::formatcp!(r#"{} +/// This constant is intended to be used by clap or other CLI tools as a long version string."#, + r##"pub const CLAP_LONG_VERSION:&str = shadow_rs::formatcp!(r#"{} tag:{} commit_hash:{} build_time:{} build_env:{},{}"#,PKG_VERSION, TAG, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST_CHANNEL -);"##; +);"##, +); gen_const!(version_branch_const, VERSION_BRANCH_CONST); gen_const!(version_tag_const, VERSION_TAG_CONST); diff --git a/src/git.rs b/src/git.rs index e627e43..ae00c87 100644 --- a/src/git.rs +++ b/src/git.rs @@ -9,7 +9,6 @@ use std::process::{Command, Stdio}; const BRANCH_DOC: &str = r#" The name of the Git branch that this project was built from. - This constant will be empty if the branch cannot be determined."#; pub const BRANCH: ShadowConst = "BRANCH"; const TAG_DOC: &str = r#"