Skip to content

Commit 081f99c

Browse files
committed
Consider targets when filtering apps, closes #10405
1 parent 7837cc5 commit 081f99c

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

lib/mix/lib/mix/dep.ex

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,6 @@ defmodule Mix.Dep do
7575
system_env: keyword
7676
}
7777

78-
@doc """
79-
Receives the project configuration and returns
80-
a map saying if dependencies are runtime or compile time.
81-
"""
82-
def deps_opts(config) do
83-
for config_dep <- Keyword.get(config, :deps, []),
84-
do: {elem(config_dep, 0), dep_opts(config_dep)}
85-
end
86-
87-
defp dep_opts({_app, opts}) when is_list(opts), do: opts
88-
defp dep_opts({_app, _req, opts}) when is_list(opts), do: opts
89-
defp dep_opts(_), do: []
90-
9178
@doc """
9279
Returns loaded dependencies from the cache for the current environment.
9380

lib/mix/lib/mix/tasks/compile.app.ex

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,15 @@ defmodule Mix.Tasks.Compile.App do
354354
defp apps_from_runtime_prod_deps(properties, config) do
355355
included_applications = Keyword.get(properties, :included_applications, [])
356356

357-
for {app, opts} <- Mix.Dep.deps_opts(config),
357+
for {app, opts} <- deps_opts(config),
358358
runtime_app?(opts),
359359
app not in included_applications,
360360
do: {app, if(Keyword.get(opts, :optional, false), do: :optional, else: :required)}
361361
end
362362

363363
defp runtime_app?(opts) do
364-
Keyword.get(opts, :runtime, true) and Keyword.get(opts, :app, true) and matching_only?(opts)
364+
Keyword.get(opts, :runtime, true) and Keyword.get(opts, :app, true) and matching_only?(opts) and
365+
matching_target?(opts)
365366
end
366367

367368
defp matching_only?(opts) do
@@ -371,6 +372,22 @@ defmodule Mix.Tasks.Compile.App do
371372
end
372373
end
373374

375+
defp matching_target?(opts) do
376+
case Keyword.fetch(opts, :targets) do
377+
{:ok, value} -> Mix.target() in List.wrap(value)
378+
:error -> true
379+
end
380+
end
381+
382+
defp deps_opts(config) do
383+
for config_dep <- Keyword.get(config, :deps, []),
384+
do: {elem(config_dep, 0), dep_opts(config_dep)}
385+
end
386+
387+
defp dep_opts({_app, opts}) when is_list(opts), do: opts
388+
defp dep_opts({_app, _req, opts}) when is_list(opts), do: opts
389+
defp dep_opts(_), do: []
390+
374391
## Helpers for loading and manipulating apps
375392

376393
@doc false
@@ -386,7 +403,7 @@ defmodule Mix.Tasks.Compile.App do
386403
Keyword.get(properties, :extra_applications, [])
387404

388405
project_apps(properties, config, extra, fn ->
389-
config |> Mix.Dep.deps_opts() |> Keyword.keys()
406+
config |> deps_opts() |> Keyword.keys()
390407
end)
391408
end
392409

lib/mix/test/mix/tasks/compile.app_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ defmodule Mix.Tasks.Compile.AppTest do
4040
{:ok6, path: "../ok", optional: true},
4141
{:ok7, path: "../ok", optional: false},
4242
{:ok8, path: "../ok", app: false},
43-
{:ok9, path: "../ok"}
43+
{:ok9, path: "../ok"},
44+
{:ok10, path: "../ok", targets: [:will_never_be_listed]},
45+
{:ok11, path: "../ok", targets: [Mix.target()]}
4446
]
4547
end
4648
end
@@ -130,7 +132,7 @@ defmodule Mix.Tasks.Compile.AppTest do
130132
properties = parse_resource_file(:custom_deps)
131133

132134
assert properties[:applications] ==
133-
[:kernel, :stdlib, :elixir, :logger, :ok1, :ok3, :ok4, :ok7]
135+
[:kernel, :stdlib, :elixir, :logger, :ok1, :ok3, :ok4, :ok7, :ok11]
134136
end)
135137
end
136138

0 commit comments

Comments
 (0)