Using epm to overcome rebar dependency handling limitations

I love rebar as a build tool, but occasionally it doesn’t do what I want. One example that keeps cropping up is managing dependencies that require complex commands in order to build them. If the dependency you want to manage is built using autotools or requires a series of commands (configure && make for example) then rebar is going to fail when you try and run ./rebar check-deps which is annoying.

I thought about extending rebar to deal with these builds, but there are so many edge cases I thought my changes unlikely to be robust enough to be pulled back upstream. The alternative seemed to be manually doing everything from a makefile, until I remembered that epm will do this for me easily. I don’t want to make epm a dependency of my own project(s) simply for builds, but luckily it’s packaged as a tiny executable script once installed, meaning that I can easily embed it with my sources and use it without much trouble. It will even update itself to the latest version which is a nice feature.

Here’s an excerpt of the makefile that I ended up with, using rebar to manage most of the build tasks and falling back to epm when installing process-one’s exmpp and ejabberd projects from github. The only kink was epm‘s insisting on taking user input from STDIN to confirm the installation – I could have patched it to add a –quiet option I suppose, but doing so seemed prohibitively long winded compared with just piping the user’s response into the process from the makefile. Naturally in this case you don’t actually need the makefile to build the code – you can just use rebar. But if you want the dependencies installed (which rebar won’t do ootb) then the makefile will sort this out for you first time around.

    mkdir $@

exmpp: deps
    echo "y" | epm install processone/exmpp \
      --tag v0.9.3 \
      --prebuild-command "autoreconf -vif" \
      --build-command "configure && make" \
      --config-set build_dir $(HERE)/build \
      --config-set install_dir $(HERE)/deps

ejabberd: deps
    echo "y" | epm install processone/ejabberd \
      --tag v2.1.4 \
      --prebuild-command "configure" \
      --build-command "make" \
      --config-set build_dir $(HERE)/build \
      --config-set install_dir $(HERE)/deps

check: ejabberd exmpp
    @(env ERL_LIBS=$$ERL_LIBS ./rebar $$VERBOSE check-deps)

compile: check
    @(env ERL_LIBS=$$ERL_LIBS ./rebar $$VERBOSE compile)

    @(./rebar clean)

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: