浏览代码

dedup `src_dirs` and `extra_src_dirs` on read

pull/898/head
alisdair sullivan 9 年前
父节点
当前提交
edfa4427a3
共有 3 个文件被更改,包括 15 次插入15 次删除
  1. +3
    -3
      src/rebar_dir.erl
  2. +6
    -6
      test/rebar_dir_SUITE.erl
  3. +6
    -6
      test/rebar_src_dirs_SUITE.erl

+ 3
- 3
src/rebar_dir.erl 查看文件

@ -139,7 +139,7 @@ src_dirs(Opts, Default) ->
Vs = proplists:get_all_values(src_dirs, ErlOpts), Vs = proplists:get_all_values(src_dirs, ErlOpts),
case lists:append([rebar_opts:get(Opts, src_dirs, []) | Vs]) of case lists:append([rebar_opts:get(Opts, src_dirs, []) | Vs]) of
[] -> Default; [] -> Default;
Dirs -> Dirs
Dirs -> lists:usort(Dirs)
end. end.
-spec extra_src_dirs(rebar_dict()) -> list(file:filename_all()). -spec extra_src_dirs(rebar_dict()) -> list(file:filename_all()).
@ -151,7 +151,7 @@ extra_src_dirs(Opts, Default) ->
Vs = proplists:get_all_values(extra_src_dirs, ErlOpts), Vs = proplists:get_all_values(extra_src_dirs, ErlOpts),
case lists:append([rebar_opts:get(Opts, extra_src_dirs, []) | Vs]) of case lists:append([rebar_opts:get(Opts, extra_src_dirs, []) | Vs]) of
[] -> Default; [] -> Default;
Dirs -> Dirs
Dirs -> lists:usort(Dirs)
end. end.
-spec all_src_dirs(rebar_dict()) -> list(file:filename_all()). -spec all_src_dirs(rebar_dict()) -> list(file:filename_all()).
@ -160,7 +160,7 @@ all_src_dirs(Opts) -> all_src_dirs(Opts, [], []).
-spec all_src_dirs(rebar_dict(), list(file:filename_all()), list(file:filename_all())) -> -spec all_src_dirs(rebar_dict(), list(file:filename_all()), list(file:filename_all())) ->
list(file:filename_all()). list(file:filename_all()).
all_src_dirs(Opts, SrcDefault, ExtraDefault) -> all_src_dirs(Opts, SrcDefault, ExtraDefault) ->
src_dirs(Opts, SrcDefault) ++ extra_src_dirs(Opts, ExtraDefault).
lists:usort(src_dirs(Opts, SrcDefault) ++ extra_src_dirs(Opts, ExtraDefault)).
%% given a path if that path is an ancestor of an app dir return the path relative to that %% given a path if that path is an ancestor of an app dir return the path relative to that
%% apps outdir. if the path is not an ancestor to any app dirs but is an ancestor of the %% apps outdir. if the path is not an ancestor to any app dirs but is an ancestor of the

+ 6
- 6
test/rebar_dir_SUITE.erl 查看文件

@ -55,19 +55,19 @@ src_dirs(Config) ->
RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}], RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}],
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["foo", "bar", "baz"] = rebar_dir:src_dirs(rebar_state:opts(State)).
["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)).
extra_src_dirs(Config) -> extra_src_dirs(Config) ->
RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}], RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}],
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(rebar_state:opts(State)).
["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State)).
all_src_dirs(Config) -> all_src_dirs(Config) ->
RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}, {extra_src_dirs, ["baz", "qux"]}]}], RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}, {extra_src_dirs, ["baz", "qux"]}]}],
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["foo", "bar", "baz", "qux"] = rebar_dir:all_src_dirs(rebar_state:opts(State)).
["bar", "baz", "foo", "qux"] = rebar_dir:all_src_dirs(rebar_state:opts(State)).
profile_src_dirs(Config) -> profile_src_dirs(Config) ->
RebarConfig = [ RebarConfig = [
@ -79,7 +79,7 @@ profile_src_dirs(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return),
R = lists:sort(["foo", "bar", "baz", "qux"]), R = lists:sort(["foo", "bar", "baz", "qux"]),
R = lists:sort(rebar_dir:src_dirs(rebar_state:opts(State))).
R = rebar_dir:src_dirs(rebar_state:opts(State)).
profile_extra_src_dirs(Config) -> profile_extra_src_dirs(Config) ->
RebarConfig = [ RebarConfig = [
@ -91,7 +91,7 @@ profile_extra_src_dirs(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return),
R = lists:sort(["foo", "bar", "baz", "qux"]), R = lists:sort(["foo", "bar", "baz", "qux"]),
R = lists:sort(rebar_dir:extra_src_dirs(rebar_state:opts(State))).
R = rebar_dir:extra_src_dirs(rebar_state:opts(State)).
profile_all_src_dirs(Config) -> profile_all_src_dirs(Config) ->
RebarConfig = [ RebarConfig = [
@ -103,7 +103,7 @@ profile_all_src_dirs(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "more", "compile"], return),
R = lists:sort(["foo", "bar", "baz", "qux"]), R = lists:sort(["foo", "bar", "baz", "qux"]),
R = lists:sort(rebar_dir:all_src_dirs(rebar_state:opts(State))).
R = rebar_dir:all_src_dirs(rebar_state:opts(State)).
retarget_path(Config) -> retarget_path(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),

+ 6
- 6
test/rebar_src_dirs_SUITE.erl 查看文件

@ -49,7 +49,7 @@ src_dirs_at_root(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["foo", "bar", "baz"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
extra_src_dirs_at_root(Config) -> extra_src_dirs_at_root(Config) ->
AppDir = ?config(apps, Config), AppDir = ?config(apps, Config),
@ -62,7 +62,7 @@ extra_src_dirs_at_root(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
src_dirs_in_erl_opts(Config) -> src_dirs_in_erl_opts(Config) ->
AppDir = ?config(apps, Config), AppDir = ?config(apps, Config),
@ -75,7 +75,7 @@ src_dirs_in_erl_opts(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["foo", "bar", "baz"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
extra_src_dirs_in_erl_opts(Config) -> extra_src_dirs_in_erl_opts(Config) ->
AppDir = ?config(apps, Config), AppDir = ?config(apps, Config),
@ -88,7 +88,7 @@ extra_src_dirs_in_erl_opts(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
src_dirs_at_root_and_in_erl_opts(Config) -> src_dirs_at_root_and_in_erl_opts(Config) ->
AppDir = ?config(apps, Config), AppDir = ?config(apps, Config),
@ -101,7 +101,7 @@ src_dirs_at_root_and_in_erl_opts(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["baz", "qux", "foo", "bar"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State), []).
extra_src_dirs_at_root_and_in_erl_opts(Config) -> extra_src_dirs_at_root_and_in_erl_opts(Config) ->
AppDir = ?config(apps, Config), AppDir = ?config(apps, Config),
@ -114,7 +114,7 @@ extra_src_dirs_at_root_and_in_erl_opts(Config) ->
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
["baz", "qux", "foo", "bar"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
["bar", "baz", "foo", "qux"] = rebar_dir:extra_src_dirs(rebar_state:opts(State), []).
build_basic_app(Config) -> build_basic_app(Config) ->
AppDir = ?config(apps, Config), AppDir = ?config(apps, Config),

正在加载...
取消
保存