diff --git a/proto-build/src/commands/apply_patches.rs b/proto-build/src/commands/apply_patches.rs index 95777ed..61258df 100644 --- a/proto-build/src/commands/apply_patches.rs +++ b/proto-build/src/commands/apply_patches.rs @@ -1,6 +1,6 @@ -use std::path::{Path, PathBuf}; -use glob::glob; use crate::utils::patch_file::patch_file; +use glob::glob; +use std::path::{Path, PathBuf}; /// Fix clashing type names in prost-generated code. fn apply_cosmos_staking_patches(out_dir: &Path) { diff --git a/proto-build/src/commands/cleanup.rs b/proto-build/src/commands/cleanup.rs index 88be386..1b61c00 100644 --- a/proto-build/src/commands/cleanup.rs +++ b/proto-build/src/commands/cleanup.rs @@ -1,6 +1,6 @@ +use glob::glob; use std::fs; use std::path::Path; -use glob::glob; const EXCLUDED_PROTO_PACKAGES: &[&str] = &["amino", "gogoproto", "google", "tendermint"]; diff --git a/proto-build/src/commands/export.rs b/proto-build/src/commands/export.rs index 756167c..8d29fae 100644 --- a/proto-build/src/commands/export.rs +++ b/proto-build/src/commands/export.rs @@ -1,7 +1,7 @@ -use std::fs; -use std::path::Path; use crate::consts::{ARCHWAY_DIR, COSMOS_SDK_DIR, IBC_DIR, WASMD_DIR}; use crate::utils::run::run_buf_export; +use std::fs; +use std::path::Path; pub fn export(submodules_dir: &Path, proto_dir: &Path) { if proto_dir.exists() { diff --git a/proto-build/src/commands/generate.rs b/proto-build/src/commands/generate.rs index 6b3e20f..e512c83 100644 --- a/proto-build/src/commands/generate.rs +++ b/proto-build/src/commands/generate.rs @@ -1,12 +1,8 @@ +use crate::utils::run::run_cmd; use std::fs; use std::path::Path; -use crate::utils::run::run_cmd; -pub fn generate( - buf_gen_path: &Path, - proto_path: &Path, - out_dir: &Path, -) -> crate::Result { +pub fn generate(buf_gen_path: &Path, proto_path: &Path, out_dir: &Path) -> crate::Result { println!("Generating proto..."); if out_dir.exists() { diff --git a/proto-build/src/commands/output_version.rs b/proto-build/src/commands/output_version.rs index 193b851..fb5bf9f 100644 --- a/proto-build/src/commands/output_version.rs +++ b/proto-build/src/commands/output_version.rs @@ -1,6 +1,6 @@ +use crate::consts::{ARCHWAY_REV, COSMOS_SDK_REV, IBC_REV, WASMD_REV}; use std::fs; use std::path::Path; -use crate::consts::{ARCHWAY_REV, COSMOS_SDK_REV, IBC_REV, WASMD_REV}; pub fn output_versions(out_dir: &Path) { println!("Writing versions..."); diff --git a/proto-build/src/commands/rustfmt.rs b/proto-build/src/commands/rustfmt.rs index 9d2db8a..cfeeb8a 100644 --- a/proto-build/src/commands/rustfmt.rs +++ b/proto-build/src/commands/rustfmt.rs @@ -1,6 +1,6 @@ -use std::path::{Path, PathBuf}; -use glob::glob; use crate::utils::run::run_cmd; +use glob::glob; +use std::path::{Path, PathBuf}; fn collect_files(dir: &Path, pattern: &str) -> crate::Result> { // dir.join("**").join(pattern); diff --git a/proto-build/src/commands/update_submodules.rs b/proto-build/src/commands/update_submodules.rs index a03ac5d..6e6c99a 100644 --- a/proto-build/src/commands/update_submodules.rs +++ b/proto-build/src/commands/update_submodules.rs @@ -1,6 +1,9 @@ -use std::path::Path; -use crate::consts::{ARCHWAY_DIR, ARCHWAY_REV, COSMOS_SDK_DIR, COSMOS_SDK_REV, IBC_DIR, IBC_REV, WASMD_DIR, WASMD_REV}; +use crate::consts::{ + ARCHWAY_DIR, ARCHWAY_REV, COSMOS_SDK_DIR, COSMOS_SDK_REV, IBC_DIR, IBC_REV, WASMD_DIR, + WASMD_REV, +}; use crate::utils::run::run_git; +use std::path::Path; pub fn update_submodules(submodules_dir: &Path) { run_git(["submodule", "update", "--init"]).unwrap(); @@ -8,11 +11,25 @@ pub fn update_submodules(submodules_dir: &Path) { println!("Updating archway-network/archway submodule..."); let archway_dir = submodules_dir.join(ARCHWAY_DIR); - run_git(["-C", archway_dir.to_str().unwrap(), "reset", "--hard", ARCHWAY_REV]).unwrap(); + run_git([ + "-C", + archway_dir.to_str().unwrap(), + "reset", + "--hard", + ARCHWAY_REV, + ]) + .unwrap(); println!("Updating cosmos/cosmos-sdk submodule..."); let sdk_dir = submodules_dir.join(COSMOS_SDK_DIR); - run_git(["-C", sdk_dir.to_str().unwrap(), "reset", "--hard", COSMOS_SDK_REV]).unwrap(); + run_git([ + "-C", + sdk_dir.to_str().unwrap(), + "reset", + "--hard", + COSMOS_SDK_REV, + ]) + .unwrap(); println!("Updating cosmos/ibc-go submodule..."); let ibc_dir = submodules_dir.join(IBC_DIR); @@ -20,5 +37,12 @@ pub fn update_submodules(submodules_dir: &Path) { println!("Updating wasmd submodule..."); let wasmd_dir = submodules_dir.join(WASMD_DIR); - run_git(["-C", wasmd_dir.to_str().unwrap(), "reset", "--hard", WASMD_REV]).unwrap(); + run_git([ + "-C", + wasmd_dir.to_str().unwrap(), + "reset", + "--hard", + WASMD_REV, + ]) + .unwrap(); } diff --git a/proto-build/src/main.rs b/proto-build/src/main.rs index 3af8070..dbf152c 100644 --- a/proto-build/src/main.rs +++ b/proto-build/src/main.rs @@ -1,13 +1,11 @@ -mod parser; -mod utils; mod commands; mod consts; +mod parser; +mod utils; -use std::{io, path::Path, process}; use std::path::PathBuf; +use std::{io, path::Path, process}; -use crate::parser::generate_advanced_struct; -use error_chain::error_chain; use crate::commands::apply_patches::apply_patches; use crate::commands::cleanup::cleanup; use crate::commands::export::export; @@ -16,7 +14,9 @@ use crate::commands::output_version::output_versions; use crate::commands::rustfmt::rustfmt; use crate::commands::update_submodules::update_submodules; use crate::consts::{OUT_DIR, PROTO_DIR}; +use crate::parser::generate_advanced_struct; use crate::utils::run::run_cargo; +use error_chain::error_chain; error_chain! { foreign_links { diff --git a/proto-build/src/parser/commands/load_and_patch_any.rs b/proto-build/src/parser/commands/load_and_patch_any.rs index 0913bde..93d8b40 100644 --- a/proto-build/src/parser/commands/load_and_patch_any.rs +++ b/proto-build/src/parser/commands/load_and_patch_any.rs @@ -1,15 +1,17 @@ -use std::collections::BTreeMap; -use std::fs; -use std::path::{Path, PathBuf}; +use crate::parser::consts::GENERICS; +use crate::parser::utils::common::{ + create_punctuated, fields_as_named, gen_generic, item_as_struct, +}; +use crate::parser::utils::gen_type_param::gen_type_param; +use crate::parser::utils::is_important::{is_important, FoundEnclosure}; use glob::glob; use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream}; use quote::TokenStreamExt; -use syn::{Attribute, AttrStyle, File, GenericParam, Item, MacroDelimiter, Meta, MetaList}; +use std::collections::BTreeMap; +use std::fs; +use std::path::{Path, PathBuf}; use syn::token::Paren; -use crate::parser::consts::GENERICS; -use crate::parser::utils::is_important::{FoundEnclosure, is_important}; -use crate::parser::utils::common::{fields_as_named, item_as_struct, create_punctuated, gen_generic}; -use crate::parser::utils::gen_type_param::gen_type_param; +use syn::{AttrStyle, Attribute, File, GenericParam, Item, MacroDelimiter, Meta, MetaList}; pub fn load_and_patch_any(out_dir: &Path) -> BTreeMap)> { // Map all file ASTs @@ -17,7 +19,10 @@ pub fn load_and_patch_any(out_dir: &Path) -> BTreeMap = glob(src_files_glob.to_str().unwrap()).unwrap().flatten().collect(); + let src_files: Vec = glob(src_files_glob.to_str().unwrap()) + .unwrap() + .flatten() + .collect(); for src in src_files { let current_file = fs::read_to_string(&src).unwrap(); diff --git a/proto-build/src/parser/commands/patch_generics.rs b/proto-build/src/parser/commands/patch_generics.rs index 9f670de..edc0a14 100644 --- a/proto-build/src/parser/commands/patch_generics.rs +++ b/proto-build/src/parser/commands/patch_generics.rs @@ -1,14 +1,19 @@ -use std::cmp::Ordering; -use std::collections::BTreeMap; +use crate::parser::consts::GENERICS; +use crate::parser::utils::common::{ + create_punctuated, fields_as_named, gen_generic, item_as_struct, +}; +use crate::parser::utils::gen_type_param::gen_type_param; +use crate::parser::utils::is_important::{is_important, FoundEnclosure}; use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream}; use quote::TokenStreamExt; -use syn::{AngleBracketedGenericArguments, Attribute, AttrStyle, File, GenericArgument, GenericParam, ItemStruct, MacroDelimiter, Meta, MetaList, Path, PathArguments, PathSegment, Type, TypePath}; +use std::cmp::Ordering; +use std::collections::BTreeMap; use syn::punctuated::Punctuated; use syn::token::Paren; -use crate::parser::consts::GENERICS; -use crate::parser::utils::is_important::{FoundEnclosure, is_important}; -use crate::parser::utils::common::{fields_as_named, item_as_struct, create_punctuated, gen_generic}; -use crate::parser::utils::gen_type_param::gen_type_param; +use syn::{ + AngleBracketedGenericArguments, AttrStyle, Attribute, File, GenericArgument, GenericParam, + ItemStruct, MacroDelimiter, Meta, MetaList, Path, PathArguments, PathSegment, Type, TypePath, +}; pub fn patch_generics(files: &mut BTreeMap)>) { let mut updated_files = BTreeMap::new(); @@ -87,7 +92,7 @@ pub fn patch_generics(files: &mut BTreeMap)>) { for (_, (ast, structs)) in files.iter_mut() { diff --git a/proto-build/src/parser/commands/save.rs b/proto-build/src/parser/commands/save.rs index 9c31d92..8cd612c 100644 --- a/proto-build/src/parser/commands/save.rs +++ b/proto-build/src/parser/commands/save.rs @@ -1,10 +1,10 @@ +use crate::utils::patch_file::patch_file; +use quote::quote; +use regex::Regex; use std::collections::BTreeMap; use std::fs; use std::path::Path; -use quote::quote; -use regex::Regex; use syn::File; -use crate::utils::patch_file::patch_file; pub fn save(out_dir: &Path, files: &BTreeMap)>) { for (file, (data, _)) in files.iter() { @@ -30,13 +30,9 @@ pub fn save(out_dir: &Path, files: &BTreeMap crate::Result<()> { println!("Loading and patching all files containing Any"); diff --git a/proto-build/src/parser/utils/common.rs b/proto-build/src/parser/utils/common.rs index 6811601..c6252cb 100644 --- a/proto-build/src/parser/utils/common.rs +++ b/proto-build/src/parser/utils/common.rs @@ -2,22 +2,8 @@ use proc_macro2::Span; use syn::punctuated::Punctuated; use syn::token::PathSep; use syn::{ - Field, - Fields, - FieldsNamed, - GenericArgument, - Ident, - Item, - ItemStruct, - Path, - PathArguments, - PathSegment, - TraitBound, - TraitBoundModifier, - Type, - TypeParam, - TypeParamBound, - TypePath, + Field, Fields, FieldsNamed, GenericArgument, Ident, Item, ItemStruct, Path, PathArguments, + PathSegment, TraitBound, TraitBoundModifier, Type, TypeParam, TypeParamBound, TypePath, }; pub fn item_as_struct(item: &mut Item) -> Option<&mut ItemStruct> { diff --git a/proto-build/src/parser/utils/gen_type_param.rs b/proto-build/src/parser/utils/gen_type_param.rs index f81a35c..a82f855 100644 --- a/proto-build/src/parser/utils/gen_type_param.rs +++ b/proto-build/src/parser/utils/gen_type_param.rs @@ -1,6 +1,6 @@ +use crate::parser::utils::common::create_punctuated; use proc_macro2::{Ident, Span}; use syn::{Path, TraitBound, TraitBoundModifier, TypeParam, TypeParamBound}; -use crate::parser::utils::common::create_punctuated; fn trait_param_bound(path: Vec<&str>) -> TypeParamBound { TypeParamBound::Trait(TraitBound { diff --git a/proto-build/src/parser/utils/is_important.rs b/proto-build/src/parser/utils/is_important.rs index bc9449b..06a7cb0 100644 --- a/proto-build/src/parser/utils/is_important.rs +++ b/proto-build/src/parser/utils/is_important.rs @@ -1,5 +1,5 @@ -use syn::{Field, GenericArgument, PathArguments, TypePath}; use crate::parser::utils::common::type_as_path; +use syn::{Field, GenericArgument, PathArguments, TypePath}; pub enum FoundEnclosure { Option, diff --git a/proto-build/src/parser/utils/mod.rs b/proto-build/src/parser/utils/mod.rs index 0e6a516..2b2b2c7 100644 --- a/proto-build/src/parser/utils/mod.rs +++ b/proto-build/src/parser/utils/mod.rs @@ -1,3 +1,3 @@ +pub mod common; pub mod gen_type_param; pub mod is_important; -pub mod common; diff --git a/proto-build/src/utils/patch_file.rs b/proto-build/src/utils/patch_file.rs index 857cb4c..1fbf320 100644 --- a/proto-build/src/utils/patch_file.rs +++ b/proto-build/src/utils/patch_file.rs @@ -1,6 +1,6 @@ -use std::{fs, io}; -use std::path::Path; use regex::Regex; +use std::path::Path; +use std::{fs, io}; pub fn patch_file(path: &Path, replacements: &[(&str, &str)]) -> io::Result<()> { let mut contents = fs::read_to_string(&path)?; diff --git a/proto-build/src/utils/run.rs b/proto-build/src/utils/run.rs index cbe3bec..f8e6247 100644 --- a/proto-build/src/utils/run.rs +++ b/proto-build/src/utils/run.rs @@ -1,6 +1,6 @@ use std::ffi::OsStr; -use std::{io, process}; use std::path::Path; +use std::{io, process}; pub fn run_git(args: impl IntoIterator>) -> crate::Result { run_cmd("git", args)