Skip to content

Commit

Permalink
erlang core plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 13, 2023
1 parent 05c6962 commit 7b19f91
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 20 deletions.
24 changes: 6 additions & 18 deletions .github/workflows/test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,18 @@ jobs:
- plugin: direnv
command: rtx exec direnv@latest -- direnv --version
- plugin: erlang
command: |
set -eux
rtx plugins install erlang
# replace FOO with BAR
sed -i 's/>\/dev\/null 2>&1//g' ~/.local/share/rtx/plugins/erlang/bin/install
cat ~/.local/share/rtx/plugins/erlang/bin/install
rtx exec erlang@latest -- erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell
command: rtx exec erlang@latest -- erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell
env:
RTX_EXPERIMENTAL: 1
- plugin: elixir
command: |
rtx plugins install erlang
rtx use --global erlang@latest
eval "$(rtx env bash)"
rtx use --global elixir@latest
eval "$(rtx env bash)"
rtx exec -- elixir --version
env:
RTX_EXPERIMENTAL: 1
- plugin: golang
command: rtx exec golang@latest -- go version
- plugin: java
Expand Down Expand Up @@ -99,16 +96,7 @@ jobs:
command: rtx exec postgres@latest -- psql -V
steps:
- name: apt-get
run: |
sudo apt-get update
sudo apt-get install zsh fish direnv re2c libcurl4-openssl-dev libgd-dev \
libonig-dev autoconf bison build-essential curl gettext git libgd-dev \
libcurl4-openssl-dev libedit-dev libicu-dev libjpeg-dev libmysqlclient-dev \
libonig-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev \
libxml2-dev libzip-dev openssl pkg-config re2c zlib1g-dev libwxgtk-webview3.0-gtk3-dev \
build-essential autoconf m4 libncurses5-dev libwxgtk3.0-gtk3-dev libwxgtk-webview3.0-gtk3-dev \
libgl1-mesa-dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop libxml2-utils \
libncurses-dev openjdk-11-jdk
run: sudo apt-get update; sudo apt-get install zsh fish direnv re2c libcurl4-openssl-dev libgd-dev libonig-dev autoconf bison build-essential curl gettext git libgd-dev libcurl4-openssl-dev libedit-dev libicu-dev libjpeg-dev libmysqlclient-dev libonig-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev libxml2-dev libzip-dev openssl pkg-config re2c zlib1g-dev libwxgtk-webview3.0-gtk3-dev
- uses: actions/download-artifact@v3
with:
name: tarball-x86_64-unknown-linux-gnu
Expand Down
8 changes: 8 additions & 0 deletions e2e/test_erlang
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
# shellcheck source-path=SCRIPTDIR
source "$(dirname "$0")/assert.sh"

export RTX_EXPERIMENTAL=1

assert_contains "rtx x [email protected] -- erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell" "XXXXXXXX"
116 changes: 116 additions & 0 deletions src/plugins/core/erlang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use std::path::PathBuf;

use color_eyre::eyre::Result;

use crate::config::Settings;

use crate::file::display_path;
use crate::install_context::InstallContext;
use crate::lock_file::LockFile;
use crate::plugins::core::CorePlugin;
use crate::plugins::{Plugin, HTTP};
use crate::toolset::ToolVersionRequest;
use crate::{cmd, file};

#[derive(Debug)]

Check warning on line 15 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L15

Added line #L15 was not covered by tests
pub struct ErlangPlugin {
core: CorePlugin,
}

const KERL_VERSION: &str = "4.0.0";

impl ErlangPlugin {
pub fn new() -> Self {
Self {
core: CorePlugin::new("erlang"),
}
}

fn kerl_path(&self) -> PathBuf {
self.core.cache_path.join(format!("kerl-{}", KERL_VERSION))
}

Check warning on line 31 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L29-L31

Added lines #L29 - L31 were not covered by tests

fn lock_build_tool(&self) -> Result<fslock::LockFile> {
LockFile::new(&self.kerl_path())
.with_callback(|l| {
trace!("install_or_update_kerl {}", l.display());
})
.lock()
}

Check warning on line 39 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L33-L39

Added lines #L33 - L39 were not covered by tests

fn update_kerl(&self) -> Result<()> {
let _lock = self.lock_build_tool();
if self.kerl_path().exists() {
return Ok(());
}
self.install_kerl()
}

Check warning on line 47 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L41-L47

Added lines #L41 - L47 were not covered by tests

fn install_kerl(&self) -> Result<()> {
debug!("Installing kerl to {}", display_path(&self.kerl_path()));
HTTP.download_file(
format!("https://raw.githubusercontent.com/kerl/kerl/{KERL_VERSION}/kerl"),
&self.kerl_path(),
)?;
file::make_executable(&self.kerl_path())?;
Ok(())
}

Check warning on line 57 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L49-L57

Added lines #L49 - L57 were not covered by tests

fn fetch_remote_versions(&self) -> Result<Vec<String>> {
match self.core.fetch_remote_versions_from_rtx() {
Ok(Some(versions)) => return Ok(versions),
Ok(None) => {}
Err(e) => warn!("failed to fetch remote versions: {}", e),

Check warning on line 63 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L60-L63

Added lines #L60 - L63 were not covered by tests
}
self.update_kerl()?;
let versions = CorePlugin::run_fetch_task_with_timeout(move || {
dbg!(self.kerl_path());
let output = cmd!(self.kerl_path(), "list", "releases", "all").read()?;
let versions = output
.split('\n')
.filter(|s| regex!(r"^[0-9].+$").is_match(s))
.map(|s| s.to_string())
.collect();
Ok(versions)
})?;
Ok(versions)
}

Check warning on line 77 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L65-L77

Added lines #L65 - L77 were not covered by tests
}

impl Plugin for ErlangPlugin {
fn name(&self) -> &str {
self.core.name
}

fn list_remote_versions(&self, _settings: &Settings) -> Result<Vec<String>> {
self.core
.remote_version_cache
.get_or_try_init(|| self.fetch_remote_versions())
.cloned()
}

Check warning on line 90 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L85-L90

Added lines #L85 - L90 were not covered by tests

fn install_version_impl(&self, ctx: &InstallContext) -> Result<()> {
self.update_kerl()?;

Check warning on line 93 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L92-L93

Added lines #L92 - L93 were not covered by tests

file::remove_all(ctx.tv.install_path())?;
let build_name = format!("rtx_{}", ctx.tv.version);
match &ctx.tv.request {

Check warning on line 97 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L95-L97

Added lines #L95 - L97 were not covered by tests
ToolVersionRequest::Ref(..) => {
unimplemented!("erlang does not yet support refs");

Check warning on line 99 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L99

Added line #L99 was not covered by tests
}
ToolVersionRequest::Version(..) => {
cmd!(
self.kerl_path(),
"build-install",
&ctx.tv.version,
&build_name,
ctx.tv.install_path()
)
.run()?;

Check warning on line 109 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L102-L109

Added lines #L102 - L109 were not covered by tests
}
_ => unimplemented!(),

Check warning on line 111 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L111

Added line #L111 was not covered by tests
}

Ok(())
}

Check warning on line 115 in src/plugins/core/erlang.rs

View check run for this annotation

Codecov / codecov/patch

src/plugins/core/erlang.rs#L114-L115

Added lines #L114 - L115 were not covered by tests
}
9 changes: 7 additions & 2 deletions src/plugins/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::cache::CacheManager;
use crate::env::RTX_NODE_BUILD;
use crate::plugins::core::bun::BunPlugin;
use crate::plugins::core::deno::DenoPlugin;
use crate::plugins::core::erlang::ErlangPlugin;
use crate::plugins::core::go::GoPlugin;
use crate::plugins::core::java::JavaPlugin;
use crate::plugins::core::node::NodePlugin;
Expand All @@ -26,6 +27,7 @@ use crate::{dirs, env};

mod bun;
mod deno;
mod erlang;
mod go;
mod java;
mod node;
Expand Down Expand Up @@ -54,8 +56,11 @@ pub static CORE_PLUGINS: Lazy<PluginMap> = Lazy::new(|| {
});

pub static EXPERIMENTAL_CORE_PLUGINS: Lazy<PluginMap> = Lazy::new(|| {
let plugins: Vec<Arc<dyn Plugin>> =
vec![Arc::new(BunPlugin::new()), Arc::new(DenoPlugin::new())];
let plugins: Vec<Arc<dyn Plugin>> = vec![
Arc::new(BunPlugin::new()),
Arc::new(DenoPlugin::new()),
Arc::new(ErlangPlugin::new()),
];
plugins
.into_iter()
.map(|plugin| (plugin.name().to_string(), plugin))
Expand Down

0 comments on commit 7b19f91

Please sign in to comment.