Skip to content

Commit

Permalink
fix #151
Browse files Browse the repository at this point in the history
  • Loading branch information
baoyachi committed Aug 22, 2024
1 parent a909ce7 commit 02900c7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
81 changes: 42 additions & 39 deletions src/gen_const.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down

0 comments on commit 02900c7

Please sign in to comment.