@@ -34,113 +34,23 @@ defmodule Expert.Port do
34
34
def elixir_executable ( % Project { } = project ) do
35
35
root_path = Project . root_path ( project )
36
36
37
- { 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 ( ) }
42
- end
37
+ # We run a shell in interactive mode to populate the PATH with the right value
38
+ # at the project root. Otherwise, we either can't find an elixir executable ,
39
+ # we use the wrong version if the user uses a version manager like asdf/mise ,
40
+ # or we get an incomplete PATH not including erl or any other version manager
41
+ # managed programs.
42
+ shell = System . get_env ( "SHELL" )
43
43
44
- case path_result do
45
- nil ->
46
- { :error , :no_elixir }
47
-
48
- executable when is_binary ( executable ) ->
49
- { :ok , executable , env }
50
- end
51
- end
52
-
53
- defp version_manager_path_and_env ( manager , root_path ) do
54
- 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
57
- { String . trim ( path ) , env }
58
- else
59
- _ ->
60
- nil
61
- end
62
- end
63
-
64
- # We launch expert by asking the version managers to provide an environment,
65
- # which contains path munging. This initial environment is present in the running
66
- # 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 )
44
+ { path , 0 } = System . cmd ( shell , [ "-i" , "-l" , "-c" , "cd #{ root_path } && echo $PATH" ] )
45
+ elixir = :os . find_executable ( ~c" elixir" , to_charlist ( path ) )
69
46
70
47
env =
71
- env
72
- |> String . trim ( )
73
- |> String . split ( "\n " )
74
- |> Enum . map ( fn key_and_value ->
75
- [ key , value ] =
76
- key_and_value
77
- |> String . split ( "=" , parts: 2 )
78
- |> Enum . map ( & String . trim / 1 )
79
-
80
- { key , value }
48
+ Enum . map ( System . get_env ( ) , fn
49
+ { "PATH" , _path } -> { "PATH" , path }
50
+ other -> other
81
51
end )
82
- |> Enum . reject ( & is_nil / 1 )
83
52
84
- asdf_path =
85
- case List . keyfind ( env , "ASDF_INSTALL_PATH" , 0 ) do
86
- { _ , path } -> Path . join ( path , "../../../shims" )
87
- _ -> ""
88
- end
89
-
90
- Enum . map ( System . get_env ( ) , fn
91
- { "PATH" , path } -> { "PATH" , "#{ asdf_path } :#{ path } " }
92
- other -> other
93
- end )
94
- end
95
-
96
- defp reset_env ( "rtx" , root_path ) do
97
- { env , _ } = System . cmd ( "rtx" , ~w( env -s bash) , cd: root_path )
98
-
99
- env
100
- |> String . trim ( )
101
- |> String . split ( "\n " )
102
- |> Enum . map ( fn
103
- "export " <> key_and_value ->
104
- [ key , value ] =
105
- key_and_value
106
- |> String . split ( "=" , parts: 2 )
107
- |> Enum . map ( & String . trim / 1 )
108
- |> then ( fn
109
- [ "PATH" , path ] -> [ "PATH" , String . trim ( path , "'" ) ]
110
- other -> other
111
- end )
112
-
113
- { key , value }
114
-
115
- _ ->
116
- nil
117
- end )
118
- |> Enum . reject ( & is_nil / 1 )
119
- end
120
-
121
- defp reset_env ( "mise" , root_path ) do
122
- { env , _ } = System . cmd ( "mise" , ~w( env -s bash) , cd: root_path )
123
-
124
- env
125
- |> String . trim ( )
126
- |> String . split ( "\n " )
127
- |> Enum . map ( fn
128
- "export " <> key_and_value ->
129
- [ key , value ] =
130
- key_and_value
131
- |> String . split ( "=" , parts: 2 )
132
- |> Enum . map ( & String . trim / 1 )
133
- |> then ( fn
134
- [ "PATH" , path ] -> [ "PATH" , String . trim ( path , "'" ) ]
135
- other -> other
136
- end )
137
-
138
- { key , value }
139
-
140
- _ ->
141
- nil
142
- end )
143
- |> Enum . reject ( & is_nil / 1 )
53
+ { :ok , elixir , env }
144
54
end
145
55
146
56
@ doc """
0 commit comments