refactor: expanded cli version info (#2742)

This commit is contained in:
Bjerg
2023-05-19 19:04:01 +02:00
committed by GitHub
parent 13a7209069
commit 3c2b591158
8 changed files with 87 additions and 70 deletions

58
Cargo.lock generated
View File

@ -138,9 +138,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299"
[[package]]
name = "anyhow"
version = "1.0.69"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]]
name = "aquamarine"
@ -509,7 +509,6 @@ checksum = "96f9cdd34d6eb553f9ea20e5bf84abb7b13c729f113fc1d8e49dc00ad9fa8738"
dependencies = [
"cargo-lock",
"chrono",
"git2",
"semver 1.0.17",
]
@ -2293,19 +2292,6 @@ version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
[[package]]
name = "git2"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc"
dependencies = [
"bitflags",
"libc",
"libgit2-sys",
"log",
"url",
]
[[package]]
name = "glob"
version = "0.3.1"
@ -3208,18 +3194,6 @@ version = "0.2.141"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
[[package]]
name = "libgit2-sys"
version = "0.14.2+1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4"
dependencies = [
"cc",
"libc",
"libz-sys",
"pkg-config",
]
[[package]]
name = "libloading"
version = "0.7.4"
@ -3236,18 +3210,6 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb"
[[package]]
name = "libz-sys"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "lifetimed-bytes"
version = "0.1.0"
@ -4649,6 +4611,7 @@ dependencies = [
"toml 0.7.3",
"tracing",
"tui",
"vergen",
]
[[package]]
@ -5788,9 +5751,9 @@ dependencies = [
[[package]]
name = "rustversion"
version = "1.0.11"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
[[package]]
name = "rusty-fork"
@ -7348,10 +7311,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcpkg"
version = "0.2.15"
name = "vergen"
version = "8.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
checksum = "6e03272e388fb78fc79481a493424f78d77be1d55f21bcd314b5a6716e195afe"
dependencies = [
"anyhow",
"rustversion",
"time",
]
[[package]]
name = "version_check"

View File

@ -7,9 +7,6 @@ repository = "https://github.com/paradigmxyz/reth"
readme = "README.md"
build = "build.rs"
[build-dependencies]
built = { version = "0.6", features = ["git2", "chrono", "semver"] }
# Add jemalloc for extra perf on Linux systems.
[target.'cfg(all(not(windows), not(target_env = "musl")))'.dependencies]
jemallocator = "0.5.0"
@ -87,7 +84,7 @@ hyper = "0.14.25"
# misc
eyre = "0.6.8"
clap = { version = "4", features = ["derive", "cargo"] }
clap = { version = "4", features = ["derive"] }
num_cpus = "1.13.0"
tempfile = { version = "3.3.0" }
backon = "0.4"
@ -97,3 +94,6 @@ pretty_assertions = "1.3.0"
[features]
only-info-logs = ["tracing/release_max_level_info"]
[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "cargo", "git", "gitcl"] }

View File

@ -1,6 +1,8 @@
fn main() {
let mut opts = built::Options::default();
opts.set_dependencies(true);
use std::error::Error;
use vergen::EmitBuilder;
built::write_built_file().expect("Failed to acquire build-time information");
fn main() -> Result<(), Box<dyn Error>> {
// Emit the instructions
EmitBuilder::builder().git_sha(true).build_timestamp().cargo_features().emit()?;
Ok(())
}

View File

@ -1,8 +1,9 @@
use crate::{
dirs::{DataDirPath, MaybePlatformPath},
node::events::{handle_events, NodeEvent},
version::SHORT_VERSION,
};
use clap::{crate_version, Parser};
use clap::Parser;
use eyre::Context;
use futures::{Stream, StreamExt};
use reth_beacon_consensus::BeaconConsensus;
@ -77,7 +78,7 @@ pub struct ImportCommand {
impl ImportCommand {
/// Execute `import` command
pub async fn execute(self) -> eyre::Result<()> {
info!(target: "reth::cli", "reth {} starting", crate_version!());
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
// add network name to data dir
let data_dir = self.datadir.unwrap_or_chain_default(self.chain.chain);

View File

@ -5,6 +5,7 @@ use crate::{
merkle_debug, node, p2p,
runner::CliRunner,
stage, test_eth_chain, test_vectors,
version::{LONG_VERSION, SHORT_VERSION},
};
use clap::{ArgAction, Args, Parser, Subcommand};
use reth_tracing::{
@ -76,7 +77,7 @@ pub enum Commands {
}
#[derive(Debug, Parser)]
#[command(author, version = "0.1", about = "Reth", long_about = None)]
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
struct Cli {
/// The command to run
#[clap(subcommand)]

View File

@ -7,8 +7,9 @@ use crate::{
prometheus_exporter,
runner::CliContext,
utils::get_single_header,
version::SHORT_VERSION,
};
use clap::{crate_version, Parser};
use clap::Parser;
use eyre::Context;
use fdlimit::raise_fd_limit;
use futures::{pin_mut, stream::select as stream_select, StreamExt};
@ -135,7 +136,7 @@ pub struct Command {
impl Command {
/// Execute `node` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
info!(target: "reth::cli", "reth {} starting", crate_version!());
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
// Raise the fd limit of the process.
// Does not do anything on windows.

View File

@ -5,6 +5,7 @@ use crate::{
args::{get_secret_key, NetworkArgs, StageEnum},
dirs::{DataDirPath, MaybePlatformPath},
prometheus_exporter,
version::SHORT_VERSION,
};
use clap::Parser;
use reth_beacon_consensus::BeaconConsensus;
@ -105,7 +106,7 @@ impl Command {
let config_path = self.config.clone().unwrap_or(data_dir.config_path());
let config: Config = confy::load_path(config_path).unwrap_or_default();
info!(target: "reth::cli", "reth {} starting stage {:?}", clap::crate_version!(), self.stage);
info!(target: "reth::cli", "reth {} starting stage {:?}", SHORT_VERSION, self.stage);
// use the overridden db path if specified
let db_path = data_dir.db_path();

View File

@ -1,13 +1,56 @@
//! This module contains the version message for the program.
include!(concat!(env!("OUT_DIR"), "/built.rs"));
//! Version information for reth.
const VERSION: &str = PKG_VERSION;
const NAME: &str = PKG_NAME;
const SHA: Option<&str> = GIT_COMMIT_HASH_SHORT;
const OS: &str = std::env::consts::OS;
/// The short version information for reth.
///
/// - The latest version from Cargo.toml
/// - The short SHA of the latest commit.
///
/// # Example
///
/// ```text
/// 0.1.0 (defa64b2)
/// ```
pub(crate) const SHORT_VERSION: &str =
concat!(env!("CARGO_PKG_VERSION"), " (", env!("VERGEN_GIT_SHA"), ")");
/// The version message for the current program, like
/// `reth/v0.1.0/macos-6fc95a5/`
pub fn version_message() -> String {
format!("{}/v{}/{}-{}", NAME, VERSION, OS, SHA.unwrap())
}
/// The long version information for reth.
///
/// - The latest version from Cargo.toml
/// - The long SHA of the latest commit.
/// - The build datetime
/// - The build features
///
/// # Example:
///
/// ```text
/// Version: 0.1.0
/// Commit SHA: defa64b2
/// Build Timestamp: 2023-05-19T01:47:19.815651705Z
/// Build Features: jemalloc
/// ```
pub(crate) const LONG_VERSION: &str = concat!(
"Version: ",
env!("CARGO_PKG_VERSION"),
"\n",
"Commit SHA: ",
env!("VERGEN_GIT_SHA"),
"\n",
"Build Timestamp: ",
env!("VERGEN_BUILD_TIMESTAMP"),
"\n",
"Build Features: ",
env!("VERGEN_CARGO_FEATURES")
);
/// The version information for reth formatted for P2P.
///
/// - The latest version from Cargo.toml
/// - The target triple
///
/// # Example
///
/// ```text
/// reth/v{major}.{minor}.{patch}/{target}
/// ```
pub(crate) const P2P_VERSION: &str =
concat!("reth/v", env!("CARGO_PKG_VERSION"), "/", env!("VERGEN_CARGO_TARGET_TRIPLE"));