4

I decided to setup lager in my Erlang project. I am using erlang.mk, so I added

ERLC_OPTS = +'{parse_transform, lager_transform}' 

to my Makefile. I can run make all and compile the modules without errors. I can also start an erl console and run the application containing the modules using lager. No errors are generated and lager logs messages during the console session. It seems as though everything is fine (this is the first time I have used lager). But, when I run Common Test, the lager calls fail:

10:11:17.174 [error] CRASH REPORT Process <0.238.0> with 2 neighbours exited with reason: call to undefined function lager:info("Params: ~p", [[]]) in gen_server:init_it/6 line 328

Since it appears as if the modules I am testing have been compile correctly, I assume this is an issue with lager module not being present. However, if I add this:

erlang:display(lager:module_info()),

above the first lager call it succeeds, printing the module info for lager. I assume the logging calls I am making are utilizing some parse transform magic in order to work and this is not present during my the Common Test runs.

Any suggestions are greatly appreciated!

Stratus3D
  • 4,648
  • 4
  • 35
  • 67
  • Solved! This was due to an error in my Makefile (not erlang.mk). I will add an answer when I get a moment. – Stratus3D Aug 27 '14 at 19:09

2 Answers2

3

Turns out I had a mispelling in my Makefile but I learned alot about erlang.mk in the process. erlang.mk was looking for a variable with a different name.

I originally this in my Makefile:

ERLC_OPTS = +'{parse_transform, lager_transform}'

But erlang.mk doesn't use ERLC_OPTS for compiling modules before testing them. It always recompiles before the Common Test suites. In order to have the modules compile with the parse transform for testing I needed to do this:

# Compile flags
ERLC_COMPILE_OPTS= +'{parse_transform, lager_transform}'

# Use the same settings for compiling releases as well as for testing
ERLC_OPTS= $(ERLC_COMPILE_OPTS)
TEST_ERLC_OPTS= $(ERLC_COMPILE_OPTS)

This makes sure that the application source code is compiled with the exact same settings during testing.

Stratus3D
  • 4,648
  • 4
  • 35
  • 67
  • 1
    I noticed that setting ERLC_OPTS like this in the Makefile before the 'include erlang.mk' line will shadow the ERLC_OPTS settings in erlang.mk itself, because it looks like this: ERLC_OPTS ?= ... – postfuturist Oct 22 '14 at 20:28
3

This is a slight reformation of Stratus3D answer that does not shadow erlang.mk's values for ERLC_OPTS and TEST_ERLC_OPTS, but adds to them:

# this must be first
include erlang.mk

# Compile flags
ERLC_COMPILE_OPTS= +'{parse_transform, lager_transform}'

# Append these settings
ERLC_OPTS += $(ERLC_COMPILE_OPTS)
TEST_ERLC_OPTS += $(ERLC_COMPILE_OPTS)
postfuturist
  • 22,211
  • 11
  • 65
  • 85