l'essentiel est invisible pour les yeux

Friday, July 04, 2008

[Erlang] How to package an application with erlware(faxien and sinan commands)

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 lib
% ls .
bin/ cmds/ doc/ lib/ releases/
%
Create directories for HAVAL bindings.
% mkdir -p lib/haval && cd lib/hava && mkdir src ebin include priv/lib
Configuration file named "_build.cfg" for this application.
% cat > _build.cfg
project : {
name : haval
vsn : "1.0.0"
},

repositories : ["http://repo.erlware.org/pub", "http://repo.martinjlogan.com/pub"]
1. Create an application
Create a HAVAL bindings for Erlang in this entry. This includes following source codes:
HAVAL bindings is provides as linked-in driver, these source are in lib/haval/c_src directory.
  • Makefile
  • config.h
  • haval.c
  • haval.h
  • haval_drv.o
2. Build the shared library
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_src
% make # Copy haval_drv.so haval/priv/lib
3. Build the application.
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 enviroment
Build the application with 'sinan' command. We can see help when '+help' command is passed.
% sinan +help
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/
%
Create a package for release. This package is generated underneath "_build/development/apps/" directory.
% sinan release
starting run
[check_depends] start
[check_depends] stop
[build] start
[build] stop
[release] start
[release] stop
run complete
%
4. Install the application locally.
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.

% faxien install-release releases/haval-1.0.0
ok
% ls /usr/local/erlware/release_packages/haval-1.0.0/
LICENCE README lib/ release/
Run and test.
% erl
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>
5. Test the application
We can use EUnit for testing the application, and do test with following command:
% sinan test