Update to vergen 5, add branch, commit time, and build target to the panic metadata, automatically update app version from crate version (#2029)

* build(deps): bump vergen from 3.2.0 to 5.1.1

* fix hardcoded version for Tracing struct

* add additional metadata

* remove extra allocations for metadata

* Remove zebrad code version from release checklist

The zebrad code automatically uses the crate version now.

* Sort panic metadata into rough categories

Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
Kirill Fomichev 2021-04-19 23:48:14 +03:00 committed by GitHub
parent 2cecd52a10
commit 43e792b9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 183 additions and 124 deletions

View File

@ -16,7 +16,7 @@ what's changed.
- [ ] Increment the crates that have new commits since the last version update
- [ ] Increment any crates that depend on crates that have changed
- [ ] Use the `zebrad` crate version in the `zebrad` app code and `zebra-network` user agent
- [ ] Use the `zebrad` crate version in the `zebra-network` user agent string
- [ ] Use the latest git tag in `README.md`
### How to Increment Versions
@ -57,7 +57,6 @@ Increment the first version component in this list, and reset the other componen
Once you know which versions you want to increment, you can find them in the:
- [ ] zebra* `Cargo.toml`s
- [ ] tower-* `Cargo.toml`s
- [ ] `zebrad` app code: https://github.com/ZcashFoundation/zebra/blob/main/zebrad/src/components/tracing/component.rs
- [ ] `zebra-network` protocol user agent: https://github.com/ZcashFoundation/zebra/blob/main/zebra-network/src/constants.rs
- [ ] `README.md`
- [ ] `Cargo.lock`: automatically generated by `cargo build`

157
Cargo.lock generated
View File

@ -106,6 +106,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "anyhow"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b"
[[package]]
name = "arc-swap"
version = "1.0.0"
@ -690,7 +696,7 @@ checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e"
dependencies = [
"cfg-if 0.1.10",
"crossbeam-channel 0.4.4",
"crossbeam-deque",
"crossbeam-deque 0.7.3",
"crossbeam-epoch 0.8.2",
"crossbeam-queue",
"crossbeam-utils 0.7.2",
@ -715,6 +721,16 @@ dependencies = [
"maybe-uninit",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils 0.8.0",
]
[[package]]
name = "crossbeam-deque"
version = "0.7.3"
@ -726,6 +742,17 @@ dependencies = [
"maybe-uninit",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-epoch 0.9.0",
"crossbeam-utils 0.8.0",
]
[[package]]
name = "crossbeam-epoch"
version = "0.8.2"
@ -982,6 +1009,26 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "enum-iterator"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c79a6321a1197d7730510c7e3f6cb80432dfefecb32426de8cea0aa19b4bb8d7"
dependencies = [
"enum-iterator-derive",
]
[[package]]
name = "enum-iterator-derive"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e94aa31f7c0dc764f57896dc615ddd76fc13b0d5dca7eb6cc5e018a5a09ec06"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.7",
"syn 1.0.60",
]
[[package]]
name = "env_logger"
version = "0.8.3"
@ -1256,12 +1303,37 @@ dependencies = [
"wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "getset"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24b328c01a4d71d2d8173daa93562a73ab0fe85616876f02500f53d82948c504"
dependencies = [
"proc-macro-error",
"proc-macro2 1.0.24",
"quote 1.0.7",
"syn 1.0.60",
]
[[package]]
name = "gimli"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce"
[[package]]
name = "git2"
version = "0.13.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d250f5f82326884bd39c2853577e70a121775db76818ffa452ed1e80de12986"
dependencies = [
"bitflags",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]]
name = "glob"
version = "0.3.0"
@ -1706,9 +1778,21 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.80"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "libgit2-sys"
version = "0.12.18+1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3da6a42da88fc37ee1ecda212ffa254c25713532980005d5f7c0b0fbe7e6e885"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]]
name = "libloading"
@ -1732,6 +1816,18 @@ dependencies = [
"libc",
]
[[package]]
name = "libz-sys"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "lock_api"
version = "0.4.2"
@ -2195,6 +2291,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]]
name = "plotters"
version = "0.3.0"
@ -2509,6 +2611,31 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rayon"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674"
dependencies = [
"autocfg",
"crossbeam-deque 0.8.0",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
dependencies = [
"crossbeam-channel 0.5.1",
"crossbeam-deque 0.8.0",
"crossbeam-utils 0.8.0",
"lazy_static",
"num_cpus",
]
[[package]]
name = "rdrand"
version = "0.4.0"
@ -2732,6 +2859,12 @@ dependencies = [
"webpki",
]
[[package]]
name = "rustversion"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd"
[[package]]
name = "rusty-fork"
version = "0.3.0"
@ -3784,6 +3917,12 @@ dependencies = [
"serde",
]
[[package]]
name = "vcpkg"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbdbff6266a24120518560b5dc983096efb98462e51d0d68169895b237be3e5d"
[[package]]
name = "vec_map"
version = "0.8.2"
@ -3792,13 +3931,17 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "vergen"
version = "3.2.0"
version = "5.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7141e445af09c8919f1d5f8a20dae0b20c3b57a45dee0d5823c6ed5d237f15a"
checksum = "05b12ae3b7d7a942d4698d79e20513c99fb3b6b7b0efc1b1f1fb0aafa31de939"
dependencies = [
"bitflags",
"anyhow",
"chrono",
"rustc_version",
"enum-iterator",
"getset",
"git2",
"rustversion",
"thiserror",
]
[[package]]

View File

@ -1,4 +1,4 @@
use std::fmt;
use std::{convert::From, fmt};
#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;
@ -13,12 +13,18 @@ pub enum Network {
Testnet,
}
impl From<&Network> for &'static str {
fn from(network: &Network) -> &'static str {
match network {
Network::Mainnet => "Mainnet",
Network::Testnet => "Testnet",
}
}
}
impl fmt::Display for Network {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Network::Mainnet => f.write_str("Mainnet"),
Network::Testnet => f.write_str("Testnet"),
}
f.write_str(self.into())
}
}

View File

@ -47,7 +47,7 @@ sentry = { version = "0.21.0", default-features = false, features = ["backtrace"
sentry-tracing = { git = "https://github.com/kellpossible/sentry-tracing.git", rev = "f1a4a4a16b5ff1022ae60be779eb3fb928ce9b0f" }
[build-dependencies]
vergen = "3.2.0"
vergen = { version = "5.1.1", default-features = false, features = ["cargo", "git"] }
[dev-dependencies]
abscissa_core = { version = "0.5", features = ["testing"] }

View File

@ -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);
let mut config = Config::default();
// 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);
}
*config.cargo_mut().features_mut() = false;
*config.cargo_mut().profile_mut() = false;
// 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();
// 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 = 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")?;
};
Ok(())
*config.git_mut().semver_mut() = false;
*config.git_mut().sha_kind_mut() = ShaKind::Short;
vergen(config).expect("Unable to generate the cargo keys!");
}

View File

@ -54,7 +54,7 @@ impl ZebradApp {
}
pub fn git_commit() -> &'static str {
const GIT_COMMIT_VERGEN: &str = env!("VERGEN_SHA_SHORT");
const GIT_COMMIT_VERGEN: &str = env!("VERGEN_GIT_SHA_SHORT");
const GIT_COMMIT_GCLOUD: Option<&str> = option_env!("SHORT_SHA");
GIT_COMMIT_GCLOUD.unwrap_or(GIT_COMMIT_VERGEN)
@ -155,17 +155,22 @@ impl Application for ZebradApp {
};
// collect the common metadata for the issue URL and panic report
let network = config.network.network.to_string();
let panic_metadata = vec![
("version", env!("CARGO_PKG_VERSION").to_string()),
("git commit", Self::git_commit().to_string()),
("Zcash network", network),
// git
("version", env!("CARGO_PKG_VERSION")),
("branch", env!("VERGEN_GIT_BRANCH")),
("git commit", Self::git_commit()),
("commit timestamp", env!("VERGEN_GIT_COMMIT_TIMESTAMP")),
// build
("target triple", env!("VERGEN_CARGO_TARGET_TRIPLE")),
// config
("Zcash network", (&config.network.network).into()),
];
let mut builder = color_eyre::config::HookBuilder::default();
let mut metadata_section = "Metadata:".to_string();
for (k, v) in panic_metadata {
builder = builder.add_issue_metadata(k, v.clone());
builder = builder.add_issue_metadata(k, v);
metadata_section.push_str(&format!("\n{}: {}", k, v));
}

View File

@ -77,7 +77,7 @@ impl<A: abscissa_core::Application> Component<A> for Tracing {
}
fn version(&self) -> abscissa_core::Version {
abscissa_core::Version::parse("1.0.0-alpha.6").unwrap()
abscissa_core::Version::parse(env!("CARGO_PKG_VERSION")).unwrap()
}
fn before_shutdown(&self, _kind: Shutdown) -> Result<(), FrameworkError> {