9 Development & Deployment

9.1 Creating Projects with Rebar

In this section we'll be exploring how rebar can be used to manage LFE projects.

9.1.1 Dependencies

You're going to need to have an Erlang. We recommend using kerl, as deponstrated in the next section. However, you may already have one set up, in which case you're good for the next step.

9.1.2 Installation

$ curl -L -O https://raw.github.com/wiki/rebar/rebar/rebar
$ mv rebar /usr/local/bin/
$ chmod a+x /usr/local/bin/rebar

Make sure everything's working as expected:

$ rebar -h

This will give you output like the following:

Usage: rebar [-h] [-c] [-v <verbose>] [-V] [-f] [-D <defines>] [-j <jobs>]
             [-C <config>] [-p] [var=value,...] <command,...>

  -h, --help        Show the program options
  -c, --commands    Show available commands
  -v, --verbose     Verbosity level (-v, -vv, -vvv, --verbose 3). Default: 0
  -V, --version     Show version information
  -f, --force       Force
  -D                Define compiler macro
  -j, --jobs        Num concurrent workers a command may use. Default: 3
  -C, --config      Rebar config file to use
  -p, --profile     Profile this run of rebar
  var=value     rebar global variables (e.g. force=1)
  command       Command to run (e.g. compile)

9.1.2 What is a Project?

The first question we should probably address is this: How are we defining a project?

An LFE project is a set of modules developed and distributed to accomplish a particular goal. The project should have a rebar configuration file, a source directory with .lfe files in it, possibly an include directory, and (ideally) unit tests in a test directory.

9.1.2 Project Structure

Let's expand upon the project definition given above, focusing on the directory structure of a prototypical project and some of the files one might find in an LFE project.

├── ebin
│   └── libexample.app
├── src
│   └── libexample.lfe
├── Makefile
├── README.md
└── rebar.config

This is from a sample project whose purpose is to provide a library for use by other LFE (or Erlang!) projects. More on that below.

Rebar supports LFE files. All that it needs is the standard rebar.config and an .app file in the ebin directory. With these, Rebar will be able to download the project dependencies and compile the *.lfe files in src to the ebin directory as *.beam files.

9.1.3 Project Dependencies

Dependencies are handled very nicely with Rebar: just add a git repo in your rebar.config file like so:

{deps, [
    {lfe, ".*", {git, "git://github.com/rvirding/lfe.git", "develop"}}

Any dependencies listed here will be downloaded with the rebar get-deps command. Once downloaded, issuing the rebar compile command will not only compile your project's src/* files into its ebin directory, but will compile all dependency project source code as well.