rebar3_thrift (rebar3_thrift v0.7.0)
View Sourcerebar3 provider that runs the thrift_generator over IDL files declared
in the consumer's rebar.config:
{thrift, [
{files, ["src/my_api.thrift"]}, %% required, one or more IDL files
{out_dir, "src"} %% optional, default "src"
]}Four optional axes mirror the standalone generator's flags and apply
only to definitions without an explicit annotation of their own:
{repr, record|map|native} (like --repr, the erl.struct_type
default), {union_type, record|sum} (like --union-type,
erl.union_type), {set, list|sets|ordset} (like --set, erl.set)
and {typedef_type, alias|nominal} (like --typedef-type, erl.type);
a file-wide namespace default overrides the option for its file.
rebar3 thrift regenerates the Erlang sources for every file; files
whose content is already up to date are left untouched, so regenerating
an unchanged IDL does not churn mtimes. To run it before every
compilation, hook it in the consumer's rebar.config:
{provider_hooks, [{pre, [{compile, {default, thrift}}]}]}rebar3 thrift --check verifies instead of writing: it fails when any
generated artifact is missing or stale relative to the IDL — a CI
freshness gate.
rebar3 thrift clean deletes the generated files from the out dir:
every .erl/.hrl carrying the generator's Autogenerated by Thrift Generator banner, so files orphaned by a removed service or a deleted
IDL go too. To run it on project cleanup, hook the namespaced clean
provider into rebar3 clean:
{provider_hooks, [{post, [{clean, {thrift, clean}}]}]}
Summary
Functions
Reads the four option axes of the {thrift, [...]} config section into
the thrift_generator:generate_opts() map: {repr, _}, {union_type, _}, {set, _} and {typedef_type, _}, each defaulting to the
generator's built-in value. Unknown axis values (including config
terms of the wrong type, e.g. the string "map") answer {error, {bad_opt, {Key, Value, Allowed}}}.
Functions
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, {rebar3_thrift, term()}}.
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
-spec thrift_gen_opts(proplists:proplist()) -> {ok, thrift_generator:generate_opts()} | {error, {bad_opt, {atom(), term(), [atom()]}}}.
Reads the four option axes of the {thrift, [...]} config section into
the thrift_generator:generate_opts() map: {repr, _}, {union_type, _}, {set, _} and {typedef_type, _}, each defaulting to the
generator's built-in value. Unknown axis values (including config
terms of the wrong type, e.g. the string "map") answer {error, {bad_opt, {Key, Value, Allowed}}}.