From d4c75daadb8987c334e9f907b488b118bc57194c Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Tue, 6 Feb 2024 12:49:27 +0200 Subject: [PATCH 1/2] proto-compiler: no formatting paths as strings Use Path facilities to compose paths as PathBuf objects rather than cycling the representation through strings with potential garbling in `.display()`. --- tools/proto-compiler/src/cmd/compile.rs | 57 ++++++++++++------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/tools/proto-compiler/src/cmd/compile.rs b/tools/proto-compiler/src/cmd/compile.rs index 4e021e14..493e432c 100644 --- a/tools/proto-compiler/src/cmd/compile.rs +++ b/tools/proto-compiler/src/cmd/compile.rs @@ -69,42 +69,42 @@ impl CompileCmd { out_dir.display() ); - let root = env!("CARGO_MANIFEST_DIR"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")); // Paths let proto_paths = [ - format!("{}/../../definitions/mock", root), - format!("{}/../../definitions/ibc/lightclients/localhost/v1", root), - format!("{}/../../definitions/stride/interchainquery/v1", root), - format!("{}/ibc", ibc_dir.display()), - format!("{}/cosmos/auth", sdk_dir.display()), - format!("{}/cosmos/gov", sdk_dir.display()), - format!("{}/cosmos/tx", sdk_dir.display()), - format!("{}/cosmos/base", sdk_dir.display()), - format!("{}/cosmos/crypto", sdk_dir.display()), - format!("{}/cosmos/bank", sdk_dir.display()), - format!("{}/cosmos/staking", sdk_dir.display()), - format!("{}/cosmos/upgrade", sdk_dir.display()), - format!("{}/interchain_security/ccv/v1", ics_dir.display()), - format!("{}/interchain_security/ccv/provider", ics_dir.display()), - format!("{}/interchain_security/ccv/consumer", ics_dir.display()), - format!("{}/ibc", nft_dir.display()), + root.join("../../definitions/mock"), + root.join("../../definitions/ibc/lightclients/localhost/v1"), + root.join("../../definitions/stride/interchainquery/v1"), + ibc_dir.join("ibc"), + sdk_dir.join("cosmos/auth"), + sdk_dir.join("cosmos/gov"), + sdk_dir.join("cosmos/tx"), + sdk_dir.join("cosmos/base"), + sdk_dir.join("cosmos/crypto"), + sdk_dir.join("cosmos/bank"), + sdk_dir.join("cosmos/staking"), + sdk_dir.join("cosmos/upgrade"), + ics_dir.join("interchain_security/ccv/v1"), + ics_dir.join("interchain_security/ccv/provider"), + ics_dir.join("interchain_security/ccv/consumer"), + nft_dir.join("ibc"), ]; let proto_includes_paths = [ - format!("{}", sdk_dir.display()), - format!("{}", ibc_dir.display()), - format!("{}", ics_dir.display()), - format!("{}", nft_dir.display()), - format!("{}/../../definitions/mock", root), - format!("{}/../../definitions/ibc/lightclients/localhost/v1", root), - format!("{}/../../definitions/stride/interchainquery/v1", root), + sdk_dir.to_path_buf(), + ibc_dir.to_path_buf(), + ics_dir.to_path_buf(), + nft_dir.to_path_buf(), + root.join("../../definitions/mock"), + root.join("../../definitions/ibc/lightclients/localhost/v1"), + root.join("../../definitions/stride/interchainquery/v1"), ]; // List available proto files let mut protos: Vec = vec![]; for proto_path in &proto_paths { - println!("Looking for proto files in {:?}", proto_path); + println!("Looking for proto files in '{}'", proto_path.display()); protos.append( &mut WalkDir::new(proto_path) .into_iter() @@ -122,13 +122,10 @@ impl CompileCmd { println!("Found the following protos:"); // Show which protos will be compiled for proto in &protos { - println!("\t-> {:?}", proto); + println!("\t-> {}", proto.display()); } println!("[info ] Compiling.."); - // List available paths for dependencies - let includes: Vec = proto_includes_paths.iter().map(PathBuf::from).collect(); - let attrs_jsonschema = r#"#[cfg_attr(all(feature = "json-schema", feature = "serde"), derive(::schemars::JsonSchema))]"#; let attrs_jsonschema_str = r#"#[cfg_attr(all(feature = "json-schema", feature = "serde"), schemars(with = "String"))]"#; @@ -170,7 +167,7 @@ impl CompileCmd { .type_attribute(".ibc.core.connection.v1.Counterparty", attrs_jsonschema) .type_attribute(".ibc.core.connection.v1.Version", attrs_jsonschema) .type_attribute(".ibc.lightclients.wasm.v1.ClientMessage", attrs_jsonschema) - .compile_with_config(config, &protos, &includes)?; + .compile_with_config(config, &protos, &proto_includes_paths)?; println!("[info ] Protos compiled successfully"); From 384ba58a9fa3a82a40ecaadb7c3691a29fe44785 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Tue, 6 Feb 2024 12:51:10 +0200 Subject: [PATCH 2/2] sync-protobuf.sh: consolidate git cache Use a single distinctive subdirectory under ~/.cache to house all checkouts for the build script, as per the XDG convention. --- scripts/sync-protobuf.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/sync-protobuf.sh b/scripts/sync-protobuf.sh index 94ba2a03..dbf5b653 100755 --- a/scripts/sync-protobuf.sh +++ b/scripts/sync-protobuf.sh @@ -22,11 +22,11 @@ set -eou pipefail # repositories over and over again every time # the script is called. -CACHE_PATH="${XDG_CACHE_HOME:-$HOME/.cache}" -COSMOS_SDK_GIT="${COSMOS_SDK_GIT:-$CACHE_PATH/cosmos/cosmos-sdk.git}" +CACHE_PATH="${XDG_CACHE_HOME:-$HOME/.cache}"/ibc-proto-rs-build +COSMOS_SDK_GIT="${COSMOS_SDK_GIT:-$CACHE_PATH/cosmos-sdk.git}" IBC_GO_GIT="${IBC_GO_GIT:-$CACHE_PATH/ibc-go.git}" -COSMOS_ICS_GIT="${COSMOS_ICS_GIT:-$CACHE_PATH/cosmos/interchain-security.git}" -NFT_TRANSFER_GIT="${NFT_TRANSFER_GIT:-$CACHE_PATH/bianjieai/nft-transfer.git}" +COSMOS_ICS_GIT="${COSMOS_ICS_GIT:-$CACHE_PATH/interchain-security.git}" +NFT_TRANSFER_GIT="${NFT_TRANSFER_GIT:-$CACHE_PATH/nft-transfer.git}" COSMOS_SDK_COMMIT="$(cat src/COSMOS_SDK_COMMIT)" IBC_GO_COMMIT="$(cat src/IBC_GO_COMMIT)"