From 24c3000801f8433dbca1877dbc9ff5f29e57be3f Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:25:11 +0100 Subject: [PATCH] fix: take TENDERDASH_VERSION from td version.go --- abci/tests/common/docker.rs | 7 +++---- proto-compiler/src/functions.rs | 31 ++++++++++++++++++++++++++++--- proto-compiler/src/lib.rs | 7 ++++--- proto/tests/unit.rs | 6 ------ 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/abci/tests/common/docker.rs b/abci/tests/common/docker.rs index 5e1e5001..9d084ca6 100644 --- a/abci/tests/common/docker.rs +++ b/abci/tests/common/docker.rs @@ -39,10 +39,9 @@ impl TenderdashDocker { app_address: &str, ) -> TenderdashDocker { // let tag = String::from(tenderdash_proto::VERSION); - let tag = match tag { - None => tenderdash_proto::meta::TENDERDASH_VERSION, - Some("") => tenderdash_proto::meta::TENDERDASH_VERSION, - Some(tag) => tag, + let tag = match tag.unwrap_or_default() { + "" => tenderdash_proto::meta::TENDERDASH_VERSION, + tag => tag, }; let app_address = url::Url::parse(app_address).expect("invalid app address"); diff --git a/proto-compiler/src/functions.rs b/proto-compiler/src/functions.rs index f3dc02c9..50ca2904 100644 --- a/proto-compiler/src/functions.rs +++ b/proto-compiler/src/functions.rs @@ -222,8 +222,32 @@ pub fn abci_version>(dir: T) -> String { .to_string() } +pub fn tenderdash_version>(dir: T) -> String { + let mut file_path = dir.as_ref().to_path_buf(); + file_path.push("version/version.go"); + + let contents = read_to_string(&file_path).expect("cannot read version/version.go"); + use regex::Regex; + + let re = Regex::new(r##"(?m)^\s+TMVersionDefault\s*=\s*"([^"]+)"\s+*$"##).unwrap(); + let captures = re + .captures(&contents) + .expect("cannot find TMVersionDefault in version/version.go"); + + captures + .get(1) + .expect("TMVersionDefault not found in version/version.go") + .as_str() + .to_string() +} + /// Create tenderdash.rs with library information -pub fn generate_tenderdash_lib(prost_dir: &Path, tenderdash_lib_target: &Path, abci_version: &str) { +pub fn generate_tenderdash_lib( + prost_dir: &Path, + tenderdash_lib_target: &Path, + abci_ver: &str, + td_ver: &str, +) { let mut file_names = WalkDir::new(prost_dir) .into_iter() .filter_map(|e| e.ok()) @@ -279,13 +303,14 @@ pub mod meta {{ /// Semantic version of ABCI protocol pub const ABCI_VERSION: &str = \"{}\"; /// Version of Tenderdash server used to generate protobuf configs - pub const TENDERDASH_VERSION: &str = env!(\"CARGO_PKG_VERSION\"); + pub const TENDERDASH_VERSION: &str =\"{}\"; }} ", content, crate::constants::TENDERDASH_REPO, tenderdash_commitish(), - abci_version, + abci_ver, + td_ver, ); let mut file = diff --git a/proto-compiler/src/lib.rs b/proto-compiler/src/lib.rs index 38b0dd70..0dcb7215 100644 --- a/proto-compiler/src/lib.rs +++ b/proto-compiler/src/lib.rs @@ -5,7 +5,7 @@ use tempfile::tempdir; mod functions; use functions::{ abci_version, copy_files, fetch_commitish, find_proto_files, generate_tenderdash_lib, - tenderdash_commitish, + tenderdash_commitish, tenderdash_version, }; mod constants; @@ -93,7 +93,8 @@ pub fn proto_compile() { ); println!("[info] => Determining ABCI protocol version."); - let abci_ver = abci_version(tenderdash_dir); + let abci_ver = abci_version(&tenderdash_dir); + let tenderdash_ver = tenderdash_version(tenderdash_dir); println!("[info] => Creating structs."); pb.compile_protos(&protos, &proto_includes_paths).unwrap(); @@ -101,7 +102,7 @@ pub fn proto_compile() { println!("[info] => Removing old structs and copying new structs."); copy_files(&out_dir, &target_dir); // This panics if it fails. - generate_tenderdash_lib(&out_dir, &tenderdash_lib_target, &abci_ver); + generate_tenderdash_lib(&out_dir, &tenderdash_lib_target, &abci_ver, &tenderdash_ver); println!("[info] => Done!"); } diff --git a/proto/tests/unit.rs b/proto/tests/unit.rs index 8ebd5929..f820160b 100644 --- a/proto/tests/unit.rs +++ b/proto/tests/unit.rs @@ -133,9 +133,3 @@ pub fn test_response_exception_from() { "string" ); } - -#[test] -pub fn test_tenderdash_version() { - let version = env!("CARGO_PKG_VERSION"); - assert_eq!(version, tenderdash_proto::meta::TENDERDASH_VERSION) -}