summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar_app_discover.erl50
-rw-r--r--src/rebar_dir.erl11
-rw-r--r--src/rebar_prv_app_discovery.erl2
-rw-r--r--src/rebar_prv_edoc.erl5
-rw-r--r--src/rebar_prv_plugins_upgrade.erl3
-rw-r--r--src/rebar_state.erl22
6 files changed, 65 insertions, 28 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 0c97ad7..0c15bb2 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -85,7 +85,12 @@ define_root_app(Apps, State) ->
format_error({module_list, File}) ->
io_lib:format("Error reading module list from ~p~n", [File]);
format_error({missing_module, Module}) ->
- io_lib:format("Module defined in app file missing: ~p~n", [Module]).
+ io_lib:format("Module defined in app file missing: ~p~n", [Module]);
+format_error({cannot_read_app_file, AppFile}) ->
+ io_lib:format("Cannot read app file: ~p~n", [AppFile]);
+format_error({bad_term_file, _File, _Reason} = Error) ->
+ rebar_file_utils:format_error(Error).
+
%% @doc merges configuration of a project app and the top level state
%% some configuration like erl_opts must be merged into a subapp's opts
@@ -348,24 +353,31 @@ app_dir(AppFile) ->
%% app file.
-spec create_app_info(rebar_app_info:t(), file:name(), file:name()) -> rebar_app_info:t().
create_app_info(AppInfo, AppDir, AppFile) ->
- [{application, AppName, AppDetails}] = rebar_config:consult_app_file(AppFile),
- AppVsn = proplists:get_value(vsn, AppDetails),
- Applications = proplists:get_value(applications, AppDetails, []),
- IncludedApplications = proplists:get_value(included_applications, AppDetails, []),
- AppInfo1 = rebar_app_info:name(
- rebar_app_info:original_vsn(
- rebar_app_info:dir(AppInfo, AppDir), AppVsn), AppName),
- AppInfo2 = rebar_app_info:applications(
- rebar_app_info:app_details(AppInfo1, AppDetails),
- IncludedApplications++Applications),
- Valid = case rebar_app_utils:validate_application_info(AppInfo2) =:= true
- andalso rebar_app_info:has_all_artifacts(AppInfo2) =:= true of
- true ->
- true;
- _ ->
- false
- end,
- rebar_app_info:dir(rebar_app_info:valid(AppInfo2, Valid), AppDir).
+ try rebar_config:consult_app_file(AppFile) of
+ [{application, AppName, AppDetails}] ->
+ AppVsn = proplists:get_value(vsn, AppDetails),
+ Applications = proplists:get_value(applications, AppDetails, []),
+ IncludedApplications = proplists:get_value(included_applications, AppDetails, []),
+ AppInfo1 = rebar_app_info:name(
+ rebar_app_info:original_vsn(
+ rebar_app_info:dir(AppInfo, AppDir), AppVsn), AppName),
+ AppInfo2 = rebar_app_info:applications(
+ rebar_app_info:app_details(AppInfo1, AppDetails),
+ IncludedApplications++Applications),
+ Valid = case rebar_app_utils:validate_application_info(AppInfo2) =:= true
+ andalso rebar_app_info:has_all_artifacts(AppInfo2) =:= true of
+ true ->
+ true;
+ _ ->
+ false
+ end,
+ rebar_app_info:dir(rebar_app_info:valid(AppInfo2, Valid), AppDir);
+ _Invalid ->
+ throw({error, {?MODULE, {cannot_read_app_file, AppFile}}})
+ catch
+ throw:{error, {rebar_file_utils, Err = {bad_term_file, _File, _Reason}}} ->
+ throw({error, {?MODULE, Err}}) % wrap this
+ end.
%% @doc Read in and parse the .app file if it is availabe. Do the same for
%% the .app.src file if it exists.
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl
index 17bc48e..aac6210 100644
--- a/src/rebar_dir.erl
+++ b/src/rebar_dir.erl
@@ -107,8 +107,15 @@ home_dir() ->
%% may be stored.
-spec global_config_dir(rebar_state:t()) -> file:filename_all().
global_config_dir(State) ->
- Home = home_dir(),
- rebar_state:get(State, global_rebar_dir, filename:join([Home, ".config", "rebar3"])).
+ filename:join([rebar_config_dir(State), ".config", "rebar3"]).
+
+rebar_config_dir(State) ->
+ case os:getenv("REBAR_GLOBAL_CONFIG_DIR") of
+ false ->
+ rebar_state:get(State, global_rebar_dir, home_dir());
+ ConfDir ->
+ ConfDir
+ end.
%% @doc returns the path of the global rebar.config file
-spec global_config(rebar_state:t()) -> file:filename_all().
diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl
index f5bab49..20b7f90 100644
--- a/src/rebar_prv_app_discovery.erl
+++ b/src/rebar_prv_app_discovery.erl
@@ -43,6 +43,8 @@ do(State) ->
{error, {rebar_packages, Error}};
throw:{error, {rebar_app_utils, Error}} ->
{error, {rebar_app_utils, Error}};
+ throw:{error, {rebar_app_discover, Error}} ->
+ {error, {rebar_app_discover, Error}};
throw:{error, Error} ->
?PRV_ERROR(Error)
end.
diff --git a/src/rebar_prv_edoc.erl b/src/rebar_prv_edoc.erl
index c78296a..5e563ab 100644
--- a/src/rebar_prv_edoc.erl
+++ b/src/rebar_prv_edoc.erl
@@ -45,7 +45,10 @@ do(State) ->
AppName = rebar_utils:to_list(rebar_app_info:name(AppInfo)),
?INFO("Running edoc for ~ts", [AppName]),
AppDir = rebar_app_info:dir(AppInfo),
- AppRes = (catch edoc:application(list_to_atom(AppName), AppDir, EdocOptsAcc)),
+ AppOpts = rebar_app_info:opts(AppInfo),
+ %% order of the merge is important to allow app opts overrides
+ AppEdocOpts = rebar_opts:get(AppOpts, edoc_opts, []) ++ EdocOptsAcc,
+ AppRes = (catch edoc:application(list_to_atom(AppName), AppDir, AppEdocOpts)),
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, AppInfo, State),
case {AppRes, ShouldAccPaths} of
{ok, true} ->
diff --git a/src/rebar_prv_plugins_upgrade.erl b/src/rebar_prv_plugins_upgrade.erl
index 7420c83..39107c9 100644
--- a/src/rebar_prv_plugins_upgrade.erl
+++ b/src/rebar_prv_plugins_upgrade.erl
@@ -90,8 +90,9 @@ find_plugin(Plugin, Profiles, State) ->
build_plugin(AppInfo, Apps, State) ->
Providers = rebar_state:providers(State),
+ Resources = rebar_state:resources(State),
AppDir = rebar_app_info:dir(AppInfo),
C = rebar_config:consult(AppDir),
S = rebar_state:new(rebar_state:all_deps(rebar_state:new(), Apps), C, AppDir),
AppInfo1 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C),
- rebar_prv_compile:compile(S, Providers, AppInfo1).
+ rebar_prv_compile:compile(rebar_state:set_resources(S, Resources), Providers, AppInfo1).
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 31d3a08..e7d772f 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -71,7 +71,7 @@
all_plugin_deps = [] :: [rebar_app_info:t()],
all_deps = [] :: [rebar_app_info:t()],
- compilers = [] :: [{compiler_type(), extension(), extension(), compile_fun()}],
+ compilers = [] :: [module()],
project_builders = [] :: [{rebar_app_info:project_type(), module()}],
resources = [],
providers = [],
@@ -81,10 +81,6 @@
-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()),
@@ -407,15 +403,31 @@ warn_old_resource(ResourceModule) ->
?WARN("Using custom resource ~s that implements a deprecated api. "
"It should be upgraded to rebar_resource_v2.", [ResourceModule]).
+%% @doc get a list of all registered compiler modules, which should implement
+%% the `rebar_compiler' behaviour
+-spec compilers(t()) -> [module()].
compilers(#state_t{compilers=Compilers}) ->
Compilers.
+%% @doc register compiler modules prior to the existing ones. Each compiler
+%% module should implement the `rebar_compiler' behaviour. Use this when
+%% your custom compiler generates .erl files (or files of another type) and
+%% that should run before other compiler modules.
+-spec prepend_compilers(t(), [module()]) -> t().
prepend_compilers(State=#state_t{compilers=Compilers}, NewCompilers) ->
State#state_t{compilers=NewCompilers++Compilers}.
+%% @doc register compiler modules. Each compiler
+%% module should implement the `rebar_compiler' behaviour. Use this when
+%% your custom compiler generates binary artifacts and does not have
+%% a particular need to run before any other compiler.
+-spec append_compilers(t(), [module()]) -> t().
append_compilers(State=#state_t{compilers=Compilers}, NewCompilers) ->
State#state_t{compilers=Compilers++NewCompilers}.
+%% @private reset all compiler modules by replacing them by a list of
+%% modules that implement the `rebar_compiler' behaviour.
+-spec compilers(t(), [module()]) -> t().
compilers(State, Compilers) ->
State#state_t{compilers=Compilers}.