Arduino IDE - git-describe automatic software versioning

HI all,
I'm trying to embed automatic versioning in my sketches to display the sketch version on Arduino startup (this will help to remember which version of which software I've installed on different Arduinos).

I reached my purpose through a script that is called every time I compile a sketch.

Basically, I've modified the file platform.local.txt adding the following line:

recipe.hooks.sketch.prebuild.1.pattern=git-version.bat {build.source.path} {build.path}

Where git-version.bat is my file.

The problem is that this file (platform.local.txt) get reset every time I update the architecture platform. Moreover this file is per-architecture, this means that every time I've install a new architecture (avr, esp8266, esp32,...) or update an old one, I have to re-modify platform.local.txt.

Is there a way to run a prebuild script regardless of the current architecture (i.e. not depending on platform.local.txt file)?

Short of modifying the Arduino IDE source code and then building the modified IDE from source, I don't know of any way to do this.

I suppose you could have an external program that watches for a specific process that indicates the start of the Arduino IDE compilation process and runs your .bat file. The tricky thing is this is going to be running in parallel to the sketch compilation process so the .bat would need to get its thing done before the critical compilation step. I'm sure there are many options for how to implement this system. The one I'm familiar with is called EventGhost. This is an automation program that has a visual programming interface, but also allows you to use Python to provide for more advanced functionality. There is a "Process Watcher" plugin included with the EventGhost installation that will generate an event for every process that happens on your computer. You can assign the event associated with the particular process you will use as the trigger to run a macro. There is a "Run application" action you can use to run your .bat file.

fabiuz7:
The problem is that this file (platform.local.txt) get reset every time I update the architecture platform. Moreover this file is per-architecture, this means that every time I've install a new architecture (avr, esp8266, esp32,...) or update an old one, I have to re-modify platform.local.txt.

Maybe a work-around is to write a short program that finds the platform.local.txt file and updates it (or all versions of it if there are several). You could run that program after you have updated the platform.

...R

fabiuz7:
The problem is that this file (platform.local.txt) get reset every time I update the architecture platform. Moreover this file is per-architecture, this means that every time I've install a new architecture (avr, esp8266, esp32,...) or update an old one, I have to re-modify platform.local.txt.

Is this also true for arduino-x.y.z/hardware/platform.txt?
I based a solution on this described here: Build process - add custom action during execution (e.g. fill build date, ... - Libraries - Arduino Forum
Maybe this helps you.

Thank alex_73, this is what I'm looking for. My config file survives to platform updates!

I should verify if Arduino IDE overwrites it when it gets updates.

EDIT: It would be nice having a "platform.txt" in the same folder of "preferences.txt", so Arduino IDE upgrades won't erase your config.

In case someone is curious about git versioning, here the repo with script + instructions :

I know your talking about git versioning but this may interest those looking to simply have a local method to identify what's programmed with what.
Using some of the environment variables you can name and datestamp at compile time and these strings could be printed out at boot or on request.
Sorry if I got the wrong end of the stick and this is not at all related.

void BUILD_RAMstrings() {
  RAM_filename = (__FILENAME__); RAM_filename.replace(F(".ino"), "");
  RAM_ssidhead = RAM_filename; RAM_ssidhead.replace(F("HV_ESP_"), ""); RAM_ssidhead += F("_");
  RAM_date  = (__DATE__); RAM_date.replace(F("  "), F(" 0")); RAM_date.replace(F(", "), " ");
  RAM_time  = (__TIME__); RAM_time.replace(F("  "), F(" 0"));
  RAM_datetime = RAM_date; RAM_datetime += " "; RAM_datetime += RAM_time;
  RAM_version = date2VER(RAM_datetime, true).toInt(); // dy.substring(2) + dm + dd + th + tm; // + ts;
  if (RAM_boottime == "-") {RAM_boottime = (String)F("Boot: ") + RAM_time;}
  //if (RAM_webwareDATE.Length() == 0){RAM_webwareDATE = RAM_datetime;}
  //if (RAM_webwareVER == String(0)) {RAM_webwareVER = RAM_version;}
}