plugin_dialyzer.mk 9.8 KB

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