Navigation Menu

Skip to content

Commit

Permalink
support both R14 'behaviours' and R15+ 'callback info'
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbmerritt committed Apr 5, 2013
1 parent a558084 commit a96ae5d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Makefile
Expand Up @@ -81,8 +81,7 @@ $(DEPS_PLT):
--apps erts kernel stdlib -r deps

dialyzer: $(DEPS_PLT)
dialyzer --plt $(DEPS_PLT) --fullpath -Wrace_conditions \
-I include -pa $(CURDIR)/ebin --src src
dialyzer --fullpath --plt $(DEPS_PLT) -I include -Wrace_conditions -r ./ebin

typer:
typer --plt $(DEPS_PLT) -r ./src
Expand Down
15 changes: 15 additions & 0 deletions rebar.config.script
@@ -0,0 +1,15 @@
{match, [ErtsNumber]} = re:run(erlang:system_info(otp_release), "R(\\d+).+", [{capture, [1], list}]),
ErtsVsn = erlang:list_to_integer(ErtsNumber),
Opts1 = case lists:keysearch(erl_opts, 1, CONFIG) of
{value, {erl_opts, Opts0}} ->
Opts0;
false ->
[]
end,
Opts2 = if
ErtsVsn >= 15 ->
[{d, have_callback_support} | Opts1];
true ->
Opts1
end,
lists:keystore(erl_opts, 1, CONFIG, {erl_opts, Opts2}).
18 changes: 18 additions & 0 deletions src/rcl_provider.erl
Expand Up @@ -41,10 +41,28 @@

-opaque t() :: {?MODULE, module()}.


-ifdef(have_callback_support).

-callback init(rcl_state:t()) -> {ok, rcl_state:t()} | relcool:error().
-callback do(rcl_state:t()) -> {ok, rcl_state:t()} | relcool:error().
-callback format_error(Reason::term()) -> iolist().

-else.

%% In the case where R14 or lower is being used to compile the system
%% we need to export a behaviour info
-export([behaviour_info/1]).
-spec behaviour_info(atom()) -> [{atom(), arity()}] | undefined.
behaviour_info(callbacks) ->
[{init, 1},
{do, 1},
{format_error, 1}];
behaviour_info(_) ->
undefined.

-endif.

%%%===================================================================
%%% API
%%%===================================================================
Expand Down

0 comments on commit a96ae5d

Please sign in to comment.