core_compat.mk 7.7 KB

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