diff --git a/.github/workflows/e2e_test.yaml b/.github/workflows/e2e_test.yaml index 8c5df9f..eb64939 100644 --- a/.github/workflows/e2e_test.yaml +++ b/.github/workflows/e2e_test.yaml @@ -3,6 +3,7 @@ name: E2E tests on: push: branches: [main] + pull_request: workflow_dispatch: jobs: @@ -10,7 +11,7 @@ jobs: 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 @@ -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' @@ -58,4 +74,15 @@ jobs: echo "===============PATH===============" cd assets erlc hello.erl - erl -noshell -s hello hello_world -s init stop \ No newline at end of file + erl -noshell -s hello hello_world -s init stop + + - name: install etcd by vfox-etcd plugin (Windows) + if: runner.os == 'Windows' + run: | + vfox install erlang@25.3.2.12 + vfox use erlang@25.3.2.12 + 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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index bd7fee0..446b731 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea .tool-versions -*.beam \ No newline at end of file +*.beam +available.cache \ No newline at end of file diff --git a/README.md b/README.md index e57daf9..e82a78b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -22,7 +22,7 @@ vofx search erlang vfox install erlang@25.3.2.10 ``` -## 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). @@ -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). @@ -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 erlang@25.3.2.10 ``` + +## 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 erlang@25.3.2.12 +vfox use erlang@25.3.2.12 +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) diff --git a/hooks/env_keys.lua b/hooks/env_keys.lua index bacb549..58b9c42 100644 --- a/hooks/env_keys.lua +++ b/hooks/env_keys.lua @@ -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", diff --git a/hooks/post_install.lua b/hooks/post_install.lua index daa655d..4557857 100644 --- a/hooks/post_install.lua +++ b/hooks/post_install.lua @@ -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 \ No newline at end of file diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index 4c55e93..c89cbf2 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -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 erlang@24.1") 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 diff --git a/lib/erlang_utils.lua b/lib/erlang_utils.lua index 88a9a36..8ffe3a1 100644 --- a/lib/erlang_utils.lua +++ b/lib/erlang_utils.lua @@ -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 @@ -14,7 +14,7 @@ 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 @@ -22,12 +22,6 @@ local function peek_lua_table(o, indent) 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