From 44fabbbf9173bc97365ccb3c7d28d1bc8503c28d Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Fri, 18 Nov 2016 17:42:39 +0100 Subject: Add 'recursive' option The option {recursive,boolean()} can now be set pr directory in 'src_dirs' and 'extra_src_dirs', and on top level in the new 'erlc_compiler' option. Example config: {erlc_compiler,[{recursive,false}]}. {src_dirs,[{"src",[{recursive,true}]}]}. This will cause recursive compilation within the "src" directory, but not in any other directoires. --- test/rebar_dir_SUITE.erl | 66 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) (limited to 'test/rebar_dir_SUITE.erl') diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index 9734830..6797802 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -3,8 +3,10 @@ -export([all/0, init_per_testcase/2, end_per_testcase/2]). -export([default_src_dirs/1, default_extra_src_dirs/1, default_all_src_dirs/1]). --export([src_dirs/1, extra_src_dirs/1, all_src_dirs/1]). +-export([src_dirs/1, src_dirs_with_opts/1, extra_src_dirs/1, all_src_dirs/1]). +-export([src_dir_opts/1, recursive/1]). -export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]). +-export([profile_src_dir_opts/1]). -export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_rel/1]). -export([global_cache_dir/1, default_global_cache_dir/1, overwrite_default_global_cache_dir/1]). @@ -14,8 +16,9 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs, - src_dirs, extra_src_dirs, all_src_dirs, + src_dirs, extra_src_dirs, all_src_dirs, src_dir_opts, recursive, profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs, + profile_src_dir_opts, retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir, default_global_cache_dir, overwrite_default_global_cache_dir]. @@ -70,6 +73,13 @@ src_dirs(Config) -> ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)). +src_dirs_with_opts(Config) -> + RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}, + {src_dirs, [{"foo",[{recursive,false}]}, "qux"]}]}], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), + + ["bar", "baz", "foo", "qux"] = rebar_dir:src_dirs(rebar_state:opts(State)). + extra_src_dirs(Config) -> RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}], {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), @@ -77,11 +87,41 @@ extra_src_dirs(Config) -> ["bar", "baz", "foo"] = rebar_dir:extra_src_dirs(rebar_state:opts(State)). 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"]}, {src_dirs, [{"foo", [{recursive,false}]}]}]}], {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return), ["bar", "baz", "foo", "qux"] = rebar_dir:all_src_dirs(rebar_state:opts(State)). +src_dir_opts(Config) -> + RebarConfig = + [{erl_opts, [{src_dirs, [{"foo",[{recursive,true}]}, "bar"]}, + {extra_src_dirs, ["baz", {"foo", [{recursive,false}]}]}, + {src_dirs, [{"foo", [{recursive,false}]}]}]}], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, + ["compile"], return), + [{recursive,true}] = rebar_dir:src_dir_opts(rebar_state:opts(State), "foo"), + [] = rebar_dir:src_dir_opts(rebar_state:opts(State), "bar"), + [] = rebar_dir:src_dir_opts(rebar_state:opts(State), "nonexisting"). + +recursive(Config) -> + RebarConfig1 = + [{erl_opts, [{src_dirs, ["foo", "bar"]}, + {extra_src_dirs, ["baz", {"foo", [{recursive,true}]}]}, + {src_dirs, [{"foo", [{recursive,false}]}]}]}], + {ok, State1} = rebar_test_utils:run_and_check(Config, RebarConfig1, + ["compile"], return), + false = rebar_dir:recursive(rebar_state:opts(State1), "foo"), + true = rebar_dir:recursive(rebar_state:opts(State1), "bar"), + + RebarConfig2 = [{erlc_compiler,[{recursive,false}]}, + {erl_opts,[{src_dirs,["foo",{"bar",[{recursive,true}]}]}]}], + {ok, State2} = rebar_test_utils:run_and_check(Config, RebarConfig2, + ["compile"], return), + false = rebar_dir:recursive(rebar_state:opts(State2), "foo"), + true = rebar_dir:recursive(rebar_state:opts(State2), "bar"), + + ok. + profile_src_dirs(Config) -> RebarConfig = [ {erl_opts, [{src_dirs, ["foo", "bar"]}]}, @@ -118,6 +158,26 @@ profile_all_src_dirs(Config) -> R = lists:sort(["foo", "bar", "baz", "qux"]), R = rebar_dir:all_src_dirs(rebar_state:opts(State)). +profile_src_dir_opts(Config) -> + RebarConfig = [ + {erl_opts, [{src_dirs, ["foo"]}, + {extra_src_dirs, [{"bar",[recursive]}]}]}, + {profiles, [ + {more, [{erl_opts, [{src_dirs, [{"bar",[{recursive,false}]}]}, + {extra_src_dirs, ["qux"]}]}]} + ]} + ], + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "more", "compile"], + return), + + [{recursive,false}] = rebar_dir:src_dir_opts(rebar_state:opts(State),"bar"), + + {ok, State1} = rebar_test_utils:run_and_check(Config, RebarConfig, + ["compile"], return), + + [{recursive,true}] = rebar_dir:src_dir_opts(rebar_state:opts(State1),"bar"). + retarget_path(Config) -> {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), -- cgit v1.1 From 7c959ccb4f91cdfdb956aa090b3789cf8fd396ed Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Wed, 30 Aug 2017 08:08:52 -0400 Subject: 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. --- test/rebar_dir_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/rebar_dir_SUITE.erl') 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)). -- cgit v1.1 From cf83eb7fc45fac677a83b5f38e87c581cf516cf2 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Wed, 27 Sep 2017 19:01:44 -0400 Subject: Corrects a fix to src_dir values The previous patch at #7c959cc fixed the usage of duplicate values for directories through relative paths, but mistakenly went overboard and dropped the `./` path, which is still fairly common. Similarly for `../". The code is modified to special-case such values and keep the code working. --- test/rebar_dir_SUITE.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/rebar_dir_SUITE.erl') diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index 3b8e1fc..4743865 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -68,10 +68,11 @@ 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", "bar", "bar/", "./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)). + [".", "..", "../..", "bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)). src_dirs_with_opts(Config) -> RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}, -- cgit v1.1 From 288d0c7484ba9214cc6598100000bcce0fefe462 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Mon, 23 Apr 2018 13:38:37 -0400 Subject: Clear all dialyzer errors - this is done by adding a HiPE dependency - also in this: adding a test for directories, and fixing some indent --- test/rebar_dir_SUITE.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test/rebar_dir_SUITE.erl') diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index 4743865..0eda5bf 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -5,6 +5,7 @@ -export([default_src_dirs/1, default_extra_src_dirs/1, default_all_src_dirs/1]). -export([src_dirs/1, src_dirs_with_opts/1, extra_src_dirs/1, all_src_dirs/1]). -export([src_dir_opts/1, recursive/1]). +-export([top_src_dirs/1]). -export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]). -export([profile_src_dir_opts/1]). -export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_rel/1]). @@ -18,7 +19,7 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs, src_dirs, extra_src_dirs, all_src_dirs, src_dir_opts, recursive, profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs, - profile_src_dir_opts, + profile_src_dir_opts, top_src_dirs, retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir, default_global_cache_dir, overwrite_default_global_cache_dir]. @@ -123,6 +124,15 @@ recursive(Config) -> ok. +top_src_dirs(Config) -> + %% We can get the same result out of specifying src_dirs from the config root, + %% not just the erl_opts + RebarConfig = [{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)). + profile_src_dirs(Config) -> RebarConfig = [ {erl_opts, [{src_dirs, ["foo", "bar"]}]}, -- cgit v1.1 From c22fde17a7a30cee5e3e5e04fab187eed2ecfe42 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 23 Apr 2018 22:34:40 +0300 Subject: fix & test --- test/rebar_dir_SUITE.erl | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'test/rebar_dir_SUITE.erl') diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index 4743865..e544410 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -3,7 +3,7 @@ -export([all/0, init_per_testcase/2, end_per_testcase/2]). -export([default_src_dirs/1, default_extra_src_dirs/1, default_all_src_dirs/1]). --export([src_dirs/1, src_dirs_with_opts/1, extra_src_dirs/1, all_src_dirs/1]). +-export([src_dirs/1, alt_src_dir_nested/1, src_dirs_with_opts/1, extra_src_dirs/1, all_src_dirs/1]). -export([src_dir_opts/1, recursive/1]). -export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]). -export([profile_src_dir_opts/1]). @@ -16,7 +16,7 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs, - src_dirs, extra_src_dirs, all_src_dirs, src_dir_opts, recursive, + src_dirs, alt_src_dir_nested, extra_src_dirs, all_src_dirs, src_dir_opts, recursive, profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs, profile_src_dir_opts, retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir, @@ -74,6 +74,26 @@ src_dirs(Config) -> [".", "..", "../..", "bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)). +alt_src_dir_nested(Config) -> + RebarConfig = [{src_dirs, ["src", "alt/nested"]}], + AppsDir = ?config(apps, Config), + Name1 = ?config(app_one, Config), + Name2 = ?config(app_two, Config), + ModDir = filename:join([AppsDir, "apps", Name1, "alt", "nested"]), + ModDir2 = filename:join([AppsDir, "apps", Name2, "alt", "nested"]), + Mod = "-module(altmod). -export([main/0]). main() -> ok.", + + ec_file:mkdir_path(ModDir), + ec_file:mkdir_path(ModDir2), + ok = file:write_file(filename:join([ModDir, "altmod.erl"]), Mod), + + Ebin = filename:join([AppsDir, "_build", "default", "lib", Name1, "ebin", "altmod.beam"]), + {ok, State} = rebar_test_utils:run_and_check( + Config, RebarConfig, ["compile"], + {ok, [{file, Ebin}]} + ), + ["alt/nested", "src"] = rebar_dir:src_dirs(rebar_state:opts(State)). + src_dirs_with_opts(Config) -> RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}, {src_dirs, [{"foo",[{recursive,false}]}, "qux"]}]}], -- cgit v1.1 From 775261dd0b24d74e48f5873ef1ffff56c0c4829a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 27 Apr 2018 09:32:39 -0400 Subject: Prevent copying or symlink non-existing src_dirs This would cause crashes on linux and force people to have a src_dirs config that is strictly matching what is on the file system rather than acting as a specification of those that are valid. To compare, if lib_dirs worked the same, then any repo that did not both have apps/ and lib/ would crash, as the spec mentions both options as valid. --- test/rebar_dir_SUITE.erl | 3 --- 1 file changed, 3 deletions(-) (limited to 'test/rebar_dir_SUITE.erl') diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index f5ac0fc..81051e6 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -79,13 +79,10 @@ alt_src_dir_nested(Config) -> RebarConfig = [{src_dirs, ["src", "alt/nested"]}], AppsDir = ?config(apps, Config), Name1 = ?config(app_one, Config), - Name2 = ?config(app_two, Config), ModDir = filename:join([AppsDir, "apps", Name1, "alt", "nested"]), - ModDir2 = filename:join([AppsDir, "apps", Name2, "alt", "nested"]), Mod = "-module(altmod). -export([main/0]). main() -> ok.", ec_file:mkdir_path(ModDir), - ec_file:mkdir_path(ModDir2), ok = file:write_file(filename:join([ModDir, "altmod.erl"]), Mod), Ebin = filename:join([AppsDir, "_build", "default", "lib", Name1, "ebin", "altmod.beam"]), -- cgit v1.1