mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 00:38:36 +02:00
Add commit hash to version command (#2312)
* Add commit to version command * Replace unwrap with expect.
This commit is contained in:
41
crates/nu-cli/build.rs
Normal file
41
crates/nu-cli/build.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use std::path::Path;
|
||||
use std::{env, fs, io};
|
||||
|
||||
use git2::Repository;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
IoError(io::Error),
|
||||
GitError(git2::Error),
|
||||
}
|
||||
|
||||
impl From<git2::Error> for Error {
|
||||
fn from(git_error: git2::Error) -> Self {
|
||||
Self::GitError(git_error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(io_error: io::Error) -> Self {
|
||||
Self::IoError(io_error)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let out_dir = env::var_os("OUT_DIR").expect(
|
||||
"\
|
||||
OUT_DIR environment variable not found. \
|
||||
OUT_DIR is guaranteed to to exist in a build script by cargo - see \
|
||||
https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts\
|
||||
");
|
||||
let latest_commit_hash = Repository::discover(env::current_dir()?)?
|
||||
.head()?
|
||||
.peel_to_commit()?
|
||||
.id()
|
||||
.to_string();
|
||||
|
||||
let commit_hash_path = Path::new(&out_dir).join("git_commit_hash");
|
||||
fs::write(commit_hash_path, latest_commit_hash)?;
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user