plugin_dialyzer.mk 7.1 KB

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