rebar.config.script 3.78 KB
Newer Older
1 2 3 4 5 6
%%%----------------------------------------------------------------------
%%% File    : rebar.config.script
%%% Author  : Mickael Remond <mremond@process-one.net>
%%% Purpose : Rebar build script. Compliant with rebar and rebar3.
%%% Created : 24 Nov 2015 by Mickael Remond <mremond@process-one.net>
%%%
7
%%% Copyright (C) 2002-2017 ProcessOne, SARL. All Rights Reserved.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%%     http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%
%%%----------------------------------------------------------------------

ModCfg0 = fun(F, Cfg, [Key|Tail], Op, Default) ->
                 {OldVal,PartCfg} = case lists:keytake(Key, 1, Cfg) of
                                        {value, {_, V1}, V2} -> {V1, V2};
                                        false -> {if Tail == [] -> Default; true -> [] end, Cfg}
                                    end,
                 case Tail of
                     [] ->
                         [{Key, Op(OldVal)} | PartCfg];
                     _ ->
                         [{Key, F(F, OldVal, Tail, Op, Default)} | PartCfg]
                 end
         end,
ModCfg = fun(Cfg, Keys, Op, Default) -> ModCfg0(ModCfg0, Cfg, Keys, Op, Default) end.

%% Rebar3 support for hex.pm support:
%% - Transform dependencies specification to use hex.pm packages:
%%   deps of the form: {Name, _Vsn, {git, _URL, {tag, Version}}}
%%     are expected to refer to package and are rewritten for rebar3 as:
%%   {Name, Version}
%% - Add rebar3_hex plugin
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,
Cfg2 = case IsRebar3 of
           true ->
               DepsFun = fun(DepsList) -> lists:map(fun({DepName,_, {git,_, {tag,Version}}}) ->
                                                            {DepName, Version};
                                                       (Dep) ->
                                                            Dep
                                                    end, DepsList)
                         end,
               RB1 = ModCfg(CONFIG, [deps], DepsFun, []),
               ModCfg(RB1, [plugins], fun(V) -> V ++ [rebar3_hex] end, []);
           false ->
               CONFIG
       end,

%% When running Travis test, upload test coverage result to coveralls:
Config = case os:getenv("TRAVIS") of
             "true" ->
                 JobId = os:getenv("TRAVIS_JOB_ID"),
                 Cfg3 = ModCfg(Cfg2, [deps], fun(V) -> [{coveralls, ".*", {git, "https://github.com/markusn/coveralls-erl.git", "master"}}|V] end, []),
70
                 ModCfg(Cfg3, [post_hooks], fun(V) -> V ++ [{eunit, "echo '\n%%! -pa .eunit/ deps/coveralls/ebin\nmain(_)->{ok,F}=file:open(\"erlang.json\",[write]),io:fwrite(F,\"~s\",[coveralls:convert_file(\".eunit/cover.coverdata\", \""++JobId++"\", \"travis-ci\",\"\")]).' > getcover.erl"},
71 72 73 74 75 76 77 78 79 80 81
                                                                   {eunit, "escript ./getcover.erl"}] end, []);
             _ ->
                 Cfg2
         end,

Config.

%% Local Variables:
%% mode: erlang
%% End:
%% vim: set filetype=erlang tabstop=8: