From e152c9d1a75a12192abe84469d616a6286eb1422 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Mon, 24 Oct 2022 10:56:16 +0200 Subject: [PATCH] Fix vendoring OTP (#1495) Summary of changes: - Vendor OTP at: rel/vendor/otp - Remove rel/vendor/otp/lib/*/src - Include /usr/local/bin in $PATH. This is not there by default and that's where homebrew (on x86_64) installs things so it should make it easier to build some packages with NIFs. --- .../lib/templates/macos/Launcher.swift.eex | 10 ++++++- mix.exs | 3 ++- rel/app/standalone.exs | 27 ++++++++++++------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app_bundler/lib/templates/macos/Launcher.swift.eex b/app_bundler/lib/templates/macos/Launcher.swift.eex index 7857be067..1274b36e8 100644 --- a/app_bundler/lib/templates/macos/Launcher.swift.eex +++ b/app_bundler/lib/templates/macos/Launcher.swift.eex @@ -1,6 +1,13 @@ <% -additional_paths = Enum.map_join(@app_options[:additional_paths], ":", &"\\(resourcePath)/#{&1}") +additional_paths = + Enum.map_join(@app_options[:additional_paths], ":", fn path -> + if String.starts_with?(path, "/") do + path + else + "\\(resourcePath)/#{path}" + end + end) %>import Cocoa @@ -88,6 +95,7 @@ func buildReleaseTask() -> Process { <%= if additional_paths != "" do %> let resourcePath = Bundle.main.resourcePath ?? "" + _ = resourcePath let additionalPaths = "<%= additional_paths %>" let path = task.environment!["PATH"] ?? "" task.environment!["PATH"] = "\(additionalPaths):\(path)" diff --git a/mix.exs b/mix.exs index d8fe5abd0..0ef3ce361 100644 --- a/mix.exs +++ b/mix.exs @@ -164,7 +164,8 @@ defmodule Livebook.MixProject do ] ], additional_paths: [ - "rel/erts-#{:erlang.system_info(:version)}/bin", + "/usr/local/bin", + "rel/vendor/otp/bin", "rel/vendor/elixir/bin" ], macos: [ diff --git a/rel/app/standalone.exs b/rel/app/standalone.exs index a1be139af..25b92c673 100644 --- a/rel/app/standalone.exs +++ b/rel/app/standalone.exs @@ -10,11 +10,13 @@ defmodule Standalone do erts_source = Path.join(:code.root_dir(), "erts-#{release.erts_version}") otp_bin_dir = Path.join(:code.root_dir(), "bin") otp_lib_dir = :code.lib_dir() + vendor_otp_dir = Path.join([release.path, "vendor", "otp"]) + File.rm_rf!(vendor_otp_dir) + File.mkdir_p!(vendor_otp_dir) # 1. copy erts/{bin,include} - release_erts_bin_dir = Path.join(release.path, "erts-#{release.erts_version}/bin") + release_erts_bin_dir = Path.join([vendor_otp_dir, "erts-#{release.erts_version}", "bin"]) File.mkdir_p!(release_erts_bin_dir) - cp_r!(Path.join(erts_source, "bin"), release_erts_bin_dir) File.rm(Path.join(release_erts_bin_dir, "erl")) @@ -37,28 +39,35 @@ defmodule Standalone do make_executable(Path.join(release_erts_bin_dir, "erl")) - release_erts_include_dir = Path.join(release.path, "erts-#{release.erts_version}/include") + release_erts_include_dir = + Path.join([vendor_otp_dir, "erts-#{release.erts_version}", "include"]) + cp_r!(Path.join(erts_source, "include"), release_erts_include_dir) # 2. copy lib - release_lib_dir = Path.join(release.path, "lib") + release_lib_dir = Path.join(vendor_otp_dir, "lib") cp_r!(otp_lib_dir, release_lib_dir) for dir <- Path.wildcard("#{release_lib_dir}/*/doc/{xml,html,pdf}") do File.rm_rf!(dir) end - # 3. copy boot files - release_bin_dir = Path.join(release.path, "bin") + for dir <- Path.wildcard("#{release_lib_dir}/*/src") do + File.rm_rf!(dir) + end - for file <- Path.wildcard(Path.join(otp_bin_dir, "*.boot")) do + # 3. copy boot files + release_bin_dir = Path.join(vendor_otp_dir, "bin") + File.mkdir!(release_bin_dir) + + for file <- Path.wildcard(Path.join(otp_bin_dir, "*")) do File.cp!(file, Path.join(release_bin_dir, Path.basename(file))) end # 4. copy usr - cp_r!(Path.join(:code.root_dir(), "usr"), Path.join(release.path, "usr")) + cp_r!(Path.join(:code.root_dir(), "usr"), Path.join(vendor_otp_dir, "usr")) - %{release | erts_source: erts_source} + release end @doc """