Skip to content

Commit 6ce06d5

Browse files
committedFeb 28, 2024·
Ensure logger compiler app is available if compile.elixir is called directly
1 parent fc90206 commit 6ce06d5

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed
 

‎lib/mix/lib/mix/tasks/compile.all.ex

+3-17
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ defmodule Mix.Tasks.Compile.All do
5353
# Build the project structure so we can write down compiled files.
5454
Mix.Project.build_structure(config)
5555

56-
with_logger_app(config, fn ->
57-
config
58-
|> Mix.Tasks.Compile.compilers()
59-
|> compile(args, :noop, [])
60-
end)
56+
config
57+
|> Mix.Tasks.Compile.compilers()
58+
|> compile(args, :noop, [])
6159
end
6260

6361
if app_cache do
@@ -84,18 +82,6 @@ defmodule Mix.Tasks.Compile.All do
8482
result
8583
end
8684

87-
defp with_logger_app(config, fun) do
88-
app = Keyword.fetch!(config, :app)
89-
logger_config_app = Application.get_env(:logger, :compile_time_application)
90-
91-
try do
92-
Logger.configure(compile_time_application: app)
93-
fun.()
94-
after
95-
Logger.configure(compile_time_application: logger_config_app)
96-
end
97-
end
98-
9985
defp compile([], _, status, diagnostics) do
10086
{status, diagnostics}
10187
end

‎lib/mix/lib/mix/tasks/compile.elixir.ex

+26-10
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,19 @@ defmodule Mix.Tasks.Compile.Elixir do
126126
# Having compilations racing with other is most undesired,
127127
# so we wrap the compiler in a lock. Ideally we would use
128128
# flock in the future.
129-
Mix.State.lock(__MODULE__, fn ->
130-
Mix.Compilers.Elixir.compile(
131-
manifest,
132-
srcs,
133-
dest,
134-
cache_key,
135-
Mix.Tasks.Compile.Erlang.manifests(),
136-
Mix.Tasks.Compile.Erlang.modules(),
137-
opts
138-
)
129+
130+
with_logger_app(project, fn ->
131+
Mix.State.lock(__MODULE__, fn ->
132+
Mix.Compilers.Elixir.compile(
133+
manifest,
134+
srcs,
135+
dest,
136+
cache_key,
137+
Mix.Tasks.Compile.Erlang.manifests(),
138+
Mix.Tasks.Compile.Erlang.modules(),
139+
opts
140+
)
141+
end)
139142
end)
140143
end
141144

@@ -149,6 +152,19 @@ defmodule Mix.Tasks.Compile.Elixir do
149152
Mix.Compilers.Elixir.clean(manifest(), dest)
150153
end
151154

155+
# Run this operation in compile.elixir as the compiler can be called directly
156+
defp with_logger_app(config, fun) do
157+
app = Keyword.fetch!(config, :app)
158+
logger_config_app = Application.get_env(:logger, :compile_time_application)
159+
160+
try do
161+
Logger.configure(compile_time_application: app)
162+
fun.()
163+
after
164+
Logger.configure(compile_time_application: logger_config_app)
165+
end
166+
end
167+
152168
defp xref_exclude_opts(opts, project) do
153169
exclude = List.wrap(project[:xref][:exclude])
154170

0 commit comments

Comments
 (0)
Please sign in to comment.