diff options
Diffstat (limited to 'src/rlx_config.erl')
-rw-r--r-- | src/rlx_config.erl | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/src/rlx_config.erl b/src/rlx_config.erl index 4160bba..90cfe7c 100644 --- a/src/rlx_config.erl +++ b/src/rlx_config.erl @@ -53,7 +53,11 @@ format_error({consult, ConfigFile, Reason}) -> io_lib:format("Unable to read file ~s: ~s", [ConfigFile, file:format_error(Reason)]); format_error({invalid_term, Term}) -> - io_lib:format("Invalid term in config file: ~p", [Term]). + io_lib:format("Invalid term in config file: ~p", [Term]); +format_error({failed_to_parse, Goal}) -> + io_lib:format("Unable to parse goal ~s", [Goal]); +format_error({invalid_goal, Goal}) -> + io_lib:format("Invalid goal: ~p", [Goal]). %%%=================================================================== %%% Internal Functions @@ -182,7 +186,7 @@ load_terms({overrides, Overrides0}, {ok, State0}) -> load_terms({dev_mode, DevMode}, {ok, State0}) -> {ok, rlx_state:dev_mode(State0, DevMode)}; load_terms({goals, Goals}, {ok, State0}) -> - {ok, rlx_state:goals(State0, Goals)}; + parse_goals(Goals, State0); load_terms({upfrom, UpFrom}, {ok, State0}) -> {ok, rlx_state:upfrom(State0, UpFrom)}; load_terms({include_src, IncludeSrc}, {ok, State0}) -> @@ -193,8 +197,7 @@ load_terms({release, {RelName, Vsn, {extend, RelName2}}, Applications}, {ok, Sta ExtendRelease = rlx_state:get_configured_release(State0, RelName2, NewVsn), Applications1 = rlx_release:goals(ExtendRelease), case rlx_release:goals(Release0, - lists:umerge(lists:usort(Applications), - lists:usort(Applications1))) of + rlx_release:merge_application_goals(Applications, Applications1)) of E={error, _} -> E; {ok, Release1} -> @@ -206,8 +209,7 @@ load_terms({release, {RelName, Vsn, {extend, RelName2}}, Applications, Config}, ExtendRelease = rlx_state:get_configured_release(State0, RelName2, NewVsn), Applications1 = rlx_release:goals(ExtendRelease), case rlx_release:goals(Release0, - lists:umerge(lists:usort(Applications), - lists:usort(Applications1))) of + rlx_release:merge_application_goals(Applications, Applications1)) of E={error, _} -> E; {ok, Release1} -> @@ -299,6 +301,34 @@ add_hooks(Hooks, State) -> rlx_state:append_hook(StateAcc, Target, Hook) end, State, Hooks)}. +parse_goals(Goals0, State) -> + {Goals, Error} = lists:mapfoldl(fun + (Goal, ok) when is_list(Goal); is_binary(Goal) -> + case rlx_goal:parse(Goal) of + {ok, Constraint} -> + {Constraint, ok}; + {fail, _} -> + {[], ?RLX_ERROR({failed_to_parse, Goal})} + end; + (Goal, ok) when is_tuple(Goal); is_atom(Goal) -> + case rlx_depsolver:is_valid_raw_constraint(Goal) of + true -> + {Goal, ok}; + false -> + {[], ?RLX_ERROR({invalid_goal, Goal})} + end; + (_, Err = {error, _}) -> + {[], Err}; + (Goal, _) -> + {[], ?RLX_ERROR({invalid_goal, Goal})} + end, ok, Goals0), + case Error of + ok -> + {ok, rlx_state:goals(State, Goals)}; + _ -> + Error + end. + list_of_overlay_vars_files(undefined) -> []; list_of_overlay_vars_files([]) -> @@ -346,6 +376,16 @@ merge_configs([{Key, Value} | CliTerms], ConfigTerms) -> merge_configs(CliTerms, lists:reverse(lists:keystore(Key, 1, lists:reverse(ConfigTerms), {Key, Value}))) end. +parse_vsn(Vsn) when Vsn =:= git ; Vsn =:= "git" -> + {ok, V} = ec_git_vsn:vsn(ec_git_vsn:new()), + V; +parse_vsn({git, short}) -> + git_ref("--short"); +parse_vsn({git, long}) -> + git_ref(""); +parse_vsn({file, File}) -> + {ok, Vsn} = file:read_file(File), + binary_to_list(rlx_string:trim(Vsn, both, "\n")); parse_vsn(Vsn) when Vsn =:= semver ; Vsn =:= "semver" -> {ok, V} = ec_git_vsn:vsn(ec_git_vsn:new()), V; @@ -357,3 +397,20 @@ parse_vsn({cmd, Command}) -> V; parse_vsn(Vsn) -> Vsn. + +git_ref(Arg) -> + case os:cmd("git rev-parse " ++ Arg ++ " HEAD") of + String -> + Vsn = rlx_string:trim(String, both, "\n"), + case length(Vsn) =:= 40 orelse length(Vsn) =:= 7 of + true -> + Vsn; + false -> + %% if the result isn't exactly either 40 or 7 characters then + %% it must have failed + {ok, Dir} = file:get_cwd(), + ec_cmd_log:warn("Getting ref of git repo failed in ~ts. " + "Falling back to version 0", [Dir]), + {plain, "0"} + end + end. |