summaryrefslogtreecommitdiff
path: root/src/rebar_state.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_state.erl')
-rw-r--r--src/rebar_state.erl37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index ec74eea..c8a9400 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -38,6 +38,11 @@
to_list/1,
+ compilers/1, compilers/2,
+ prepend_compilers/2, append_compilers/2,
+
+ project_builders/1, add_project_builder/3,
+
create_resources/2,
resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2,
@@ -66,6 +71,8 @@
all_plugin_deps = [] :: [rebar_app_info:t()],
all_deps = [] :: [rebar_app_info:t()],
+ compilers = [] :: [{compiler_type(), extension(), extension(), compile_fun()}],
+ project_builders = [] :: [{rebar_app_info:project_type(), module()}],
resources = [],
providers = [],
allow_provider_overrides = false :: boolean()}).
@@ -74,6 +81,10 @@
-type t() :: #state_t{}.
+-type compiler_type() :: atom().
+-type extension() :: string().
+-type compile_fun() :: fun(([file:filename()], rebar_app_info:t(), list()) -> ok).
+
-spec new() -> t().
new() ->
BaseState = base_state(dict:new()),
@@ -392,6 +403,32 @@ warn_old_resource(ResourceModule) ->
?WARN("Using custom resource ~s that implements a deprecated api. "
"It should be upgraded to rebar_resource_v2.", [ResourceModule]).
+compilers(#state_t{compilers=Compilers}) ->
+ Compilers.
+
+prepend_compilers(State=#state_t{compilers=Compilers}, NewCompilers) ->
+ State#state_t{compilers=NewCompilers++Compilers}.
+
+append_compilers(State=#state_t{compilers=Compilers}, NewCompilers) ->
+ State#state_t{compilers=Compilers++NewCompilers}.
+
+compilers(State, Compilers) ->
+ State#state_t{compilers=Compilers}.
+
+project_builders(#state_t{project_builders=ProjectBuilders}) ->
+ ProjectBuilders.
+
+add_project_builder(State=#state_t{project_builders=ProjectBuilders}, Type, Module) ->
+ _ = code:ensure_loaded(Module),
+ case erlang:function_exported(Module, build, 1) of
+ true ->
+ State#state_t{project_builders=[{Type, Module} | ProjectBuilders]};
+ false ->
+ ?WARN("Unable to add project builder for type ~s, required function ~s:build/1 not found.",
+ [Type, Module]),
+ State
+ end.
+
create_resources(Resources, State) ->
lists:foldl(fun(R, StateAcc) ->
add_resource(StateAcc, R)