summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-08-30 08:08:52 -0400
committerFred Hebert <mononcqc@ferd.ca>2017-08-30 08:41:03 -0400
commit7c959ccb4f91cdfdb956aa090b3789cf8fd396ed (patch)
treeb2d297cc38b688256d367ff5db7b137a4ea3f456
parent92d3fa9272582eea6ce77faab19fb74be0d4c6ce (diff)
Fix relative src dir specifications
When fetching src_dir values, some relative paths can be inserted. When deduplicating the paths on the fetch, this fact means that logically duplicate (but literally different) directories can be returned at once. By normalizing the names, duplication bugs can be resolved.
-rw-r--r--src/rebar_dir.erl11
-rw-r--r--test/rebar_dir_SUITE.erl2
2 files changed, 10 insertions, 3 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl
index d0c7805..7a779d1 100644
--- a/src/rebar_dir.erl
+++ b/src/rebar_dir.erl
@@ -258,8 +258,11 @@ extra_src_dirs(Opts, Default) ->
%% @private agnostic version of src_dirs and extra_src_dirs.
src_dirs(Type, Opts, Default) ->
- lists:usort([case D0 of {D,_} -> D; _ -> D0 end ||
- D0 <- raw_src_dirs(Type,Opts,Default)]).
+ lists:usort([
+ case D0 of
+ {D,_} -> normalize_relative_path(D);
+ _ -> normalize_relative_path(D0)
+ end || D0 <- raw_src_dirs(Type,Opts,Default)]).
%% @private extracts the un-formatted src_dirs or extra_src_dirs
%% options as configured.
@@ -271,6 +274,10 @@ raw_src_dirs(Type, Opts, Default) ->
Dirs -> Dirs
end.
+%% @private normalizes relative paths so that ./a/b/c/ => a/b/c
+normalize_relative_path(Path) ->
+ make_normalized_path(filename:split(Path), []).
+
%% @doc returns all the source directories (`src_dirs' and
%% `extra_src_dirs').
-spec all_src_dirs(rebar_dict()) -> list(file:filename_all()).
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 6797802..3b8e1fc 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -68,7 +68,7 @@ default_all_src_dirs(Config) ->
["src", "test"] = rebar_dir:all_src_dirs(rebar_state:opts(State), ["src"], ["test"]).
src_dirs(Config) ->
- RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}],
+ RebarConfig = [{erl_opts, [{src_dirs, ["foo", "./bar", "bar", "bar/", "./bar/", "baz"]}]}],
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)).