fix: disable_backends on windows (#3052)

This commit is contained in:
jdx 2024-11-16 09:44:04 -06:00 committed by GitHub
parent cb9d81da9e
commit 773652abea
13 changed files with 117 additions and 105 deletions

View File

@ -20,7 +20,7 @@ fn codegen_registry() {
let out_dir = env::var_os("OUT_DIR").unwrap(); let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("registry.rs"); let dest_path = Path::new(&out_dir).join("registry.rs");
let mut lines = vec![r#" let mut lines = vec![r#"
pub static FULL_REGISTRY: Lazy<BTreeMap<&'static str, RegistryTool>> = Lazy::new(|| ["# pub static REGISTRY: Lazy<BTreeMap<&'static str, RegistryTool>> = Lazy::new(|| ["#
.to_string()]; .to_string()];
let registry: toml::Table = fs::read_to_string("registry.toml") let registry: toml::Table = fs::read_to_string("registry.toml")
@ -78,8 +78,8 @@ pub static FULL_REGISTRY: Lazy<BTreeMap<&'static str, RegistryTool>> = Lazy::new
os os
}) })
.unwrap_or_default(); .unwrap_or_default();
lines.push(format!( let rt = format!(
r#" ("{short}", RegistryTool{{backends: vec!["{backends}"], aliases: &[{aliases}], test: &{test}, os: &[{os}]}}),"#, r#"RegistryTool{{short: "{short}", backends: vec!["{backends}"], aliases: &[{aliases}], test: &{test}, os: &[{os}]}}"#,
backends = fulls.join("\", \""), backends = fulls.join("\", \""),
aliases = aliases aliases = aliases
.iter() .iter()
@ -94,7 +94,11 @@ pub static FULL_REGISTRY: Lazy<BTreeMap<&'static str, RegistryTool>> = Lazy::new
.map(|o| format!("\"{o}\"")) .map(|o| format!("\"{o}\""))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
)); );
lines.push(format!(r#" ("{short}", {rt}),"#));
for alias in aliases {
lines.push(format!(r#" ("{alias}", {rt}),"#));
}
} }
lines.push(r#"].into());"#.to_string()); lines.push(r#"].into());"#.to_string());

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
export MISE_EXPERIMENTAL=1
assert "mise registry age" "aqua:FiloSottile/age asdf:threkk/asdf-age"
mise install age
assert_fail "ls $MISE_DATA_DIR/plugins/age"
mise uninstall age
MISE_DISABLE_BACKENDS=aqua mise install age
ls "$MISE_DATA_DIR/plugins/age"
mise uninstall age

21
e2e/tasks/test_task_deps Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
cat <<EOF >mise.toml
tasks.a.run = "echo a"
tasks.b.run = "echo b"
tasks.c.run = "echo c"
tasks.c.depends = ["a"]
tasks.b.depends = ["a"]
tasks.d.run = "echo d"
tasks.d.depends = ["c"]
tasks.d.wait_for = ["b"]
EOF
assert "mise run d" "a
c
d"
assert "mise run d ::: b" "[a] a
[b] b
[c] c
[d] d"

View File

@ -13,7 +13,6 @@ use crate::file::{display_path, remove_all, remove_all_with_warning};
use crate::install_context::InstallContext; use crate::install_context::InstallContext;
use crate::plugins::core::CORE_PLUGINS; use crate::plugins::core::CORE_PLUGINS;
use crate::plugins::{Plugin, PluginType, VERSION_REGEX}; use crate::plugins::{Plugin, PluginType, VERSION_REGEX};
use crate::registry::REGISTRY_BACKEND_MAP;
use crate::runtime_symlinks::is_runtime_symlink; use crate::runtime_symlinks::is_runtime_symlink;
use crate::toolset::{ use crate::toolset::{
install_state, is_outdated_version, ToolRequest, ToolSource, ToolVersion, Toolset, install_state, is_outdated_version, ToolRequest, ToolSource, ToolVersion, Toolset,
@ -177,15 +176,6 @@ pub trait Backend: Debug + Send + Sync {
.get_dependencies(tvr)? .get_dependencies(tvr)?
.into_iter() .into_iter()
.filter(|ba| self.ba() != ba) // prevent infinite loop .filter(|ba| self.ba() != ba) // prevent infinite loop
.flat_map(|ba| {
let short = ba.short.clone();
[ba].into_iter().chain(
REGISTRY_BACKEND_MAP
.get(short.as_str())
.cloned()
.unwrap_or_default(),
)
})
.collect(); .collect();
let dep_backends = deps let dep_backends = deps
.iter() .iter()

View File

@ -1,9 +1,9 @@
use crate::backend::backend_type::BackendType; use crate::backend::backend_type::BackendType;
use crate::backend::{unalias_backend, ABackend}; use crate::backend::{unalias_backend, ABackend};
use crate::config::CONFIG; use crate::config::CONFIG;
use crate::registry::{FULL_REGISTRY, REGISTRY_BACKEND_MAP}; use crate::registry::REGISTRY;
use crate::toolset::{install_state, parse_tool_options, ToolVersionOptions}; use crate::toolset::{install_state, parse_tool_options, ToolVersionOptions};
use crate::{backend, config, dirs, env}; use crate::{backend, config, dirs};
use contracts::requires; use contracts::requires;
use eyre::{bail, Result}; use eyre::{bail, Result};
use heck::ToKebabCase; use heck::ToKebabCase;
@ -36,13 +36,14 @@ pub struct BackendArg {
impl<A: AsRef<str>> From<A> for BackendArg { impl<A: AsRef<str>> From<A> for BackendArg {
fn from(s: A) -> Self { fn from(s: A) -> Self {
let s = s.as_ref(); let s = s.as_ref();
if let Some(ba) = REGISTRY_BACKEND_MAP let short = unalias_backend(s).to_string();
.get(unalias_backend(s)) if let Some(backend) = REGISTRY
.and_then(|rbm| rbm.first()) .get(&s)
.and_then(|rbm| rbm.backends().first().copied())
{ {
ba.clone() BackendArg::new(short, Some(backend.to_string()))
} else { } else {
Self::new(s.to_string(), None) Self::new(short, None)
} }
} }
} }
@ -146,8 +147,8 @@ impl BackendArg {
if self.uses_plugin() { if self.uses_plugin() {
return true; return true;
} }
if let Some(rt) = FULL_REGISTRY.get(self.short.as_str()) { if let Some(rt) = REGISTRY.get(self.short.as_str()) {
return rt.os.is_empty() || rt.os.contains(&env::consts::OS); return rt.is_supported_os();
} }
true true
} }

View File

@ -26,7 +26,7 @@ impl Registry {
pub fn run(self) -> Result<()> { pub fn run(self) -> Result<()> {
let filter_backend = |rt: &RegistryTool| { let filter_backend = |rt: &RegistryTool| {
if let Some(backend) = self.backend { if let Some(backend) = self.backend {
rt.backends rt.backends()
.iter() .iter()
.filter(|full| full.starts_with(&format!("{backend}:"))) .filter(|full| full.starts_with(&format!("{backend}:")))
.cloned() .cloned()
@ -37,7 +37,7 @@ impl Registry {
}; };
if let Some(name) = &self.name { if let Some(name) = &self.name {
if let Some(rt) = REGISTRY.get(name.as_str()) { if let Some(rt) = REGISTRY.get(name.as_str()) {
miseprintln!("{}", rt.backends.join(" ")); miseprintln!("{}", rt.backends().join(" "));
} else { } else {
bail!("tool not found in registry: {name}"); bail!("tool not found in registry: {name}");
} }

View File

@ -105,10 +105,19 @@ impl TestTool {
}; };
ts.install_arg_versions(&CONFIG, &opts)?; ts.install_arg_versions(&CONFIG, &opts)?;
ts.notify_if_versions_missing(); ts.notify_if_versions_missing();
let tv = &ts.versions.get(&tool.ba).unwrap().versions[0]; let tv = if let Some(tv) = ts
.versions
.get(&tool.ba)
.and_then(|tvl| tvl.versions.first())
{
tv.clone()
} else {
warn!("no versions found for {tool}");
return Ok(());
};
let backend = tv.backend()?; let backend = tv.backend()?;
let env = ts.env_with_path(&CONFIG)?; let env = ts.env_with_path(&CONFIG)?;
let which_cmd = backend.which(tv, cmd.split_whitespace().next().unwrap())?; let which_cmd = backend.which(&tv, cmd.split_whitespace().next().unwrap())?;
info!( info!(
"$ {which_cmd} {rest}", "$ {which_cmd} {rest}",
which_cmd = display_path(which_cmd.unwrap_or_default()), which_cmd = display_path(which_cmd.unwrap_or_default()),
@ -128,7 +137,7 @@ impl TestTool {
Some(0) => {} Some(0) => {}
Some(code) => { Some(code) => {
if code == 127 { if code == 127 {
let bin_dirs = backend.list_bin_paths(tv)?; let bin_dirs = backend.list_bin_paths(&tv)?;
for bin_dir in &bin_dirs { for bin_dir in &bin_dirs {
let bins = file::ls(bin_dir)? let bins = file::ls(bin_dir)?
.into_iter() .into_iter()

View File

@ -20,7 +20,7 @@ use crate::config::env_directive::{EnvDirective, PathEntry};
use crate::config::settings::SettingsPartial; use crate::config::settings::SettingsPartial;
use crate::config::{Alias, AliasMap}; use crate::config::{Alias, AliasMap};
use crate::file::{create_dir_all, display_path}; use crate::file::{create_dir_all, display_path};
use crate::registry::REGISTRY_BACKEND_MAP; use crate::registry::REGISTRY;
use crate::task::Task; use crate::task::Task;
use crate::tera::{get_tera, BASE_CONTEXT}; use crate::tera::{get_tera, BASE_CONTEXT};
use crate::toolset::{ToolRequest, ToolRequestSet, ToolSource, ToolVersionOptions}; use crate::toolset::{ToolRequest, ToolRequestSet, ToolSource, ToolVersionOptions};
@ -299,10 +299,7 @@ impl ConfigFile for MiseToml {
) -> eyre::Result<()> { ) -> eyre::Result<()> {
let existing = self.tools.entry(ba.clone()).or_default(); let existing = self.tools.entry(ba.clone()).or_default();
let output_empty_opts = |opts: &ToolVersionOptions| { let output_empty_opts = |opts: &ToolVersionOptions| {
if let Some(reg_ba) = REGISTRY_BACKEND_MAP if let Some(reg_ba) = REGISTRY.get(ba.short.as_str()).and_then(|b| b.ba()) {
.get(ba.short.as_str())
.and_then(|b| b.first())
{
if reg_ba.opts.as_ref().is_some_and(|o| o == opts) { if reg_ba.opts.as_ref().is_some_and(|o| o == opts) {
// in this case the options specified are the same as in the registry so output no options and rely on the defaults // in this case the options specified are the same as in the registry so output no options and rely on the defaults
return true; return true;

View File

@ -1,9 +1,8 @@
use crate::backend::backend_type::BackendType; use crate::backend::backend_type::BackendType;
use crate::cli::args::BackendArg; use crate::cli::args::BackendArg;
use crate::config::SETTINGS; use crate::config::SETTINGS;
use itertools::Itertools;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashSet};
use std::env::consts::OS; use std::env::consts::OS;
use std::iter::Iterator; use std::iter::Iterator;
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
@ -14,78 +13,60 @@ include!(concat!(env!("OUT_DIR"), "/registry.rs"));
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct RegistryTool { pub struct RegistryTool {
#[allow(unused)]
pub short: &'static str,
pub backends: Vec<&'static str>, pub backends: Vec<&'static str>,
#[allow(unused)]
pub aliases: &'static [&'static str], pub aliases: &'static [&'static str],
pub test: &'static Option<(&'static str, &'static str)>, pub test: &'static Option<(&'static str, &'static str)>,
pub os: &'static [&'static str], pub os: &'static [&'static str],
} }
// a rust representation of registry.toml impl RegistryTool {
pub static REGISTRY: Lazy<BTreeMap<&str, RegistryTool>> = Lazy::new(|| { pub fn backends(&self) -> Vec<&'static str> {
let mut backend_types = BackendType::iter() static BACKEND_TYPES: Lazy<HashSet<String>> = Lazy::new(|| {
.map(|b| b.to_string()) let mut backend_types = BackendType::iter()
.collect::<HashSet<_>>(); .map(|b| b.to_string())
for backend in &SETTINGS.disable_backends { .collect::<HashSet<_>>();
backend_types.remove(backend); for backend in &SETTINGS.disable_backends {
} backend_types.remove(backend);
if cfg!(windows) { }
backend_types.remove("asdf"); if cfg!(windows) {
} backend_types.remove("asdf");
if cfg!(unix) && !SETTINGS.experimental { }
backend_types.remove("aqua"); if cfg!(unix) && !SETTINGS.experimental {
backend_types.remove("aqua");
}
backend_types
});
self.backends
.iter()
.filter(|full| {
full.split(':')
.next()
.map_or(false, |b| BACKEND_TYPES.contains(b))
})
.copied()
.collect()
} }
let mut registry: BTreeMap<&str, RegistryTool> = FULL_REGISTRY pub fn is_supported_os(&self) -> bool {
.iter() self.os.is_empty() || self.os.contains(&OS)
.filter(|(_, tr)| tr.os.is_empty() || tr.os.contains(&OS)) }
.map(|(short, tr)| {
let mut tr = tr.clone();
tr.backends = tr
.backends
.iter()
.filter(|full| {
full.split(':')
.next()
.map_or(false, |b| backend_types.contains(b))
})
.copied()
.collect();
(*short, tr)
})
.filter(|(_, tr)| !tr.backends.is_empty())
.collect();
let aliased = registry pub fn ba(&self) -> Option<BackendArg> {
.values() self.backends()
.flat_map(|tool| tool.aliases.iter().map(move |alias| (*alias, tool.clone()))) .first()
.collect_vec(); .map(|f| BackendArg::new(self.short.to_string(), Some(f.to_string())))
}
registry.extend(aliased); }
registry
});
pub static REGISTRY_BACKEND_MAP: Lazy<HashMap<&'static str, Vec<BackendArg>>> = Lazy::new(|| {
REGISTRY
.iter()
.map(|(short, tool)| {
(
*short,
tool.backends
.iter()
.map(|f| BackendArg::new(short.to_string(), Some(f.to_string())))
.collect(),
)
})
.collect()
});
pub fn is_trusted_plugin(name: &str, remote: &str) -> bool { pub fn is_trusted_plugin(name: &str, remote: &str) -> bool {
let normalized_url = normalize_remote(remote).unwrap_or("INVALID_URL".into()); let normalized_url = normalize_remote(remote).unwrap_or("INVALID_URL".into());
let is_shorthand = REGISTRY let is_shorthand = REGISTRY
.get(name) .get(name)
.and_then(|tool| tool.backends.first()) .and_then(|tool| tool.backends().first().copied())
.map(|full| full_to_url(full)) .map(full_to_url)
.is_some_and(|s| normalize_remote(&s).unwrap_or_default() == normalized_url); .is_some_and(|s| normalize_remote(&s).unwrap_or_default() == normalized_url);
let is_mise_url = normalized_url.starts_with("github.com/mise-plugins/"); let is_mise_url = normalized_url.starts_with("github.com/mise-plugins/");

View File

@ -20,7 +20,7 @@ pub fn get_shorthands(settings: &Settings) -> Shorthands {
.map(|(id, rt)| { .map(|(id, rt)| {
( (
id.to_string(), id.to_string(),
rt.backends rt.backends()
.iter() .iter()
.filter(|f| f.starts_with("asdf:") || f.starts_with("vfox:")) .filter(|f| f.starts_with("asdf:") || f.starts_with("vfox:"))
.map(|f| f.to_string()) .map(|f| f.to_string())

View File

@ -137,8 +137,8 @@ pub fn short_to_full(short: &str, meta_full: Option<String>) -> Result<Option<St
Ok(Some(full)) Ok(Some(full))
} else if let Some(full) = REGISTRY } else if let Some(full) = REGISTRY
.get(short) .get(short)
.map(|r| &r.backends) .map(|r| r.backends())
.unwrap_or(&EMPTY_VEC) .unwrap_or_default()
.first() .first()
{ {
Ok(Some(full.to_string())) Ok(Some(full.to_string()))
@ -245,8 +245,6 @@ pub fn incomplete_file_path(short: &str, v: &str) -> PathBuf {
.join("incomplete") .join("incomplete")
} }
static EMPTY_VEC: Vec<&'static str> = vec![];
pub fn reset() { pub fn reset() {
*INSTALL_STATE_PLUGINS.lock().unwrap() = None; *INSTALL_STATE_PLUGINS.lock().unwrap() = None;
*INSTALL_STATE_TOOLS.lock().unwrap() = None; *INSTALL_STATE_TOOLS.lock().unwrap() = None;

View File

@ -91,14 +91,14 @@ impl Toolset {
} }
} }
pub fn add_version(&mut self, tvr: ToolRequest) { pub fn add_version(&mut self, tvr: ToolRequest) {
let fa = tvr.ba(); let ba = tvr.ba();
if self.is_disabled(fa) { if self.is_disabled(ba) {
return; return;
} }
let tvl = self let tvl = self
.versions .versions
.entry(tvr.ba().clone()) .entry(tvr.ba().clone())
.or_insert_with(|| ToolVersionList::new(fa.clone(), self.source.clone().unwrap())); .or_insert_with(|| ToolVersionList::new(ba.clone(), self.source.clone().unwrap()));
tvl.requests.push(tvr); tvl.requests.push(tvr);
} }
pub fn merge(&mut self, other: Toolset) { pub fn merge(&mut self, other: Toolset) {
@ -611,9 +611,8 @@ impl Toolset {
); );
} }
fn is_disabled(&self, fa: &BackendArg) -> bool { fn is_disabled(&self, ba: &BackendArg) -> bool {
let fa = fa.to_string(); !ba.is_os_supported() || SETTINGS.disable_tools.contains(&ba.short)
SETTINGS.disable_tools.iter().any(|s| s == &fa)
} }
} }

View File

@ -30,7 +30,7 @@ pub fn list_versions(ba: &BackendArg) -> eyre::Result<Option<Vec<String>>> {
let normalized_remote = normalize_remote(&remote_url).unwrap_or("INVALID_URL".into()); let normalized_remote = normalize_remote(&remote_url).unwrap_or("INVALID_URL".into());
let shorthand_remote = REGISTRY let shorthand_remote = REGISTRY
.get(plugin.name()) .get(plugin.name())
.map(|rt| registry::full_to_url(rt.backends[0])) .and_then(|rt| rt.backends().first().map(|b| registry::full_to_url(b)))
.unwrap_or_default(); .unwrap_or_default();
if normalized_remote != normalize_remote(&shorthand_remote).unwrap_or_default() { if normalized_remote != normalize_remote(&shorthand_remote).unwrap_or_default() {
trace!( trace!(