Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
use git2::{DescribeFormatOptions, DescribeOptions, Repository};
use git2::{DescribeFormatOptions, DescribeOptions, Error, Repository};

fn main() {
let Ok(repo) = Repository::open(".").map_err(|e| {
println!("cargo::warning={}", e);
e
}) else {
return;
};
let Ok(git_describe_result) = repo
.describe(
DescribeOptions::new()
.describe_tags()
.show_commit_oid_as_fallback(true),
)
.and_then(|describe| {
describe.format(Some(
DescribeFormatOptions::new()
.always_use_long_format(true)
.dirty_suffix("-dirty"),
))
}).map_err(|e| {
println!("cargo::warning={}", e);
e
})
else {
return;
};
println!("cargo::rustc-env=GIT_DESCRIBE={git_describe_result}")
match get_git_describe_result() {
Ok(result) => println!("cargo::rustc-env=GIT_DESCRIBE={result}"),
Err(e) => println!("cargo::warning={}", e),
}
}

fn get_git_describe_result() -> Result<String, Error> {
let repo = Repository::open(".")?;
let describe = repo.describe(
DescribeOptions::new()
.describe_tags()
.show_commit_oid_as_fallback(true),
)?;
let formatted = describe.format(Some(
DescribeFormatOptions::new()
.always_use_long_format(true)
.dirty_suffix("-dirty"),
))?;
Ok(formatted)
}