Browse Source

Rework debug/diagnostic logs for compile tasks

This should cover most cases, including hooks.
What this specifically does is change some less useful messages for more
contextualized ones, including tying specific configurations to actions
taking place. This is particularly visible in hooks, and hopefully
provides some amount of discoverability.

Also of note:
- ebin/ directory copying is called explicitly when done since people
  have issues with that
- paths for compiled files are made relative since the analysis list
  shows the full paths already
- hooks are a bit more verbose but also more useful.
pull/2375/head
Fred Hebert 4 years ago
parent
commit
26064098fd
5 changed files with 38 additions and 21 deletions
  1. +5
    -5
      src/rebar_compiler.erl
  2. +1
    -1
      src/rebar_compiler_epp.erl
  3. +2
    -2
      src/rebar_compiler_erl.erl
  4. +29
    -13
      src/rebar_hooks.erl
  5. +1
    -0
      src/rebar_prv_compile.erl

+ 5
- 5
src/rebar_compiler.erl View File

@ -321,21 +321,21 @@ compile_worker(Source, [Opts, Config, Outs, CompilerMod]) ->
{Result, Source}. {Result, Source}.
compile_handler({ok, Source}, _Args) -> compile_handler({ok, Source}, _Args) ->
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), Source]),
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), filename:basename(Source)]),
ok; ok;
compile_handler({{ok, Tracked}, Source}, [_, Tracking]) when Tracking -> compile_handler({{ok, Tracked}, Source}, [_, Tracking]) when Tracking ->
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), Source]),
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), filename:basename(Source)]),
{ok, Tracked}; {ok, Tracked};
compile_handler({{ok, Warnings}, Source}, _Args) -> compile_handler({{ok, Warnings}, Source}, _Args) ->
report(Warnings), report(Warnings),
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), Source]),
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), filename:basename(Source)]),
ok; ok;
compile_handler({{ok, Tracked, Warnings}, Source}, [_, Tracking]) when Tracking -> compile_handler({{ok, Tracked, Warnings}, Source}, [_, Tracking]) when Tracking ->
report(Warnings), report(Warnings),
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), Source]),
?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), filename:basename(Source)]),
{ok, Tracked}; {ok, Tracked};
compile_handler({skipped, Source}, _Args) -> compile_handler({skipped, Source}, _Args) ->
?DEBUG("~sSkipped ~s", [rebar_utils:indent(1), Source]),
?DEBUG("~sSkipped ~s", [rebar_utils:indent(1), filename:basename(Source)]),
ok; ok;
compile_handler({Error, Source}, [Config | _Rest]) -> compile_handler({Error, Source}, [Config | _Rest]) ->
NewSource = format_error_source(Source, Config), NewSource = format_error_source(Source, Config),

+ 1
- 1
src/rebar_compiler_epp.erl View File

@ -145,7 +145,7 @@ list_directory(Dir, Cache) ->
{Cache, []}, DirFiles), {Cache, []}, DirFiles),
{NewFs#{Dir => Files}, Files}; {NewFs#{Dir => Files}, Files};
{error, Reason} -> {error, Reason} ->
?DEBUG("Failed to list ~s, ~p", [Dir, Reason]),
?DIAGNOSTIC("Failed to list ~s, ~p", [Dir, Reason]),
{Cache, []} {Cache, []}
end end
end. end.

+ 2
- 2
src/rebar_compiler_erl.erl View File

@ -48,8 +48,8 @@ needed_files(Graph, FoundFiles, _, AppInfo) ->
EbinDir = rebar_app_info:ebin_dir(AppInfo), EbinDir = rebar_app_info:ebin_dir(AppInfo),
RebarOpts = rebar_app_info:opts(AppInfo), RebarOpts = rebar_app_info:opts(AppInfo),
ErlOpts = rebar_opts:erl_opts(RebarOpts), ErlOpts = rebar_opts:erl_opts(RebarOpts),
?DEBUG("erlopts ~p", [ErlOpts]),
?DEBUG("files to compile ~p", [FoundFiles]),
?DEBUG("compile options: {erl_opts, ~p}.", [ErlOpts]),
?DEBUG("files to analyze ~p", [FoundFiles]),
%% Make sure that the ebin dir is on the path %% Make sure that the ebin dir is on the path
ok = rebar_file_utils:ensure_dir(EbinDir), ok = rebar_file_utils:ensure_dir(EbinDir),

+ 29
- 13
src/rebar_hooks.erl View File

@ -12,20 +12,34 @@
atom() | {atom(), atom()} | string(), atom() | {atom(), atom()} | string(),
[providers:t()], rebar_app_info:t(), rebar_state:t()) -> rebar_app_info:t(). [providers:t()], rebar_app_info:t(), rebar_state:t()) -> rebar_app_info:t().
run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) -> run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) ->
?DEBUG("Running hooks for ~p in app ~ts (~ts) with configuration:",
[Command, rebar_app_info:name(AppInfo), Dir]),
State1 = rebar_state:current_app(State, AppInfo), State1 = rebar_state:current_app(State, AppInfo),
State2 = run_provider_hooks(Dir, Type, Command, Providers, rebar_app_info:opts(AppInfo), State1), State2 = run_provider_hooks(Dir, Type, Command, Providers, rebar_app_info:opts(AppInfo), State1),
run_hooks(Dir, Type, Command, rebar_app_info:opts(AppInfo), State1), run_hooks(Dir, Type, Command, rebar_app_info:opts(AppInfo), State1),
rebar_state:current_app(State2). rebar_state:current_app(State2).
run_all_hooks(Dir, Type, Command, Providers, State) -> run_all_hooks(Dir, Type, Command, Providers, State) ->
?DEBUG("Running hooks for ~p with configuration:", [Command]),
run_provider_hooks(Dir, Type, Command, Providers, rebar_state:opts(State), State), run_provider_hooks(Dir, Type, Command, Providers, rebar_state:opts(State), State),
run_hooks(Dir, Type, Command, rebar_state:opts(State), State). run_hooks(Dir, Type, Command, rebar_state:opts(State), State).
run_project_and_app_hooks(Dir, Type, Command, Providers, State) -> run_project_and_app_hooks(Dir, Type, Command, Providers, State) ->
ProjectApps = rebar_state:project_apps(State), ProjectApps = rebar_state:project_apps(State),
?DEBUG("Running app-specific hooks", []),
[rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) || AppInfo <- ProjectApps], [rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) || AppInfo <- ProjectApps],
?DEBUG("Running project-wide hooks", []),
run_all_hooks(Dir, Type, Command, Providers, State). run_all_hooks(Dir, Type, Command, Providers, State).
format_error({bad_provider, Type, Command, {Name, Namespace}}) ->
io_lib:format("Unable to run ~ts hooks for '~p', command '~p' in namespace '~p' not found.", [Type, Command, Namespace, Name]);
format_error({bad_provider, Type, Command, Name}) ->
io_lib:format("Unable to run ~ts hooks for '~p', command '~p' not found.", [Type, Command, Name]).
%%%%%%%%%%%%%%%
%%% PRIVATE %%%
%%%%%%%%%%%%%%%
run_provider_hooks(Dir, Type, Command, Providers, Opts, State) -> run_provider_hooks(Dir, Type, Command, Providers, Opts, State) ->
case rebar_opts:get(Opts, provider_hooks, []) of case rebar_opts:get(Opts, provider_hooks, []) of
[] -> [] ->
@ -40,11 +54,14 @@ run_provider_hooks_(_Dir, _Type, _Command, _Providers, [], State) ->
run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) -> run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) ->
case proplists:get_all_values(Command, TypeHooks) of case proplists:get_all_values(Command, TypeHooks) of
[] -> [] ->
?DEBUG("\t{provider_hooks, []}.", []),
State; State;
HookProviders -> HookProviders ->
rebar_paths:set_paths([plugins], State), rebar_paths:set_paths([plugins], State),
Providers1 = rebar_state:providers(State), Providers1 = rebar_state:providers(State),
State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers++Providers1), State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers++Providers1),
?DEBUG("\t{provider_hooks, [{~p, ~p}]}.",
[Type, HookProviders]),
case rebar_core:do(HookProviders, State1) of case rebar_core:do(HookProviders, State1) of
{error, ProviderName} -> {error, ProviderName} ->
?DEBUG(format_error({bad_provider, Type, Command, ProviderName}), []), ?DEBUG(format_error({bad_provider, Type, Command, ProviderName}), []),
@ -55,11 +72,6 @@ run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) ->
end end
end. end.
format_error({bad_provider, Type, Command, {Name, Namespace}}) ->
io_lib:format("Unable to run ~ts hooks for '~p', command '~p' in namespace '~p' not found.", [Type, Command, Namespace, Name]);
format_error({bad_provider, Type, Command, Name}) ->
io_lib:format("Unable to run ~ts hooks for '~p', command '~p' not found.", [Type, Command, Name]).
run_hooks(Dir, pre, Command, Opts, State) -> run_hooks(Dir, pre, Command, Opts, State) ->
run_hooks(Dir, pre_hooks, Command, Opts, State); run_hooks(Dir, pre_hooks, Command, Opts, State);
run_hooks(Dir, post, Command, Opts, State) -> run_hooks(Dir, post, Command, Opts, State) ->
@ -67,17 +79,21 @@ run_hooks(Dir, post, Command, Opts, State) ->
run_hooks(Dir, Type, Command, Opts, State) -> run_hooks(Dir, Type, Command, Opts, State) ->
case rebar_opts:get(Opts, Type, []) of case rebar_opts:get(Opts, Type, []) of
[] -> [] ->
?DEBUG("run_hooks(~p, ~p, ~p) -> no hooks defined\n", [Dir, Type, Command]),
?DEBUG("\t{~p, []}.", [Type]),
?DIAGNOSTIC("run_hooks(~p, ~p, ~p) -> no hooks defined\n", [Dir, Type, Command]),
ok; ok;
Hooks -> Hooks ->
Env = rebar_env:create_env(State, Opts), Env = rebar_env:create_env(State, Opts),
lists:foreach(fun({_, C, _}=Hook) when C =:= Command ->
apply_hook(Dir, Env, Hook);
({C, _}=Hook) when C =:= Command ->
apply_hook(Dir, Env, Hook);
(_) ->
continue
end, Hooks)
CommandHooks = lists:filter(
fun({_, C, _}) when C =:= Command -> true;
({C, _}) when C =:= Command -> true;
(_) -> false
end,
Hooks
),
?DEBUG("\t{~p, ~p}.",
[Type, CommandHooks]),
lists:foreach(fun(Hook) -> apply_hook(Dir, Env, Hook) end, CommandHooks)
end. end.
apply_hook(Dir, Env, {Arch, Command, Hook}) -> apply_hook(Dir, Env, {Arch, Command, Hook}) ->

+ 1
- 0
src/rebar_prv_compile.erl View File

@ -378,6 +378,7 @@ copy_app_dirs(AppInfo, OldAppDir, AppDir) ->
true -> true ->
OutEbin = filename:join([AppDir, "ebin"]), OutEbin = filename:join([AppDir, "ebin"]),
filelib:ensure_dir(filename:join([OutEbin, "dummy.beam"])), filelib:ensure_dir(filename:join([OutEbin, "dummy.beam"])),
?DEBUG("Copying existing files from ~ts to ~ts", [EbinDir, OutEbin]),
rebar_file_utils:cp_r(filelib:wildcard(filename:join([EbinDir, "*"])), OutEbin); rebar_file_utils:cp_r(filelib:wildcard(filename:join([EbinDir, "*"])), OutEbin);
false -> false ->
ok ok

Loading…
Cancel
Save