You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB

  1. % This file is part of Jiffy released under the MIT license.
  2. % See the LICENSE file for more information.
  3. % Only include PropEr as a dependency when the JIFFY_DEV
  4. % environment variable is defined. This allows downstream
  5. % applications to avoid requiring PropEr.
  6. %
  7. % This script is based on the example provided with Rebar.
  8. IsRebar3 = erlang:function_exported(rebar3, main, 1),
  9. PropErUrl = "git://github.com/manopapad/proper.git",
  10. IsDevEnv = begin
  11. ConfigPath = filename:dirname(SCRIPT),
  12. DevMarker = filename:join([ConfigPath, ".jiffy.dev"]),
  13. filelib:is_file(DevMarker)
  14. end.
  15. Deps = if not IsDevEnv -> []; true ->
  16. [{proper, ".*", {git, PropErUrl, {branch, "master"}}}]
  17. end,
  18. ErlOpts = if not IsDevEnv -> []; true ->
  19. [{d, 'JIFFY_DEV'}]
  20. end,
  21. Plugins = case IsRebar3 of
  22. true -> [pc];
  23. false -> [rebar_gdb_plugin]
  24. end,
  25. ProviderHooks = if not IsRebar3 -> []; true ->
  26. [{pre, [
  27. {compile, {pc, compile}},
  28. {clean, {pc, clean}}
  29. ]}]
  30. end,
  31. OptsToAdd = [
  32. {deps, Deps},
  33. {erl_opts, ErlOpts},
  34. {plugins, Plugins},
  35. {provider_hooks, ProviderHooks}
  36. ],
  37. AddOpt = fun(Name, Value, Config) when is_list(Value) ->
  38. case lists:keyfind(Name, 1, Config) of
  39. {Name, CurrVal} when is_list(CurrVal) ->
  40. lists:keyreplace(Name, 1, Config, {Name, CurrVal ++ Value});
  41. false ->
  42. Config ++ [{Name, Value}];
  43. _ ->
  44. Config
  45. end
  46. end,
  47. lists:foldl(fun({Name, Value}, CfgAcc) ->
  48. AddOpt(Name, Value, CfgAcc)
  49. end, CONFIG, OptsToAdd).