Skip to content

Commit 85f2541

Browse files
committed
Hard requirement for :nerves >= 1.8
The mix tooling was moved to Nerves starting in 1.8. Since we removed the duplicated tasks from the attic code, we now need to require this version of Nerves for future versions of Nerves bootstrap. This adds compilation failures and warnings where possible to help people through the transition
1 parent f965fd2 commit 85f2541

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
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:39:unknown_function Function Hex.start/0 does not exist."},
4-
{"lib/nerves_bootstrap.ex:40:unknown_function Function Hex.API.Package.get/2 does not exist."}
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."}
55
]

lib/mix/tasks/nerves/bootstrap.ex

+12-22
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,28 @@ defmodule Mix.Tasks.Nerves.Bootstrap do
2121
def run(_args) do
2222
debug("load nerves START")
2323

24+
nerves_ver = Nerves.Bootstrap.nerves_version()
25+
26+
if is_nil(nerves_ver) do
27+
Mix.raise(":nerves is required as a dependency of this project")
28+
end
29+
30+
if Version.match?(nerves_ver, "< 1.8.0") do
31+
Mix.raise(":nerves version requirement not met")
32+
end
33+
2434
unless Code.ensure_loaded?(Nerves.Env) do
35+
# The tooling mix tasks are maintained in :nerves so we need to
36+
# ensure it is compiled here first so the tasks are available
2537
_ = Mix.Tasks.Deps.Loadpaths.run(["--no-compile"])
26-
27-
# Nerves.Bootstrap used to manage all the Nerves mix tasks and continues
28-
# to define them for backwards compatibilty. But the mix tasks were moved
29-
# to Nerves in new versions to be maintained there. So if the newer Nerves
30-
# version is being used, then there will be lots of warnings about modules
31-
# from Nerves.Bootstrap being redefined in Nerves, so we opt to suppress
32-
# them only while we compile Nerves, and then set back to original option
33-
{ignore?, prev} = get_ignore_opts()
34-
Code.put_compiler_option(:ignore_module_conflict, ignore?)
3538
Mix.Tasks.Deps.Compile.run(["nerves", "--include-children"])
36-
Code.put_compiler_option(:ignore_module_conflict, prev)
3739
end
3840

3941
Nerves.Bootstrap.check_for_update()
4042

4143
debug("load nerves END")
4244
end
4345

44-
defp get_ignore_opts() do
45-
version = Nerves.Bootstrap.nerves_version()
46-
prev = Code.get_compiler_option(:ignore_module_conflict) || false
47-
48-
if version && Version.match?(version, "> 1.7.16") do
49-
debug("ignoring module conflict warnings with Nerves")
50-
{true, prev}
51-
else
52-
{false, false}
53-
end
54-
end
55-
5646
defp debug(msg) do
5747
if System.get_env("NERVES_DEBUG") == "1" do
5848
Mix.shell().info([:inverse, "|nerves_boostrap| #{msg}", :reset])

lib/nerves_bootstrap.ex

+15-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ 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+
922
Nerves.Bootstrap.Aliases.init()
1023
{:ok, self()}
1124
end
@@ -93,13 +106,10 @@ defmodule Nerves.Bootstrap do
93106
message <>
94107
"""
95108
96-
It is recommended to update your `:nerves` version also as this update
97-
utilizes updates and improvements from `:nerves >= 1.8.0`.
98-
(You currently have #{nerves_ver})
109+
This version requires `:nerves >= 1.8.0` (You currently have #{nerves_ver})
110+
You must also update your `:nerves` dependency by running
99111
100112
mix deps.update nerves
101-
102-
However, this is backwards compatible if you cannot update `:nerves` at this time.
103113
""",
104114
else: message
105115

test/nerves_bootstrap_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ defmodule Nerves.BootstrapTest do
139139
Nerves.Bootstrap.render_update_message(current_version, latest_version, nerves_ver)
140140

141141
assert_receive {:mix_shell, :info, [message]}
142-
assert message =~ "It is recommended to update your `:nerves`"
142+
assert message =~ "This version requires `:nerves >= 1.8.0`"
143143
end
144144

145145
test "Does not include nerves message when acceptable version in deps" do
@@ -149,6 +149,6 @@ defmodule Nerves.BootstrapTest do
149149
Nerves.Bootstrap.render_update_message(current_version, latest_version, nerves_ver)
150150

151151
assert_receive {:mix_shell, :info, [message]}
152-
refute message =~ "It is recommended to update your `:nerves`"
152+
refute message =~ "This version requires `:nerves >= 1.8.0`"
153153
end
154154
end

0 commit comments

Comments
 (0)