Kerl Rocks!!
Submitted by Bill St. Clair on Fri, 02 Oct 2015 10:41:59 GMT
I interviewed with Basho last week, hoping for a job writing Erlang for their Riak distributed database. They didn't hire me, at least not yet, but their system is open source, so I decided one way to convince them I'm capable, and to ground the Erlang study I've been doing for the last couple of months, is to submit some pull requests. They ship binaries built against their fork of version R16B03 of Erlang, and Riak builds in 17.5, but you get build errors for 18.x, so I decided to fix those build errors.
The build errors are mostly due to erlang:now()
being deprecated and most of the Riak source set to error on warnings, so the fixes are easy. You either change to os:now()
, which returns the same form of result, but doesn't guarantee a unique value each time, or you call erlang:timestamp()
, falling back to erlang:now()
if it isn't defined (which it isn't before 18.x). time_compat:timestamp()
from time_compat.erl does exactly that. Easy fixes, but testing needed in the Basho versions of Erlang 16, 17, and 18 before a pull request is ready for submission.
And that's where Yurii Rashkovskii's kerl
comes in. It makes it very easy to download source, build, install, and choose from a bunch of different versions of Erlang. Now would be a good time to click Yurii's photo below and read the README for kerl
. I'll go over some of the details, but only what I've used so far.
On a new Ubuntu 14.04 machine, I had to install some packages to get Erlang to build:
$ sudo apt-get install build-essential git libncurses5-dev # not strictly necessary, but enables those Erlang applications $ sudo apt-get install libssl-dev libssh-dev
You'll also need to install Sun's Java SDK, if you need the jinterface
application and java_src
from the ic
application (necessary, or at least desireable for Riak).
kerl
, like erlang.mk
, and rebar
is a single file, containing a shell script (rebar
's script is mostly Erlang binary). Here's how I installed it on my machine (~/bin
is in my PATH
):
$ mkdir -p erlang $ cd ~/erlang $ git clone git@github.com:yrashk/kerl.git $ ln -s ~/erlang/kerl/kerl ~/bin/
And here's how I know it worked:
$ kerl kerl: build and install Erlang/OTP usage: .../bin/kerl <command> [options ...]Command to be executed Valid commands are: build Build specified release or git repository install Install the specified release at the given location ...
To find which releases kerl
knows about:
$ kerl list usage: .../bin/kerl list$ kerl list releases R10B-0 ... R16B03 ... 17.4 17.5 18.0 18.1 Run ".../bin/kerl update releases" to update this list from erlang.org
Download and install one of them:
$ kerl build R16B03 erlang-r16b03 Downloading otp_src_R16B03.tar.gz to .../.kerl/archives ... Verifying archive checksum... Checksum verified (c330150913556a0fe73e57a441cb6375) Extracting source code Building Erlang/OTP R16B03 (erlang-r16b03), please wait... Erlang/OTP R16B03 (erlang-r16b03) has been successfully built
kerl
doesn't print out much while building. To see progress, you can look at the log file (from another shell window, the log file is deleted when the build completes successfully):
$ cd ~/.kerl/builds/erlang-r16b03/ $ tail -f otp_build_R16B03.log
The Erlang configure script omits applications for which you have no library support on your system. Here's how to find which ones the build will skip:
$ cd ~/.kerl/builds/erlang-r16b03/ $ find . -name SKIP ./otp_src_R16B03/lib/odbc/SKIP
Install the build you just made in a directory of your choosing:
$ mkdir -p ~/erlang/release $ kerl install erlang-r16b03 ~/erlang/release/r16b03 Installing Erlang/OTP R16B03 (erlang-r16b03) in .../erlang/release/r16b03... You can activate this installation running the following command: . .../erlang/release/activate Later on, you can leave the installation typing: kerl_deactivate
Start using the new installation:
$ kerl list installations erlang-17.5 .../erlang/release/17.5 erlang-18.1 .../erlang/release/18.1 erlang-r16b03 .../erlang/release/r16b03 $ KERL_ENABLE_PROMPT=y . ~/erlang/release/r16b03/activate (erlang-r16b03)$ which erl .../erlang/release/r16b03/bin/erl (erlang-r16b03)$ erl Eshell V5.10.4 (abort with ^G) 1>halt(). (erlang-r16b03)$ kerl_deactivate $ which erl $
I rarely use kerl_deactivate
. Instead I just activate a different version.
Riak builds require Basho's special patched Erlang versions. You can use kerl
for them, too. Below I build the basho-otp-16
branch of Basho's OTP fork:
$ kerl build git usage: .../bin/kerl build git <git_url> <git_version> <build_name> $ kerl build git git@github.com:basho/otp.git basho-otp-16 basho-r16 Checking Erlang/OTP git repository from git@github.com:basho/otp.git... Building Erlang/OTP basho-r16 from git, please wait... Erlang/OTP basho-r16 from git has been successfully built $ kerl install basho-r16 ~/erlang/release/basho-r16 Installing Erlang/OTP git (basho-r16) in .../erlang/release/basho-r16... ... $ KERL_ENABLE_PROMPT=y . ~/erlang/release/basho-r16/activate (basho-r16)billstclair@Gabriel:~/erlang/release$ erl Eshell V5.10.3 (abort with ^G) 1> halt(). (basho-r16)$ kerl_deactivate $
KERL_ENABLE_PROMPT=y
is responsible for the (basho-r16)
prefix on the shell prompt. If you don't like that, don't use it. I have a shell script that automates most of the activation. I'll document it soon, along with some of my other useful scripts, with code on GitHub.
$ . kerl_activate basho-r16 (basho-r16)$ kerl_deactivate $
kerl
makes it easy to test my Riak patches in the three most recent Erlang versions. It has more features, but you already clicked on Yurii's photo, right? So you know about them.