Makefile 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # Copyright (c) 2015-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # Copyright (c) 2014, Viktor Söderqvist <viktor@zuiderkwast.se>
  3. # This file is part of erlang.mk and subject to the terms of the ISC License.
  4. # ZSH users have a more modern shell which doesn't need to
  5. # have the same safeguards as other shells. To use ZSH instead
  6. # of the default shell, set ZSH=1.
  7. ifdef ZSH
  8. SHELL := $(shell which zsh)
  9. endif
  10. # Temporary application name, taken from rule name.
  11. APP = test_$(subst -,_,$@)
  12. # Erlang, quickly!
  13. ERL = erl +A0 -noinput -boot start_clean
  14. # Platform detection, condensed version.
  15. UNAME_S := $(shell uname -s)
  16. ifeq ($(UNAME_S),Darwin)
  17. PLATFORM = darwin
  18. else ifeq ($(UNAME_S),FreeBSD)
  19. PLATFORM = freebsd
  20. else ifeq ($(shell uname -o),Msys)
  21. PLATFORM = msys2
  22. else
  23. PLATFORM = unix
  24. endif
  25. # Some systems do not have sub-second file times resolution.
  26. # This is the case for older systems like OSX that uses the HFS+
  27. # file system. HFS+ has a 1 second time resolution. This is a
  28. # problem because the Erlang.mk tests rely on file modification
  29. # times to ensure files were rebuilt. To fix this issue, we
  30. # detect here whether the system supports sub-second resolution,
  31. # and maybe sleep during test execution.
  32. #
  33. # Also see:
  34. # * http://arstechnica.com/apple/2011/07/mac-os-x-10-7/12/#hfs-problems
  35. # * https://apple.stackexchange.com/questions/51650/linus-torvalds-and-the-os-x-filesystem
  36. ifeq ($(shell touch a; sleep 0.01; touch b; sleep 0.01; touch c; test c -nt b -a b -nt a; echo $$?; rm a b c),1)
  37. SLEEP = sleep 1
  38. else
  39. SLEEP =
  40. endif
  41. # OTP master, for downloading files for testing.
  42. OTP_MASTER = https://raw.githubusercontent.com/erlang/otp/master
  43. # Verbosity.
  44. #
  45. # V=0: Show info messages only.
  46. # V=1: Show test commands.
  47. # V=2: Also show normal Erlang.mk output.
  48. # V=3: Also show verbose Erlang.mk output.
  49. # V=4: Also show a trace of each command after expansion.
  50. V ?= 0
  51. # t: Verbosity control for tests.
  52. # v: Verbosity control for erlang.mk.
  53. # i: Command to display (or suppress) info messages.
  54. ifeq ($V,0)
  55. t = @
  56. v = V=0 >/dev/null 2>&1
  57. i = @echo $@:
  58. else ifeq ($V,1)
  59. t =
  60. v = V=0 >/dev/null 2>&1
  61. i = @echo == $@:
  62. else ifeq ($V,2)
  63. t = @echo " TEST " $@;
  64. v = V=0
  65. i = @echo == $@:
  66. else
  67. t =
  68. v = V=$(shell echo $$(($(V)-2)))
  69. i = @echo == $@:
  70. endif
  71. # Automatic listing of targets from test files.
  72. define list_targets
  73. $(sort $(shell grep ^$1- $(lastword $(MAKEFILE_LIST)) | cut -d: -f1))
  74. endef
  75. # Main targets.
  76. .PHONY: all clean init
  77. all:: core
  78. clean::
  79. $t rm -rf erl_crash.dump packages/ test_*/
  80. init: clean
  81. $i "Prefetch Rebar if necessary"
  82. $t if [ ! -d test_rebar_git ]; then \
  83. git clone -q -n -- https://github.com/rebar/rebar test_rebar_git; \
  84. fi
  85. $i "Generate a bleeding edge Erlang.mk"
  86. $t cd .. && $(MAKE) $v
  87. REBAR_GIT = file://$(CURDIR)/test_rebar_git
  88. export REBAR_GIT
  89. # Core.
  90. .PHONY: core
  91. define include_core
  92. core:: core-$1
  93. include core_$1.mk
  94. endef
  95. $(eval $(foreach t,$(patsubst %.mk,%,$(patsubst core_%,%,$(wildcard core_*.mk))),$(call include_core,$t)))
  96. # Plugins.
  97. define include_plugin
  98. all:: $1
  99. include plugin_$1.mk
  100. endef
  101. $(eval $(foreach t,$(patsubst %.mk,%,$(patsubst plugin_%,%,$(wildcard plugin_*.mk))),$(call include_plugin,$t)))
  102. # Packages.
  103. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
  104. EXCLUDE_FROM_CHECK = ['ci.erlang.mk', hexer_mk, inaka_mk, 'lfe.mk', rabbitmq_codegen]
  105. packages: $(addprefix pkg-,$(PACKAGES))
  106. define pkg_target
  107. .PHONY: pkg-$1
  108. pkg-$1: init
  109. # Make sure $@ is defined inside the define.
  110. $(eval @ = pkg-$1)
  111. # Get the real application's name.
  112. $(eval APP_NAME := $(shell sed '2!d;s/pkg_$1_name = //' ../index/$1.mk))
  113. $i "Bootstrap a new OTP library in packages/$1_pkg"
  114. $t mkdir -p packages/$1_pkg/
  115. $t cp ../erlang.mk packages/$1_pkg/
  116. $t cd packages/$1_pkg/ && $(MAKE) -f erlang.mk bootstrap-lib $v
  117. $i "Add package $1 to the Makefile"
  118. $t perl -ni.bak -e 'print;if ($$$$.==1) {print "DEPS = $1\n"}' packages/$1_pkg/Makefile
  119. $i "Compile package $1"
  120. $t if ! ( cd packages/$1_pkg/ && $(MAKE) $(PATCHES) $v ); then \
  121. echo "$1: compile error" >> packages/errors.log; \
  122. false; \
  123. fi
  124. $i "Check that $1 has a .app file"
  125. $t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
  126. echo "$1: no .app file" >> packages/errors.log; \
  127. false; \
  128. fi
  129. $i "Check that all applications and their modules can be loaded"
  130. $t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
  131. Apps0 = [list_to_atom(App) || \"deps/\" ++ App \
  132. <- filelib:wildcard(\"deps/*\")], \
  133. Apps = [App || App <- Apps0, not lists:member(App, $(EXCLUDE_FROM_CHECK))], \
  134. [begin \
  135. io:format(\"Loading application ~p~n\", [App]), \
  136. case application:load(App) of \
  137. ok -> ok; \
  138. {error, {already_loaded, App}} -> ok \
  139. end, \
  140. {ok, Mods} = application:get_key(App, modules), \
  141. [try io:format(\" Loading module ~p~n\", [Mod]), \
  142. {module, Mod} = code:load_file(Mod) \
  143. catch C:R -> timer:sleep(500), erlang:C(R) \
  144. end || Mod <- Mods] \
  145. end || App <- Apps], \
  146. halt()." ); then \
  147. echo "$1: load error" >> packages/errors.log; \
  148. false; \
  149. fi
  150. $i "Recompile package $1"
  151. $t if ! ( cd packages/$1_pkg/ && $(MAKE) $(PATCHES) FULL=1 $v ); then \
  152. echo "$(1): recompile error" >> packages/errors.log; \
  153. false; \
  154. fi
  155. $i "Check that $1 has a .app file"
  156. $t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
  157. echo "$1: no .app file" >> packages/errors.log; \
  158. false; \
  159. fi
  160. $i "Check that all applications and their modules can still be loaded"
  161. $t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
  162. Apps0 = [list_to_atom(App) || \"deps/\" ++ App \
  163. <- filelib:wildcard(\"deps/*\")], \
  164. Apps = [App || App <- Apps0, not lists:member(App, $(EXCLUDE_FROM_CHECK))], \
  165. [begin \
  166. io:format(\"Loading application ~p~n\", [App]), \
  167. case application:load(App) of \
  168. ok -> ok; \
  169. {error, {already_loaded, App}} -> ok \
  170. end, \
  171. {ok, Mods} = application:get_key(App, modules), \
  172. [try io:format(\" Loading module ~p~n\", [Mod]), \
  173. {module, Mod} = code:load_file(Mod) \
  174. catch C:R -> timer:sleep(500), erlang:C(R) \
  175. end || Mod <- Mods] \
  176. end || App <- Apps], \
  177. halt()." ); then \
  178. echo "$1: recompile+load error" >> packages/errors.log; \
  179. false; \
  180. fi
  181. $i "Check that no erl_crash.dump file exists"
  182. $t if ( ! find packages/$1_pkg/ -type f -name erl_crash.dump ); then \
  183. echo "$(1): erl_crash.dump found" >> packages/errors.log; \
  184. fi
  185. $(if $(KEEP_BUILDS),,
  186. $i "OK; delete the build directory"
  187. $t rm -rf packages/$1_pkg/)
  188. endef
  189. $(foreach pkg,$(PACKAGES),$(eval $(call pkg_target,$(pkg))))