- 1 year ago
Batch script to output git sha1id to a #define in header file
Here's an example batch script that you can use to output the Git SHA1 ID to a #define
statement in a header file:
vbnet@echo off
REM Set the path to the Git executable
set GIT_PATH=C:\Program Files\Git\bin\git.exe
REM Set the path to the header file
set HEADER_FILE=example.h
REM Get the Git SHA1 ID
for /f %%i in ('%GIT_PATH% rev-parse HEAD') do set SHA1ID=%%i
REM Write the #define statement to the header file
echo #define GIT_SHA1ID "%SHA1ID%" > %HEADER_FILE%
To use this script, you can save it to a file with a .bat
extension (e.g. update_git_sha1id.bat
) and then run it from the command line. Make sure to set the GIT_PATH
and HEADER_FILE
variables to the correct values for your environment.
When you run the script, it will use the Git executable to get the SHA1 ID of the current commit, and then write a #define
statement to the specified header file with the SHA1 ID as the value of the GIT_SHA1ID
macro.
You can then include the header file in your code and use the GIT_SHA1ID
macro to access the Git SHA1 ID at compile time. For example:
arduino#include "example.h"
int main() {
printf("Git SHA1 ID: %s\n", GIT_SHA1ID);
return 0;
}
This will print the Git SHA1 ID to the console when the program is run. Note that you will need to re-run the batch script to update the #define
statement in the header file whenever the Git SHA1 ID changes.