Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>
Expand All @@ -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.<br>
If you run task **my_task** on windows, mac or freebsd, it will invoke the **do_nothing** task.<br>
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.*
Expand Down Expand Up @@ -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" }
]
Expand Down Expand Up @@ -1317,7 +1320,7 @@ The same process can be used to override tasks from other makefiles loaded using

<a name="usage-platform-override"></a>
#### 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.<br>
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.<br>
For example:

```toml
Expand Down Expand Up @@ -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.<br>
**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.**<br>
**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias attributes.**<br>
**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias, freebsd_alias attributes.**<br>
**In addition, aliases cannot be defined in platform override tasks, only in parent tasks.**

<a name="usage-task-extend-attribute"></a>
Expand Down Expand Up @@ -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.<br>
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]
Expand All @@ -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
Expand Down Expand Up @@ -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.<br>
This is done by setting up an installation script in the **install_script** attribute of the task.<br>
It is possible to use platform overrides to specify different installation scripts for Linux/macOS/Windows platforms.<br>
It is possible to use platform overrides to specify different installation scripts for Linux/macOS/FreeBSD/Windows platforms.<br>
For example:

```toml
Expand Down
17 changes: 10 additions & 7 deletions docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my hunch is that a bit more is needed for this to work.

  1. add the attributes in the task type
  2. proxy to it when platform is freebsd

if i'm not wrong.
and therefore i would also add a test for it.
without it, i feel the change you didn't won't actually impact anything. could be wrong but don't think so.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to add a relevant test for that but please take a look at my new commit and tell me if it's enough. Thank you.


[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.<br>
Expand All @@ -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.<br>
If you run task **my_task** on windows, mac or freebsd, it will invoke the **do_nothing** task.<br>
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.*
Expand Down Expand Up @@ -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" }
]
Expand Down Expand Up @@ -1179,7 +1182,7 @@ The same process can be used to override tasks from other makefiles loaded using

<a name="usage-platform-override"></a>
#### 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.<br>
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.<br>
For example:

```toml
Expand Down Expand Up @@ -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.<br>
**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.**<br>
**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias attributes.**<br>
**To have an alias redirect per-platform, use the linux_alias, windows_alias, mac_alias, freebsd_alias attributes.**<br>
**In addition, aliases cannot be defined in platform override tasks, only in parent tasks.**

<a name="usage-task-extend-attribute"></a>
Expand Down Expand Up @@ -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.<br>
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]
Expand All @@ -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
Expand Down Expand Up @@ -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.<br>
This is done by setting up an installation script in the **install_script** attribute of the task.<br>
It is possible to use platform overrides to specify different installation scripts for Linux/macOS/Windows platforms.<br>
It is possible to use platform overrides to specify different installation scripts for Linux/macOS/FreeBSD/Windows platforms.<br>
For example:

```toml
Expand Down
2 changes: 2 additions & 0 deletions src/lib/descriptor/makefiles/mod_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/lib/descriptor/makefiles/rust-coverage.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ condition = { env_not_set = [
], platforms = [
"linux",
"mac",
"freebsd",
] }
script_runner = "bash"
script = '''
Expand Down
32 changes: 32 additions & 0 deletions src/lib/execution_plan_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
Expand Down Expand Up @@ -1305,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);

Expand Down Expand Up @@ -1557,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());
Expand Down
2 changes: 2 additions & 0 deletions src/lib/plugin/runner_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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();
Expand Down
46 changes: 46 additions & 0 deletions src/lib/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -1153,6 +1155,8 @@ pub struct Task {
pub windows_alias: Option<String>,
/// acts like alias if runtime OS is Mac (takes precedence over alias)
pub mac_alias: Option<String>,
/// acts like alias if runtime OS is FreeBSD (takes precedence over alias)
pub freebsd_alias: Option<String>,
/// if defined, the provided crate will be installed (if needed) before running the task
pub install_crate: Option<InstallCrate>,
/// additional cargo install arguments
Expand Down Expand Up @@ -1183,6 +1187,8 @@ pub struct Task {
pub windows: Option<PlatformOverrideTask>,
/// override task if runtime OS is Mac (takes precedence over alias)
pub mac: Option<PlatformOverrideTask>,
/// override task if runtime OS is FreeBSD (takes precedence over alias)
pub freebsd: Option<PlatformOverrideTask>,
}

/// A toolchain, defined either as a string (following the rustup syntax)
Expand Down Expand Up @@ -1383,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();

Expand Down Expand Up @@ -1595,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 {
Expand Down Expand Up @@ -1715,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()),
Expand Down Expand Up @@ -1754,6 +1778,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(),
Expand All @@ -1769,6 +1794,7 @@ impl Task {
linux: None,
windows: None,
mac: None,
freebsd: None,
}
}
None => self.clone(),
Expand All @@ -1787,6 +1813,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),
Expand Down Expand Up @@ -2187,6 +2218,8 @@ pub struct ConfigSection {
pub windows_load_script: Option<ScriptValue>,
/// acts like load_script if runtime OS is Mac (takes precedence over load_script)
pub mac_load_script: Option<ScriptValue>,
/// acts like load_script if runtime OS is FreeBSD (takes precedence over load_script)
pub freebsd_load_script: Option<ScriptValue>,
/// Enables unstable cargo-make features
pub unstable_features: Option<IndexSet<UnstableFeature>>,
}
Expand Down Expand Up @@ -2333,6 +2366,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);
Expand All @@ -2358,6 +2398,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()
Expand Down
Loading
Loading