Skip to content

Commit

Permalink
Load current application in compile.app
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 27, 2024
1 parent 9dcdc1a commit 80eef8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/mix/lib/mix/tasks/compile.app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ defmodule Mix.Tasks.Compile.App do
The complete list can be found on [Erlang's application
specification](https://www.erlang.org/doc/man/app).
From Elixir v1.17 onwards, the application .app file is also loaded
whenever the task runs.
## Command line options
* `--force` - forces compilation regardless of modification times
Expand Down Expand Up @@ -167,12 +170,14 @@ defmodule Mix.Tasks.Compile.App do

properties = [config_mtime: new_mtime] ++ properties
contents = :io_lib.format("~p.~n", [{:application, app, properties}])
:application.load({:application, app, properties})

Mix.Project.ensure_structure()
File.write!(target, IO.chardata_to_string(contents))
Mix.shell().info("Generated #{app} app")
{:ok, []}
else
:application.load({:application, app, current_properties})
{:noop, []}
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/mix/test/mix/tasks/compile.app_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ defmodule Mix.Tasks.Compile.AppTest do
assert Mix.Tasks.Compile.App.run([]) == {:ok, []}

properties = parse_resource_file(:sample)
assert Application.spec(:sample, :vsn) == ~c"0.1.0"
assert properties[:vsn] == ~c"0.1.0"
assert properties[:modules] == [A, B]
assert properties[:applications] == [:kernel, :stdlib, :elixir]
refute Keyword.has_key?(properties, :compile_env)

Application.unload(:sample)
assert Mix.Tasks.Compile.App.run([]) == {:noop, []}
assert Application.spec(:sample, :vsn) == ~c"0.1.0"
end)
end

Expand Down Expand Up @@ -114,6 +117,7 @@ defmodule Mix.Tasks.Compile.AppTest do
Mix.Tasks.Compile.App.run([])

properties = parse_resource_file(:custom_project)
assert Application.spec(:custom_project, :vsn) == ~c"0.2.0"
assert properties[:vsn] == ~c"0.2.0"
assert properties[:maxT] == :infinity
assert properties[:optional_applications] == [:ex_unit, :mix]
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/test/mix/tasks/eval_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Mix.Tasks.EvalTest do

test "does not start applications", context do
in_tmp(context.test, fn ->
expr = "send self(), {:apps, Application.loaded_applications()}"
expr = "send self(), {:apps, Application.started_applications()}"
Mix.Tasks.Eval.run([expr])
assert_received {:apps, apps}
refute List.keyfind(apps, :sample, 0)
Expand Down

0 comments on commit 80eef8c

Please sign in to comment.