Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/mix/tasks/compile.elixir_make.ex
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,20 @@ defmodule Mix.Tasks.Compile.ElixirMake do
{:ok, target, nif_version_to_use, url} ->
archived_fullpath = Artefact.archive_path(config, target, nif_version_to_use)

unless File.exists?(archived_fullpath) do
Mix.shell().info("Downloading precompiled NIF to #{archived_fullpath}")
download =
unless File.exists?(archived_fullpath) do
Mix.shell().info("Downloading precompiled NIF to #{archived_fullpath}")

with {:ok, archived_data} <- Artefact.download(config, url) do
File.mkdir_p(Path.dirname(archived_fullpath))
File.write(archived_fullpath, archived_data)
with {:ok, archived_data} <- Artefact.download(config, url) do
File.mkdir_p(Path.dirname(archived_fullpath))
File.write(archived_fullpath, archived_data)
end
end
end

Artefact.verify_and_decompress(archived_fullpath, app_priv)
case download do
{:error, _} = error -> error
_ -> Artefact.verify_and_decompress(archived_fullpath, app_priv)
end

{:error, msg} ->
{:error, msg}
Expand Down
30 changes: 30 additions & 0 deletions test/mix/tasks/compile.make_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
:ok
end

test "running with a specific executable" do

Check failure on line 35 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test running with a specific executable (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
with_project_config([make_executable: "nonexistentmake"], fn ->
assert_raise Mix.Error, ~r/not found in the path/, fn ->
Expand All @@ -42,7 +42,7 @@
end)
end

test "running without a makefile" do

Check failure on line 45 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test running without a makefile (Mix.Tasks.Compile.ElixirMakeTest)
msg = ~r/\ACould not compile with/

in_fixture(fn ->
Expand Down Expand Up @@ -100,7 +100,7 @@
end)
end

test "warns if the cwd contains a space" do

Check failure on line 103 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test warns if the cwd contains a space (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
File.mkdir_p!("subdir with spaces")

Expand Down Expand Up @@ -185,7 +185,7 @@
end)
end

test "overwrite default env" do

Check failure on line 188 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test overwrite default env (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
File.write!("Makefile", """
all:
Expand All @@ -198,7 +198,7 @@
end)
end

test "specifying a makefile" do

Check failure on line 201 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test specifying a makefile (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
File.write("MyMakefile", """
all:
Expand Down Expand Up @@ -238,7 +238,7 @@
end)
end

test "user-defined executable through environment variable" do

Check failure on line 241 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test user-defined executable through environment variable (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
System.put_env("MAKE", "nonexistentmake")

Expand All @@ -250,7 +250,7 @@
end)
end

test "user-defined executable with no arguments allowed" do

Check failure on line 253 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test user-defined executable with no arguments allowed (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
System.put_env("MAKE", "make -f makefile")

Expand Down Expand Up @@ -278,7 +278,7 @@
end)
end

test "additional args to make" do

Check failure on line 281 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test additional args to make (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
File.write("Makefile", """
all:
Expand All @@ -292,7 +292,7 @@
end)
end

test "doesn't clobber existing build artifacts" do

Check failure on line 295 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test doesn't clobber existing build artifacts (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
build_file_path = "./_build/test/lib/my_app/priv/build_file"

Expand Down Expand Up @@ -381,7 +381,7 @@
end)
end

test "custom downloader" do

Check failure on line 384 in test/mix/tasks/compile.make_test.exs

View workflow job for this annotation

GitHub Actions / test (1.19, 28, lint)

test custom downloader (Mix.Tasks.Compile.ElixirMakeTest)
in_fixture(fn ->
File.mkdir!("priv")

Expand Down Expand Up @@ -421,6 +421,29 @@
end)
end

test "surfaces the download error instead of a misleading file-not-found" do
in_fixture(fn ->
File.mkdir!("priv")

File.write("Makefile", """
all:
\t@touch priv/my_app
""")

with_project_config(
[
make_precompiler: {:nif, MyApp.Precompiler},
make_precompiler_url: "https://example.com/@{artefact_filename}",
make_precompiler_downloader: MyApp.FailingDownloader
],
fn ->
System.put_env("ELIXIR_MAKE_CACHE_DIR", "./cache")
assert capture_io(:stderr, fn -> run([]) end) =~ "download boom"
end
)
end)
end

defp in_fixture(fun) do
File.cd!(@fixture_project, fun)
end
Expand All @@ -440,3 +463,10 @@
File.read(path)
end
end

defmodule MyApp.FailingDownloader do
@behaviour ElixirMake.Downloader

@impl true
def download(_url), do: {:error, "download boom"}
end