Skip to content

Instantly share code, notes, and snippets.

@dreid
Created August 11, 2011 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dreid/1139033 to your computer and use it in GitHub Desktop.
Save dreid/1139033 to your computer and use it in GitHub Desktop.
A second pass at making using dialyzer a little easier. This time as a Makefile.
##
## dialyzer.mk: Useful make targets for working with erlang's
## dialyzer. Manages a per-OTP version PLT which is then copied
## to your project directory and adds your dependencies to the
## plt. By default the OTP plt is stored in ~/.dialyzer so that
## it is used by all dialyzer.mk using projects. This can be
## changed with the PLT_BASE variable.
##
## Recommended usage is to add `include dialyzer.mk` to your
## projects Makefile.
##
## Author: David Reid <dreid@mochimedia.com>
##
DEPS_DIR=deps
PLT_BASE?=$(HOME)/.dialyzer
ERL=$(shell type -Pf erl)
ERL_LIB=$(shell dirname $(shell dirname ${ERL}))/lib/erlang/lib
OTP_VERSION=$(shell ${ERL} \
-noinput \
-noshell \
-eval 'io:fwrite(erlang:system_info(otp_release)).' \
-s init stop)
PLT_DIR=${PLT_BASE}/${OTP_VERSION}
OTP_PLT=${PLT_DIR}/otp_plt
DEPS_PLT=ebin/.deps_plt
DIALYZER_WARNINGS?=
OTP_APPS?=$(wildcard ${ERL_LIB}/*/ebin)
${PLT_DIR}:
@echo "Creating plt directory: ${PLT_DIR}"
@mkdir -p $@
${OTP_PLT}: ${PLT_DIR}
@echo "Generating OTP plt at ${OTP_PLT}"
@dialyzer --build_plt --output_plt $@ --apps $(OTP_APPS)
${DEPS_PLT}: ${OTP_PLT}
cp ${OTP_PLT} ${DEPS_PLT}
dialyzer --add_to_plt --plt ${DEPS_PLT} ${DEPS_DIR}/*/ebin
.PHONY: analyze
analyze: ${DEPS_PLT}
dialyzer --plt ${DEPS_PLT} $(DIALYZER_WARNINGS) -r src --src
@wardbekker
Copy link

Great, we use Kerl (https://github.com/spawngrid/kerl/tree/) for side by side Erlang installations, so this would be a good thing to add.

@dreid
Copy link
Author

dreid commented Aug 17, 2011

@wardbekker I'm not exactly sure what you mean by "add". This uses whatever erl is on your path, kerl changes the path so doing kerl activate R14B01 && make analyze should do the right thing.

@wardbekker
Copy link

Current plan of attack: To prevent re-building the plt for the standard erlang/otp applications, I'm going to pre-generate those for every Erlang version during Travis Virtual Machine provisioning. That way only the deps plt needs to be created on every build before running dialyzer.

@wardbekker
Copy link

dreid, what's the advantage of the --src switch in the analyze target?

@dreid
Copy link
Author

dreid commented Aug 21, 2011

@wardbekker Runs the analysis over the source, instead of the beam files. Basically lets you run the analysis without having to compile first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment