diff --git a/tooling/cli/src/helpers/template.rs b/tooling/cli/src/helpers/template.rs index 20e64cf01..3bc03eeb2 100644 --- a/tooling/cli/src/helpers/template.rs +++ b/tooling/cli/src/helpers/template.rs @@ -54,7 +54,7 @@ pub fn render, D: Serialize>( create_dir_all(&parent)?; created_dirs.push(parent); } - File::create(path) + File::create(path).map(Some) }, ) } @@ -62,7 +62,7 @@ pub fn render, D: Serialize>( pub fn render_with_generator< P: AsRef, D: Serialize, - F: FnMut(&PathBuf) -> std::io::Result, + F: FnMut(&PathBuf) -> std::io::Result>, >( handlebars: &Handlebars<'_>, data: &D, @@ -80,13 +80,14 @@ pub fn render_with_generator< file_path.set_extension("toml"); } } - let mut output_file = out_file_generator(&file_path)?; - if let Some(utf8) = file.contents_utf8() { - handlebars - .render_template_to_write(utf8, &data, &mut output_file) - .expect("Failed to render template"); - } else { - output_file.write_all(file.contents())?; + if let Some(mut output_file) = out_file_generator(&file_path)? { + if let Some(utf8) = file.contents_utf8() { + handlebars + .render_template_to_write(utf8, &data, &mut output_file) + .expect("Failed to render template"); + } else { + output_file.write_all(file.contents())?; + } } } for dir in dir.dirs() { diff --git a/tooling/cli/src/info.rs b/tooling/cli/src/info.rs index 1f5d78f56..b4b4b3c90 100644 --- a/tooling/cli/src/info.rs +++ b/tooling/cli/src/info.rs @@ -641,7 +641,7 @@ pub fn command(_options: Options) -> Result<()> { InfoBlock::new("MSVC", "").display(); for i in build_tools { indent(6); - println!("{}", format!("{} {}", "-".cyan(), i)); + println!("{} {}", "-".cyan(), i); } } } diff --git a/tooling/cli/src/mobile/android/project.rs b/tooling/cli/src/mobile/android/project.rs index 8a06701f6..16b5cacfe 100644 --- a/tooling/cli/src/mobile/android/project.rs +++ b/tooling/cli/src/mobile/android/project.rs @@ -122,6 +122,7 @@ pub fn gen( } let mut options = fs::OpenOptions::new(); + options.write(true); #[cfg(unix)] if path.file_name().unwrap() == OsStr::new("gradlew") { @@ -129,7 +130,11 @@ pub fn gen( options.mode(0o755); } - options.create_new(true).write(true).open(path) + if path.file_name().unwrap() == OsStr::new("BuildTask.kt") || !path.exists() { + options.create(true).open(path).map(Some) + } else { + Ok(None) + } }, ) .with_context(|| "failed to process template")?; diff --git a/tooling/cli/src/mobile/ios/project.rs b/tooling/cli/src/mobile/ios/project.rs index a2ddc1a3a..ea7bf3035 100644 --- a/tooling/cli/src/mobile/ios/project.rs +++ b/tooling/cli/src/mobile/ios/project.rs @@ -18,8 +18,8 @@ use cargo_mobile::{ use handlebars::Handlebars; use include_dir::{include_dir, Dir}; use std::{ - ffi::OsString, - fs::{create_dir_all, File}, + ffi::{OsStr, OsString}, + fs::{create_dir_all, OpenOptions}, path::{Component, PathBuf}, }; @@ -136,7 +136,14 @@ pub fn gen( created_dirs.push(parent); } - File::create(path) + let mut options = OpenOptions::new(); + options.write(true); + + if path.file_name().unwrap() == OsStr::new("BuildTask.kt") || !path.exists() { + options.create(true).open(path).map(Some) + } else { + Ok(None) + } }, ) .with_context(|| "failed to process template")?; diff --git a/tooling/cli/templates/mobile/android/.gitignore b/tooling/cli/templates/mobile/android/.gitignore index aa724b770..09f56a443 100644 --- a/tooling/cli/templates/mobile/android/.gitignore +++ b/tooling/cli/templates/mobile/android/.gitignore @@ -8,7 +8,9 @@ /.idea/navEditor.xml /.idea/assetWizardSettings.xml .DS_Store -/build +build +/buildSrc/src/main/{{package-path}}/kotlin/BuildTask.kt +/buildSrc/src/main/{{package-path}}/kotlin/RustPlugin.kt /captures .externalNativeBuild .cxx diff --git a/tooling/cli/templates/mobile/android/app/.gitignore b/tooling/cli/templates/mobile/android/app/.gitignore index 357fc705c..5da460648 100644 --- a/tooling/cli/templates/mobile/android/app/.gitignore +++ b/tooling/cli/templates/mobile/android/app/.gitignore @@ -1,2 +1 @@ -/build /src/main/{{package-path}}/generated