diff options
author | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2017-01-21 09:53:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-21 09:53:15 -0800 |
commit | 6a1cfaf9483e93b5410a21e4967d53f0ecf4b3c0 (patch) | |
tree | 49a1515f9e74f506d973fd16aab40eb1a916ea62 /src/rebar_dir.erl | |
parent | e3f08361b66df8f7a4b33402a62ce739c791b422 (diff) | |
parent | f16fdd35be2d0d6acb0a4b3448b12d7796751b80 (diff) |
Merge pull request #1450 from ferd/relative-dialyzer-paths
Relative dialyzer paths
Diffstat (limited to 'src/rebar_dir.erl')
-rw-r--r-- | src/rebar_dir.erl | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 069d8fd..b61bfcc 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -26,7 +26,8 @@ src_dir_opts/2, recursive/2, extra_src_dirs/1, extra_src_dirs/2, all_src_dirs/1, all_src_dirs/3, - retarget_path/2]). + retarget_path/2, + format_source_file_name/2]). -include("rebar.hrl"). @@ -334,3 +335,39 @@ retarget_path(State, Path, [App|Rest]) -> {ok, NewPath} -> filename:join([rebar_app_info:out_dir(App), NewPath]); {error, badparent} -> retarget_path(State, Path, Rest) end. + +format_source_file_name(Path, Opts) -> + Type = case rebar_opts:get(Opts, compiler_source_format, + ?DEFAULT_COMPILER_SOURCE_FORMAT) of + V when V == absolute; V == relative; V == build -> + V; + Other -> + warn_source_format_once(Other) + end, + case Type of + absolute -> resolve_linked_source(Path); + build -> Path; + relative -> + Cwd = rebar_dir:get_cwd(), + rebar_dir:make_relative_path(resolve_linked_source(Path), Cwd) + end. + +%% @private displays a warning for the compiler source format option +%% only once +-spec warn_source_format_once(term()) -> ok. +warn_source_format_once(Format) -> + Warn = application:get_env(rebar, warn_source_format) =/= {ok, false}, + application:set_env(rebar, warn_source_format, false), + case Warn of + false -> + ok; + true -> + ?WARN("Invalid argument ~p for compiler_source_format - " + "assuming ~s~n", [Format, ?DEFAULT_COMPILER_SOURCE_FORMAT]) + end. + +%% @private takes a filename and canonicalizes its path if it is a link. +-spec resolve_linked_source(file:filename()) -> file:filename(). +resolve_linked_source(Src) -> + {Dir, Base} = rebar_file_utils:split_dirname(Src), + filename:join(rebar_file_utils:resolve_link(Dir), Base). |