]> granicus.if.org Git - ejabberd/commitdiff
Make compatible with rebar3
authorPaweł Chmielowski <pchmielowski@process-one.net>
Thu, 24 Nov 2016 13:07:08 +0000 (14:07 +0100)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Thu, 24 Nov 2016 13:23:20 +0000 (14:23 +0100)
rebar.config.script

index 2a924d26cceeb82f3db749a7b9b337b754b01a8d..34e0c328e6998cb4507a5b3a2472809bde592e99 100644 (file)
@@ -21,6 +21,14 @@ ModCfg0 = fun(F, Cfg, [Key|Tail], Op, Default) ->
          end,
 ModCfg = fun(Cfg, Keys, Op, Default) -> ModCfg0(ModCfg0, Cfg, Keys, Op, Default) end,
 
+IsRebar3 = case application:get_key(rebar, vsn) of
+              {ok, VSN} ->
+                  [VSN1 | _] = string:tokens(VSN, "-"),
+                  [Maj, Min, Patch] = string:tokens(VSN1, "."),
+                  (list_to_integer(Maj) >= 3);
+              undefined ->
+                  lists:keymember(mix, 1, application:loaded_applications())
+          end,
 Cfg = case file:consult(filename:join(filename:dirname(SCRIPT), "vars.config")) of
           {ok, Terms} ->
               Terms;
@@ -121,16 +129,62 @@ TestConfig = case file:read_file_info(TestConfigFile) of
                      ""
             end,
 
+ResolveDepPath = case IsRebar3 of
+                    true ->
+                        fun("deps/" ++ Rest) ->
+                                Slash = string:str(Rest, "/"),
+                                Dir = "_build/default/lib/" ++
+                                    string:sub_string(Rest, 1, Slash-1),
+                                Dir ++ string:sub_string(Rest, Slash);
+                           (Path) ->
+                                Path
+                        end;
+                    _ ->
+                        fun(P) ->
+                                 P
+                        end
+                end,
+
 CtIncludes = case lists:keyfind(eunit_compile_opts, 1, Conf1) of
                 false ->
                     [];
                 {_, EunitCompOpts} ->
-                    [[" -include ", filename:join([Cwd, IncPath])]
+                    [[" -include ", filename:join([Cwd, ResolveDepPath(IncPath)])]
                      || {i, IncPath} <- EunitCompOpts]
             end,
 
-Conf2 = [{ct_extra_params, lists:flatten(["-ct_hooks cth_surefire ", TestConfig,
-                                         CtIncludes])} | Conf1],
+ProcessErlOpt = fun({i, Path}) ->
+                       {i, ResolveDepPath(Path)};
+                  (ErlOpt) ->
+                       ErlOpt
+                end,
+
+Conf1a = ModCfg(Conf1, [erl_opts],
+                fun(ErlOpts) -> lists:map(ProcessErlOpt, ErlOpts) end, []),
+
+Conf2a = [{ct_extra_params, lists:flatten(["-ct_hooks cth_surefire ", TestConfig,
+                                         CtIncludes])} | Conf1a],
+
+Conf2 = case IsRebar3 of
+           true ->
+               DepsFun = fun(DepsList) ->
+                                 lists:filtermap(fun({rebar_elixir_plugin, _, _}) ->
+                                                         false;
+                                                    ({DepName,_, {git,_, _} = Git}) ->
+                                                         {true, {DepName, Git}};
+                                                    (Dep) ->
+                                                         true
+                                                 end, DepsList)
+                         end,
+               RB1 = ModCfg(Conf2a, [deps], DepsFun, []),
+               ModCfg(RB1, [plugins], fun(V) -> V -- [deps_erl_opts,
+                                                      rebar_elixir_compiler,
+                                                      rebar_exunit] ++
+                                                    [rebar3_hex] end, []);
+           false ->
+               Conf2a
+       end,
+
 
 Conf3 = case lists:keytake(xref_exclusions, 1, Conf2) of
             {value, {_, Items2}, Rest2} ->