diff options
author | Heinz N. Gies <heinz@licenser.net> | 2015-09-20 22:08:12 +0200 |
---|---|---|
committer | Heinz N. Gies <heinz@licenser.net> | 2015-09-20 22:08:12 +0200 |
commit | 0867cadbd706aad81068dd3de5fae9d3f9a8b89f (patch) | |
tree | 1e7e631aa166f1c0c74827a58cd9414acea571c2 /src | |
parent | fb63743bc6f8dbdf07efda65e78ff68567a8d5d5 (diff) |
Fix consult_and_eval/2 to behave like consult
Diffstat (limited to 'src')
-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"). |