Skip to content
Permalink
Browse files

Fix release tar when include_erts is false (#9570)

Now excludes files that does not exist on the file system. This could
happen e.g. if the release is built with `include_erts: false`.

Otherwise building the tar would fail with `:enoent`.
  • Loading branch information
lasseebert authored and fertapric committed Nov 22, 2019
1 parent 0555260 commit 1767df47472d095d7985e07036721f83674cd078
Showing with 28 additions and 1 deletion.
  1. +3 −1 lib/mix/lib/mix/tasks/release.ex
  2. +25 −0 lib/mix/test/mix/tasks/release_test.exs
@@ -1033,7 +1033,9 @@ defmodule Mix.Tasks.Release do
lib_dirs ++ release_files

files =
Enum.map(dirs, &{String.to_charlist(&1), String.to_charlist(Path.join(release.path, &1))})
dirs
|> Enum.filter(&File.exists?(Path.join(release.path, &1)))
|> Enum.map(&{String.to_charlist(&1), String.to_charlist(Path.join(release.path, &1))})

File.rm(out_path)
:ok = :erl_tar.create(String.to_charlist(out_path), files, [:dereference, :compressed])
@@ -67,6 +67,8 @@ defmodule Mix.Tasks.ReleaseTest do
assert "releases/0.1.0/vm.args" in files
assert "releases/COOKIE" in files
assert "releases/start_erl.data" in files
assert Enum.any?(files, &(&1 =~ "erts"))
assert Enum.any?(files, &(&1 =~ "stdlib"))

for dir <- files_with_versions -- ["ignored_app-0.1.0"] do
[name | _] = String.split(dir, "-")
@@ -79,6 +81,29 @@ defmodule Mix.Tasks.ReleaseTest do
end)
end

test "tar without ERTS" do
in_fixture("release_test", fn ->
config = [releases: [demo: [include_erts: false, steps: [:assemble, :tar]]]]

Mix.Project.in_project(:release_test, ".", config, fn _ ->
root = Path.absname("_build/#{Mix.env()}/rel/demo")

Mix.Task.run("release")
tar_path = Path.expand(Path.join([root, "..", "..", "demo-0.1.0.tar.gz"]))
message = "* building #{tar_path}"
assert_received {:mix_shell, :info, [^message]}
assert File.exists?(tar_path)

{:ok, files} = String.to_charlist(tar_path) |> :erl_tar.table([:compressed])
files = Enum.map(files, &to_string/1)

assert "bin/demo" in files
refute Enum.any?(files, &(&1 =~ "erts"))
refute Enum.any?(files, &(&1 =~ "stdlib"))
end)
end)
end

test "steps" do
in_fixture("release_test", fn ->
last_step = fn release ->

0 comments on commit 1767df4

Please sign in to comment.
You can’t perform that action at this time.