I don't know if this is something common for people to do or not, but I personally always keep track of the number of times I built my code. That is, both the number of times I called make
and the number of times the build was successful.
My current solution
I have a simple code that takes a file as parameter, opens it, increments the number inside and overwrites it. This code is compiled, first thing when make
is called.
Immediately after, ./increase_build build.txt
is called which increments the number of times I called make
to build the library.
Then, the code is compiled and the lib file is made (with ar cq ...
). After that, ./increase_build libbuild.txt
is called that increments the number of successful builds. Finally the tests are built.
This is an example of one of my Makefiles.
Why I got concerned
This always worked fine, until I started using version control. There seemed like there is no problem: I am the sole author of my own libraries and I add features one by one.
One day though, I was testing branching and merging (I use git for myself and svn at work), so I added one feature in a branch and changed something in master and I merged the two. Now the build count files have different values.
The problem
The problem is, let's say at the time of branch, the build count is 100. Then I write something in branch and the build count gets to 110. I write something in master branch and the build count gets to 120. When I merge the two, I see one is 110 and one is 120 (which is a conflict by the way). The correct solution would be to set the build to 130.
However, I can't (read I don't want to) go back to the commit where the branch took off and find that it was 100 so I compute 100+(110-100)+(120-100) = 130! I want this to be automatic
The question
Well the question is obvious: How do I do this? How do I keep track of my build count (not commit count!) when I'm working with version control? I don't want an answer that is based on a feature in the version control, because the problem arises anew if I change version control system.
What I though could work was to add one line in the build count file for every build, something say with data and time. Then the build number would be the number of lines in the build count files. Also, unless I get two builds on two branches that were done the EXACT same time then merging the files would be just the union of the two.
I wonder though, are there any better solutions to this? Is what I want (build counts) even worth the effort?
P.S. If you are wondering why I do it with both the number of builds and the number of successful builds, that's just something personal. I like to see how much rebuild I get for small typos and errors I make when I code.
Edit: I program in C and C++, so a solution in either works for me.