core_compat.mk 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. # Core: Compatibility with other build tools.
  2. #
  3. # Note: autopatch functionality is covered separately.
  4. CORE_COMPAT_TARGETS = $(call list_targets,core-compat)
  5. REBAR_BINARY = https://github.com/rebar/rebar/releases/download/2.6.0/rebar
  6. REBAR3_BINARY = https://s3.amazonaws.com/rebar3/rebar3
  7. .PHONY: core-compat $(CORE_COMPAT_TARGETS)
  8. core-compat: $(CORE_COMPAT_TARGETS)
  9. core-compat-auto-rebar: init
  10. $i "Bootstrap a new OTP library named $(APP)"
  11. $t mkdir $(APP)/
  12. $t cp ../erlang.mk $(APP)/
  13. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  14. $i "Add rebar.config as a dependency of 'app' target"
  15. $t echo "app:: rebar.config" >> $(APP)/Makefile
  16. $i "Build the application"
  17. $t $(MAKE) -C $(APP) $v
  18. $i "Check that rebar.config was created"
  19. $t test -f $(APP)/rebar.config
  20. $i "Check that rebar.config can be loaded"
  21. $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
  22. $i "Create a temporary file"
  23. $t touch $(APP)/older_file
  24. $t $(SLEEP)
  25. $i "Build the application again"
  26. $t $(MAKE) -C $(APP) $v
  27. $i "Check that rebar.config is newer than the temporary file"
  28. $t test $(APP)/rebar.config -nt $(APP)/older_file
  29. $i "Check that rebar.config can be loaded"
  30. $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
  31. $i "Distclean the application"
  32. $t $(MAKE) -C $(APP) distclean $v
  33. $i "Download rebar"
  34. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  35. $t chmod +x $(APP)/rebar
  36. $i "Use rebar to build the application"
  37. $t cd $(APP) && ./rebar compile $v
  38. core-compat-rebar: init
  39. $i "Bootstrap a new OTP library named $(APP)"
  40. $t mkdir $(APP)/
  41. $t cp ../erlang.mk $(APP)/
  42. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  43. $i "Run 'make rebar.config'"
  44. $t $(MAKE) -C $(APP) rebar.config $v
  45. $i "Check that rebar.config was created"
  46. $t test -f $(APP)/rebar.config
  47. $i "Check that rebar.config can be loaded"
  48. $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
  49. $i "Create a temporary file"
  50. $t touch $(APP)/older_file
  51. $t $(SLEEP)
  52. $i "Run 'make rebar.config' again"
  53. $t $(MAKE) -C $(APP) rebar.config $v
  54. $i "Check that rebar.config is newer than the temporary file"
  55. $t test $(APP)/rebar.config -nt $(APP)/older_file
  56. $i "Check that rebar.config can be loaded"
  57. $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
  58. $i "Distclean the application"
  59. $t $(MAKE) -C $(APP) distclean $v
  60. $i "Download rebar"
  61. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  62. $t chmod +x $(APP)/rebar
  63. $i "Use rebar to build the application"
  64. $t cd $(APP) && ./rebar compile $v
  65. core-compat-rebar-deps-git: init
  66. $i "Bootstrap a new OTP library named $(APP)"
  67. $t mkdir $(APP)/
  68. $t cp ../erlang.mk $(APP)/
  69. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  70. $i "Add Cowboy as a dependency"
  71. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\ndep_cowboy = git https://github.com/ninenines/cowboy 1.0.0\n"}' $(APP)/Makefile
  72. $i "Run 'make rebar.config'"
  73. $t $(MAKE) -C $(APP) rebar.config $v
  74. $i "Check that rebar.config was created"
  75. $t test -f $(APP)/rebar.config
  76. $i "Check that Cowboy is listed in rebar.config"
  77. $t $(ERL) -eval " \
  78. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  79. {_, [{cowboy, _, {git, _, \"1.0.0\"}}]} = lists:keyfind(deps, 1, C), \
  80. halt()"
  81. $i "Distclean the application"
  82. $t $(MAKE) -C $(APP) distclean $v
  83. $i "Download rebar"
  84. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  85. $t chmod +x $(APP)/rebar
  86. $i "Use rebar to build the application"
  87. $t cd $(APP) && ./rebar get-deps compile $v
  88. core-compat-rebar-deps-hex: init
  89. $i "Bootstrap a new OTP library named $(APP)"
  90. $t mkdir $(APP)/
  91. $t cp ../erlang.mk $(APP)/
  92. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  93. $i "Add Cowboy as a dependency"
  94. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\ndep_cowboy = hex 1.0.0\n"}' $(APP)/Makefile
  95. $i "Run 'make rebar.config'"
  96. $t $(MAKE) -C $(APP) rebar.config $v
  97. $i "Check that rebar.config was created"
  98. $t test -f $(APP)/rebar.config
  99. $i "Check that Cowboy is listed in rebar.config"
  100. $t $(ERL) -eval " \
  101. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  102. {_, [{cowboy, \"1.0.0\"}]} = lists:keyfind(deps, 1, C), \
  103. halt()"
  104. $i "Distclean the application"
  105. $t $(MAKE) -C $(APP) distclean $v
  106. $i "Download rebar3"
  107. $t curl -s -L -o $(APP)/rebar3 $(REBAR3_BINARY)
  108. $t chmod +x $(APP)/rebar3
  109. $i "Use rebar to build the application"
  110. $t cd $(APP) && ./rebar3 compile $v
  111. core-compat-rebar-deps-pkg: init
  112. $i "Bootstrap a new OTP library named $(APP)"
  113. $t mkdir $(APP)/
  114. $t cp ../erlang.mk $(APP)/
  115. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  116. $i "Add Cowboy package as a dependency"
  117. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\n"}' $(APP)/Makefile
  118. $i "Run 'make rebar.config'"
  119. $t $(MAKE) -C $(APP) rebar.config $v
  120. $i "Check that rebar.config was created"
  121. $t test -f $(APP)/rebar.config
  122. $i "Check that Cowboy is listed in rebar.config"
  123. $t $(ERL) -eval " \
  124. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  125. {_, [{cowboy, _, {git, \"https://github.com/\" ++ _, _}}]} = lists:keyfind(deps, 1, C), \
  126. halt()"
  127. $i "Distclean the application"
  128. $t $(MAKE) -C $(APP) distclean $v
  129. $i "Download rebar"
  130. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  131. $t chmod +x $(APP)/rebar
  132. $i "Use rebar to build the application"
  133. $t cd $(APP) && ./rebar get-deps compile $v
  134. core-compat-rebar-erlc-opts: init
  135. $i "Bootstrap a new OTP library named $(APP)"
  136. $t mkdir $(APP)/
  137. $t cp ../erlang.mk $(APP)/
  138. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  139. $i "Add extra options to ERLC_OPTS"
  140. $t echo "ERLC_OPTS += +warn_export_all +warn_missing_spec +warn_untyped_record" >> $(APP)/Makefile
  141. $i "Run 'make rebar.config'"
  142. $t $(MAKE) -C $(APP) rebar.config $v
  143. $i "Check that rebar.config was created"
  144. $t test -f $(APP)/rebar.config
  145. $i "Check that -Werror is not listed in rebar.config"
  146. $t $(ERL) -eval " \
  147. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  148. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  149. false = lists:member(warning_as_errors, Opts), \
  150. halt()"
  151. $i "Check that debug_info is listed in rebar.config"
  152. $t $(ERL) -eval " \
  153. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  154. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  155. true = lists:member(debug_info, Opts), \
  156. halt()"
  157. $i "Check that extra options are listed in rebar.config"
  158. $t $(ERL) -eval " \
  159. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  160. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  161. true = lists:member(warn_export_all, Opts), \
  162. true = lists:member(warn_missing_spec, Opts), \
  163. true = lists:member(warn_untyped_record, Opts), \
  164. halt()"
  165. $i "Distclean the application"
  166. $t $(MAKE) -C $(APP) distclean $v
  167. $i "Download rebar"
  168. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  169. $t chmod +x $(APP)/rebar
  170. $i "Use rebar to build the application"
  171. $t cd $(APP) && ./rebar compile $v
  172. core-compat-rebar-pt: init
  173. $i "Bootstrap a new OTP library named $(APP)"
  174. $t mkdir $(APP)/
  175. $t cp ../erlang.mk $(APP)/
  176. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  177. $i "Generate .erl files"
  178. $t echo "-module(boy)." > $(APP)/src/boy.erl
  179. $t echo "-module(girl)." > $(APP)/src/girl.erl
  180. $i "Add lager to the list of dependencies"
  181. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = lager\n"}' $(APP)/Makefile
  182. $i "Add the lager_transform parse_transform to ERLC_OPTS"
  183. $t echo "ERLC_OPTS += +'{parse_transform, lager_transform}' +'{lager_truncation_size, 1234}'" >> $(APP)/Makefile
  184. $i "Build the application"
  185. $t $(MAKE) -C $(APP) $v
  186. $i "Run 'make rebar.config'"
  187. $t $(MAKE) -C $(APP) rebar.config $v
  188. $i "Check that rebar.config was created"
  189. $t test -f $(APP)/rebar.config
  190. $i "Check that the parse_transform option is listed in rebar.config"
  191. $t $(ERL) -eval " \
  192. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  193. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  194. true = lists:member({parse_transform, lager_transform}, Opts), \
  195. true = lists:member({lager_truncation_size, 1234}, Opts), \
  196. halt()"
  197. # For the new build method, we have to simulate keeping the .app file
  198. # inside the repository, by leaving it in the ebin/ directory before
  199. # calling Rebar.
  200. ifndef LEGACY
  201. $i "Move the .app file outside ebin/"
  202. $t mv $(APP)/ebin/$(APP).app $(APP)/
  203. endif
  204. $i "Distclean the application"
  205. $t $(MAKE) -C $(APP) distclean $v
  206. ifndef LEGACY
  207. $i "Put the .app file back into ebin/"
  208. $t mkdir $(APP)/ebin/
  209. $t mv $(APP)/$(APP).app $(APP)/ebin/
  210. endif
  211. $i "Download rebar"
  212. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  213. $t chmod +x $(APP)/rebar
  214. $i "Use rebar to build the application"
  215. $t cd $(APP) && ./rebar get-deps compile $v
  216. $i "Check that all compiled files exist"
  217. $t test -f $(APP)/ebin/$(APP).app
  218. $t test -f $(APP)/ebin/boy.beam
  219. $t test -f $(APP)/ebin/girl.beam