core_compat.mk 8.0 KB

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