@@ -61,108 +61,6 @@ defmodule Mix.Rebar do
6161 end
6262 end
6363
64- @ doc """
65- Merges a rebar3 parent config with a child config.
66- """
67- # From https://github.com/rebar/rebar3/blob/b1da2ec0674df89599564252734bd4d794436425/src/rebar_opts.erl#L103
68- def merge_config ( old , new ) do
69- Keyword . merge ( old , new , fn
70- :deps , old , _new -> old
71- { :deps , _ } , _old , new -> new
72- :plugins , _old , new -> new
73- { :plugins , _ } , _old , new -> new
74- :profiles , old , new -> merge_config ( old , new )
75- :mib_first_files , value , value -> value
76- :mib_first_files , old , new -> old ++ new
77- :relx , old , new -> tuple_merge ( new , old )
78- _key , old , new when is_list ( new ) ->
79- case :io_lib . printable_list ( new ) do
80- true when new == [ ] ->
81- if :io_lib . printable_list ( old ) , do: new , else: old
82- true ->
83- new
84- false ->
85- tuple_merge ( old , new )
86- end
87- _key , _old , new -> new
88- end )
89- end
90-
91- # From https://github.com/rebar/rebar3/blob/b1da2ec0674df89599564252734bd4d794436425/src/rebar_utils.erl#L282
92- defp tuple_merge ( old , new ) ,
93- do: do_tuple_merge ( tuple_sort ( old ) , tuple_sort ( new ) )
94-
95- defp do_tuple_merge ( old , [ ] ) ,
96- do: old
97- defp do_tuple_merge ( olds , [ new | news ] ) ,
98- do: do_tuple_umerge_dedup ( umerge ( :new , olds , [ ] , news , new ) , [ ] )
99-
100- defp umerge ( _ , [ ] , [ ] , acc , current ) ,
101- do: [ current | acc ]
102- defp umerge ( :new , [ ] , news , acc , current ) ,
103- do: Enum . reverse ( news , [ current | acc ] )
104- defp umerge ( :old , olds , [ ] , acc , current ) ,
105- do: Enum . reverse ( olds , [ current | acc ] )
106- defp umerge ( :new , [ old | olds ] , news , acc , current ) do
107- { dir , merged , new_current } = compare ( { :new , current } , { :old , old } )
108- umerge ( dir , olds , news , [ merged | acc ] , new_current )
109- end
110- defp umerge ( :old , olds , [ new | news ] , acc , current ) do
111- { dir , merged , new_current } = compare ( { :new , new } , { :old , current } )
112- umerge ( dir , olds , news , [ merged | acc ] , new_current )
113- end
114-
115- defp compare ( { priority , a } , { secondary , b } ) when is_tuple ( a ) and is_tuple ( b ) do
116- ka = elem ( a , 0 )
117- kb = elem ( b , 0 )
118- cond do
119- ka == kb -> { secondary , a , b }
120- ka < kb -> { secondary , a , b }
121- ka > kb -> { priority , b , a }
122- end
123- end
124- defp compare ( { priority , a } , { secondary , b } ) when not is_tuple ( a ) and not is_tuple ( b ) do
125- cond do
126- a == b -> { secondary , a , b }
127- a < b -> { secondary , a , b }
128- a > b -> { priority , b , a }
129- end
130- end
131- defp compare ( { priority , a } , { secondary , b } ) when is_tuple ( a ) and not is_tuple ( b ) do
132- ka = elem ( a , 0 )
133- cond do
134- ka == b -> { secondary , a , b }
135- ka < b -> { secondary , a , b }
136- ka > b -> { priority , b , a }
137- end
138- end
139- defp compare ( { priority , a } , { secondary , b } ) when not is_tuple ( a ) and is_tuple ( b ) do
140- kb = elem ( b , 0 )
141- cond do
142- a == kb -> { secondary , a , b }
143- a < kb -> { secondary , a , b }
144- a > kb -> { priority , b , a }
145- end
146- end
147-
148- defp do_tuple_umerge_dedup ( [ ] , acc ) , do: acc
149- defp do_tuple_umerge_dedup ( [ h | t ] , acc ) do
150- if h in t do
151- do_tuple_umerge_dedup ( t , acc )
152- else
153- do_tuple_umerge_dedup ( t , [ h | acc ] )
154- end
155- end
156-
157- defp tuple_sort ( list ) do
158- Enum . sort ( list , fn
159- a , b when is_tuple ( a ) and is_tuple ( b ) -> elem ( a , 0 ) <= elem ( b , 0 )
160- a , b when is_tuple ( a ) -> elem ( a , 0 ) <= b
161- a , b when is_tuple ( b ) -> a <= elem ( b , 0 )
162- a , b -> a <= b
163- end )
164- end
165-
16664 @ doc """
16765 Serializes a Rebar config to a term file.
16866 """
@@ -178,7 +76,7 @@ defmodule Mix.Rebar do
17876 def dependency_config ( config ) do
17977 Enum . map ( config , fn
18078 { :erl_opts , opts } ->
181- { :erl_opts , Enum . reject ( opts , & ( & 1 == :warnings_as_errors ) ) }
79+ { :erl_opts , List . delete ( opts , :warnings_as_errors ) }
18280 other ->
18381 other
18482 end )
@@ -187,10 +85,9 @@ defmodule Mix.Rebar do
18785 @ doc """
18886 Parses the dependencies in given `rebar.config` to Mix's dependency format.
18987 """
190- def deps ( app , config , overrides ) do
88+ def deps ( config ) do
19189 # We don't have to handle rebar3 profiles because dependencies
19290 # are always in the default profile which cannot be customized
193- config = apply_overrides ( app , config , overrides )
19491 if deps = config [ :deps ] do
19592 Enum . map ( deps , & parse_dep / 1 )
19693 else
@@ -201,19 +98,17 @@ defmodule Mix.Rebar do
20198 @ doc """
20299 Runs `fun` for the given config and for each `sub_dirs` in the
203100 given Rebar config.
204- """
205- def recur ( config , fun ) when is_binary ( config ) do
206- recur ( load_config ( config ) , fun )
207- end
208101
102+ `sub_dirs` is only supported in Rebar 2. In Rebar 3, the equivalent
103+ to umbrella apps cannot be used as dependencies, so we don't need
104+ to worry about such cases in Mix.
105+ """
209106 def recur ( config , fun ) do
210107 subs =
211108 ( config [ :sub_dirs ] || [ ] )
212- |> Enum . map ( & Path . wildcard ( & 1 ) )
213- |> Enum . concat
109+ |> Enum . flat_map ( & Path . wildcard ( & 1 ) )
214110 |> Enum . filter ( & File . dir? ( & 1 ) )
215- |> Enum . map ( & recur ( & 1 , fun ) )
216- |> Enum . concat
111+ |> Enum . flat_map ( & recur ( load_config ( & 1 ) , fun ) )
217112
218113 [ fun . ( config ) | subs ]
219114 end
@@ -325,9 +220,11 @@ defmodule Mix.Rebar do
325220 end
326221 end
327222
328- defp apply_overrides ( app , config , overrides ) do
223+ @ doc """
224+ Applies the given overrides for app config.
225+ """
226+ def apply_overrides ( app , config , overrides ) do
329227 # Inefficient. We want the order we get here though.
330-
331228 config =
332229 Enum . reduce ( overrides , config , fn
333230 { :override , overrides } , config ->
@@ -340,22 +237,25 @@ defmodule Mix.Rebar do
340237
341238 config =
342239 Enum . reduce ( overrides , config , fn
343- { :override , oapp , overrides } , config when oapp == app ->
240+ { :override , ^ app , overrides } , config ->
344241 Enum . reduce ( overrides , config , fn { key , value } , config ->
345242 Keyword . put ( config , key , value )
346243 end )
347244 _ , config ->
348245 config
349246 end )
350247
351- Enum . reduce ( overrides , config , fn
352- { :add , oapp , overrides } , config when oapp == app ->
353- Enum . reduce ( overrides , config , fn { key , value } , config ->
354- old_value = Keyword . get ( config , key , [ ] )
355- Keyword . put ( config , key , value ++ old_value )
248+ config =
249+ Enum . reduce ( overrides , config , fn
250+ { :add , ^ app , overrides } , config ->
251+ Enum . reduce ( overrides , config , fn { key , value } , config ->
252+ old_value = Keyword . get ( config , key , [ ] )
253+ Keyword . put ( config , key , value ++ old_value )
254+ end )
255+ _ , config ->
256+ config
356257 end )
357- _ , config ->
358- config
359- end )
258+
259+ Keyword . update ( config , :overrides , overrides , & ( overrides ++ & 1 ) )
360260 end
361261end
0 commit comments