rebar.config.script 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.202"}}}.
  24. Dialyzer = fun(Config) ->
  25. {dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config),
  26. {plt_extra_apps, OldExtra} = lists:keyfind(plt_extra_apps, 1, OldDialyzerConfig),
  27. Extra = OldExtra ++ [quicer || IsQuicSupp()],
  28. NewDialyzerConfig = [{plt_extra_apps, Extra} | OldDialyzerConfig],
  29. lists:keystore(
  30. dialyzer,
  31. 1,
  32. Config,
  33. {dialyzer, NewDialyzerConfig}
  34. )
  35. end.
  36. ExtraDeps = fun(C) ->
  37. {deps, Deps0} = lists:keyfind(deps, 1, C),
  38. {erl_opts, ErlOpts0} = lists:keyfind(erl_opts, 1, C),
  39. IsQuic = IsQuicSupp(),
  40. New = [
  41. {deps, Deps0 ++ [Bcrypt || not IsWin32()] ++ [Quicer || IsQuic]},
  42. {erl_opts, ErlOpts0 ++ [{d, 'BUILD_WITHOUT_QUIC'} || not IsQuic]}
  43. ],
  44. lists:foldl(
  45. fun({Key, _Val} = KV, Acc) ->
  46. lists:keystore(Key, 1, Acc, KV)
  47. end,
  48. C,
  49. New
  50. )
  51. end,
  52. Dialyzer(ExtraDeps(CONFIG)).