@@ -28,20 +28,49 @@ defmodule Expert.EngineNode do
2828 @ dialyzer { :nowarn_function , start: 3 }
2929
3030 def start ( % __MODULE__ { } = state , paths , from ) do
31- this_node = inspect ( Node . self ( ) )
32-
33- args = [
34- "--name" ,
35- Project . node_name ( state . project ) ,
36- "--cookie" ,
37- state . cookie ,
38- "--no-halt" ,
39- "-e" ,
40- "Node.connect(#{ this_node } )"
41- | path_append_arguments ( paths )
42- ]
43-
44- case Expert.Port . open_elixir ( state . project , args: args ) do
31+ epmd_module = to_charlist ( Forge.EPMD )
32+
33+ case :init . get_argument ( :epmd_module ) do
34+ { :ok , [ [ ^ epmd_module ] ] } ->
35+ :ok
36+
37+ _ ->
38+ Application . put_env ( :kernel , :epmd_module , Forge.EPMD , persistent: true )
39+
40+ # Note: this is a private API
41+ if :net_kernel . epmd_module ( ) != Forge.EPMD do
42+ raise ( """
43+ you must set the environment variable ELIXIR_ERL_OPTIONS="-epmd_module #{ Forge.EPMD } "
44+ """ )
45+ end
46+ end
47+
48+ this_node = to_string ( Node . self ( ) )
49+ dist_port = Forge.EPMD . dist_port ( )
50+
51+ args =
52+ [
53+ "--erl" ,
54+ "-start_epmd false -epmd_module #{ Forge.EPMD } " ,
55+ "--cookie" ,
56+ state . cookie ,
57+ "--no-halt" ,
58+ "-e" ,
59+ """
60+ {:ok, _} = Node.start(:"#{ Project . node_name ( state . project ) } ", :longnames)
61+ #{ Forge.NodePortMapper } .register()
62+ IO.puts(\" ok\" )
63+ """
64+ | path_append_arguments ( paths )
65+ ]
66+
67+ env =
68+ [
69+ { "EXPERT_PARENT_NODE" , this_node } ,
70+ { "EXPERT_PARENT_PORT" , to_string ( dist_port ) }
71+ ]
72+
73+ case Expert.Port . open_elixir ( state . project , args: args , env: env ) do
4574 { :error , :no_elixir , message } ->
4675 GenLSP . error ( Expert . get_lsp ( ) , message )
4776 Expert . terminate ( "Failed to find an elixir executable, shutting down" , 1 )
@@ -64,7 +93,7 @@ defmodule Expert.EngineNode do
6493 end
6594
6695 def on_nodeup ( % __MODULE__ { } = state , node_name ) do
67- if node_name == Project . node_name ( state . project ) do
96+ if String . starts_with? ( to_string ( node_name ) , to_string ( Project . node_name ( state . project ) ) ) do
6897 { pid , _ref } = state . started_by
6998 Process . monitor ( pid )
7099 GenServer . reply ( state . started_by , :ok )
@@ -117,7 +146,6 @@ defmodule Expert.EngineNode do
117146 use GenServer
118147
119148 def start ( project ) do
120- :ok = ensure_epmd_started ( )
121149 start_net_kernel ( project )
122150
123151 node_name = Project . node_name ( project )
@@ -134,23 +162,13 @@ defmodule Expert.EngineNode do
134162
135163 defp start_net_kernel ( % Project { } = project ) do
136164 manager = Project . manager_node_name ( project )
137- :net_kernel . start ( manager , % { name_domain: : longnames} )
165+ Node . start ( manager , : longnames)
138166 end
139167
140168 defp ensure_apps_started ( node ) do
141169 :rpc . call ( node , Engine , :ensure_apps_started , [ ] )
142170 end
143171
144- defp ensure_epmd_started do
145- case System . cmd ( "epmd" , ~w( -daemon) ) do
146- { "" , 0 } ->
147- :ok
148-
149- _ ->
150- { :error , :epmd_failed }
151- end
152- end
153-
154172 if Mix . env ( ) == :test do
155173 # In test environment, Expert depends on the Engine app, so we look for it
156174 # in the expert build path.
@@ -294,7 +312,7 @@ defmodule Expert.EngineNode do
294312
295313 @ impl true
296314 def handle_call ( { :start , paths } , from , % State { } = state ) do
297- :ok = :net_kernel . monitor_nodes ( true , node_type: :visible )
315+ :ok = :net_kernel . monitor_nodes ( true , node_type: :all )
298316 Process . send_after ( self ( ) , :maybe_start_timeout , @ start_timeout )
299317
300318 case State . start ( state , paths , from ) do
@@ -365,7 +383,8 @@ defmodule Expert.EngineNode do
365383 end
366384
367385 @ impl true
368- def handle_info ( { _port , { :data , _message } } , % State { } = state ) do
386+ def handle_info ( { _port , { :data , message } } , % State { } = state ) do
387+ Logger . debug ( "Node port message: #{ to_string ( message ) } " )
369388 { :noreply , state }
370389 end
371390
0 commit comments