plugin_dialyzer.mk 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. # Dialyzer plugin.
  2. DIALYZER_CASES = app apps-only apps-with-local-deps beam check custom-plt deps erlc-opts local-deps opts plt-apps
  3. DIALYZER_TARGETS = $(addprefix dialyzer-,$(DIALYZER_CASES))
  4. ifneq ($(shell which sem 2>/dev/null),)
  5. DIALYZER_MUTEX = sem --fg --id dialyzer
  6. endif
  7. .PHONY: dialyzer $(C_SRC_TARGETS)
  8. dialyzer: $(DIALYZER_TARGETS)
  9. dialyzer-app: build clean
  10. $i "Bootstrap a new OTP application named $(APP)"
  11. $t mkdir $(APP)/
  12. $t cp ../erlang.mk $(APP)/
  13. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  14. $i "Run Dialyzer"
  15. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  16. $i "Check that the PLT file was created"
  17. $t test -f $(APP)/.$(APP).plt
  18. $i "Create a module with a function that has no local return"
  19. $t printf "%s\n" \
  20. "-module(warn_me)." \
  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: build clean
  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. "doit() -> 1 = 2, ok." > $(APP)/apps/my_app/src/warn_me.erl
  49. $i "Confirm that Dialyzer errors out"
  50. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  51. dialyzer-apps-with-local-deps: build clean
  52. $i "Create a multi application repository with no root application"
  53. $t mkdir $(APP)/
  54. $t cp ../erlang.mk $(APP)/
  55. $t echo "include erlang.mk" > $(APP)/Makefile
  56. $i "Create a new application my_app"
  57. $t $(MAKE) -C $(APP) new-app in=my_app $v
  58. $i "Create a new application my_core_app"
  59. $t $(MAKE) -C $(APP) new-app in=my_core_app $v
  60. $i "Add my_core_app to the list of local dependencies for my_app"
  61. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = my_core_app\n"}' $(APP)/apps/my_app/Makefile
  62. $i "Run Dialyzer"
  63. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  64. $i "Check that the PLT file was created automatically"
  65. $t test -f $(APP)/.$(APP).plt
  66. $i "Confirm that my_core_app was NOT included in the PLT"
  67. $t ! dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q my_core_app
  68. dialyzer-beam: build clean
  69. $i "Bootstrap a new OTP application named $(APP)"
  70. $t mkdir $(APP)/
  71. $t cp ../erlang.mk $(APP)/
  72. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  73. $i "Add lager to the list of dependencies"
  74. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = lager\n"}' $(APP)/Makefile
  75. $i "Add lager_transform to ERLC_OPTS"
  76. $t echo "ERLC_OPTS += +'{parse_transform, lager_transform}'" >> $(APP)/Makefile
  77. $i "Make Dialyzer use the beam files"
  78. $t echo "DIALYZER_DIRS = -r ebin" >> $(APP)/Makefile
  79. $i "Create a module that calls lager"
  80. $t printf "%s\n" \
  81. "-module(use_lager)." \
  82. "-export([doit/0])." \
  83. "doit() -> lager:error(\"Some message\")." > $(APP)/src/use_lager.erl
  84. $i "Build the application"
  85. $t $(MAKE) -C $(APP) $v
  86. $i "Run Dialyzer"
  87. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  88. dialyzer-check: build clean
  89. $i "Bootstrap a new OTP application named $(APP)"
  90. $t mkdir $(APP)/
  91. $t cp ../erlang.mk $(APP)/
  92. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  93. $i "Run 'make check'"
  94. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  95. $i "Check that the PLT file was created"
  96. $t test -f $(APP)/.$(APP).plt
  97. $i "Create a module with a function that has no local return"
  98. $t printf "%s\n" \
  99. "-module(warn_me)." \
  100. "doit() -> 1 = 2, ok." > $(APP)/src/warn_me.erl
  101. $i "Confirm that Dialyzer errors out on 'make check'"
  102. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  103. dialyzer-custom-plt: build clean
  104. $i "Bootstrap a new OTP application named $(APP)"
  105. $t mkdir $(APP)/
  106. $t cp ../erlang.mk $(APP)/
  107. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  108. $i "Set a custom DIALYZER_PLT location"
  109. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_PLT = custom.plt\n"}' $(APP)/Makefile
  110. $i "Run Dialyzer"
  111. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  112. $i "Check that the PLT file was created"
  113. $t test -f $(APP)/custom.plt
  114. $i "Distclean the application"
  115. $t $(MAKE) -C $(APP) distclean $v
  116. $i "Check that the PLT file was removed"
  117. $t test ! -e $(APP)/custom.plt
  118. dialyzer-deps: build clean
  119. $i "Bootstrap a new OTP application named $(APP)"
  120. $t mkdir $(APP)/
  121. $t cp ../erlang.mk $(APP)/
  122. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  123. $i "Add Cowlib to the list of dependencies"
  124. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/Makefile
  125. $i "Run Dialyzer"
  126. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  127. $i "Check that the PLT file was created"
  128. $t test -f $(APP)/.$(APP).plt
  129. $i "Confirm that Cowlib was included in the PLT"
  130. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  131. dialyzer-erlc-opts: build clean
  132. $i "Bootstrap a new OTP application named $(APP)"
  133. $t mkdir $(APP)/
  134. $t cp ../erlang.mk $(APP)/
  135. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  136. $i "Create a header file in a non-standard directory"
  137. $t mkdir $(APP)/exotic/
  138. $t touch $(APP)/exotic/dialyze.hrl
  139. $i "Create a module that includes this header"
  140. $t printf "%s\n" \
  141. "-module(no_warn)." \
  142. "-export([doit/0])." \
  143. "-include(\"dialyze.hrl\")." \
  144. "doit() -> ok." > $(APP)/src/no_warn.erl
  145. $i "Point ERLC_OPTS to the non-standard include directory"
  146. $t perl -ni.bak -e 'print;if ($$.==1) {print "ERLC_OPTS += -I exotic\n"}' $(APP)/Makefile
  147. $i "Run Dialyzer"
  148. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  149. dialyzer-local-deps: build clean
  150. $i "Bootstrap a new OTP application named $(APP)"
  151. $t mkdir $(APP)/
  152. $t cp ../erlang.mk $(APP)/
  153. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  154. $i "Add runtime_tools to the list of local dependencies"
  155. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = runtime_tools\n"}' $(APP)/Makefile
  156. $i "Build the PLT"
  157. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  158. $i "Confirm that runtime_tools was included in the PLT"
  159. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools
  160. dialyzer-opts: build clean
  161. $i "Bootstrap a new OTP application named $(APP)"
  162. $t mkdir $(APP)/
  163. $t cp ../erlang.mk $(APP)/
  164. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  165. $i "Make Dialyzer save output to a file"
  166. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_OPTS = -o output.txt\n"}' $(APP)/Makefile
  167. $i "Create a module with a function that has no local return"
  168. $t printf "%s\n" \
  169. "-module(warn_me)." \
  170. "-export([doit/0])." \
  171. "doit() -> gen_tcp:connect(a, b, c), ok." > $(APP)/src/warn_me.erl
  172. $i "Run Dialyzer"
  173. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  174. $i "Check that the PLT file was created"
  175. $t test -f $(APP)/.$(APP).plt
  176. $i "Check that the output file was created"
  177. $t test -f $(APP)/output.txt
  178. dialyzer-plt-apps: build clean
  179. $i "Bootstrap a new OTP application named $(APP)"
  180. $t mkdir $(APP)/
  181. $t cp ../erlang.mk $(APP)/
  182. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  183. $i "Add runtime_tools to PLT_APPS"
  184. $t perl -ni.bak -e 'print;if ($$.==1) {print "PLT_APPS = runtime_tools\n"}' $(APP)/Makefile
  185. $i "Build the PLT"
  186. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  187. $i "Confirm that runtime_tools was included in the PLT"
  188. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools