Current section
Files
Jump to
Current section
Files
vsn_transform
README.md
README.md
# vsn_transformErlang parse transform to add `-vsn` attributes from (e.g.) git.## MotivationBy default, an Erlang module has a `vsn` attribute that's the MD5 checksum of the module. You'd probably prefersomething easier to read, such as `1.0.2`. You can control this version by adding a `-vsn` module attribute, forexample:```erlang-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 rebar3Add 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 explicitlyNote that the parse transform runs the command once for each file being compiled, which can sometimes be slow. If you'dprefer, 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 environmentvariable, 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").## LicenseApache 2.0