-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to vergen 5, add branch, commit time, and build target to the panic metadata, automatically update app version from crate version #2029
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aee3bef
build(deps): bump vergen from 3.2.0 to 5.1.1
fanatid 8668492
fix hardcoded version for Tracing struct
fanatid b0cdadb
add additional metadata
fanatid 521b85d
remove extra allocations for metadata
fanatid c40d2c7
Remove zebrad code version from release checklist
teor2345 9264005
Sort panic metadata into rough categories
teor2345 1dd13bb
Merge remote-tracking branch 'upstream/main' into vergen
fanatid 5176643
Merge remote-tracking branch 'upstream/main' into vergen
fanatid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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,107 +1,13 @@ | ||
#![allow(clippy::try_err)] | ||
|
||
use std::{env, fs, fs::File, io::Read, path::PathBuf}; | ||
|
||
use vergen::{generate_cargo_keys, ConstantsFlags}; | ||
use vergen::{vergen, Config, ShaKind}; | ||
|
||
fn main() { | ||
let mut flags = ConstantsFlags::empty(); | ||
flags.toggle(ConstantsFlags::SHA_SHORT); | ||
|
||
// We want to use REBUILD_ON_HEAD_CHANGE here, but vergen assumes that the | ||
// git directory is in the crate directory, and Zebra uses a workspace. | ||
// See rustyhorde/vergen#15 and rustyhorde/vergen#21 for details. | ||
let result = generate_rebuild_key(); | ||
if let Err(err) = result { | ||
eprintln!("Error generating 'cargo:rerun-if-changed': {:?}", err); | ||
} | ||
|
||
// Generate the 'cargo:' key output | ||
generate_cargo_keys(flags).expect("Unable to generate the cargo keys!"); | ||
} | ||
|
||
/// Generate the `cargo:` rebuild keys output | ||
/// | ||
/// The keys that can be generated include: | ||
/// * `cargo:rustc-rerun-if-changed=<git dir>/HEAD` | ||
/// * `cargo:rustc-rerun-if-changed=<file git HEAD points to>` | ||
fn generate_rebuild_key() -> Result<(), Box<dyn std::error::Error>> { | ||
// Look for .git and ../.git | ||
// We should really use the `git2` crate here, see rustyhorde/vergen#15 | ||
let mut git_dir_or_file = env::current_dir()?.join(".git"); | ||
let mut metadata = fs::metadata(&git_dir_or_file); | ||
// git searches all the ancestors of the current directory, but Zebra's | ||
// crates are direct children of the workspace directory, so we only | ||
// need to look at the parent directory | ||
if metadata.is_err() { | ||
git_dir_or_file = env::current_dir()? | ||
.parent() | ||
.ok_or("finding crate's parent directory")? | ||
.to_path_buf() | ||
.join(".git"); | ||
metadata = fs::metadata(&git_dir_or_file); | ||
} | ||
|
||
// Modified from vergen's REBUILD_ON_HEAD_CHANGE implementation: | ||
// https://github.com/rustyhorde/vergen/blob/master/src/output/envvar.rs#L46 | ||
if let Ok(metadata) = metadata { | ||
if metadata.is_dir() { | ||
// Echo the HEAD path | ||
let git_head_path = git_dir_or_file.join("HEAD"); | ||
println!("cargo:rerun-if-changed={}", git_head_path.display()); | ||
|
||
// Determine where HEAD points and echo that path also. | ||
let mut f = File::open(&git_head_path)?; | ||
let mut git_head_contents = String::new(); | ||
let _ = f.read_to_string(&mut git_head_contents)?; | ||
eprintln!("HEAD contents: {}", git_head_contents); | ||
let ref_vec: Vec<&str> = git_head_contents.split(": ").collect(); | ||
|
||
if ref_vec.len() == 2 { | ||
let current_head_file = ref_vec[1].trim(); | ||
let git_refs_path = git_dir_or_file.join(current_head_file); | ||
println!("cargo:rerun-if-changed={}", git_refs_path.display()); | ||
} else { | ||
eprintln!("You are most likely in a detached HEAD state"); | ||
} | ||
} else if metadata.is_file() { | ||
// We are in a worktree, so find out where the actual worktrees/<name>/HEAD file is. | ||
let mut git_file = File::open(&git_dir_or_file)?; | ||
let mut git_contents = String::new(); | ||
let _ = git_file.read_to_string(&mut git_contents)?; | ||
let dir_vec: Vec<&str> = git_contents.split(": ").collect(); | ||
eprintln!(".git contents: {}", git_contents); | ||
let git_path = dir_vec[1].trim(); | ||
|
||
// Echo the HEAD path | ||
let git_head_path = PathBuf::from(git_path).join("HEAD"); | ||
println!("cargo:rerun-if-changed={}", git_head_path.display()); | ||
|
||
// Find out what the full path to the .git dir is. | ||
let mut actual_git_dir = PathBuf::from(git_path); | ||
actual_git_dir.pop(); | ||
actual_git_dir.pop(); | ||
let mut config = Config::default(); | ||
|
||
// Determine where HEAD points and echo that path also. | ||
let mut f = File::open(&git_head_path)?; | ||
let mut git_head_contents = String::new(); | ||
let _ = f.read_to_string(&mut git_head_contents)?; | ||
eprintln!("HEAD contents: {}", git_head_contents); | ||
let ref_vec: Vec<&str> = git_head_contents.split(": ").collect(); | ||
*config.cargo_mut().features_mut() = false; | ||
*config.cargo_mut().profile_mut() = false; | ||
|
||
if ref_vec.len() == 2 { | ||
let current_head_file = ref_vec[1].trim(); | ||
let git_refs_path = actual_git_dir.join(current_head_file); | ||
println!("cargo:rerun-if-changed={}", git_refs_path.display()); | ||
} else { | ||
eprintln!("You are most likely in a detached HEAD state"); | ||
} | ||
} else { | ||
Err("Invalid .git format (Not a directory or a file)")?; | ||
}; | ||
} else { | ||
Err(".git directory or file not found in crate dir or parent dir")?; | ||
}; | ||
*config.git_mut().semver_mut() = false; | ||
*config.git_mut().sha_kind_mut() = ShaKind::Short; | ||
|
||
Ok(()) | ||
vergen(config).expect("Unable to generate the cargo keys!"); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I've been waiting for these for a while.