Skip to main content
DiBosco
Senior
October 18, 2023
Solved

Auto incrementing a build number after each compile?

Folks,

Is there a way to have a variable that is incremented each time the project is compiled? I can do this with Rowley Crossworks and it's really useful. I define and major and minor number then a build number gets incremented each time I compile and I can get those vlaues when I interrogate the device using a CLI.

Thanks

    This topic has been closed for replies.
    Bob S
    Bob SBest answer
    Super User
    October 18, 2023

    Write your script/program to do whatever you need.  Then call it from the "pre-build" steps in the project's C/C++ Build settings.  Go to the project properties, then expand "C/C+ Build" on the left side, then click on "settings".  In the right side, click on the "Build Steps" tab.

    4 replies

    Bob S
    Super User
    October 18, 2023

    Not built in to the IDE, though there are probably Eclipse add-ons that do this.  But you can add your own pre-build or post-build steps to do that.  Run a script file that mods the value inside a .c file.  I use the pre-build steps to insert the GIT commit hash into a variable, and the post-build steps to further process the hex/binary files (add CRC/SHA hashes, etc.).  Even on Windows, the IDE runs a Linux compatible shell so you have sed available.

    DiBosco
    DiBoscoAuthor
    Senior
    October 18, 2023

    Hi, thanks for the reply.

    When you say script, I'm guessing you mean you can get, say, a Python script to automatically run once you hit CTL-B, but before it actually does the compile?

     

    If so, how do you implement the running of that script please? I can write the Python much easier than I can a bash script (I am running Linux so could run the latter at a push, although Python is likely better as some colleagues are unfortunate enough to have to run Windows.

     

    Thanks!

    Bob S
    Bob SBest answer
    Super User
    October 18, 2023

    Write your script/program to do whatever you need.  Then call it from the "pre-build" steps in the project's C/C++ Build settings.  Go to the project properties, then expand "C/C+ Build" on the left side, then click on "settings".  In the right side, click on the "Build Steps" tab.

    DiBosco
    DiBoscoAuthor
    Senior
    October 19, 2023

    Great, thanks very much. :)