Skip to content

Commit 7626f90

Browse files
authored
fix: make sure asdf shims are in the PATH (#87)
1 parent 55be3ba commit 7626f90

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

apps/expert/lib/expert/engine_node.ex

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule Expert.EngineNode do
22
alias Forge.Project
33
require Logger
44

5+
use Expert.Project.Progress.Support
6+
57
defmodule State do
68
defstruct [
79
:project,
@@ -169,7 +171,7 @@ defmodule Expert.EngineNode do
169171
# Expert release, and we build it on the fly for the project elixir+opt
170172
# versions if it was not built yet.
171173
defp glob_paths(%Project{} = project) do
172-
{:ok, elixir, _} = Expert.Port.elixir_executable(project)
174+
{:ok, elixir, env} = Expert.Port.elixir_executable(project)
173175

174176
expert_priv = :code.priv_dir(:expert)
175177
packaged_engine_source = Path.join([expert_priv, "engine_source", "apps", "engine"])
@@ -192,20 +194,26 @@ defmodule Expert.EngineNode do
192194
"--vsn",
193195
Expert.vsn()
194196
],
197+
env: Expert.Port.ensure_charlists(env),
195198
cd: engine_source
196199
]
197200

198201
launcher = Expert.Port.path()
199202

200-
Logger.info("Finding or building engine for project #{Project.name(project)}")
203+
GenLSP.info(
204+
Expert.get_lsp(),
205+
"Finding or building engine for project #{Project.name(project)}"
206+
)
201207

202-
port =
203-
Port.open(
204-
{:spawn_executable, launcher},
205-
opts
206-
)
208+
with_progress(project, "Building engine for #{Project.name(project)}", fn ->
209+
port =
210+
Port.open(
211+
{:spawn_executable, launcher},
212+
opts
213+
)
207214

208-
wait_for_engine(port)
215+
wait_for_engine(port)
216+
end)
209217
end
210218

211219
defp wait_for_engine(port) do

apps/expert/lib/expert/port.ex

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,31 @@ defmodule Expert.Port do
6464
# We launch expert by asking the version managers to provide an environment,
6565
# which contains path munging. This initial environment is present in the running
6666
# 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-
orig_path = System.get_env("PATH_SAVE", System.get_env("PATH"))
67+
defp reset_env("asdf", root_path) do
68+
{env, _} = System.cmd("asdf", ~w(env elixir), cd: root_path)
69+
70+
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}
81+
end)
82+
|> Enum.reject(&is_nil/1)
83+
84+
asdf_path =
85+
case List.keyfind(env, "ASDF_INSTALL_PATH", 0) do
86+
{_, path} -> Path.join(path, "../../../shims")
87+
_ -> ""
88+
end
6989

7090
Enum.map(System.get_env(), fn
71-
{"ASDF_ELIXIR_VERSION", _} -> {"ASDF_ELIXIR_VERSION", nil}
72-
{"ASDF_ERLANG_VERSION", _} -> {"ASDF_ERLANG_VERSION", nil}
73-
{"PATH", _} -> {"PATH", orig_path}
91+
{"PATH", path} -> {"PATH", "#{asdf_path}:#{path}"}
7492
other -> other
7593
end)
7694
end
@@ -169,7 +187,7 @@ defmodule Expert.Port do
169187
raise ArgumentError, "Operating system #{inspect(os_tuple)} is not currently supported"
170188
end
171189

172-
defp ensure_charlists(environment_variables) do
190+
def ensure_charlists(environment_variables) do
173191
Enum.map(environment_variables, fn {key, value} ->
174192
# using to_string ensures nil values won't blow things up
175193
erl_key = key |> to_string() |> String.to_charlist()

0 commit comments

Comments
 (0)