Including lager in an erlang.mk project - erlang

I'm trying to add lager to a simple erlang.mk project. I understand lager uses parse transforms, so you have to set compile flags accordingly; so following advice from here:
Lager calls failing during Common Test test runs
my Makefile looks as follows:
PROJECT = hello_erlang_mk
DEPS = cowboy lager
# 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)
The release builds fine but somehow lager never seems to be included:
Eshell V5.10.4 (abort with ^G)
(hello_erlang_mk#127.0.0.1)1> lager:info("~s is ~s!", [lager, cool]).
** exception error: undefined function lager:info/2
Anyone have any pointers on how to get lager working within an erlang.mk project ?
[I'm using Erlang R16B03, Ubuntu 14.04]
Thanks.

I believe there is nothing to do with erlang.mk. The problem is -- you try to call lager:info from the shell. But actually there is no such function in the lager module. lager:info is just a command for parse transform that is unfolded to some other (more complex) constructions during compilation time.
If you want to check if you application contains lager, you can try from shell lager:status() for example (which is 'honest' function in the lager module). Or lager:module_info().

Forgive me. Noob error. application:start(lager). Sorry.

Related

Rebar eunit runs non native (non Hipe) code

I have compiled my Erlang module using
rebar compile
using the following option in rebar.config
{erl_opts, [native, {hipe, [verbose]}, warnings_as_errors, debug_info]}.
{eunit_compile_opts, [native, {hipe, [verbose]}, warnings_as_errors, debug_info]}.
I see that the code is indeed compiled to native since I see Hipe messages during compilation and the .beam file size are also larger than non-native compilation.
However when I run
rebar eunit
which tests my module I always get false for
code:is_module_native(?MODULE)
within my module under test.
Why does rebar not run my eunit test as native code?
I have additionally added this line to the reltool.config file,
{app, hipe, [{incl_cond, include}]},
rebar 2.1.0-pre 17 20140421_192321 git 2.1.0-pre-166-ged88055
Your code is recompiled when you run "rebar eunit" using the compile options defined by
{erl_opts, [native, {hipe, [verbose]}, warnings_as_errors, debug_info]}.
and modified by the compile options defined by
{eunit_compile_opts, [???]}.
Did you check these options?

Command 'rebar doc' is inconsistent

First of all, 'rebar doc' works sometimes and sometimes not. It is strange.
Rebar version which I'm using is 2.5.1
My folder structure is:
Header_Directory
1.1 apps
1.1.1 sub_dir_1
1.1.2 sub_dir_2 / include
1.1.3 sub_dir_3
1.2 deps
1.3 confs
rebar.config
Modules in sub_dir_3 also use some include files from sub_dir_2/include folder.
The error I get when I use the command rebar doc is:
.sub_dir_3/src/my_log_worker.erl, in module header: at line 9: file
not found: some.hrl edoc: skipping source file
'sub_dir_3/src/my_log_worker.erl': {'EXIT',error}. edoc: error in
doclet 'edoc_doclet': {'EXIT',error}. ERROR: doc failed while
processing /home/learn/header_directory/apps/sub_dir_3: {'EXIT',error}
I do 'rebar clean' and then 'rebar compile' prior to 'rebar doc'
Also,when I do it in erl shell, I get error.
edoc:file("some_log_worker.erl", []).
edoc: error reading file 'some_log_worker.erl'.
** exception exit: {error,enoent}
in function edoc:read_source/2 (edoc.erl, line 664)
in call from edoc_extract:source/3 (edoc_extract.erl, line 52)
in call from edoc:read/2 (edoc.erl, line 537)
in call from edoc:file/2 (edoc.erl, line 116)
Is there any way by which I can include my hrl file either in rebar.config or edoc options?
I have '{edoc_opts, [{ i, "apps/sub_dir_3/include" }]}.' in rebar.config, still of no help.
It looks like you didn't follow the rebar/OTP conventions:
OTP Conventions
Rebar expects projects to follow the OTP conventions as described in
the OTP Design Principles document: Applications
An application should consists of the following set of directories:
src
ebin
priv
include
and have an application resource file: ebin/example_project.app or
src/example_project.app.src. In the later case, the
ebin/example_project.app file is generated from the
src/example_project.app.src one automatically during the compilation
phase.
Rebar & OTP convetions
I recommend you to move to that file organisation, it will be really much simpler to benefit from standard tools like rebar.
Yes, it is always in the best interest to follow the OTP principles. However, it worked for my app structure.
The only problem was because of #headerfile annotation in the erlang modules. Somehow, I don't know how to correctly use the #headerfile annotation.
Thanks for all the help. :)

Chicagoboss make error for lager

I am porting my web application developed in Chicagoboss from my mac to ubuntu. But when I run make on ubuntu I get the following error:
ERROR: pre_compile failed while processing /home/myname/myapp_priv: {'EXIT',{undef,[{lager,start,[],[]},
{boss_rebar,compile,4,
[{file,"../ChicagoBoss-0.8.12/priv/rebar/boss_rebar.erl"},
{line,97}]},
{boss_plugin,pre_compile,2,
[{file,"priv/rebar/boss_plugin.erl"},{line,105}]},
{rebar_core,run_modules,4,[]},
{rebar_core,execute,5,[]},
{rebar_core,process_dir1,6,[]},
{rebar_core,process_commands,2,[]},
{rebar,main,1,[]}]}}
make: *** [all] Error 1
Am I missing something? Thanking all in advance.
This error indicates, that lager parse transforms are not present while compiling. Lager does not define functions like lager:info or lager:error directly. During compilation, it changes those calls adding line number and other useful things.
Your problem can be usually solved by moving lager before any other dependency in ./deps/boss/rebar.config or adding it as a dependency directly to your application in ./rebar.config.

Configuring Lager - I get this error: undefined parse transform 'lager_transform'

I'm testing this https://github.com/saleyn/erws_example on R16B03 (both on windows & Ubuntu)
==> erws_example (compile)
src/erws_handler.erl:none: undefined parse transform 'lager_transform'
ERROR: compile failed while processing /home/charles/erws_example: rebar_abort
I've seen this suggestion http://philipcristiano.com/2013/05/27/ordering-of-rebar-dependencies.html
So far, i'm unable to get any headway.
Thanks.
It seems rebar can not compile parse transforms before compiling everything else (https://github.com/basho/rebar/issues/270). The solution is to compile module with parse transform manually or use file-level parse_transform compiler directive instead of project level.
Try to put lager to first position in rebar dependency list. it will fix it. rebar ordering compile dependencies according to this list, not dependency tree))

rebar compile eunit error

I user rebar to make a eunit test with command "rebar compile eunit",but get a error info:
==> myapp (compile)
==> myapp (eunit)
src/myapp_app.erl:8: badly formed 'include_lib'
src/myapp_app.erl:26: undefined macro 'assertNot/1'
ERROR: eunit failed while processing /Users/Dao/ErlProject/myapp: rebar_abort
I really don't know how this mean,who can tell me why?
PS:my english is poor,please forgive me
myapp_app.erl like this:
-ifdef(TEST).
-include_lib(“eunit/include/eunit.hrl”).
-endif.
........
-ifdef(TEST).
simple_test() ->
ok = application:start(myapp),
?assertNot(undefined == whereis(myapp_sup)).
-endif.
and It's came from here:https://github.com/rebar/rebar/wiki/Getting-started
I follow the step,but got the error!
My erlang version is R15B03
os: OS X Lion
Based on the code you've presented, I believe the problem has to do with the doublequotes you're using. Right now, you are using some kind of slanted quotes, which, if I copy and paste it and use that same definition myself in a test module, it generates the same error.
You want to make sure for your doublequotes that you use "normal" ones:
" (ASCII 34) instead of ”, which is unicode.
So change
-include_lib(“eunit/include/eunit.hrl”).
to
-include_lib("eunit/include/eunit.hrl").
Make sure you include eunit in the following way:
-include_lib("eunit/include/eunit.hrl").
Needless to say, make sure you installed eunit at all. So far I remember, it may be not installed by default in some Ubuntu versions, for instance.

Resources