Sublime Forum

Inserting Build Numbers

#1

Hi All,

Been googling this for an hour now and thought id ask for help. Sorry if its already posted somewhere, but I couldn’t find it.

I use sublime to write and compile code. Is it possible to have a build number in my file incremented each time I run a build off?

Thanks

Sam

0 Likes

#2

This was asked on the forum a few years ago (see the forum post linked below) and the answers are still pretty much the same at this point.

The least obtrusive way would be to have whatever the build is launching do the work. For example if you were writing C and using make, a rule in the Makefile could fiddle the content around. If you’re just compiling and running a single file you could launch a script that updates the file and then builds it, and so on.

It’s also possible to modify the sublime-build file to have it execute plugin code instead of the standard action that it would take when executing the build. In that case the plugin could do the file modification for you and then defer to what it would have done. There’s somewhat of an example of that in the post linked below.

I’ve written something like that previously, which modifies a particular file that contains just the build number and nothing else (which then gets picked up by the code that wants to know about it, displayed in scripts, etc).

If you wanted something that actually modifies a source file directly, that’s also possible but more work (and potentially more error prone as well).

If you want to go the custom build route and can provide more details on how you’d like it to work, I may be able to assist you with the plugin code required to do something like that.

0 Likes