plugin_dialyzer.mk 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "Run Dialyzer"
  85. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  86. dialyzer-check: build clean
  87. $i "Bootstrap a new OTP application named $(APP)"
  88. $t mkdir $(APP)/
  89. $t cp ../erlang.mk $(APP)/
  90. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  91. $i "Run 'make check'"
  92. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  93. $i "Check that the PLT file was created"
  94. $t test -f $(APP)/.$(APP).plt
  95. $i "Create a module with a function that has no local return"
  96. $t printf "%s\n" \
  97. "-module(warn_me)." \
  98. "doit() -> 1 = 2, ok." > $(APP)/src/warn_me.erl
  99. $i "Confirm that Dialyzer errors out on 'make check'"
  100. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) check $v
  101. dialyzer-custom-plt: build clean
  102. $i "Bootstrap a new OTP application named $(APP)"
  103. $t mkdir $(APP)/
  104. $t cp ../erlang.mk $(APP)/
  105. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  106. $i "Set a custom DIALYZER_PLT location"
  107. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_PLT = custom.plt\n"}' $(APP)/Makefile
  108. $i "Run Dialyzer"
  109. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  110. $i "Check that the PLT file was created"
  111. $t test -f $(APP)/custom.plt
  112. $i "Distclean the application"
  113. $t $(MAKE) -C $(APP) distclean $v
  114. $i "Check that the PLT file was removed"
  115. $t test ! -e $(APP)/custom.plt
  116. dialyzer-deps: build clean
  117. $i "Bootstrap a new OTP application named $(APP)"
  118. $t mkdir $(APP)/
  119. $t cp ../erlang.mk $(APP)/
  120. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  121. $i "Add Cowlib to the list of dependencies"
  122. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/Makefile
  123. $i "Run Dialyzer"
  124. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  125. $i "Check that the PLT file was created"
  126. $t test -f $(APP)/.$(APP).plt
  127. $i "Confirm that Cowlib was included in the PLT"
  128. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  129. dialyzer-erlc-opts: build clean
  130. $i "Bootstrap a new OTP application named $(APP)"
  131. $t mkdir $(APP)/
  132. $t cp ../erlang.mk $(APP)/
  133. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  134. $i "Create a header file in a non-standard directory"
  135. $t mkdir $(APP)/exotic/
  136. $t touch $(APP)/exotic/dialyze.hrl
  137. $i "Create a module that includes this header"
  138. $t printf "%s\n" \
  139. "-module(no_warn)." \
  140. "-export([doit/0])." \
  141. "-include(\"dialyze.hrl\")." \
  142. "doit() -> ok." > $(APP)/src/no_warn.erl
  143. $i "Point ERLC_OPTS to the non-standard include directory"
  144. $t perl -ni.bak -e 'print;if ($$.==1) {print "ERLC_OPTS += -I exotic\n"}' $(APP)/Makefile
  145. $i "Run Dialyzer"
  146. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  147. dialyzer-local-deps: build clean
  148. $i "Bootstrap a new OTP application named $(APP)"
  149. $t mkdir $(APP)/
  150. $t cp ../erlang.mk $(APP)/
  151. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  152. $i "Add runtime_tools to the list of local dependencies"
  153. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = runtime_tools\n"}' $(APP)/Makefile
  154. $i "Build the PLT"
  155. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  156. $i "Confirm that runtime_tools was included in the PLT"
  157. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools
  158. dialyzer-opts: build clean
  159. $i "Bootstrap a new OTP application named $(APP)"
  160. $t mkdir $(APP)/
  161. $t cp ../erlang.mk $(APP)/
  162. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  163. $i "Make Dialyzer save output to a file"
  164. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_OPTS = -o output.txt\n"}' $(APP)/Makefile
  165. $i "Create a module with a function that has no local return"
  166. $t printf "%s\n" \
  167. "-module(warn_me)." \
  168. "-export([doit/0])." \
  169. "doit() -> gen_tcp:connect(a, b, c), ok." > $(APP)/src/warn_me.erl
  170. $i "Run Dialyzer"
  171. $t ! $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
  172. $i "Check that the PLT file was created"
  173. $t test -f $(APP)/.$(APP).plt
  174. $i "Check that the output file was created"
  175. $t test -f $(APP)/output.txt
  176. dialyzer-plt-apps: build clean
  177. $i "Bootstrap a new OTP application named $(APP)"
  178. $t mkdir $(APP)/
  179. $t cp ../erlang.mk $(APP)/
  180. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  181. $i "Add runtime_tools to PLT_APPS"
  182. $t perl -ni.bak -e 'print;if ($$.==1) {print "PLT_APPS = runtime_tools\n"}' $(APP)/Makefile
  183. $i "Build the PLT"
  184. $t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) plt $v
  185. $i "Confirm that runtime_tools was included in the PLT"
  186. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools