diff --git a/lib/bundlex/build_script.ex b/lib/bundlex/build_script.ex index c820cbe..547c94e 100644 --- a/lib/bundlex/build_script.ex +++ b/lib/bundlex/build_script.ex @@ -3,7 +3,7 @@ defmodule Bundlex.BuildScript do use Bunch - alias Bundlex.Platform + alias Bundlex.{Output, Platform} @script_ext unix: ".sh", windows: ".bat" @script_prefix unix: "#!/bin/sh\n", windows: "@echo off\r\n" @@ -29,7 +29,7 @@ defmodule Bundlex.BuildScript do def run(script, platform) def run(%__MODULE__{commands: []}, _platform) do - IO.warn("The list of commands is empty, did you forget to specify natives?") + Output.warn("The list of commands is empty, did you forget to specify natives?") end def run(%__MODULE__{commands: commands}, platform) do diff --git a/lib/bundlex/loader.ex b/lib/bundlex/loader.ex index 81bb47f..9a5e663 100644 --- a/lib/bundlex/loader.ex +++ b/lib/bundlex/loader.ex @@ -140,11 +140,15 @@ defmodule Bundlex.Loader do :ok else {:error, {reason, text}} -> - raise """ + require Logger + + Logger.error(""" Bundlex cannot load nif #{inspect(nif_name)} of app #{inspect(app)} from "#{path}", check bundlex.exs file for information about nifs. Reason: #{inspect(reason)}, #{to_string(text)} - """ + """) + + :abort end end end diff --git a/lib/bundlex/native.ex b/lib/bundlex/native.ex index 1346960..69da5ae 100644 --- a/lib/bundlex/native.ex +++ b/lib/bundlex/native.ex @@ -106,7 +106,7 @@ defmodule Bundlex.Native do native = if native.pkg_configs != [] do - IO.warn("`pkg_configs` option has been deprecated. Please use `os_deps` option.") + Output.warn("`pkg_configs` option has been deprecated. Please use `os_deps` option.") %{native | os_deps: [{:pkg_config, native.pkg_configs} | native.os_deps]} else native diff --git a/lib/bundlex/output.ex b/lib/bundlex/output.ex index d5c65ca..9015c8a 100644 --- a/lib/bundlex/output.ex +++ b/lib/bundlex/output.ex @@ -6,6 +6,11 @@ defmodule Bundlex.Output do Mix.shell().info("Bundlex: " <> msg) end + @spec warn(String.t()) :: :ok + def warn(msg) do + IO.warn("Bundlex: " <> msg, []) + end + @spec raise(binary()) :: no_return() def raise(msg) do Mix.raise("Bundlex: " <> msg) diff --git a/lib/bundlex/platform.ex b/lib/bundlex/platform.ex index ee6a307..fc130ed 100644 --- a/lib/bundlex/platform.ex +++ b/lib/bundlex/platform.ex @@ -41,7 +41,9 @@ defmodule Bundlex.Platform do Otherwise raises Mix error. """ @spec get_target!() :: name_t - if Mix.target() == :host do + mix_target = Mix.target() + + if mix_target == :host do def get_target!(), do: get_host!() else def get_target!() do @@ -50,7 +52,10 @@ defmodule Bundlex.Platform do :nerves :error -> - IO.warn("Crosscompilation supported only for Nerves systems, assuming host's platform") + Output.warn( + "MIX_TARGET #{inspect(unquote(mix_target))} is not supported. Bundlex will compile for the host platform." + ) + get_host!() end end diff --git a/lib/bundlex/project.ex b/lib/bundlex/project.ex index 3d4cfa9..feb5832 100644 --- a/lib/bundlex/project.ex +++ b/lib/bundlex/project.ex @@ -47,15 +47,21 @@ defmodule Bundlex.Project do - `precompiled` - Downloads the dependency from a given url and sets appropriate compilation and linking flags. Can be either `{:precompiled, url, libs}` or `{:precompiled, url}`, in which case the dependency name will be used as the lib name. - Precompiled dependencies for given applications (Mix projects) can be disabled via configuration, for example: + Precompiled dependencies can be disabled via configuration globally: - ```elixir - config :bundlex, :disable_precompiled_os_deps, - apps: [:my_application, :another_application] - ``` + ```elixir + config :bundlex, :disable_precompiled_os_deps, true + ``` - Note that this will affect the natives and libs defined in the `bundlex.exs` files of specified - applications only, not in their dependencies. + or for given applications (Mix projects), for example: + + ```elixir + config :bundlex, :disable_precompiled_os_deps, + apps: [:my_application, :another_application] + ``` + + Note that this will affect the natives and libs defined in the `bundlex.exs` files of specified + applications only, not in their dependencies. Check `t:os_dep/0` for details. * `pkg_configs` - (deprecated, use `os_deps` instead) Names of libraries for which the appropriate flags will be diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index ff111a2..e2c0455 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -38,7 +38,7 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do end if is_old_api do - IO.warn(""" + Output.warn(""" Native #{inspect(native_name)} uses deprecated syntax for `os_deps`. \ See `Bundlex.Project.os_dep` for the new syntax. """) @@ -110,12 +110,13 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do end defp resolve_os_dep_provider(name, {:precompiled, url, lib_names}, native) do - disabled_apps = - Application.get_env(:bundlex, :disable_precompiled_os_deps, []) - |> Keyword.get(:apps, []) - |> Bunch.listify() + is_precompiled_disabled = + case Application.get_env(:bundlex, :disable_precompiled_os_deps, false) do + bool when is_boolean(bool) -> bool + [apps: apps] when is_list(apps) -> native.app in apps + end - if native.app in disabled_apps do + if is_precompiled_disabled do {:error, """ is disabled in the application configuration, check the config.exs file. @@ -136,7 +137,7 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do create_relative_symlink(lib_path, output_path, dep_dir_name) # TODO: pass the platform via arguments - # $ORIGIN must be escaped soo that it's not treated as an ENV variable + # $ORIGIN must be escaped so that it's not treated as an ENV variable rpath_root = if Bundlex.platform() == :macosx, do: "@loader_path", else: "\\$ORIGIN" [ @@ -183,11 +184,13 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do |> then(&{:ok, &1}) rescue e -> - {:error, - """ - couldn't load #{inspect(pkg_configs)} libraries with pkg-config due to: - #{format_exception(e)} - """} + error = """ + couldn't load #{inspect(pkg_configs)} libraries with pkg-config due to: + #{format_exception(e)} + """ + + Output.warn(error) + {:error, error} end end @@ -222,11 +225,13 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do e -> File.rm_rf!(package_path) - {:error, - """ - couldn't download and extract the precompiled dependency #{inspect(name)} due to: - #{format_exception(e)} - """} + error = """ + couldn't download and extract the precompiled dependency #{inspect(name)} due to: + #{format_exception(e)} + """ + + Output.warn(error) + {:error, error} end end end diff --git a/mix.exs b/mix.exs index 0f94bbf..45fc73e 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Bundlex.Mixfile do use Mix.Project - @version "1.4.4" + @version "1.4.5" @github_url "https://github.com/membraneframework/bundlex" def project do