mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-13 00:14:33 +08:00
standalone.exs: Ensure OTP version (#987)
This commit is contained in:
parent
19f4f17e74
commit
2c34f62c11
2 changed files with 45 additions and 16 deletions
6
mix.exs
6
mix.exs
|
@ -2,10 +2,12 @@ defmodule Livebook.MixProject do
|
|||
use Mix.Project
|
||||
|
||||
@elixir_requirement "~> 1.13"
|
||||
@app_elixir_version "1.13.2"
|
||||
@version "0.5.2"
|
||||
@description "Interactive and collaborative code notebooks - made with Phoenix LiveView"
|
||||
|
||||
@app_elixir_version "1.13.2"
|
||||
@app_otp_version "24.2"
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :livebook,
|
||||
|
@ -155,7 +157,7 @@ defmodule Livebook.MixProject do
|
|||
Code.require_file("rel/app/standalone.exs")
|
||||
|
||||
release
|
||||
|> Standalone.copy_erlang()
|
||||
|> Standalone.copy_otp(@app_otp_version)
|
||||
|> Standalone.copy_elixir(@app_elixir_version)
|
||||
end
|
||||
|
||||
|
|
|
@ -3,10 +3,16 @@ defmodule Standalone do
|
|||
require Logger
|
||||
|
||||
@doc """
|
||||
Copies ERTS into the release.
|
||||
Copies OTP into the release.
|
||||
"""
|
||||
@spec copy_erlang(Mix.Release.t()) :: Mix.Release.t()
|
||||
def copy_erlang(release) do
|
||||
@spec copy_otp(Mix.Release.t(), otp_version :: String.t()) :: Mix.Release.t()
|
||||
def copy_otp(release, otp_version) do
|
||||
expected_otp_version = otp_version()
|
||||
|
||||
if otp_version != expected_otp_version do
|
||||
raise "expected OTP #{expected_otp_version}, got: #{otp_version}"
|
||||
end
|
||||
|
||||
{erts_source, erts_bin_dir, erts_lib_dir, _erts_version} = erts_data()
|
||||
|
||||
erts_destination_source = Path.join(release.path, "vendor/bin")
|
||||
|
@ -35,6 +41,7 @@ defmodule Standalone do
|
|||
export PROGNAME
|
||||
exec "$BINDIR/erlexec" ${1+"$@"}
|
||||
""")
|
||||
|
||||
executable!(Path.join(erts_destination_source, "erl"))
|
||||
|
||||
# Copy lib
|
||||
|
@ -45,9 +52,13 @@ defmodule Standalone do
|
|||
|> File.cp_r!(erts_destination_lib, fn _, _ -> false end)
|
||||
|
||||
# copy *.boot files to <resource_path>/bin
|
||||
erts_destination_bin = Path.join(release.path, "bin")
|
||||
erts_destination_bin = Path.join(release.path, "bin")
|
||||
|
||||
boot_files = erts_bin_dir |> Path.join("*.boot") |> Path.wildcard() |> Enum.map(& String.split(&1, "/") |> List.last())
|
||||
boot_files =
|
||||
erts_bin_dir
|
||||
|> Path.join("*.boot")
|
||||
|> Path.wildcard()
|
||||
|> Enum.map(&(String.split(&1, "/") |> List.last()))
|
||||
|
||||
File.mkdir_p!(erts_destination_bin)
|
||||
|
||||
|
@ -58,18 +69,32 @@ defmodule Standalone do
|
|||
%{release | erts_source: erts_source}
|
||||
end
|
||||
|
||||
# From https://github.com/fishcakez/dialyze/blob/6698ae582c77940ee10b4babe4adeff22f1b7779/lib/mix/tasks/dialyze.ex#L168
|
||||
defp otp_version do
|
||||
major = :erlang.system_info(:otp_release) |> List.to_string()
|
||||
vsn_file = Path.join([:code.root_dir(), "releases", major, "OTP_VERSION"])
|
||||
|
||||
try do
|
||||
{:ok, contents} = File.read(vsn_file)
|
||||
String.split(contents, "\n", trim: true)
|
||||
else
|
||||
[full] -> full
|
||||
_ -> major
|
||||
catch
|
||||
:error, _ -> major
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Copies elixir into the release.
|
||||
Copies Elixir into the release.
|
||||
"""
|
||||
@spec copy_elixir(Mix.Release.t(), elixir_version :: String.t()) :: Mix.Release.t()
|
||||
def copy_elixir(release, elixir_version) do
|
||||
# download and unzip
|
||||
standalone_destination = Path.join(release.path, "vendor/elixir")
|
||||
download_elixir_at_destination(standalone_destination, elixir_version)
|
||||
|
||||
# make executable
|
||||
["elixir", "elixirc", "mix", "iex"]
|
||||
|> Enum.map(&(executable!(Path.join(standalone_destination, "bin/#{&1}"))))
|
||||
|> Enum.map(&executable!(Path.join(standalone_destination, "bin/#{&1}")))
|
||||
|
||||
release
|
||||
end
|
||||
|
@ -83,20 +108,22 @@ defmodule Standalone do
|
|||
|
||||
defp erts_data do
|
||||
version = :erlang.system_info(:version)
|
||||
{:filename.join(:code.root_dir(), 'erts-#{version}'), :filename.join(:code.root_dir(), 'bin'), :code.lib_dir(), version}
|
||||
|
||||
{:filename.join(:code.root_dir(), 'erts-#{version}'), :filename.join(:code.root_dir(), 'bin'),
|
||||
:code.lib_dir(), version}
|
||||
end
|
||||
|
||||
defp fetch_body!(url) do
|
||||
Logger.debug("Downloading elixir from #{url}")
|
||||
case Livebook.Utils.HTTP.request(:get, url, [timeout: :infinity]) do
|
||||
Logger.debug("Downloading Elixir from #{url}")
|
||||
|
||||
case Livebook.Utils.HTTP.request(:get, url, timeout: :infinity) do
|
||||
{:ok, 200, _headers, body} ->
|
||||
body
|
||||
|
||||
{:error, error} ->
|
||||
{:error, error} ->
|
||||
raise "couldn't fetch #{url}: #{inspect(error)}"
|
||||
end
|
||||
end
|
||||
|
||||
defp executable!(path), do: File.chmod!(path, 0o755)
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue