core_compat.mk 7.9 KB

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