Browse Source

Fix and document Dialyzer against beam files

Loïc Hoguin 6 years ago
parent
commit
3acdef8ed9
3 changed files with 22 additions and 3 deletions
  1. 13 0
      doc/src/guide/dialyzer.asciidoc
  2. 1 1
      plugins/dialyzer.mk
  3. 8 2
      test/plugin_dialyzer.mk

+ 13 - 0
doc/src/guide/dialyzer.asciidoc

@@ -71,3 +71,16 @@ it doesn't exist. This is normally not necessary as
 Dialyzer creates it automatically.
 
 The PLT file will be removed when you run `make distclean`.
+
+=== Dialyzing beam files
+
+By default Erlang.mk will run Dialyzer against the source
+code. It is possible to configure Erlang.mk to use the
+compiled source files instead. This is done using the
+`DIALYZER_DIRS` variable:
+
+[source,make]
+DIALYZER_DIRS = -r ebin
+
+This value must be set before including Erlang.mk to
+function properly.

+ 1 - 1
plugins/dialyzer.mk

@@ -54,7 +54,7 @@ distclean-plt:
 	$(gen_verbose) rm -f $(DIALYZER_PLT)
 
 ifneq ($(wildcard $(DIALYZER_PLT)),)
-dialyze:
+dialyze: $(if $(filter --src,$(DIALYZER_DIRS)),,deps app)
 else
 dialyze: $(DIALYZER_PLT)
 endif

+ 8 - 2
test/plugin_dialyzer.mk

@@ -6,7 +6,7 @@ ifneq ($(shell which sem 2>/dev/null),)
 	DIALYZER_MUTEX = sem --fg --id dialyzer
 endif
 
-.PHONY: dialyzer $(C_SRC_TARGETS)
+.PHONY: dialyzer $(DIALYZER_TARGETS)
 
 dialyzer: $(DIALYZER_TARGETS)
 
@@ -109,7 +109,7 @@ dialyzer-beam: build clean
 	$t echo "ERLC_OPTS += +'{parse_transform, lager_transform}'" >> $(APP)/Makefile
 
 	$i "Make Dialyzer use the beam files"
-	$t echo "DIALYZER_DIRS = -r ebin" >> $(APP)/Makefile
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_DIRS = -r ebin\n"}' $(APP)/Makefile
 
 	$i "Create a module that calls lager"
 	$t printf "%s\n" \
@@ -120,6 +120,12 @@ dialyzer-beam: build clean
 	$i "Run Dialyzer"
 	$t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
 
+	$i "Clean the application"
+	$t $(MAKE) -C $(APP) clean $v
+
+	$i "Run Dialyzer again using the produced PLT file"
+	$t $(DIALYZER_MUTEX) $(MAKE) -C $(APP) dialyze $v
+
 dialyzer-check: build clean
 
 	$i "Bootstrap a new OTP application named $(APP)"