Skip to content

Commit

Permalink
fix(cli): IDE failing to read CLI options on build --open commands (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Nov 14, 2023
1 parent ecb5b0c commit 977d0e5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-ide-build-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
"@tauri-apps/cli": patch:bug
---

Fixes `android build --open` and `ios build --open` IDE failing to read CLI options.
10 changes: 5 additions & 5 deletions tooling/cli/src/mobile/android/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::{
configure_cargo, delete_codegen_vars, ensure_init, env, get_app, get_config, inject_assets,
log_finished, open_and_wait, MobileTarget,
log_finished, open_and_wait, MobileTarget, OptionsHandle,
};
use crate::{
build::Options as BuildOptions,
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn command(mut options: Options, noise_level: NoiseLevel) -> Result<()> {
)?;

let open = options.open;
run_build(
let _handle = run_build(
options,
tauri_config,
profile,
Expand All @@ -154,7 +154,7 @@ fn run_build(
config: &AndroidConfig,
env: &mut Env,
noise_level: NoiseLevel,
) -> Result<()> {
) -> Result<OptionsHandle> {
if !(options.apk || options.aab) {
// if the user didn't specify the format to build, we'll do both
options.apk = true;
Expand Down Expand Up @@ -192,7 +192,7 @@ fn run_build(
noise_level,
vars: Default::default(),
};
let _handle = write_options(
let handle = write_options(
&tauri_config
.lock()
.unwrap()
Expand Down Expand Up @@ -240,7 +240,7 @@ fn run_build(
log_finished(apk_outputs, "APK");
log_finished(aab_outputs, "AAB");

Ok(())
Ok(handle)
}

fn get_targets_or_all<'a>(targets: Vec<String>) -> Result<Vec<&'a Target<'a>>> {
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/mobile/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sublime_fuzzy::best_match;
use super::{
ensure_init, get_app,
init::{command as init_command, configure_cargo},
log_finished, read_options, setup_dev_config, CliOptions, Target as MobileTarget,
log_finished, read_options, setup_dev_config, CliOptions, OptionsHandle, Target as MobileTarget,
MIN_DEVICE_MATCH_SCORE,
};
use crate::{helpers::config::Config as TauriConfig, Result};
Expand Down
10 changes: 5 additions & 5 deletions tooling/cli/src/mobile/ios/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::{
configure_cargo, detect_target_ok, ensure_init, env, get_app, get_config, inject_assets,
log_finished, merge_plist, open_and_wait, MobileTarget,
log_finished, merge_plist, open_and_wait, MobileTarget, OptionsHandle,
};
use crate::{
build::Options as BuildOptions,
Expand Down Expand Up @@ -115,7 +115,7 @@ pub fn command(mut options: Options, noise_level: NoiseLevel) -> Result<()> {
configure_cargo(&app, None)?;

let open = options.open;
run_build(options, tauri_config, &config, &mut env, noise_level)?;
let _handle = run_build(options, tauri_config, &config, &mut env, noise_level)?;

if open {
open_and_wait(&config, &env);
Expand All @@ -130,7 +130,7 @@ fn run_build(
config: &AppleConfig,
env: &mut Env,
noise_level: NoiseLevel,
) -> Result<()> {
) -> Result<OptionsHandle> {
let profile = if options.debug {
Profile::Debug
} else {
Expand Down Expand Up @@ -163,7 +163,7 @@ fn run_build(
noise_level,
vars: Default::default(),
};
let _handle = write_options(
let handle = write_options(
&tauri_config
.lock()
.unwrap()
Expand Down Expand Up @@ -211,5 +211,5 @@ fn run_build(

log_finished(out_files, "IPA");

Ok(())
Ok(handle)
}
2 changes: 1 addition & 1 deletion tooling/cli/src/mobile/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sublime_fuzzy::best_match;
use super::{
ensure_init, env, get_app,
init::{command as init_command, configure_cargo},
log_finished, read_options, setup_dev_config, CliOptions, Target as MobileTarget,
log_finished, read_options, setup_dev_config, CliOptions, OptionsHandle, Target as MobileTarget,
MIN_DEVICE_MATCH_SCORE,
};
use crate::{helpers::config::Config as TauriConfig, Result};
Expand Down
9 changes: 4 additions & 5 deletions tooling/cli/src/mobile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,10 @@ fn env() -> Result<Env, EnvError> {
Ok(env)
}

pub struct OptionsHandle(Runtime, ServerHandle);

/// Writes CLI options to be used later on the Xcode and Android Studio build commands
pub fn write_options(
identifier: &str,
mut options: CliOptions,
) -> crate::Result<(Runtime, ServerHandle)> {
pub fn write_options(identifier: &str, mut options: CliOptions) -> crate::Result<OptionsHandle> {
options.vars.extend(env_vars());

let runtime = Runtime::new().unwrap();
Expand All @@ -243,7 +242,7 @@ pub fn write_options(
addr.to_string(),
)?;

Ok((runtime, handle))
Ok(OptionsHandle(runtime, handle))
}

fn read_options(identifier: &str) -> CliOptions {
Expand Down

0 comments on commit 977d0e5

Please sign in to comment.