Skip to content

Commit 81b3068

Browse files
committed
Rollback code
1 parent 72554cc commit 81b3068

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/gen_const.rs

-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{Shadow, CARGO_CLIPPY_ALLOW_ALL, CARGO_METADATA};
22

33
macro_rules! gen_const {
44
($fn_name:ident, $fn_body:expr) => {
5-
#[allow(unused)]
65
pub fn $fn_name() -> String {
76
let (doc, content) = $fn_body;
87
format!(
@@ -16,7 +15,6 @@ macro_rules! gen_const {
1615
};
1716
}
1817

19-
#[allow(dead_code)]
2018
const VERSION_BRANCH_CONST: (&str, &str) = (
2119
r#"/// A long version string describing the project.
2220
/// The version string contains the package version, branch, commit hash, build time, and build environment on separate lines.
@@ -30,7 +28,6 @@ build_env:{},{}"#,PKG_VERSION, BRANCH, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, R
3028
);"##,
3129
);
3230

33-
#[allow(dead_code)]
3431
const VERSION_TAG_CONST: (&str, &str) = (
3532
r#"/// A long version string describing the project.
3633
/// The version string contains the package version, current Git tag, commit hash, build time, and build environment on separate lines.
@@ -44,7 +41,6 @@ build_env:{},{}"#,PKG_VERSION, TAG, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST
4441
);"##,
4542
);
4643

47-
#[allow(dead_code)]
4844
const CLAP_VERSION_BRANCH_CONST: (&str, &str) = (
4945
r#"#[deprecated = "Replaced with `CLAP_LONG_VERSION`"]"#,
5046
r##"pub const CLAP_VERSION:&str = shadow_rs::formatcp!(r#"{}
@@ -55,7 +51,6 @@ build_env:{},{}"#,PKG_VERSION, BRANCH, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, R
5551
);"##,
5652
);
5753

58-
#[allow(dead_code)]
5954
const CLAP_VERSION_TAG_CONST: (&str, &str) = (
6055
r#"#[deprecated = "Replaced with `CLAP_LONG_VERSION`"]"#,
6156
r##"pub const CLAP_VERSION:&str = shadow_rs::formatcp!(r#"{}
@@ -66,7 +61,6 @@ build_env:{},{}"#,PKG_VERSION, TAG, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, RUST
6661
);"##,
6762
);
6863

69-
#[allow(dead_code)]
7064
const CLAP_LONG_VERSION_BRANCH_CONST: (&str, &str) = (
7165
r#"/// A long version string describing the project.
7266
/// The version string contains the package version, branch, commit hash, build time, and build environment on separate lines.
@@ -79,7 +73,6 @@ build_env:{},{}"#,PKG_VERSION, BRANCH, SHORT_COMMIT, BUILD_TIME, RUST_VERSION, R
7973
);"##,
8074
);
8175

82-
#[allow(dead_code)]
8376
const CLAP_LONG_VERSION_TAG_CONST: (&str, &str) = (
8477
r#"/// A long version string describing the project.
8578
/// The version string contains the package version, current Git tag, commit hash, build time, and build environment on separate lines.
@@ -102,9 +95,7 @@ gen_const!(
10295
);
10396
gen_const!(clap_long_version_tag_const, CLAP_LONG_VERSION_TAG_CONST);
10497

105-
#[allow(dead_code)]
10698
pub(crate) const BUILD_CONST_VERSION: &str = "VERSION";
107-
#[allow(dead_code)]
10899
pub(crate) const BUILD_CONST_CLAP_LONG_VERSION: &str = "CLAP_LONG_VERSION";
109100

110101
pub(crate) fn cargo_metadata_fn(shadow: &Shadow) -> String {

src/git.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ pub fn branch() -> String {
367367
#[cfg(feature = "git2")]
368368
{
369369
use crate::git::git2_mod::{git2_current_branch, git_repo};
370-
git_repo("../..")
370+
git_repo(".")
371371
.map(|x| git2_current_branch(&x))
372372
.unwrap_or_else(|_| command_current_branch())
373373
.unwrap_or_default()
@@ -393,7 +393,7 @@ pub fn git_clean() -> bool {
393393
#[cfg(feature = "git2")]
394394
{
395395
use crate::git::git2_mod::git_repo;
396-
git_repo("../..")
396+
git_repo(".")
397397
.map(|x| Git::git2_dirty_stage(&x))
398398
.map(|x| x.trim().is_empty())
399399
.unwrap_or(true)
@@ -413,7 +413,7 @@ pub fn git_status_file() -> String {
413413
#[cfg(feature = "git2")]
414414
{
415415
use crate::git::git2_mod::git_repo;
416-
git_repo("../..")
416+
git_repo(".")
417417
.map(|x| Git::git2_dirty_stage(&x))
418418
.unwrap_or_default()
419419
}
@@ -437,7 +437,7 @@ struct GitCommandExecutor<'a> {
437437

438438
impl Default for GitCommandExecutor<'_> {
439439
fn default() -> Self {
440-
Self::new(Path::new("../.."))
440+
Self::new(Path::new("."))
441441
}
442442
}
443443

@@ -599,7 +599,7 @@ mod tests {
599599
#[cfg(feature = "git2")]
600600
{
601601
use crate::git::git2_mod::{git2_current_branch, git_repo};
602-
let git2_branch = git_repo("../")
602+
let git2_branch = git_repo(".")
603603
.map(|x| git2_current_branch(&x))
604604
.unwrap_or(None);
605605
let command_branch = command_current_branch();

src/lib.rs

+25
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,31 @@ const DEFINE_SHADOW_RS: &str = "shadow.rs";
194194
pub const CARGO_CLIPPY_ALLOW_ALL: &str =
195195
"#[allow(clippy::all, clippy::pedantic, clippy::restriction, clippy::nursery)]";
196196

197+
/// Add a module with the provided name which contains the build information generated by `shadow-rs`.
198+
///
199+
/// # Example
200+
///
201+
/// ```ignore
202+
/// use shadow_rs::shadow;
203+
///
204+
/// shadow!(my_build_information);
205+
///
206+
/// fn main() {
207+
/// println!("I'm version {}!", my_build_information::VERSION);
208+
/// }
209+
/// ```
210+
///
211+
/// The convention, however, is to use `shadow!(build);`.
212+
#[macro_export]
213+
macro_rules! shadow {
214+
($build_mod:ident) => {
215+
#[doc = r#"shadow-rs mod"#]
216+
pub mod $build_mod {
217+
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
218+
}
219+
};
220+
}
221+
197222
/// Generates build information for the current project.
198223
/// This function must be called from `build.rs`.
199224
///

0 commit comments

Comments
 (0)