dialyzer.mk 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (c) 2013-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: plt distclean-plt dialyze
  4. # Configuration.
  5. DIALYZER_PLT ?= $(CURDIR)/.$(PROJECT).plt
  6. export DIALYZER_PLT
  7. PLT_APPS ?=
  8. DIALYZER_DIRS ?= --src -r $(wildcard src) $(ALL_APPS_DIRS)
  9. DIALYZER_OPTS ?= -Werror_handling -Wunmatched_returns # -Wunderspecs
  10. DIALYZER_PLT_OPTS ?=
  11. # Core targets.
  12. check:: dialyze
  13. distclean:: distclean-plt
  14. help::
  15. $(verbose) printf "%s\n" "" \
  16. "Dialyzer targets:" \
  17. " plt Build a PLT file for this project" \
  18. " dialyze Analyze the project using Dialyzer"
  19. # Plugin-specific targets.
  20. define filter_opts.erl
  21. Opts = init:get_plain_arguments(),
  22. {Filtered, _} = lists:foldl(fun
  23. (O, {Os, true}) -> {[O|Os], false};
  24. (O = "-D", {Os, _}) -> {[O|Os], true};
  25. (O = [\\$$-, \\$$D, _ | _], {Os, _}) -> {[O|Os], false};
  26. (O = "-I", {Os, _}) -> {[O|Os], true};
  27. (O = [\\$$-, \\$$I, _ | _], {Os, _}) -> {[O|Os], false};
  28. (O = "-pa", {Os, _}) -> {[O|Os], true};
  29. (_, Acc) -> Acc
  30. end, {[], false}, Opts),
  31. io:format("~s~n", [string:join(lists:reverse(Filtered), " ")]),
  32. halt().
  33. endef
  34. # DIALYZER_PLT is a variable understood directly by Dialyzer.
  35. #
  36. # We append the path to erts at the end of the PLT. This works
  37. # because the PLT file is in the external term format and the
  38. # function binary_to_term/1 ignores any trailing data.
  39. $(DIALYZER_PLT): deps app
  40. $(eval DEPS_LOG := $(shell test -f $(ERLANG_MK_TMP)/deps.log && \
  41. while read p; do test -d $$p/ebin && echo $$p/ebin; done <$(ERLANG_MK_TMP)/deps.log))
  42. $(verbose) dialyzer --build_plt $(DIALYZER_PLT_OPTS) --apps \
  43. erts kernel stdlib $(PLT_APPS) $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS_LOG) || test $$? -eq 2
  44. $(verbose) $(ERL) -eval 'io:format("~n~s~n", [code:lib_dir(erts)]), halt().' >> $@
  45. plt: $(DIALYZER_PLT)
  46. distclean-plt:
  47. $(gen_verbose) rm -f $(DIALYZER_PLT)
  48. ifneq ($(wildcard $(DIALYZER_PLT)),)
  49. dialyze: $(if $(filter --src,$(DIALYZER_DIRS)),,deps app)
  50. $(verbose) if ! tail -n1 $(DIALYZER_PLT) | \
  51. grep -q "^`$(ERL) -eval 'io:format("~s", [code:lib_dir(erts)]), halt().'`$$"; then \
  52. rm $(DIALYZER_PLT); \
  53. $(MAKE) plt; \
  54. fi
  55. else
  56. dialyze: $(DIALYZER_PLT)
  57. endif
  58. $(verbose) dialyzer --no_native `$(ERL) \
  59. -eval "$(subst $(newline),,$(call escape_dquotes,$(call filter_opts.erl)))" \
  60. -extra $(ERLC_OPTS)` $(DIALYZER_DIRS) $(DIALYZER_OPTS) $(if $(wildcard ebin/),-pa ebin/)