diff options
-rw-r--r-- | priv/templates/app.erl | 4 | ||||
-rw-r--r-- | priv/templates/escript_mod.erl | 2 | ||||
-rw-r--r-- | priv/templates/escript_rebar.config | 6 | ||||
-rw-r--r-- | priv/templates/gitignore | 6 | ||||
-rw-r--r-- | priv/templates/mod.erl | 2 | ||||
-rw-r--r-- | priv/templates/otp_app.app.src | 4 | ||||
-rw-r--r-- | priv/templates/otp_lib.app.src | 2 | ||||
-rw-r--r-- | priv/templates/plugin.erl | 4 | ||||
-rw-r--r-- | priv/templates/provider.erl | 4 | ||||
-rw-r--r-- | priv/templates/relx_rebar.config | 4 | ||||
-rw-r--r-- | priv/templates/sup.erl | 2 | ||||
-rw-r--r-- | priv/templates/sys.config | 2 | ||||
-rw-r--r-- | src/rebar3.erl | 2 | ||||
-rw-r--r-- | src/rebar_app_utils.erl | 4 | ||||
-rw-r--r-- | src/rebar_file_utils.erl | 16 | ||||
-rw-r--r-- | src/rebar_git_resource.erl | 4 | ||||
-rw-r--r-- | src/rebar_plugins.erl | 12 | ||||
-rw-r--r-- | src/rebar_prv_app_discovery.erl | 3 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 19 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 5 | ||||
-rw-r--r-- | src/rebar_templater.erl | 25 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 40 | ||||
-rw-r--r-- | test/rebar_eunit_SUITE.erl | 9 | ||||
-rw-r--r-- | test/rebar_file_utils_SUITE.erl | 21 | ||||
-rw-r--r-- | test/rebar_plugins_SUITE.erl | 36 |
25 files changed, 179 insertions, 59 deletions
diff --git a/priv/templates/app.erl b/priv/templates/app.erl index 2e7b909..83eb9a3 100644 --- a/priv/templates/app.erl +++ b/priv/templates/app.erl @@ -3,7 +3,7 @@ %% @end %%%------------------------------------------------------------------- --module('{{name}}_app'). +-module({{name}}_app). -behaviour(application). @@ -16,7 +16,7 @@ %%==================================================================== start(_StartType, _StartArgs) -> - '{{name}}_sup':start_link(). + {{name}}_sup:start_link(). %%-------------------------------------------------------------------- stop(_State) -> diff --git a/priv/templates/escript_mod.erl b/priv/templates/escript_mod.erl index dd2feb8..f8a779b 100644 --- a/priv/templates/escript_mod.erl +++ b/priv/templates/escript_mod.erl @@ -1,4 +1,4 @@ --module('{{name}}'). +-module({{name}}). %% API exports -export([main/1]). diff --git a/priv/templates/escript_rebar.config b/priv/templates/escript_rebar.config index c0a3301..196f835 100644 --- a/priv/templates/escript_rebar.config +++ b/priv/templates/escript_rebar.config @@ -2,9 +2,9 @@ {deps, []}. {escript_incl_apps, - ['{{name}}']}. -{escript_top_level_app, '{{name}}'}. -{escript_name, '{{name}}'}. + [{{name}}]}. +{escript_top_level_app, {{name}}}. +{escript_name, {{name}}}. {escript_emu_args, "%%! +sbtu +A0\n"}. %% Profiles diff --git a/priv/templates/gitignore b/priv/templates/gitignore index a939dce..ced0c5e 100644 --- a/priv/templates/gitignore +++ b/priv/templates/gitignore @@ -11,9 +11,5 @@ ebin log erl_crash.dump .rebar -_rel -_deps -_plugins -_tdeps logs -_build
\ No newline at end of file +_build diff --git a/priv/templates/mod.erl b/priv/templates/mod.erl index 208307e..2f5e09e 100644 --- a/priv/templates/mod.erl +++ b/priv/templates/mod.erl @@ -1,4 +1,4 @@ --module('{{name}}'). +-module({{name}}). %% API exports -export([]). diff --git a/priv/templates/otp_app.app.src b/priv/templates/otp_app.app.src index 783a130..243cef5 100644 --- a/priv/templates/otp_app.app.src +++ b/priv/templates/otp_app.app.src @@ -1,8 +1,8 @@ -{application, '{{name}}', +{application, {{name}}, [{description, "{{desc}}"}, {vsn, "0.1.0"}, {registered, []}, - {mod, {'{{name}}_app', []}}, + {mod, {{{name}}_app, []}}, {applications, [kernel, stdlib diff --git a/priv/templates/otp_lib.app.src b/priv/templates/otp_lib.app.src index 6e76b4b..5b98a51 100644 --- a/priv/templates/otp_lib.app.src +++ b/priv/templates/otp_lib.app.src @@ -1,4 +1,4 @@ -{application, '{{name}}', +{application, {{name}}, [{description, "{{desc}}"}, {vsn, "0.1.0"}, {registered, []}, diff --git a/priv/templates/plugin.erl b/priv/templates/plugin.erl index c6e5e40..218960d 100644 --- a/priv/templates/plugin.erl +++ b/priv/templates/plugin.erl @@ -1,8 +1,8 @@ --module('{{name}}'). +-module({{name}}). -export([init/1]). -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> - {ok, State1} = '{{name}}_prv':init(State), + {ok, State1} = {{name}}_prv:init(State), {ok, State1}. diff --git a/priv/templates/provider.erl b/priv/templates/provider.erl index 669df83..7639d97 100644 --- a/priv/templates/provider.erl +++ b/priv/templates/provider.erl @@ -1,8 +1,8 @@ --module('{{name}}_prv'). +-module({{name}}_prv). -export([init/1, do/1, format_error/1]). --define(PROVIDER, '{{name}}'). +-define(PROVIDER, {{name}}). -define(DEPS, [app_discovery]). %% =================================================================== diff --git a/priv/templates/relx_rebar.config b/priv/templates/relx_rebar.config index da32819..eab99ac 100644 --- a/priv/templates/relx_rebar.config +++ b/priv/templates/relx_rebar.config @@ -1,8 +1,8 @@ {erl_opts, [debug_info]}. {deps, []}. -{relx, [{release, {'{{name}}', "0.1.0"}, - ['{{name}}', +{relx, [{release, {{{name}}, "0.1.0"}, + [{{name}}, sasl]}, {sys_config, "./config/sys.config"}, diff --git a/priv/templates/sup.erl b/priv/templates/sup.erl index cd9192a..a2e7209 100644 --- a/priv/templates/sup.erl +++ b/priv/templates/sup.erl @@ -3,7 +3,7 @@ %% @end %%%------------------------------------------------------------------- --module('{{name}}_sup'). +-module({{name}}_sup). -behaviour(supervisor). diff --git a/priv/templates/sys.config b/priv/templates/sys.config index 7fd6bcb..b587675 100644 --- a/priv/templates/sys.config +++ b/priv/templates/sys.config @@ -1,3 +1,3 @@ [ - {'{{name}}', []} + {{{name}}, []} ]. diff --git a/src/rebar3.erl b/src/rebar3.erl index 9106bb8..84d7c3e 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -123,7 +123,7 @@ run_aux(State, RawArgs) -> {ok, Providers} = application:get_env(rebar, providers), %% Providers can modify profiles stored in opts, so set default after initializing providers State5 = rebar_state:create_logic_providers(Providers, State4), - State6 = rebar_plugins:project_apps_install(State5), + State6 = rebar_plugins:top_level_install(State5), State7 = rebar_state:default(State6, rebar_state:opts(State6)), {Task, Args} = parse_args(RawArgs), diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index ae1ea1c..d3ef841 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -166,7 +166,9 @@ dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State) -> Overrides = rebar_state:get(State, overrides, []), AppInfo2 = rebar_app_info:set(AppInfo1, overrides, rebar_app_info:get(AppInfo, overrides, [])++Overrides), AppInfo3 = rebar_app_info:apply_overrides(rebar_app_info:get(AppInfo2, overrides, []), AppInfo2), - rebar_app_info:is_lock(AppInfo3, IsLock). + AppInfo4 = rebar_app_info:apply_profiles(AppInfo3, [default, prod]), + AppInfo5 = rebar_app_info:profiles(AppInfo4, [default]), + rebar_app_info:is_lock(AppInfo5, IsLock). update_source(AppInfo, {pkg, PkgName, PkgVsn}, State) -> {PkgName1, PkgVsn1} = case PkgVsn of diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 8c57d19..0f84520 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -262,9 +262,11 @@ path_from_ancestor_(_, _) -> {error, badparent}. %% reduce a filepath by removing all incidences of `.' and `..' -spec canonical_path(string()) -> string(). -canonical_path(Dir) -> canonical_path([], filename:split(filename:absname(Dir))). +canonical_path(Dir) -> + Canon = canonical_path([], filename:split(filename:absname(Dir))), + filename:nativename(Canon). -canonical_path([], []) -> filename:nativename("/"); +canonical_path([], []) -> filename:absname("/"); canonical_path(Acc, []) -> filename:join(lists:reverse(Acc)); canonical_path(Acc, ["."|Rest]) -> canonical_path(Acc, Rest); canonical_path([_|Acc], [".."|Rest]) -> canonical_path(Acc, Rest); @@ -283,13 +285,19 @@ delete_each_dir_win32([Dir | Rest]) -> delete_each_dir_win32(Rest). xcopy_win32(Source,Dest)-> - %% "xcopy \"~s\" \"~s\" /q /y /e 2> nul", Chanegd to robocopy to + %% "xcopy \"~s\" \"~s\" /q /y /e 2> nul", Changed to robocopy to %% handle long names. May have issues with older windows. Cmd = case filelib:is_dir(Source) of true -> + %% For robocopy, copying /a/b/c/ to /d/e/f/ recursively does not + %% create /d/e/f/c/*, but rather copies all files to /d/e/f/*. + %% The usage we make here expects the former, not the later, so we + %% must manually add the last fragment of a directory to the `Dest` + %% in order to properly replicate POSIX platforms + NewDest = filename:join([Dest, filename:basename(Source)]), ?FMT("robocopy \"~s\" \"~s\" /e /is 1> nul", [rebar_utils:escape_double_quotes(filename:nativename(Source)), - rebar_utils:escape_double_quotes(filename:nativename(Dest))]); + rebar_utils:escape_double_quotes(filename:nativename(NewDest))]); false -> ?FMT("robocopy \"~s\" \"~s\" \"~s\" /e /is 1> nul", [rebar_utils:escape_double_quotes(filename:nativename(filename:dirname(Source))), diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index bea74a2..876d047 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -45,7 +45,7 @@ needs_update(Dir, {git, Url, {branch, Branch}}) -> not ((Current =:= []) andalso compare_url(Dir, Url)); needs_update(Dir, {git, Url, "master"}) -> needs_update(Dir, {git, Url, {branch, "master"}}); -needs_update(Dir, {git, Url, Ref}) -> +needs_update(Dir, {git, _, Ref}) -> {ok, Current} = rebar_utils:sh(?FMT("git rev-parse -q HEAD", []), [{cd, Dir}]), Current1 = string:strip(string:strip(Current, both, $\n), both, $\r), @@ -64,7 +64,7 @@ needs_update(Dir, {git, Url, Ref}) -> end, ?DEBUG("Comparing git ref ~s with ~s", [Ref1, Current1]), - not ((Current1 =:= Ref2) andalso compare_url(Dir, Url)). + (Current1 =/= Ref2). compare_url(Dir, Url) -> {ok, CurrentUrl} = rebar_utils:sh(?FMT("git config --get remote.origin.url", []), diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index f2d3977..b4cc3ec 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -3,7 +3,8 @@ -module(rebar_plugins). --export([project_apps_install/1 +-export([top_level_install/1 + ,project_apps_install/1 ,install/2 ,handle_plugins/3 ,handle_plugins/4]). @@ -14,11 +15,18 @@ %% Public API %% =================================================================== +-spec top_level_install(rebar_state:t()) -> rebar_state:t(). +top_level_install(State) -> + Profiles = rebar_state:current_profiles(State), + lists:foldl(fun(Profile, StateAcc) -> + Plugins = rebar_state:get(State, {plugins, Profile}, []), + handle_plugins(Profile, Plugins, StateAcc) + end, State, Profiles). + -spec project_apps_install(rebar_state:t()) -> rebar_state:t(). project_apps_install(State) -> Profiles = rebar_state:current_profiles(State), ProjectApps = rebar_state:project_apps(State), - lists:foldl(fun(Profile, StateAcc) -> Plugins = rebar_state:get(State, {plugins, Profile}, []), StateAcc1 = handle_plugins(Profile, Plugins, StateAcc), diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl index 5449f82..1954214 100644 --- a/src/rebar_prv_app_discovery.erl +++ b/src/rebar_prv_app_discovery.erl @@ -36,7 +36,8 @@ do(State) -> LibDirs = rebar_dir:lib_dirs(State), try State1 = rebar_app_discover:do(State, LibDirs), - {ok, State1} + State2 = rebar_plugins:project_apps_install(State1), + {ok, State2} catch throw:{error, {rebar_packages, Error}} -> {error, {rebar_packages, Error}}; diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index d57b82b..30af90b 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -247,6 +247,21 @@ resolve_src_dirs(Opts) -> %% in src_dirs also exist in extra_src_dirs normalize_src_dirs(SrcDirs, ExtraDirs) -> S = lists:usort(SrcDirs), - E = lists:usort(ExtraDirs), - {S, lists:subtract(E, S)}. + E = lists:subtract(lists:usort(ExtraDirs), S), + ok = warn_on_problematic_directories(S ++ E), + {S, E}. + +%% warn when directories called `eunit' and `ct' are added to compile dirs +warn_on_problematic_directories(AllDirs) -> + F = fun(Dir) -> + case is_a_problem(Dir) of + true -> ?WARN("Possible name clash with directory ~p.", [Dir]); + false -> ok + end + end, + lists:foreach(F, AllDirs). + +is_a_problem("eunit") -> true; +is_a_problem("common_test") -> true; +is_a_problem(_) -> false. diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 118d799..a484c5f 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -251,13 +251,12 @@ update_unseen_dep(AppInfo, Profile, Level, Deps, Apps, State, Upgrade, Seen, Loc -spec handle_dep(rebar_state:t(), atom(), file:filename_all(), rebar_app_info:t(), list(), integer()) -> {rebar_app_info:t(), [rebar_app_info:t()], rebar_state:t()}. handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) -> - Profiles = rebar_state:current_profiles(State), Name = rebar_app_info:name(AppInfo), C = rebar_config:consult(rebar_app_info:dir(AppInfo)), AppInfo0 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C), AppInfo1 = rebar_app_info:apply_overrides(rebar_app_info:get(AppInfo, overrides, []), AppInfo0), - AppInfo2 = rebar_app_info:apply_profiles(AppInfo1, Profiles), + AppInfo2 = rebar_app_info:apply_profiles(AppInfo1, [default, prod]), Plugins = rebar_app_info:get(AppInfo2, plugins, []), AppInfo3 = rebar_app_info:set(AppInfo2, {plugins, Profile}, Plugins), @@ -269,7 +268,7 @@ handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) -> State1 = rebar_plugins:install(State, AppInfo3), %% Upgrade lock level to be the level the dep will have in this dep tree - Deps = rebar_app_info:get(AppInfo3, {deps, default}, []), + Deps = rebar_app_info:get(AppInfo3, {deps, default}, []) ++ rebar_app_info:get(AppInfo3, {deps, prod}, []), AppInfo4 = rebar_app_info:deps(AppInfo3, rebar_state:deps_names(Deps)), %% Keep all overrides from the global config and this dep when parsing its deps diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index f687637..2f33bfc 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -159,9 +159,34 @@ drop_var_docs([{K,V}|Rest]) -> [{K,V} | drop_var_docs(Rest)]. create({Template, Type, File}, Files, UserVars, Force, State) -> TemplateTerms = consult(load_file(Files, Type, File)), Vars = drop_var_docs(override_vars(UserVars, get_template_vars(TemplateTerms, State))), + maybe_warn_about_name(Vars), TemplateCwd = filename:dirname(File), execute_template(TemplateTerms, Files, {Template, Type, TemplateCwd}, Vars, Force). +maybe_warn_about_name(Vars) -> + Name = proplists:get_value(name, Vars, "valid"), + case validate_atom(Name) of + invalid -> + ?WARN("The 'name' variable is often associated with Erlang " + "module names and/or file names. The value submitted " + "(~s) isn't an unquoted Erlang atom. Templates " + "generated may contain errors.", + [Name]); + valid -> + ok + end. + +validate_atom(Str) -> + case io_lib:fread("~a", unicode:characters_to_list(Str)) of + {ok, [Atom], ""} -> + case io_lib:write_atom(Atom) of + "'" ++ _ -> invalid; % quoted + _ -> valid % unquoted + end; + _ -> + invalid + end. + %% Run template instructions one at a time. execute_template([], _, {Template,_,_}, _, _) -> ?DEBUG("Template ~s applied", [Template]), diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index ef9cf97..cbf59ef 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -37,7 +37,8 @@ only_default_transitive_deps/1, clean_all/1, override_deps/1, - profile_override_deps/1]). + profile_override_deps/1, + deps_build_in_prod/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -58,7 +59,7 @@ all() -> deps_in_path, checkout_priority, highest_version_of_pkg_dep, parse_transform_test, erl_first_files_test, mib_test, umbrella_mib_first_test, only_default_transitive_deps, - clean_all, override_deps, profile_override_deps]. + clean_all, override_deps, profile_override_deps, deps_build_in_prod]. groups() -> [{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]}, @@ -89,7 +90,7 @@ init_per_group(basic_app, Config) -> Name = rebar_test_utils:create_random_name("app1"), Vsn = rebar_test_utils:create_random_vsn(), rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), - + [{app_names, [Name]}, {vsns, [Vsn]}|NewConfig]; init_per_group(release_apps, Config) -> @@ -103,7 +104,7 @@ init_per_group(release_apps, Config) -> Name2 = rebar_test_utils:create_random_name("relapp2_"), Vsn2 = rebar_test_utils:create_random_vsn(), rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]), - + [{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig]; init_per_group(checkout_apps, Config) -> @@ -415,7 +416,7 @@ paths_basic_app(Config) -> [Vsn] = ?config(vsns, Config), {ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return), - + code:add_paths(rebar_state:code_paths(State, all_deps)), ok = application:load(list_to_atom(Name)), Loaded = application:loaded_applications(), @@ -1173,3 +1174,32 @@ profile_override_deps(Config) -> {ok, [{dep, "some_dep"},{dep_not_exist, "other_dep"}]} ). +%% verify a deps prod profile is used +%% tested by checking prod hooks run and outputs to default profile dir for dep +%% and prod deps are installed for dep +deps_build_in_prod(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + GitDeps = rebar_test_utils:expand_deps(git, [{"asdf", "1.0.0", []}]), + PkgName = rebar_test_utils:create_random_name("pkg1_"), + {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps), + mock_git_resource:mock([{deps, SrcDeps}, + {config, [{profiles, [{prod, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]}, + {deps, [list_to_atom(PkgName)]}]}]}]}]), + + mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]), + + Deps = rebar_test_utils:top_level_deps(GitDeps), + RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName}, + {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]} + ). diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl index 1b11c5a..896c624 100644 --- a/test/rebar_eunit_SUITE.erl +++ b/test/rebar_eunit_SUITE.erl @@ -42,13 +42,10 @@ groups() -> init_per_suite(Config) -> PrivDir = ?config(priv_dir, Config), DataDir = ?config(data_dir, Config), - {ok, Cwd} = file:get_cwd(), - file:set_cwd(PrivDir), ok = ec_file:copy(filename:join([DataDir, "basic_app.zip"]), filename:join([PrivDir, "basic_app.zip"])), - {ok, _} = zip:extract(filename:join([PrivDir, "basic_app.zip"])), + {ok, _} = zip:extract(filename:join([PrivDir, "basic_app.zip"]), [{cwd, PrivDir}]), ok = ec_file:copy(filename:join([DataDir, "multi_app.zip"]), filename:join([PrivDir, "multi_app.zip"])), - {ok, _} = zip:extract(filename:join([PrivDir, "multi_app.zip"])), - file:set_cwd(Cwd), + {ok, _} = zip:extract(filename:join([PrivDir, "multi_app.zip"]), [{cwd, PrivDir}]), Config. init_per_group(basic_app, Config) -> @@ -546,4 +543,4 @@ misspecified_eunit_first_files(Config) -> {error, {rebar_prv_eunit, Error}} = rebar_test_utils:run_and_check(State, RebarConfig, ["eunit"], return), - {badconfig, {"Value `~p' of option `~p' must be a list", {some_file, eunit_first_files}}} = Error.
\ No newline at end of file + {badconfig, {"Value `~p' of option `~p' must be a list", {some_file, eunit_first_files}}} = Error. diff --git a/test/rebar_file_utils_SUITE.erl b/test/rebar_file_utils_SUITE.erl index a061325..c1f85b3 100644 --- a/test/rebar_file_utils_SUITE.erl +++ b/test/rebar_file_utils_SUITE.erl @@ -97,10 +97,17 @@ path_from_ancestor(_Config) -> ?assertEqual({error, badparent}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/foo/bar/baz/qux")). canonical_path(_Config) -> - ?assertEqual(filename:nativename("/"), rebar_file_utils:canonical_path("/")), - ?assertEqual(filename:nativename("/"), rebar_file_utils:canonical_path("/../../..")), - ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/bar/..")), - ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/../foo")), - ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/.")), - ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/./.")), - ?assertEqual("/foo/bar", rebar_file_utils:canonical_path("/foo/./bar")).
\ No newline at end of file + %% We find the root so that the name works both on unix-likes and + %% with Windows. + Root = case os:type() of + {win32, _} -> filename:nativename(filename:absname("/")); % C:\, with proper drive + _ -> "/" + end, + ?assertEqual(filename:nativename(Root), rebar_file_utils:canonical_path("/")), + ?assertEqual(filename:nativename(Root), rebar_file_utils:canonical_path("/../../..")), + ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/bar/..")), + ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/../foo")), + ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/.")), + ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/./.")), + ?assertEqual(filename:nativename(Root ++ "foo/bar"), + rebar_file_utils:canonical_path("/foo/./bar")). diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl index 3df3c0e..cce6126 100644 --- a/test/rebar_plugins_SUITE.erl +++ b/test/rebar_plugins_SUITE.erl @@ -10,7 +10,8 @@ compile_global_plugins/1, complex_plugins/1, list/1, - upgrade/1]). + upgrade/1, + sub_app_plugins/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -32,7 +33,7 @@ end_per_testcase(_, _Config) -> catch meck:unload(). all() -> - [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade]. + [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins]. %% Tests that compiling a project installs and compiles the plugins of deps compile_plugins(Config) -> @@ -208,3 +209,34 @@ upgrade(Config) -> Config, RConf, ["plugins", "upgrade", PkgName], {ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]} ). + +sub_app_plugins(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("sub_app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + + DepName = rebar_test_utils:create_random_name("dep1_"), + PluginName = rebar_test_utils:create_random_name("plugin1_"), + + mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}, + {{list_to_binary(PluginName), list_to_binary(Vsn)}, []}]}]), + + SubAppsDir = filename:join([AppDir, "apps", Name]), + + rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:create_config(SubAppsDir, [{deps, [{list_to_binary(DepName), list_to_binary(Vsn)}]}, + {plugins, [list_to_atom(PluginName)]}]), + + RConfFile = + rebar_test_utils:create_config(AppDir, + [{deps, [ + list_to_atom(DepName) + ]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {dep, DepName}, {plugin, PluginName}]} + ). |