I want to pass a {custom_build_number}, is this possible using the built in build system? Even if there is some way to ask the user for a build number, rather than automatic increment, I can work with that. Or can I create a custom variable that is âvisibleâ to the build system? Do I have to resort to a plugin?
I donât think there is any direct way to do something like this without plugin code or enhancing something elsewhere, but I may be wrong.
One way to go about that would be to have whatever tracks the build number be done externally, within build.cmd itself. That way no matter how you execute the build (from within sublime, from the command line, etc) your build number would always auto-increment, which from a completeness/correctness standpoint may be the âbestâ way (best being used very loosely).
It is possible to modify a build system so that instead of invoking the exec command directly to execute the build, it executes a custom sublime command instead (from a plugin). That would necessitate building some plugin logic that either tracks the current build number and increments it every time, or prompting the user for what to use.
Prompting the user may quickly get tedious if you do frequent builds, although you could mitigate that somewhat by perhaps remembering what was used last time and then providing that as the default for next time, or only asking on the first build in a session and then auto-incrementing after that.
Below is an example of enhancing the build system to allow you to specify your own custom build variables outside of those inherently supported by Sublime. The code assumes that the extra settings are coming from a setting specific to the project file, but you could modify that so that instead of doing that it looked e.g. at some file on disk and used that as the value of the variable instead.
Hi @OdatNurd, thanks for your prompt reply. Unfortunately, the build.cmd is not maintained by me, I cannot modify that. However, I could create a duplicate file and modify that and call that each time for compile. The build.cmd file does not change often. Its a good idea, I had not explored that option.
I will also explore the plugin option from the github link.
I guess thatâs going to be what you need, or instead of running build.cmd, you run an other script that runs build.cmd which increments the counter for you. (I think the second solution is the best)
Hi @OdatNurd, I was interested in adding my own custom variables and followed your code on github. I have modified my sublime-build file to look like this
I have copied your custom_build_variables.py to my plugins folder and sublime loads it. Now when I launch build drop down (Ctrl + Shift + B), I donât see the newly added item there. Did I miss something or my understanding of your build enhancement plugin is wrong?
Hi @math2001, thatâs a good idea, Let me try that. I dont see why that would not work. I am hoping I can get @OdatNurdâs method to work, it will help me add more variable in the future.
Thanks for your time all.
The popup that you get with that key sequence shows you the list of variants in the currently selected build system.
Build systems show up in the menu based on the name of the file that you saved them into, e.g. MyBuildSystem.sublime-build shows up in the menu as MyBuildSystem. Since there isnât anything in the build system as defined that tells Sublime to use it automatically, you need to manually select the build from the menu (Tools > Build System) to select it, and then just press Ctrl+B to build with it.
The modification doesnât change how the build is presented to you, only in what happens when the build executes.
Note also that there is a trailing comma in the text you posted above after the closing }; if that is in your build system it wonât work (unless that excerpt is e.g. from a project specific build in your project file; in that case, the name of the build in the menu is based on a name field in the build system, which you would need to add to see it).
I have a custom build, my file is called Scons.sublime-build. In this file, I have many variants. They all pop up when I hit Ctrl+Shift+B. I can then select from this list and it builds without issue. I added a new item to this list as indicated above, however the newly added item does not show in the list, so I am unable to invoke that build.
The trailing â,â is for other variants in my Scons.sublime-build file. I was missing the ânameâ part, its showing up now.
Which settings file is this? Is this the sublime-project file? Right now, when I invoke the command from build, the build is called with an empty stings for my build number.
Yes, itâs possible to have a "settings" key in your project file to apply settings that are specific to your project. That might look something like this:
As written, the code tries to pull the setting first from the view settings, with the project settings being used if the view doesnât have that setting. That allows for you to have an overall project specific setting for something but to override it for a particular file or view if you want to.
Views get settings from other places (e.g. global preferences and syntax specific) so if you put your setting directly in your user preferences instead of your project, it would get pulled from there instead for example.
For your purposes you may want to pull that setting from somewhere else instead of the project settings (or get the default from another location) so that you can increment the value after you apply it and store the value back for next time you build.