From 7f901a81dbdb40efcfb008f01cfe461c958b9b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=9Aled=C5=BA?= Date: Wed, 22 Jul 2020 15:29:13 +0200 Subject: [PATCH] Remove support for deprecated format of bundlex.exs --- bundlex.exs | 4 ++-- lib/unifex/code_generator.ex | 29 ++++++++++++----------------- lib/unifex/loader.ex | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/bundlex.exs b/bundlex.exs index 7f676643..d84c23ea 100644 --- a/bundlex.exs +++ b/bundlex.exs @@ -13,12 +13,12 @@ defmodule Unifex.BundlexProject do deps: [shmex: :lib_nif], src_base: "unifex/nif/unifex", sources: ["unifex.c", "payload.c"], - interfaces: [:nif] + interface: :nif ], unifex: [ src_base: "unifex/cnode/unifex", sources: ["unifex.c", "cnode.c", "payload.c"], - interfaces: [:cnode] + interface: :cnode ] ] end diff --git a/lib/unifex/code_generator.ex b/lib/unifex/code_generator.ex index c5be5421..fc6c15cc 100644 --- a/lib/unifex/code_generator.ex +++ b/lib/unifex/code_generator.ex @@ -22,23 +22,18 @@ defmodule Unifex.CodeGenerator do defp get_generator(%Specs{name: name, interface: nil}) do {:ok, bundlex_project} = Bundlex.Project.get() - - [:nifs, :cnodes, :natives, :libs] - |> Enum.find(&(bundlex_project.config |> Keyword.get(&1, []) |> Keyword.has_key?(name))) - |> case do - :nifs -> - Unifex.CodeGenerators.NIF - - :cnodes -> - Unifex.CodeGenerators.CNode - - :natives -> - interfaces = bundlex_project.config[:natives][name][:interfaces] - get_generator(get_generator_module_name(List.first(interfaces))) - - _ -> - Unifex.CodeGenerators.NIF - end + config = bundlex_project.config + + [:natives, :libs] + |> Enum.find(&(config |> Keyword.get(&1, []) |> Keyword.has_key?(name))) + |> (fn type -> + interfaces = Keyword.get(config[type][name], :interface, []) |> Bunch.listify() + + case interfaces do + [] -> Unifex.CodeGenerators.NIF + _ -> get_generator(get_generator_module_name(List.first(interfaces))) + end + end).() end defp get_generator(%Specs{interface: interface}) do diff --git a/lib/unifex/loader.ex b/lib/unifex/loader.ex index 139ebd1f..ba5cf6d8 100644 --- a/lib/unifex/loader.ex +++ b/lib/unifex/loader.ex @@ -24,7 +24,7 @@ defmodule Unifex.Loader do arg_names = args |> Keyword.keys() |> Enum.map(&Macro.var(&1, nil)) quote do - defnifp unquote(wrapped_name)(unquote_splicing(arg_names)) + defnifp(unquote(wrapped_name)(unquote_splicing(arg_names))) @compile {:inline, [unquote({name, length(args)})]} def unquote(name)(unquote_splicing(arg_names)) do