Skip to content

Commit

Permalink
fix(ubi): fixed misc bugs with versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed May 13, 2024
1 parent 13f16cb commit e2daee6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
30 changes: 5 additions & 25 deletions src/forge/ubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ use crate::toolset::ToolVersionRequest;
pub struct UbiForge {
fa: ForgeArg,
remote_version_cache: CacheManager<Vec<String>>,
latest_version_cache: CacheManager<Option<String>>,
}

// Uses ubi for installations https://github.com/houseabsolute/ubi
// it can be installed via mise install cargo:ubi
// TODO: doesn't currently work when ubi installed via mise :-/
impl Forge for UbiForge {
fn get_type(&self) -> ForgeType {
ForgeType::Ubi
Expand Down Expand Up @@ -55,30 +53,15 @@ impl Forge for UbiForge {
}
}

fn latest_stable_version(&self) -> eyre::Result<Option<String>> {
if name_is_url(self.name()) {
Ok(Some("latest".to_string()))
} else {
self.latest_version_cache
.get_or_try_init(|| Ok(Some(self.list_remote_versions()?.last().unwrap().into())))
.cloned()
}
}

fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> {
let config = Config::try_get()?;
let settings = Settings::get();
let version = &ctx.tv.version;
settings.ensure_experimental("ubi backend")?;
// Workaround because of not knowing how to pull out the value correctly without quoting
let matching_version = self
.list_remote_versions()?
.into_iter()
.find(|v| v.contains(&ctx.tv.version))
.unwrap()
.replace('"', "");
let path_with_bin = ctx.tv.install_path().join("bin");

let cmd = CmdLineRunner::new("ubi")
let mut cmd = CmdLineRunner::new("ubi")
.arg("--in")
.arg(path_with_bin)
.arg("--project")
Expand All @@ -87,13 +70,11 @@ impl Forge for UbiForge {
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?;

if name_is_url(self.name()) {
cmd.execute()?;
} else {
cmd.arg("--tag").arg(matching_version).execute()?;
if version != "latest" {
cmd = cmd.arg("--tag").arg(version);
}

Ok(())
cmd.execute()
}
}

Expand All @@ -104,7 +85,6 @@ impl UbiForge {
remote_version_cache: CacheManager::new(
fa.cache_path.join("remote_versions.msgpack.z"),
),
latest_version_cache: CacheManager::new(fa.cache_path.join("latest_version.msgpack.z")),
fa,
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::thread;
use std::thread::sleep;
use std::time::Duration;
use std::{panic, thread};

use console::truncate_str;
use eyre::Result;
Expand Down Expand Up @@ -180,7 +180,9 @@ impl Toolset {
for tv in versions {
for dep in t.get_dependencies(&tv)? {
while installing.lock().unwrap().contains(&dep.to_string()) {
trace!("{tv} waiting for dependency {dep} to finish installing");
trace!(
"{tv} waiting for dependency {dep} to finish installing"
);
sleep(Duration::from_millis(100));
}
}
Expand All @@ -199,16 +201,19 @@ impl Toolset {
Ok(installed)
})
})
.collect_vec()
.collect::<Vec<_>>()
.into_iter()
.map(|t| t.join().unwrap())
.map(|t| match t.join() {
Ok(x) => x,
Err(e) => panic::resume_unwind(e),
})
.collect::<Result<Vec<Vec<ToolVersion>>>>()
// TODO: figure out how to get Result<Vec<ToolVersion>> instead
.map(|x| x.into_iter().flatten().collect())
})?;
self.resolve();
shims::reshim(self)?;
runtime_symlinks::rebuild(config)?;
Ok(installed.into_iter().flatten().collect())
Ok(installed)
}

pub fn list_missing_versions(&self) -> Vec<ToolVersion> {
Expand Down

0 comments on commit e2daee6

Please sign in to comment.