-
-
Notifications
You must be signed in to change notification settings - Fork 769
feat(lockfile): add URL support for vfox backend #7114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ use tokio::sync::RwLock; | |
|
|
||
| use crate::backend::Backend; | ||
| use crate::backend::backend_type::BackendType; | ||
| use crate::backend::platform_target::PlatformTarget; | ||
| use crate::cache::{CacheManager, CacheManagerBuilder}; | ||
| use crate::cli::args::BackendArg; | ||
| use crate::config::{Config, Settings}; | ||
|
|
@@ -54,21 +55,14 @@ impl Backend for VfoxBackend { | |
| this.ensure_plugin_installed(config).await?; | ||
|
|
||
| // Use backend methods if the plugin supports them | ||
| if matches!(&this.plugin_enum, PluginEnum::VfoxBackend(_)) { | ||
| if this.is_backend_plugin() { | ||
| Settings::get().ensure_experimental("custom backends")?; | ||
| debug!("Using backend method for plugin: {}", this.pathname); | ||
| let tool_name = this.tool_name.as_ref().ok_or_else(|| { | ||
| eyre::eyre!("VfoxBackend requires a tool name (plugin:tool format)") | ||
| })?; | ||
| match vfox.backend_list_versions(&this.pathname, tool_name).await { | ||
| Ok(versions) => { | ||
| return Ok(versions); | ||
| } | ||
| Err(e) => { | ||
| debug!("Backend method failed: {}", e); | ||
| return Err(e).wrap_err("Backend list versions method failed"); | ||
| } | ||
| } | ||
| let tool_name = this.get_tool_name()?; | ||
| return vfox | ||
| .backend_list_versions(&this.pathname, tool_name) | ||
| .await | ||
| .wrap_err("Backend list versions method failed"); | ||
| } | ||
|
|
||
| // Use default vfox behavior for traditional plugins | ||
|
|
@@ -99,22 +93,13 @@ impl Backend for VfoxBackend { | |
| }); | ||
|
|
||
| // Use backend methods if the plugin supports them | ||
| if matches!(&self.plugin_enum, PluginEnum::VfoxBackend(_)) { | ||
| if self.is_backend_plugin() { | ||
| Settings::get().ensure_experimental("custom backends")?; | ||
| let tool_name = self.tool_name.as_ref().ok_or_else(|| { | ||
| eyre::eyre!("VfoxBackend requires a tool name (plugin:tool format)") | ||
| })?; | ||
| match vfox | ||
| .backend_install(&self.pathname, tool_name, &tv.version, tv.install_path()) | ||
| let tool_name = self.get_tool_name()?; | ||
| vfox.backend_install(&self.pathname, tool_name, &tv.version, tv.install_path()) | ||
| .await | ||
| { | ||
| Ok(_response) => { | ||
| return Ok(tv); | ||
| } | ||
| Err(e) => { | ||
| return Err(e).wrap_err("Backend install method failed"); | ||
| } | ||
| } | ||
| .wrap_err("Backend install method failed")?; | ||
| return Ok(tv); | ||
| } | ||
|
|
||
| // Use default vfox behavior for traditional plugins | ||
|
|
@@ -174,9 +159,45 @@ impl Backend for VfoxBackend { | |
| ) | ||
| }) | ||
| } | ||
|
|
||
| async fn get_tarball_url( | ||
| &self, | ||
| tv: &ToolVersion, | ||
| target: &PlatformTarget, | ||
| ) -> eyre::Result<Option<String>> { | ||
| let config = Config::get().await?; | ||
| self.ensure_plugin_installed(&config).await?; | ||
|
|
||
| // Map mise platform names to vfox platform names | ||
| let os = match target.os_name() { | ||
| "macos" => "darwin", | ||
| os => os, | ||
| }; | ||
| let arch = match target.arch_name() { | ||
| "x64" => "amd64", | ||
| arch => arch, | ||
| }; | ||
|
|
||
| let (vfox, _log_rx) = self.plugin.vfox(); | ||
|
||
| let pre_install = vfox | ||
| .pre_install_for_platform(&self.pathname, &tv.version, os, arch) | ||
| .await?; | ||
|
|
||
| Ok(pre_install.url) | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| impl VfoxBackend { | ||
| fn is_backend_plugin(&self) -> bool { | ||
| matches!(&self.plugin_enum, PluginEnum::VfoxBackend(_)) | ||
| } | ||
|
|
||
| fn get_tool_name(&self) -> eyre::Result<&str> { | ||
| self.tool_name | ||
| .as_deref() | ||
| .ok_or_else(|| eyre::eyre!("VfoxBackend requires a tool name (plugin:tool format)")) | ||
| } | ||
|
|
||
| pub fn from_arg(ba: BackendArg, backend_plugin_name: Option<String>) -> Self { | ||
| let pathname = match &backend_plugin_name { | ||
| Some(plugin_name) => plugin_name.clone(), | ||
|
|
@@ -233,63 +254,31 @@ impl VfoxBackend { | |
| let (vfox, _log_rx) = self.plugin.vfox(); | ||
|
|
||
| // Use backend methods if the plugin supports them | ||
| if matches!(&self.plugin_enum, PluginEnum::VfoxBackend(_)) { | ||
| let tool_name = self.tool_name.as_ref().ok_or_else(|| { | ||
| eyre::eyre!("VfoxBackend requires a tool name (plugin:tool format)") | ||
| })?; | ||
| match vfox | ||
| .backend_exec_env(&self.pathname, tool_name, &tv.version, tv.install_path()) | ||
| let env_keys = if self.is_backend_plugin() { | ||
| let tool_name = self.get_tool_name()?; | ||
| vfox.backend_exec_env(&self.pathname, tool_name, &tv.version, tv.install_path()) | ||
| .await | ||
| { | ||
| Ok(response) => { | ||
| return Ok(response.into_iter().fold( | ||
| BTreeMap::new(), | ||
| |mut acc, env_key| { | ||
| let key = &env_key.key; | ||
| if let Some(val) = acc.get(key) { | ||
| let mut paths = | ||
| env::split_paths(val).collect::<Vec<PathBuf>>(); | ||
| paths.push(PathBuf::from(env_key.value)); | ||
| acc.insert( | ||
| env_key.key, | ||
| env::join_paths(paths) | ||
| .unwrap() | ||
| .to_string_lossy() | ||
| .to_string(), | ||
| ); | ||
| } else { | ||
| acc.insert(key.clone(), env_key.value); | ||
| } | ||
| acc | ||
| }, | ||
| )); | ||
| } | ||
| Err(e) => { | ||
| debug!("Backend method failed: {}", e); | ||
| return Err(e).wrap_err("Backend exec env method failed"); | ||
| } | ||
| } | ||
| } | ||
| .wrap_err("Backend exec env method failed")? | ||
| } else { | ||
| vfox.env_keys(&self.pathname, &tv.version).await? | ||
| }; | ||
|
|
||
| // Use default vfox behavior for traditional plugins | ||
| Ok(vfox | ||
| .env_keys(&self.pathname, &tv.version) | ||
| .await? | ||
| Ok(env_keys | ||
| .into_iter() | ||
| .fold(BTreeMap::new(), |mut acc, env_key| { | ||
| let key = &env_key.key; | ||
| if let Some(val) = acc.get(key) { | ||
| let mut paths = env::split_paths(val).collect::<Vec<PathBuf>>(); | ||
| paths.push(PathBuf::from(env_key.value)); | ||
| paths.push(PathBuf::from(&env_key.value)); | ||
| acc.insert( | ||
| env_key.key, | ||
| env_key.key.clone(), | ||
| env::join_paths(paths) | ||
| .unwrap() | ||
| .to_string_lossy() | ||
| .to_string(), | ||
| ); | ||
| } else { | ||
| acc.insert(key.clone(), env_key.value); | ||
| acc.insert(key.clone(), env_key.value.clone()); | ||
| } | ||
| acc | ||
| })) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable override pattern may cause issues in concurrent scenarios. If multiple calls to
pre_install_for_platform()execute simultaneously, they could interfere with each other's OS_TYPE/ARCH_TYPE values. Consider using a more isolated approach, such as passing platform parameters directly to the plugin function if the vfox plugin API supports it, or ensuring this method is called under a lock.