barrel-db / rebar3_elixir_compile

Elixir rebar3 compiler plugin
Other
90 stars 29 forks source link

Specifying vm.args (with hostname) makes "rebar3 shell" crash #27

Open vasu-dasari opened 6 years ago

vasu-dasari commented 6 years ago

I have been playing with the example "demo" code from the repo. I wanted to add a sname to the demo Erlang VM. So, created a file called, config/vm.args in the demo directory which looks like:

-sname demo

And issued the following commands from the demo directory:

docker run --rm -v ${HOME}:${HOME} -w `pwd` -it elixir bash # Elixir (1.6) docker environment

And in docker from demo directory:

mix local.rebar --force
mix local.hex --force

rebar3 compile
ERL_FLAGS=" -args_file config/vm.args" rebar3 shell

I see the following error:

root@b40fb051a6c7:demo# ERL_FLAGS=" -args_file config/vm.args" rebar3 shell
===> Failed creating providers. Run with DEBUG=1 for stacktrace or consult rebar3.crashdump.

On turning DEBUG=1, I see the following message:

===> sh info:
    cwd: "/Users/vdasari/Developer/demo"
    cmd: elixir -e "IO.puts :code.lib_dir(:elixir)"

===>    opts: []

===> Port Cmd: elixir -e "IO.puts :code.lib_dir(:elixir)"
Port Opts: [exit_status,{line,16384},use_stdio,stderr_to_stdout,hide,eof]

===> sh(elixir -e "IO.puts :code.lib_dir(:elixir)")
failed with return code 1 and the following output:
Protocol 'inet_tcp': the name demo@b40fb051a6c7 seems to be in use by another Erlang node

===> throw: rebar_abort [{rebar_utils,debug_and_abort,2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_utils.erl"},
                                  {line,605}]},
                                {rebar_utils,sh,2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_utils.erl"},
                                  {line,197}]},
                                {rebar3_elixir_compile_util,get_details,1,
                                 [{file,
                                   "/Users/vdasari/Developer/demo/_build/default/plugins/rebar3_elixir_compile/src/rebar3_elixir_compile_util.erl"},
                                  {line,66}]},
                                {rebar3_elixir_compile,init,1,
                                 [{file,
                                   "/Users/vdasari/Developer/demo/_build/default/plugins/rebar3_elixir_compile/src/rebar3_elixir_compile.erl"},
                                  {line,8}]},
                                {rebar_state,
                                 '-create_logic_providers/2-fun-0-',2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_state.erl"},
                                  {line,409}]},
                                {lists,foldl,3,
                                 [{file,"lists.erl"},{line,1263}]},
                                {rebar_state,create_logic_providers,2,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_state.erl"},
                                  {line,408}]},
                                {rebar_plugins,'-handle_plugins/4-fun-0-',4,
                                 [{file,
                                   "/usr/src/rebar3-src/_build/default/lib/rebar/src/rebar_plugins.erl"},
                                  {line,84}]}]
===> Failed creating providers. Run with DEBUG=1 for stacktrace or consult rebar3.crashdump.

I generally use this command ERL_FLAGS=" -args_file config/vm.args" rebar3 shell to run rebar3 shell for normal Erlang-Rebar projects. I expected to see this working for Elixir imported projects as well. May I know what do I need to do to make this command work.

vasu-dasari commented 6 years ago

Just found that I had to give full path name of where vm.args file is located, that fixed the problem of locating the vm.args file. But, for consistency it will be a good idea to fix this. Now, I see this error:

===> sh(elixir -e "IO.puts :code.lib_dir(:elixir)")
failed with return code 1 and the following output:
Protocol 'inet_tcp': the name demo@b40fb051a6c7 seems to be in use by another Erlang node

This is a fresh docker instance, and no other instances of demo are running. So, this error message looks suspicious. Can you help me fix this error?

vasu-dasari commented 6 years ago

Ok. I see the reason why it is failing. Will have a PR shortly. Now I start application with:

ERL_FLAGS=" -args_file ${PWD}config/vm.args" rebar3 shell and my vm.args file contains, -snmae demo.

rebar3 shell tries to issue compile directive to provider(plugins) to see if the source code has to be re-compiled. rebar3 would have set ERL_FLAGS to "ERL_FLAGS= -args_file .../demo/config/vm.args" already before calling this. And also, it would have started the VM already with vm.args. Lets call this parent VM, and will have sname as specified in vm.args.

In rebar3_elixir_compile_util, a dependency elixir file is compiled with following command: /usr/local/bin/mix deps.get.

Now, this would spawn another VM with previously set ERL_FLAGS. And this new VM could not be spawned because the node name is already in use(becuase of parent VM created by rebar3 shell).

So, the fix would be to create wrapper for rebar_utils:sh() in rebar3_elixir_compile_util as:

sh(Command, Options) ->
    rebar_utils:sh(Command, [{env, [{"ERL_FLAGS", ""}]} | Options]).

I will shortly create pull request for this.

benoitc commented 6 years ago

him interesting I wonder if except the node name resolution something else can be problematic. Imo we should be able to pass includes -I and path -pa args at least so everything would be included. Thoughts?