Giter Club home page Giter Club logo

vsn_transform's Introduction

vsn_transform

Erlang parse transform to add -vsn attributes from (e.g.) git.

Motivation

By default, an Erlang module has a vsn attribute that's the MD5 checksum of the module. You'd probably prefer something easier to read, such as 1.0.2. You can control this version by adding a -vsn module attribute, for example:

-module(foo).
-vsn("1.0.2").

% ...

But that's tedious. So we wrote a parse transform that allows you to set the version attribute at build time.

Using it with rebar3

Add it to your rebar.config file, as follows:

{deps, [
    {vsn_transform, ".*",
        {git, "https://github.com/rlipscombe/vsn_transform.git"}}
]}.

{erl_opts, [
    {parse_transform, vsn_transform},
    {vsn_command, "git describe --tags"}
]}.

Obviously, you can change the command as needed. You might want to use git rev-parse --short HEAD, for example.

Setting it explicitly

Note that the parse transform runs the command once for each file being compiled, which can sometimes be slow. If you'd prefer, you can set the version explicitly:

    {vsn, "1.0.2"}

You lose some flexibility, because the value's now hard-coded in rebar.config. If you'd prefer to use an environment variable, create a rebar.config.script file. See examples/rebar_script_example.

Did it work?

You can check it with the following:

lists:map(
    fun({Mod, Path}) ->
        Vsn = proplists:get_value(vsn, Mod:module_info(attributes)),
        {Mod, Vsn}
    end, code:all_loaded()).

Or with:

beam_lib:version("path/to/some.beam").

License

Apache 2.0

vsn_transform's People

Contributors

rlipscombe avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.