dialyzer.mk 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 -Wrace_conditions -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): deps app
  35. $(eval DEPS_LOG := $(shell test -f $(ERLANG_MK_TMP)/deps.log && \
  36. while read p; do test -d $$p/ebin && echo $$p/ebin; done <$(ERLANG_MK_TMP)/deps.log))
  37. $(verbose) dialyzer --build_plt $(DIALYZER_PLT_OPTS) --apps \
  38. erts kernel stdlib $(PLT_APPS) $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS_LOG) || test $$? -eq 2
  39. plt: $(DIALYZER_PLT)
  40. distclean-plt:
  41. $(gen_verbose) rm -f $(DIALYZER_PLT)
  42. ifneq ($(wildcard $(DIALYZER_PLT)),)
  43. dialyze:
  44. else
  45. dialyze: $(DIALYZER_PLT)
  46. endif
  47. $(verbose) dialyzer --no_native `$(ERL) -eval "$(subst $(newline),,$(call escape_dquotes,$(call filter_opts.erl)))" -extra $(ERLC_OPTS)` $(DIALYZER_DIRS) $(DIALYZER_OPTS)