From 8df694d426335c140f1ad69117693c752fd1efd3 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 14 Sep 2018 15:09:52 -0600 Subject: [PATCH] add compile type for dynamic project compilation --- src/rebar_app_discover.erl | 2 +- src/rebar_app_info.erl | 14 ++++++++++++++ src/rebar_prv_compile.erl | 14 +++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 224539b1..655094ae 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -427,7 +427,7 @@ try_handle_app_src_file(AppInfo, _, _AppDir, [], _Validate) -> %% a .app after this step case filelib:is_file(filename:join(rebar_app_info:dir(AppInfo), "mix.exs")) of true -> - {true, AppInfo}; + {true, rebar_app_info:compile_type(AppInfo, mix)}; false -> false end; diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index eb953115..ba4eb171 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -47,6 +47,8 @@ set/3, source/1, source/2, + compile_type/1, + compile_type/2, is_lock/1, is_lock/2, is_checkout/1, @@ -89,6 +91,7 @@ is_lock=false :: boolean(), is_checkout=false :: boolean(), valid :: boolean() | undefined, + compile_type :: rebar3 | mix | undefined, is_available=false :: boolean()}). %%============================================================================ @@ -500,6 +503,17 @@ is_available(#app_info_t{is_available=IsAvailable}) -> is_available(AppInfo=#app_info_t{}, 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 -spec valid(t()) -> boolean(). valid(AppInfo=#app_info_t{valid=undefined}) -> diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index edb2d82c..1690f068 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -150,7 +150,19 @@ compile(State, Providers, AppInfo) -> 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), - 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), AppInfo4 = rebar_hooks:run_all_hooks(AppDir, pre, ?APP_HOOK, Providers, AppInfo3, State),