Skip to content

Commit e75ba4c

Browse files
committed
Move Nerves version check to deps.precompile
If a user does not have a `deps` folder with Nerves fetched, then the new Nerves version check would error out as Nerves.Bootstrap is starting. However, the compilation would continue and other libs later on would fail to compile because they would be missing the Nerves tooling as a result of the bootstraping crash. To fix this, the check has been moved to the `nerves.bootstrap` task and also added before `deps.precompile` to ensure the deps are fetched first before attempting to read any of the `:nerves` dep information
1 parent 831239d commit e75ba4c

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

.dialyzer_ignore.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Run `mix dialyzer --format short` for strings
22
[
3-
{"lib/nerves_bootstrap.ex:52:unknown_function Function Hex.start/0 does not exist."},
4-
{"lib/nerves_bootstrap.ex:53:unknown_function Function Hex.API.Package.get/2 does not exist."}
3+
{"lib/nerves_bootstrap.ex:41:unknown_function Function Hex.start/0 does not exist."},
4+
{"lib/nerves_bootstrap.ex:42:unknown_function Function Hex.API.Package.get/2 does not exist."}
55
]

lib/mix/tasks/nerves/bootstrap.ex

+10-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ defmodule Mix.Tasks.Nerves.Bootstrap do
2828
end
2929

3030
if Version.match?(nerves_ver, "< 1.8.0") do
31-
Mix.raise(":nerves version requirement not met")
31+
Mix.raise("""
32+
You are using :nerves #{nerves_ver} which is incompatible with this version
33+
of nerves_bootstrap and will result in compilation failures.
34+
35+
Please update to :nerves >= 1.8.0 or downgrade your nerves_bootstrap <= 1.11.5
36+
""")
3237
end
3338

34-
unless Code.ensure_loaded?(Nerves.Env) do
39+
if Mix.target() != :host and not Code.ensure_loaded?(Nerves.Env) do
3540
# The tooling mix tasks are maintained in :nerves so we need to
36-
# ensure it is compiled here first so the tasks are available
41+
# ensure it is compiled here first so the tasks are available.
42+
# If the target is host, then this will be handled by the regular
43+
# compilation process
3744
_ = Mix.Tasks.Deps.Loadpaths.run(["--no-compile"])
3845
Mix.Tasks.Deps.Compile.run(["nerves", "--include-children"])
3946
end

lib/nerves_bootstrap.ex

+2-13
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ defmodule Nerves.Bootstrap do
66

77
@impl Application
88
def start(_type, _args) do
9-
nerves_ver = nerves_version()
10-
11-
if nerves_ver && Version.match?(nerves_ver, "< 1.8.0") do
12-
message = """
13-
You are using :nerves #{nerves_ver} which is incompatible with this version
14-
of nerves_bootstrap and will result in compilation failures.
15-
16-
Please update to :nerves >= 1.8.0 or downgrade your nerves_bootstrap <= 1.11.5
17-
"""
18-
19-
Mix.shell().info([:yellow, message, :reset])
20-
end
21-
229
Nerves.Bootstrap.Aliases.init()
2310
{:ok, self()}
2411
end
@@ -37,6 +24,8 @@ defmodule Nerves.Bootstrap do
3724
if path = Mix.Project.deps_paths()[:nerves] do
3825
Mix.Project.in_project(:nerves, path, fn _ -> Mix.Project.config()[:version] end)
3926
end
27+
catch
28+
_, _ -> nil
4029
end
4130

4231
@doc """

lib/nerves_bootstrap/aliases.ex

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ defmodule Nerves.Bootstrap.Aliases do
4141
aliases
4242
|> append("deps.get", "nerves.bootstrap")
4343
|> append("deps.get", "nerves.deps.get")
44+
|> prepend("deps.precompile", "nerves.bootstrap")
4445
|> replace("deps.update", &Nerves.Bootstrap.Aliases.deps_update/1)
4546
end
4647

test/nerves_bootstrap_test.exs

+2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ defmodule Nerves.BootstrapTest do
55
deps_loadpaths = ["nerves.bootstrap", "nerves.loadpaths", "deps.loadpaths"]
66
deps_get = ["deps.get", "nerves.bootstrap", "nerves.deps.get"]
77
deps_update = [&Nerves.Bootstrap.Aliases.deps_update/1]
8+
deps_precompile = ["nerves.bootstrap", "deps.precompile"]
89
deps_compile = ["nerves.bootstrap", "nerves.loadpaths", "deps.compile"]
910

1011
aliases = Nerves.Bootstrap.add_aliases([])
1112
assert Keyword.get(aliases, :"deps.loadpaths") == deps_loadpaths
1213
assert Keyword.get(aliases, :"deps.get") == deps_get
1314
assert Keyword.get(aliases, :"deps.update") == deps_update
15+
assert Keyword.get(aliases, :"deps.precompile") == deps_precompile
1416
assert Keyword.get(aliases, :"deps.compile") == deps_compile
1517
end
1618

0 commit comments

Comments
 (0)