Function grev::git_revision
source · pub fn git_revision<D, S, I>(directory: D, sources: S) -> Result<Option<String>>where
D: AsRef<Path>,
S: IntoIterator<Item = I>,
I: AsRef<Path>,
Expand description
Retrieve a git revision identifier that either includes the tag we
are on or the shortened SHA-1. It also contains an indication (+
)
whether local changes were present.
This function is meant to be run from a Cargo build script. It takes
care of printing necessary rerun-if-changed
directives to stdout
as expected by cargo
. As a result, callers are advised to invoke
it only once and cache the result.
The provided directory
is a path expected to point somewhere into
the git repository in question. Typically, it can simply be set to
the value of the CARGO_MANIFEST_DIR
variable, as set by Cargo.
The provided sources
should be a list of source files or
directories (excluding any git
data) that influence the components
embedding the git revision produced in one way or another. Typically
including src/
in there is sufficient, but more advanced
applications may depend on additional data.
The function works on a best-effort basis: if git is not available
or no git repository is present, it will fail gracefully by
returning Ok(None)
.