Browse Source

add compile type for dynamic project compilation

pull/1893/head
Tristan Sloughter 6 years ago
parent
commit
8df694d426
No known key found for this signature in database GPG Key ID: AAB97DDECCEB8150
3 changed files with 28 additions and 2 deletions
  1. +1
    -1
      src/rebar_app_discover.erl
  2. +14
    -0
      src/rebar_app_info.erl
  3. +13
    -1
      src/rebar_prv_compile.erl

+ 1
- 1
src/rebar_app_discover.erl View File

@ -427,7 +427,7 @@ try_handle_app_src_file(AppInfo, _, _AppDir, [], _Validate) ->
%% a .app after this step %% a .app after this step
case filelib:is_file(filename:join(rebar_app_info:dir(AppInfo), "mix.exs")) of case filelib:is_file(filename:join(rebar_app_info:dir(AppInfo), "mix.exs")) of
true -> true ->
{true, AppInfo};
{true, rebar_app_info:compile_type(AppInfo, mix)};
false -> false ->
false false
end; end;

+ 14
- 0
src/rebar_app_info.erl View File

@ -47,6 +47,8 @@
set/3, set/3,
source/1, source/1,
source/2, source/2,
compile_type/1,
compile_type/2,
is_lock/1, is_lock/1,
is_lock/2, is_lock/2,
is_checkout/1, is_checkout/1,
@ -89,6 +91,7 @@
is_lock=false :: boolean(), is_lock=false :: boolean(),
is_checkout=false :: boolean(), is_checkout=false :: boolean(),
valid :: boolean() | undefined, valid :: boolean() | undefined,
compile_type :: rebar3 | mix | undefined,
is_available=false :: boolean()}). is_available=false :: boolean()}).
%%============================================================================ %%============================================================================
@ -500,6 +503,17 @@ is_available(#app_info_t{is_available=IsAvailable}) ->
is_available(AppInfo=#app_info_t{}, IsAvailable) -> is_available(AppInfo=#app_info_t{}, IsAvailable) ->
AppInfo#app_info_t{is_available=IsAvailable}. AppInfo#app_info_t{is_available=IsAvailable}.
%% @doc
-spec compile_type(t()) -> atom().
compile_type(#app_info_t{compile_type=CompileType}) ->
CompileType.
%% @doc
-spec compile_type(t(), atom()) -> t().
compile_type(AppInfo=#app_info_t{}, CompileType) ->
AppInfo#app_info_t{compile_type=CompileType}.
%% @doc returns whether the app is valid (built) or not %% @doc returns whether the app is valid (built) or not
-spec valid(t()) -> boolean(). -spec valid(t()) -> boolean().
valid(AppInfo=#app_info_t{valid=undefined}) -> valid(AppInfo=#app_info_t{valid=undefined}) ->

+ 13
- 1
src/rebar_prv_compile.erl View File

@ -150,7 +150,19 @@ compile(State, Providers, AppInfo) ->
AppInfo1 = rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State), AppInfo1 = rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State),
AppInfo2 = rebar_hooks:run_all_hooks(AppDir, pre, ?ERLC_HOOK, Providers, AppInfo1, State), AppInfo2 = rebar_hooks:run_all_hooks(AppDir, pre, ?ERLC_HOOK, Providers, AppInfo1, State),
rebar_erlc_compiler:compile(AppInfo2),
case rebar_app_info:compile_type(AppInfo) of
mix ->
rebar_utils:sh("mix compile --no-deps-check --no-protocol-consolidation",
[{cd, AppDir},
{return_on_error, true},
{use_stdout, true},
{env, [{"MIX_BUILD_PATH", filename:join(AppDir, "../../")},
{"MIX_ENV", "prod"}]}]);
_ ->
rebar_erlc_compiler:compile(AppInfo2)
end,
AppInfo3 = rebar_hooks:run_all_hooks(AppDir, post, ?ERLC_HOOK, Providers, AppInfo2, State), AppInfo3 = rebar_hooks:run_all_hooks(AppDir, post, ?ERLC_HOOK, Providers, AppInfo2, State),
AppInfo4 = rebar_hooks:run_all_hooks(AppDir, pre, ?APP_HOOK, Providers, AppInfo3, State), AppInfo4 = rebar_hooks:run_all_hooks(AppDir, pre, ?APP_HOOK, Providers, AppInfo3, State),

Loading…
Cancel
Save