summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_app_discover.erl13
-rw-r--r--test/rebar_compile_SUITE.erl73
2 files changed, 61 insertions, 25 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 21dea29..0c97ad7 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -52,7 +52,7 @@ do(State, LibDirs) ->
Name = rebar_app_info:name(AppInfo),
case enable(State, AppInfo) of
true ->
- {AppInfo1, StateAcc1} = merge_opts(AppInfo, StateAcc),
+ {AppInfo1, StateAcc1} = merge_opts(TopLevelApp, AppInfo, StateAcc),
OutDir = filename:join(DepsDir, Name),
AppInfo2 = rebar_app_info:out_dir(AppInfo1, OutDir),
ProjectDeps1 = lists:delete(Name, ProjectDeps),
@@ -91,9 +91,9 @@ format_error({missing_module, Module}) ->
%% some configuration like erl_opts must be merged into a subapp's opts
%% while plugins and hooks need to be kept defined to only either the
%% top level state or an individual application.
--spec merge_opts(rebar_app_info:t(), rebar_state:t()) ->
+-spec merge_opts(root | binary(), rebar_app_info:t(), rebar_state:t()) ->
{rebar_app_info:t(), rebar_state:t()}.
-merge_opts(AppInfo, State) ->
+merge_opts(TopLevelApp, AppInfo, State) ->
%% These steps make sure that hooks and artifacts are run in the context of
%% the application they are defined at. If an umbrella structure is used and
%% they are defined at the top level they will instead run in the context of
@@ -104,7 +104,12 @@ merge_opts(AppInfo, State) ->
Name = rebar_app_info:name(AppInfo1),
%% We reset the opts here to default so no profiles are applied multiple times
- AppInfo2 = rebar_app_info:apply_overrides(rebar_state:get(State1, overrides, []), AppInfo1),
+ AppInfo2 = case TopLevelApp of
+ Name -> % don't apply to the root app
+ AppInfo;
+ _ -> % apply overrides when in an umbrella project or on deps
+ rebar_app_info:apply_overrides(rebar_state:get(State1, overrides, []), AppInfo1)
+ end,
AppInfo3 = rebar_app_info:apply_profiles(AppInfo2, CurrentProfiles),
%% Will throw an exception if checks fail
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 44f20d7..8389ebc 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -27,7 +27,7 @@ all() ->
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,
+ apply_overrides_exactly_once, override_only_deps,
profile_override_deps, profile_override_add_deps, profile_override_del_deps,
profile_override_opts, profile_override_add_opts, profile_override_del_opts,
include_file_relative_to_working_directory, include_file_in_src,
@@ -1442,10 +1442,11 @@ override_del_deps(Config) ->
).
override_opts(Config) ->
- AppDir = ?config(apps, Config),
+ AppsDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
+ AppDir = filename:join([AppsDir, "apps", Name]),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [
@@ -1460,12 +1461,12 @@ override_opts(Config) ->
]}
],
- rebar_test_utils:create_config(AppDir, RebarConfig),
+ rebar_test_utils:create_config(AppsDir, RebarConfig),
rebar_test_utils:run_and_check(
Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
- Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
+ Path = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
code:add_patha(Path),
Mod = list_to_atom("not_a_real_src_" ++ Name),
@@ -1502,7 +1503,7 @@ apply_overrides_exactly_once(Config) ->
rebar_test_utils:run_and_check(
Config, RebarConfig, ["ct", "--compile_only"], {ok, [{app, Name}, {dep, "some_dep"}], "test"}).
-override_add_opts(Config) ->
+override_only_deps(Config) ->
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
@@ -1510,6 +1511,30 @@ override_add_opts(Config) ->
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [
+ {deps, []}, %% with deps enabled, this test fails
+ {overrides, [
+ {add, [
+ {erl_opts, [{d, bad, a}, {d, bad, b}]}
+ ]}
+ ]}
+ ],
+
+ rebar_test_utils:create_config(AppDir, RebarConfig),
+
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
+
+ ok.
+
+override_add_opts(Config) ->
+ AppsDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ AppDir = filename:join([AppsDir, "apps", Name]),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RebarConfig = [
{erl_opts, [
warn_missing_spec
]},
@@ -1520,12 +1545,12 @@ override_add_opts(Config) ->
]}
],
- rebar_test_utils:create_config(AppDir, RebarConfig),
+ rebar_test_utils:create_config(AppsDir, RebarConfig),
rebar_test_utils:run_and_check(
Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
- Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
+ Path = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
code:add_patha(Path),
Mod = list_to_atom("not_a_real_src_" ++ Name),
@@ -1534,10 +1559,11 @@ override_add_opts(Config) ->
true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
override_del_opts(Config) ->
- AppDir = ?config(apps, Config),
+ AppsDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
+ AppDir = filename:join([AppsDir, "apps", Name]),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [
@@ -1552,18 +1578,19 @@ override_del_opts(Config) ->
]}
],
- rebar_test_utils:create_config(AppDir, RebarConfig),
+ rebar_test_utils:create_config(AppsDir, RebarConfig),
rebar_test_utils:run_and_check(
Config, RebarConfig, ["compile"], {ok, [{app, Name}]}),
- Path = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]),
+ Path = filename:join([AppsDir, "_build", "default", "lib", Name, "ebin"]),
code:add_patha(Path),
Mod = list_to_atom("not_a_real_src_" ++ Name),
true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
- false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
+ false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])),
+ ok.
profile_override_deps(Config) ->
Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),
@@ -1665,10 +1692,11 @@ profile_override_del_deps(Config) ->
).
profile_override_opts(Config) ->
- AppDir = ?config(apps, Config),
+ AppsDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
+ AppDir = filename:join([AppsDir, "apps", Name]),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [
@@ -1687,12 +1715,12 @@ profile_override_opts(Config) ->
]}
],
- rebar_test_utils:create_config(AppDir, RebarConfig),
+ rebar_test_utils:create_config(AppsDir, RebarConfig),
rebar_test_utils:run_and_check(
Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
- Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
+ Path = filename:join([AppsDir, "_build", "a", "lib", Name, "ebin"]),
code:add_patha(Path),
Mod = list_to_atom("not_a_real_src_" ++ Name),
@@ -1701,10 +1729,11 @@ profile_override_opts(Config) ->
false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
profile_override_add_opts(Config) ->
- AppDir = ?config(apps, Config),
+ AppsDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
+ AppDir = filename:join([AppsDir, "apps", Name]),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [
@@ -1722,12 +1751,12 @@ profile_override_add_opts(Config) ->
]}
],
- rebar_test_utils:create_config(AppDir, RebarConfig),
+ rebar_test_utils:create_config(AppsDir, RebarConfig),
rebar_test_utils:run_and_check(
Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
- Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
+ Path = filename:join([AppsDir, "_build", "a", "lib", Name, "ebin"]),
code:add_patha(Path),
Mod = list_to_atom("not_a_real_src_" ++ Name),
@@ -1736,10 +1765,11 @@ profile_override_add_opts(Config) ->
true = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
profile_override_del_opts(Config) ->
- AppDir = ?config(apps, Config),
+ AppsDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
+ AppDir = filename:join([AppsDir, "apps", Name]),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [
@@ -1758,18 +1788,19 @@ profile_override_del_opts(Config) ->
]}
],
- rebar_test_utils:create_config(AppDir, RebarConfig),
+ rebar_test_utils:create_config(AppsDir, RebarConfig),
rebar_test_utils:run_and_check(
Config, RebarConfig, ["as", "a", "compile"], {ok, [{app, Name}]}),
- Path = filename:join([AppDir, "_build", "a", "lib", Name, "ebin"]),
+ Path = filename:join([AppsDir, "_build", "a", "lib", Name, "ebin"]),
code:add_patha(Path),
Mod = list_to_atom("not_a_real_src_" ++ Name),
true = lists:member(compressed, proplists:get_value(options, Mod:module_info(compile), [])),
- false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])).
+ false = lists:member(warn_missing_spec, proplists:get_value(options, Mod:module_info(compile), [])),
+ ok.
profile_deps(Config) ->
Deps = rebar_test_utils:expand_deps(git, [{"some_dep", "0.0.1", [{"other_dep", "0.0.1", []}]}]),