A little POSIX shell script that generates a C/C++ header or a Cmake variable file containing the version information (Major Minor etc...) of a Git based repository.
The script simply parses the git describe
command to extract the firmware information, and create the corresponding defines.
The script will generate a C header file.
./project-version.sh -f h -o project/include/version.h
The script will generate a C++ header file.
./project-version.sh -f hpp -o project/include/version.hpp
The script will generate a cmake variable file.
./project-version.sh -f cmake -o cmake-project/VERSION
- Restricted to git based repository.
- Git must be available from the PATH. (On windows, run the script with git bash).
Clone the repo or simply copy the project-version.sh
script into your repository and let the magic happen.
All available options can be listed with option -h
$ ./project-version.sh -h
==> project-version.sh 0.6.0
A little POSIX shell script to generate
version information for your C project.
ref: https://github.com/AlexFabre/project-version
Usage:
project-version.sh <options>
-f <output format>
-f h : (default) Generate a C header file (.h).
-f hpp : Generate a C++ header file (.hpp).
-f cmake : Generate a cmake variable file.
-o <output file name>
-t <git tag format> (default 'v') (ex. 'v' will match tags 'v0.3.1' and 'v0.2.1-beta' but not tags '1.3.4' nor 'version3.2.3')
-h <help>
-v <script version>
-l <script logs> (default none)
/**
* @file version.h
* @brief This file declares the firmware revision information
*
* Generated with project-version.sh 0.6.0
* A little POSIX shell script to generate
* version information for your C project.
* ref: https://github.com/AlexFabre/project-version
*
* Do not edit this file manually. Its content
* is generated with project-version.sh script.
*/
#ifndef VERSION_H__
#define VERSION_H__
/* Project version */
#define VERSION_MAJOR 0
#define VERSION_MINOR 5
#define VERSION_PATCH 0
/* Git repo info */
#define VERSION_BRANCH_NAME "main"
#define VERSION_NB_COMMITS_SINCE_LAST_TAG 3
#define VERSION_COMMIT_SHORT_SHA "b620737"
/* Build date time (UTC) */
#define VERSION_BUILD_DAY 15
#define VERSION_BUILD_MONTH 11
#define VERSION_BUILD_YEAR 2024
#define VERSION_BUILD_HOUR 9
#endif /* VERSION_H__ */
# This file declares the firmware revision information
#
# Generated with project-version.sh 0.6.0
# A little POSIX shell script to generate
# version information for your C project.
# ref: https://github.com/AlexFabre/project-version
#
# Do not edit this file manually. Its content
# is generated with project-version.sh script.
VERSION_MAJOR = 0
VERSION_MINOR = 5
PATCHLEVEL = 0
VERSION_TWEAK = 3
EXTRAVERSION = main
- Shellcheck
- Codespell
- Path handling in
file_path_checker
function: The function currently assumes that the provided path always ends with a filename. If the input path doesn't have a filename or extension, it defaults toversion.h
. This could lead to incorrect behavior in some cases. Consider validating the input path and handling errors more explicitly.