[erlang-questions] Including other peoples code in my code in a future proof way
Loïc Hoguin
essen@REDACTED
Tue Mar 17 15:07:44 CET 2015
On 03/17/2015 02:53 PM, Joe Armstrong wrote:
> How do I include another application in my application?
>
> I've written a program that I want to distibute.
> I'll make it available on github.
>
> The problem is that my program uses cowboy and a few other
> things (which are also on github)
>
> I'd like my program to work "out of the box" - just type Make and off
> you go.
>
> I'd also like my to work for a long time so if rebar and
> cowboy change in the future I'd like my program to still build
> correctly.
>
> Now what I could do is:
>
> use rebar and a rebar.config file that point to cowboy etc.
>
> My rebar-config is like this
>
> {deps, [
> ...
> {cowboy, ".*", {git, "git://github.com/extend/cowboy.git", "master"}}
> ]}.
>
> The problem with this is that
>
> 1) my version of rebar might not be the same as on the target machine
> where the makefile is run
This is a problem erlang.mk solves. You include erlang.mk in your
project therefore everyone has the same when they compile it.
You still are at the whim of Make having an incompatible change that
breaks something, but you also have that issue with rebar when a newer
Erlang version breaks something in it. The chances of either happening
are very slim though.
> 2) The cowboy reference is to "the latest version" and not
> an immutable version that I know works
>
> So How should I fix this? Is the answer:
>
> a) Include rebar in my distribution
> (I don't really like this, since I'd just like to have my code in
> my project archive)
That's what I would advise you to do, though. Do note however that if
your project is to be used as a dependency then it won't be your rebar
that will be used but the user's (or the top-level project's) rebar.
This is another issue erlang.mk solves as the dependency's Makefile is
always used and not the top-level erlang.mk. The dependency can run a
different erlang.mk or just a plain Makefile, or even a Makefile that
calls the bundled rebar, it doesn't matter as long as there is a Makefile.
> b) Point to a absolute version of cowboy - but how do I do this?
Simply put the tag or commit number instead of "master" in rebar.config,
for example "1.0.1".
Make sure to do this with all your dependencies, and check that the
dependencies themselves do it.
I believe rebar3 has a way to lock dependencies into a specific commit
for the projects that depend on another's "master".
> Or c)
> Include all the source code of cowboy etc in my release
This also works but will prove to be more time consuming when you need
to update dependencies. However if you intend to just release the
project and make little maintenance over it afterward (for example if
it's a proof of concept or a prototype) then this might just be the way
to go.
--
Loïc Hoguin
http://ninenines.eu
More information about the erlang-questions
mailing list