diff options
-rw-r--r-- | priv/shell-completion/bash/rebar3 | 38 | ||||
-rw-r--r-- | src/rebar3.erl | 3 | ||||
-rw-r--r-- | src/rebar_pkg_resource.erl | 2 | ||||
-rw-r--r-- | src/rebar_plugins.erl | 18 | ||||
-rw-r--r-- | src/rebar_prv_common_test.erl | 25 | ||||
-rw-r--r-- | src/rebar_prv_dialyzer.erl | 23 | ||||
-rw-r--r-- | src/rebar_prv_update.erl | 2 | ||||
-rw-r--r-- | src/rebar_utils.erl | 7 | ||||
-rw-r--r-- | test/rebar_ct_SUITE.erl | 11 | ||||
-rw-r--r-- | test/rebar_plugins_SUITE.erl | 45 |
10 files changed, 137 insertions, 37 deletions
diff --git a/priv/shell-completion/bash/rebar3 b/priv/shell-completion/bash/rebar3 index 771297c..3cd3cd7 100644 --- a/priv/shell-completion/bash/rebar3 +++ b/priv/shell-completion/bash/rebar3 @@ -10,7 +10,8 @@ _rebar3() if [[ ${prev} == rebar3 ]] ; then sopts="-h -v" lopts="--help --version" - cmdsnvars="as \ + cmdsnvars=" \ + as \ clean \ compile \ cover \ @@ -37,7 +38,8 @@ _rebar3() update \ upgrade \ version \ - xref" + xref \ + " elif [[ ${prev} == as ]] ; then : elif [[ ${prev} == clean ]] ; then @@ -50,7 +52,8 @@ _rebar3() lopts="--reset --verbose" elif [[ ${prev} == ct ]] ; then sopts="-c -v" - lopts="--dir \ + lopts=" \ + --dir \ --suite \ --group \ --case \ @@ -74,8 +77,9 @@ _rebar3() --multiply_timetraps \ --scale_timetraps \ --create_priv_dir \ - --verbose" \ - --auto_compile + --verbose \ + --auto_compile \ + " elif [[ ${prev} == deps ]] ; then : elif [[ ${prev} == dialyzer ]] ; then @@ -97,7 +101,8 @@ _rebar3() lopts="--force" elif [[ ${prev} == path ]] ; then sopts="-s" - lopts="--app \ + lopts=" \ + --app \ --base \ --bin \ --ebin \ @@ -105,14 +110,16 @@ _rebar3() --priv \ --separator \ --src \ - --rel" + --rel \ + " elif [[ ${prev} == pkgs ]] ; then : elif [[ ${prev} == plugins ]] ; then : elif [[ ${prev} == release ]] ; then sopts="-n -v -g -u -o -h -l -p -V -d -i -a -c -r" - lopts="--relname \ + lopts=" \ + --relname \ --relvsn \ --goal \ --upfrom \ @@ -131,10 +138,12 @@ _rebar3() --sys_config \ --system_libs \ --version \ - --root" + --root \ + " elif [[ ${prev} == relup ]] ; then sopts="-n -v -g -u -o -h -l -p -V -d -i -a -c -r" - lopts="--relname \ + lopts=" \ + --relname \ --relvsn \ --goal \ --upfrom \ @@ -153,14 +162,16 @@ _rebar3() --sys_config \ --system_libs \ --version \ - --root" + --root \ + " elif [[ ${prev} == report ]] ; then : elif [[ ${prev} == shell ]] ; then : elif [[ ${prev} == tar ]] ; then sopts="-n -v -g -u -o -h -l -p -V -d -i -a -c -r" - lopts="--relname \ + lopts=" \ + --relname \ --relvsn \ --goal \ --upfrom \ @@ -179,7 +190,8 @@ _rebar3() --sys_config \ --system_libs \ --version \ - --root" + --root \ + " elif [[ ${prev} == tree ]] ; then sopts="-v" lopts="--verbose" diff --git a/src/rebar3.erl b/src/rebar3.erl index 84d7c3e..879378e 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -105,6 +105,9 @@ run_aux(State, RawArgs) -> rebar_state:apply_profiles(State, [list_to_atom(Profile)]) end, + rebar_utils:check_min_otp_version(rebar_state:get(State1, minimum_otp_vsn, undefined)), + rebar_utils:check_blacklisted_otp_versions(rebar_state:get(State1, blacklisted_otp_vsns, undefined)), + State2 = case os:getenv("HEX_CDN") of false -> State1; diff --git a/src/rebar_pkg_resource.erl b/src/rebar_pkg_resource.erl index 33687e4..ec7e09d 100644 --- a/src/rebar_pkg_resource.erl +++ b/src/rebar_pkg_resource.erl @@ -104,7 +104,7 @@ make_vsn(_) -> {error, "Replacing version of type pkg not supported."}. request(Url, ETag) -> - case httpc:request(get, {Url, [{"if-none-match", ETag} || ETag =/= false]}, + case httpc:request(get, {Url, [{"if-none-match", ETag} || ETag =/= false]++[{"User-Agent", rebar_utils:user_agent()}]}, [{ssl, ssl_opts(Url)}, {relaxed, true}], [{body_format, binary}], rebar) of diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index b4cc3ec..3c33498 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -42,10 +42,20 @@ project_apps_install(State) -> -spec install(rebar_state:t(), rebar_app_info:t()) -> rebar_state:t(). install(State, AppInfo) -> Profiles = rebar_state:current_profiles(State), - lists:foldl(fun(Profile, StateAcc) -> - Plugins = rebar_app_info:get(AppInfo, {plugins, Profile}, []), - handle_plugins(Profile, Plugins, StateAcc) - end, State, Profiles). + + %% don't lose the overrides of the dep we are processing plugins for + Overrides = rebar_app_info:get(AppInfo, overrides, []), + StateOverrides = rebar_state:get(State, overrides, []), + AllOverrides = Overrides ++ StateOverrides, + State1 = rebar_state:set(State, overrides, AllOverrides), + + State2 = lists:foldl(fun(Profile, StateAcc) -> + Plugins = rebar_app_info:get(AppInfo, {plugins, Profile}, []), + handle_plugins(Profile, Plugins, StateAcc) + end, State1, Profiles), + + %% Reset the overrides after processing the dep + rebar_state:set(State2, overrides, StateOverrides). handle_plugins(Profile, Plugins, State) -> handle_plugins(Profile, Plugins, State, false). diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 1136e08..4be50d8 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -281,7 +281,8 @@ inject_ct_state(State, [App|Rest], Acc) -> inject_ct_state(State, [], Acc) -> case inject(rebar_state:opts(State), State) of {error, _} = Error -> Error; - NewOpts -> {ok, {rebar_state:opts(State, NewOpts), lists:reverse(Acc)}} + NewOpts -> + {ok, {rebar_state:opts(State, NewOpts), lists:reverse(Acc)}} end. opts(Opts, Key, Default) -> @@ -380,12 +381,10 @@ maybe_inject_test_dir(State, AppAcc, [App|Rest], Dir) -> %% suite exists in but if the suite is in the app root directory %% the current compiler tries to compile all subdirs including priv %% instead copy only files ending in `.erl' and directories - %% ending in `_SUITE_data' into the `_build/PROFILE/extras' dir - {ok, RelAppDir} = rebar_file_utils:path_from_ancestor(rebar_app_info:dir(App), rebar_state:dir(State)), - ExtrasDir = filename:join([rebar_dir:base_dir(State), "extras", RelAppDir]), - ok = copy_bare_suites(Dir, ExtrasDir), - Opts = inject_test_dir(rebar_state:opts(State), ExtrasDir), - {rebar_state:opts(State, Opts), AppAcc}; + %% ending in `_SUITE_data' into the `_build/PROFILE/lib/APP' dir + ok = copy_bare_suites(Dir, rebar_app_info:out_dir(App)), + Opts = inject_test_dir(rebar_state:opts(State), rebar_app_info:out_dir(App)), + {rebar_state:opts(State, Opts), AppAcc ++ [App]}; {ok, Path} -> Opts = inject_test_dir(rebar_app_info:opts(App), Path), {State, AppAcc ++ [rebar_app_info:opts(App, Opts)] ++ Rest}; @@ -449,15 +448,23 @@ translate_suites(_State, [], Acc) -> lists:reverse(Acc); translate_suites(State, [{suite, Suite}|Rest], Acc) when is_integer(hd(Suite)) -> %% single suite Apps = rebar_state:project_apps(State), - translate_suites(State, Rest, [{suite, translate(State, Apps, Suite)}|Acc]); + translate_suites(State, Rest, [{suite, translate_suite(State, Apps, Suite)}|Acc]); translate_suites(State, [{suite, Suites}|Rest], Acc) -> %% multiple suites Apps = rebar_state:project_apps(State), - NewSuites = {suite, lists:map(fun(Suite) -> translate(State, Apps, Suite) end, Suites)}, + NewSuites = {suite, lists:map(fun(Suite) -> translate_suite(State, Apps, Suite) end, Suites)}, translate_suites(State, Rest, [NewSuites|Acc]); translate_suites(State, [Test|Rest], Acc) -> translate_suites(State, Rest, [Test|Acc]). +translate_suite(State, Apps, Suite) -> + Dirname = filename:dirname(Suite), + Basename = filename:basename(Suite), + case Dirname of + "." -> Suite; + _ -> filename:join([translate(State, Apps, Dirname), Basename]) + end. + translate(State, [App|Rest], Path) -> case rebar_file_utils:path_from_ancestor(Path, rebar_app_info:dir(App)) of {ok, P} -> filename:join([rebar_app_info:out_dir(App), P]); diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index 2e5728a..834eb98 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -397,7 +397,7 @@ run_dialyzer(State, Opts, Output) -> case proplists:get_bool(get_warnings, Opts) of true -> WarningsList = get_config(State, warnings, []), - Opts2 = [{warnings, WarningsList}, + Opts2 = [{warnings, legacy_warnings(WarningsList)}, {check_plt, false} | Opts], ?DEBUG("Running dialyzer with options: ~p~n", [Opts2]), @@ -412,6 +412,14 @@ run_dialyzer(State, Opts, Output) -> {0, State} end. +legacy_warnings(Warnings) -> + case dialyzer_version() of + TupleVsn when TupleVsn < {2, 8, 0} -> + [Warning || Warning <- Warnings, Warning =/= unknown]; + _ -> + Warnings + end. + format_warnings(Output, Warnings) -> Warnings1 = rebar_dialyzer_format:format_warnings(Warnings), console_warnings(Warnings1), @@ -475,3 +483,16 @@ collect_nested_dependent_apps(App, Seen) -> end end end. + +dialyzer_version() -> + _ = application:load(dialyzer), + {ok, Vsn} = application:get_key(dialyzer, vsn), + case string:tokens(Vsn, ".") of + [Major, Minor] -> + version_tuple(Major, Minor, "0"); + [Major, Minor, Patch | _] -> + version_tuple(Major, Minor, Patch) + end. + +version_tuple(Major, Minor, Patch) -> + {list_to_integer(Major), list_to_integer(Minor), list_to_integer(Patch)}. diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 1cdf6af..0e3b9a0 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -48,7 +48,7 @@ do(State) -> case rebar_utils:url_append_path(CDN, ?REMOTE_REGISTRY_FILE) of {ok, Url} -> ?DEBUG("Fetching registry from ~p", [Url]), - case httpc:request(get, {Url, []}, + case httpc:request(get, {Url, [{"User-Agent", rebar_utils:user_agent()}]}, [], [{stream, TmpFile}, {sync, true}], rebar) of {ok, saved_to_file} -> diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 07bf789..56a3940 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -68,7 +68,8 @@ check_min_otp_version/1, check_blacklisted_otp_versions/1, info_useless/2, - list_dir/1]). + list_dir/1, + user_agent/0]). %% for internal use only -export([otp_release/0]). @@ -407,6 +408,10 @@ abort_if_blacklisted(BlacklistedRegex, OtpRelease) -> [OtpRelease, BlacklistedRegex]) end. +user_agent() -> + {ok, Vsn} = application:get_key(rebar, vsn), + ?FMT("Rebar/~s (OTP/~s)", [Vsn, otp_release()]). + %% ==================================================================== %% Internal functions %% ==================================================================== diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl index 183a1d0..94ab690 100644 --- a/test/rebar_ct_SUITE.erl +++ b/test/rebar_ct_SUITE.erl @@ -681,25 +681,26 @@ suite_at_app_root(Config) -> Opts = rebar_prv_common_test:translate_paths(NewState, T), Suite = proplists:get_value(suite, Opts), - Expected = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE"]), + Expected = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE"]), [Expected] = Suite, - TestHrl = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.hrl"]), + TestHrl = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE.hrl"]), true = filelib:is_file(TestHrl), - TestBeam = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.beam"]), + TestBeam = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE.beam"]), true = filelib:is_file(TestBeam), - DataDir = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE_data"]), + DataDir = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE_data"]), true = filelib:is_dir(DataDir), - DataFile = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data", "some_data.txt"]), + DataFile = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE_data", "some_data.txt"]), true = filelib:is_file(DataFile). %% this test probably only fails when this suite is run via rebar3 with the --cover flag data_dir_correct(Config) -> DataDir = ?config(data_dir, Config), Parts = filename:split(DataDir), + ct:pal(Parts), ["rebar_ct_SUITE_data","test","rebar","lib","test","_build"|_] = lists:reverse(Parts). cmd_label(Config) -> diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl index cce6126..c1a98de 100644 --- a/test/rebar_plugins_SUITE.erl +++ b/test/rebar_plugins_SUITE.erl @@ -11,7 +11,8 @@ complex_plugins/1, list/1, upgrade/1, - sub_app_plugins/1]). + sub_app_plugins/1, + sub_app_plugin_overrides/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -33,7 +34,7 @@ end_per_testcase(_, _Config) -> catch meck:unload(). all() -> - [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins]. + [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins, sub_app_plugin_overrides]. %% Tests that compiling a project installs and compiles the plugins of deps compile_plugins(Config) -> @@ -240,3 +241,43 @@ sub_app_plugins(Config) -> Config, RConf, ["compile"], {ok, [{app, Name}, {dep, DepName}, {plugin, PluginName}]} ). + +%% Tests that overrides in a dep that includes a plugin are applied to plugin fetching +sub_app_plugin_overrides(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("sub_app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + Dep2Name = rebar_test_utils:create_random_name("dep2_"), + + DepName = rebar_test_utils:create_random_name("dep1_"), + PluginName = rebar_test_utils:create_random_name("plugin1_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + + Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, [{DepName, Vsn, []}]}, + {DepName, Vsn, []}]), + {SrcDeps, _} = rebar_test_utils:flat_deps(Deps), + mock_git_resource:mock([{deps, SrcDeps}]), + + mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(Dep2Name), list_to_binary(Vsn)}, []}]}, + {config, [{plugins, [{list_to_atom(PluginName), + {git, "http://site.com/user/"++PluginName++".git", + {tag, Vsn}}}]}, + %% Dep2 overrides the plugin's deps to have vsn2 of dep1 + {overrides, [{override, list_to_atom(PluginName), + [{deps, [{list_to_atom(DepName), + {git, "http://site.com/user/"++DepName++".git", + {tag, Vsn2}}}]}]}]}]}]), + + SubAppsDir = filename:join([AppDir, "apps", Name]), + + rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]), + + RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [{list_to_binary(Dep2Name), list_to_binary(Vsn)}]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {dep, Dep2Name, Vsn}, {plugin, DepName, Vsn2}, {plugin, PluginName}]} + ). |