@@ -32,28 +32,36 @@ defmodule Expert.Port do
3232 end
3333
3434 def elixir_executable ( % Project { } = project ) do
35+ find_executable ( project , "elixir" )
36+ end
37+
38+ def erlang_executable ( % Project { } = project ) do
39+ find_executable ( project , "erl" )
40+ end
41+
42+ defp find_executable ( project , exe ) do
3543 root_path = Project . root_path ( project )
3644
3745 { path_result , env } =
38- with nil <- version_manager_path_and_env ( "asdf" , root_path ) ,
39- nil <- version_manager_path_and_env ( "mise" , root_path ) ,
40- nil <- version_manager_path_and_env ( "rtx" , root_path ) do
41- { File . cd! ( root_path , fn -> System . find_executable ( "elixir" ) end ) , System . get_env ( ) }
46+ with nil <- version_manager_path_and_env ( "asdf" , exe , root_path ) ,
47+ nil <- version_manager_path_and_env ( "mise" , exe , root_path ) ,
48+ nil <- version_manager_path_and_env ( "rtx" , exe , root_path ) do
49+ { File . cd! ( root_path , fn -> System . find_executable ( exe ) end ) , System . get_env ( ) }
4250 end
4351
4452 case path_result do
4553 nil ->
46- { :error , :no_elixir }
54+ { :error , :" #{ exe } _not_found" }
4755
4856 executable when is_binary ( executable ) ->
4957 { :ok , executable , env }
5058 end
5159 end
5260
53- defp version_manager_path_and_env ( manager , root_path ) do
61+ defp version_manager_path_and_env ( manager , exe , root_path ) do
5462 with true <- is_binary ( System . find_executable ( manager ) ) ,
55- env = reset_env ( manager , root_path ) ,
56- { path , 0 } <- System . cmd ( manager , ~w ( which elixir ) , cd: root_path , env: env ) do
63+ env = reset_env ( manager , exe , root_path ) ,
64+ { path , 0 } <- System . cmd ( manager , [ " which" , exe ] , cd: root_path , env: env ) do
5765 { String . trim ( path ) , env }
5866 else
5967 _ ->
@@ -64,8 +72,8 @@ defmodule Expert.Port do
6472 # We launch expert by asking the version managers to provide an environment,
6573 # which contains path munging. This initial environment is present in the running
6674 # VM, and needs to be undone so we can find the correct elixir executable in the project.
67- defp reset_env ( "asdf" , root_path ) do
68- { env , _ } = System . cmd ( "asdf" , ~w ( env elixir ) , cd: root_path )
75+ defp reset_env ( "asdf" , exe , root_path ) do
76+ { env , _ } = System . cmd ( "asdf" , [ " env" , exe ] , cd: root_path )
6977
7078 env =
7179 env
@@ -93,7 +101,7 @@ defmodule Expert.Port do
93101 end )
94102 end
95103
96- defp reset_env ( "rtx" , root_path ) do
104+ defp reset_env ( "rtx" , _exe , root_path ) do
97105 { env , _ } = System . cmd ( "rtx" , ~w( env -s bash) , cd: root_path )
98106
99107 env
@@ -118,7 +126,7 @@ defmodule Expert.Port do
118126 |> Enum . reject ( & is_nil / 1 )
119127 end
120128
121- defp reset_env ( "mise" , root_path ) do
129+ defp reset_env ( "mise" , _exe , root_path ) do
122130 { env , _ } = System . cmd ( "mise" , ~w( env -s bash) , cd: root_path )
123131
124132 env
0 commit comments