瀏覽代碼

fix(cli/android): fallback to all targets (#7028)

fix regression introduced in https://github.com/tauri-apps/tauri/commit/d03e47d141c3917520975be9081775dbc4e9d4fd
Amr Bashir 2 年之前
父節點
當前提交
3f4c4ce88b
共有 2 個文件被更改,包括 30 次插入21 次删除
  1. 5 0
      .changes/cli-android-split-per-abit-target.md
  2. 25 21
      tooling/cli/src/mobile/android/build.rs

+ 5 - 0
.changes/cli-android-split-per-abit-target.md

@@ -0,0 +1,5 @@
+---
+'cli.rs': 'patch'
+---
+
+Fix `--split-per-abi` not building any targets unless specified by `--target` flag.

+ 25 - 21
tooling/cli/src/mobile/android/build.rs

@@ -186,7 +186,7 @@ fn run_build(
       env,
       noise_level,
       profile,
-      get_targets(options.targets.clone().unwrap_or_default())?,
+      get_targets_or_all(options.targets.clone().unwrap_or_default())?,
       options.split_per_abi,
     )?
   } else {
@@ -199,7 +199,7 @@ fn run_build(
       env,
       noise_level,
       profile,
-      get_targets(options.targets.unwrap_or_default())?,
+      get_targets_or_all(options.targets.unwrap_or_default())?,
       options.split_per_abi,
     )?
   } else {
@@ -212,24 +212,28 @@ fn run_build(
   Ok(())
 }
 
-fn get_targets<'a>(targets: Vec<String>) -> Result<Vec<&'a Target<'a>>> {
-  let mut outs = Vec::new();
-
-  let possible_targets = Target::all()
-    .keys()
-    .map(|key| key.to_string())
-    .collect::<Vec<String>>()
-    .join(",");
-
-  for t in targets {
-    let target = Target::for_name(&t).ok_or_else(|| {
-      anyhow::anyhow!(
-        "Target {} is invalid; the possible targets are {}",
-        t,
-        possible_targets
-      )
-    })?;
-    outs.push(target);
+fn get_targets_or_all<'a>(targets: Vec<String>) -> Result<Vec<&'a Target<'a>>> {
+  if targets.is_empty() {
+    Ok(Target::all().iter().map(|t| t.1).collect())
+  } else {
+    let mut outs = Vec::new();
+
+    let possible_targets = Target::all()
+      .keys()
+      .map(|key| key.to_string())
+      .collect::<Vec<String>>()
+      .join(",");
+
+    for t in targets {
+      let target = Target::for_name(&t).ok_or_else(|| {
+        anyhow::anyhow!(
+          "Target {} is invalid; the possible targets are {}",
+          t,
+          possible_targets
+        )
+      })?;
+      outs.push(target);
+    }
+    Ok(outs)
   }
-  Ok(outs)
 }