Skip to content

Commit b3d35a2

Browse files
authored
Merge pull request #2968 from sg2342/release_command_line_overrides
relx: do not discard command line parameters when parameter is not in…
2 parents 2235876 + 2a79259 commit b3d35a2

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

apps/rebar/src/rebar_relx.erl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,16 @@ maybe_obey_command_args(RelxConfig, Opts, Args) ->
235235
undefined ->
236236
Acc;
237237
V ->
238-
replace_all_instance(Opt, V, Acc)
238+
add_or_replace_all_instance(Opt, V, Acc)
239239
end
240240
end, RelxConfig, Args).
241241

242-
replace_all_instance(Opt, Value, RelxConfig) ->
243-
lists:map(fun({K, _}) when K =:= Opt -> {K, Value};
244-
(Other) -> Other end, RelxConfig).
242+
add_or_replace_all_instance(Opt, Value, RelxConfig) ->
243+
case lists:keymember(Opt, 1, RelxConfig) of
244+
true -> lists:map(fun({K, _}) when K =:= Opt -> {K, Value};
245+
(Other) -> Other end, RelxConfig);
246+
false -> [{Opt, Value} | RelxConfig]
247+
end.
245248

246249
%%
247250

apps/rebar/test/rebar_release_SUITE.erl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ all() -> [release,
88
dev_mode_release,
99
profile_dev_mode_override_release,
1010
tar,
11+
command_line_override,
1112
profile_ordering_sys_config_extend,
1213
profile_ordering_sys_config_extend_3_tuple_merge,
1314
extend_release,
@@ -74,6 +75,19 @@ config_file(Config) ->
7475
rebar_test_utils:run_and_check(Config, [{relx, RelxConfig("4.0.0")}], ["release"],
7576
{ok, [{release, Name, "4.0.0", false}]}).
7677

78+
command_line_override(Config) ->
79+
%% regression test for #2967
80+
AppDir = ?config(apps, Config),
81+
Vsn = "0.0.0",
82+
Name = list_to_atom(?config(name, Config)),
83+
Content = [{Name, [{something, true}]}],
84+
InputPath = filename:join([AppDir, "config", "mysysconfig"]),
85+
rebar_test_utils:create_config(AppDir, InputPath, Content),
86+
RelxConfig = [{release, {Name, Vsn}, [Name]}, {lib_dirs, [AppDir]}],
87+
rebar_test_utils:run_and_check(Config, [{relx, RelxConfig}], ["release", "--sys_config=" ++ InputPath],
88+
{ok, [{release, Name, Vsn, false}]}),
89+
{ok, Content} = file:consult(filename:join([AppDir, "_build/default/rel", Name, "releases", Vsn, "sys.config"])).
90+
7791
dev_mode_release(Config) ->
7892
AppDir = ?config(apps, Config),
7993
Name = ?config(name, Config),

0 commit comments

Comments
 (0)