Skip to content

Commit 831046f

Browse files
zinedjosevalim
authored andcommitted
Ensure ERTS is not copied into release (#9752)
The default behaviour when starting a new mix project is to `include_erts: true`. If at some point you choose to `include_erts: false`, but have the ERTS artifact hanging around from previous builds, it gets included in future builds, therefore rendering `include_erts: false` broken when running on systems that have built with `include_erts: true` for the same environment. `make_tar/1` currently always tries to include the ERTS artifact into the archive, regardless of our `include_erts` configuration. this fails in 1.9.4 if no previous artifact is present, and seems to be worked around in the current implementation by simply ignoring source directories that don't exist. This adds a regression test for the behaviour by "simulating" an ERTS leftover from a previous build. This also adds logic to not try to include ERTS into archives in the first place when our release is configured with `include_erts: false`.
1 parent 6c44fea commit 831046f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/mix/lib/mix/tasks/release.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,14 +1075,20 @@ defmodule Mix.Tasks.Release do
10751075
[Path.join("lib", "#{name}-#{vsn}") | acc]
10761076
end)
10771077

1078+
erts_dir =
1079+
case release.erts_source do
1080+
nil -> []
1081+
_ -> ["erts-#{release.erts_version}"]
1082+
end
1083+
10781084
release_files =
10791085
for basename <- File.ls!(Path.join(release.path, "releases")),
10801086
not File.dir?(Path.join([release.path, "releases", basename])),
10811087
do: Path.join("releases", basename)
10821088

10831089
dirs =
1084-
["bin", Path.join("releases", release.version), "erts-#{release.erts_version}"] ++
1085-
lib_dirs ++ release_files
1090+
["bin", Path.join("releases", release.version)] ++
1091+
erts_dir ++ lib_dirs ++ release_files
10861092

10871093
files =
10881094
dirs

lib/mix/test/mix/tasks/release_test.exs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,34 @@ defmodule Mix.Tasks.ReleaseTest do
208208
end)
209209
end)
210210
end
211+
212+
test "without ERTS when a previous build included ERTS" do
213+
in_fixture("release_test", fn ->
214+
config = [releases: [demo: [include_erts: false, steps: [:assemble, :tar]]]]
215+
216+
Mix.Project.in_project(:release_test, ".", config, fn _ ->
217+
root = Path.absname("_build/#{Mix.env()}/rel/demo")
218+
219+
erts_dir_from_previous_build =
220+
Path.absname("_build/#{Mix.env()}/rel/demo/erts-#{@erts_version}")
221+
222+
File.mkdir_p!(erts_dir_from_previous_build)
223+
224+
Mix.Task.run("release")
225+
tar_path = Path.expand(Path.join([root, "..", "..", "demo-0.1.0.tar.gz"]))
226+
message = "* building #{tar_path}"
227+
assert_received {:mix_shell, :info, [^message]}
228+
assert File.exists?(tar_path)
229+
230+
{:ok, files} = String.to_charlist(tar_path) |> :erl_tar.table([:compressed])
231+
files = Enum.map(files, &to_string/1)
232+
233+
assert "bin/demo" in files
234+
refute Enum.any?(files, &(&1 =~ "erts"))
235+
refute Enum.any?(files, &(&1 =~ "stdlib"))
236+
end)
237+
end)
238+
end
211239
end
212240

213241
test "assembles a bootable release with ERTS" do

0 commit comments

Comments
 (0)