Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Locked Topic Automatic build version in built code (Read 7417 times)
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Automatic build version in built code
Dec 22nd, 2018 at 9:36am
 
Hi,

it would be a nice feature to be able to automatically include a build number in built bin files that can then be used in the Sketch.

For example:
A file 'BuildVersion.h' included in the project that contains:
#define VERSION 3.1

Each time the project is built this number gets automatically (if desired by a setting)  incremented 

The version can then be used as desired in the sketch.

I guess this could be implemented using a pre or post build script. 

Acuario
  
Back to top
 
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
RE: Automatic build version in built code (SOLUTION)
Reply #1 - Dec 23rd, 2018 at 7:42am
 
For anyone who wants this feature, here is a way to achieve at least a basic way of doing it.

1. Create a file in your project called version.h
2. Put the following in version.h 
Code
Select All
#define VERSION 1 


3. Create a version.bat file in your project and mark it as Exclude from project
4. Add the following to version.bat:
Code
Select All
@echo off
setlocal EnableDelayedExpansion
set file=%1

for /F "tokens=1-3 delims=N " %%a in (%file%) do (
   for %%A in (%%a %%b %%c) do set "i=%%A"
)
set /a i=i+1
echo #define VERSION %i% > %file% 



5. Add the following to your Board.txt
Code
Select All
# Increment version before build
recipe.hooks.sketch.prebuild.1.pattern=cmd.exe /c "{build.project_path}\version.bat {build.project_path}\version.h"
 



6. Add #Include "version.h" in your sketch

The version number will increment by 1 every time you do a build, irrespective if it succeeds or fails.

To use the version just use the defined VERSION in your code for example:
Code
Select All
Serial.printf("Startup Version:%d\n", VERSION);
 



Acuario
« Last Edit: Dec 24th, 2018 at 3:30pm by Tim@Visual Micro »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Automatic build version in built code
Reply #2 - Dec 24th, 2018 at 3:32pm
 
Excellent thank you!
  
Back to top
WWW  
IP Logged
 
Acuario
Full Member
***
Offline


Posts: 233
Location: Spain
Joined: Aug 28th, 2015
Re: Automatic build version in built code
Reply #3 - Jun 10th, 2019 at 7:48am
 
I just upgraded to the latest version of VS and it broke my auto update.

It appears something has changed in the build process and now the quotes on the command string are no longer required.

To fix this change the code in step 5 from this:
Code
Select All
# Increment version before build
recipe.hooks.sketch.prebuild.1.pattern=cmd.exe /c "{build.project_path}\version.bat {build.project_path}\version.h" 



to this:
Code
Select All
# Increment version before build
recipe.hooks.sketch.prebuild.1.pattern=cmd.exe /c {build.project_path}\version.bat {build.project_path}\version.h 



The version increment then works correctly.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Automatic build version in built code
Reply #4 - Jun 10th, 2019 at 1:00pm
 
Thanks, sadly, the quotes cause an issue with some platforms. Sorry forgot to add to the release notes.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint