Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support install Erlang/OTP in windows #3

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions .github/workflows/e2e_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ name: E2E tests
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
e2e_tests:
strategy:
matrix:
# ref: https://github.com/actions/runner-images
os: [ubuntu-20.04, macos-13]
os: [ubuntu-20.04, macos-13, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -27,10 +28,25 @@ jobs:
run: |
brew tap version-fox/tap
brew install vfox

- name: add vfox-erlang plugin

- name: install scoop (Windows)
if: runner.os == 'Windows'
uses: MinoruSekine/setup-scoop@v3

- name: install vfox (Windows)
if: runner.os == 'Windows'
run: |
scoop install vfox

- name: add vfox-erlang plugin (Unix-like)
if: runner.os != 'Windows'
run: |
vfox add --source https://github.com/version-fox/vfox-erlang/archive/${GITHUB_REF}.zip erlang

- name: add vfox-erlang plugin (Windows)
if: runner.os == 'Windows'
run: |
vfox add --source https://github.com/version-fox/vfox-erlang/archive/refs/heads/main.zip erlang
vfox add --source https://github.com/version-fox/vfox-erlang/archive/$env:GITHUB_REF.zip erlang

- name: install Erlang/OTP by vfox-erlang plugin (Linux)
if: runner.os == 'Linux'
Expand Down Expand Up @@ -58,4 +74,15 @@ jobs:
echo "===============PATH==============="
cd assets
erlc hello.erl
erl -noshell -s hello hello_world -s init stop
erl -noshell -s hello hello_world -s init stop

- name: install etcd by vfox-etcd plugin (Windows)
if: runner.os == 'Windows'
run: |
vfox install [email protected]
vfox use [email protected]
Invoke-Expression "$(vfox activate pwsh)"
echo "===============PATH==============="
echo $env:PATH
echo "===============PATH==============="
& erl.exe -eval 'erlang:display({otp_release, erlang:system_info(otp_release)}), halt().' -noshell
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.tool-versions
*.beam
*.beam
available.cache
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# vfox-erlang plugin

Erlang/OTP [vfox](https://github.com/version-fox) plugin. Use the vfox to manage multiple [Erlang/OTP](https://www.erlang.org/) versions in Linux/Darwin.
Erlang/OTP [vfox](https://github.com/version-fox) plugin. Use the vfox to manage multiple [Erlang/OTP](https://www.erlang.org/) versions in Linux/Darwin MacOS/Windows. all platform~

## Usage

Expand All @@ -22,7 +22,7 @@ vofx search erlang
vfox install [email protected]
```

## Before install Erlang/OTP
## Before install Erlang/OTP in Linux/Darwin MacOS

vfox-erlang plugin would install Erlang/OTP through the [Erlang/OTP](https://www.erlang.org/doc/installation_guide/install#how-to-build-and-install-erlang-otp) source code compilation. So you must have the utilities mentioned in the document -> [Building and Installing Erlang/OTP](https://www.erlang.org/doc/installation_guide/install#how-to-build-and-install-erlang-otp).

Expand All @@ -46,7 +46,7 @@ brew install autoconf libxslt fop wxwidgets openssl

You can reference the E2E test in MacOS 13: [https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml)

## Note
### Note

By default, vfox-erlang plugin will Build [EEP-48 documentation chunks](https://www.erlang.org/doc/apps/kernel/eep48_chapter) for get doc in REPL (eg: h(list).) and [lsp docs hint](https://github.com/elixir-lsp/vscode-elixir-ls/issues/284).

Expand All @@ -59,3 +59,19 @@ You cal also use the `OTP_CONFIGURE_ARGS` environment variable to control instal
export OTP_CONFIGURE_ARGS="--enable-jit --enable-kernel-poll"
vfox install [email protected]
```

## install Erlang/OTP in Windows platform

In windows, the vfox-erlang plugin downloads the Erlang/OTP version of the exe installer from the [Erlang/OTP releases](https://github.com/erlang/otp/releases) and executes it for you.

This is an installation example in PowerShell:

```pwsh
vfox install [email protected]
vfox use [email protected]
Invoke-Expression "$(vfox activate pwsh)"
# Test the installation results
& erl.exe -eval 'erlang:display({otp_release, erlang:system_info(otp_release)}), halt().' -noshell
```

You can reference the E2E test in in windows-2022: [https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml)
8 changes: 7 additions & 1 deletion hooks/env_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
--- @field ctx.path string SDK installation directory
function PLUGIN:EnvKeys(ctx)
--- this variable is same as ctx.sdkInfo['plugin-name'].path
local mainPath = ctx.path .. "/release/bin"
local mainPath
if RUNTIME.osType == "windows" then
mainPath = ctx.path .. "\\release\\bin"
else
mainPath = ctx.path .. "/release/bin"
end

return {
{
key = "PATH",
Expand Down
50 changes: 33 additions & 17 deletions hooks/post_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,43 @@
--- Currently can be left unimplemented!
function PLUGIN:PostInstall(ctx)
--- ctx.rootPath SDK installation directory
-- use ENV OTP_COMPILE_ARGS to control compile behavior
local configure_args = os.getenv("OTP_CONFIGURE_ARGS") or ""
print("Erlang/OTP compile configure args: %s", configure_args)

-- use ENV OTP_BUILD_DOCS to control bytecode with docs chunks
local docs_target = os.getenv("DOC_TARGETS") or "chunks"

print("If you enable some Erlang/OTP features, maybe you can reference this guide: https://github.com/erlang/otp/blob/master/HOWTO/INSTALL.md#configuring-1")
os.execute("sleep " .. tonumber(3))

local sdkInfo = ctx.sdkInfo['erlang']
local path = sdkInfo.path

local configure_cmd = "cd " .. path .. " && ./configure --prefix=" .. path .. "/release " .. configure_args
if RUNTIME.osType == "windows" then
local installer
if RUNTIME.archType == "amd64" then
installer = path .. "\\otp_win64_" .. sdkInfo.version .. ".exe"
else
installer = path .. "\\otp_win32_" .. sdkInfo.version .. ".exe"
end

-- local install_cmd = "powershell Start-Process -FilePath " .. installer .. " -ArgumentList \"/S\", \"/D=" .. path .. "\" -Verb RunAs -Wait -PassThru -NoNewWindow"
local install_cmd = installer .. " -Wait -PassThru" .. " /S /D=" .. path .. "\\release"
print("install cmd: " .. install_cmd)
local status = os.execute(install_cmd)
if status ~= 0 then
error("Erlang/OTP install failed, please check the stdout for details.")
end
else
-- use ENV OTP_COMPILE_ARGS to control compile behavior
local configure_args = os.getenv("OTP_CONFIGURE_ARGS") or ""
print("Erlang/OTP compile configure args: %s", configure_args)

-- use ENV OTP_BUILD_DOCS to control bytecode with docs chunks
local docs_target = os.getenv("DOC_TARGETS") or "chunks"

print("If you enable some Erlang/OTP features, maybe you can reference this guide: https://github.com/erlang/otp/blob/master/HOWTO/INSTALL.md#configuring-1")
os.execute("sleep " .. tonumber(3))
local configure_cmd = "cd " .. path .. " && ./configure --prefix=" .. path .. "/release " .. configure_args

local install_erlang_cmd = "cd " .. path .. "&& make && make install"
-- install with docs chunk for IDE/REPL docs hits & type hits
local install_erlang_docs_cmd = "cd " .. path .. " && make docs DOC_TARGETS=" .. docs_target .. " && make release_docs DOC_TARGETS=" .. docs_target
local install_erlang_cmd = "cd " .. path .. "&& make && make install"
-- install with docs chunk for IDE/REPL docs hits & type hits
local install_erlang_docs_cmd = "cd " .. path .. " && make docs DOC_TARGETS=" .. docs_target .. " && make release_docs DOC_TARGETS=" .. docs_target

local status = os.execute(configure_cmd .. " && " .. install_erlang_cmd .. " && " ..install_erlang_docs_cmd)
if status ~= 0 then
error("Erlang/OTP install failed, please check the stdout for details. Make sure you have the required utilties: https://www.erlang.org/doc/installation_guide/install#required-utilities")
local status = os.execute(configure_cmd .. " && " .. install_erlang_cmd .. " && " ..install_erlang_docs_cmd)
if status ~= 0 then
error("Erlang/OTP install failed, please check the stdout for details. Make sure you have the required utilties: https://www.erlang.org/doc/installation_guide/install#required-utilities")
end
end
end
19 changes: 13 additions & 6 deletions hooks/pre_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ local erlangUtils = require("erlang_utils")
--- @field ctx.version string User-input version
--- @return table Version information
function PLUGIN:PreInstall(ctx)

erlangUtils.check_platform()

local erlang_version = ctx.version
print("You will install the Erlang/OTP version is: " .. erlang_version)
if erlang_version == nil then
print("You will install the Erlang/OTP version is" .. erlang_version)
error("You must provide a version number for Erlang/OTP, eg: vfox install [email protected]")
end
erlangUtils.check_version_existence("https://github.com/erlang/otp/releases/tag/OTP-" .. erlang_version)

local download_url = "https://github.com/erlang/otp/archive/refs/tags/OTP-" .. erlang_version .. ".tar.gz"

local download_url
if RUNTIME.osType == "windows" then
if RUNTIME.archType == "amd64" then
download_url = "https://github.com/erlang/otp/releases/download/OTP-" .. erlang_version .. "/otp_win64_" .. erlang_version .. ".exe"
else
download_url = "https://github.com/erlang/otp/releases/download/OTP-" .. erlang_version .. "/otp_win32_" .. erlang_version .. ".exe"
end
else
download_url = "https://github.com/erlang/otp/archive/refs/tags/OTP-" .. erlang_version .. ".tar.gz"
end

return {
version = erlang_version,
url = download_url
Expand Down
10 changes: 2 additions & 8 deletions lib/erlang_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local erlang_utils = {}

local function peek_lua_table(o, indent)
indent = indent or 0

local function handle_table(t, currentIndent)
local result = {}
for k, v in pairs(t) do
Expand All @@ -14,20 +14,14 @@ local function peek_lua_table(o, indent)
end
return '{\n' .. table.concat(result, ',\n') .. '\n' .. string.rep(' ', currentIndent) .. '}'
end

if type(o) == 'table' then
return handle_table(o, indent)
else
return tostring(o)
end
end

function erlang_utils.check_platform()
if RUNTIME.OS_TYPE == "windows" then
error("Windows is not supported. Please direct use the offcial installer to setup Erlang/OTP. visit: https://www.erlang.org/downloads")
end
end

function erlang_utils.check_version_existence(url)
local resp, err = http.get({
url = url
Expand Down