rebar.config.script 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. %% -*- mode: erlang -*-
  2. IsCentos6 = fun() ->
  3. case file:read_file("/etc/centos-release") of
  4. {ok, <<"CentOS release 6", _/binary>>} ->
  5. true;
  6. _ ->
  7. false
  8. end
  9. end,
  10. IsWin32 = fun() ->
  11. win32 =:= element(1, os:type())
  12. end,
  13. IsMacOS = fun() ->
  14. {unix, darwin} =:= os:type()
  15. end,
  16. IsQuicSupp = fun() ->
  17. not (IsCentos6() orelse IsWin32() orelse
  18. IsMacOS() orelse
  19. false =/= os:getenv("BUILD_WITHOUT_QUIC")) orelse
  20. "1" == os:getenv("BUILD_WITH_QUIC")
  21. end,
  22. Bcrypt = {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {tag, "0.6.0"}}},
  23. Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.313"}}}.
  24. Dialyzer = fun(Config) ->
  25. {dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config),
  26. Extra = [quicer || IsQuicSupp()],
  27. NewDialyzerConfig = [{plt_extra_apps, Extra} | OldDialyzerConfig],
  28. lists:keystore(
  29. dialyzer,
  30. 1,
  31. Config,
  32. {dialyzer, NewDialyzerConfig}
  33. )
  34. end.
  35. ExtraDeps = fun(C) ->
  36. {deps, Deps0} = lists:keyfind(deps, 1, C),
  37. {erl_opts, ErlOpts0} = lists:keyfind(erl_opts, 1, C),
  38. IsQuic = IsQuicSupp(),
  39. New = [
  40. {deps, Deps0 ++ [Bcrypt || not IsWin32()] ++ [Quicer || IsQuic]},
  41. {erl_opts, ErlOpts0 ++ [{d, 'BUILD_WITHOUT_QUIC'} || not IsQuic]}
  42. ],
  43. lists:foldl(
  44. fun({Key, _Val} = KV, Acc) ->
  45. lists:keystore(Key, 1, Acc, KV)
  46. end,
  47. C,
  48. New
  49. )
  50. end,
  51. Dialyzer(ExtraDeps(CONFIG)).