core_compat.mk 8.7 KB

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