mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Rework lighthouse_version to reduce spurious recompilation (#8336)
#8311 Removes the `git_version` crate from `lighthouse_version` and implements git `HEAD` tracking manually. This removes the (mostly) broken dirty tracking but prevents spurious recompilation of the `lighthouse_version` crate. This also reworks the way crate versions are handled by utilizing workspace version inheritance and Cargo environment variables. This means the _only_ place where Lighthouse's version is defined is in the top level `Cargo.toml` for the workspace. All relevant binaries then inherit this version. This largely makes the `change_version.sh` script useless so I've removed it, although we could keep a version which just alters the workspace version (if we need to maintain compatibility with certain build/release tooling. ### When is a Rebuild Triggered? 1. When the build.rs file is changed. 2. When the HEAD commit changes (added, removed, rebased, etc) 3. When the branch changes (this includes changing to the current branch, and creating a detached HEAD) Note that working/staged changes will not trigger a recompile of `lighthouse_version`. Co-Authored-By: Mac L <mjladson@pm.me> Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
27
Cargo.lock
generated
27
Cargo.lock
generated
@@ -4,7 +4,7 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "account_manager"
|
||||
version = "0.3.5"
|
||||
version = "8.0.0-rc.2"
|
||||
dependencies = [
|
||||
"account_utils",
|
||||
"bls",
|
||||
@@ -3860,26 +3860,6 @@ version = "0.31.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
||||
|
||||
[[package]]
|
||||
name = "git-version"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ad568aa3db0fcbc81f2f116137f263d7304f512a1209b35b85150d3ef88ad19"
|
||||
dependencies = [
|
||||
"git-version-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git-version-macro"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.100",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.2"
|
||||
@@ -5711,9 +5691,8 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lighthouse_version"
|
||||
version = "0.1.0"
|
||||
version = "8.0.0-rc.2"
|
||||
dependencies = [
|
||||
"git-version",
|
||||
"regex",
|
||||
]
|
||||
|
||||
@@ -10112,7 +10091,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "validator_client"
|
||||
version = "0.3.5"
|
||||
version = "8.0.0-rc.2"
|
||||
dependencies = [
|
||||
"account_utils",
|
||||
"beacon_node_fallback",
|
||||
|
||||
@@ -94,6 +94,7 @@ resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
edition = "2024"
|
||||
version = "8.0.0-rc.2"
|
||||
|
||||
[workspace.dependencies]
|
||||
account_utils = { path = "common/account_utils" }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "account_manager"
|
||||
version = "0.3.5"
|
||||
version = { workspace = true }
|
||||
authors = [
|
||||
"Paul Hauner <paul@paulhauner.com>",
|
||||
"Luke Anderson <luke@sigmaprime.io>",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "beacon_node"
|
||||
version = "8.0.0-rc.2"
|
||||
version = { workspace = true }
|
||||
authors = [
|
||||
"Paul Hauner <paul@paulhauner.com>",
|
||||
"Age Manning <Age@AgeManning.com",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "boot_node"
|
||||
version = "8.0.0-rc.2"
|
||||
version = { workspace = true }
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = { workspace = true }
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
[package]
|
||||
name = "lighthouse_version"
|
||||
version = "0.1.0"
|
||||
version = { workspace = true }
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = { workspace = true }
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
git-version = "0.3.4"
|
||||
|
||||
[dev-dependencies]
|
||||
regex = { workspace = true }
|
||||
|
||||
81
common/lighthouse_version/build.rs
Normal file
81
common/lighthouse_version/build.rs
Normal file
@@ -0,0 +1,81 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
const CLIENT_NAME: &str = "Lighthouse";
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let manifest_path = Path::new(&manifest_dir);
|
||||
|
||||
// The crate version is inherited from the workspace.
|
||||
let semantic_version = env::var("CARGO_PKG_VERSION").unwrap();
|
||||
|
||||
// Hardcode the .git/ path.
|
||||
// This assumes the `lighthouse_version` crate will never move.
|
||||
let git_dir = manifest_path.join("../../.git");
|
||||
|
||||
if git_dir.exists() {
|
||||
// HEAD either contains a commit hash directly (detached HEAD), or a reference to a branch.
|
||||
let head_path = git_dir.join("HEAD");
|
||||
if head_path.exists() {
|
||||
println!("cargo:rerun-if-changed={}", head_path.display());
|
||||
|
||||
if let Ok(head_content) = fs::read_to_string(&head_path) {
|
||||
let head_content = head_content.trim();
|
||||
|
||||
// If HEAD is a reference, also check that file.
|
||||
if let Some(ref_path) = head_content.strip_prefix("ref: ") {
|
||||
let full_ref_path = git_dir.join(ref_path);
|
||||
if full_ref_path.exists() {
|
||||
println!("cargo:rerun-if-changed={}", full_ref_path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Construct Lighthouse version string without commit hash.
|
||||
let base_version = format!("{}/v{}", CLIENT_NAME, semantic_version);
|
||||
|
||||
let commit_hash = get_git_hash(7);
|
||||
let commit_prefix = get_git_hash(8);
|
||||
|
||||
// If commit hash is valid, construct the full version string.
|
||||
let version = if !commit_hash.is_empty() && commit_hash.len() >= 7 {
|
||||
format!("{}-{}", base_version, commit_hash)
|
||||
} else {
|
||||
base_version
|
||||
};
|
||||
|
||||
println!("cargo:rustc-env=GIT_VERSION={}", version);
|
||||
println!("cargo:rustc-env=GIT_COMMIT_PREFIX={}", commit_prefix);
|
||||
println!("cargo:rustc-env=CLIENT_NAME={}", CLIENT_NAME);
|
||||
println!("cargo:rustc-env=SEMANTIC_VERSION={}", semantic_version);
|
||||
}
|
||||
|
||||
fn get_git_hash(len: usize) -> String {
|
||||
Command::new("git")
|
||||
.args(["rev-parse", &format!("--short={}", len), "HEAD"])
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|output| {
|
||||
if output.status.success() {
|
||||
String::from_utf8(output.stdout).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|s| s.trim().to_string())
|
||||
.unwrap_or_else(|| {
|
||||
// Fallback commit prefix for execution engine reporting.
|
||||
if len == 8 {
|
||||
"00000000".to_string()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,49 +1,25 @@
|
||||
use git_version::git_version;
|
||||
use std::env::consts;
|
||||
|
||||
/// Returns the current version of this build of Lighthouse.
|
||||
///
|
||||
/// A plus-sign (`+`) is appended to the git commit if the tree is dirty.
|
||||
/// Commit hash is omitted if the sources don't include git information.
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// `Lighthouse/v1.5.1-67da032+`
|
||||
pub const VERSION: &str = git_version!(
|
||||
args = [
|
||||
"--always",
|
||||
"--dirty=+",
|
||||
"--abbrev=7",
|
||||
// NOTE: using --match instead of --exclude for compatibility with old Git
|
||||
"--match=thiswillnevermatchlol"
|
||||
],
|
||||
prefix = "Lighthouse/v8.0.0-rc.2-",
|
||||
fallback = "Lighthouse/v8.0.0-rc.2"
|
||||
);
|
||||
/// `Lighthouse/v8.0.0-67da032`
|
||||
pub const VERSION: &str = env!("GIT_VERSION");
|
||||
|
||||
/// Returns the first eight characters of the latest commit hash for this build.
|
||||
///
|
||||
/// No indication is given if the tree is dirty. This is part of the standard
|
||||
/// for reporting the client version to the execution engine.
|
||||
pub const COMMIT_PREFIX: &str = git_version!(
|
||||
args = [
|
||||
"--always",
|
||||
"--abbrev=8",
|
||||
// NOTE: using --match instead of --exclude for compatibility with old Git
|
||||
"--match=thiswillnevermatchlol"
|
||||
],
|
||||
prefix = "",
|
||||
suffix = "",
|
||||
cargo_prefix = "",
|
||||
cargo_suffix = "",
|
||||
fallback = "00000000"
|
||||
);
|
||||
pub const COMMIT_PREFIX: &str = env!("GIT_COMMIT_PREFIX");
|
||||
|
||||
/// Returns `VERSION`, but with platform information appended to the end.
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// `Lighthouse/v1.5.1-67da032+/x86_64-linux`
|
||||
/// `Lighthouse/v8.0.0-67da032/x86_64-linux`
|
||||
pub fn version_with_platform() -> String {
|
||||
format!("{}/{}-{}", VERSION, consts::ARCH, consts::OS)
|
||||
}
|
||||
@@ -52,16 +28,16 @@ pub fn version_with_platform() -> String {
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// `1.5.1`
|
||||
/// `8.0.0`
|
||||
pub fn version() -> &'static str {
|
||||
"8.0.0-rc.2"
|
||||
env!("SEMANTIC_VERSION")
|
||||
}
|
||||
|
||||
/// Returns the name of the current client running.
|
||||
///
|
||||
/// This will usually be "Lighthouse"
|
||||
pub fn client_name() -> &'static str {
|
||||
"Lighthouse"
|
||||
env!("CLIENT_NAME")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -72,7 +48,7 @@ mod test {
|
||||
#[test]
|
||||
fn version_formatting() {
|
||||
let re = Regex::new(
|
||||
r"^Lighthouse/v[0-9]+\.[0-9]+\.[0-9]+(-(rc|beta).[0-9])?(-[[:xdigit:]]{7})?\+?$",
|
||||
r"^Lighthouse/v[0-9]+\.[0-9]+\.[0-9]+(-(rc|beta)\.[0-9])?(-[[:xdigit:]]{7})?$",
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
@@ -91,4 +67,14 @@ mod test {
|
||||
version()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_name_is_lighthouse() {
|
||||
assert_eq!(client_name(), "Lighthouse");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_contains_semantic_version() {
|
||||
assert!(VERSION.contains(version()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "lcli"
|
||||
description = "Lighthouse CLI (modeled after zcli)"
|
||||
version = "8.0.0-rc.2"
|
||||
version = { workspace = true }
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = { workspace = true }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "lighthouse"
|
||||
version = "8.0.0-rc.2"
|
||||
version = { workspace = true }
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = { workspace = true }
|
||||
autotests = false
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Change the version across multiple files, prior to a release. Use `sed` to
|
||||
# find/replace the exiting version with the new one.
|
||||
#
|
||||
# Takes two arguments:
|
||||
#
|
||||
# 1. Current version (e.g., `0.2.6`)
|
||||
# 2. New version (e.g., `0.2.7`)
|
||||
#
|
||||
# ## Example:
|
||||
#
|
||||
# `./change_version.sh 0.2.6 0.2.7`
|
||||
|
||||
FROM=$1
|
||||
TO=$2
|
||||
VERSION_CRATE="../common/lighthouse_version/src/lib.rs"
|
||||
|
||||
update_cargo_toml () {
|
||||
echo $1
|
||||
sed -i -e "s/version = \"$FROM\"/version = \"$TO\"/g" $1
|
||||
}
|
||||
|
||||
echo "Changing version from $FROM to $TO"
|
||||
|
||||
update_cargo_toml ../account_manager/Cargo.toml
|
||||
update_cargo_toml ../beacon_node/Cargo.toml
|
||||
update_cargo_toml ../boot_node/Cargo.toml
|
||||
update_cargo_toml ../lcli/Cargo.toml
|
||||
update_cargo_toml ../lighthouse/Cargo.toml
|
||||
update_cargo_toml ../validator_client/Cargo.toml
|
||||
|
||||
echo $VERSION_CRATE
|
||||
sed -i -e "s/$FROM/$TO/g" $VERSION_CRATE
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "validator_client"
|
||||
version = "0.3.5"
|
||||
version = { workspace = true }
|
||||
authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = { workspace = true }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user