Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 build
  77. all:: core
  78. clean::
  79. $t rm -rf erl_crash.dump packages/ test_*/
  80. build:
  81. $i "Generate a bleeding edge Erlang.mk"
  82. $t cd .. && $(MAKE) $v
  83. # Core.
  84. .PHONY: core
  85. define include_core
  86. core:: core-$1
  87. include core_$1.mk
  88. endef
  89. $(eval $(foreach t,$(patsubst %.mk,%,$(patsubst core_%,%,$(wildcard core_*.mk))),$(call include_core,$t)))
  90. # Plugins.
  91. define include_plugin
  92. all:: $1
  93. include plugin_$1.mk
  94. endef
  95. $(eval $(foreach t,$(patsubst %.mk,%,$(patsubst plugin_%,%,$(wildcard plugin_*.mk))),$(call include_plugin,$t)))
  96. # Packages.
  97. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
  98. EXCLUDE_FROM_CHECK = ['ci.erlang.mk', hexer_mk, inaka_mk, rabbitmq_codegen]
  99. packages: $(addprefix pkg-,$(PACKAGES))
  100. define pkg_target
  101. .PHONY: pkg-$1
  102. pkg-$1: build clean
  103. # Make sure $@ is defined inside the define.
  104. $(eval @ = pkg-$1)
  105. # Get the real application's name.
  106. $(eval APP_NAME := $(shell sed '2!d;s/pkg_$1_name = //' ../index/$1.mk))
  107. $i "Bootstrap a new OTP library in packages/$1_pkg"
  108. $t mkdir -p packages/$1_pkg/
  109. $t cp ../erlang.mk packages/$1_pkg/
  110. $t cd packages/$1_pkg/ && $(MAKE) -f erlang.mk bootstrap-lib $v
  111. $i "Add package $1 to the Makefile"
  112. $t perl -ni.bak -e 'print;if ($$$$.==1) {print "DEPS = $1\n"}' packages/$1_pkg/Makefile
  113. $i "Compile package $1"
  114. $t if ! ( cd packages/$1_pkg/ && $(MAKE) $(PATCHES) $v ); then \
  115. echo "$1: compile error" >> packages/errors.log; \
  116. false; \
  117. fi
  118. $i "Check that $1 has a .app file"
  119. $t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
  120. echo "$1: no .app file" >> packages/errors.log; \
  121. false; \
  122. fi
  123. $i "Check that all applications and their modules can be loaded"
  124. $t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
  125. Apps0 = [list_to_atom(App) || \"deps/\" ++ App \
  126. <- filelib:wildcard(\"deps/*\")], \
  127. Apps = [App || App <- Apps0, not lists:member(App, $(EXCLUDE_FROM_CHECK))], \
  128. [begin \
  129. io:format(\"Loading application ~p~n\", [App]), \
  130. case application:load(App) of \
  131. ok -> ok; \
  132. {error, {already_loaded, App}} -> ok \
  133. end, \
  134. {ok, Mods} = application:get_key(App, modules), \
  135. [try io:format(\" Loading module ~p~n\", [Mod]), \
  136. {module, Mod} = code:load_file(Mod) \
  137. catch C:R -> timer:sleep(500), erlang:C(R) \
  138. end || Mod <- Mods] \
  139. end || App <- Apps], \
  140. halt()." ); then \
  141. echo "$1: load error" >> packages/errors.log; \
  142. false; \
  143. fi
  144. $i "Recompile package $1"
  145. $t if ! ( cd packages/$1_pkg/ && $(MAKE) $(PATCHES) $v ); then \
  146. echo "$(1): recompile error" >> packages/errors.log; \
  147. false; \
  148. fi
  149. $i "Check that $1 has a .app file"
  150. $t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
  151. echo "$1: no .app file" >> packages/errors.log; \
  152. false; \
  153. fi
  154. $i "Check that all applications and their modules can still be loaded"
  155. $t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
  156. Apps0 = [list_to_atom(App) || \"deps/\" ++ App \
  157. <- filelib:wildcard(\"deps/*\")], \
  158. Apps = [App || App <- Apps0, not lists:member(App, $(EXCLUDE_FROM_CHECK))], \
  159. [begin \
  160. io:format(\"Loading application ~p~n\", [App]), \
  161. case application:load(App) of \
  162. ok -> ok; \
  163. {error, {already_loaded, App}} -> ok \
  164. end, \
  165. {ok, Mods} = application:get_key(App, modules), \
  166. [try io:format(\" Loading module ~p~n\", [Mod]), \
  167. {module, Mod} = code:load_file(Mod) \
  168. catch C:R -> timer:sleep(500), erlang:C(R) \
  169. end || Mod <- Mods] \
  170. end || App <- Apps], \
  171. halt()." ); then \
  172. echo "$1: recompile+load error" >> packages/errors.log; \
  173. false; \
  174. fi
  175. $i "Check that no erl_crash.dump file exists"
  176. $t if ( ! find packages/$1_pkg/ -type f -name erl_crash.dump ); then \
  177. echo "$(1): erl_crash.dump found" >> packages/errors.log; \
  178. fi
  179. $(if $(KEEP_BUILDS),,
  180. $i "OK; delete the build directory"
  181. $t rm -rf packages/$1_pkg/)
  182. endef
  183. $(foreach pkg,$(PACKAGES),$(eval $(call pkg_target,$(pkg))))