@@ -32,28 +32,36 @@ defmodule Expert.Port do
32
32
end
33
33
34
34
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
35
43
root_path = Project . root_path ( project )
36
44
37
45
{ 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 ( ) }
42
50
end
43
51
44
52
case path_result do
45
53
nil ->
46
- { :error , :no_elixir }
54
+ { :error , :" #{ exe } _not_found" }
47
55
48
56
executable when is_binary ( executable ) ->
49
57
{ :ok , executable , env }
50
58
end
51
59
end
52
60
53
- defp version_manager_path_and_env ( manager , root_path ) do
61
+ defp version_manager_path_and_env ( manager , exe , root_path ) do
54
62
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
57
65
{ String . trim ( path ) , env }
58
66
else
59
67
_ ->
@@ -64,8 +72,8 @@ defmodule Expert.Port do
64
72
# We launch expert by asking the version managers to provide an environment,
65
73
# which contains path munging. This initial environment is present in the running
66
74
# 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 )
69
77
70
78
env =
71
79
env
@@ -93,7 +101,7 @@ defmodule Expert.Port do
93
101
end )
94
102
end
95
103
96
- defp reset_env ( "rtx" , root_path ) do
104
+ defp reset_env ( "rtx" , _exe , root_path ) do
97
105
{ env , _ } = System . cmd ( "rtx" , ~w( env -s bash) , cd: root_path )
98
106
99
107
env
@@ -118,7 +126,7 @@ defmodule Expert.Port do
118
126
|> Enum . reject ( & is_nil / 1 )
119
127
end
120
128
121
- defp reset_env ( "mise" , root_path ) do
129
+ defp reset_env ( "mise" , _exe , root_path ) do
122
130
{ env , _ } = System . cmd ( "mise" , ~w( env -s bash) , cd: root_path )
123
131
124
132
env
0 commit comments