From 42e02e5a6ab5b718be184b3a92534bfe75f0519f Mon Sep 17 00:00:00 2001 From: Philippe Jalaber Date: Tue, 10 Dec 2024 13:50:28 +0100 Subject: [PATCH 1/5] Platform name freebsd supports --- src/lib/types.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/types.rs b/src/lib/types.rs index 9f4fe0a7..0e587233 100755 --- a/src/lib/types.rs +++ b/src/lib/types.rs @@ -22,6 +22,8 @@ pub fn get_platform_name() -> String { "windows".to_string() } else if cfg!(target_os = "macos") || cfg!(target_os = "ios") { "mac".to_string() + } else if cfg!(target_os = "freebsd") { + "freebsd".to_string() } else { "linux".to_string() } From 5c70aee14e2c04d75a97402f09319324539e0f2f Mon Sep 17 00:00:00 2001 From: Philippe Jalaber Date: Thu, 2 Jan 2025 14:37:26 +0100 Subject: [PATCH 2/5] Update docs with Freebsd platform --- README.md | 17 ++++++++++------- docs/_includes/content.md | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d5b5804a..ed7d4f98 100644 --- a/README.md +++ b/README.md @@ -446,12 +446,15 @@ It is also possible to define platform specific aliases, for example: linux_alias = "linux_my_task" windows_alias = "windows_my_task" mac_alias = "mac_my_task" +freebsd_alias = "freebsd_my_task" [tasks.linux_my_task] [tasks.mac_my_task] [tasks.windows_my_task] + +[tasks.freebsd_my_task] ``` If platform specific alias is found and matches current platform it will take precedence over the non platform alias definition.
@@ -468,7 +471,7 @@ script = "echo hello" [tasks.do_nothing] ``` -If you run task **my_task** on windows or mac, it will invoke the **do_nothing** task.
+If you run task **my_task** on windows, mac or freebsd, it will invoke the **do_nothing** task.
However, if executed on a linux platform, it will invoke the **run** task. *As a side note, cargo-make will attempt to invoke the task dependencies in the order that they were defined, unless they are defined also as sub dependencies.* @@ -532,7 +535,7 @@ args = ["running test-default"] [tasks.test-routing] run_task = [ { name = "test1", condition = { platforms = ["windows", "linux"], channels = ["beta", "stable"] } }, - { name = "test2", condition = { platforms = ["mac"], rust_version = { min = "1.20.0", max = "1.30.0" } } }, + { name = "test2", condition = { platforms = ["mac", "freebsd"], rust_version = { min = "1.20.0", max = "1.30.0" } } }, { name = "test3", condition_script = [ "somecommand" ] }, { name = "test-default" } ] @@ -1317,7 +1320,7 @@ The same process can be used to override tasks from other makefiles loaded using #### Platform Override -If you want to override a task (or specific attributes in a task) for specific platforms, you can define an override task with the platform name (currently Linux, Windows, and macOS) under the specific task.
+If you want to override a task (or specific attributes in a task) for specific platforms, you can define an override task with the platform name (currently Linux, Windows, macOS and FreeBSD) under the specific task.
For example: ```toml @@ -1369,7 +1372,7 @@ echo "Hello World From Linux" This means, however, that you will have to redefine all attributes in the override task that you want to carry with you from the parent task.
**Important: alias comes before checking override task, so if the parent task has an alias, it will be redirected to that task instead of the override.**
-**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias attributes.**
+**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias, freebsd_alias attributes.**
**In addition, aliases cannot be defined in platform override tasks, only in parent tasks.** @@ -1837,7 +1840,7 @@ The task runner will evaluate any condition defined and a task definition may co The condition attribute may define multiple parameters to validate.
All defined parameters must be valid for the condition as a whole to be true and enable the task to run. -Below is an example of a condition definition that checks that we are running on Windows or Linux (but not macOS) and that we are running on beta or nightly (but not stable): +Below is an example of a condition definition that checks that we are running on Windows or Linux (but neither macOS nor FreeBSD) and that we are running on beta or nightly (but not stable): ```toml [tasks.test-condition] @@ -1851,7 +1854,7 @@ The following condition types are available: * **profile** - See [profiles](#usage-profiles) for more info * **os** - List of OS names (Windows, macOS, iOS, Linux, Android, etc... as defined by cfg!(target_os)) -* **platforms** - List of platform names (windows, linux, mac) +* **platforms** - List of platform names (windows, linux, mac, freebsd) * **channels** - List of rust channels (stable, beta, nightly) * **env_set** - List of environment variables that must be defined * **env_not_set** - List of environment variables that must not be defined @@ -2092,7 +2095,7 @@ install_crate = { rustup_component_name = "rust-src" } Native dependencies can also be installed, however it is up to the Makefile author to write the script which checks the dependency exists and if not, to install it correctly.
This is done by setting up an installation script in the **install_script** attribute of the task.
-It is possible to use platform overrides to specify different installation scripts for Linux/macOS/Windows platforms.
+It is possible to use platform overrides to specify different installation scripts for Linux/macOS/FreeBSD/Windows platforms.
For example: ```toml diff --git a/docs/_includes/content.md b/docs/_includes/content.md index 352ac455..de936fc2 100755 --- a/docs/_includes/content.md +++ b/docs/_includes/content.md @@ -308,12 +308,15 @@ It is also possible to define platform specific aliases, for example: linux_alias = "linux_my_task" windows_alias = "windows_my_task" mac_alias = "mac_my_task" +freebsd_alias = "freebsd_my_task" [tasks.linux_my_task] [tasks.mac_my_task] [tasks.windows_my_task] + +[tasks.freebsd_my_task] ``` If platform specific alias is found and matches current platform it will take precedence over the non platform alias definition.
@@ -330,7 +333,7 @@ script = "echo hello" [tasks.do_nothing] ``` -If you run task **my_task** on windows or mac, it will invoke the **do_nothing** task.
+If you run task **my_task** on windows, mac or freebsd, it will invoke the **do_nothing** task.
However, if executed on a linux platform, it will invoke the **run** task. *As a side note, cargo-make will attempt to invoke the task dependencies in the order that they were defined, unless they are defined also as sub dependencies.* @@ -394,7 +397,7 @@ args = ["running test-default"] [tasks.test-routing] run_task = [ { name = "test1", condition = { platforms = ["windows", "linux"], channels = ["beta", "stable"] } }, - { name = "test2", condition = { platforms = ["mac"], rust_version = { min = "1.20.0", max = "1.30.0" } } }, + { name = "test2", condition = { platforms = ["mac", "freebsd"], rust_version = { min = "1.20.0", max = "1.30.0" } } }, { name = "test3", condition_script = [ "somecommand" ] }, { name = "test-default" } ] @@ -1179,7 +1182,7 @@ The same process can be used to override tasks from other makefiles loaded using #### Platform Override -If you want to override a task (or specific attributes in a task) for specific platforms, you can define an override task with the platform name (currently Linux, Windows, and macOS) under the specific task.
+If you want to override a task (or specific attributes in a task) for specific platforms, you can define an override task with the platform name (currently Linux, Windows, macOS and FreeBSD) under the specific task.
For example: ```toml @@ -1231,7 +1234,7 @@ echo "Hello World From Linux" This means, however, that you will have to redefine all attributes in the override task that you want to carry with you from the parent task.
**Important: alias comes before checking override task, so if the parent task has an alias, it will be redirected to that task instead of the override.**
-**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias attributes.**
+**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias, freebsd_alias attributes.**
**In addition, aliases cannot be defined in platform override tasks, only in parent tasks.** @@ -1699,7 +1702,7 @@ The task runner will evaluate any condition defined and a task definition may co The condition attribute may define multiple parameters to validate.
All defined parameters must be valid for the condition as a whole to be true and enable the task to run. -Below is an example of a condition definition that checks that we are running on Windows or Linux (but not macOS) and that we are running on beta or nightly (but not stable): +Below is an example of a condition definition that checks that we are running on Windows or Linux (but neither macOS nor FreeBSD) and that we are running on beta or nightly (but not stable): ```toml [tasks.test-condition] @@ -1713,7 +1716,7 @@ The following condition types are available: * **profile** - See [profiles](#usage-profiles) for more info * **os** - List of OS names (Windows, macOS, iOS, Linux, Android, etc... as defined by cfg!(target_os)) -* **platforms** - List of platform names (windows, linux, mac) +* **platforms** - List of platform names (windows, linux, mac, freebsd) * **channels** - List of rust channels (stable, beta, nightly) * **env_set** - List of environment variables that must be defined * **env_not_set** - List of environment variables that must not be defined @@ -1954,7 +1957,7 @@ install_crate = { rustup_component_name = "rust-src" } Native dependencies can also be installed, however it is up to the Makefile author to write the script which checks the dependency exists and if not, to install it correctly.
This is done by setting up an installation script in the **install_script** attribute of the task.
-It is possible to use platform overrides to specify different installation scripts for Linux/macOS/Windows platforms.
+It is possible to use platform overrides to specify different installation scripts for Linux/macOS/FreeBSD/Windows platforms.
For example: ```toml From 5c3a5f0ea64c4b2e63633fad2fb0dca5c1a7ac81 Mon Sep 17 00:00:00 2001 From: Philippe Jalaber Date: Thu, 2 Jan 2025 15:52:07 +0100 Subject: [PATCH 3/5] Update Task struct for FreeBSD support --- src/lib/execution_plan_test.rs | 2 + src/lib/plugin/runner_test.rs | 2 + src/lib/types.rs | 24 ++++ src/lib/types_test.rs | 194 +++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+) diff --git a/src/lib/execution_plan_test.rs b/src/lib/execution_plan_test.rs index f68c5bbc..7d4a3e2f 100644 --- a/src/lib/execution_plan_test.rs +++ b/src/lib/execution_plan_test.rs @@ -125,6 +125,8 @@ fn get_actual_task_name_platform_alias() { task.windows_alias = Some("test2".to_string()); } else if cfg!(target_os = "macos") || cfg!(target_os = "ios") { task.mac_alias = Some("test2".to_string()); + } else if cfg!(target_os = "freebsd") { + task.freebsd_alias = Some("test2".to_string()); } else { task.linux_alias = Some("test2".to_string()); }; diff --git a/src/lib/plugin/runner_test.rs b/src/lib/plugin/runner_test.rs index 7d5dc690..0b8468bf 100644 --- a/src/lib/plugin/runner_test.rs +++ b/src/lib/plugin/runner_test.rs @@ -484,6 +484,7 @@ fn run_task_invoked_valid() { linux_alias: Some("linux".to_string()), windows_alias: Some("windows".to_string()), mac_alias: Some("mac".to_string()), + freebsd_alias: Some("freebsd".to_string()), install_script: Some(ScriptValue::Text(vec!["i1".to_string(), "i2".to_string()])), args: Some(vec!["a1".to_string(), "a2".to_string()]), script: Some(ScriptValue::Text(vec![ @@ -500,6 +501,7 @@ fn run_task_invoked_valid() { linux: None, windows: None, mac: None, + freebsd: None, }; let mut flow_info = create_empty_flow_info(); diff --git a/src/lib/types.rs b/src/lib/types.rs index 0e587233..1cfcf1a4 100755 --- a/src/lib/types.rs +++ b/src/lib/types.rs @@ -1155,6 +1155,8 @@ pub struct Task { pub windows_alias: Option, /// acts like alias if runtime OS is Mac (takes precedence over alias) pub mac_alias: Option, + /// acts like alias if runtime OS is FreeBSD (takes precedence over alias) + pub freebsd_alias: Option, /// if defined, the provided crate will be installed (if needed) before running the task pub install_crate: Option, /// additional cargo install arguments @@ -1185,6 +1187,8 @@ pub struct Task { pub windows: Option, /// override task if runtime OS is Mac (takes precedence over alias) pub mac: Option, + /// override task if runtime OS is FreeBSD (takes precedence over alias) + pub freebsd: Option, } /// A toolchain, defined either as a string (following the rustup syntax) @@ -1385,6 +1389,13 @@ impl Task { )); } + if self.freebsd_alias.is_some() { + self.freebsd_alias = Some(get_namespaced_task_name( + namespace, + &self.freebsd_alias.clone().unwrap(), + )); + } + if self.run_task.is_some() { let mut run_task = self.run_task.clone().unwrap(); @@ -1597,6 +1608,12 @@ impl Task { self.mac_alias = None; } + if task.freebsd_alias.is_some() { + self.freebsd_alias = task.freebsd_alias.clone(); + } else if override_values { + self.freebsd_alias = None; + } + if task.install_crate.is_some() { self.install_crate = task.install_crate.clone(); } else if override_values { @@ -1756,6 +1773,7 @@ impl Task { linux_alias: None, windows_alias: None, mac_alias: None, + freebsd_alias: None, install_crate: override_task.install_crate.clone(), install_crate_args: override_task.install_crate_args.clone(), install_script: override_task.install_script.clone(), @@ -1771,6 +1789,7 @@ impl Task { linux: None, windows: None, mac: None, + freebsd: None, } } None => self.clone(), @@ -1789,6 +1808,11 @@ impl Task { Some(ref value) => Some(value), _ => None, } + } else if cfg!(target_os = "freebsd") { + match self.freebsd_alias { + Some(ref value) => Some(value), + _ => None, + } } else { match self.linux_alias { Some(ref value) => Some(value), diff --git a/src/lib/types_test.rs b/src/lib/types_test.rs index 33f2252c..0ddfbf52 100755 --- a/src/lib/types_test.rs +++ b/src/lib/types_test.rs @@ -1719,6 +1719,7 @@ fn task_new() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.install_script.is_none()); assert!(task.args.is_none()); assert!(task.script.is_none()); @@ -1824,6 +1825,7 @@ fn task_extend_both_have_misc_data() { linux_alias: None, windows_alias: None, mac_alias: None, + freebsd_alias: None, install_crate_args: None, install_script: None, args: None, @@ -1837,6 +1839,7 @@ fn task_extend_both_have_misc_data() { linux: None, windows: None, mac: None, + freebsd: None, }; base.extend(&extended); @@ -1865,6 +1868,7 @@ fn task_extend_both_have_misc_data() { assert!(base.linux_alias.is_none()); assert!(base.windows_alias.is_none()); assert!(base.mac_alias.is_none()); + assert!(base.freebsd_alias.is_none()); assert!(base.install_crate_args.is_none()); assert!(base.install_script.is_none()); assert!(base.script_runner.is_none()); @@ -1926,6 +1930,7 @@ fn task_extend_extended_have_all_fields() { linux_alias: None, windows_alias: None, mac_alias: None, + freebsd_alias: None, install_crate_args: None, install_script: None, args: None, @@ -1939,6 +1944,7 @@ fn task_extend_extended_have_all_fields() { linux: None, windows: None, mac: None, + freebsd: None, }; let mut env = IndexMap::new(); @@ -1986,6 +1992,7 @@ fn task_extend_extended_have_all_fields() { linux_alias: Some("linux".to_string()), windows_alias: Some("windows".to_string()), mac_alias: Some("mac".to_string()), + freebsd_alias: Some("freebsd".to_string()), install_script: Some(ScriptValue::Text(vec!["i1".to_string(), "i2".to_string()])), args: Some(vec!["a1".to_string(), "a2".to_string()]), script: Some(ScriptValue::Text(vec![ @@ -2149,6 +2156,56 @@ fn task_extend_extended_have_all_fields() { dependencies: Some(vec!["A".into()]), toolchain: Some("toolchain".into()), }), + freebsd: Some(PlatformOverrideTask { + clear: None, + install_crate: Some(InstallCrate::Value("my crate2".to_string())), + install_crate_args: Some(vec!["c1".to_string(), "c2".to_string()]), + command: Some("test2".to_string()), + disabled: Some(true), + private: Some(false), + deprecated: Some(DeprecationInfo::Boolean(false)), + extend: Some("extended".to_string()), + plugin: Some("plugin".to_string()), + watch: Some(TaskWatchOptions::Boolean(false)), + condition: Some(TaskCondition { + condition_type: None, + fail_message: None, + profiles: Some(vec!["development".to_string()]), + os: Some(vec!["os1".to_string(), "os2".to_string()]), + platforms: Some(vec!["linux".to_string(), "mac".to_string()]), + channels: Some(vec!["nightly".to_string(), "stable".to_string()]), + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }), + condition_script: Some(ConditionScriptValue::Text(vec!["exit 0".to_string()])), + condition_script_runner_args: Some(vec!["csr_a1".to_string(), "csr_a2".to_string()]), + ignore_errors: Some(true), + force: Some(true), + env_files: Some(vec![EnvFile::Path("extended".to_string())]), + env: Some(env.clone()), + cwd: Some("cwd".to_string()), + install_script: Some(ScriptValue::Text(vec!["i1".to_string(), "i2".to_string()])), + args: Some(vec!["a1".to_string(), "a2".to_string()]), + script: Some(ScriptValue::Text(vec![ + "1".to_string(), + "2".to_string(), + "3".to_string(), + ])), + script_runner: Some("sh3".to_string()), + script_runner_args: Some(vec!["sr_a1".to_string(), "sr_a2".to_string()]), + script_extension: Some("ext3".to_string()), + run_task: Some(RunTaskInfo::Name("task3".to_string())), + dependencies: Some(vec!["A".into()]), + toolchain: Some("toolchain".into()), + }), }; base.extend(&extended); @@ -2178,6 +2235,7 @@ fn task_extend_extended_have_all_fields() { assert!(base.linux_alias.is_some()); assert!(base.windows_alias.is_some()); assert!(base.mac_alias.is_some()); + assert!(base.freebsd_alias.is_some()); assert!(base.install_script.is_some()); assert!(base.args.is_some()); assert!(base.script.is_some()); @@ -2222,6 +2280,7 @@ fn task_extend_extended_have_all_fields() { assert_eq!(base.linux_alias.unwrap(), "linux"); assert_eq!(base.windows_alias.unwrap(), "windows"); assert_eq!(base.mac_alias.unwrap(), "mac"); + assert_eq!(base.freebsd_alias.unwrap(), "freebsd"); assert_eq!(get_script_as_vec(base.install_script).len(), 2); assert_eq!(base.args.unwrap().len(), 2); assert_eq!(base.script_runner.unwrap(), "sh2"); @@ -2290,6 +2349,7 @@ fn task_extend_clear_with_no_data() { linux_alias: Some("linux".to_string()), windows_alias: Some("windows".to_string()), mac_alias: Some("mac".to_string()), + freebsd_alias: Some("freebsd".to_string()), install_script: Some(ScriptValue::Text(vec!["i1".to_string(), "i2".to_string()])), args: Some(vec!["a1".to_string(), "a2".to_string()]), script: Some(ScriptValue::Text(vec![ @@ -2453,6 +2513,56 @@ fn task_extend_clear_with_no_data() { dependencies: Some(vec!["A".into()]), toolchain: Some("toolchain".into()), }), + freebsd: Some(PlatformOverrideTask { + clear: None, + install_crate: Some(InstallCrate::Value("my crate2".to_string())), + install_crate_args: Some(vec!["c1".to_string(), "c2".to_string()]), + command: Some("test2".to_string()), + disabled: Some(true), + private: Some(false), + deprecated: Some(DeprecationInfo::Boolean(true)), + extend: Some("base".to_string()), + plugin: Some("base".to_string()), + watch: Some(TaskWatchOptions::Boolean(false)), + condition: Some(TaskCondition { + condition_type: None, + fail_message: None, + profiles: Some(vec!["development".to_string()]), + os: Some(vec!["os1".to_string(), "os2".to_string()]), + platforms: Some(vec!["linux".to_string(), "mac".to_string()]), + channels: Some(vec!["nightly".to_string(), "stable".to_string()]), + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }), + condition_script: Some(ConditionScriptValue::Text(vec!["exit 0".to_string()])), + condition_script_runner_args: Some(vec!["csr_a1".to_string(), "csr_a2".to_string()]), + ignore_errors: Some(true), + force: Some(true), + env_files: Some(vec![]), + env: Some(env.clone()), + cwd: Some("cwd".to_string()), + install_script: Some(ScriptValue::Text(vec!["i1".to_string(), "i2".to_string()])), + args: Some(vec!["a1".to_string(), "a2".to_string()]), + script: Some(ScriptValue::Text(vec![ + "1".to_string(), + "2".to_string(), + "3".to_string(), + ])), + script_runner: Some("sh3".to_string()), + script_runner_args: Some(vec!["sr_a1".to_string(), "sr_a2".to_string()]), + script_extension: Some("ext3".to_string()), + run_task: Some(RunTaskInfo::Name("task3".to_string())), + dependencies: Some(vec!["A".into()]), + toolchain: Some("toolchain".into()), + }), }; let mut extended = Task::new(); @@ -2484,6 +2594,7 @@ fn task_extend_clear_with_no_data() { assert!(base.linux_alias.is_none()); assert!(base.windows_alias.is_none()); assert!(base.mac_alias.is_none()); + assert!(base.freebsd_alias.is_none()); assert!(base.install_crate_args.is_none()); assert!(base.install_script.is_none()); assert!(base.script_runner.is_none()); @@ -2547,6 +2658,7 @@ fn task_extend_clear_with_all_data() { linux_alias: Some("linux".to_string()), windows_alias: Some("windows".to_string()), mac_alias: Some("mac".to_string()), + freebsd_alias: Some("freebsd".to_string()), install_script: Some(ScriptValue::Text(vec!["i1".to_string(), "i2".to_string()])), args: Some(vec!["a1".to_string(), "a2".to_string()]), script: Some(ScriptValue::Text(vec![ @@ -2710,6 +2822,56 @@ fn task_extend_clear_with_all_data() { dependencies: Some(vec!["A".into()]), toolchain: Some("toolchain".into()), }), + freebsd: Some(PlatformOverrideTask { + clear: None, + install_crate: Some(InstallCrate::Value("my crate2".to_string())), + install_crate_args: Some(vec!["c1".to_string(), "c2".to_string()]), + command: Some("test2".to_string()), + disabled: Some(true), + private: Some(false), + deprecated: Some(DeprecationInfo::Boolean(true)), + extend: Some("base".to_string()), + plugin: Some("plugin".to_string()), + watch: Some(TaskWatchOptions::Boolean(false)), + condition: Some(TaskCondition { + condition_type: None, + fail_message: None, + profiles: Some(vec!["development".to_string()]), + os: Some(vec!["os1".to_string(), "os2".to_string()]), + platforms: Some(vec!["linux".to_string(), "mac".to_string()]), + channels: Some(vec!["nightly".to_string(), "stable".to_string()]), + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }), + condition_script: Some(ConditionScriptValue::Text(vec!["exit 0".to_string()])), + condition_script_runner_args: Some(vec!["csr_a1".to_string(), "csr_a2".to_string()]), + ignore_errors: Some(true), + force: Some(true), + env_files: Some(vec![]), + env: Some(env.clone()), + cwd: Some("cwd".to_string()), + install_script: Some(ScriptValue::Text(vec!["i1".to_string(), "i2".to_string()])), + args: Some(vec!["a1".to_string(), "a2".to_string()]), + script: Some(ScriptValue::Text(vec![ + "1".to_string(), + "2".to_string(), + "3".to_string(), + ])), + script_runner: Some("sh3".to_string()), + script_runner_args: Some(vec!["sr_a1".to_string(), "sr_a2".to_string()]), + script_extension: Some("ext3".to_string()), + run_task: Some(RunTaskInfo::Name("task3".to_string())), + dependencies: Some(vec!["A".into()]), + toolchain: Some("toolchain".into()), + }), }; base.extend(&extended); @@ -2738,6 +2900,7 @@ fn task_extend_clear_with_all_data() { assert!(base.linux_alias.is_some()); assert!(base.windows_alias.is_some()); assert!(base.mac_alias.is_some()); + assert!(base.freebsd_alias.is_some()); assert!(base.install_crate_args.is_some()); assert!(base.install_script.is_some()); assert!(base.script_runner.is_some()); @@ -2777,6 +2940,7 @@ fn task_get_alias_platform_defined() { task.linux_alias = Some("linux".to_string()); task.windows_alias = Some("windows".to_string()); task.mac_alias = Some("mac".to_string()); + task.freebsd_alias = Some("freebsd".to_string()); let alias = task.get_alias(); if cfg!(windows) { @@ -2796,6 +2960,7 @@ fn task_get_normalized_task_undefined() { linux_alias: Some("linux".to_string()), windows_alias: Some("windows".to_string()), mac_alias: Some("mac".to_string()), + freebsd_alias: Some("freebsd".to_string()), install_crate: Some(InstallCrate::Value("install_crate".to_string())), install_crate_args: None, command: Some("command".to_string()), @@ -2832,6 +2997,7 @@ fn task_get_normalized_task_undefined() { linux: None, windows: None, mac: None, + freebsd: None, }; let normalized_task = task.get_normalized_task(); @@ -2857,6 +3023,7 @@ fn task_get_normalized_task_undefined() { assert!(normalized_task.linux_alias.is_some()); assert!(normalized_task.windows_alias.is_some()); assert!(normalized_task.mac_alias.is_some()); + assert!(normalized_task.freebsd_alias.is_some()); assert!(normalized_task.install_script.is_some()); assert!(normalized_task.args.is_some()); assert!(normalized_task.script.is_some()); @@ -2901,6 +3068,7 @@ fn task_get_normalized_task_undefined() { assert_eq!(normalized_task.linux_alias.unwrap(), "linux"); assert_eq!(normalized_task.windows_alias.unwrap(), "windows"); assert_eq!(normalized_task.mac_alias.unwrap(), "mac"); + assert_eq!(normalized_task.freebsd_alias.unwrap(), "freebsd"); assert_eq!(get_script_as_vec(normalized_task.install_script).len(), 3); assert_eq!(normalized_task.args.unwrap().len(), 2); assert_eq!(normalized_task.script_runner.unwrap(), "sh1"); @@ -2927,6 +3095,7 @@ fn task_get_normalized_task_with_override_no_clear() { linux_alias: Some("bad".to_string()), windows_alias: Some("bad".to_string()), mac_alias: Some("bad".to_string()), + freebsd_alias: Some("bad".to_string()), install_crate: Some(InstallCrate::Value("install_crate".to_string())), install_crate_args: Some(vec!["c1".to_string(), "c2".to_string()]), command: Some("command".to_string()), @@ -3042,6 +3211,7 @@ fn task_get_normalized_task_with_override_no_clear() { }), windows: None, mac: None, + freebsd: None, }; let normalized_task = task.get_normalized_task(); @@ -3071,6 +3241,7 @@ fn task_get_normalized_task_with_override_no_clear() { assert!(normalized_task.linux_alias.is_none()); assert!(normalized_task.windows_alias.is_none()); assert!(normalized_task.mac_alias.is_none()); + assert!(normalized_task.freebsd_alias.is_none()); assert!(normalized_task.install_script.is_some()); assert!(normalized_task.args.is_some()); assert!(normalized_task.script.is_some()); @@ -3151,6 +3322,7 @@ fn task_get_normalized_task_with_override_clear_false() { linux_alias: Some("bad".to_string()), windows_alias: Some("bad".to_string()), mac_alias: Some("bad".to_string()), + freebsd_alias: Some("bad".to_string()), install_crate: Some(InstallCrate::Value("install_crate".to_string())), install_crate_args: Some(vec!["c1".to_string(), "c2".to_string()]), command: Some("command".to_string()), @@ -3273,6 +3445,7 @@ fn task_get_normalized_task_with_override_clear_false() { }), windows: None, mac: None, + freebsd: None, }; let normalized_task = task.get_normalized_task(); @@ -3301,6 +3474,7 @@ fn task_get_normalized_task_with_override_clear_false() { assert!(normalized_task.linux_alias.is_none()); assert!(normalized_task.windows_alias.is_none()); assert!(normalized_task.mac_alias.is_none()); + assert!(normalized_task.freebsd_alias.is_none()); assert!(normalized_task.install_crate_args.is_some()); assert!(normalized_task.install_script.is_some()); assert!(normalized_task.args.is_some()); @@ -3379,6 +3553,7 @@ fn task_get_normalized_task_with_override_clear_false_partial_override() { linux_alias: Some("bad".to_string()), windows_alias: Some("bad".to_string()), mac_alias: Some("bad".to_string()), + freebsd_alias: Some("bad".to_string()), install_crate: Some(InstallCrate::Value("install_crate".to_string())), install_crate_args: Some(vec!["c1".to_string(), "c2".to_string()]), command: Some("command".to_string()), @@ -3460,6 +3635,7 @@ fn task_get_normalized_task_with_override_clear_false_partial_override() { }), windows: None, mac: None, + freebsd: None, }; let normalized_task = task.get_normalized_task(); @@ -3485,6 +3661,7 @@ fn task_get_normalized_task_with_override_clear_false_partial_override() { assert!(normalized_task.linux_alias.is_none()); assert!(normalized_task.windows_alias.is_none()); assert!(normalized_task.mac_alias.is_none()); + assert!(normalized_task.freebsd_alias.is_none()); assert!(normalized_task.install_script.is_some()); assert!(normalized_task.args.is_some()); assert!(normalized_task.script.is_some()); @@ -3552,6 +3729,7 @@ fn task_get_normalized_task_with_override_clear_true() { linux_alias: Some("bad".to_string()), windows_alias: Some("bad".to_string()), mac_alias: Some("bad".to_string()), + freebsd_alias: Some("bad".to_string()), install_crate: Some(InstallCrate::Value("install_crate".to_string())), install_crate_args: Some(vec!["c1".to_string(), "c2".to_string()]), command: Some("command".to_string()), @@ -3633,6 +3811,7 @@ fn task_get_normalized_task_with_override_clear_true() { }), windows: None, mac: None, + freebsd: None, }; let normalized_task = task.get_normalized_task(); @@ -3659,6 +3838,7 @@ fn task_get_normalized_task_with_override_clear_true() { assert!(normalized_task.linux_alias.is_none()); assert!(normalized_task.windows_alias.is_none()); assert!(normalized_task.mac_alias.is_none()); + assert!(normalized_task.freebsd_alias.is_none()); assert!(normalized_task.install_script.is_none()); assert!(normalized_task.args.is_none()); assert!(normalized_task.script.is_none()); @@ -4233,6 +4413,7 @@ fn task_apply_task_empty_modify_empty() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.run_task.is_none()); assert!(task.dependencies.is_none()); } @@ -4251,6 +4432,7 @@ fn task_apply_task_empty_modify_private() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.run_task.is_none()); assert!(task.dependencies.is_none()); } @@ -4269,6 +4451,7 @@ fn task_apply_task_empty_modify_not_private() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.run_task.is_none()); assert!(task.dependencies.is_none()); } @@ -4288,6 +4471,7 @@ fn task_apply_modify_empty() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.run_task.is_none()); assert!(task.dependencies.is_none()); } @@ -4307,6 +4491,7 @@ fn task_apply_modify_private() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.run_task.is_none()); assert!(task.dependencies.is_none()); } @@ -4326,6 +4511,7 @@ fn task_apply_modify_not_private() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.run_task.is_none()); assert!(task.dependencies.is_none()); } @@ -4344,6 +4530,7 @@ fn task_apply_task_empty_modify_namespace() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); assert!(task.run_task.is_none()); assert!(task.dependencies.is_none()); } @@ -4360,6 +4547,7 @@ fn task_apply_no_run_task_modify_namespace() { task.linux_alias = Some("linux_alias".to_string()); task.windows_alias = Some("windows_alias".to_string()); task.mac_alias = Some("mac_alias".to_string()); + task.freebsd_alias = Some("freebsd_alias".to_string()); task.dependencies = Some(vec!["dep1".into(), "dep2".into()]); task.apply(&modify_config); @@ -4369,6 +4557,7 @@ fn task_apply_no_run_task_modify_namespace() { assert_eq!(task.linux_alias.unwrap(), "default::linux_alias"); assert_eq!(task.windows_alias.unwrap(), "default::windows_alias"); assert_eq!(task.mac_alias.unwrap(), "default::mac_alias"); + assert_eq!(task.freebsd_alias.unwrap(), "default::freebsd_alias"); assert!(task.run_task.is_none()); let expected: Vec = vec!["default::dep1".into(), "default::dep2".into()]; @@ -4392,6 +4581,7 @@ fn task_apply_run_task_name_modify_namespace() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); let run_task_name = match task.run_task.unwrap() { RunTaskInfo::Name(name) => name, _ => panic!("Invalid run task value."), @@ -4422,6 +4612,7 @@ fn task_apply_run_task_details_single_modify_namespace() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); let details = match task.run_task.unwrap() { RunTaskInfo::Details(ref mut details) => details.clone(), _ => panic!("Invalid run task value."), @@ -4455,6 +4646,7 @@ fn task_apply_run_task_details_multiple_modify_namespace() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); let details = match task.run_task.unwrap() { RunTaskInfo::Details(ref mut details) => details.clone(), _ => panic!("Invalid run task value."), @@ -4494,6 +4686,7 @@ fn task_apply_run_task_routing_info_single_modify_namespace() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); let routing_info = match task.run_task.unwrap() { RunTaskInfo::Routing(ref mut info) => info.pop(), _ => panic!("Invalid run task value."), @@ -4530,6 +4723,7 @@ fn task_apply_run_task_routing_info_multiple_modify_namespace() { assert!(task.linux_alias.is_none()); assert!(task.windows_alias.is_none()); assert!(task.mac_alias.is_none()); + assert!(task.freebsd_alias.is_none()); let routing_info = match task.run_task.unwrap() { RunTaskInfo::Routing(ref mut info) => info.pop(), _ => panic!("Invalid run task value."), From 3f56e40a5105cea936c17d07abddf317a14f7d48 Mon Sep 17 00:00:00 2001 From: Philippe Jalaber Date: Thu, 2 Jan 2025 17:30:09 +0100 Subject: [PATCH 4/5] Make all tests pass on FreeBSD --- src/lib/descriptor/makefiles/mod_test.rs | 2 ++ .../descriptor/makefiles/rust-coverage.toml | 1 + src/lib/types.rs | 15 +++++++++++ src/lib/types_test.rs | 25 +++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/src/lib/descriptor/makefiles/mod_test.rs b/src/lib/descriptor/makefiles/mod_test.rs index 7edd059a..6c596c1e 100644 --- a/src/lib/descriptor/makefiles/mod_test.rs +++ b/src/lib/descriptor/makefiles/mod_test.rs @@ -51,6 +51,8 @@ fn makefile_task_condition_test(name: &str, expect_enabled: bool, linux_only: bo config: task, }; + println!("flow_info={flow_info:?}"); + println!("step={step:?}"); let enabled = condition::validate_condition_for_step(&flow_info, &step).unwrap(); let should_be_enabled = if expect_enabled { diff --git a/src/lib/descriptor/makefiles/rust-coverage.toml b/src/lib/descriptor/makefiles/rust-coverage.toml index 41d19603..b477436c 100644 --- a/src/lib/descriptor/makefiles/rust-coverage.toml +++ b/src/lib/descriptor/makefiles/rust-coverage.toml @@ -212,6 +212,7 @@ condition = { env_not_set = [ ], platforms = [ "linux", "mac", + "freebsd", ] } script_runner = "bash" script = ''' diff --git a/src/lib/types.rs b/src/lib/types.rs index 1cfcf1a4..cdc226cd 100755 --- a/src/lib/types.rs +++ b/src/lib/types.rs @@ -2213,6 +2213,8 @@ pub struct ConfigSection { pub windows_load_script: Option, /// acts like load_script if runtime OS is Mac (takes precedence over load_script) pub mac_load_script: Option, + /// acts like load_script if runtime OS is FreeBSD (takes precedence over load_script) + pub freebsd_load_script: Option, /// Enables unstable cargo-make features pub unstable_features: Option>, } @@ -2359,6 +2361,13 @@ impl ConfigSection { ); } + if extended.freebsd_load_script.is_some() { + self.freebsd_load_script = extend_script_value( + self.freebsd_load_script.clone(), + extended.freebsd_load_script.clone(), + ); + } + if let Some(extended_unstable_features) = extended.unstable_features.clone() { if let Some(unstable_features) = &mut self.unstable_features { unstable_features.extend(extended_unstable_features); @@ -2384,6 +2393,12 @@ impl ConfigSection { } else { self.load_script.clone() } + } else if platform_name == "freebsd" { + if self.freebsd_load_script.is_some() { + self.freebsd_load_script.clone() + } else { + self.load_script.clone() + } } else { if self.linux_load_script.is_some() { self.linux_load_script.clone() diff --git a/src/lib/types_test.rs b/src/lib/types_test.rs index 0ddfbf52..9e5e1074 100755 --- a/src/lib/types_test.rs +++ b/src/lib/types_test.rs @@ -1732,6 +1732,7 @@ fn task_new() { assert!(task.linux.is_none()); assert!(task.windows.is_none()); assert!(task.mac.is_none()); + assert!(task.freebsd.is_none()); } #[test] @@ -1882,6 +1883,7 @@ fn task_extend_both_have_misc_data() { assert!(base.linux.is_none()); assert!(base.windows.is_none()); assert!(base.mac.is_none()); + assert!(base.freebsd.is_none()); assert_eq!(get_script_vec(&base).len(), 2); assert_eq!( @@ -2947,6 +2949,8 @@ fn task_get_alias_platform_defined() { assert_eq!(alias.unwrap(), "windows"); } else if cfg!(target_os = "macos") || cfg!(target_os = "ios") { assert_eq!(alias.unwrap(), "mac"); + } else if cfg!(target_os = "freebsd") { + assert_eq!(alias.unwrap(), "freebsd"); } else { assert_eq!(alias.unwrap(), "linux"); }; @@ -4085,6 +4089,7 @@ fn config_section_new() { assert!(config.linux_load_script.is_none()); assert!(config.windows_load_script.is_none()); assert!(config.mac_load_script.is_none()); + assert!(config.freebsd_load_script.is_none()); } #[test] @@ -4124,6 +4129,10 @@ fn config_section_extend_all_values() { "mac".to_string(), "base_info".to_string(), ])); + base.freebsd_load_script = Some(ScriptValue::Text(vec![ + "freebsd".to_string(), + "base_info".to_string(), + ])); extended.skip_core_tasks = Some(false); extended.modify_core_tasks = Some(ModifyConfig { @@ -4152,6 +4161,7 @@ fn config_section_extend_all_values() { extended.linux_load_script = Some(ScriptValue::Text(vec!["extended_info".to_string()])); extended.windows_load_script = Some(ScriptValue::Text(vec!["extended_info".to_string()])); extended.mac_load_script = Some(ScriptValue::Text(vec!["extended_info".to_string()])); + extended.freebsd_load_script = Some(ScriptValue::Text(vec!["extended_info".to_string()])); base.extend(&mut extended); @@ -4183,6 +4193,8 @@ fn config_section_extend_all_values() { assert_eq!(get_script_as_vec(base.linux_load_script).len(), 1); assert_eq!(get_script_as_vec(base.windows_load_script).len(), 1); assert_eq!(get_script_as_vec(base.mac_load_script).len(), 1); + println!("{:?}", base.freebsd_load_script); + assert_eq!(get_script_as_vec(base.freebsd_load_script).len(), 1); } #[test] @@ -4226,6 +4238,11 @@ fn config_section_extend_no_values() { "base_info".to_string(), ])); + base.freebsd_load_script = Some(ScriptValue::Text(vec![ + "freebsd".to_string(), + "base_info".to_string(), + ])); + base.extend(&mut extended); assert!(base.skip_core_tasks.unwrap()); @@ -4256,6 +4273,7 @@ fn config_section_extend_no_values() { assert_eq!(get_script_as_vec(base.linux_load_script).len(), 2); assert_eq!(get_script_as_vec(base.windows_load_script).len(), 2); assert_eq!(get_script_as_vec(base.mac_load_script).len(), 2); + assert_eq!(get_script_as_vec(base.freebsd_load_script).len(), 2); } #[test] @@ -4298,6 +4316,10 @@ fn config_section_extend_some_values() { "mac".to_string(), "base_info".to_string(), ])); + base.freebsd_load_script = Some(ScriptValue::Text(vec![ + "freebsd".to_string(), + "base_info".to_string(), + ])); extended.skip_core_tasks = Some(false); extended.init_task = Some("extended_init".to_string()); @@ -4332,6 +4354,7 @@ fn config_section_extend_some_values() { assert_eq!(get_script_as_vec(base.linux_load_script).len(), 2); assert_eq!(get_script_as_vec(base.windows_load_script).len(), 2); assert_eq!(get_script_as_vec(base.mac_load_script).len(), 2); + assert_eq!(get_script_as_vec(base.freebsd_load_script).len(), 2); } #[test] @@ -4357,6 +4380,7 @@ fn config_section_get_get_load_script_platform_some() { config.linux_load_script = Some(ScriptValue::Text(vec!["exit 0".to_string()])); config.windows_load_script = Some(ScriptValue::Text(vec!["exit 0".to_string()])); config.mac_load_script = Some(ScriptValue::Text(vec!["exit 0".to_string()])); + config.freebsd_load_script = Some(ScriptValue::Text(vec!["exit 0".to_string()])); let load_script = config.get_load_script(); assert!(load_script.is_some()); @@ -4369,6 +4393,7 @@ fn config_section_get_get_load_script_all_defined() { config.linux_load_script = Some(ScriptValue::Text(vec!["linux".to_string()])); config.windows_load_script = Some(ScriptValue::Text(vec!["windows".to_string()])); config.mac_load_script = Some(ScriptValue::Text(vec!["mac".to_string()])); + config.freebsd_load_script = Some(ScriptValue::Text(vec!["freebsd".to_string()])); let load_script = config.get_load_script(); assert!(load_script.is_some()); From 191889a7e5f118c563961cf2d987f5710dacc613 Mon Sep 17 00:00:00 2001 From: Philippe Jalaber Date: Fri, 3 Jan 2025 11:17:06 +0100 Subject: [PATCH 5/5] Fix FreeBSD platform override --- src/lib/execution_plan_test.rs | 30 ++++++++++++++++++++++++++++++ src/lib/types.rs | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/src/lib/execution_plan_test.rs b/src/lib/execution_plan_test.rs index 7d4a3e2f..1a603917 100644 --- a/src/lib/execution_plan_test.rs +++ b/src/lib/execution_plan_test.rs @@ -1307,6 +1307,35 @@ fn create_platform_disabled() { dependencies: None, toolchain: None, }); + task.freebsd = Some(PlatformOverrideTask { + clear: Some(true), + disabled: Some(true), + private: Some(false), + deprecated: None, + extend: None, + plugin: None, + watch: Some(TaskWatchOptions::Boolean(false)), + condition: None, + condition_script: None, + condition_script_runner_args: None, + install_crate: None, + install_crate_args: None, + command: None, + ignore_errors: None, + force: None, + env_files: None, + env: None, + cwd: None, + install_script: None, + args: None, + script: None, + script_runner: None, + script_runner_args: None, + script_extension: None, + run_task: None, + dependencies: None, + toolchain: None, + }); config.tasks.insert("test".to_string(), task); @@ -1559,6 +1588,7 @@ fn get_normalized_task_multi_extend() { task2.linux = Some(platform_task.clone()); task2.mac = Some(platform_task.clone()); task2.windows = Some(platform_task.clone()); + task2.freebsd = Some(platform_task.clone()); let mut task3 = Task::new(); task3.extend = Some("2".to_string()); diff --git a/src/lib/types.rs b/src/lib/types.rs index cdc226cd..061dd337 100755 --- a/src/lib/types.rs +++ b/src/lib/types.rs @@ -1734,6 +1734,11 @@ impl Task { Some(ref value) => Some(value.clone()), _ => None, } + } else if platform_name == "freebsd" { + match self.freebsd { + Some(ref value) => Some(value.clone()), + _ => None, + } } else { match self.linux { Some(ref value) => Some(value.clone()),