Skip to content

Commit

Permalink
Revert so path resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Mar 23, 2020
1 parent 8f74f26 commit 8ccf8ac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ tests:
clean:
@rebar3 clean

hex-publish: distclean
hex-publish: clean
rebar3 hex publish
2 changes: 0 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
{w, all},
warn_export_all]}.

{deps, [{hex2bin, "1.0.0"}]}.

{plugins, [pc]}.

{provider_hooks, [
Expand Down
8 changes: 4 additions & 4 deletions src/crc32cer.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
]
}.

31 changes: 18 additions & 13 deletions src/crc32cer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

-on_load(init/0).

-ifndef(APPLICATION).
-define(APPLICATION, crc32cer).
-endif.

-spec init() -> ok.
init() ->
_ = erlang:load_nif(so_path(), 0),
Expand All @@ -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).

Expand Down

0 comments on commit 8ccf8ac

Please sign in to comment.