@@ -233,26 +233,46 @@ defmodule Mix.Project do
233233 @ spec apps_paths ( ) :: % { atom => Path . t } | nil
234234 def apps_paths ( config \\ config ( ) ) do
235235 if apps_path = config [ :apps_path ] do
236- apps_path
237- |> Path . join ( "*/mix.exs" )
238- |> Path . wildcard ( )
239- |> Enum . map ( & Path . dirname / 1 )
240- |> extract_umbrella
241- |> filter_umbrella ( config [ :apps ] )
242- |> Map . new
236+ Mix.ProjectStack . read_cache ( :apps_path ) ||
237+ Mix.ProjectStack . write_cache ( :apps_path ,
238+ config [ :apps ] |> umbrella_apps ( apps_path ) |> to_apps_path ( apps_path ) )
243239 end
244240 end
245241
246- defp extract_umbrella ( paths ) do
247- for path <- paths do
248- app = path |> Path . basename |> String . downcase |> String . to_atom
249- { app , path }
242+ defp umbrella_apps ( nil , apps_path ) do
243+ case File . ls ( apps_path ) do
244+ { :ok , apps } -> Enum . map ( apps , & String . to_atom / 1 )
245+ { :error , _ } -> [ ]
250246 end
251247 end
248+ defp umbrella_apps ( apps , _apps_path ) when is_list ( apps ) do
249+ apps
250+ end
251+
252+ defp to_apps_path ( apps , apps_path ) do
253+ for app <- apps ,
254+ path = path_with_mix_exs_otherwise_warn ( app , apps_path ) ,
255+ do: { app , path } ,
256+ into: % { }
257+ end
258+
259+ defp path_with_mix_exs_otherwise_warn ( app , apps_path ) do
260+ path = Path . join ( apps_path , Atom . to_string ( app ) )
261+ cond do
262+ File . regular? ( Path . join ( path , "mix.exs" ) ) ->
263+ path
252264
253- defp filter_umbrella ( pairs , nil ) , do: pairs
254- defp filter_umbrella ( pairs , apps ) when is_list ( apps ) do
255- for { app , _ } = pair <- pairs , app in apps , do: pair
265+ File . dir? ( path ) ->
266+ Mix . shell . error "warning: path #{ inspect Path . relative_to_cwd ( path ) } is a directory but " <>
267+ "it has no mix.exs. Mix won't consider this directory as part of your " <>
268+ "umbrella application. Please add a \" mix.exs\" or set the \" :apps\" key " <>
269+ "in your umbrella configuration with all relevant apps names as atoms"
270+ nil
271+
272+ true ->
273+ # If it is a stray file, we just ignore it.
274+ nil
275+ end
256276 end
257277
258278 @ doc ~S"""
0 commit comments