mirror of https://github.com/jdx/mise
fix: disable_backends on windows (#3052)
This commit is contained in:
parent
cb9d81da9e
commit
773652abea
12
build.rs
12
build.rs
|
@ -20,7 +20,7 @@ fn codegen_registry() {
|
|||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
let dest_path = Path::new(&out_dir).join("registry.rs");
|
||||
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()];
|
||||
|
||||
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
|
||||
})
|
||||
.unwrap_or_default();
|
||||
lines.push(format!(
|
||||
r#" ("{short}", RegistryTool{{backends: vec!["{backends}"], aliases: &[{aliases}], test: &{test}, os: &[{os}]}}),"#,
|
||||
let rt = format!(
|
||||
r#"RegistryTool{{short: "{short}", backends: vec!["{backends}"], aliases: &[{aliases}], test: &{test}, os: &[{os}]}}"#,
|
||||
backends = fulls.join("\", \""),
|
||||
aliases = aliases
|
||||
.iter()
|
||||
|
@ -94,7 +94,11 @@ pub static FULL_REGISTRY: Lazy<BTreeMap<&'static str, RegistryTool>> = Lazy::new
|
|||
.map(|o| format!("\"{o}\""))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
));
|
||||
);
|
||||
lines.push(format!(r#" ("{short}", {rt}),"#));
|
||||
for alias in aliases {
|
||||
lines.push(format!(r#" ("{alias}", {rt}),"#));
|
||||
}
|
||||
}
|
||||
lines.push(r#"].into());"#.to_string());
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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"
|
|
@ -13,7 +13,6 @@ use crate::file::{display_path, remove_all, remove_all_with_warning};
|
|||
use crate::install_context::InstallContext;
|
||||
use crate::plugins::core::CORE_PLUGINS;
|
||||
use crate::plugins::{Plugin, PluginType, VERSION_REGEX};
|
||||
use crate::registry::REGISTRY_BACKEND_MAP;
|
||||
use crate::runtime_symlinks::is_runtime_symlink;
|
||||
use crate::toolset::{
|
||||
install_state, is_outdated_version, ToolRequest, ToolSource, ToolVersion, Toolset,
|
||||
|
@ -177,15 +176,6 @@ pub trait Backend: Debug + Send + Sync {
|
|||
.get_dependencies(tvr)?
|
||||
.into_iter()
|
||||
.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();
|
||||
let dep_backends = deps
|
||||
.iter()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::backend::backend_type::BackendType;
|
||||
use crate::backend::{unalias_backend, ABackend};
|
||||
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::{backend, config, dirs, env};
|
||||
use crate::{backend, config, dirs};
|
||||
use contracts::requires;
|
||||
use eyre::{bail, Result};
|
||||
use heck::ToKebabCase;
|
||||
|
@ -36,13 +36,14 @@ pub struct BackendArg {
|
|||
impl<A: AsRef<str>> From<A> for BackendArg {
|
||||
fn from(s: A) -> Self {
|
||||
let s = s.as_ref();
|
||||
if let Some(ba) = REGISTRY_BACKEND_MAP
|
||||
.get(unalias_backend(s))
|
||||
.and_then(|rbm| rbm.first())
|
||||
let short = unalias_backend(s).to_string();
|
||||
if let Some(backend) = REGISTRY
|
||||
.get(&s)
|
||||
.and_then(|rbm| rbm.backends().first().copied())
|
||||
{
|
||||
ba.clone()
|
||||
BackendArg::new(short, Some(backend.to_string()))
|
||||
} else {
|
||||
Self::new(s.to_string(), None)
|
||||
Self::new(short, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,8 +147,8 @@ impl BackendArg {
|
|||
if self.uses_plugin() {
|
||||
return true;
|
||||
}
|
||||
if let Some(rt) = FULL_REGISTRY.get(self.short.as_str()) {
|
||||
return rt.os.is_empty() || rt.os.contains(&env::consts::OS);
|
||||
if let Some(rt) = REGISTRY.get(self.short.as_str()) {
|
||||
return rt.is_supported_os();
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ impl Registry {
|
|||
pub fn run(self) -> Result<()> {
|
||||
let filter_backend = |rt: &RegistryTool| {
|
||||
if let Some(backend) = self.backend {
|
||||
rt.backends
|
||||
rt.backends()
|
||||
.iter()
|
||||
.filter(|full| full.starts_with(&format!("{backend}:")))
|
||||
.cloned()
|
||||
|
@ -37,7 +37,7 @@ impl Registry {
|
|||
};
|
||||
if let Some(name) = &self.name {
|
||||
if let Some(rt) = REGISTRY.get(name.as_str()) {
|
||||
miseprintln!("{}", rt.backends.join(" "));
|
||||
miseprintln!("{}", rt.backends().join(" "));
|
||||
} else {
|
||||
bail!("tool not found in registry: {name}");
|
||||
}
|
||||
|
|
|
@ -105,10 +105,19 @@ impl TestTool {
|
|||
};
|
||||
ts.install_arg_versions(&CONFIG, &opts)?;
|
||||
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 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!(
|
||||
"$ {which_cmd} {rest}",
|
||||
which_cmd = display_path(which_cmd.unwrap_or_default()),
|
||||
|
@ -128,7 +137,7 @@ impl TestTool {
|
|||
Some(0) => {}
|
||||
Some(code) => {
|
||||
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 {
|
||||
let bins = file::ls(bin_dir)?
|
||||
.into_iter()
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::config::env_directive::{EnvDirective, PathEntry};
|
|||
use crate::config::settings::SettingsPartial;
|
||||
use crate::config::{Alias, AliasMap};
|
||||
use crate::file::{create_dir_all, display_path};
|
||||
use crate::registry::REGISTRY_BACKEND_MAP;
|
||||
use crate::registry::REGISTRY;
|
||||
use crate::task::Task;
|
||||
use crate::tera::{get_tera, BASE_CONTEXT};
|
||||
use crate::toolset::{ToolRequest, ToolRequestSet, ToolSource, ToolVersionOptions};
|
||||
|
@ -299,10 +299,7 @@ impl ConfigFile for MiseToml {
|
|||
) -> eyre::Result<()> {
|
||||
let existing = self.tools.entry(ba.clone()).or_default();
|
||||
let output_empty_opts = |opts: &ToolVersionOptions| {
|
||||
if let Some(reg_ba) = REGISTRY_BACKEND_MAP
|
||||
.get(ba.short.as_str())
|
||||
.and_then(|b| b.first())
|
||||
{
|
||||
if let Some(reg_ba) = REGISTRY.get(ba.short.as_str()).and_then(|b| b.ba()) {
|
||||
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
|
||||
return true;
|
||||
|
|
101
src/registry.rs
101
src/registry.rs
|
@ -1,9 +1,8 @@
|
|||
use crate::backend::backend_type::BackendType;
|
||||
use crate::cli::args::BackendArg;
|
||||
use crate::config::SETTINGS;
|
||||
use itertools::Itertools;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::env::consts::OS;
|
||||
use std::iter::Iterator;
|
||||
use strum::IntoEnumIterator;
|
||||
|
@ -14,78 +13,60 @@ include!(concat!(env!("OUT_DIR"), "/registry.rs"));
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RegistryTool {
|
||||
#[allow(unused)]
|
||||
pub short: &'static str,
|
||||
pub backends: Vec<&'static str>,
|
||||
#[allow(unused)]
|
||||
pub aliases: &'static [&'static str],
|
||||
pub test: &'static Option<(&'static str, &'static str)>,
|
||||
pub os: &'static [&'static str],
|
||||
}
|
||||
|
||||
// a rust representation of registry.toml
|
||||
pub static REGISTRY: Lazy<BTreeMap<&str, RegistryTool>> = Lazy::new(|| {
|
||||
let mut backend_types = BackendType::iter()
|
||||
.map(|b| b.to_string())
|
||||
.collect::<HashSet<_>>();
|
||||
for backend in &SETTINGS.disable_backends {
|
||||
backend_types.remove(backend);
|
||||
}
|
||||
if cfg!(windows) {
|
||||
backend_types.remove("asdf");
|
||||
}
|
||||
if cfg!(unix) && !SETTINGS.experimental {
|
||||
backend_types.remove("aqua");
|
||||
impl RegistryTool {
|
||||
pub fn backends(&self) -> Vec<&'static str> {
|
||||
static BACKEND_TYPES: Lazy<HashSet<String>> = Lazy::new(|| {
|
||||
let mut backend_types = BackendType::iter()
|
||||
.map(|b| b.to_string())
|
||||
.collect::<HashSet<_>>();
|
||||
for backend in &SETTINGS.disable_backends {
|
||||
backend_types.remove(backend);
|
||||
}
|
||||
if cfg!(windows) {
|
||||
backend_types.remove("asdf");
|
||||
}
|
||||
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
|
||||
.iter()
|
||||
.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();
|
||||
pub fn is_supported_os(&self) -> bool {
|
||||
self.os.is_empty() || self.os.contains(&OS)
|
||||
}
|
||||
|
||||
let aliased = registry
|
||||
.values()
|
||||
.flat_map(|tool| tool.aliases.iter().map(move |alias| (*alias, tool.clone())))
|
||||
.collect_vec();
|
||||
|
||||
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 ba(&self) -> Option<BackendArg> {
|
||||
self.backends()
|
||||
.first()
|
||||
.map(|f| BackendArg::new(self.short.to_string(), Some(f.to_string())))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_trusted_plugin(name: &str, remote: &str) -> bool {
|
||||
let normalized_url = normalize_remote(remote).unwrap_or("INVALID_URL".into());
|
||||
let is_shorthand = REGISTRY
|
||||
.get(name)
|
||||
.and_then(|tool| tool.backends.first())
|
||||
.map(|full| full_to_url(full))
|
||||
.and_then(|tool| tool.backends().first().copied())
|
||||
.map(full_to_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/");
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ pub fn get_shorthands(settings: &Settings) -> Shorthands {
|
|||
.map(|(id, rt)| {
|
||||
(
|
||||
id.to_string(),
|
||||
rt.backends
|
||||
rt.backends()
|
||||
.iter()
|
||||
.filter(|f| f.starts_with("asdf:") || f.starts_with("vfox:"))
|
||||
.map(|f| f.to_string())
|
||||
|
|
|
@ -137,8 +137,8 @@ pub fn short_to_full(short: &str, meta_full: Option<String>) -> Result<Option<St
|
|||
Ok(Some(full))
|
||||
} else if let Some(full) = REGISTRY
|
||||
.get(short)
|
||||
.map(|r| &r.backends)
|
||||
.unwrap_or(&EMPTY_VEC)
|
||||
.map(|r| r.backends())
|
||||
.unwrap_or_default()
|
||||
.first()
|
||||
{
|
||||
Ok(Some(full.to_string()))
|
||||
|
@ -245,8 +245,6 @@ pub fn incomplete_file_path(short: &str, v: &str) -> PathBuf {
|
|||
.join("incomplete")
|
||||
}
|
||||
|
||||
static EMPTY_VEC: Vec<&'static str> = vec![];
|
||||
|
||||
pub fn reset() {
|
||||
*INSTALL_STATE_PLUGINS.lock().unwrap() = None;
|
||||
*INSTALL_STATE_TOOLS.lock().unwrap() = None;
|
||||
|
|
|
@ -91,14 +91,14 @@ impl Toolset {
|
|||
}
|
||||
}
|
||||
pub fn add_version(&mut self, tvr: ToolRequest) {
|
||||
let fa = tvr.ba();
|
||||
if self.is_disabled(fa) {
|
||||
let ba = tvr.ba();
|
||||
if self.is_disabled(ba) {
|
||||
return;
|
||||
}
|
||||
let tvl = self
|
||||
.versions
|
||||
.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);
|
||||
}
|
||||
pub fn merge(&mut self, other: Toolset) {
|
||||
|
@ -611,9 +611,8 @@ impl Toolset {
|
|||
);
|
||||
}
|
||||
|
||||
fn is_disabled(&self, fa: &BackendArg) -> bool {
|
||||
let fa = fa.to_string();
|
||||
SETTINGS.disable_tools.iter().any(|s| s == &fa)
|
||||
fn is_disabled(&self, ba: &BackendArg) -> bool {
|
||||
!ba.is_os_supported() || SETTINGS.disable_tools.contains(&ba.short)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 shorthand_remote = REGISTRY
|
||||
.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();
|
||||
if normalized_remote != normalize_remote(&shorthand_remote).unwrap_or_default() {
|
||||
trace!(
|
||||
|
|
Loading…
Reference in New Issue