plugin_dialyzer.mk 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 $(C_SRC_TARGETS)
  7. dialyzer: $(DIALYZER_TARGETS)
  8. dialyzer-app: build clean
  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: build clean
  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: build clean
  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: build clean
  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 echo "DIALYZER_DIRS = -r ebin" >> $(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. dialyzer-check: build clean
  86. $i "Bootstrap a new OTP application named $(APP)"
  87. $t mkdir $(APP)/
  88. $t cp ../erlang.mk $(APP)/
  89. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  90. $i "Run 'make check'"
  91. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  92. $i "Check that the PLT file was created"
  93. $t test -f $(APP)/.$(APP).plt
  94. $i "Create a module with a function that has no local return"
  95. $t printf "%s\n" \
  96. "-module(warn_me)." \
  97. "doit() -> 1 = 2, ok." > $(APP)/src/warn_me.erl
  98. $i "Confirm that Dialyzer errors out on 'make check'"
  99. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  100. dialyzer-custom-plt: build clean
  101. $i "Bootstrap a new OTP application named $(APP)"
  102. $t mkdir $(APP)/
  103. $t cp ../erlang.mk $(APP)/
  104. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  105. $i "Set a custom DIALYZER_PLT location"
  106. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_PLT = custom.plt\n"}' $(APP)/Makefile
  107. $i "Run Dialyzer"
  108. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  109. $i "Check that the PLT file was created"
  110. $t test -f $(APP)/custom.plt
  111. $i "Distclean the application"
  112. $t $(MAKE) -C $(APP) distclean $v
  113. $i "Check that the PLT file was removed"
  114. $t test ! -e $(APP)/custom.plt
  115. dialyzer-deps: build clean
  116. $i "Bootstrap a new OTP application named $(APP)"
  117. $t mkdir $(APP)/
  118. $t cp ../erlang.mk $(APP)/
  119. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  120. $i "Add Cowlib to the list of dependencies"
  121. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/Makefile
  122. $i "Run Dialyzer"
  123. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  124. $i "Check that the PLT file was created"
  125. $t test -f $(APP)/.$(APP).plt
  126. $i "Confirm that Cowlib was included in the PLT"
  127. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  128. dialyzer-erlc-opts: build clean
  129. $i "Bootstrap a new OTP application named $(APP)"
  130. $t mkdir $(APP)/
  131. $t cp ../erlang.mk $(APP)/
  132. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  133. $i "Create a header file in a non-standard directory"
  134. $t mkdir $(APP)/exotic-include-path/
  135. $t touch $(APP)/exotic-include-path/dialyze.hrl
  136. $i "Create a module that includes this header"
  137. $t printf "%s\n" \
  138. "-module(no_warn)." \
  139. "-export([doit/0])." \
  140. "-include(\"dialyze.hrl\")." \
  141. "doit() -> ?OK." > $(APP)/src/no_warn.erl
  142. $i "Point ERLC_OPTS to the non-standard include directory"
  143. $t perl -ni.bak -e 'print;if ($$.==1) {print "ERLC_OPTS += -I exotic-include-path -DOK=ok\n"}' $(APP)/Makefile
  144. $i "Run Dialyzer"
  145. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  146. dialyzer-local-deps: build clean
  147. $i "Bootstrap a new OTP application named $(APP)"
  148. $t mkdir $(APP)/
  149. $t cp ../erlang.mk $(APP)/
  150. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  151. $i "Add runtime_tools to the list of local dependencies"
  152. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = runtime_tools\n"}' $(APP)/Makefile
  153. $i "Build the PLT"
  154. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  155. $i "Confirm that runtime_tools was included in the PLT"
  156. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools
  157. dialyzer-opts: build clean
  158. $i "Bootstrap a new OTP application named $(APP)"
  159. $t mkdir $(APP)/
  160. $t cp ../erlang.mk $(APP)/
  161. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  162. $i "Make Dialyzer save output to a file"
  163. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_OPTS = -o output.txt\n"}' $(APP)/Makefile
  164. $i "Create a module with a function that has no local return"
  165. $t printf "%s\n" \
  166. "-module(warn_me)." \
  167. "-export([doit/0])." \
  168. "doit() -> gen_tcp:connect(a, b, c), ok." > $(APP)/src/warn_me.erl
  169. $i "Run Dialyzer"
  170. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  171. $i "Check that the PLT file was created"
  172. $t test -f $(APP)/.$(APP).plt
  173. $i "Check that the output file was created"
  174. $t test -f $(APP)/output.txt
  175. dialyzer-plt-apps: build clean
  176. $i "Bootstrap a new OTP application named $(APP)"
  177. $t mkdir $(APP)/
  178. $t cp ../erlang.mk $(APP)/
  179. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  180. $i "Add runtime_tools to PLT_APPS"
  181. $t perl -ni.bak -e 'print;if ($$.==1) {print "PLT_APPS = runtime_tools\n"}' $(APP)/Makefile
  182. $i "Build the PLT"
  183. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  184. $i "Confirm that runtime_tools was included in the PLT"
  185. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools
  186. dialyzer-plt-ebin-only: build clean
  187. $i "Bootstrap a new OTP application named $(APP)"
  188. $t mkdir $(APP)/
  189. $t cp ../erlang.mk $(APP)/
  190. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  191. $i "Add Cowlib to the list of dependencies"
  192. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\ndep_cowlib_commit = master\n"}' $(APP)/Makefile
  193. $i "Build the application"
  194. $t $(MAKE) -C $(APP) $v
  195. $i "Run Cowlib tests to fetch autopatched dependencies"
  196. $t $(MAKE) -C $(APP)/deps/cowlib tests $v
  197. $i "Run Dialyzer"
  198. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  199. $i "Check that the PLT file was created"
  200. $t test -f $(APP)/.$(APP).plt
  201. $i "Confirm that Cowlib was included in the PLT"
  202. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  203. $i "Confirm that rebar files were not included in the PLT"
  204. $t ! dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q rebar
  205. dialyzer-plt-swallow-warnings: build clean
  206. $i "Bootstrap a new OTP application named $(APP)"
  207. $t mkdir $(APP)/
  208. $t cp ../erlang.mk $(APP)/
  209. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  210. $i "Add LFE version referring to a missing function to the list of dependencies"
  211. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = lfe\ndep_lfe_commit = 2880c8a2a7f\n"}' $(APP)/Makefile
  212. $i "Create the PLT file"
  213. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v