Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to compiler provider to only build dependencies #1888

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/rebar_prv_compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,41 @@ init(State) ->
{example, "rebar3 compile"},
{short_desc, "Compile apps .app.src and .erl files."},
{desc, "Compile apps .app.src and .erl files."},
{opts, []}])),
{opts, [{deps_only, $d, "deps_only", undefined,
"Only compile dependencies, no project apps will be built."}]}])),
{ok, State1}.

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
IsDepsOnly = is_deps_only(State),
DepsPaths = rebar_state:code_paths(State, all_deps),
PluginDepsPaths = rebar_state:code_paths(State, all_plugin_deps),
rebar_utils:remove_from_code_path(PluginDepsPaths),
code:add_pathsa(DepsPaths),

ProjectApps = rebar_state:project_apps(State),
Providers = rebar_state:providers(State),
Deps = rebar_state:deps_to_build(State),
Cwd = rebar_state:dir(State),

copy_and_build_apps(State, Providers, Deps),

State1 = case IsDepsOnly of
true ->
State;
false ->
handle_project_apps(DepsPaths, Providers, State)
end,

rebar_utils:cleanup_code_path(rebar_state:code_paths(State1, default)
++ rebar_state:code_paths(State, all_plugin_deps)),

{ok, State1}.

is_deps_only(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
proplists:get_value(deps_only, Args, false).

handle_project_apps(DepsPaths, Providers, State) ->
Cwd = rebar_state:dir(State),
ProjectApps = rebar_state:project_apps(State),
{ok, ProjectApps1} = rebar_digraph:compile_order(ProjectApps),

%% Run top level hooks *before* project apps compiled but *after* deps are
Expand All @@ -66,10 +85,9 @@ do(State) ->
true ->
true
end,
rebar_utils:cleanup_code_path(rebar_state:code_paths(State3, default)
++ rebar_state:code_paths(State, all_plugin_deps)),

{ok, State3}.
State3.


-spec format_error(any()) -> iolist().
format_error({missing_artifact, File}) ->
Expand Down
21 changes: 20 additions & 1 deletion test/rebar_compile_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ all() ->
deps_in_path, checkout_priority, highest_version_of_pkg_dep,
parse_transform_test, erl_first_files_test, mib_test,
umbrella_mib_first_test, only_default_transitive_deps, clean_all,
profile_deps, deps_build_in_prod,
profile_deps, deps_build_in_prod, only_deps,
override_deps, override_add_deps, override_del_deps,
override_opts, override_add_opts, override_del_opts,
apply_overrides_exactly_once,
Expand Down Expand Up @@ -1655,6 +1655,25 @@ profile_deps(Config) ->
{ok, [{dep, "some_dep"},{dep, "other_dep"}]}
).

only_deps(Config) ->
AppDir = ?config(apps, Config),

Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),

Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
TopDeps = rebar_test_utils:top_level_deps(Deps),
{SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
mock_git_resource:mock([{deps, SrcDeps}]),

RConfFile = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
{ok, RConf} = file:consult(RConfFile),
rebar_test_utils:run_and_check(
Config, RConf, ["compile", "--deps_only"],
{ok, [{app_not_exist, Name}, {dep, "some_dep"},{dep, "other_dep"}]}
).

%% verify a deps prod profile is used
%% tested by checking prod hooks run and outputs to default profile dir for dep
%% and prod deps are installed for dep
Expand Down
8 changes: 8 additions & 0 deletions test/rebar_test_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ check_results(AppDir, Expected, ProfileRun) ->
ok
end
; ({dep_not_exist, Name}) ->
ct:pal("Dep Not Exist Name: ~p", [Name]),
case lists:keyfind(Name, 1, DepsNames) of
false ->
ok;
{Name, _App} ->
error({app_found, Name})
end
; ({app_not_exist, Name}) ->
ct:pal("App Not Exist Name: ~p", [Name]),
case lists:keyfind(Name, 1, DepsNames) of
false ->
Expand Down