-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use core::str; | ||
use git2::{Repository, StatusOptions}; | ||
use std::{env, error::Error}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
// In contrast to git describe, we don't want to show a tag name, but always the short sha and | ||
// dirty status as a useful addition to the version number in CARGO_PKG_VERSION. | ||
let repo = Repository::discover(env::var("CARGO_MANIFEST_DIR")?)?; | ||
let head_obj = repo.revparse_single("HEAD")?; | ||
let short_sha_buf = head_obj.short_id()?; | ||
let short_sha = str::from_utf8(&short_sha_buf)?; | ||
let mut status_options = StatusOptions::default(); | ||
// let _ = status_options.include_untracked(true); | ||
let statuses = repo.statuses(Some(&mut status_options))?; | ||
let dirty = statuses.iter().any(|st| !st.status().is_ignored()); | ||
let dirty_str = if dirty { "+" } else { "" }; | ||
println!("cargo::rustc-env=GIT_SHORT_SHA={}{}", short_sha, dirty_str); | ||
|
||
println!("cargo::rerun-if-changed=build.rs"); | ||
println!("cargo::rerun-if-changed=.git/"); | ||
println!("cargo::rerun-if-changed=.git/HEAD"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters