From 8ccf8acb709b0bbe1d2d69edd8eceb0802de4963 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Sun, 22 Mar 2020 17:25:16 +0100 Subject: [PATCH] Revert so path resolution. --- Makefile | 2 +- rebar.config | 2 -- src/crc32cer.app.src | 8 ++++---- src/crc32cer.erl | 31 ++++++++++++++++++------------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 3a44e00761..05a979c36a 100644 --- a/Makefile +++ b/Makefile @@ -11,5 +11,5 @@ tests: clean: @rebar3 clean -hex-publish: distclean +hex-publish: clean rebar3 hex publish diff --git a/rebar.config b/rebar.config index 1b3169bf07..4b87ba2e58 100644 --- a/rebar.config +++ b/rebar.config @@ -4,8 +4,6 @@ {w, all}, warn_export_all]}. -{deps, [{hex2bin, "1.0.0"}]}. - {plugins, [pc]}. {provider_hooks, [ diff --git a/src/crc32cer.app.src b/src/crc32cer.app.src index ce4784c1b9..564f41520b 100644 --- a/src/crc32cer.app.src +++ b/src/crc32cer.app.src @@ -7,10 +7,10 @@ , {env,[]} , {modules,[]} , {licenses,["Apache License 2.0"]} - , {links,[{"Github","https://github.com/zmstone/crc32cert .git"}]} - , {build_tools,["make","rebar","rebar3"]} - , {files,["c_src/*.h","c_src/*.c", "rebar.config", - "src", "erlang.mk","Makefile"]} + , {links,[{"Github","https://github.com/zmstone/crc32cer.git"}]} + , {build_tools,["rebar3"]} + , {files,["c_src/Makefile", "c_src/*.h","c_src/*.c", "rebar.config", + "src", "Makefile"]} ] }. diff --git a/src/crc32cer.erl b/src/crc32cer.erl index f0f56ee21e..a6adf9d332 100644 --- a/src/crc32cer.erl +++ b/src/crc32cer.erl @@ -5,10 +5,6 @@ -on_load(init/0). --ifndef(APPLICATION). --define(APPLICATION, crc32cer). --endif. - -spec init() -> ok. init() -> _ = erlang:load_nif(so_path(), 0), @@ -24,15 +20,24 @@ nif(_Acc, _IoData) -> -spec so_path() -> string(). so_path() -> - filename:join(case code:priv_dir(?MODULE) of - {error, bad_name} -> - %% this is here for testing purposes - filename:join( - [filename:dirname( - code:which(?MODULE)),"..","priv"]); - Dir -> - Dir - end, atom_to_list(?MODULE) ++ "_nif"). + filename:join([get_nif_bin_dir(), "crc32cer_nif"]). + +get_nif_bin_dir() -> + {ok, Cwd} = file:get_cwd(), + get_nif_bin_dir( + [ code:priv_dir(crc32cer) + , filename:join([Cwd, "..", "priv"]) + , filename:join(Cwd, "priv") + , os:getenv("NIF_BIN_DIR") + ]). + +get_nif_bin_dir([]) -> erlang:error(crc32cer_nif_not_found); +get_nif_bin_dir([false | Rest]) -> get_nif_bin_dir(Rest); +get_nif_bin_dir([Dir | Rest]) -> + case filelib:wildcard(filename:join([Dir, "crc32cer_nif*"])) of + [] -> get_nif_bin_dir(Rest); + [_ | _] -> Dir + end. -ifdef(TEST).