Skip to content

Commit

Permalink
feat: very basic dependency support
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Mar 16, 2024
1 parent 962bed0 commit 6dbbc41
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 19 deletions.
2 changes: 1 addition & 1 deletion scripts/pre-release-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euxo pipefail

if [[ "${NO_UPDATE:-}" == "1" ]]; then
echo "NO_UPDATE is set, skipping update"
echo "NO_UPDATE is set, skipping update"
# else
# cargo update && git add Cargo.lock
fi
Expand Down
36 changes: 18 additions & 18 deletions scripts/update-shorthand-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ pub static DEFAULT_SHORTHANDS: Lazy<HashMap<&'static str, &'static str>> =
EOF
count=0
for plugin in $asdf_plugins; do
file="asdf-plugins/plugins/$plugin"
repository=$(grep -e '^repository = ' "$file")
repository="${repository/#repository = /}"
printf "\033[2K[%03d/%d] %s\r" $((++count)) "$num_plugins" "$repository"
if [[ $repository == "https://github.com/mise-plugins/"* ]]; then
trusted+=("$plugin")
elif grep -qe '^first-party = true' "$file"; then
trusted+=("$plugin")
fi
# if [[ $repository == "https://github.com/"* ]]; then
# owner=${repository#*github.com/}
# owner=${owner%/*}
# repo=${repository#*github.com/*/}
# repo=${repo%.git}
# stars["$owner/$repo"]="$plugin"
# fi
echo " (\"$plugin\", \"$repository\")," >>src/default_shorthands.rs
file="asdf-plugins/plugins/$plugin"
repository=$(grep -e '^repository = ' "$file")
repository="${repository/#repository = /}"
printf "\033[2K[%03d/%d] %s\r" $((++count)) "$num_plugins" "$repository"
if [[ $repository == "https://github.com/mise-plugins/"* ]]; then
trusted+=("$plugin")
elif grep -qe '^first-party = true' "$file"; then
trusted+=("$plugin")
fi
# if [[ $repository == "https://github.com/"* ]]; then
# owner=${repository#*github.com/}
# owner=${owner%/*}
# repo=${repository#*github.com/*/}
# repo=${repo%.git}
# stars["$owner/$repo"]="$plugin"
# fi
echo " (\"$plugin\", \"$repository\")," >>src/default_shorthands.rs
done
echo "]));" >>src/default_shorthands.rs

Expand All @@ -63,7 +63,7 @@ pub static TRUSTED_SHORTHANDS: Lazy<HashSet<&'static str>> =
Lazy::new(|| HashSet::from([
EOF
for plugin in "${trusted[@]}"; do
echo " \"$plugin\"," >>src/default_shorthands.rs
echo " \"$plugin\"," >>src/default_shorthands.rs
done
echo "]));" >>src/default_shorthands.rs

Expand Down
5 changes: 5 additions & 0 deletions src/forge/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::file;
use crate::forge::{Forge, ForgeType};
use crate::http::HTTP_FETCH;
use crate::install_context::InstallContext;
use crate::toolset::ToolVersion;

#[derive(Debug)]
pub struct CargoForge {
Expand All @@ -27,6 +28,10 @@ impl Forge for CargoForge {
&self.fa
}

fn get_dependencies(&self, _tv: &ToolVersion) -> eyre::Result<Vec<String>> {
Ok(vec!["cargo".into(), "rust".into()])
}

fn list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
Expand Down
5 changes: 5 additions & 0 deletions src/forge/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::config::{Config, Settings};

use crate::forge::{Forge, ForgeType};
use crate::install_context::InstallContext;
use crate::toolset::ToolVersion;

#[derive(Debug)]
pub struct GoForge {
Expand All @@ -23,6 +24,10 @@ impl Forge for GoForge {
&self.fa
}

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

fn list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
Expand Down
5 changes: 5 additions & 0 deletions src/forge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ pub trait Forge: Debug + Send + Sync {
fn get_plugin_type(&self) -> PluginType {
PluginType::Core
}
/// If any of these tools are installing in parallel, we should wait for them to finish
/// before installing this tool.
fn get_dependencies(&self, _tv: &ToolVersion) -> eyre::Result<Vec<String>> {
Ok(vec![])
}
fn list_remote_versions(&self) -> eyre::Result<Vec<String>>;
fn latest_stable_version(&self) -> eyre::Result<Option<String>> {
self.latest_version(Some("latest".into()))
Expand Down
5 changes: 5 additions & 0 deletions src/forge/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::config::{Config, Settings};

use crate::forge::{Forge, ForgeType};
use crate::install_context::InstallContext;
use crate::toolset::ToolVersion;
use serde_json::Value;

#[derive(Debug)]
Expand All @@ -25,6 +26,10 @@ impl Forge for NPMForge {
&self.fa
}

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

fn list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/external_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@ impl Forge for ExternalPlugin {
fn get_plugin_type(&self) -> PluginType {
PluginType::External
}

fn get_dependencies(&self, tv: &ToolVersion) -> Result<Vec<String>> {
let out = match tv.forge.name.as_str() {
"poetry" | "pipenv" => vec!["python"],
"elixir" => vec!["erlang"],
_ => vec![],
};
Ok(out.into_iter().map(|s| s.into()).collect())
}

fn list_remote_versions(&self) -> Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| self.fetch_remote_versions())
Expand Down
16 changes: 16 additions & 0 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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 console::truncate_str;
use eyre::Result;
Expand Down Expand Up @@ -154,15 +156,28 @@ impl Toolset {
true => 1,
false => opts.jobs.unwrap_or(settings.jobs),
};
let installing: HashSet<String> = HashSet::new();
let installing = Arc::new(Mutex::new(installing));
thread::scope(|s| {
(0..jobs)
.map(|_| {
let queue = queue.clone();
let installing = installing.clone();
let ts = &*self;
s.spawn(move || {
let next_job = || queue.lock().unwrap().pop();
while let Some((t, versions)) = next_job() {
installing.lock().unwrap().insert(t.id().into());
for tv in versions {
for dep in t.get_dependencies(&tv)? {
while installing.lock().unwrap().contains(dep.as_str()) {
trace!(
"{tv} waiting for dependency {} to finish installing",
dep
);
sleep(Duration::from_millis(100));
}
}
let tv = tv.request.resolve(
t.as_ref(),
tv.opts.clone(),
Expand All @@ -177,6 +192,7 @@ impl Toolset {
};
t.install_version(ctx)?;
}
installing.lock().unwrap().remove(t.id());
}
Ok(())
})
Expand Down

0 comments on commit 6dbbc41

Please sign in to comment.