Search code examples
erlangrebarerl

Pass args through rebar shell to erl?


I am using "rebar shell" to test my app. This is documented as:

Start a shell with project and deps preloaded similar to

'erl -pa ebin -pa deps/*/ebin'.

How do I add extra args to the underlying invocation of 'erl'? For example, I want to add application specific environment variables and run a Module/Function. I want to invoke something like:

 erl -pa ebin -pa deps/*/ebin -browser_spy browser_exe "/my/dir" -run bs_example test

(and I want code:priv_dir to work as it does when using rebar shell, which the above 'erl' command does not do).


Solution

  • You cannot

    rebar shell does not execute erl ... command actually, but only tries to replicate its behaviour.

    Actually rebar just turns yourself into the shell along with mimicking -pa by adding paths with code:add_pathz

    See here for implementation details:

    shell(_Config, _AppFile) ->
        true = code:add_pathz(rebar_utils:ebin_dir()),
        %% scan all processes for any with references to the old user and save them to
        %% update later
        NeedsUpdate = [Pid || Pid <- erlang:processes(),
            proplists:get_value(group_leader, erlang:process_info(Pid)) == whereis(user)
        ],
        %% terminate the current user
        ok = supervisor:terminate_child(kernel_sup, user),
        %% start a new shell (this also starts a new user under the correct group)
        _ = user_drv:start(),
        %% wait until user_drv and user have been registered (max 3 seconds)
        ok = wait_until_user_started(3000),
        %% set any process that had a reference to the old user's group leader to the
        %% new user process
        _ = [erlang:group_leader(whereis(user), Pid) || Pid <- NeedsUpdate],
        %% enable error_logger's tty output
        ok = error_logger:swap_handler(tty),
        %% disable the simple error_logger (which may have been added multiple
        %% times). removes at most the error_logger added by init and the
        %% error_logger added by the tty handler
        ok = remove_error_handler(3),
        %% this call never returns (until user quits shell)
        timer:sleep(infinity).