From a8c4ee77e4e84945e8da06f040b78fc8b06b497f Mon Sep 17 00:00:00 2001 From: Satoshi Otomakan Date: Fri, 24 Nov 2023 18:25:27 +0100 Subject: [PATCH] [Codegen]: Add stdout logs, fix codegen-v1 --- .../cpp/blockchain_dispatcher_generator.rs | 4 +++- codegen-v2/src/codegen/cpp/entry_generator.rs | 9 ++++----- .../cpp/tw_any_address_tests_generator.rs | 2 ++ .../cpp/tw_any_signer_tests_generator.rs | 2 ++ codegen-v2/src/codegen/cpp/tw_blockchain.rs | 4 +++- ...coin_address_derivation_tests_generator.rs | 10 ++++++---- .../src/codegen/cpp/tw_coin_type_generator.rs | 4 +++- .../cpp/tw_coin_type_tests_generator.rs | 2 ++ .../src/codegen/proto/proto_generator.rs | 2 ++ .../rust/blockchain_dispatcher_generator.rs | 1 + .../codegen/rust/blockchain_type_generator.rs | 1 + .../coin_address_derivation_test_generator.rs | 10 ++++++---- codegen-v2/src/codegen/rust/coin_crate.rs | 19 +++++++++++++------ .../codegen/rust/coin_integration_tests.rs | 8 +++++++- .../rust/coin_registry_manifest_generator.rs | 1 + codegen-v2/src/main.rs | 5 +++++ codegen/lib/coin_skeleton_gen.rb | 3 +-- 17 files changed, 62 insertions(+), 25 deletions(-) diff --git a/codegen-v2/src/codegen/cpp/blockchain_dispatcher_generator.rs b/codegen-v2/src/codegen/cpp/blockchain_dispatcher_generator.rs index 58b13ac452c..d0b4fcd552a 100644 --- a/codegen-v2/src/codegen/cpp/blockchain_dispatcher_generator.rs +++ b/codegen-v2/src/codegen/cpp/blockchain_dispatcher_generator.rs @@ -24,7 +24,9 @@ pub struct BlockchainDispatcherGenerator; impl BlockchainDispatcherGenerator { pub fn generate_new_blockchain_type_dispatching(coin: &CoinItem) -> Result<()> { - let mut file_content = FileContent::read(dispatcher_coin_cpp_path())?; + let dispatcher_path = dispatcher_coin_cpp_path(); + println!("[EDIT] {dispatcher_path:?}"); + let mut file_content = FileContent::read(dispatcher_path)?; Self::generate_include_of_blockchain_entry(coin, &mut file_content)?; Self::generate_blockchain_entry_constant(coin, &mut file_content)?; diff --git a/codegen-v2/src/codegen/cpp/entry_generator.rs b/codegen-v2/src/codegen/cpp/entry_generator.rs index 033c94d6856..f7c453b719d 100644 --- a/codegen-v2/src/codegen/cpp/entry_generator.rs +++ b/codegen-v2/src/codegen/cpp/entry_generator.rs @@ -25,14 +25,13 @@ impl EntryGenerator { let entry_header_path = blockchain_dir.join("Entry.h"); if blockchain_dir.exists() { - return Err(Error::IoError(io::Error::new( - io::ErrorKind::AlreadyExists, - "blockchain already exists", - ))); + println!("[SKIP] Entry file already exists: {blockchain_dir:?}"); + return Ok(blockchain_dir); } - fs::create_dir(&blockchain_dir)?; + fs::create_dir_all(&blockchain_dir)?; + println!("[ADD] {entry_header_path:?}"); TemplateGenerator::new(ENTRY_HEADER_TEMPLATE) .write_to(entry_header_path.clone()) .with_default_patterns(coin) diff --git a/codegen-v2/src/codegen/cpp/tw_any_address_tests_generator.rs b/codegen-v2/src/codegen/cpp/tw_any_address_tests_generator.rs index f7d7384a0d8..f6fa62ac324 100644 --- a/codegen-v2/src/codegen/cpp/tw_any_address_tests_generator.rs +++ b/codegen-v2/src/codegen/cpp/tw_any_address_tests_generator.rs @@ -26,9 +26,11 @@ impl TWAnyAddressTestsGenerator { fs::create_dir_all(coin_tests_dir)?; if tw_any_address_tests_path.exists() { + println!("[SKIP] {tw_any_address_tests_path:?} already exists"); return Ok(()); } + println!("[ADD] {tw_any_address_tests_path:?}"); TemplateGenerator::new(TW_ANY_ADDRESS_TESTS_TEMPLATE) .write_to(tw_any_address_tests_path) .with_default_patterns(coin) diff --git a/codegen-v2/src/codegen/cpp/tw_any_signer_tests_generator.rs b/codegen-v2/src/codegen/cpp/tw_any_signer_tests_generator.rs index 32391ffe618..677162aee84 100644 --- a/codegen-v2/src/codegen/cpp/tw_any_signer_tests_generator.rs +++ b/codegen-v2/src/codegen/cpp/tw_any_signer_tests_generator.rs @@ -26,9 +26,11 @@ impl TWAnySignerTestsGenerator { fs::create_dir_all(coin_tests_dir)?; if tw_any_signer_tests_path.exists() { + println!("[SKIP] {tw_any_signer_tests_path:?} already exists"); return Ok(()); } + println!("[ADD] {tw_any_signer_tests_path:?}"); TemplateGenerator::new(TW_ANY_SIGNER_TESTS_TEMPLATE) .write_to(tw_any_signer_tests_path) .with_default_patterns(coin) diff --git a/codegen-v2/src/codegen/cpp/tw_blockchain.rs b/codegen-v2/src/codegen/cpp/tw_blockchain.rs index dee2986d328..f74c1e20ea9 100644 --- a/codegen-v2/src/codegen/cpp/tw_blockchain.rs +++ b/codegen-v2/src/codegen/cpp/tw_blockchain.rs @@ -23,8 +23,10 @@ pub struct TWBlockchainGenerator; impl TWBlockchainGenerator { pub fn generate_blockchain_type_variant(coin: &CoinItem) -> Result<()> { let coin_type = coin.blockchain_type(); + let tw_blockchain_type_path = tw_blockchain_path(); - let mut tw_blockchain_type_rs = FileContent::read(tw_blockchain_path())?; + println!("[EDIT] {tw_blockchain_type_path:?}"); + let mut tw_blockchain_type_rs = FileContent::read(tw_blockchain_type_path)?; { let mut enum_region = diff --git a/codegen-v2/src/codegen/cpp/tw_coin_address_derivation_tests_generator.rs b/codegen-v2/src/codegen/cpp/tw_coin_address_derivation_tests_generator.rs index 772fea23676..1cdeaf295ac 100644 --- a/codegen-v2/src/codegen/cpp/tw_coin_address_derivation_tests_generator.rs +++ b/codegen-v2/src/codegen/cpp/tw_coin_address_derivation_tests_generator.rs @@ -27,9 +27,10 @@ pub struct CoinAddressDerivationTestsGenerator; impl CoinAddressDerivationTestsGenerator { pub fn generate_new_coin_type_case(coin: &CoinItem) -> Result<()> { let coin_type = coin.coin_type(); + let test_path = coin_address_derivation_tests_path(); + println!("[EDIT] {test_path:?}"); - let mut coin_address_derivation_test_rs = - FileContent::read(coin_address_derivation_tests_path())?; + let mut coin_address_derivation_test_rs = FileContent::read(test_path)?; { let mut switch_case_region = coin_address_derivation_test_rs @@ -50,9 +51,10 @@ r#" case TWCoinType{coin_type}: pub fn generate_new_evm_coin_type_case(coin: &CoinItem) -> Result<()> { let coin_type = coin.coin_type(); + let test_path = coin_address_derivation_tests_path(); + println!("[EDIT] {test_path:?}"); - let mut evm_address_derivation_test_rs = - FileContent::read(coin_address_derivation_tests_path())?; + let mut evm_address_derivation_test_rs = FileContent::read(test_path)?; { let mut switch_case_region = evm_address_derivation_test_rs diff --git a/codegen-v2/src/codegen/cpp/tw_coin_type_generator.rs b/codegen-v2/src/codegen/cpp/tw_coin_type_generator.rs index 385f69076cd..d238922ae4d 100644 --- a/codegen-v2/src/codegen/cpp/tw_coin_type_generator.rs +++ b/codegen-v2/src/codegen/cpp/tw_coin_type_generator.rs @@ -23,8 +23,10 @@ impl TWCoinTypeGenerator { pub fn generate_coin_type_variant(coin: &CoinItem) -> Result<()> { let coin_type = coin.coin_type(); let coin_id_number = coin.coin_id_number; + let tw_coin_type_file_path = tw_coin_type_path(); - let mut tw_coin_type_rs = FileContent::read(tw_coin_type_path())?; + println!("[EDIT] {tw_coin_type_file_path:?}"); + let mut tw_coin_type_rs = FileContent::read(tw_coin_type_file_path)?; { let mut enum_region = diff --git a/codegen-v2/src/codegen/cpp/tw_coin_type_tests_generator.rs b/codegen-v2/src/codegen/cpp/tw_coin_type_tests_generator.rs index 2790c302138..8b85c4e79f4 100644 --- a/codegen-v2/src/codegen/cpp/tw_coin_type_tests_generator.rs +++ b/codegen-v2/src/codegen/cpp/tw_coin_type_tests_generator.rs @@ -26,9 +26,11 @@ impl TWCoinTypeTestsGenerator { fs::create_dir(coin_tests_dir)?; if tw_coin_type_tests_path.exists() { + println!("[SKIP] {tw_coin_type_tests_path:?} already exists"); return Ok(()); } + println!("[ADD] {tw_coin_type_tests_path:?}"); TemplateGenerator::new(TW_COIN_TYPE_TESTS_TEMPLATE) .write_to(tw_coin_type_tests_path) .with_default_patterns(coin) diff --git a/codegen-v2/src/codegen/proto/proto_generator.rs b/codegen-v2/src/codegen/proto/proto_generator.rs index 3b08ef8b16c..f3bd016984d 100644 --- a/codegen-v2/src/codegen/proto/proto_generator.rs +++ b/codegen-v2/src/codegen/proto/proto_generator.rs @@ -24,9 +24,11 @@ impl ProtoGenerator { let proto_path = blockchain_proto_path(coin); if proto_path.exists() { + println!("[SKIP] Protobuf interface already exists: {proto_path:?}"); return Ok(()); } + println!("[ADD] {proto_path:?}"); TemplateGenerator::new(PROTO_TEMPLATE) .write_to(proto_path) .with_default_patterns(coin) diff --git a/codegen-v2/src/codegen/rust/blockchain_dispatcher_generator.rs b/codegen-v2/src/codegen/rust/blockchain_dispatcher_generator.rs index 4c00268a7ca..19c83519e15 100644 --- a/codegen-v2/src/codegen/rust/blockchain_dispatcher_generator.rs +++ b/codegen-v2/src/codegen/rust/blockchain_dispatcher_generator.rs @@ -24,6 +24,7 @@ pub struct BlockchainDispatcherGenerator; impl BlockchainDispatcherGenerator { pub fn generate_new_blockchain_type_dispatching(coin: &CoinItem) -> Result<()> { let dispatcher_rs_path = dispatcher_path(); + println!("[EDIT] {dispatcher_rs_path:?}"); let mut dispatcher_rs = FileContent::read(dispatcher_rs_path)?; Self::generate_use_of_blockchain_entry(coin, &mut dispatcher_rs)?; diff --git a/codegen-v2/src/codegen/rust/blockchain_type_generator.rs b/codegen-v2/src/codegen/rust/blockchain_type_generator.rs index f82ce5144fa..b902e88f739 100644 --- a/codegen-v2/src/codegen/rust/blockchain_type_generator.rs +++ b/codegen-v2/src/codegen/rust/blockchain_type_generator.rs @@ -27,6 +27,7 @@ impl BlockchainTypeGenerator { let blockchain_type_rs_path = blockchain_type_path(); let blockchain_type = coin.blockchain_type(); + println!("[EDIT] {blockchain_type_rs_path:?}"); let mut blockchain_type_rs = FileContent::read(blockchain_type_rs_path)?; { diff --git a/codegen-v2/src/codegen/rust/coin_address_derivation_test_generator.rs b/codegen-v2/src/codegen/rust/coin_address_derivation_test_generator.rs index 25b2b9933b4..4a5d3acdcc6 100644 --- a/codegen-v2/src/codegen/rust/coin_address_derivation_test_generator.rs +++ b/codegen-v2/src/codegen/rust/coin_address_derivation_test_generator.rs @@ -25,10 +25,11 @@ pub struct CoinAddressDerivationTestGenerator; impl CoinAddressDerivationTestGenerator { pub fn generate_new_coin_type_case(coin: &CoinItem) -> Result<()> { + let test_path = coin_address_derivation_test_path(); let coin_type = coin.coin_type(); - let mut coin_address_derivation_test_rs = - FileContent::read(coin_address_derivation_test_path())?; + println!("[EDIT] {test_path:?}"); + let mut coin_address_derivation_test_rs = FileContent::read(test_path)?; { let mut end_of_test = coin_address_derivation_test_rs @@ -40,10 +41,11 @@ impl CoinAddressDerivationTestGenerator { } pub fn generate_new_evm_coin_type_case(coin: &CoinItem) -> Result<()> { + let test_path = coin_address_derivation_test_path(); let coin_type = coin.coin_type(); - let mut coin_address_derivation_test_rs = - FileContent::read(coin_address_derivation_test_path())?; + println!("[EDIT] {test_path:?}"); + let mut coin_address_derivation_test_rs = FileContent::read(test_path)?; { let mut end_of_test = coin_address_derivation_test_rs diff --git a/codegen-v2/src/codegen/rust/coin_crate.rs b/codegen-v2/src/codegen/rust/coin_crate.rs index 8b6ef18b3c1..330d84e26b2 100644 --- a/codegen-v2/src/codegen/rust/coin_crate.rs +++ b/codegen-v2/src/codegen/rust/coin_crate.rs @@ -46,40 +46,47 @@ impl CoinCrate { let blockchain_signer_rs_path = blockchain_src_path.join("signer.rs"); if blockchain_path.exists() { - return Err(Error::IoError(io::Error::new( - io::ErrorKind::AlreadyExists, - "blockchain already exists", - ))); + let tw_crate_name = self.coin.id.to_tw_crate_name(); + println!( + "[SKIP] '{tw_crate_name}' blockchain crate already exists: {blockchain_path:?}" + ); + return Ok(blockchain_path); } - fs::create_dir(&blockchain_path)?; - fs::create_dir(&blockchain_src_path)?; + fs::create_dir_all(&blockchain_path)?; + fs::create_dir_all(&blockchain_src_path)?; + println!("[ADD] {blockchain_toml_path:?}"); TemplateGenerator::new(BLOCKCHAIN_MANIFEST_TEMPLATE) .write_to(blockchain_toml_path) .with_default_patterns(&self.coin) .write()?; + println!("[ADD] {blockchain_lib_rs_path:?}"); TemplateGenerator::new(BLOCKCHAIN_LIB_TEMPLATE) .write_to(blockchain_lib_rs_path) .with_default_patterns(&self.coin) .write()?; + println!("[ADD] {blockchain_entry_path:?}"); TemplateGenerator::new(BLOCKCHAIN_ENTRY_TEMPLATE) .write_to(blockchain_entry_path) .with_default_patterns(&self.coin) .write()?; + println!("[ADD] {blockchain_compiler_path:?}"); TemplateGenerator::new(BLOCKCHAIN_COMPILER_TEMPLATE) .write_to(blockchain_compiler_path) .with_default_patterns(&self.coin) .write()?; + println!("[ADD] {blockchain_address_rs_path:?}"); TemplateGenerator::new(BLOCKCHAIN_ADDRESS_TEMPLATE) .write_to(blockchain_address_rs_path) .with_default_patterns(&self.coin) .write()?; + println!("[ADD] {blockchain_signer_rs_path:?}"); TemplateGenerator::new(BLOCKCHAIN_SIGNER_TEMPLATE) .write_to(blockchain_signer_rs_path) .with_default_patterns(&self.coin) diff --git a/codegen-v2/src/codegen/rust/coin_integration_tests.rs b/codegen-v2/src/codegen/rust/coin_integration_tests.rs index 18c5356f064..541e1b2ae3c 100644 --- a/codegen-v2/src/codegen/rust/coin_integration_tests.rs +++ b/codegen-v2/src/codegen/rust/coin_integration_tests.rs @@ -44,10 +44,11 @@ impl CoinIntegrationTests { pub fn create(self) -> Result { let blockchain_tests_path = self.coin_tests_directory(); if blockchain_tests_path.exists() { + println!("[SKIP] integration tests already exists: {blockchain_tests_path:?}"); return Ok(blockchain_tests_path); } - fs::create_dir(&blockchain_tests_path)?; + fs::create_dir_all(&blockchain_tests_path)?; self.list_blockchain_in_chains_mod()?; self.create_address_tests()?; @@ -68,6 +69,7 @@ impl CoinIntegrationTests { .coin_tests_directory() .join(format!("{coin_id}_address.rs")); + println!("[ADD] {address_tests_path:?}"); TemplateGenerator::new(ADDRESS_TESTS_TEMPLATE) .write_to(address_tests_path) .with_default_patterns(&self.coin) @@ -80,6 +82,7 @@ impl CoinIntegrationTests { .coin_tests_directory() .join(format!("{coin_id}_compile.rs")); + println!("[ADD] {compile_tests_path:?}"); TemplateGenerator::new(COMPILE_TESTS_TEMPLATE) .write_to(compile_tests_path) .with_default_patterns(&self.coin) @@ -92,6 +95,7 @@ impl CoinIntegrationTests { .coin_tests_directory() .join(format!("{coin_id}_sign.rs")); + println!("[ADD] {sign_tests_path:?}"); TemplateGenerator::new(SIGN_TESTS_TEMPLATE) .write_to(sign_tests_path) .with_default_patterns(&self.coin) @@ -101,6 +105,7 @@ impl CoinIntegrationTests { fn create_chain_tests_mod_rs(&self) -> Result<()> { let blockchain_tests_mod_path = self.coin_tests_directory().join("mod.rs"); + println!("[ADD] {blockchain_tests_mod_path:?}"); TemplateGenerator::new(MOD_TESTS_TEMPLATE) .write_to(blockchain_tests_mod_path) .with_default_patterns(&self.coin) @@ -111,6 +116,7 @@ impl CoinIntegrationTests { let chains_mod_path = chains_integration_tests_directory().join("mod.rs"); let chain_id = self.coin.id.as_str(); + println!("[EDIT] {chains_mod_path:?}"); let mut chains_mod_rs = FileContent::read(chains_mod_path)?; { diff --git a/codegen-v2/src/codegen/rust/coin_registry_manifest_generator.rs b/codegen-v2/src/codegen/rust/coin_registry_manifest_generator.rs index 6b0ff03b2f2..f76fed045db 100644 --- a/codegen-v2/src/codegen/rust/coin_registry_manifest_generator.rs +++ b/codegen-v2/src/codegen/rust/coin_registry_manifest_generator.rs @@ -15,6 +15,7 @@ pub struct CoinRegistryManifestGenerator; impl CoinRegistryManifestGenerator { pub fn add_dependency(coin: &CoinItem, path_to_new_blockchain_crate: &Path) -> Result<()> { let path_to_cargo_manifest = coin_registry_directory().join("Cargo.toml"); + println!("[EDIT] {path_to_cargo_manifest:?}"); Dependencies::new(path_to_cargo_manifest) .insert_dependency(&coin.id.to_tw_crate_name(), path_to_new_blockchain_crate) } diff --git a/codegen-v2/src/main.rs b/codegen-v2/src/main.rs index a45bb39d733..d708659a4c0 100644 --- a/codegen-v2/src/main.rs +++ b/codegen-v2/src/main.rs @@ -33,6 +33,7 @@ fn new_blockchain_rust(args: &[String]) -> Result<()> { let coin_id = CoinId::new(coin_str.clone())?; let coin_item = read_coin_from_registry(&coin_id)?; + println!("New Rust blockchain template for coin '{coin_str}' requested"); rust::new_blockchain::new_blockchain(&coin_item)?; Ok(()) @@ -43,6 +44,8 @@ fn new_blockchain(args: &[String]) -> Result<()> { let coin_id = CoinId::new(coin_str.clone())?; let coin_item = read_coin_from_registry(&coin_id)?; + println!("New '{coin_str}' blockchain template requested"); + proto::new_blockchain::new_blockchain(&coin_item)?; rust::new_blockchain::new_blockchain(&coin_item)?; cpp::new_blockchain::new_blockchain(&coin_item)?; @@ -55,6 +58,8 @@ fn new_evmchain(args: &[String]) -> Result<()> { let coin_id = CoinId::new(coin_str.clone())?; let coin_item = read_coin_from_registry(&coin_id)?; + println!("New '{coin_str}' EVM chain template requested"); + rust::new_evmchain::new_evmchain(&coin_item)?; cpp::new_evmchain::new_evmchain(&coin_item)?; diff --git a/codegen/lib/coin_skeleton_gen.rb b/codegen/lib/coin_skeleton_gen.rb index 9a12fca1e9e..b0bcbe85e80 100755 --- a/codegen/lib/coin_skeleton_gen.rb +++ b/codegen/lib/coin_skeleton_gen.rb @@ -117,6 +117,7 @@ def generate_mobile_tests(coin) end def generate_coin_type_tests(coin) + coin_test_gen = CoinTestGen.new() coin_test_gen.generate_coin_test_file(coin, 'TWCoinTypeTests.cpp.erb', true) end @@ -133,8 +134,6 @@ def generate_skeleton(coin_id, mode) @coins = coins - coin_test_gen = CoinTestGen.new() - # Find coin in list of coins, by Id coinSelect = coins.select {|c| c['id'] == coin_id} if coinSelect.length() == 0