Skip to content

Commit

Permalink
[Codegen]: Add stdout logs, fix codegen-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Nov 24, 2023
1 parent 6ef3eb5 commit a8c4ee7
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
9 changes: 4 additions & 5 deletions codegen-v2/src/codegen/cpp/entry_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions codegen-v2/src/codegen/cpp/tw_any_address_tests_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions codegen-v2/src/codegen/cpp/tw_any_signer_tests_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion codegen-v2/src/codegen/cpp/tw_blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion codegen-v2/src/codegen/cpp/tw_coin_type_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions codegen-v2/src/codegen/cpp/tw_coin_type_tests_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions codegen-v2/src/codegen/proto/proto_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
1 change: 1 addition & 0 deletions codegen-v2/src/codegen/rust/blockchain_type_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 13 additions & 6 deletions codegen-v2/src/codegen/rust/coin_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion codegen-v2/src/codegen/rust/coin_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ impl CoinIntegrationTests {
pub fn create(self) -> Result<PathBuf> {
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()?;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)?;

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions codegen-v2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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)?;
Expand All @@ -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)?;

Expand Down
3 changes: 1 addition & 2 deletions codegen/lib/coin_skeleton_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit a8c4ee7

Please sign in to comment.