plugin_dialyzer.mk 7.4 KB

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