Skip to content

Commit

Permalink
Merge pull request #1 from cloudian/rebar3
Browse files Browse the repository at this point in the history
Rebar3 and other goodies
  • Loading branch information
zerth authored Aug 17, 2018
2 parents 0b6d7d9 + 0b103b2 commit 87fff9e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 59 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.PHONY: compile test

all:
./rebar compile eunit
all: compile test

compile:
@./rebar compile

clean:
./rebar clean
./rebar clean

include tools.mk
2 changes: 1 addition & 1 deletion ebin/ebloom.app
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, ebloom,
[
{description, ""},
{vsn, "1.1.2"},
{vsn, "2.0.0"},
{modules, [
ebloom
]},
Expand Down
16 changes: 16 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
%% port compiler plugin for rebar3
{plugins, [pc]}.

{provider_hooks,
[
{pre,
[
{compile, {pc, compile}},
{clean, {pc, clean}}
]
}
]
}.

{port_specs, [{"priv/ebloom_nifs.so", ["c_src/*.cpp"]}]}.
{port_env, [
%% Make sure to link -lstdc++
{"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
"LDFLAGS", "$LDFLAGS -lstdc++"}
]}.

{erl_opts, [debug_info, warnings_as_errors]}.
71 changes: 16 additions & 55 deletions src/ebloom.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,93 +54,54 @@
-spec deserialize(binary()) -> {ok, reference()}.

init() ->
case code:priv_dir(ebloom) of
SoName = case code:priv_dir(ebloom) of
{error, bad_name} ->
case code:which(?MODULE) of
Filename when is_list(Filename) ->
SoName = filename:join([filename:dirname(Filename),"../priv", "ebloom_nifs"]);
filename:join([filename:dirname(Filename),"../priv", "ebloom_nifs"]);
_ ->
SoName = filename:join("../priv", "ebloom_nifs")
filename:join("../priv", "ebloom_nifs")
end;
Dir ->
SoName = filename:join(Dir, "ebloom_nifs")
filename:join(Dir, "ebloom_nifs")
end,
erlang:load_nif(SoName, 0).

new(_Count, _FalseProb, _Seed) ->
case random:uniform(999999999999) of
666 -> {ok, make_ref()};
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

insert(_Ref, _Bin) ->
case random:uniform(999999999999) of
666 -> ok;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

contains(_Ref, _Bin) ->
case random:uniform(999999999999) of
666 -> true;
667 -> false;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

clear(_Ref) ->
case random:uniform(999999999999) of
666 -> ok;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

size(_Ref) ->
case random:uniform(999999999999) of
666 -> random:uniform(4242);
667 -> 0;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

elements(_Ref) ->
case random:uniform(999999999999) of
666 -> random:uniform(4242);
667 -> 0;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

effective_fpp(_Ref) ->
case random:uniform(999999999999) of
666 -> random:uniform(4242) / 42.42;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

intersect(_Ref, _OtherRef) ->
case random:uniform(999999999999) of
666 -> ok;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

union(_Ref, _OtherRef) ->
case random:uniform(999999999999) of
666 -> ok;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

difference(_Ref, _OtherRef) ->
case random:uniform(999999999999) of
666 -> ok;
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

serialize(_Ref) ->
case random:uniform(999999999999) of
666 -> list_to_binary(lists:duplicate(random:uniform(255), random:uniform(4242)));
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

deserialize(_Bin) ->
case random:uniform(999999999999) of
666 -> {ok, make_ref()};
_ -> exit("NIF library not loaded")
end.
erlang:nif_error({error, not_loaded}).

%% ===================================================================
%% EUnit tests
Expand Down
45 changes: 45 additions & 0 deletions tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
test: compile
./rebar eunit skip_deps=true

docs:
./rebar doc skip_deps=true

PLT ?= $(HOME)/.riak_combo_dialyzer_plt
LOCAL_PLT = .local_dialyzer_plt
DIALYZER_FLAGS ?= -Wunmatched_returns

${PLT}: compile
ifneq (,$(wildcard $(PLT)))
dialyzer --check_plt --plt $(PLT) --apps $(DIALYZER_APPS) && \
dialyzer --add_to_plt --plt $(PLT) --output_plt $(PLT) --apps $(DIALYZER_APPS) ; test $$? -ne 1
else
dialyzer --build_plt --output_plt $(PLT) --apps $(DIALYZER_APPS); test $$? -ne 1
endif

${LOCAL_PLT}: compile
ifneq (,$(wildcard deps/*))
ifneq (,$(wildcard $(LOCAL_PLT)))
dialyzer --check_plt --plt $(LOCAL_PLT) deps/*/ebin && \
dialyzer --add_to_plt --plt $(LOCAL_PLT) --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
else
dialyzer --build_plt --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
endif
endif

dialyzer: ${PLT} ${LOCAL_PLT}
@echo "==> $(shell basename $(shell pwd)) (dialyzer)"
@if [ -f $(LOCAL_PLT) ]; then \
dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin; \
else \
dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin; \
fi

cleanplt:
@echo
@echo "Are you sure? It takes several minutes to re-build."
@echo Deleting $(PLT) and $(LOCAL_PLT) in 5 seconds.
@echo
sleep 5
rm $(PLT)
rm $(LOCAL_PLT)

0 comments on commit 87fff9e

Please sign in to comment.