core_compat.mk 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\ndep_cowboy = git https://github.com/ninenines/cowboy 1.0.0\n"}' $(APP)/Makefile
  76. $i "Run 'make rebar.config'"
  77. $t $(MAKE) -C $(APP) rebar.config $v
  78. $i "Check that rebar.config was created"
  79. $t test -f $(APP)/rebar.config
  80. $i "Check that Cowboy is listed in rebar.config"
  81. $t $(ERL) -eval " \
  82. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  83. {_, [{cowboy, _, {git, _, \"1.0.0\"}}]} = lists:keyfind(deps, 1, C), \
  84. halt()"
  85. $i "Distclean the application"
  86. $t $(MAKE) -C $(APP) distclean $v
  87. $i "Download rebar"
  88. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  89. $t chmod +x $(APP)/rebar
  90. $i "Use rebar to build the application"
  91. $t cd $(APP) && ./rebar get-deps compile $v
  92. core-compat-rebar-deps-pkg: build clean-core-compat-rebar-deps-pkg
  93. $i "Bootstrap a new OTP library named $(APP)"
  94. $t mkdir $(APP)/
  95. $t cp ../erlang.mk $(APP)/
  96. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  97. $i "Add Cowboy package as a dependency"
  98. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\n"}' $(APP)/Makefile
  99. $i "Run 'make rebar.config'"
  100. $t $(MAKE) -C $(APP) rebar.config $v
  101. $i "Check that rebar.config was created"
  102. $t test -f $(APP)/rebar.config
  103. $i "Check that Cowboy is listed in rebar.config"
  104. $t $(ERL) -eval " \
  105. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  106. {_, [{cowboy, _, {git, \"https://github.com/\" ++ _, _}}]} = lists:keyfind(deps, 1, C), \
  107. halt()"
  108. $i "Distclean the application"
  109. $t $(MAKE) -C $(APP) distclean $v
  110. $i "Download rebar"
  111. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  112. $t chmod +x $(APP)/rebar
  113. $i "Use rebar to build the application"
  114. $t cd $(APP) && ./rebar get-deps compile $v
  115. core-compat-rebar-erlc-opts: build clean-core-compat-rebar-erlc-opts
  116. $i "Bootstrap a new OTP library named $(APP)"
  117. $t mkdir $(APP)/
  118. $t cp ../erlang.mk $(APP)/
  119. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  120. $i "Add extra options to ERLC_OPTS"
  121. $t echo "ERLC_OPTS += +warn_export_all +warn_missing_spec +warn_untyped_record" >> $(APP)/Makefile
  122. $i "Run 'make rebar.config'"
  123. $t $(MAKE) -C $(APP) rebar.config $v
  124. $i "Check that rebar.config was created"
  125. $t test -f $(APP)/rebar.config
  126. $i "Check that -Werror is not listed in rebar.config"
  127. $t $(ERL) -eval " \
  128. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  129. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  130. false = lists:member(warning_as_errors, Opts), \
  131. halt()"
  132. $i "Check that debug_info is listed in rebar.config"
  133. $t $(ERL) -eval " \
  134. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  135. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  136. true = lists:member(debug_info, Opts), \
  137. halt()"
  138. $i "Check that extra options are listed in rebar.config"
  139. $t $(ERL) -eval " \
  140. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  141. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  142. true = lists:member(warn_export_all, Opts), \
  143. true = lists:member(warn_missing_spec, Opts), \
  144. true = lists:member(warn_untyped_record, Opts), \
  145. halt()"
  146. $i "Distclean the application"
  147. $t $(MAKE) -C $(APP) distclean $v
  148. $i "Download rebar"
  149. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  150. $t chmod +x $(APP)/rebar
  151. $i "Use rebar to build the application"
  152. $t cd $(APP) && ./rebar compile $v
  153. core-compat-rebar-pt: build clean-core-compat-rebar-pt
  154. $i "Bootstrap a new OTP library named $(APP)"
  155. $t mkdir $(APP)/
  156. $t cp ../erlang.mk $(APP)/
  157. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  158. $i "Generate .erl files"
  159. $t echo "-module(boy)." > $(APP)/src/boy.erl
  160. $t echo "-module(girl)." > $(APP)/src/girl.erl
  161. $i "Add lager to the list of dependencies"
  162. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = lager\n"}' $(APP)/Makefile
  163. $i "Add the lager_transform parse_transform to ERLC_OPTS"
  164. $t echo "ERLC_OPTS += +'{parse_transform, lager_transform}'" >> $(APP)/Makefile
  165. $i "Build the application"
  166. $t $(MAKE) -C $(APP) $v
  167. $i "Run 'make rebar.config'"
  168. $t $(MAKE) -C $(APP) rebar.config $v
  169. $i "Check that rebar.config was created"
  170. $t test -f $(APP)/rebar.config
  171. $i "Check that the parse_transform option is listed in rebar.config"
  172. $t $(ERL) -eval " \
  173. {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
  174. {_, Opts} = lists:keyfind(erl_opts, 1, C), \
  175. true = lists:member({parse_transform, lager_transform}, Opts), \
  176. halt()"
  177. # For the new build method, we have to simulate keeping the .app file
  178. # inside the repository, by leaving it in the ebin/ directory before
  179. # calling Rebar.
  180. ifndef LEGACY
  181. $i "Move the .app file outside ebin/"
  182. $t mv $(APP)/ebin/$(APP).app $(APP)/
  183. endif
  184. $i "Distclean the application"
  185. $t $(MAKE) -C $(APP) distclean $v
  186. ifndef LEGACY
  187. $i "Put the .app file back into ebin/"
  188. $t mkdir $(APP)/ebin/
  189. $t mv $(APP)/$(APP).app $(APP)/ebin/
  190. endif
  191. $i "Download rebar"
  192. $t curl -s -L -o $(APP)/rebar $(REBAR_BINARY)
  193. $t chmod +x $(APP)/rebar
  194. $i "Use rebar to build the application"
  195. $t cd $(APP) && ./rebar get-deps compile $v
  196. $i "Check that all compiled files exist"
  197. $t test -f $(APP)/ebin/$(APP).app
  198. $t test -f $(APP)/ebin/boy.beam
  199. $t test -f $(APP)/ebin/girl.beam