Skip to content

Commit

Permalink
fix: prefix: on tool dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 16, 2024
1 parent cb9b55c commit 52fd25a
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/backend/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl Backend for AsdfBackend {
Some(PluginType::Asdf)
}

fn get_dependencies(&self, tvr: &ToolRequest) -> Result<Vec<BackendArg>> {
fn get_dependencies(&self, tvr: &ToolRequest) -> Result<Vec<String>> {
let out = match tvr.ba().tool_name.as_str() {
"poetry" | "pipenv" | "pipx" => vec!["python"],
"elixir" => vec!["erlang"],
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Backend for CargoBackend {
&self.ba
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<String>> {
Ok(vec![
"rust".into(),
"cargo-binstall".into(),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Backend for GoBackend {
&self.ba
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<String>> {
Ok(vec!["go".into()])
}

Expand Down
32 changes: 16 additions & 16 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ pub trait Backend: Debug + Send + Sync {
}
/// If any of these tools are installing in parallel, we should wait for them to finish
/// before installing this tool.
fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<String>> {
Ok(vec![])
}
fn get_all_dependencies(&self, tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
fn get_all_dependencies(&self, tvr: &ToolRequest) -> eyre::Result<Vec<String>> {
let mut deps: IndexSet<_> = self
.get_dependencies(tvr)?
.into_iter()
.filter(|ba| self.ba() != ba) // prevent infinite loop
.filter(|short| self.ba().short != *short) // prevent infinite loop
.collect();
let dep_backends = deps
.iter()
.flat_map(|ba| ba.backend())
.flat_map(|short| get(&short.into()))
.collect::<Vec<ABackend>>();
for dep in dep_backends {
// TODO: pass the right tvr
Expand Down Expand Up @@ -244,16 +244,16 @@ pub trait Backend: Debug + Send + Sync {
};
match tv.request {
ToolRequest::System { .. } => true,
ToolRequest::Prefix { .. } => {
// can't use tv.request.install_path() in this case since it may point to a version
// that matches the prefix but is not the correct one. For example, in the following
// scenario this would not upgrade tiny because "prefix:1" would still match and
// `mise up` would think it is installed
// mise install [email protected]
// mise use tiny@prefix:1
// mise up tiny
check_path(&tv.install_path())
}
// ToolRequest::Prefix { .. } => {
// // can't use tv.request.install_path() in this case since it may point to a version
// // that matches the prefix but is not the correct one. For example, in the following
// // scenario this would not upgrade tiny because "prefix:1" would still match and
// // `mise up` would think it is installed
// // mise install [email protected]
// // mise use tiny@prefix:1
// // mise up tiny
// check_path(&tv.install_path())
// }
_ => {
if let Some(install_path) = tv.request.install_path() {
if check_path(&install_path) {
Expand Down Expand Up @@ -352,7 +352,7 @@ pub trait Backend: Debug + Send + Sync {
if !deps.is_empty() {
trace!("Ensuring dependencies installed for {}", self.id());
let config = Config::get();
let ts = config.get_tool_request_set()?.filter_by_tool(&deps);
let ts = config.get_tool_request_set()?.filter_by_tool(deps);
let missing = ts.missing_tools();
if !missing.is_empty() {
bail!(
Expand Down Expand Up @@ -556,7 +556,7 @@ pub trait Backend: Debug + Send + Sync {
.collect();
let mut ts: Toolset = config
.get_tool_request_set()?
.filter_by_tool(&dependencies)
.filter_by_tool(dependencies)
.into();
ts.resolve()?;
Ok(ts)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Backend for NPMBackend {
&self.ba
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<String>> {
Ok(vec!["node".into(), "bun".into()])
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/pipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Backend for PIPXBackend {
&self.ba
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<String>> {
Ok(vec!["pipx".into(), "uv".into()])
}

Expand Down
5 changes: 1 addition & 4 deletions src/backend/spm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ impl Backend for SPMBackend {
&self.ba
}

fn get_dependencies(
&self,
_tvr: &crate::toolset::ToolRequest,
) -> eyre::Result<Vec<BackendArg>> {
fn get_dependencies(&self, _tvr: &crate::toolset::ToolRequest) -> eyre::Result<Vec<String>> {
// TODO: swift as dependencies (wait for swift core plugin: https://github.com/jdx/mise/pull/1708)
Ok(vec![])
}
Expand Down
5 changes: 0 additions & 5 deletions src/backend/ubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::env::GITHUB_TOKEN;
use crate::github;
use crate::install_context::InstallContext;
use crate::plugins::VERSION_REGEX;
use crate::toolset::ToolRequest;
use eyre::bail;
use regex::Regex;
use std::fmt::Debug;
Expand All @@ -31,10 +30,6 @@ impl Backend for UbiBackend {
&self.ba
}

fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
Ok(vec![])
}

fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
if name_is_url(self.name()) {
Ok(vec!["latest".to_string()])
Expand Down
2 changes: 1 addition & 1 deletion src/backend/vfox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Backend for VfoxBackend {
.collect())
}

fn get_dependencies(&self, tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
fn get_dependencies(&self, tvr: &ToolRequest) -> eyre::Result<Vec<String>> {
let out = match tvr.ba().tool_name.as_str() {
"poetry" | "pipenv" | "pipx" => vec!["python"],
"elixir" => vec!["erlang"],
Expand Down
7 changes: 3 additions & 4 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::args::{BackendArg, ToolArg};
use crate::cli::args::ToolArg;
use crate::config::Config;
use crate::lockfile;
use crate::toolset::{
Expand All @@ -7,7 +7,6 @@ use crate::toolset::{
use crate::ui::multi_progress_report::MultiProgressReport;
use eyre::{Result, WrapErr};
use itertools::Itertools;
use std::collections::HashSet;

/// Install a tool version
///
Expand Down Expand Up @@ -59,8 +58,8 @@ impl Install {

fn install_runtimes(&self, config: &Config, runtimes: &[ToolArg]) -> Result<Vec<ToolVersion>> {
let mpr = MultiProgressReport::get();
let tools: HashSet<BackendArg> = runtimes.iter().map(|ta| ta.ba.clone()).collect();
let mut ts = config.get_tool_request_set()?.filter_by_tool(&tools).into();
let tools = runtimes.iter().map(|ta| ta.ba.short.clone()).collect();
let mut ts = config.get_tool_request_set()?.filter_by_tool(tools).into();
let tool_versions = self.get_requested_tool_versions(&ts, runtimes)?;
if tool_versions.is_empty() {
warn!("no runtimes to install");
Expand Down
3 changes: 2 additions & 1 deletion src/cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ impl Upgrade {
return Ok(());
}
let opts = InstallOptions {
force: false,
// TODO: can we remove this without breaking e2e/cli/test_upgrade? it may be causing tools to re-install
force: true,
jobs: self.jobs,
raw: self.raw,
resolve_options: ResolveOptions {
Expand Down
5 changes: 4 additions & 1 deletion src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ impl From<ToolRequestSet> for Toolset {
}

fn get_leaf_dependencies(requests: &[ToolRequest]) -> eyre::Result<Vec<&ToolRequest>> {
let versions_hash = requests.iter().map(|tr| tr.ba()).collect::<HashSet<_>>();
let versions_hash = requests
.iter()
.map(|tr| tr.ba().short.to_string())
.collect::<HashSet<_>>();
let leaves = requests
.iter()
.map(|tr| {
Expand Down
2 changes: 1 addition & 1 deletion src/toolset/tool_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl ToolRequest {
}
self
}
pub fn dependencies(&self) -> eyre::Result<Vec<BackendArg>> {
pub fn dependencies(&self) -> eyre::Result<Vec<String>> {
let backend = self.ba().backend()?;
backend.get_all_dependencies(self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/toolset/tool_request_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ impl ToolRequestSet {
})
}

pub fn filter_by_tool(&self, tools: &HashSet<BackendArg>) -> Self {
pub fn filter_by_tool(&self, tools: HashSet<String>) -> ToolRequestSet {
self.iter()
.filter(|(fa, ..)| tools.contains(fa))
.filter(|(ba, ..)| tools.contains(&ba.short))
.map(|(fa, trl, ts)| (fa.clone(), trl.clone(), ts.clone()))
.collect::<ToolRequestSet>()
}
Expand Down

0 comments on commit 52fd25a

Please sign in to comment.