diff options
Diffstat (limited to 'src/rebar_file_utils.erl')
-rw-r--r-- | src/rebar_file_utils.erl | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 0f84520..667be62 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -27,6 +27,7 @@ -module(rebar_file_utils). -export([try_consult/1, + consult_config/2, format_error/1, symlink_or_copy/2, rm_rf/1, @@ -39,7 +40,9 @@ reset_dir/1, touch/1, path_from_ancestor/2, - canonical_path/1]). + canonical_path/1, + resolve_link/1, + split_dirname/1]). -include("rebar.hrl"). @@ -61,6 +64,20 @@ try_consult(File) -> throw(?PRV_ERROR({bad_term_file, File, Reason})) end. +-spec consult_config(rebar_state:t(), string()) -> [[tuple()]]. +consult_config(State, Filename) -> + Fullpath = filename:join(rebar_dir:root_dir(State), Filename), + ?DEBUG("Loading configuration from ~p", [Fullpath]), + Config = case try_consult(Fullpath) of + [T] -> T; + [] -> [] + end, + SubConfigs = [consult_config(State, Entry ++ ".config") || + Entry <- Config, is_list(Entry) + ], + + [Config | lists:merge(SubConfigs)]. + format_error({bad_term_file, AppFile, Reason}) -> io_lib:format("Error reading file ~s: ~s", [AppFile, file:format_error(Reason)]). @@ -273,6 +290,22 @@ canonical_path([_|Acc], [".."|Rest]) -> canonical_path(Acc, Rest); canonical_path([], [".."|Rest]) -> canonical_path([], Rest); canonical_path(Acc, [Component|Rest]) -> canonical_path([Component|Acc], Rest). +%% returns canonical target of path if path is a link, otherwise returns path +-spec resolve_link(string()) -> string(). + +resolve_link(Path) -> + case file:read_link(Path) of + {ok, Target} -> + canonical_path(filename:absname(Target, filename:dirname(Path))); + {error, _} -> Path + end. + +%% splits a path into dirname and basename +-spec split_dirname(string()) -> {string(), string()}. + +split_dirname(Path) -> + {filename:dirname(Path), filename:basename(Path)}. + %% =================================================================== %% Internal functions %% =================================================================== |