From 82764a4b86b927a79d1ad51c57e47f23accee86a Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Wed, 21 Feb 2024 11:25:42 -0500 Subject: [PATCH 1/2] Rename Cargo.toml to Cargo.text in the init template files --- cmd/soroban-cli/src/commands/contract/init.rs | 8 +++++++- .../contract-init-template/{Cargo.toml => Cargo.text} | 0 2 files changed, 7 insertions(+), 1 deletion(-) rename cmd/soroban-cli/src/utils/contract-init-template/{Cargo.toml => Cargo.text} (100%) diff --git a/cmd/soroban-cli/src/commands/contract/init.rs b/cmd/soroban-cli/src/commands/contract/init.rs index fe88dbb68..9ea566658 100644 --- a/cmd/soroban-cli/src/commands/contract/init.rs +++ b/cmd/soroban-cli/src/commands/contract/init.rs @@ -198,7 +198,8 @@ fn init( fn copy_template_files(project_path: &Path) -> Result<(), Error> { for item in TemplateFiles::iter() { - let to = project_path.join(item.as_ref()); + let mut to = project_path.join(item.as_ref()); + if file_exists(&to.to_string_lossy()) { println!( "ℹ️ Skipped creating {} as it already exists", @@ -224,6 +225,11 @@ fn copy_template_files(project_path: &Path) -> Result<(), Error> { e })?; + // We need to include the Cargo.toml file as Cargo.text in the template so that it will be included the package. This is making sure that the Cargo file is written as Cargo.toml in the new project. This is a workaround for this issue: https://github.com/rust-lang/cargo/issues/8597. + if item == "Cargo.text" { + to = project_path.join("Cargo.toml"); + } + println!("➕ Writing {}", &to.to_string_lossy()); write(&to, file_contents).map_err(|e| { eprintln!("Error writing file: {to:?}"); diff --git a/cmd/soroban-cli/src/utils/contract-init-template/Cargo.toml b/cmd/soroban-cli/src/utils/contract-init-template/Cargo.text similarity index 100% rename from cmd/soroban-cli/src/utils/contract-init-template/Cargo.toml rename to cmd/soroban-cli/src/utils/contract-init-template/Cargo.text From 433668854d8ac14b82e12d992b0a396b5f4f3672 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:07:48 -0500 Subject: [PATCH 2/2] Address PR feedback --- cmd/soroban-cli/src/commands/contract/init.rs | 2 +- .../{Cargo.text => Cargo.toml.removeextension} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename cmd/soroban-cli/src/utils/contract-init-template/{Cargo.text => Cargo.toml.removeextension} (100%) diff --git a/cmd/soroban-cli/src/commands/contract/init.rs b/cmd/soroban-cli/src/commands/contract/init.rs index 9ea566658..ef25c08ad 100644 --- a/cmd/soroban-cli/src/commands/contract/init.rs +++ b/cmd/soroban-cli/src/commands/contract/init.rs @@ -226,7 +226,7 @@ fn copy_template_files(project_path: &Path) -> Result<(), Error> { })?; // We need to include the Cargo.toml file as Cargo.text in the template so that it will be included the package. This is making sure that the Cargo file is written as Cargo.toml in the new project. This is a workaround for this issue: https://github.com/rust-lang/cargo/issues/8597. - if item == "Cargo.text" { + if item == "Cargo.toml.removeextension" { to = project_path.join("Cargo.toml"); } diff --git a/cmd/soroban-cli/src/utils/contract-init-template/Cargo.text b/cmd/soroban-cli/src/utils/contract-init-template/Cargo.toml.removeextension similarity index 100% rename from cmd/soroban-cli/src/utils/contract-init-template/Cargo.text rename to cmd/soroban-cli/src/utils/contract-init-template/Cargo.toml.removeextension