summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_prv_compile.erl32
-rw-r--r--test/rebar_compile_SUITE.erl21
-rw-r--r--test/rebar_test_utils.erl8
3 files changed, 53 insertions, 8 deletions
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 0b4fa5f..edb2d82 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -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
@@ -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}) ->
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 10effda..269413e 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -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,
@@ -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
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index 8bcb6d1..efe7467 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -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 ->