|
|
@ -13,17 +13,12 @@ |
|
|
|
-define(PROVIDER, compile). |
|
|
|
-define(DEPS, [lock]). |
|
|
|
|
|
|
|
-define(DEFAULT_JOBS, 3). |
|
|
|
|
|
|
|
%% =================================================================== |
|
|
|
%% Public API |
|
|
|
%% =================================================================== |
|
|
|
|
|
|
|
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. |
|
|
|
init(State) -> |
|
|
|
JobsHelp = io_lib:format( |
|
|
|
"Number of concurrent workers the compiler may use. Default: ~B", |
|
|
|
[?DEFAULT_JOBS]), |
|
|
|
State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER}, |
|
|
|
{module, ?MODULE}, |
|
|
|
{bare, false}, |
|
|
@ -31,42 +26,37 @@ init(State) -> |
|
|
|
{example, "rebar3 compile"}, |
|
|
|
{short_desc, "Compile apps .app.src and .erl files."}, |
|
|
|
{desc, ""}, |
|
|
|
{opts, [ |
|
|
|
{jobs, $j, "jobs", integer, JobsHelp} |
|
|
|
]}])), |
|
|
|
{opts, []}])), |
|
|
|
{ok, State1}. |
|
|
|
|
|
|
|
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. |
|
|
|
do(State) -> |
|
|
|
{ok, State1} = handle_args(State), |
|
|
|
Jobs = rebar_state:get(State1, jobs), |
|
|
|
|
|
|
|
ProjectApps = rebar_state:project_apps(State1), |
|
|
|
Deps = rebar_state:deps_to_build(State1), |
|
|
|
ProjectApps = rebar_state:project_apps(State), |
|
|
|
Deps = rebar_state:deps_to_build(State), |
|
|
|
Cwd = rebar_dir:get_cwd(), |
|
|
|
rebar_hooks:run_compile_hooks(Cwd, pre_hooks, compile, State1), |
|
|
|
rebar_hooks:run_compile_hooks(Cwd, pre_hooks, compile, State), |
|
|
|
|
|
|
|
%% Need to allow global config vars used on deps |
|
|
|
%% Right now no way to differeniate and just give deps a new state |
|
|
|
EmptyState = rebar_state:new(), |
|
|
|
build_apps(EmptyState, Deps, Jobs), |
|
|
|
build_apps(EmptyState, Deps), |
|
|
|
|
|
|
|
%% Use the project State for building project apps |
|
|
|
%% Set hooks to empty so top-level hooks aren't run for each project app |
|
|
|
State2 = rebar_state:set(rebar_state:set(State1, post_hooks, []), pre_hooks, []), |
|
|
|
ProjectApps1 = build_apps(State2, ProjectApps, Jobs), |
|
|
|
rebar_hooks:run_compile_hooks(Cwd, post_hooks, compile, State1), |
|
|
|
State2 = rebar_state:set(rebar_state:set(State, post_hooks, []), pre_hooks, []), |
|
|
|
ProjectApps1 = build_apps(State2, ProjectApps), |
|
|
|
rebar_hooks:run_compile_hooks(Cwd, post_hooks, compile, State), |
|
|
|
|
|
|
|
{ok, rebar_state:project_apps(State1, ProjectApps1)}. |
|
|
|
{ok, rebar_state:project_apps(State, ProjectApps1)}. |
|
|
|
|
|
|
|
-spec format_error(any()) -> iolist(). |
|
|
|
format_error(Reason) -> |
|
|
|
io_lib:format("~p", [Reason]). |
|
|
|
|
|
|
|
build_apps(State, Apps, Jobs) -> |
|
|
|
[build_app(State, AppInfo, Jobs) || AppInfo <- Apps]. |
|
|
|
build_apps(State, Apps) -> |
|
|
|
[build_app(State, AppInfo) || AppInfo <- Apps]. |
|
|
|
|
|
|
|
build_app(State, AppInfo, Jobs) -> |
|
|
|
build_app(State, AppInfo) -> |
|
|
|
AppDir = rebar_app_info:dir(AppInfo), |
|
|
|
OutDir = rebar_app_info:out_dir(AppInfo), |
|
|
|
|
|
|
@ -80,14 +70,10 @@ build_app(State, AppInfo, Jobs) -> |
|
|
|
AppState |
|
|
|
end, |
|
|
|
|
|
|
|
%% Set jobs in opts that was passed as an argument to the provider |
|
|
|
%% This is in case the AppInfo had a state set and used it for S |
|
|
|
S1 = rebar_state:set(S, jobs, Jobs), |
|
|
|
|
|
|
|
%% Legacy hook support |
|
|
|
rebar_hooks:run_compile_hooks(AppDir, pre_hooks, compile, S1), |
|
|
|
AppInfo1 = compile(S1, AppInfo), |
|
|
|
rebar_hooks:run_compile_hooks(AppDir, post_hooks, compile, S1), |
|
|
|
rebar_hooks:run_compile_hooks(AppDir, pre_hooks, compile, S), |
|
|
|
AppInfo1 = compile(S, AppInfo), |
|
|
|
rebar_hooks:run_compile_hooks(AppDir, post_hooks, compile, S), |
|
|
|
|
|
|
|
true = code:add_patha(rebar_app_info:ebin_dir(AppInfo1)), |
|
|
|
AppInfo1. |
|
|
@ -106,11 +92,6 @@ compile(State, AppInfo) -> |
|
|
|
%% Internal functions |
|
|
|
%% =================================================================== |
|
|
|
|
|
|
|
handle_args(State) -> |
|
|
|
{Args, _} = rebar_state:command_parsed_args(State), |
|
|
|
Jobs = proplists:get_value(jobs, Args, ?DEFAULT_JOBS), |
|
|
|
{ok, rebar_state:set(State, jobs, Jobs)}. |
|
|
|
|
|
|
|
copy_app_dirs(State, OldAppDir, AppDir) -> |
|
|
|
case ec_cnv:to_binary(filename:absname(OldAppDir)) =/= |
|
|
|
ec_cnv:to_binary(filename:absname(AppDir)) of |
|
|
|