-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Elixir <Badge type="warning" text="experimental" /> | ||
|
||
## Usage | ||
|
||
Use the latest stable version of elixir: | ||
|
||
```sh | ||
mise use -g erlang elixir | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
assert "mise use erlang@27.2" | ||
assert_contains "mise x -- erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell" "27" | ||
assert_contains "mise x elixir@1.17.3 -- elixir --version 2>&1" "Elixir 1.17.3" | ||
assert_contains "mise x elixir@1.17.3 -- mix --version 2>&1" "Mix 1.17.3" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use crate::backend::Backend; | ||
use crate::cli::args::BackendArg; | ||
use crate::cmd::CmdLineRunner; | ||
use crate::http::{HTTP, HTTP_FETCH}; | ||
use crate::install_context::InstallContext; | ||
use crate::plugins::VERSION_REGEX; | ||
use crate::toolset::ToolVersion; | ||
use crate::ui::progress_report::SingleReport; | ||
use crate::{file, plugins}; | ||
use eyre::Result; | ||
use itertools::Itertools; | ||
use versions::Versioning; | ||
use xx::regex; | ||
|
||
#[derive(Debug)] | ||
pub struct ElixirPlugin { | ||
ba: BackendArg, | ||
} | ||
|
||
impl ElixirPlugin { | ||
pub fn new() -> Self { | ||
Self { | ||
ba: plugins::core::new_backend_arg("elixir"), | ||
} | ||
} | ||
|
||
fn elixir_bin(&self, tv: &ToolVersion) -> PathBuf { | ||
tv.install_path().join("bin").join("elixir") | ||
} | ||
|
||
fn test_elixir(&self, ctx: &InstallContext, tv: &ToolVersion) -> Result<()> { | ||
ctx.pr.set_message("elixir --version".into()); | ||
CmdLineRunner::new(self.elixir_bin(tv)) | ||
.with_pr(ctx.pr.as_ref()) | ||
.envs(self.dependency_env()?) | ||
.arg("--version") | ||
.execute() | ||
} | ||
|
||
fn download(&self, tv: &ToolVersion, pr: &dyn SingleReport) -> Result<PathBuf> { | ||
let version = &tv.version; | ||
let url = format!("https://builds.hex.pm/builds/elixir/v{version}.zip"); | ||
|
||
let filename = url.split('/').last().unwrap(); | ||
let tarball_path = tv.download_path().join(filename); | ||
|
||
pr.set_message(format!("download {filename}")); | ||
if !tarball_path.exists() { | ||
HTTP.download_file(&url, &tarball_path, Some(pr))?; | ||
} | ||
|
||
Ok(tarball_path) | ||
} | ||
|
||
fn install(&self, ctx: &InstallContext, tv: &ToolVersion, tarball_path: &Path) -> Result<()> { | ||
let filename = tarball_path.file_name().unwrap().to_string_lossy(); | ||
ctx.pr.set_message(format!("extract {filename}")); | ||
file::remove_all(tv.install_path())?; | ||
file::unzip(tarball_path, &tv.install_path())?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn verify(&self, ctx: &InstallContext, tv: &ToolVersion) -> Result<()> { | ||
self.test_elixir(ctx, tv) | ||
} | ||
} | ||
|
||
impl Backend for ElixirPlugin { | ||
fn ba(&self) -> &BackendArg { | ||
&self.ba | ||
} | ||
|
||
fn _list_remote_versions(&self) -> Result<Vec<String>> { | ||
let versions: Vec<String> = HTTP_FETCH | ||
.get_text("https://builds.hex.pm/builds/elixir/builds.txt")? | ||
.lines() | ||
.unique() | ||
.filter_map(|s| s.split_once(' ').map(|(v, _)| v.trim_start_matches('v'))) | ||
.filter(|s| regex!(r"^[0-9]+\.[0-9]+\.[0-9]").is_match(s)) | ||
.sorted_by_cached_key(|s| { | ||
( | ||
Versioning::new(s.split_once('-').map(|(v, _)| v).unwrap_or(s)), | ||
!VERSION_REGEX.is_match(s), | ||
s.contains("-otp-"), | ||
Versioning::new(s), | ||
s.to_string(), | ||
) | ||
}) | ||
.map(|s| s.to_string()) | ||
.collect(); | ||
Ok(versions) | ||
} | ||
|
||
fn get_dependencies(&self) -> Result<Vec<&str>> { | ||
Ok(vec!["erlang"]) | ||
} | ||
|
||
fn install_version_(&self, ctx: &InstallContext, mut tv: ToolVersion) -> Result<ToolVersion> { | ||
let tarball_path = self.download(&tv, ctx.pr.as_ref())?; | ||
self.verify_checksum(ctx, &mut tv, &tarball_path)?; | ||
self.install(ctx, &tv, &tarball_path)?; | ||
self.verify(ctx, &tv)?; | ||
Ok(tv) | ||
} | ||
|
||
fn list_bin_paths(&self, tv: &ToolVersion) -> Result<Vec<PathBuf>> { | ||
Ok(["bin", ".mix/escripts"] | ||
.iter() | ||
.map(|p| tv.install_path().join(p)) | ||
.collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters