Skip to content

Commit

Permalink
Merge pull request #836 from tsloughter/overlay-var-files
Browse files Browse the repository at this point in the history
fix overlay vars from embedded files not taking precedence
  • Loading branch information
ferd authored Nov 19, 2020
2 parents e5c6bed + a978fda commit 6242f9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/rlx_overlay.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ check_overlay_inclusion(State, RelativeRoot, Terms) ->
-spec check_overlay_inclusion(rlx_state:t(), string(), proplists:proplist(), proplists:proplist()) ->
proplists:proplist().
check_overlay_inclusion(State, RelativeRoot, [File|T], Terms) when is_list(File) ->
IncludedTerms = merge_overlay_vars(State, [filename:join(RelativeRoot, File)]),
check_overlay_inclusion(State, RelativeRoot, T, Terms ++ IncludedTerms);
%% merge terms from the file into the current terms of the system
%% passing the Terms ensures duplicates delete the existing pair
%% while keeping the order of terms the same, as is done in `merge_overlay_vars'
IncludedTerms = merge_overlay_vars(State, Terms, [filename:join(RelativeRoot, File)]),
check_overlay_inclusion(State, RelativeRoot, T, IncludedTerms);
check_overlay_inclusion(State, RelativeRoot, [Tuple|T], Terms) ->
check_overlay_inclusion(State, RelativeRoot, T, Terms ++ [Tuple]);
check_overlay_inclusion(_State, _RelativeRoot, [], Terms) ->
Expand All @@ -130,6 +133,9 @@ check_overlay_inclusion(_State, _RelativeRoot, [], Terms) ->
-spec merge_overlay_vars(rlx_state:t(), [file:name()]) ->
proplists:proplist().
merge_overlay_vars(State, FileNames) ->
merge_overlay_vars(State, [], FileNames).

merge_overlay_vars(State, Terms0, FileNames) ->
RelativeRoot = get_relative_root(State),
lists:foldl(fun(FileName, Acc) when is_list(FileName) ->
RelativePath = filename:join(RelativeRoot, iolist_to_binary(FileName)),
Expand All @@ -150,7 +156,7 @@ merge_overlay_vars(State, FileNames) ->
end;
(Var, Acc) ->
lists:keystore(element(1, Var), 1, Acc, Var)
end, [], FileNames).
end, Terms0, FileNames).

-spec render_overlay_vars(proplists:proplist(), proplists:proplist(),
proplists:proplist()) ->
Expand Down
11 changes: 7 additions & 4 deletions test/rlx_release_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ overlay_release(Config) ->
TestFileFull = filename:join(TestDirFull, TestFile),
SecondTestDir = "second_test_dir",
RelxConfig = [{overlay_vars, [{var_list_dir, "non-file-variable-list"},
OverlayVars1, OverlayVars2, OverlayVars4]},
OverlayVars1, OverlayVars2]},
{overlay, [{mkdir, "{{target_dir}}/fooo"},
{mkdir, "{{target_dir}}/{{var_list_dir}}"},
{copy, "{{goal_app_1}}/priv/subdir/foo.txt",
Expand Down Expand Up @@ -440,18 +440,23 @@ overlay_release(Config) ->
{yahoo2, [{foo, "bar"}]},
{foo_yahoo, "foo_{{yahoo}}"},
{foo_dir, "foodir"},
{prop2, 1},
{tpl_var, "defined in vars1"},
{api_caller_var, "{{api_caller_var}}"}]),

%% regression test for #827
%% OverlayVars4 must take precedence over OverlayVars3, meaning prop2 should equal 2 not 3
VarsFile2 = filename:join([LibDir1, "vars2.config"]),
rlx_test_utils:write_config(VarsFile2, [{google, "yahoo"},
{yahoo2, "foo"},
{tpl_arg, "a template value"},
{tpl_var, "Redefined in vars2 with {{tpl_arg}}"},
OverlayVars3]),
OverlayVars3,
OverlayVars4]),

VarsFile3 = filename:join([LibDir1, "vars3.config"]),
rlx_test_utils:write_config(VarsFile3, [{google, "yahoo"},
{prop2, 3},
{yahoo4, "{{yahoo}}/{{yahoo2}}4"}]),

VarsFile4 = filename:join([LibDir1, "vars4.config"]),
Expand All @@ -466,8 +471,6 @@ overlay_release(Config) ->
{ok, FileInfo} = file:read_file_info(TemplateFile),
ok = file:write_file_info(TemplateFile, FileInfo#file_info{mode=8#00777}),



ApiCallerVarValue = "api-caller-var",
ApiCallerReleaseNameValue = "release-var-conflict",
ApiCallerConfigFileValue = "state-var-conflict",
Expand Down

0 comments on commit 6242f9c

Please sign in to comment.