Cannot start sample erlang release generated with rebar - erlang

I'm a beginner with rebar and erlang generally. I was trying to create an erlang release with rebar according to this tutorial: http://www.metabrew.com/article/erlang-rebar-tutorial-generating-releases-upgrades and got stuck at the point of running generated release.
My system is Ubuntu 11.04 64bit, erlang R14B03, installed from sources.
When i'm invoking 'bin/somenode console', I get one of the following errors:
Exec: /home/ghik/Inz/somerel/rel/somenode/erts-5.8.4/bin/erlexec -boot /home/ghik/Inz/somerel/rel/somenode/releases/1/somenode -mode embedded -config /home/ghik/Inz/somerel/rel/somenode/etc/app.config -args_file /home/ghik/Inz/somerel/rel/somenode/etc/vm.args -- console
Root: /home/ghik/Inz/somerel/rel/somenode
{"init terminating in do_boot",{'cannot load',hipe_amd64_encode,get_files}}
Crash dump was written to: erl_crash.dump
init terminating in do_boot ()
Interestingly, each time I run it, different atom is listed instead of 'hipe_amd64_encode', for example: 'hipe_amd64_defuse', 'hipe_amd64_assemble', etc.
I'm guessing erlang is unable to load hipe, but I have no idea why is is trying to load it in the first place. The release contains only one, very simple application dependent only on kernel and stdlib.
For some reason, rebar generates a .rel file with lots of unnecessary applications:
%% rel generated at {2011,9,6} {20,5,48}
{release,{"somenode","1"},
{erts,"5.8.4"},
[{kernel,"2.14.4"},
{stdlib,"1.17.4"},
{sasl,"2.1.9.4"},
{someapp,"1"},
{compiler,"4.7.4",load},
{crypto,"2.0.3",load},
{et,"1.4.3",load},
{gs,"1.5.13",load},
{hipe,"3.8",load},
{inets,"5.6",load},
{mnesia,"4.4.19",load},
{observer,"0.9.9",load},
{public_key,"0.12",load},
{runtime_tools,"1.8.5",load},
{ssl,"4.1.5",load},
{syntax_tools,"1.6.7.1",load},
{tools,"2.6.6.4",load},
{webtool,"0.8.8",load},
{wx,"0.98.10",load}]}.
Why does rebar list soo many applications in the .rel file? And event if it's fine, why doesn't the release start?

Add to reltool.config, the following line:
{app, hipe, [{incl_cond, exclude}]}

First of all, you can try to see what fails during the booting of the VM by adding the arguments init_debug to the VM:
$ erl -init_debug
{progress,preloaded}
{progress,kernel_load_completed}
{progress,modules_loaded}
{start,heart}
{start,error_logger}
{start,application_controller}
{progress,init_kernel_started}
...
{progress,applications_loaded}
{apply,{application,start_boot,[kernel,permanent]}}
{apply,{application,start_boot,[stdlib,permanent]}}
{apply,{c,erlangrc,[]}}
{progress,started}
Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.8.4 (abort with ^G)
1>
Using this, you'll be able to see with more details the kind of interactions going on. It might be that libraries are being loaded in the wrong order, you don't support native, etc.
Second issue, the rel file containing too many applications. This is likely due to the fact that Rebar uses Reltool ot generate releases, and that different applications can be loaded depending on how granular the control is whne generating releases (see incl_cond material in the docs). There are a few examples for this in the Release is The Word chapter of Learn You Some Erlang:
{sys, [
{lib_dirs, ["/home/ferd/code/learn-you-some-erlang/release/"]},
{erts, [{mod_cond, derived}, % derived makes it pick less stuff
{app_file, strip}]},
{rel, "erlcount", "1.0.0", [kernel, stdlib, ppool, erlcount]},
{boot_rel, "erlcount"},
{relocatable, true},
{profile, embedded}, % reduces the files included from each app
{app_file, strip}, % reduces the size of app files if possible
{incl_cond, exclude}, % by default, don't include apps. 'derived' is another option
{app, stdlib, [{mod_cond, derived}, {incl_cond, include}]}, % include at the app
{app, kernel, [{incl_cond, include}]}, % level overrides the
{app, ppool, [{vsn, "1.0.0"}, {incl_cond, include}]}, % exclude put earlier
{app, erlcount, [{vsn, "1.0.0"}, {incl_cond, include}]}
]}.
And this should generate smaller releases.

I don't know the good answer, but I do know that I couldn't start a release running on several CentOS versions with a couple different kernels, so this isn't exactly unusual. Upgrading to 5.6 made it finally work. You can see which OSes actually get tested every day here:
http://www.erlang.org/doc/installation_guide/INSTALL.html#id62915
Also, you could compile without HIPE, I guess.

Lately I found this post:
http://mokele.co.uk/2011/07/01/rebar-release-upgrade-caveats.html
It uncovers a list of errors in rebar, one of them being the reason why my release couldn't launch. There are also fixes published. I hope they will be merged into main rebar repository ASAP.

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. :)

Including lager in an erlang.mk project

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.

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.

Command 'generate' not understood or not applicable

I am trying to run rebar generate to generate a release for an erlang rebar project and getting the following error. Any ideas what I am doing wrong?
./rebar generate
Command 'generate' not understood or not applicable
I am on OSX with erlang version Erlang R14B03 and below is my rebar.conf
{lib_dirs, ["deps"]}.
{sub_dirs, ["rel"]}.
{deps, [
{folsom, ".*", {git, "git://github.com/boundary/folsom", "master"}}
]}.
{require_otp_vsn, "R14|R15"}.
{erl_opts, [
fail_on_warning,
debug_info,
warn_missing_spec
]}.
{clean_files, ["*.eunit", "ebin/*.beam", "rel/graphsom"]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report, {eunit_surefire, [{dir, "."}]}}]}.
You are getting this error because rebar is unable to find a release. You should check if you have reltool.config somewhere and rebar knows about it.
If no release exists, you can create a new one:
mkdir rel
cd rel
../rebar create-node nodeid=YOUR_NODE_ID
Lastly, you need to tell rebar about the release. In your case, you already have the following added to rebar.config:
{sub_dirs, ["rel"]}.
This should allow the generate command to build a new release.

Resources