Command 'escriptize not understood or not applicable - erlang

When I run ./rebar get-deps compile escriptize, it fails with the following:
WARN: 'escriptize' command does not apply to directory /path/to/foo
Command 'escriptize' not understood or not applicable
What have I forgotten?

Even though you're generating an escript package, rebar still needs the foo.app file. If you didn't use ./rebar create-app appid=foo to create your "application", you'll need to create one by hand:
{application, foo,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel, stdlib
]},
{env, []}
]}.
Note that you might need to ./rebar compile again in order to generate the foo.app file before ./rebar escriptize will generate the script correctly.

Related

Erlang: How to plug Elvis style check to rebar3 project properly?

I'm adding Elvis check style to Erlang project built with rebar3.
Initially I've found rebar3_lint plugin for this. But then it appeared to use some old version of Elvis and fails not very graciously on errors.
Then after some play I attached elvis directly as a test dependency and then calling it with pre_hook and erlang code line:
{profiles, [
{test, [
{deps, [
{elvis_core,
{git, "https://github.com/inaka/elvis_core",
{branch, "master"}}}
]},
{pre_hooks, [{compile,
"erl -pa _build/test/lib/*/ebin -noshell -eval 'init:stop(case elvis_core:rock() of ok -> 0; _ -> 1 end)'"}]}
]},
]}
This works nicely, though looks awkward.
So is there any more "proper" way? Thanks in advance!

Reltool copies files I don't want into release

I have the following .config file:
{sys, [
{lib_dirs, ["/Users/dan/learn_you_some_erlang/erlcount"]},
{rel, "erlcount", "1.0.0", [
kernel,
stdlib,
{ppool, permanent},
{erlcount, transient}
]},
{boot_rel, "erlcount"},
{erts, [
{mod_cond, derived},
{app_file, strip}]},
{profile, embedded}
]}.
and when I run reltool, I get a directory erts-9.1/doc containing a 400-page book about Erlang (among other things). How do I get rid of this?
I tried adding {excl_sys_filters, ["^doc"]} to the erts options, but I get an error
Illegal option: {excl_sys_filters,[\"^doc\"]}

rebar: Missing application directory

I'm testing rebar on
Windows 8 64Bis
Erlang 64bits R15B02
I've compiled rebar from github code and created a basic app
$ mkdir testapp; cd testapp
$ mkdir rel
$ rebar create-app appid=testapp
$ echo "{sub_dirs, ["rel"]}." > rebar.config
$ cd rel
$ rebar create-node nodeid=testnode
$ cd -
$ rebar compile
$ rebar generate
ERROR: generate failed while processing testapp/rel: {'EXIT',{{badmatch,{error,"testapp: : Missing application directory."}
...
I'm reading the reltool documentation but i cant found anything about application dir the only relevant option is incl_cond but is defined by default by rebar command
src/testapp.app.src
{application, testapp,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{mod, { testapp_app, []}},
{env, []}
]}.
rel/reltool.config
{sys, [
{lib_dirs, []},
{erts, [{mod_cond, derived}, {app_file, strip}]},
{app_file, strip},
{rel, "testapp", "1",
[
kernel,
stdlib,
sasl,
testapp
]},
{rel, "start_clean", "",
[
kernel,
stdlib
]},
{boot_rel, "testapp"},
{profile, embedded},
{incl_cond, derived},
{mod_cond, derived},
{excl_archive_filters, [".*"]}, %% Do not archive built libs
{excl_sys_filters, ["^bin/.*", "^erts.*/bin/(dialyzer|typer)",
"^erts.*/(doc|info|include|lib|man|src)"]},
{excl_app_filters, ["\.gitignore"]},
{app, testapp, [{mod_cond, app}, {incl_cond, include}]}
]}.
{target_dir, "testapp"}.
{overlay, [
{mkdir, "log/sasl"},
{copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"},
{copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"},
{copy, "files/testapp", "bin/testapp"},
{copy, "files/testapp.cmd", "bin/testapp.cmd"},
{copy, "files/start_erl.cmd", "bin/start_erl.cmd"},
{copy, "files/install_upgrade.escript", "bin/install_upgrade.escript"},
{copy, "files/sys.config", "releases/\{\{rel_vsn\}\}/sys.config"},
{copy, "files/vm.args", "releases/\{\{rel_vsn\}\}/vm.args"}
]}.
In my case I had to modify the default rel/reltool.config line
{lib_dirs, []},
to
{lib_dirs, ["../../"]},
Where the layout of my project is:
Makefile
ebin/
rebar.config
rel/
src/
This might help you. (quoted below in case the original link disappears)
Not exactly sure what's the reason for that change for versions following R15B01 though.
Thanks to Siri, reltool in R15B01 includes a really useful feature.
Many Erlang projects are using the following structure:
./src/foo.app.src
./src/foo.erl
./rel/reltool.config
When you wanted to reference the application foo in
rel/reltool.config, you previously had three options:
* project-local libs/ or apps/ directory
* unsafe {lib_dirs, "../.."} reltool.config setting
* rebar_reltool_link fake_lib_dir plugin
Starting with R15B01 all you have to do now is specify
{app, foo, [{incl_cond, include}, {lib_dir, ".."}]}
in reltool.config for applications not in lib_dirs.
Although R15B01 is still in development, this feature is complete and
can be used in the otp.git maint branch.
Refer this guideline,
https://github.com/rebar/rebar/wiki/Release-handling
If you're using R15B01 or newer change,
{app, exemplar, [{mod_cond, app}, {incl_cond, include}, {lib_dir, ".."}]}
above way of mentioning path solved the application directory not found issue for me.

Starting application with Erlang

I would like to write a standalone Erlang application which could be run just like any other program (by clicking on .exe executable). Something like Wings3D does.
How can I do it ? What is the best approach to make it possible ? I am on Windows platform, if it is important.
2nd UPDATE:
Well, I haven't exported the promodb:start/0 function and that was the reason Erlang could'n start (and, as the Muzaaya Joshua says, werl -s does not work). But now, I have another strange problem. In my rebar.config I have 2 dependencies:
{deps, [
{cowboy, ".*", {git, "https://github.com/extend/cowboy.git"}},
{erlydtl, ".*", {git, "https://github.com/evanmiller/erlydtl.git"}}
]
}.
and after I start Erlang using
erl -pa ebin deps/cowboy/ebin deps/erlydtl/ebin deps/proper/ebin -s promodb
I find by application:which_application() that only Cowboy is started:
[{cowboy,"Small, fast, modular HTTP server.","0.4.0"},
{stdlib,"ERTS CXC 138 10","1.18"},
{kernel,"ERTS CXC 138 10","2.15"}]
As far as I know, Erlang should start all needed applications that I put in my promodb.app file, as:
{application, promodb,
[
{description, ""},
{vsn, "0.1"},
{registered, [promodb_sup]},
{applications, [
kernel,
stdlib,
cowboy,
erlydtl
]},
{mod, { promodb, []}},
{env, []}
]}.
What did I do wrong ?
I use rebar escriptize to pack a standalone package like rebar. Then you can use ./PackageName in linux or escript.exe PackageName in windows.
I think you need to create a release package and a boot script as explained in the documentation.
Actually the -s option works everywhere. Just use erl NOT werl. The werl command attempts to load a GUI on Windows.
The BitRock Install Builder is a great tool you need to check out. Yaws Web Server written in Erlang, uses it and many other applications.
Erlydtl doesn't have an application behaviour, it works like a library. As you can see in erlydtl examples, no app is needed to be started.
https://github.com/evanmiller/erlydtl#template-compilation
Check this:
erl -pa ebin deps/*/ebin
1> erlydtl:compile(<<"{{ foo }}">>, my_module_name).
Does it works?
I like escriptize rebar option to create executables.

Starting inets/httpd with custom application

I've got a module that I'm attempting to turn into a proper OTP application. Currently, the module has start/0 which starts a genserver which supplies configuration data read from a config file. It then calls inets:start(httpd,config:lookup(httpd_conf)). I gather that I need to move the starting of these out into the .app file's (application list) but I'm not sure how to get my config data into the inets:start function (or pass in httpd)?
Thanks,
--tim
Here's what I've figured out...
First, I needed to create the inets config file:
inets.config:
[{inets, [{services, [{httpd, [{proplist_file,
"8080.conf"}]},
].
Then, create the httpd conf file:
8080.conf
[
{modules, [
mod_alias,
mod_auth,
mod_esi,
mod_actions,
mod_cgi,
mod_dir,
mod_get,
mod_head,
mod_log,
mod_disk_log
]},
{port,8080},
{server_name,"hello_world"},
{server_root,"log"},
{document_root,"www"},
{erl_script_alias, {"/erl", [hello_world]}},
{error_log, "error.log"},
{security_log, "security.log"},
{transfer_log, "transfer.log"},
{mime_types,[
{"html","text/html"},
{"css","text/css"},
{"js","application/x-javascript"}
]}
]
Now, when booting my app, I just reference the inets.conf file with:
$ erl -boot start_sasl -pa ebin -config inets.config
This seems to work not sure if it's the "right" way or not...

Resources