We usually need to package system and repositories in order to create a big application. Erlware is a repository for Erlang programs and it provides softaware to create a package and release it to the world. There are pretty cool, it is just thing I want to. This entry introduces that how to create an application as package and install to system.
I create a HAVAL bindings for Erlang in order to learn how to create linked-in driver.
See Tutorial for how to create Erlang linked-in driver.
In this entry, I introduce how to create an application provides API for HAVAL bindings for Erlang. We need to install Faxien and Sinan previously.
0. Dicied a names of application and start to development a pakcage.
Create required directories for the application.
% mkdir haval && cd haval && mkdir -p cmds doc bin libCreate directories for HAVAL bindings.
% ls .
bin/ cmds/ doc/ lib/ releases/
%
% mkdir -p lib/haval && cd lib/hava && mkdir src ebin include priv/libConfiguration file named "_build.cfg" for this application.
% cat > _build.cfg1. Create an application
project : {
name : haval
vsn : "1.0.0"
},
repositories : ["http://repo.erlware.org/pub", "http://repo.martinjlogan.com/pub"]
Create a HAVAL bindings for Erlang in this entry. This includes following source codes:
- haval.erl - Source provides API for HAVAL bindings
- haval_server.erl - Server to handle the shared library of HAVAL linked-in driver.
- haval_sup.erl - Supervisor
- haval_app.erl - An application
- Makefile
- config.h
- haval.c
- haval.h
- haval_drv.o
HAVAL bindings requires shared library named "erl_drv.so", we may think want to integrate building task for linked-in driver to the package manager(Faxien). But unfortunately I don't know that, so I need to research for handling shared library.
All sources are here.
Do make task manually here.
% cd lib/haval/c_src3. Build the application.
% make # Copy haval_drv.so haval/priv/lib
It 'sinan' command is used for building the application. We need to run background server with 'sinserv' command before compile them.
% sinserv # Placed in "/usr/local/erlware/release_packages/sinan-0.10.0.12/bin/sinserv" in my enviromentBuild the application with 'sinan' command. We can see help when '+help' command is passed.
% sinan +helpCreate a package for release. This package is generated underneath "_build/development/apps/" directory.
sinan [args] [task]
local args (+) and server args. local args may be any of the following
+url : The url to connect to and control
+help : This help message
Server args are much more complex. There are always sane defaults so
you shouldn't need them, but you may. To get information about server
args read the sinan documentation.
%
% sinan # Default task is build
starting run
[check_depends] start
[check_depends] stop
[build] start
[build] Building ~/haval-1.0.0/lib/haval/src/haval_server.erl
[build] Building ~/haval-1.0.0/lib/haval/src/haval_sup.erl
[build] Building ~/haval-1.0.0/lib/haval/src/haval_app.erl
[build] Building ~/haval-1.0.0/lib/haval/src/haval.erl
[build] stop
run complete
% ls _build/development/apps/haval-1.0.0 # Generated following sources
c_src/ ebin/ include/ priv/ src/
%
% sinan release4. Install the application locally.
starting run
[check_depends] start
[check_depends] stop
[build] start
[build] stop
[release] start
[release] stop
run complete
%
Some of tasks are required in order to install the application. At first, we need to prepare the directory for released package, copy "_build/development/release" to "releases/haval-1.0.0/" and copy "_build/development/haval-1.0.0" to "releases/haval-1.0.0".
% mkdir releases/haval-1.0.0/ && mkdir lib
% cp -r _build/development/release releases/haval-1.0.0/
% cp -r _build/development/apps/haval-1.0.0 releases/haval-1.0.0/lib
Install the application locally, there will be deployed on "/usr/local/erlware/release_packages/haval-1.0.0/". We can use 'faxien' command in order to handle the packages (local and remote). Please execute "faxien help commands" for more details.
Run and test.
% faxien install-release releases/haval-1.0.0
ok
% ls /usr/local/erlware/release_packages/haval-1.0.0/
LICENCE README lib/ release/
% erl5. Test the application
Erlang (BEAM) emulator version 5.6.2 [source] [smp:2] [async-threads:0] [kernel-poll:false]
Eshell V5.6.2 (abort with ^G)
1> haval:start().
ok
2> haval:haval_string("test").
"593C9AED973BB51A3C852FB4E051D7C26686B9468B4E405350CB6805DC1B99E6"
3> haval:haval_file("_build.cfg").
"5A114E356FBB0CCCED8C7574B7A71780C8F33D3A9B37B8642126B78429B2988F"
4>
We can use EUnit for testing the application, and do test with following command:
% sinan test