@@ -10,7 +10,7 @@ defmodule Mix.Tasks.Deps.Partition do
10
10
@ deps_partition_install_mix_exs ~c" deps.partition.mix.exs"
11
11
12
12
def server ( deps , count , force? ) do
13
- { :ok , socket } = :gen_tcp . listen ( 0 , [ :binary , packet: :line , active: true , reuseaddr: true ] )
13
+ { :ok , socket } = :gen_tcp . listen ( 0 , [ :binary , packet: :line , active: false ] )
14
14
15
15
try do
16
16
server ( socket , deps , count , force? )
@@ -71,28 +71,37 @@ defmodule Mix.Tasks.Deps.Partition do
71
71
:use_stdio ,
72
72
:stderr_to_stdout ,
73
73
line: 1_000_000 ,
74
- args: args ,
75
74
env: [ { ~c" MIX_OS_CONCURRENCY_LOCK" , ~c" false" } | env_vars ]
76
75
]
77
76
78
- clients =
79
- Enum . map ( 1 .. count // 1 , fn index ->
77
+ ports =
78
+ Map . new ( 1 .. count // 1 , fn index ->
80
79
if Mix . debug? ( ) do
81
80
IO . puts ( "-> Starting mix deps.partition ##{ index } " )
82
81
end
83
82
84
- port = Port . open ( { :spawn_executable , String . to_charlist ( elixir ) } , options )
83
+ args = args ++ [ ~c" --index" , Integer . to_charlist ( index ) ]
84
+ port = Port . open ( { :spawn_executable , String . to_charlist ( elixir ) } , [ args: args ] ++ options )
85
85
86
- case :gen_tcp . accept ( socket , 15000 ) do
87
- { :ok , client } ->
88
- % { port: port , index: index , socket: client }
86
+ { index , port }
87
+ end )
89
88
89
+ clients =
90
+ Enum . map ( 1 .. count // 1 , fn _ ->
91
+ with { :ok , client } <- :gen_tcp . accept ( socket , 15000 ) ,
92
+ { :ok , message } <- :gen_tcp . recv ( socket , 0 , 15000 ) do
93
+ :inet . setopts ( client , active: true )
94
+ index = message |> String . trim ( ) |> String . to_integer ( )
95
+ % { port: Map . fetch! ( ports , index ) , index: index , socket: client }
96
+ else
90
97
error ->
98
+ logs =
99
+ Enum . map_join ( ports , "\n " , fn { index , port } -> close_port ( port , "#{ index } >" ) end )
100
+
91
101
Mix . raise ( """
92
102
could not start partition dependency compiler, no connection made to TCP port: #{ inspect ( error ) }
93
103
94
- The spawned operating system process wrote the following output:
95
- #{ close_port ( port , "" ) }
104
+ #{ logs }
96
105
""" )
97
106
end
98
107
end )
@@ -203,7 +212,7 @@ defmodule Mix.Tasks.Deps.Partition do
203
212
204
213
## Client
205
214
206
- @ switches [ port: :integer , host: :string , force: :boolean ]
215
+ @ switches [ port: :integer , host: :string , force: :boolean , index: :string ]
207
216
208
217
@ impl true
209
218
def run ( args ) do
@@ -216,11 +225,14 @@ defmodule Mix.Tasks.Deps.Partition do
216
225
{ opts , [ ] } = OptionParser . parse! ( args , strict: @ switches )
217
226
host = Keyword . fetch! ( opts , :host )
218
227
port = Keyword . fetch! ( opts , :port )
228
+ index = Keyword . fetch! ( opts , :index )
219
229
force? = Keyword . get ( opts , :force , false )
220
230
221
231
{ :ok , socket } =
222
232
:gen_tcp . connect ( String . to_charlist ( host ) , port , [ :binary , packet: :line , active: false ] )
223
233
234
+ :gen_tcp . send ( socket , "#{ index } \n " )
235
+
224
236
try do
225
237
deps = Mix.Dep . load_and_cache ( )
226
238
client_loop ( socket , deps , force? , Mix.Project . deps_config ( ) )
0 commit comments