diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-09-22 14:13:02 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-09-22 14:13:02 -0400 |
commit | 762e8da4d383f38b9afe6002067f4fac3ecf90a8 (patch) | |
tree | 85128f4db82b6847115fc1312fa140d6b27cfe8b | |
parent | 9c5d4bfac5d3e24f38ec5f54b7517c52b053c349 (diff) | |
parent | 0867cadbd706aad81068dd3de5fae9d3f9a8b89f (diff) |
Merge pull request #821 from project-fifo/consult_and_eval-fix
Fix consult_and_eval/2 to behave like consult
-rw-r--r-- | src/rebar_config.erl | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/rebar_config.erl b/src/rebar_config.erl index 44072e8..15797da 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -109,10 +109,24 @@ format_error({bad_dep_name, Dep}) -> %% Internal functions %% =================================================================== +-spec consult_and_eval(File::file:name_all(), Script::file:name_all()) -> + {ok, Terms::[term()]} | + {error, Reason::term()}. consult_and_eval(File, Script) -> ?DEBUG("Evaluating config script ~p", [Script]), StateData = rebar_file_utils:try_consult(File), - file:script(Script, bs([{'CONFIG', StateData}, {'SCRIPT', Script}])). + %% file:consult/1 always returns the terms as a list, however file:script + %% can (and will) return any kind of term(), to make consult_and_eval + %% work the same way as eval we ensure that when no list is returned we + %% convert it in a list. + case file:script(Script, bs([{'CONFIG', StateData}, {'SCRIPT', Script}])) of + {ok, Terms} when is_list(Terms) -> + {ok, Terms}; + {ok, Term} -> + {ok, [Term]}; + Error -> + Error + end. remove_script_ext(F) -> filename:rootname(F, ".script"). |