compile-time-regular-expressions
compile-time-regular-expressions copied to clipboard
Put version number into ctre.hpp
Please add the library's version number to the single-header file (ctre.hpp
) so that users can check which version they already have and whether they need to update.
Also, please supply a ctre::version()
function (or whatever name you prefer) to make the version number accessible to application programs.
May I suggest using git tag based version number management? The idea is to define the current version number as a git tag, and only as a git tag (no manual editing of the version number in one of the source files). The benefits are:
- Version number is in exactly one place (no risk of inconsistent edits)
- Can check out by version number (like,
git checkout 1.2.3
) - git automatically creates "intermediate version numbers" (something like "we are 5 commits after version 1.2.3")
Here's how to do it. First define the current version number as an annotated git tag, e. g.
$ git tag -a 1.2.3
Then, modify the build framework to put the following line into the appropriate place of ctre.hpp
when building it:
auto version() { return "XXX"; }
where XXX is the output of git describe --dirty --always
. For example, ctre.hpp
would contain something like:
auto version() { return "1.2.3"; }
The nice thing is that the version number will automatically go up as you add new commits, even if you don't create a new tag. For example, after seven commits, the version number will be something like:
auto version() { return "1.2.3-7-gabcde"; }
where abcde
is the commit ID. You can return to that exact version later with git checkout abcde
. Also, if you changed something but didn't commit it yet, the version number will be something like
auto version() { return "1.2.3-7-gabcde-dirty"; }
indicating that this was built from a "dirty" working tree, and this exact version may not be recoverable from the repository later.
Then, when you release a new version, you simply do git tag -a 1.2.4
, and you'll automatically get
auto version() { return "1.2.4"; }
without further ado.
I've been using this tag-based version number management in my production system for some time and find it really convenient. Here's how I do it in a C++ project: https://gitlab.com/wolframroesler/version Maybe you'll find this useful.