浏览代码

fix(cli): add MaybeWorkspace to license field (#8672)

* Add MaybeWorkspace to license field

* Fix last changes

* Fix formatting

* Add change .MD file
Andrew 1 年之前
父节点
当前提交
9cb9aa7978
共有 2 个文件被更改,包括 18 次插入2 次删除
  1. 6 0
      .changes/cli-license-field-workspace.md
  2. 12 2
      tooling/cli/src/interface/rust.rs

+ 6 - 0
.changes/cli-license-field-workspace.md

@@ -0,0 +1,6 @@
+---
+"tauri-cli": patch:bug
+"@tauri-apps/cli": patch:bug
+---
+
+Allow license field in Cargo.toml to be `{ workspace = true }`

+ 12 - 2
tooling/cli/src/interface/rust.rs

@@ -612,6 +612,7 @@ struct WorkspacePackageSettings {
   description: Option<String>,
   homepage: Option<String>,
   version: Option<String>,
+  license: Option<String>,
 }
 
 #[derive(Clone, Debug, Deserialize)]
@@ -635,7 +636,7 @@ pub struct CargoPackageSettings {
   /// the package's authors.
   pub authors: Option<MaybeWorkspace<Vec<String>>>,
   /// the package's license.
-  pub license: Option<String>,
+  pub license: Option<MaybeWorkspace<String>>,
   /// the default binary to run.
   pub default_run: Option<String>,
 }
@@ -930,7 +931,16 @@ impl RustAppSettings {
           })
           .unwrap()
       }),
-      license: cargo_package_settings.license.clone(),
+      license: cargo_package_settings.license.clone().map(|license| {
+        license
+          .resolve("license", || {
+            ws_package_settings
+              .as_ref()
+              .and_then(|v| v.license.clone())
+              .ok_or_else(|| anyhow::anyhow!("Couldn't inherit value for `license` from workspace"))
+          })
+          .unwrap()
+      }),
       default_run: cargo_package_settings.default_run.clone(),
     };