Skip to content

Instantly share code, notes, and snippets.

@Scottapotamas
Created January 29, 2020 06:04
Show Gist options
  • Save Scottapotamas/6ade419f25218cd0b60a06420737f7e1 to your computer and use it in GitHub Desktop.
Save Scottapotamas/6ade419f25218cd0b60a06420737f7e1 to your computer and use it in GitHub Desktop.
Generate C header defines with git tag/commit information
@rem === Batch file to generate build information from the git tag and log information.===
@rem === Get Git Build Info ===
@git describe --tags --abbrev=4 --dirty --always > tmp.txt
@set /p BUILD_INFO=<tmp.txt
@del tmp.txt
@rem -------------------------------------------------------------------
@git branch > tmp.txt
@set /p BUILD_BRANCHES=<tmp.txt
@del tmp.txt
@rem -------------------------------------------------------------------
@rem === Get Git Build Date & Time ===
@git log -1 --format=%%ci > tmp.txt
@set /p BUILD_FULL_DATE=<tmp.txt
@for /F "usebackq tokens=1-4 delims=/ " %%I IN (`@echo %BUILD_FULL_DATE%`) do @set BUILD_DATE=%%I
@for /F "usebackq tokens=1-4 delims=/ " %%I IN (`@echo %BUILD_FULL_DATE%`) do @set BUILD_TIME=%%J
@for /F "usebackq tokens=1-4 delims=/ " %%I IN (`@echo %BUILD_BRANCHES%`) do @set BUILD_BRANCH=%%J
@del tmp.txt
@rem -------------------------------------------------------------------
@set BUILD_INFO_FILE=../Src/app_state_machines/build_info.h
@rem === Create Build Info Header File ===
@echo[
@echo -------------------------------------------------------------------
@echo Build Info: %BUILD_BRANCH% %BUILD_INFO% %BUILD_DATE% %BUILD_TIME% into %BUILD_INFO_FILE%
@echo -------------------------------------------------------------------
@echo[
@echo /** > %BUILD_INFO_FILE%
@echo * @file build_info.h >> %BUILD_INFO_FILE%
@echo * @brief Git tag and commit information >> %BUILD_INFO_FILE%
@echo * @warning DO NOT EDIT! >> %BUILD_INFO_FILE%
@echo * Generated by CreateBuildInfo.bat >> %BUILD_INFO_FILE%
@echo */ >> %BUILD_INFO_FILE%
@echo[ >> %BUILD_INFO_FILE%
@echo #ifndef BUILD_INFO_H >> %BUILD_INFO_FILE%
@echo #define BUILD_INFO_H >> %BUILD_INFO_FILE%
@echo[ >> %BUILD_INFO_FILE%
@echo #define BUILD_DATE "%BUILD_DATE%" >> %BUILD_INFO_FILE%
@echo[ >> %BUILD_INFO_FILE%
@echo #define BUILD_TIME "%BUILD_TIME%" >> %BUILD_INFO_FILE%
@echo[ >> %BUILD_INFO_FILE%
@echo #define BUILD_INFO "%BUILD_INFO%" >> %BUILD_INFO_FILE%
@echo[ >> %BUILD_INFO_FILE%
@echo #define BUILD_BRANCH "%BUILD_BRANCH%" >> %BUILD_INFO_FILE%
@echo[ >> %BUILD_INFO_FILE%
@echo #endif /* BUILD_INFO_H */ >> %BUILD_INFO_FILE%
@echo[ >> %BUILD_INFO_FILE%
@rem -------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment