feat(cli/mobile/init): add --skip-targets-install, ref #7044 #7058 (#7062)

This commit is contained in:
Lucas Fernandes Nogueira 2023-05-26 08:49:51 -07:00 committed by GitHub
parent 7fee3d3a2a
commit 735db1ce83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 29 deletions

View File

@ -0,0 +1,6 @@
---
'cli.rs': 'patch:enhance'
'cli.js': 'patch:enhance'
---
Add `--skip-targets-install` flag for `tauri android init` and `tauri ios init` to skip installing needed rust targets vie rustup.

View File

@ -62,6 +62,9 @@ pub struct InitOptions {
/// Skip prompting for values
#[clap(long)]
ci: bool,
/// Skips installing rust toolchains via rustup
#[clap(long)]
skip_targets_install: bool,
}
#[derive(Subcommand)]
@ -78,7 +81,12 @@ enum Commands {
pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
match cli.command {
Commands::Init(options) => init_command(MobileTarget::Android, options.ci, false)?,
Commands::Init(options) => init_command(
MobileTarget::Android,
options.ci,
false,
options.skip_targets_install,
)?,
Commands::Open => open::command()?,
Commands::Dev(options) => dev::command(options, noise_level)?,
Commands::Build(options) => build::command(options, noise_level)?,

View File

@ -34,23 +34,25 @@ pub fn gen(
metadata: &Metadata,
(handlebars, mut map): (Handlebars, template::JsonMap),
wrapper: &TextWrapper,
skip_targets_install: bool,
) -> Result<()> {
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
let missing_targets = Target::all()
.values()
.filter(|t| !installed_targets.contains(&t.triple().into()))
.collect::<Vec<&Target>>();
if !skip_targets_install {
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
let missing_targets = Target::all()
.values()
.filter(|t| !installed_targets.contains(&t.triple().into()))
.collect::<Vec<&Target>>();
if !missing_targets.is_empty() {
println!("Installing Android Rust toolchains...");
for target in missing_targets {
target
.install()
.context("failed to install target with rustup")?;
if !missing_targets.is_empty() {
println!("Installing Android Rust toolchains...");
for target in missing_targets {
target
.install()
.context("failed to install target with rustup")?;
}
}
}
println!("Generating Android Studio project...");
let dest = config.project_dir();
let asset_packs = metadata.asset_packs().unwrap_or_default();

View File

@ -24,13 +24,19 @@ use std::{
path::PathBuf,
};
pub fn command(target: Target, ci: bool, reinstall_deps: bool) -> Result<()> {
pub fn command(
target: Target,
ci: bool,
reinstall_deps: bool,
skip_targets_install: bool,
) -> Result<()> {
let wrapper = TextWrapper::with_splitter(textwrap::termwidth(), textwrap::NoHyphenation);
exec(
target,
&wrapper,
ci || var_os("CI").is_some(),
reinstall_deps,
skip_targets_install,
)
.map_err(|e| anyhow::anyhow!("{:#}", e))?;
Ok(())
@ -78,6 +84,7 @@ pub fn exec(
wrapper: &TextWrapper,
#[allow(unused_variables)] non_interactive: bool,
#[allow(unused_variables)] reinstall_deps: bool,
skip_targets_install: bool,
) -> Result<App> {
let tauri_config = get_tauri_config(None)?;
let tauri_config_guard = tauri_config.lock().unwrap();
@ -154,7 +161,13 @@ pub fn exec(
let (app, config, metadata) =
super::android::get_config(Some(app), tauri_config_, &Default::default());
map.insert("android", &config);
super::android::project::gen(&config, &metadata, (handlebars, map), wrapper)?;
super::android::project::gen(
&config,
&metadata,
(handlebars, map),
wrapper,
skip_targets_install,
)?;
app
}
Err(err) => {
@ -183,6 +196,7 @@ pub fn exec(
wrapper,
non_interactive,
reinstall_deps,
skip_targets_install,
)?;
app
}

View File

@ -66,6 +66,9 @@ pub struct InitOptions {
/// Reinstall dependencies
#[clap(short, long)]
reinstall_deps: bool,
/// Skips installing rust toolchains via rustup
#[clap(long)]
skip_targets_install: bool,
}
#[derive(Subcommand)]
@ -82,7 +85,12 @@ enum Commands {
pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
match cli.command {
Commands::Init(options) => init_command(MobileTarget::Ios, options.ci, options.reinstall_deps)?,
Commands::Init(options) => init_command(
MobileTarget::Ios,
options.ci,
options.reinstall_deps,
options.skip_targets_install,
)?,
Commands::Open => open::command()?,
Commands::Dev(options) => dev::command(options, noise_level)?,
Commands::Build(options) => build::command(options, noise_level)?,

View File

@ -33,20 +33,23 @@ pub fn gen(
wrapper: &TextWrapper,
non_interactive: bool,
reinstall_deps: bool,
skip_targets_install: bool,
) -> Result<()> {
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
let missing_targets = Target::all()
.values()
.filter(|t| !installed_targets.contains(&t.triple().into()))
.collect::<Vec<&Target>>();
if !skip_targets_install {
let installed_targets =
crate::interface::rust::installation::installed_targets().unwrap_or_default();
let missing_targets = Target::all()
.values()
.filter(|t| !installed_targets.contains(&t.triple().into()))
.collect::<Vec<&Target>>();
if !missing_targets.is_empty() {
println!("Installing iOS Rust toolchains...");
for target in missing_targets {
target
.install()
.context("failed to install target with rustup")?;
if !missing_targets.is_empty() {
println!("Installing iOS Rust toolchains...");
for target in missing_targets {
target
.install()
.context("failed to install target with rustup")?;
}
}
}