core_compat.mk 8.6 KB

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