Skip to content

Commit

Permalink
fix: Benchy test without git code cannot output result
Browse files Browse the repository at this point in the history
  • Loading branch information
lovel8 committed Mar 30, 2023
1 parent 963eb08 commit 79edf81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
3 changes: 3 additions & 0 deletions fil-proofs-tooling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ humansize = "1.1.0"
blstrs = "0.6.0"
time = "0.3.9"

[build-dependencies]
vergen = "3.1.0"

[features]
default = ["opencl", "measurements"]
cuda = [
Expand Down
4 changes: 4 additions & 0 deletions fil-proofs-tooling/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use vergen::{ConstantsFlags, generate_cargo_keys};
fn main() {
generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate cargo keys!");
}
19 changes: 3 additions & 16 deletions fil-proofs-tooling/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use anyhow::{anyhow, Result};
use chrono::{DateTime, TimeZone, Utc};
use git2::Repository;
use serde::Serialize;

/// Captures metadata about the current setup.
Expand All @@ -27,25 +25,14 @@ impl<T> Metadata<T> {
#[serde(rename_all = "kebab-case")]
pub struct GitMetadata {
hash: String,
date: DateTime<Utc>,
date: String,
}

impl GitMetadata {
pub fn new() -> Result<Self> {
let repo_path = if let Ok(mdir) = std::env::var("CARGO_MANIFEST_DIR") {
std::path::Path::new(&mdir).into()
} else {
std::env::current_dir()?
};
let repo = Repository::discover(repo_path)?;
let head = repo.head()?;
let commit = head.peel_to_commit()?;
// Unwrap is OK as the given seconds won't be out of range.
let date = Utc.timestamp_opt(commit.time().seconds(), 0).unwrap();

Ok(GitMetadata {
hash: commit.id().to_string(),
date,
hash: env!("VERGEN_SHA").to_string(),
date: env!("VERGEN_COMMIT_DATE").to_string(),
})
}
}
Expand Down

0 comments on commit 79edf81

Please sign in to comment.