Skip to content

Commit

Permalink
feat: added os option to mise.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 16, 2024
1 parent a47fc30 commit 860aa80
Show file tree
Hide file tree
Showing 23 changed files with 307 additions and 101 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ jobs:
- run: npm install
- run: mise run render
- run: mise run lint-fix
- run: mise run snapshots
- uses: autofix-ci/[email protected]
if: ${{ always() }}
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ jobs:
- run: cargo test
continue-on-error: true
- run: mise install
continue-on-error: true
- run: mise test-tool --all
continue-on-error: true
windows-e2e:
Expand Down
4 changes: 2 additions & 2 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shfmt = "3"
jq = "latest"
cargo-binstall = "latest"
"cargo:cargo-edit" = "latest"
"cargo:cargo-show" = "latest"
"cargo:cargo-show" = {version = "latest", os = ["linux", "macos"]}
"cargo:cargo-insta" = "latest"
"cargo:git-cliff" = "latest"
"npm:markdownlint-cli" = "latest"
Expand All @@ -19,7 +19,7 @@ direnv = "latest"
actionlint = "latest"
ripgrep = "latest"
"pipx:toml-sort" = "latest"
"cargo:usage-cli" = "1.3"
"cargo:usage-cli" = {version = "1.3", os = ["linux", "macos"]}
#python = { version = "latest", virtualenv = "{{env.HOME}}/.cache/venv" }

[task_config]
Expand Down
1 change: 1 addition & 0 deletions registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ updatecli.backends = ["aqua:updatecli/updatecli", "asdf:updatecli/asdf-updatecli
upt.backends = ["asdf:ORCID/asdf-upt"]
upx.backends = ["asdf:jimmidyson/asdf-upx"]
usage.backends = ["ubi:jdx/usage", "asdf:jdx/mise-usage"]
usage.os = ["linux", "macos"]
usql.backends = ["aqua:xo/usql", "asdf:itspngu/asdf-usql"]
uv.backends = ["aqua:astral-sh/uv", "asdf:asdf-community/asdf-uv"]
v.backends = ["asdf:jthegedus/asdf-v"]
Expand Down
23 changes: 21 additions & 2 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,35 @@
"version": {
"description": "version of the tool to install",
"type": "string"
},
"os": {
"oneOf": [
{
"description": "operating system to install on",
"type": "array"
},
{
"description": "option to pass to tool",
"type": "string"
}
]
}
},
"required": ["version"],
"type": "object"
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "string"
}
]
}
}
]
}
},
"additionalProperties": false,
"description": "config file for mise version manager (.mise.toml)",
"description": "config file for mise version manager (mise.toml)",
"properties": {
"alias": {
"additionalProperties": {
Expand Down
23 changes: 21 additions & 2 deletions schema/mise.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,37 @@
"version": {
"description": "version of the tool to install",
"type": "string"
},
"os": {
"oneOf": [
{
"description": "operating system to install on",
"type": "array"
},
{
"description": "option to pass to tool",
"type": "string"
}
]
}
},
"required": [
"version"
],
"type": "object"
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "string"
}
]
}
}
]
}
},
"additionalProperties": false,
"description": "config file for mise version manager (.mise.toml)",
"description": "config file for mise version manager (mise.toml)",
"properties": {
"alias": {
"additionalProperties": {
Expand Down
8 changes: 4 additions & 4 deletions src/backend/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl AsdfBackend {

fn fetch_bin_paths(&self, tv: &ToolVersion) -> Result<Vec<String>> {
let list_bin_paths = self.plugin_path.join("bin/list-bin-paths");
let bin_paths = if matches!(tv.request, ToolRequest::System(..)) {
let bin_paths = if matches!(tv.request, ToolRequest::System { .. }) {
Vec::new()
} else if list_bin_paths.exists() {
let sm = self.script_man_for_tv(tv)?;
Expand Down Expand Up @@ -184,9 +184,9 @@ impl AsdfBackend {
let install_type = match &tv.request {
ToolRequest::Version { .. } | ToolRequest::Prefix { .. } => "version",
ToolRequest::Ref { .. } => "ref",
ToolRequest::Path(..) => "path",
ToolRequest::Path { .. } => "path",
ToolRequest::Sub { .. } => "sub",
ToolRequest::System(..) => {
ToolRequest::System { .. } => {
panic!("should not be called for system tool")
}
};
Expand Down Expand Up @@ -384,7 +384,7 @@ impl Backend for AsdfBackend {
ts: &Toolset,
tv: &ToolVersion,
) -> eyre::Result<BTreeMap<String, String>> {
if matches!(tv.request, ToolRequest::System(..)) {
if matches!(tv.request, ToolRequest::System { .. }) {
return Ok(BTreeMap::new());
}
if !self.plugin.script_man.script_exists(&ExecEnv) || *env::__MISE_SCRIPT {
Expand Down
43 changes: 32 additions & 11 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ pub trait Backend: Debug + Send + Sync {
.collect::<Vec<ABackend>>();
for dep in dep_backends {
// TODO: pass the right tvr
let tvr = ToolRequest::System(dep.id().into(), ToolSource::Unknown);
let tvr = ToolRequest::System {
backend: dep.id().into(),
source: ToolSource::Unknown,
os: None,
};
deps.extend(dep.get_all_dependencies(&tvr)?);
}
Ok(deps.into_iter().collect())
Expand Down Expand Up @@ -242,7 +246,7 @@ pub trait Backend: Debug + Send + Sync {
}
fn is_version_installed(&self, tv: &ToolVersion, check_symlink: bool) -> bool {
match tv.request {
ToolRequest::System(..) => true,
ToolRequest::System { .. } => true,
_ => {
let check_path = |install_path: &Path| {
let is_installed = install_path.exists();
Expand Down Expand Up @@ -338,7 +342,11 @@ pub trait Backend: Debug + Send + Sync {

fn ensure_dependencies_installed(&self) -> eyre::Result<()> {
let deps = self
.get_all_dependencies(&ToolRequest::System(self.id().into(), ToolSource::Unknown))?
.get_all_dependencies(&ToolRequest::System {
backend: self.id().into(),
source: ToolSource::Unknown,
os: None,
})?
.into_iter()
.collect::<HashSet<_>>();
if !deps.is_empty() {
Expand Down Expand Up @@ -474,7 +482,7 @@ pub trait Backend: Debug + Send + Sync {
}
fn list_bin_paths(&self, tv: &ToolVersion) -> eyre::Result<Vec<PathBuf>> {
match tv.request {
ToolRequest::System(..) => Ok(vec![]),
ToolRequest::System { .. } => Ok(vec![]),
_ => Ok(vec![tv.install_path().join("bin")]),
}
}
Expand All @@ -494,9 +502,21 @@ pub trait Backend: Debug + Send + Sync {
.into_iter()
.filter(|p| p.parent().is_some());
for bin_path in bin_paths {
let bin_path = bin_path.join(bin_name);
if bin_path.exists() {
return Ok(Some(bin_path));
let paths_with_ext = if cfg!(windows) {
vec![
bin_path.clone(),
bin_path.join(bin_name).with_extension("exe"),
bin_path.join(bin_name).with_extension("cmd"),
bin_path.join(bin_name).with_extension("bat"),
bin_path.join(bin_name).with_extension("ps1"),
]
} else {
vec![bin_path.join(bin_name)]
};
for bin_path in paths_with_ext {
if bin_path.exists() && file::is_executable(&bin_path) {
return Ok(Some(bin_path));
}
}
}
Ok(None)
Expand Down Expand Up @@ -531,10 +551,11 @@ pub trait Backend: Debug + Send + Sync {
fn dependency_toolset(&self) -> eyre::Result<Toolset> {
let config = Config::get();
let dependencies = self
.get_all_dependencies(&ToolRequest::System(
self.name().into(),
ToolSource::Unknown,
))?
.get_all_dependencies(&ToolRequest::System {
backend: self.name().into(),
source: ToolSource::Unknown,
os: None,
})?
.into_iter()
.collect();
let mut ts: Toolset = config
Expand Down
1 change: 1 addition & 0 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl Install {
let tvr = ToolRequest::Version {
backend: ta.ba.clone(),
version: "latest".into(),
os: None,
options: ta.opts.clone().unwrap_or(Default::default()),
source: ToolSource::Argument,
};
Expand Down
Loading

0 comments on commit 860aa80

Please sign in to comment.