Bladeren bron

Fix issues on `symlink_to_last_ct_logs/1`

Now it should work in Erlang/OTP versions earlier than 20 and
update the symlink in case of one already existing (so that `last`
always points to the last run).
pull/2248/head
Pablo Costas 5 jaren geleden
bovenliggende
commit
b4e0393fd6
1 gewijzigde bestanden met toevoegingen van 17 en 15 verwijderingen
  1. +17
    -15
      src/rebar_prv_common_test.erl

+ 17
- 15
src/rebar_prv_common_test.erl Bestand weergeven

@ -74,7 +74,7 @@ do(State, Tests) ->
%% Run ct provider post hooks for all project apps and top level project hooks
rebar_hooks:run_project_and_app_hooks(Cwd, post, ?PROVIDER, Providers, State),
rebar_paths:set_paths([plugins, deps], State),
symlink_to_last_ct_logs(),
symlink_to_last_ct_logs(State),
{ok, State};
Error ->
rebar_paths:set_paths([plugins, deps], State),
@ -119,24 +119,26 @@ format_error({error_reading_testspec, Reason}) ->
%% Internal functions
%% ===================================================================
%% @doc Tries to make the symlink `_build_test_logs/last` to the `ct_run` directory
%% @doc Tries to make the symlink `_build/<profile>/logs/last` to the `ct_run` directory
%% of the last common test run.
-spec symlink_to_last_ct_logs() -> ok.
symlink_to_last_ct_logs() ->
LogsFolder = "_build/test/logs/",
{ok, Filenames} = file:list_dir(LogsFolder),
CtRunFolders = lists:filter(fun(S) -> string:find(S, "ct_run") /= nomatch end, Filenames),
NewestFolder = lists:last(lists:sort(CtRunFolders)),
Target = filename:join(LogsFolder, "last"),
Existing = filename:join(LogsFolder, NewestFolder),
-spec symlink_to_last_ct_logs(rebar_state:t()) -> ok.
symlink_to_last_ct_logs(State) ->
LogDir = filename:join([rebar_dir:base_dir(State), "logs"]),
{ok, Filenames} = file:list_dir(LogDir),
CtRunDirs = lists:filter(fun(S) -> re:run(S, "ct_run", [unicode]) /= nomatch end, Filenames),
NewestDir = lists:last(lists:sort(CtRunDirs)),
Target = filename:join([LogDir, "last"]),
Existing = filename:join([LogDir, NewestDir]),
case rebar_file_utils:symlink_or_copy(Existing, Target) of
ok ->
ok;
_ ->
?DEBUG("Warning, couldn't make a symlink to ~ts.", [Target])
ok -> ok;
exists ->
%% in case the symlink already exists we remove it
%% 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])
end.
setup_name(State) ->
{Long, Short, Opts} = rebar_dist_utils:find_options(State),
rebar_dist_utils:either(Long, Short, Opts).

Laden…
Annuleren
Opslaan