Skip to content

Commit

Permalink
fix: take TENDERDASH_VERSION from td version.go
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Jan 31, 2024
1 parent 712c33c commit 24c3000
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
7 changes: 3 additions & 4 deletions abci/tests/common/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
31 changes: 28 additions & 3 deletions proto-compiler/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,32 @@ pub fn abci_version<T: AsRef<Path>>(dir: T) -> String {
.to_string()
}

pub fn tenderdash_version<T: AsRef<Path>>(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())
Expand Down Expand Up @@ -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 =
Expand Down
7 changes: 4 additions & 3 deletions proto-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,15 +93,16 @@ 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();

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!");
}
6 changes: 0 additions & 6 deletions proto/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 24c3000

Please sign in to comment.