-
Notifications
You must be signed in to change notification settings - Fork 1
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
3 changed files
with
28 additions
and
86 deletions.
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 |
---|---|---|
@@ -1,56 +1,37 @@ | ||
use anyhow::Result; | ||
use git2_rs::Repository; | ||
use std::collections::BTreeMap; | ||
|
||
use vergen::{AddCustomEntries, CargoRerunIfChanged, CargoWarning, DefaultConfig, Emitter}; | ||
|
||
#[derive(Default)] | ||
struct VersionEntryBuilder {} | ||
|
||
impl AddCustomEntries<&str, String> for VersionEntryBuilder { | ||
fn add_calculated_entries( | ||
&self, | ||
_idempotent: bool, | ||
cargo_rustc_env_map: &mut BTreeMap<&str, String>, | ||
_cargo_rerun_if_changed: &mut CargoRerunIfChanged, | ||
cargo_warning: &mut CargoWarning, | ||
) -> Result<()> { | ||
let repo_dir = std::env::current_dir()?; | ||
let repo = Repository::discover(repo_dir)?; | ||
let ref_head = repo.revparse_single("HEAD")?; | ||
let git_sha_buf = ref_head.short_id()?; | ||
let git_sha = git_sha_buf.as_str(); | ||
|
||
let pkg_version = std::env::var("CARGO_PKG_VERSION")?; | ||
|
||
let mut version = format!("Eclair v{}", pkg_version); | ||
|
||
if pkg_version.contains("-dev") { | ||
if let Some(git_short_sha) = git_sha { | ||
version = format!("{} ({})", version, git_short_sha); | ||
} else { | ||
cargo_warning.push("Failed to get git short sha".to_string()); | ||
} | ||
} | ||
|
||
cargo_rustc_env_map.insert("ECLAIR_VERSION", version); | ||
fn get_eclair_version() -> Result<(String, Vec<String>)> { | ||
let mut warnings = vec![]; | ||
|
||
Ok(()) | ||
} | ||
let repo_dir = std::env::current_dir()?; | ||
let repo = Repository::discover(repo_dir)?; | ||
let ref_head = repo.revparse_single("HEAD")?; | ||
let git_sha_buf = ref_head.short_id()?; | ||
let git_sha = git_sha_buf.as_str(); | ||
|
||
let pkg_version = std::env::var("CARGO_PKG_VERSION")?; | ||
|
||
fn add_default_entries( | ||
&self, | ||
_config: &DefaultConfig, | ||
_cargo_rustc_env_map: &mut BTreeMap<&str, String>, | ||
_cargo_rerun_if_changed: &mut CargoRerunIfChanged, | ||
_cargo_warning: &mut CargoWarning, | ||
) -> Result<()> { | ||
Ok(()) | ||
let mut version = format!("Eclair v{}", pkg_version); | ||
|
||
if pkg_version.contains("-dev") { | ||
if let Some(git_short_sha) = git_sha { | ||
version = format!("{} ({})", version, git_short_sha); | ||
} else { | ||
warnings.push("Failed to get git short sha".to_string()); | ||
} | ||
} | ||
Ok((version, warnings)) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
Emitter::default() | ||
.add_custom_instructions(&VersionEntryBuilder::default())? | ||
.emit() | ||
let (version, warnings) = get_eclair_version()?; | ||
|
||
for warning in warnings { | ||
println!("cargo::warning={}", warning); | ||
} | ||
|
||
println!("cargo::rustc-env=ECLAIR_VERSION={}", version); | ||
|
||
Ok(()) | ||
} |