From 114150a44c9380c1074a6361d29bec4064da925c Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 7 Dec 2023 13:13:04 -0800 Subject: [PATCH 1/6] Check for global. --- crates/cli/src/commands/install_all.rs | 5 ++- crates/core/src/proto.rs | 1 + crates/core/src/proto_config.rs | 45 ++++++++++++++++++-------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/crates/cli/src/commands/install_all.rs b/crates/cli/src/commands/install_all.rs index 72ad7cfdd..d5b3728aa 100644 --- a/crates/cli/src/commands/install_all.rs +++ b/crates/cli/src/commands/install_all.rs @@ -19,7 +19,10 @@ pub async fn install_all(proto: ResourceRef) { debug!("Detecting tool versions to install"); - let config = proto.env.load_config()?; + let config = proto + .env + .load_config_manager()? + .get_merged_config_without_global()?; let mut versions = config.versions.to_owned(); for tool in &tools { diff --git a/crates/core/src/proto.rs b/crates/core/src/proto.rs index 5ec9ff500..1fa834fa6 100644 --- a/crates/core/src/proto.rs +++ b/crates/core/src/proto.rs @@ -108,6 +108,7 @@ impl ProtoEnvironment { manager.files.push(ProtoConfigFile { exists: path.exists(), + global: true, path, config: ProtoConfig::load_from(&self.root, true)?, }); diff --git a/crates/core/src/proto_config.rs b/crates/core/src/proto_config.rs index b62f82617..405e8b4e7 100644 --- a/crates/core/src/proto_config.rs +++ b/crates/core/src/proto_config.rs @@ -307,6 +307,7 @@ impl ProtoConfig { #[derive(Debug)] pub struct ProtoConfigFile { pub exists: bool, + pub global: bool, pub path: PathBuf, pub config: PartialProtoConfig, } @@ -336,6 +337,7 @@ impl ProtoConfigManager { files.push(ProtoConfigFile { exists: path.exists(), + global: false, path, config: ProtoConfig::load_from(dir, false)?, }); @@ -354,26 +356,41 @@ impl ProtoConfigManager { } pub fn get_merged_config(&self) -> miette::Result<&ProtoConfig> { - self.merged_config.get_or_try_init(|| { + self.merged_config + .get_or_try_init(|| self.merge_configs(true)) + } + + pub fn get_merged_config_without_global(&self) -> miette::Result { + self.merge_configs(false) + } + + fn merge_configs(&self, with_global: bool) -> miette::Result { + if with_global { debug!("Merging loaded configs"); + } else { + debug!("Merging loaded configs without global"); + } - let mut partial = PartialProtoConfig::default(); - let mut count = 0; - let context = &(); + let mut partial = PartialProtoConfig::default(); + let mut count = 0; + let context = &(); - for file in self.files.iter().rev() { - if file.exists { - partial.merge(context, file.config.to_owned())?; - count += 1; - } + for file in self.files.iter().rev() { + if !with_global && file.global { + continue; } - let mut config = ProtoConfig::from_partial(partial.finalize(context)?); - config.inherit_builtin_plugins(); + if file.exists { + partial.merge(context, file.config.to_owned())?; + count += 1; + } + } + + let mut config = ProtoConfig::from_partial(partial.finalize(context)?); + config.inherit_builtin_plugins(); - debug!("Merged {} configs", count); + debug!("Merged {} configs", count); - Ok(config) - }) + Ok(config) } } From 2837cf2e5a21b293617fadc190f384649d685890 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 7 Dec 2023 13:15:42 -0800 Subject: [PATCH 2/6] Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd91cea02..799f7f2f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ #### 🐞 Fixes +- Fixed an issue where `proto use` would install tools from `~/.proto/.prototools`. - Fixed stable being considered a latest alias. #### ⚙️ Internal From cec7d4bdc39201271c17b66f634dc8aaf00cec37 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 7 Dec 2023 13:17:22 -0800 Subject: [PATCH 3/6] Add test. --- crates/cli/tests/use_test.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/cli/tests/use_test.rs b/crates/cli/tests/use_test.rs index 4bf715eaf..a3317e06b 100644 --- a/crates/cli/tests/use_test.rs +++ b/crates/cli/tests/use_test.rs @@ -46,4 +46,23 @@ deno = "1.30.0" assert!(node_path.exists()); } + + #[test] + fn doesnt_install_global_tools() { + let sandbox = create_empty_sandbox(); + let node_path = sandbox.path().join(".proto/tools/node/19.0.0"); + let deno_path = sandbox.path().join(".proto/tools/deno/1.30.0"); + + sandbox.create_file(".prototools", r#"node = "19.0.0""#); + sandbox.create_file(".proto/.prototools", r#"deno = "1.30.0""#); + + assert!(!node_path.exists()); + assert!(!deno_path.exists()); + + let mut cmd = create_proto_command(sandbox.path()); + cmd.arg("use").assert().success(); + + assert!(node_path.exists()); + assert!(!deno_path.exists()); + } } From 0a77818b3dce58e72d1400e15151f009803302d4 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 7 Dec 2023 13:37:13 -0800 Subject: [PATCH 4/6] Debug rust. --- crates/cli/tests/plugins_test.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/cli/tests/plugins_test.rs b/crates/cli/tests/plugins_test.rs index 310dabdd1..8d4f23a9e 100644 --- a/crates/cli/tests/plugins_test.rs +++ b/crates/cli/tests/plugins_test.rs @@ -277,11 +277,14 @@ mod plugins { fn supports_rust() { let sandbox = create_empty_sandbox(); - create_proto_command(sandbox.path()) + let assert = create_proto_command(sandbox.path()) .arg("install") .arg("rust") - .assert() - .success(); + .assert(); + + println!("{}", assert); + + assert.success(); } #[test] From eb539644743acf88ce9d1de70805b8e42e1e561a Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 7 Dec 2023 13:51:47 -0800 Subject: [PATCH 5/6] Debug rust. --- crates/cli/tests/plugins_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/tests/plugins_test.rs b/crates/cli/tests/plugins_test.rs index 8d4f23a9e..b14223028 100644 --- a/crates/cli/tests/plugins_test.rs +++ b/crates/cli/tests/plugins_test.rs @@ -282,7 +282,7 @@ mod plugins { .arg("rust") .assert(); - println!("{}", assert); + starbase_sandbox::debug_process_output(assert.get_output()); assert.success(); } From c1003b9c54dbb945e5dbca2dbccfc4d6cda68dfc Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 7 Dec 2023 14:16:43 -0800 Subject: [PATCH 6/6] Fix windows. --- CHANGELOG.md | 1 + crates/core/src/tool.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 799f7f2f0..d609c7759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ #### 🐞 Fixes - Fixed an issue where `proto use` would install tools from `~/.proto/.prototools`. +- Fixed an issue where our directory locking would fail on Windows when the inventory path was overwritten. - Fixed stable being considered a latest alias. #### ⚙️ Internal diff --git a/crates/core/src/tool.rs b/crates/core/src/tool.rs index 190e3f89d..d38d144bb 100644 --- a/crates/core/src/tool.rs +++ b/crates/core/src/tool.rs @@ -949,9 +949,19 @@ impl Tool { } let install_dir = self.get_tool_dir(); - let install_lock = fs::lock_directory(&install_dir)?; let mut installed = false; + // Lock the install directory. If the inventory has been overridden, + // lock the internal proto tool directory instead. + let install_lock = fs::lock_directory(if self.metadata.inventory.override_dir.is_some() { + self.proto + .tools_dir + .join(self.id.as_str()) + .join(self.get_resolved_version().to_string()) + } else { + install_dir.clone() + })?; + self.on_installing .emit(InstallingEvent { version: self.get_resolved_version(),