Sfoglia il codice sorgente

Allow passing arguments in r3:do and r3:async_do

async_do with arguments is useful for debugging a particular suite/test
with r3:break()

Example session:
Add r3:break() in recompile_when_hrl_changes test in test/rebar_compile_SUITE.erl

rebar3 shell
...
1> r3:async_do(default, ct, "--suite=test/rebar_compile_SUITE.erl --case=recompile_when_hrl_changes").
ok
Running Common Test suites...
%%% rebar_compile_SUITE:
=== BREAK ===

2> r3:resume().
ok
3> .
All 1 tests passed.
pull/2203/head
Manas Chaudhari 5 anni fa
parent
commit
38bfaaa1ee
3 ha cambiato i file con 26 aggiunte e 9 eliminazioni
  1. +1
    -0
      THANKS
  2. +13
    -5
      src/r3.erl
  3. +12
    -4
      src/rebar_agent.erl

+ 1
- 0
THANKS Vedi File

@ -144,3 +144,4 @@ Niklas Johansson
Bryan Paxton
Justin Wood
Guilherme Andrade
Manas Chaudhari

+ 13
- 5
src/r3.erl Vedi File

@ -1,26 +1,34 @@
%%% @doc external alias for `rebar_agent' for more convenient
%%% calls from a shell.
-module(r3).
-export([do/1, do/2, async_do/1, async_do/2, break/0, resume/0]).
-export([do/1, do/2, do/3, async_do/1, async_do/2, async_do/3, break/0, resume/0]).
-export(['$handle_undefined_function'/2]).
-include("rebar.hrl").
%% @doc alias for `rebar_agent:do/1'
-spec do(atom()) -> ok | {error, term()}.
-spec do(atom() | string()) -> ok | {error, term()}.
do(Command) -> rebar_agent:do(Command).
%% @doc alias for `rebar_agent:do/2'
-spec do(atom(), atom()) -> ok | {error, term()}.
-spec do(atom(), atom() | string()) -> ok | {error, term()}.
do(Namespace, Command) -> rebar_agent:do(Namespace, Command).
%% @doc alias for `rebar_agent:do/3'
-spec do(atom(), atom(), string()) -> ok | {error, term()}.
do(Namespace, Command, Args) -> rebar_agent:do(Namespace, Command, Args).
%% @doc alias for `rebar_agent:async_do/1'
-spec async_do(atom()) -> ok | {error, term()}.
-spec async_do(atom()) -> ok.
async_do(Command) -> rebar_agent:async_do(Command).
%% @doc alias for `rebar_agent:async_do/2'
-spec async_do(atom(), atom()) -> ok | {error, term()}.
-spec async_do(atom(), atom()) -> ok.
async_do(Namespace, Command) -> rebar_agent:async_do(Namespace, Command).
%% @doc alias for `rebar_agent:async_do/3'
-spec async_do(atom(), atom(), string()) -> ok.
async_do(Namespace, Command, Args) -> rebar_agent:async_do(Namespace, Command, Args).
break() ->
case whereis(rebar_agent) of % is the shell running
undefined ->

+ 12
- 4
src/rebar_agent.erl Vedi File

@ -1,7 +1,7 @@
%%% @doc Runs a process that holds a rebar3 state and can be used
%%% to statefully maintain loaded project state into a running VM.
-module(rebar_agent).
-export([start_link/1, do/1, do/2, async_do/1, async_do/2]).
-export([start_link/1, do/1, do/2, do/3, async_do/1, async_do/2, async_do/3]).
-export(['$handle_undefined_function'/2]).
-export([init/1,
handle_call/3, handle_cast/2, handle_info/2,
@ -21,7 +21,7 @@ start_link(State) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, State, []).
%% @doc runs a given command in the agent's context.
-spec do(atom()) -> ok | {error, term()}.
-spec do(atom() | string()) -> ok | {error, term()}.
do(Command) when is_atom(Command) ->
gen_server:call(?MODULE, {cmd, Command}, infinity);
do(Args) when is_list(Args) ->
@ -29,13 +29,17 @@ do(Args) when is_list(Args) ->
%% @doc runs a given command in the agent's context, under a given
%% namespace.
-spec do(atom(), atom()) -> ok | {error, term()}.
-spec do(atom(), atom() | string()) -> ok | {error, term()}.
do(Namespace, Command) when is_atom(Namespace), is_atom(Command) ->
gen_server:call(?MODULE, {cmd, Namespace, Command}, infinity);
do(Namespace, Args) when is_atom(Namespace), is_list(Args) ->
gen_server:call(?MODULE, {cmd, Namespace, do, Args}, infinity).
-spec async_do(atom()) -> ok | {error, term()}.
-spec do(atom(), atom(), string()) -> ok | {error, term()}.
do(Namespace, Command, Args) when is_atom(Namespace), is_atom(Command), is_list(Args) ->
gen_server:call(?MODULE, {cmd, Namespace, Command, Args}, infinity).
-spec async_do(atom()) -> ok.
async_do(Command) when is_atom(Command) ->
gen_server:cast(?MODULE, {cmd, Command});
async_do(Args) when is_list(Args) ->
@ -47,6 +51,10 @@ async_do(Namespace, Command) when is_atom(Namespace), is_atom(Command) ->
async_do(Namespace, Args) when is_atom(Namespace), is_list(Args) ->
gen_server:cast(?MODULE, {cmd, Namespace, do, Args}).
-spec async_do(atom(), atom(), string()) -> ok.
async_do(Namespace, Command, Args) when is_atom(Namespace), is_atom(Command), is_list(Args) ->
gen_server:cast(?MODULE, {cmd, Namespace, Command, Args}).
'$handle_undefined_function'(Cmd, [Namespace, Args]) ->
gen_server:call(?MODULE, {cmd, Namespace, Cmd, Args}, infinity);
'$handle_undefined_function'(Cmd, [Args]) ->

Caricamento…
Annulla
Salva