feat(cli/mobile): allow checking gen folder into source control (#5146)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir
2022-09-12 21:46:09 +02:00
committed by GitHub
parent 8ea87e9c9c
commit 10ab3e2f5e
6 changed files with 30 additions and 16 deletions

View File

@@ -54,7 +54,7 @@ pub fn render<P: AsRef<Path>, 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<P: AsRef<Path>, D: Serialize>(
pub fn render_with_generator<
P: AsRef<Path>,
D: Serialize,
F: FnMut(&PathBuf) -> std::io::Result<File>,
F: FnMut(&PathBuf) -> std::io::Result<Option<File>>,
>(
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() {

View File

@@ -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);
}
}
}

View File

@@ -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")?;

View File

@@ -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")?;

View File

@@ -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

View File

@@ -1,2 +1 @@
/build
/src/main/{{package-path}}/generated