Skip to content

Commit

Permalink
proto-compiler: no formatting paths as strings
Browse files Browse the repository at this point in the history
Use Path facilities to compose paths as PathBuf objects rather than
cycling the representation through strings with potential garbling in `.display()`.
  • Loading branch information
mzabaluev committed Feb 6, 2024
1 parent 7643fa3 commit d4c75da
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions tools/proto-compiler/src/cmd/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> = 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()
Expand All @@ -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<PathBuf> = 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"))]"#;

Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit d4c75da

Please sign in to comment.