fix(bpapi): Fix build

This commit is contained in:
k32 2022-01-04 20:28:31 +01:00
parent eaa71438b2
commit 0f6ec9d646
4 changed files with 111 additions and 116 deletions

View File

@ -4,8 +4,6 @@
{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
deprecated_function_calls,warnings_as_errors,deprecated_functions]}.
{erl_first_files, ["apps/emqx/src/bpapi/emqx_bpapi.erl"]}.
%% Deps here may duplicate with emqx.git root level rebar.config
%% but there not be any descrpancy.
%% This rebar.config is necessary because the app may be used as a

View File

@ -15,9 +15,7 @@
%%--------------------------------------------------------------------
-module(emqx_bpapi).
-export([parse_semver/1, api_and_version/1]).
-export_type([var_name/0, call/0, rpc/0, bpapi_meta/0]).
-export_type([var_name/0, call/0, rpc/0, bpapi_meta/0, semver/0]).
-type semver() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}.
@ -33,22 +31,3 @@
, calls := [rpc()]
, casts := [rpc()]
}.
-spec parse_semver(string()) -> {ok, semver()}
| false.
parse_semver(Str) ->
Opts = [{capture, all_but_first, list}],
case re:run(Str, "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$", Opts) of
{match, [A, B, C]} -> {ok, {list_to_integer(A), list_to_integer(B), list_to_integer(C)}};
nomatch -> error
end.
-spec api_and_version(module()) -> {atom(), non_neg_integer()}.
api_and_version(Module) ->
Opts = [{capture, all_but_first, list}],
case re:run(atom_to_list(Module), "(.*)_proto_v([0-9]+)$", Opts) of
{match, [API, VsnStr]} ->
{ok, list_to_atom(API), list_to_integer(VsnStr)};
nomatch ->
error(Module)
end.

View File

@ -64,19 +64,19 @@ parse_transform(Forms, _Options) ->
go({attribute, _, file, {File, _}}, S) ->
S#s{file = File};
go({attribute, Line, module, Mod}, S) ->
case emqx_bpapi:api_and_version(Mod) of
case api_and_version(Mod) of
{ok, API, Vsn} -> S#s{api = API, version = Vsn, module = Mod};
error -> push_err(Line, invalid_name, S)
end;
go({attribute, _Line, introduced_in, Str}, S) ->
case is_list(Str) andalso emqx_bpapi:parse_semver(Str) of
case is_list(Str) andalso parse_semver(Str) of
{ok, Vsn} -> S#s{introduced_in = Vsn};
false -> S %% Don't report error here, it's done in check/1
error -> S %% Don't report error here, it's done in check/1
end;
go({attribute, Line, deprecated_since, Str}, S) ->
case is_list(Str) andalso emqx_bpapi:parse_semver(Str) of
case is_list(Str) andalso parse_semver(Str) of
{ok, Vsn} -> S#s{deprecated_since = Vsn};
false -> push_err(Line, invalid_deprecated_since, S)
error -> push_err(Line, invalid_deprecated_since, S)
end;
go({function, Line, Name, Arity, Clauses}, S) ->
analyze_fun(Line, Name, Arity, Clauses, S);
@ -191,6 +191,26 @@ push_err(Line, Err, S = #s{errors = Errs}) ->
push_target(Target, S = #s{targets = Targets}) ->
S#s{targets = [Target|Targets]}.
-spec parse_semver(string()) -> {ok, emqx_bpapi:semver()}
| error.
parse_semver(Str) ->
Opts = [{capture, all_but_first, list}],
case re:run(Str, "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$", Opts) of
{match, [A, B, C]} -> {ok, {list_to_integer(A), list_to_integer(B), list_to_integer(C)}};
nomatch -> error
end.
-spec api_and_version(module()) -> {ok, emqx_bpapi:api(), emqx_bpapi:version()} | error.
api_and_version(Module) ->
Opts = [{capture, all_but_first, list}],
case re:run(atom_to_list(Module), "(.*)_proto_v([0-9]+)$", Opts) of
{match, [API, VsnStr]} ->
{ok, list_to_atom(API), list_to_integer(VsnStr)};
nomatch ->
error
end.
-ifdef(debug).
log(Fmt, Args) ->
io:format(user, "!! " ++ Fmt ++ "~n", Args).

View File

@ -13,8 +13,6 @@
{d, snk_kind, msg}
]}.
{erl_first_files, ["apps/emqx/src/bpapi/emqx_bpapi.erl"]}.
{xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
deprecated_function_calls,warnings_as_errors,deprecated_functions]}.