From bc9aa873bfc16a0719fe523c18dd1dae100c7617 Mon Sep 17 00:00:00 2001 From: itowlson Date: Fri, 17 Nov 2023 10:33:25 +1300 Subject: [PATCH] Add manifest field for plugin settings Signed-off-by: itowlson --- crates/manifest/src/compat.rs | 2 ++ crates/manifest/src/schema/v2.rs | 41 +++++++++++++++++++++++++++ crates/manifest/tests/ui/maximal.json | 10 +++++++ crates/manifest/tests/ui/maximal.toml | 6 ++++ 4 files changed, 59 insertions(+) diff --git a/crates/manifest/src/compat.rs b/crates/manifest/src/compat.rs index fd453fa5ee..4cb12d698d 100644 --- a/crates/manifest/src/compat.rs +++ b/crates/manifest/src/compat.rs @@ -21,6 +21,7 @@ pub fn v1_to_v2_app(manifest: v1::AppManifestV1) -> Result Result]` #[serde(rename = "trigger", default, skip_serializing_if = "Map::is_empty")] pub trigger_global_configs: Map, + /// Settings for custom tools or plugins. Spin ignores this field. + #[serde(default, skip_serializing_if = "Map::is_empty")] + pub tool: Map, } /// Trigger configuration @@ -131,6 +134,9 @@ pub struct Component { /// Build configuration #[serde(default, skip_serializing_if = "Option::is_none")] pub build: Option, + /// Settings for custom tools or plugins. Spin ignores this field. + #[serde(default, skip_serializing_if = "Map::is_empty")] + pub tool: Map, } impl Component { @@ -224,6 +230,41 @@ mod tests { FakeTriggerConfig::deserialize(manifest.triggers["fake"][0].config.clone()).unwrap(); } + #[derive(Deserialize)] + #[allow(dead_code)] + struct FakeGlobalToolConfig { + lint_level: String, + } + + #[derive(Deserialize)] + #[allow(dead_code)] + struct FakeComponentToolConfig { + command: String, + } + + #[test] + fn deserialising_custom_tool_settings() { + let manifest = AppManifest::deserialize(toml! { + spin_manifest_version = 2 + [application] + name = "trigger-configs" + [application.tool.lint] + lint_level = "savage" + [[trigger.fake]] + something = "something else" + [component.fake] + source = "dummy" + [component.fake.tool.clean] + command = "cargo clean" + }) + .unwrap(); + + FakeGlobalToolConfig::deserialize(manifest.application.tool["lint"].clone()).unwrap(); + let fake_id: KebabId = "fake".to_owned().try_into().unwrap(); + FakeComponentToolConfig::deserialize(manifest.components[&fake_id].tool["clean"].clone()) + .unwrap(); + } + #[test] fn test_valid_snake_ids() { for valid in ["default", "mixed_CASE_words", "letters1_then2_numbers345"] { diff --git a/crates/manifest/tests/ui/maximal.json b/crates/manifest/tests/ui/maximal.json index 4780f693b1..1968f2d32f 100644 --- a/crates/manifest/tests/ui/maximal.json +++ b/crates/manifest/tests/ui/maximal.json @@ -12,6 +12,11 @@ "fake": { "global_option": true } + }, + "tool": { + "lint": { + "lint_level": "savage" + } } }, "variables": { @@ -77,6 +82,11 @@ "watch": [ "src/**/*.rs" ] + }, + "tool": { + "clean": { + "command": "cargo clean" + } } } } diff --git a/crates/manifest/tests/ui/maximal.toml b/crates/manifest/tests/ui/maximal.toml index dba5abb55c..0fd7c96b06 100644 --- a/crates/manifest/tests/ui/maximal.toml +++ b/crates/manifest/tests/ui/maximal.toml @@ -9,6 +9,9 @@ authors = ["alice@example.com", "bob@example.com"] [application.trigger.fake] global_option = true +[application.tool.lint] +lint_level = "savage" + [variables] var_one = { default = "Default" } var_TWO = { required = true, secret = true } @@ -38,3 +41,6 @@ ai_models = ["llama2-chat"] command = "cargo build" workdir = "my-component" watch = ["src/**/*.rs"] + +[component.maximal-component.tool.clean] +command = "cargo clean"