From fcd6c27488e523b001cf54b8b7e9b672b4c94fb1 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sun, 29 Sep 2024 08:29:27 +0000 Subject: [PATCH] Enhancement: config to disable all installation steps #1147 --- CHANGELOG.md | 4 ++++ examples/install_disabled.toml | 13 +++++++++++++ src/lib/installer/mod.rs | 6 ++++++ src/lib/installer/mod_test.rs | 14 ++++++++++++++ src/lib/types.rs | 6 ++++++ src/lib/types_test.rs | 8 ++++++++ 6 files changed, 51 insertions(+) create mode 100644 examples/install_disabled.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f1b1f0a..c6eece8c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### v0.37.18 + +* Enhancement: config to disable all installation steps #1147 + ### v0.37.17 (2024-09-28) * Fix: support encrypted drives (shorten script file names) #1150 diff --git a/examples/install_disabled.toml b/examples/install_disabled.toml new file mode 100644 index 00000000..a7509a23 --- /dev/null +++ b/examples/install_disabled.toml @@ -0,0 +1,13 @@ + +[config] +skip_core_tasks = true +disable_install = true + +[tasks.alt-command-example1] +install_crate = { install_command = "custom-install" } +command = "cargo" +args = ["somecrate"] + +[tasks.alt-command-example2] +install_crate = { crate_name = "somecrate", install_command = "custom-install" } + diff --git a/src/lib/installer/mod.rs b/src/lib/installer/mod.rs index 2f5806f0..24ba279b 100644 --- a/src/lib/installer/mod.rs +++ b/src/lib/installer/mod.rs @@ -65,6 +65,12 @@ pub(crate) fn install( flow_info: &FlowInfo, flow_state: Rc>, ) -> Result<(), CargoMakeError> { + if let Some(disable_install) = flow_info.config.config.disable_install { + if disable_install { + return Ok(()); + } + } + let validate = !task_config.should_ignore_errors(); let toolchain = task_config.toolchain.clone(); diff --git a/src/lib/installer/mod_test.rs b/src/lib/installer/mod_test.rs index 1155619f..d2871f20 100644 --- a/src/lib/installer/mod_test.rs +++ b/src/lib/installer/mod_test.rs @@ -101,6 +101,20 @@ fn install_empty_args() { .unwrap(); } +#[test] +fn install_disabled() { + let mut task = Task::new(); + task.install_crate = Some(InstallCrate::Value("test".to_string())); + task.command = Some("cargo".to_string()); + task.args = Some(vec![]); + + let mut flow_info = test::create_empty_flow_info(); + flow_info.config.config.disable_install = Some(true); + + // this should throw but since we disabled installation, we just return + install(&task, &flow_info, Rc::new(RefCell::new(FlowState::new()))).unwrap(); +} + #[test] fn install_enabled_crate_already_installed() { let mut task = Task::new(); diff --git a/src/lib/types.rs b/src/lib/types.rs index be05db14..7124f934 100755 --- a/src/lib/types.rs +++ b/src/lib/types.rs @@ -2172,6 +2172,8 @@ pub struct ConfigSection { pub time_summary: Option, /// Automatically load cargo aliases as cargo-make tasks pub load_cargo_aliases: Option, + /// If true (default false) disable all automatic/defined installation instructions + pub disable_install: Option, /// The project information member (used by workspaces) pub main_project_member: Option, /// Invoked while loading the descriptor file but before loading any extended descriptor @@ -2294,6 +2296,10 @@ impl ConfigSection { self.load_cargo_aliases = extended.load_cargo_aliases.clone(); } + if extended.disable_install.is_some() { + self.disable_install = extended.disable_install.clone(); + } + if extended.main_project_member.is_some() { self.main_project_member = extended.main_project_member.clone(); } diff --git a/src/lib/types_test.rs b/src/lib/types_test.rs index 58b1c2f1..33f2252c 100755 --- a/src/lib/types_test.rs +++ b/src/lib/types_test.rs @@ -3899,6 +3899,7 @@ fn config_section_new() { assert!(config.reduce_output.is_none()); assert!(config.time_summary.is_none()); assert!(config.load_cargo_aliases.is_none()); + assert!(config.disable_install.is_none()); assert!(config.main_project_member.is_none()); assert!(config.load_script.is_none()); assert!(config.linux_load_script.is_none()); @@ -3929,6 +3930,7 @@ fn config_section_extend_all_values() { base.reduce_output = Some(true); base.time_summary = Some(true); base.load_cargo_aliases = Some(true); + base.disable_install = Some(true); base.load_script = Some(ScriptValue::Text(vec!["base_info".to_string()])); base.linux_load_script = Some(ScriptValue::Text(vec![ "linux".to_string(), @@ -3962,6 +3964,7 @@ fn config_section_extend_all_values() { extended.reduce_output = Some(false); extended.time_summary = Some(false); extended.load_cargo_aliases = Some(false); + extended.disable_install = Some(false); extended.load_script = Some(ScriptValue::Text(vec![ "extended_info".to_string(), "arg2".to_string(), @@ -3995,6 +3998,7 @@ fn config_section_extend_all_values() { assert!(!base.reduce_output.unwrap()); assert!(!base.time_summary.unwrap()); assert!(!base.load_cargo_aliases.unwrap()); + assert!(!base.disable_install.unwrap()); assert_eq!(get_script_as_vec(base.load_script).len(), 2); assert_eq!(get_script_as_vec(base.linux_load_script).len(), 1); assert_eq!(get_script_as_vec(base.windows_load_script).len(), 1); @@ -4024,6 +4028,7 @@ fn config_section_extend_no_values() { base.reduce_output = Some(true); base.time_summary = Some(true); base.load_cargo_aliases = Some(true); + base.disable_install = Some(true); base.load_script = Some(ScriptValue::Text(vec![ "base_info".to_string(), "arg2".to_string(), @@ -4066,6 +4071,7 @@ fn config_section_extend_no_values() { assert!(base.reduce_output.unwrap()); assert!(base.time_summary.unwrap()); assert!(base.load_cargo_aliases.unwrap()); + assert!(base.disable_install.unwrap()); assert_eq!(get_script_as_vec(base.load_script).len(), 2); assert_eq!(get_script_as_vec(base.linux_load_script).len(), 2); assert_eq!(get_script_as_vec(base.windows_load_script).len(), 2); @@ -4095,6 +4101,7 @@ fn config_section_extend_some_values() { base.reduce_output = Some(true); base.time_summary = Some(true); base.load_cargo_aliases = Some(true); + base.disable_install = Some(true); base.load_script = Some(ScriptValue::Text(vec![ "base_info".to_string(), "arg2".to_string(), @@ -4140,6 +4147,7 @@ fn config_section_extend_some_values() { assert!(base.reduce_output.unwrap()); assert!(base.time_summary.unwrap()); assert!(base.load_cargo_aliases.unwrap()); + assert!(base.disable_install.unwrap()); assert_eq!(get_script_as_vec(base.load_script).len(), 2); assert_eq!(get_script_as_vec(base.linux_load_script).len(), 2); assert_eq!(get_script_as_vec(base.windows_load_script).len(), 2);