plugin_dialyzer.mk 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. # Dialyzer plugin.
  2. DIALYZER_TARGETS = $(call list_targets,dialyzer)
  3. ifneq ($(shell which sem 2>/dev/null),)
  4. DIALYZER_MUTEX = sem --fg --id dialyzer
  5. endif
  6. .PHONY: dialyzer $(DIALYZER_TARGETS)
  7. dialyzer: $(DIALYZER_TARGETS)
  8. dialyzer-app: init
  9. $i "Bootstrap a new OTP application named $(APP)"
  10. $t mkdir $(APP)/
  11. $t cp ../erlang.mk $(APP)/
  12. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  13. $i "Run Dialyzer"
  14. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  15. $i "Check that the PLT file was created"
  16. $t test -f $(APP)/.$(APP).plt
  17. $i "Create a module with a function that has no local return"
  18. $t printf "%s\n" \
  19. "-module(warn_me)." \
  20. "-export([doit/0])." \
  21. "doit() -> 1 = 2, ok." > $(APP)/src/warn_me.erl
  22. $i "Confirm that Dialyzer errors out"
  23. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  24. $i "Distclean the application"
  25. $t $(MAKE) -C $(APP) distclean $v
  26. $i "Check that the PLT file was removed"
  27. $t test ! -e $(APP)/.$(APP).plt
  28. dialyzer-apps-only: init
  29. $i "Create a multi application repository with no root application"
  30. $t mkdir $(APP)/
  31. $t cp ../erlang.mk $(APP)/
  32. $t echo "include erlang.mk" > $(APP)/Makefile
  33. $i "Create a new application my_app"
  34. $t $(MAKE) -C $(APP) new-app in=my_app $v
  35. $i "Create a module my_server from gen_server template in my_app"
  36. $t $(MAKE) -C $(APP) new t=gen_server n=my_server in=my_app $v
  37. $i "Add Cowlib to the list of dependencies"
  38. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/apps/my_app/Makefile
  39. $i "Run Dialyzer"
  40. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  41. $i "Check that the PLT file was created automatically"
  42. $t test -f $(APP)/.$(APP).plt
  43. $i "Confirm that Cowlib was included in the PLT"
  44. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  45. $i "Create a module with a function that has no local return"
  46. $t printf "%s\n" \
  47. "-module(warn_me)." \
  48. "-export([doit/0])." \
  49. "doit() -> 1 = 2, ok." > $(APP)/apps/my_app/src/warn_me.erl
  50. $i "Confirm that Dialyzer errors out"
  51. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  52. dialyzer-apps-with-local-deps: init
  53. $i "Create a multi application repository with no root application"
  54. $t mkdir $(APP)/
  55. $t cp ../erlang.mk $(APP)/
  56. $t echo "include erlang.mk" > $(APP)/Makefile
  57. $i "Create a new application my_app"
  58. $t $(MAKE) -C $(APP) new-app in=my_app $v
  59. $i "Create a new application my_core_app"
  60. $t $(MAKE) -C $(APP) new-app in=my_core_app $v
  61. $i "Add my_core_app to the list of local dependencies for my_app"
  62. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = my_core_app\n"}' $(APP)/apps/my_app/Makefile
  63. $i "Run Dialyzer"
  64. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  65. $i "Check that the PLT file was created automatically"
  66. $t test -f $(APP)/.$(APP).plt
  67. $i "Confirm that my_core_app was NOT included in the PLT"
  68. $t ! dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q my_core_app
  69. dialyzer-beam: init
  70. $i "Bootstrap a new OTP application named $(APP)"
  71. $t mkdir $(APP)/
  72. $t cp ../erlang.mk $(APP)/
  73. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  74. $i "Add lager to the list of dependencies"
  75. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = lager\n"}' $(APP)/Makefile
  76. $i "Add lager_transform to ERLC_OPTS"
  77. $t echo "ERLC_OPTS += +'{parse_transform, lager_transform}'" >> $(APP)/Makefile
  78. $i "Make Dialyzer use the beam files"
  79. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_DIRS = -r ebin\n"}' $(APP)/Makefile
  80. $i "Create a module that calls lager"
  81. $t printf "%s\n" \
  82. "-module(use_lager)." \
  83. "-export([doit/0])." \
  84. "doit() -> lager:error(\"Some message\")." > $(APP)/src/use_lager.erl
  85. $i "Run Dialyzer"
  86. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  87. $i "Clean the application"
  88. $t $(MAKE) -C $(APP) clean $v
  89. $i "Run Dialyzer again using the produced PLT file"
  90. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  91. dialyzer-check: init
  92. $i "Bootstrap a new OTP application named $(APP)"
  93. $t mkdir $(APP)/
  94. $t cp ../erlang.mk $(APP)/
  95. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  96. $i "Run 'make check'"
  97. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  98. $i "Check that the PLT file was created"
  99. $t test -f $(APP)/.$(APP).plt
  100. $i "Create a module with a function that has no local return"
  101. $t printf "%s\n" \
  102. "-module(warn_me)." \
  103. "-export([doit/0])." \
  104. "doit() -> 1 = 2, ok." > $(APP)/src/warn_me.erl
  105. $i "Confirm that Dialyzer errors out on 'make check'"
  106. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  107. dialyzer-custom-plt: init
  108. $i "Bootstrap a new OTP application named $(APP)"
  109. $t mkdir $(APP)/
  110. $t cp ../erlang.mk $(APP)/
  111. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  112. $i "Set a custom DIALYZER_PLT location"
  113. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_PLT = custom.plt\n"}' $(APP)/Makefile
  114. $i "Run Dialyzer"
  115. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  116. $i "Check that the PLT file was created"
  117. $t test -f $(APP)/custom.plt
  118. $i "Distclean the application"
  119. $t $(MAKE) -C $(APP) distclean $v
  120. $i "Check that the PLT file was removed"
  121. $t test ! -e $(APP)/custom.plt
  122. dialyzer-deps: init
  123. $i "Bootstrap a new OTP application named $(APP)"
  124. $t mkdir $(APP)/
  125. $t cp ../erlang.mk $(APP)/
  126. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  127. $i "Add Cowlib to the list of dependencies"
  128. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/Makefile
  129. $i "Run Dialyzer"
  130. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  131. $i "Check that the PLT file was created"
  132. $t test -f $(APP)/.$(APP).plt
  133. $i "Confirm that Cowlib was included in the PLT"
  134. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  135. dialyzer-erlc-opts: init
  136. $i "Bootstrap a new OTP application named $(APP)"
  137. $t mkdir $(APP)/
  138. $t cp ../erlang.mk $(APP)/
  139. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  140. $i "Create a header file in a non-standard directory"
  141. $t mkdir $(APP)/exotic-include-path/
  142. $t touch $(APP)/exotic-include-path/dialyze.hrl
  143. $i "Create a module that includes this header"
  144. $t printf "%s\n" \
  145. "-module(no_warn)." \
  146. "-export([doit/0])." \
  147. "-include(\"dialyze.hrl\")." \
  148. "doit() -> ?OK." > $(APP)/src/no_warn.erl
  149. $i "Point ERLC_OPTS to the non-standard include directory"
  150. $t perl -ni.bak -e 'print;if ($$.==1) {print "ERLC_OPTS += -I exotic-include-path -DOK=ok\n"}' $(APP)/Makefile
  151. $i "Run Dialyzer"
  152. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  153. dialyzer-local-deps: init
  154. $i "Bootstrap a new OTP application named $(APP)"
  155. $t mkdir $(APP)/
  156. $t cp ../erlang.mk $(APP)/
  157. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  158. $i "Add runtime_tools to the list of local dependencies"
  159. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = runtime_tools\n"}' $(APP)/Makefile
  160. $i "Build the PLT"
  161. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  162. $i "Confirm that runtime_tools was included in the PLT"
  163. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools
  164. dialyzer-opts: init
  165. $i "Bootstrap a new OTP application named $(APP)"
  166. $t mkdir $(APP)/
  167. $t cp ../erlang.mk $(APP)/
  168. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  169. $i "Make Dialyzer save output to a file"
  170. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_OPTS = -o output.txt\n"}' $(APP)/Makefile
  171. $i "Create a module with a function that has no local return"
  172. $t printf "%s\n" \
  173. "-module(warn_me)." \
  174. "-export([doit/0])." \
  175. "doit() -> gen_tcp:connect(a, b, c), ok." > $(APP)/src/warn_me.erl
  176. $i "Run Dialyzer"
  177. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  178. $i "Check that the PLT file was created"
  179. $t test -f $(APP)/.$(APP).plt
  180. $i "Check that the output file was created"
  181. $t test -f $(APP)/output.txt
  182. dialyzer-plt-apps: init
  183. $i "Bootstrap a new OTP application named $(APP)"
  184. $t mkdir $(APP)/
  185. $t cp ../erlang.mk $(APP)/
  186. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  187. $i "Add runtime_tools to PLT_APPS"
  188. $t perl -ni.bak -e 'print;if ($$.==1) {print "PLT_APPS = runtime_tools\n"}' $(APP)/Makefile
  189. $i "Build the PLT"
  190. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  191. $i "Confirm that runtime_tools was included in the PLT"
  192. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools
  193. dialyzer-plt-ebin-only: init
  194. $i "Bootstrap a new OTP application named $(APP)"
  195. $t mkdir $(APP)/
  196. $t cp ../erlang.mk $(APP)/
  197. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  198. $i "Add Cowlib to the list of dependencies"
  199. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\ndep_cowlib_commit = master\n"}' $(APP)/Makefile
  200. $i "Build the application"
  201. $t $(MAKE) -C $(APP) $v
  202. $i "Build Cowlib for tests to fetch autopatched dependencies"
  203. $t $(MAKE) -C $(APP)/deps/cowlib test-build $v
  204. $i "Run Dialyzer"
  205. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  206. $i "Check that the PLT file was created"
  207. $t test -f $(APP)/.$(APP).plt
  208. $i "Confirm that Cowlib was included in the PLT"
  209. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  210. $i "Confirm that rebar files were not included in the PLT"
  211. $t ! dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q rebar
  212. dialyzer-plt-swallow-warnings: init
  213. $i "Bootstrap a new OTP application named $(APP)"
  214. $t mkdir $(APP)/
  215. $t cp ../erlang.mk $(APP)/
  216. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  217. $i "Add LFE version referring to a missing function to the list of dependencies"
  218. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = lfe\ndep_lfe_commit = d656987dc5f5e08306531ad1ce13bf9ca9ec9e5a\n"}' $(APP)/Makefile
  219. $i "Create the PLT file"
  220. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  221. dialyzer-pt: init
  222. $i "Bootstrap a new OTP library named $(APP)"
  223. $t mkdir $(APP)/
  224. $t cp ../erlang.mk $(APP)/
  225. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  226. $i "Generate a parse_transform module"
  227. $t printf "%s\n" \
  228. "-module(my_pt)." \
  229. "-export([parse_transform/2])." \
  230. "parse_transform(Forms, _) ->" \
  231. " io:format(\"# Running my_pt parse_transform.~n\")," \
  232. " Forms." > $(APP)/src/my_pt.erl
  233. $i "Generate a .erl file that uses the my_pt parse_transform"
  234. $t printf "%s\n" \
  235. "-module(my_user)." \
  236. "-compile({parse_transform, my_pt})." > $(APP)/src/my_user.erl
  237. $i "Run Dialyzer"
  238. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v