Skip to content

Commit

Permalink
Disable workspace support via makefile config #264
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jul 28, 2019
1 parent deb28ce commit cf9db75
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 6 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,15 @@ workspace = false
```

Setting **workspace=false** for the task requested on the cargo-make command line is equivalent to calling it with the **--no-workspace** flag.<br>
This flag is only checked for the task on the cargo-make command line and is completely ignored for all other tasks which are executed as part of the flow.
This flag is only checked for the task on the cargo-make command line and is completely ignored for all other tasks which are executed as part of the flow.<br>
By default the workspace flag for all tasks is set to true, but that can be configured differently in the config section as follows:

```toml
[config]
default_to_workspace = false
```

In which case, workspace level support is **always** disabled unless a task defines **workspace=true**.

<a name="usage-workspace-support-skip-members"></a>
#### Skipping Specific Members
Expand Down
10 changes: 9 additions & 1 deletion docs/_includes/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,15 @@ workspace = false
```

Setting **workspace=false** for the task requested on the cargo-make command line is equivalent to calling it with the **--no-workspace** flag.<br>
This flag is only checked for the task on the cargo-make command line and is completely ignored for all other tasks which are executed as part of the flow.
This flag is only checked for the task on the cargo-make command line and is completely ignored for all other tasks which are executed as part of the flow.<br>
By default the workspace flag for all tasks is set to true, but that can be configured differently in the config section as follows:

```toml
[config]
default_to_workspace = false
```

In which case, workspace level support is **always** disabled unless a task defines **workspace=true**.

<a name="usage-workspace-support-skip-members"></a>
#### Skipping Specific Members
Expand Down
1 change: 1 addition & 0 deletions src/lib/Makefile.stable.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
init_task = "init"
end_task = "end"
skip_core_tasks = false
default_to_workspace = true
additional_profiles = []

[env]
Expand Down
5 changes: 4 additions & 1 deletion src/lib/execution_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ fn is_workspace_flow(
// project is a workspace and wasn't disabled via cli, need to check requested task
let cli_task = get_normalized_task(config, task, true);

cli_task.workspace.unwrap_or(true)
// check for configured default workspace flag
let default_to_workspace = config.config.default_to_workspace.unwrap_or(true);

cli_task.workspace.unwrap_or(default_to_workspace)
}
}

Expand Down
68 changes: 65 additions & 3 deletions src/lib/execution_plan_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ fn create_workspace_task_extend_workspace_makefile() {

#[test]
fn is_workspace_flow_true_default() {
let crate_info = CrateInfo::new();
let mut crate_info = CrateInfo::new();
let members = vec![];
crate_info.workspace = Some(Workspace {
members: Some(members),
exclude: None,
});

let task = Task::new();

Expand All @@ -214,12 +219,69 @@ fn is_workspace_flow_true_default() {

let workspace_flow = is_workspace_flow(&config, "test", false, &crate_info);

assert!(workspace_flow);
}

#[test]
fn is_workspace_flow_false_in_config() {
let mut crate_info = CrateInfo::new();
let members = vec![];
crate_info.workspace = Some(Workspace {
members: Some(members),
exclude: None,
});

let task = Task::new();

let mut config_section = ConfigSection::new();
config_section.default_to_workspace = Some(false);

let mut config = Config {
config: config_section,
env: IndexMap::new(),
tasks: IndexMap::new(),
};
config.tasks.insert("test".to_string(), task);

let workspace_flow = is_workspace_flow(&config, "test", false, &crate_info);

assert!(!workspace_flow);
}

#[test]
fn is_workspace_flow_true_in_config() {
let mut crate_info = CrateInfo::new();
let members = vec![];
crate_info.workspace = Some(Workspace {
members: Some(members),
exclude: None,
});

let task = Task::new();

let mut config_section = ConfigSection::new();
config_section.default_to_workspace = Some(true);

let mut config = Config {
config: config_section,
env: IndexMap::new(),
tasks: IndexMap::new(),
};
config.tasks.insert("test".to_string(), task);

let workspace_flow = is_workspace_flow(&config, "test", false, &crate_info);

assert!(workspace_flow);
}

#[test]
fn is_workspace_flow_true_in_task() {
let crate_info = CrateInfo::new();
let mut crate_info = CrateInfo::new();
let members = vec![];
crate_info.workspace = Some(Workspace {
members: Some(members),
exclude: None,
});

let mut task = Task::new();
task.workspace = Some(true);
Expand All @@ -233,7 +295,7 @@ fn is_workspace_flow_true_in_task() {

let workspace_flow = is_workspace_flow(&config, "test", false, &crate_info);

assert!(!workspace_flow);
assert!(workspace_flow);
}

#[test]
Expand Down
7 changes: 7 additions & 0 deletions src/lib/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,8 @@ pub struct ConfigSection {
pub additional_profiles: Option<Vec<String>>,
/// Minimum cargo-make/makers version
pub min_version: Option<String>,
/// The task.workspace default value
pub default_to_workspace: Option<bool>,
/// Invoked while loading the descriptor file but before loading any extended descriptor
pub load_script: Option<Vec<String>>,
/// acts like load_script if runtime OS is Linux (takes precedence over load_script)
Expand All @@ -1429,6 +1431,7 @@ impl ConfigSection {
on_error_task: None,
additional_profiles: None,
min_version: None,
default_to_workspace: None,
load_script: None,
linux_load_script: None,
windows_load_script: None,
Expand Down Expand Up @@ -1499,6 +1502,10 @@ impl ConfigSection {
self.min_version = extended.min_version.clone();
}

if extended.default_to_workspace.is_some() {
self.default_to_workspace = extended.default_to_workspace.clone();
}

if extended.load_script.is_some() {
self.load_script = extended.load_script.clone();
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/types_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@ fn config_section_new() {
assert!(config.on_error_task.is_none());
assert!(config.additional_profiles.is_none());
assert!(config.min_version.is_none());
assert!(config.default_to_workspace.is_none());
assert!(config.load_script.is_none());
assert!(config.linux_load_script.is_none());
assert!(config.windows_load_script.is_none());
Expand All @@ -2122,6 +2123,7 @@ fn config_section_extend_all_values() {
base.on_error_task = Some("base_err".to_string());
base.additional_profiles = Some(vec!["b1".to_string(), "b2".to_string()]);
base.min_version = Some("1.0.0".to_string());
base.default_to_workspace = Some(true);
base.load_script = Some(vec!["base_info".to_string()]);
base.linux_load_script = Some(vec!["linux".to_string(), "base_info".to_string()]);
base.windows_load_script = Some(vec!["windows".to_string(), "base_info".to_string()]);
Expand All @@ -2137,6 +2139,7 @@ fn config_section_extend_all_values() {
extended.on_error_task = Some("extended_err".to_string());
extended.additional_profiles = Some(vec!["e1".to_string(), "e2".to_string()]);
extended.min_version = Some("2.0.0".to_string());
extended.default_to_workspace = Some(false);
extended.load_script = Some(vec!["extended_info".to_string(), "arg2".to_string()]);
extended.linux_load_script = Some(vec!["extended_info".to_string()]);
extended.windows_load_script = Some(vec!["extended_info".to_string()]);
Expand All @@ -2156,6 +2159,7 @@ fn config_section_extend_all_values() {
vec!["e1".to_string(), "e2".to_string()]
);
assert_eq!(base.min_version.unwrap(), "2.0.0".to_string());
assert!(!base.default_to_workspace.unwrap());
assert_eq!(base.load_script.unwrap().len(), 2);
assert_eq!(base.linux_load_script.unwrap().len(), 1);
assert_eq!(base.windows_load_script.unwrap().len(), 1);
Expand All @@ -2177,6 +2181,7 @@ fn config_section_extend_no_values() {
base.on_error_task = Some("base_err".to_string());
base.additional_profiles = Some(vec!["b1".to_string(), "b2".to_string()]);
base.min_version = Some("1.0.0".to_string());
base.default_to_workspace = Some(true);
base.load_script = Some(vec!["base_info".to_string(), "arg2".to_string()]);
base.linux_load_script = Some(vec!["linux".to_string(), "base_info".to_string()]);
base.windows_load_script = Some(vec!["windows".to_string(), "base_info".to_string()]);
Expand All @@ -2196,6 +2201,7 @@ fn config_section_extend_no_values() {
vec!["b1".to_string(), "b2".to_string()]
);
assert_eq!(base.min_version.unwrap(), "1.0.0".to_string());
assert!(base.default_to_workspace.unwrap());
assert_eq!(base.load_script.unwrap().len(), 2);
assert_eq!(base.linux_load_script.unwrap().len(), 2);
assert_eq!(base.windows_load_script.unwrap().len(), 2);
Expand All @@ -2217,6 +2223,7 @@ fn config_section_extend_some_values() {
base.on_error_task = Some("base_err".to_string());
base.additional_profiles = Some(vec!["b1".to_string(), "b2".to_string()]);
base.min_version = Some("1.0.0".to_string());
base.default_to_workspace = Some(true);
base.load_script = Some(vec!["base_info".to_string(), "arg2".to_string()]);
base.linux_load_script = Some(vec!["linux".to_string(), "base_info".to_string()]);
base.windows_load_script = Some(vec!["windows".to_string(), "base_info".to_string()]);
Expand All @@ -2239,6 +2246,7 @@ fn config_section_extend_some_values() {
vec!["b1".to_string(), "b2".to_string()]
);
assert_eq!(base.min_version.unwrap(), "1.0.0".to_string());
assert!(base.default_to_workspace.unwrap());
assert_eq!(base.load_script.unwrap().len(), 2);
assert_eq!(base.linux_load_script.unwrap().len(), 2);
assert_eq!(base.windows_load_script.unwrap().len(), 2);
Expand Down

0 comments on commit cf9db75

Please sign in to comment.