From 97f9b655f2de9074970ff6f614b143984f81fd8a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Wed, 7 Oct 2020 23:07:26 +0000 Subject: [PATCH 1/6] Advertise DEBUG=1 in `rebar3 help` Since we switched to DIAGNOSTIC=1 in the crashdump, the only way to make DEBUG=1 discoverable (outside of docs) is in the help provider. --- src/rebar_prv_help.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rebar_prv_help.erl b/src/rebar_prv_help.erl index f34c755d..961b21d1 100644 --- a/src/rebar_prv_help.erl +++ b/src/rebar_prv_help.erl @@ -55,14 +55,15 @@ format_error(Reason) -> %% print help/usage string %% help(State) -> - ?CONSOLE("Rebar3 is a tool for working with Erlang projects.~n~n", []), + ?CONSOLE("Rebar3 is a tool for working with Erlang projects.~n", []), OptSpecList = rebar3:global_option_spec_list(), getopt:usage(OptSpecList, "rebar3", "", []), - ?CONSOLE("~nSeveral tasks are available:~n", []), + ?CONSOLE(" Set the environment variable DEBUG=1 for detailed output.~n", []), + ?CONSOLE("Several tasks are available:~n", []), providers:help(rebar_state:providers(State)), - ?CONSOLE("~nRun 'rebar3 help ' for details.~n~n", []). + ?CONSOLE("~nRun 'rebar3 help ' for details.", []). task_help(Namespace, Name, State) -> Providers = rebar_state:providers(State), From 9096e827547c1d79968ed352f49fc934f9e8b7ac Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 9 Oct 2020 14:57:06 +0000 Subject: [PATCH 2/6] Adjust tests-related DEBUG output Mostly changing the format of debug messages, fixing one URL that was bad in a warning. --- src/rebar_prv_common_test.erl | 9 +++++---- src/rebar_prv_cover.erl | 1 + src/rebar_prv_eunit.erl | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index c27c1bfb..fd437b3f 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -90,7 +90,7 @@ run_tests(State, Opts) -> T = translate_paths(State, Opts), Opts1 = setup_logdir(State, T), Opts2 = turn_off_auto_compile(Opts1), - ?DEBUG("ct_opts ~p", [Opts2]), + ?DEBUG("Running tests with {ct_opts, ~p}.", [Opts2]), {RawOpts, _} = rebar_state:command_parsed_args(State), Result = case proplists:get_value(verbose, RawOpts, false) of true -> run_test_verbose(Opts2); @@ -145,7 +145,7 @@ symlink_to_last_ct_logs(State, Opts) -> %% and make a new updated one rebar_file_utils:rm_rf(Target), rebar_file_utils:symlink_or_copy(Existing, Target); - Reason -> ?DEBUG("Warning, couldn't make a symlink to ~ts, reason: ~p.", [Target, Reason]) + Reason -> ?DIAGNOSTIC("Warning, couldn't make a symlink to ~ts, reason: ~p.", [Target, Reason]) end end. @@ -235,7 +235,7 @@ cfgopts(State) -> ensure_opts([], Acc) -> lists:reverse(Acc); ensure_opts([{cover, _}|Rest], Acc) -> - ?WARN("Cover specs not supported. See http://www.rebar3.org/docs/running-tests#common-test", []), + ?WARN("Cover specs not supported. See https://www.rebar3.org/docs/testing/ct/", []), ensure_opts(Rest, Acc); ensure_opts([{auto_compile, _}|Rest], Acc) -> ?WARN("Auto compile not supported", []), @@ -389,6 +389,7 @@ compile(State, {ok, _} = Tests) -> compile(_State, Error) -> Error. do_compile(State) -> + ?DEBUG("Re-compiling the project under the test profile with CT options injected...", []), {ok, S} = rebar_prv_compile:do(State), ok = maybe_cover_compile(S), {ok, S}. @@ -704,7 +705,7 @@ handle_keep_logs(LogDir, N) -> SortedDirs = lists:reverse(lists:sort(Dirs)), %% sort the log dirs and keep the N - 1 newest {_Keep, Discard} = lists:split(N - 1, SortedDirs), - ?DEBUG("Removing the following directories because keep_logs option was found: ~p", [Discard]), + ?DEBUG("Removing the following directories because keep_logs is in ct_opts: ~p", [Discard]), [rebar_file_utils:rm_rf(filename:join([LogDir, Dir])) || Dir <- Discard], ok; %% we still dont have enough log run directories as to crash diff --git a/src/rebar_prv_cover.erl b/src/rebar_prv_cover.erl index 1acf4f82..611795d9 100644 --- a/src/rebar_prv_cover.erl +++ b/src/rebar_prv_cover.erl @@ -326,6 +326,7 @@ cover_compile(State, Dirs) -> %% redirect cover output true = redirect_cover_output(State, CoverPid), ExclMods = rebar_state:get(State, cover_excl_mods, []), + ?DEBUG("Ignoring cover compilation of modules in {cover_excl_mods, ~p}", [ExclMods]), lists:foreach(fun(Dir) -> case file:list_dir(Dir) of {ok, Files} -> diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index 47644392..399d88c6 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -81,8 +81,8 @@ do(State, Tests) -> run_tests(State, Tests) -> T = translate_paths(State, Tests), EUnitOpts = resolve_eunit_opts(State), - ?DEBUG("eunit_tests ~p", [T]), - ?DEBUG("eunit_opts ~p", [EUnitOpts]), + ?DEBUG("finding tests in:~n\t{eunit_tests, ~p}.", [T]), + ?DEBUG("with options:~n\t{eunit_opts, ~p}.", [EUnitOpts]), try eunit:test(T, EUnitOpts) of Result -> ok = maybe_write_coverdata(State), From 5d920096525f7f37bb82a128a89f04828b5a8844 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 9 Oct 2020 20:16:18 +0000 Subject: [PATCH 3/6] downgrade rebar_agent log severity --- src/rebar_agent.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rebar_agent.erl b/src/rebar_agent.erl index c4eccc9d..d89a643e 100644 --- a/src/rebar_agent.erl +++ b/src/rebar_agent.erl @@ -159,7 +159,7 @@ run(Namespace, Command, StrArgs, RState, Cwd) -> end catch ?WITH_STACKTRACE(Type, Reason, Stacktrace) - ?DEBUG("Agent Stacktrace: ~p", [Stacktrace]), + ?DIAGNOSTIC("Agent Stacktrace: ~p", [Stacktrace]), {{error, {Type, Reason}}, RState} end. @@ -215,7 +215,7 @@ refresh_path(Path, Blacklist) -> refresh_path_do(Path, App) -> Modules = mods_in_path(Path), - ?DEBUG("reloading ~p from ~ts", [Modules, Path]), + ?DIAGNOSTIC("reloading ~p from ~ts", [Modules, Path]), code:replace_path(App, Path), reload_modules(Modules). @@ -226,7 +226,7 @@ refresh_path_do(Path, App) -> %% run by no processes get unloaded by rebar_paths, without being loaded back in. refresh_path_blacklisted(Path) -> Modules = [M || M <- mods_in_path(Path), not is_loaded(M)], - ?DEBUG("ensure ~p loaded", [Modules]), + ?DIAGNOSTIC("ensure ~p loaded", [Modules]), code:add_pathz(Path), % in case the module is only in a new non-clashing path _ = [code:ensure_loaded(M) || M <- Modules], ok. @@ -326,7 +326,7 @@ reload_modules(Modules, true) -> reload_modules([ModError], false), [ModError|Acc]; _ -> - ?DEBUG("Module ~p failed to atomic load because ~p", [ModError, Error]), + ?DIAGNOSTIC("Module ~p failed to atomic load because ~p", [ModError, Error]), [ModError|Acc] end end, @@ -342,7 +342,7 @@ reload_modules(Modules, false) -> case code:load_file(M) of {module, M} -> ok; {error, Error} -> - ?DEBUG("Module ~p failed to load because ~p", [M, Error]) + ?DIAGNOSTIC("Module ~p failed to load because ~p", [M, Error]) end end, Modules ). From 504660ee6bdd46112cda58a29e8a2dbd69c8b343 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 9 Oct 2020 20:19:45 +0000 Subject: [PATCH 4/6] adjust compiler DEBUG verbosity --- src/rebar_compiler_dag.erl | 6 +++--- src/rebar_compiler_erl.erl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rebar_compiler_dag.erl b/src/rebar_compiler_dag.erl index ef01523a..6fcc3e1a 100644 --- a/src/rebar_compiler_dag.erl +++ b/src/rebar_compiler_dag.erl @@ -296,12 +296,12 @@ maybe_rm_artifact_and_edge(G, OutDir, SrcExt, Ext, Source) -> case Targets of [] -> Target = target(OutDir, Source, SrcExt, Ext), - ?DEBUG("Source ~ts is gone, deleting previous ~ts file if it exists ~ts", [Source, Ext, Target]), + ?DIAGNOSTIC("Source ~ts is gone, deleting previous ~ts file if it exists ~ts", [Source, Ext, Target]), file:delete(Target); [_|_] -> lists:foreach(fun(Target) -> - ?DEBUG("Source ~ts is gone, deleting artifact ~ts " - "if it exists", [Source, Target]), + ?DIAGNOSTIC("Source ~ts is gone, deleting artifact ~ts " + "if it exists", [Source, Target]), file:delete(Target) end, Targets) end, diff --git a/src/rebar_compiler_erl.erl b/src/rebar_compiler_erl.erl index 587b3541..5c00ab8a 100644 --- a/src/rebar_compiler_erl.erl +++ b/src/rebar_compiler_erl.erl @@ -110,7 +110,7 @@ dependencies(Source, _SourceDir, Dirs, DepOpts) -> behaviour := Behaviours} -> %% TODO: check for core transforms? {_MissIncl, _MissInclLib} =/= {[],[]} andalso - ?DEBUG("Missing: ~p", [{_MissIncl, _MissInclLib}]), + ?DIAGNOSTIC("Missing: ~p", [{_MissIncl, _MissInclLib}]), lists:filtermap( fun (Mod) -> rebar_compiler_epp:resolve_source(Mod, Dirs) end, OptPTrans ++ PTrans ++ Behaviours) ++ AbsIncls @@ -404,7 +404,7 @@ expand_file_names(Files, Dirs) -> Res = rebar_utils:find_files_in_dirs(Dirs, [$^, Incl, $$], true), case Res of [] -> - ?DEBUG("FILE ~p NOT FOUND", [Incl]), + ?DIAGNOSTIC("FILE ~p NOT FOUND", [Incl]), []; _ -> Res From 5a45fde441c3244e974a7be83ae37ba7c33ccb98 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 9 Oct 2020 21:58:28 +0000 Subject: [PATCH 5/6] more DIAGNOSTIC-level output --- src/rebar_fetch.erl | 2 +- src/rebar_parallel.erl | 2 +- src/rebar_paths.erl | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl index 3696b339..4590b10f 100644 --- a/src/rebar_fetch.erl +++ b/src/rebar_fetch.erl @@ -45,7 +45,7 @@ download_source(AppInfo, State) -> throw:{no_resource, Type, Location} -> throw(?PRV_ERROR({no_resource, Location, Type})); ?WITH_STACKTRACE(C,T,S) - ?DEBUG("rebar_fetch exception ~p ~p ~p", [C, T, S]), + ?DIAGNOSTIC("rebar_fetch exception ~p ~p ~p", [C, T, S]), throw(?PRV_ERROR({fetch_fail, rebar_app_info:source(AppInfo)})) end. diff --git a/src/rebar_parallel.erl b/src/rebar_parallel.erl index 8e48c9b7..e1b62161 100644 --- a/src/rebar_parallel.erl +++ b/src/rebar_parallel.erl @@ -14,7 +14,7 @@ queue(Tasks, WorkF, WArgs, Handler, HArgs) -> Parent = self(), Worker = fun() -> worker(Parent, WorkF, WArgs) end, Jobs = min(length(Tasks), erlang:system_info(schedulers)), - ?DEBUG("Starting ~B worker(s)", [Jobs]), + ?DIAGNOSTIC("Starting ~B worker(s)", [Jobs]), Pids = [spawn_monitor(Worker) || _ <- lists:seq(1, Jobs)], parallel_dispatch(Tasks, Pids, Handler, HArgs). diff --git a/src/rebar_paths.erl b/src/rebar_paths.erl index 6b8d6a30..7a494430 100644 --- a/src/rebar_paths.erl +++ b/src/rebar_paths.erl @@ -14,6 +14,7 @@ -spec set_paths(targets(), rebar_state:t()) -> ok. set_paths(UserTargets, State) -> Targets = normalize_targets(UserTargets), + ?DIAGNOSTIC("Setting paths to ~p", [Targets]), GroupPaths = path_groups(Targets, State), Paths = lists:append(lists:reverse([P || {_, P} <- GroupPaths])), code:add_pathsa(Paths), @@ -24,6 +25,7 @@ set_paths(UserTargets, State) -> -spec unset_paths(targets(), rebar_state:t()) -> ok. unset_paths(UserTargets, State) -> Targets = normalize_targets(UserTargets), + ?DIAGNOSTIC("Removing ~p paths", [Targets]), GroupPaths = path_groups(Targets, State), Paths = lists:append([P || {_, P} <- GroupPaths]), [code:del_path(P) || P <- Paths], @@ -240,4 +242,4 @@ get_runtime_apps([App|Rest0], AppsAcc0, AppsList) -> error -> {Rest, Acc} end end, {Rest0, sets:add_element(App, AppsAcc0)}, TotalApps), - get_runtime_apps(Rest1 ++ TotalApps, AppsAcc1, AppsList). \ No newline at end of file + get_runtime_apps(Rest1 ++ TotalApps, AppsAcc1, AppsList). From 6fb49e7837a0c1dc3c2de38cb543219661b4054a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 9 Oct 2020 22:21:09 +0000 Subject: [PATCH 6/6] discoverable edoc and escriptize --- src/rebar_prv_common_test.erl | 2 +- src/rebar_prv_edoc.erl | 1 + src/rebar_prv_escriptize.erl | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index fd437b3f..34ecfcd0 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -120,7 +120,7 @@ format_error({error_reading_testspec, Reason}) -> %% Internal functions %% =================================================================== -%% @doc Tries to make the symlink `_build//logs/last` to the `ct_run` directory +%% @doc Tries to make the symlink `_build//logs/last' to the `ct_run' directory %% of the last common test run. -spec symlink_to_last_ct_logs(rebar_state:t(), list()) -> ok. symlink_to_last_ct_logs(State, Opts) -> diff --git a/src/rebar_prv_edoc.erl b/src/rebar_prv_edoc.erl index 0c03f7bf..c7782d22 100644 --- a/src/rebar_prv_edoc.erl +++ b/src/rebar_prv_edoc.erl @@ -48,6 +48,7 @@ do(State) -> AppOpts = rebar_app_info:opts(AppInfo), %% order of the merge is important to allow app opts overrides AppEdocOpts = merge_opts(rebar_opts:get(AppOpts, edoc_opts, []), EdocOptsAcc), + ?DEBUG("{edoc_opts, ~p}.", [AppEdocOpts]), AppRes = (catch edoc:application(list_to_atom(AppName), AppDir, AppEdocOpts)), rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, AppInfo, State), case {AppRes, ShouldAccPaths} of diff --git a/src/rebar_prv_escriptize.erl b/src/rebar_prv_escriptize.erl index 9399a5bf..38976987 100644 --- a/src/rebar_prv_escriptize.erl +++ b/src/rebar_prv_escriptize.erl @@ -108,6 +108,7 @@ escriptize(State0, App) -> TopInclApps = lists:usort([ec_cnv:to_atom(AppName) | rebar_state:get(State, escript_incl_apps, [])]), AllApps = rebar_state:all_deps(State)++rebar_state:project_apps(State), InclApps = find_deps(TopInclApps, AllApps), + ?DEBUG("bundled applications:~n\t~p", [InclApps]), InclBeams = get_apps_beams(InclApps, AllApps), %% Look for a list of extra files to include in the output file. @@ -130,6 +131,8 @@ escriptize(State0, App) -> , {comment, def("%%", State, escript_comment, "%%\n")} , {emu_args, def("%%!", State, escript_emu_args, DefaultEmuArgs)} , {archive, Files, []} ], + ?DEBUG("escript options:", []), + [?DEBUG("\t{escript_~p, ~p}.", [K, V]) || {K, V} <- lists:droplast(EscriptSections)], case escript:create(Filename, EscriptSections) of ok -> ok; {error, EscriptError} -> @@ -249,7 +252,7 @@ find_deps(AppNames, AllApps) -> %% Should look at the app files to find direct dependencies find_deps_of_deps([], _, Acc) -> Acc; find_deps_of_deps([Name|Names], Apps, Acc) -> - ?DEBUG("processing ~p", [Name]), + ?DIAGNOSTIC("processing ~p", [Name]), {ok, App} = rebar_app_utils:find(Name, Apps), DepNames = proplists:get_value(applications, rebar_app_info:app_details(App), []), BinDepNames = [rebar_utils:to_binary(Dep) || Dep <- DepNames, @@ -258,7 +261,7 @@ find_deps_of_deps([Name|Names], Apps, Acc) -> DepDir =:= {error, bad_name} orelse % those are all local not lists:prefix(code:root_dir(), DepDir)] -- ([Name|Names]++Acc), % avoid already seen deps - ?DEBUG("new deps of ~p found to be ~p", [Name, BinDepNames]), + ?DIAGNOSTIC("new deps of ~p found to be ~p", [Name, BinDepNames]), find_deps_of_deps(BinDepNames ++ Names, Apps, BinDepNames ++ Acc). def(Rm, State, Key, Default) ->