rebar.config.script 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. %% -*- mode: erlang -*-
  2. %% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
  3. %% ex: ts=4 sw=4 ft=erlang et
  4. %% rebar.config.script GENERATED BY concrete
  5. %%
  6. %% YOU SHOULDN'T NEED TO EDIT THIS FILE
  7. %%
  8. {concrete_rebar_script_version, 3}.
  9. %% We need the following helper function to merge dev only options
  10. %% into the values provided by rebar.config.
  11. %% Merge the list values in `ToAdd' into the list found at key `Key'
  12. %% in proplist `C'. Don't duplicate items. New Items are added to the
  13. %% front of existing items. It is an error if the value at `Key' is
  14. %% not a list in `C'.
  15. MergeConfig = fun(skip, C) ->
  16. C;
  17. ({Key, ToAdd}, C) ->
  18. case lists:keyfind(Key, 1, C) of
  19. false ->
  20. lists:keystore(Key, 1, C, {Key, ToAdd});
  21. {Key, List} when is_list(List) ->
  22. %% remove items in ToAdd already in List
  23. ToAdd1 = [ I || I <- ToAdd, not lists:member(I, List) ],
  24. lists:keystore(Key, 1, C, {Key, List ++ ToAdd1 })
  25. end
  26. end,
  27. %% -- Add development only options if we are a top-level build --
  28. %%
  29. %% If a file named `.concrete/DEV_MODE' exists, we assume we are a
  30. %% top-level build (not being built as a dep of another project). We
  31. %% add the deps from dev_only_deps defined in rebar.config, add
  32. %% concrete as a dep, and define the compiler macro DEV_ONLY.
  33. %% This macro can be used to conditionally enable code (e.g. tests)
  34. %% that depend on development only dependencies.
  35. ErlOpts = {erl_opts, [{d, 'DEV_ONLY'}]},
  36. %% Development only dependencies can be specified in the main
  37. %% rebar.config. This file should not need to be edited directly.
  38. DevOnlyDeps = case lists:keyfind(dev_only_deps, 1, CONFIG) of
  39. false ->
  40. skip;
  41. {dev_only_deps, DOD} ->
  42. {deps, DOD}
  43. end,
  44. EDown = case proplists:get_value(use_edown, CONFIG) of
  45. false ->
  46. skip;
  47. _ ->
  48. DocOpts = case lists:keymember(edoc_opts, 1, CONFIG) of
  49. true ->
  50. skip;
  51. false ->
  52. {edoc_opts, [{doclet, edown_doclet}]}
  53. end,
  54. [DocOpts,
  55. {deps,
  56. [{edown, ".*",
  57. {git, "git://github.com/seth/edown.git",
  58. {branch, "master"}}}]}]
  59. end,
  60. LockDeps = case proplists:get_value(use_lock_deps, CONFIG) of
  61. false ->
  62. skip;
  63. V ->
  64. Tag = case V of
  65. {_, _} = T -> T;
  66. _ -> {branch, "master"}
  67. end,
  68. [{deps,
  69. [{rebar_lock_deps_plugin, ".*",
  70. {git, "git://github.com/seth/rebar_lock_deps_plugin.git",
  71. Tag}}]},
  72. {plugins, [rebar_lock_deps_plugin]}]
  73. end,
  74. ConfigPath = filename:dirname(SCRIPT),
  75. DevMarker = filename:join([ConfigPath, ".concrete/DEV_MODE"]),
  76. case filelib:is_file(DevMarker) of
  77. true ->
  78. ToMerge = lists:flatten([DevOnlyDeps, LockDeps, EDown, ErlOpts]),
  79. lists:foldl(fun(I, C) -> MergeConfig(I, C) end,
  80. CONFIG, ToMerge);
  81. false ->
  82. %% If the .concrete/ marker is not present, this script simply
  83. %% returns the config specified in rebar.config. This will be
  84. %% the behavior when the project is built as a dependency of
  85. %% another project.
  86. CONFIG
  87. end.