Skip to content

Commit

Permalink
support tuples in overlay_vars so rebar3 can pass variables (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter authored Oct 5, 2018
1 parent 048788f commit bb8af6d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/rlx_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ list_of_overlay_vars_files(undefined) ->
[];
list_of_overlay_vars_files([]) ->
[];
list_of_overlay_vars_files([H | _]=FileNames) when erlang:is_list(H) ->
FileNames;
list_of_overlay_vars_files([H | _]=Vars) when erlang:is_list(H) ;
is_tuple(H) ->
Vars;
list_of_overlay_vars_files(FileName) when is_list(FileName) ->
[FileName].

Expand All @@ -328,7 +329,8 @@ merge_configs([{Key, Value} | CliTerms], ConfigTerms) ->
end;
overlay_vars ->
case lists:keyfind(overlay_vars, 1, ConfigTerms) of
{_, [H | _] = Vars} when is_list(H) ->
{_, [H | _] = Vars} when is_list(H) ;
is_tuple(H) ->
MergedValue = Vars ++ Value,
merge_configs(CliTerms, lists:keyreplace(overlay_vars, 1, ConfigTerms, {Key, MergedValue}));
{_, Vars} when is_list(Vars) ->
Expand Down
21 changes: 8 additions & 13 deletions src/rlx_prv_overlay.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ get_overlay_vars_from_file(State, OverlayVars) ->
OverlayVars;
[] ->
OverlayVars;
[H | _]=FileNames when is_list(H) ->
[H | _]=FileNames when is_list(H) ;
is_tuple(H) ->
read_overlay_vars(State, OverlayVars, FileNames);
FileName when is_list(FileName) ->
read_overlay_vars(State, OverlayVars, [FileName])
Expand Down Expand Up @@ -181,30 +182,24 @@ check_overlay_inclusion(_State, _RelativeRoot, [], Terms) ->
proplists:proplist().
merge_overlay_vars(State, FileNames) ->
RelativeRoot = get_relative_root(State),
lists:foldl(fun(FileName, Acc) ->
RelativePath = filename:join(RelativeRoot, erlang:iolist_to_binary(FileName)),
lists:foldl(fun(FileName, Acc) when is_list(FileName) ->
RelativePath = filename:join(RelativeRoot, iolist_to_binary(FileName)),
case file:consult(RelativePath) of
%% {ok, [Terms]} ->
%% lists:ukeymerge(1, lists:ukeysort(1, Terms), Acc);
%% % the location of the included overlay files will be relative
%% %% to the current one being read
%% %% OverlayRelativeRoot = filename:dirname(FileName),
%% %% NewTerms = check_overlay_inclusion(State, OverlayRelativeRoot, Terms),

%% %% lists:ukeymerge(1, lists:ukeysort(1, NewTerms), Acc);
{ok, Terms} ->
%% the location of the included overlay files will be relative
%% to the current one being read
OverlayRelativeRoot = filename:dirname(FileName),
NewTerms = check_overlay_inclusion(State, OverlayRelativeRoot, Terms),
lists:foldl(fun(NewTerm, A) ->
lists:keystore(element(1, NewTerm), 1, A, NewTerm)
lists:keystore(element(1, NewTerm), 1, A, NewTerm)
end, Acc, NewTerms);
{error, Reason} ->
ec_cmd_log:warn(rlx_state:log(State),
format_error({unable_to_read_varsfile, FileName, Reason})),
Acc
end
end;
(Var, Acc) ->
lists:keystore(element(1, Var), 1, Acc, Var)
end, [], FileNames).

-spec render_overlay_vars(proplists:proplist(), proplists:proplist(),
Expand Down
5 changes: 4 additions & 1 deletion test/rlx_release_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,10 @@ overlay_release(Config) ->
TestFileFull = filename:join(TestDirFull, TestFile),
SecondTestDir = "second_test_dir",
rlx_test_utils:write_config(ConfigFile,
[{overlay_vars, [OverlayVars1, OverlayVars2, OverlayVars4]},
[{overlay_vars, [{var_list_dir, "non-file-variable-list"},
OverlayVars1, OverlayVars2, OverlayVars4]},
{overlay, [{mkdir, "{{target_dir}}/fooo"},
{mkdir, "{{target_dir}}/{{var_list_dir}}"},
{copy, OverlayVars1,
"{{target_dir}}/{{foo_dir}}/vars1.config"},
{copy, OverlayVars1,
Expand Down Expand Up @@ -727,6 +729,7 @@ overlay_release(Config) ->
?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)),

?assert(ec_file:exists(filename:join([OutputDir, "foo", "non-file-variable-list"]))),
?assert(ec_file:exists(filename:join([OutputDir, "foo", "fooo"]))),
?assert(ec_file:exists(filename:join([OutputDir, "foo", "foodir", "vars1.config"]))),
?assert(ec_file:exists(filename:join([OutputDir, "foo", "yahoo", "vars1.config"]))),
Expand Down

0 comments on commit bb8af6d

Please sign in to comment.