Skip to content

Commit

Permalink
script: remove zephyr support
Browse files Browse the repository at this point in the history
Zephyr support will lead to a new project
  • Loading branch information
AlexFabre committed Nov 15, 2024
1 parent b620737 commit d678d04
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:
- name: Codespell action
uses: codespell-project/actions-codespell@v2
with:
ignore_words_list: rever
ignore_words_list: project-version

6 changes: 3 additions & 3 deletions .github/workflows/tag-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
with:
fetch-depth: 0 # Fetch all history for all branches and tags

- name: Run rever on itself
run: ./rever.sh -l -o base_version.h -f base -t v
- name: Run project-version on itself
run: ./project-version.sh -l -o base_version.h -f base -t v

- name: Checking version
run: ci-script/check_rever_version.sh rever.sh base_version.h
run: ci-script/check_script_self_version.sh project-version.sh base_version.h
51 changes: 13 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# rever
# project-version

A little POSIX shell script that generates a C header containing the version information (Major Minor etc...) of a Git based repository.

Expand All @@ -11,15 +11,15 @@ The script simply parses the `git describe` command to extract the firmware info
The script will generate a C header file.

```sh
./rever.sh -o project/include/version.h
./project-version.sh -o project/include/version.h
```

### Zephyr project

The script will generate the cmake version file.

```sh
./rever.sh -f zephyr -o cmake-project/VERSION
./project-version.sh -f zephyr -o cmake-project/VERSION
```

## Requirements
Expand All @@ -29,21 +29,21 @@ The script will generate the cmake version file.

## Usage

Clone the repo or simply copy the `rever.sh` script into your repository and let the magic happen.
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`

~~~sh
$ ./rever.sh -h
==> rever.sh 0.5.0
$ ./project-version.sh -h
==> project-version.sh 0.5.0
A little POSIX shell script to generate
version information for your C project.
ref: https://github.com/AlexFabre/rever
ref: https://github.com/AlexFabre/project-version
Usage:
rever.sh <options>
project-version.sh <options>
-f <project format>
-f zephyr: Generate a 'VERSION' file, specific to zephyr projects
-f base: (default) Generate the basic rever format file
-f base: (default) Generate the basic project-version format file
-o <output file>
-t <git tag format> (default 'v')
-h <help>
Expand All @@ -58,13 +58,13 @@ rever.sh <options>
* @file version.h
* @brief version information of project build
*
* Generated with rever.sh 0.5.0
* Generated with project-version.sh 0.5.0
* A little POSIX shell script to generate
* version information for your C project.
* ref: https://github.com/AlexFabre/rever
* ref: https://github.com/AlexFabre/project-version
*
* Do not edit this file manually. Its content
* is generated with rever.sh script.
* is generated with project-version.sh script.
*/
#ifndef VERSION_H__
#define VERSION_H__
Expand All @@ -75,7 +75,7 @@ rever.sh <options>
#define VERSION_PATCH 0

/* Git repo info */
#define VERSION_BRANCH_NAME "feat/add-zephyr-compatibility"
#define VERSION_BRANCH_NAME "feat/dev-branch"
#define VERSION_NB_COMMITS_SINCE_LAST_TAG 6
#define VERSION_COMMIT_SHORT_SHA "08df77b"

Expand All @@ -89,31 +89,6 @@ rever.sh <options>

~~~

### Example of generated header for Zephyr project

~~~txt
# This file declares the firmware revision information
# both for cmake and for mcuboot
#
# ref: https://docs.zephyrproject.org/latest/build/version/index.html
#
# Generated with rever.sh 0.5.0
# A little POSIX shell script to generate
# version information for your C project.
# ref: https://github.com/AlexFabre/rever
#
# Do not edit this file manually. Its content
# is generated with rever.sh script.
VERSION_MAJOR = 0
VERSION_MINOR = 5
PATCHLEVEL = 0
VERSION_TWEAK = 6
EXTRAVERSION = "feat/add-zephyr-compatibility08df77b"
~~~

## Code quality
- Shellcheck
- Codespell
Expand Down
162 changes: 61 additions & 101 deletions rever.sh → project-version.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#!/bin/sh
# ==========================================
# rever - A little POSIX shell script to generate
# project-version - A little POSIX shell script to generate
# version information for your C project
# Copyright (C) 2024 Alex Fabre
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================

# ==========================================
# Usage with standard tag names vXX.YY.ZZ
# $> rever.sh -o dir/subdir/version.h
# $> project-version.sh -o dir/subdir/version.h
#
# Usage with custom tag names fw-XX.YY.ZZ
# $> rever.sh -o dir/subdir/file_version.h -t fw-
# $> project-version.sh -o dir/subdir/file_version.h -t fw-
#
# ==========================================

# Script self version information
REVER_MAJOR=0
REVER_MINOR=5
REVER_PATCH=0
PROJECT_VERSION_MAJOR=0
PROJECT_VERSION_MINOR=5
PROJECT_VERSION_PATCH=0

# Print variables
REVER_SCRIPT_NAME="rever.sh"
REVER_VERSION="$REVER_MAJOR.$REVER_MINOR.$REVER_PATCH"
REVER_INTRO_L1="A little POSIX shell script to generate"
REVER_INTRO_L2="version information for your C project."
REVER_INTRO_L3="ref: https://github.com/AlexFabre/rever"
PROJECT_VERSION_SCRIPT_NAME="project-version.sh"
PROJECT_VERSION_VERSION="$PROJECT_VERSION_MAJOR.$PROJECT_VERSION_MINOR.$PROJECT_VERSION_PATCH"
PROJECT_VERSION_INTRO_L1="A little POSIX shell script to generate"
PROJECT_VERSION_INTRO_L2="version information for your C project."
PROJECT_VERSION_INTRO_L3="ref: https://github.com/AlexFabre/project-version"

# ==========================================
# Default settings
Expand All @@ -34,7 +34,7 @@ REVER_INTRO_L3="ref: https://github.com/AlexFabre/rever"
# If the path provided with option -o does end on a directory
# (with a trailing '/' (ex. -o dir/subdir/ )), then the script
# will create the file in that directory with the following name.
DEFAULT_FILE_NAME="VERSION"
DEFAULT_FILE_NAME="version"

# By default the script will look for tags in the format
# v1.0.4
Expand All @@ -55,22 +55,17 @@ LOG_VERBOSITY=0
# Default file path output
OUTPUT_FILE_PATH=$DEFAULT_FILE_NAME

OUTPUT_FILE_FORMAT="base"

# ==========================================
# Script call checks
# ==========================================

usage() {
echo "==> $REVER_SCRIPT_NAME $REVER_VERSION"
echo "$REVER_INTRO_L1"
echo "$REVER_INTRO_L2"
echo "$REVER_INTRO_L3"
echo "==> $PROJECT_VERSION_SCRIPT_NAME $PROJECT_VERSION_VERSION"
echo "$PROJECT_VERSION_INTRO_L1"
echo "$PROJECT_VERSION_INTRO_L2"
echo "$PROJECT_VERSION_INTRO_L3"
echo "Usage:"
echo "$REVER_SCRIPT_NAME <options>"
echo " -f <project format>"
echo " -f zephyr: Generate a 'VERSION' file, specific to zephyr projects"
echo " -f base: (default) Generate the basic rever format file"
echo "$PROJECT_VERSION_SCRIPT_NAME <options>"
echo " -o <output file>"
echo " -t <git tag format> (default 'v')"
echo " -h <help>"
Expand All @@ -79,11 +74,8 @@ usage() {
}

# Check the call of the script
while getopts ":f:o:t:hvl" opt; do
while getopts ":o:t:hvl" opt; do
case "${opt}" in
f)
OUTPUT_FILE_FORMAT=${OPTARG}
;;
o)
OUTPUT_FILE_PATH=${OPTARG}
;;
Expand All @@ -95,7 +87,7 @@ while getopts ":f:o:t:hvl" opt; do
exit 0
;;
v)
echo "$REVER_VERSION"
echo "$PROJECT_VERSION_VERSION"
exit 0
;;
l)
Expand Down Expand Up @@ -160,15 +152,9 @@ fi
git_version=$(git --version)
log "$git_version"

# Handle file format depending on project format
log "Format: $OUTPUT_FILE_FORMAT"
if [ "$OUTPUT_FILE_FORMAT" = "base" ]; then
EXTENSION=".h"
fi

if [ "$OUTPUT_FILE_FORMAT" = "zephyr" ]; then
EXTENSION=""
fi
EXTENSION=".h"


# Version file path
FILE_PATH=$(file_path_checker "$OUTPUT_FILE_PATH")
Expand Down Expand Up @@ -239,73 +225,47 @@ HOUR=$(date -u +"%-H")
# Extract filename with extension...
BASENAME="$(basename "$FILE_PATH")"

# Generated for a Zephyr project
if [ "$OUTPUT_FILE_FORMAT" = "zephyr" ]; then
# Modify the tmp version file
{ echo "# This file declares the firmware revision information";
echo "# both for cmake and for mcuboot";
echo "#";
echo "# ref: https://docs.zephyrproject.org/latest/build/version/index.html";
echo "#";
echo "# Generated with $REVER_SCRIPT_NAME $REVER_VERSION";
echo "# $REVER_INTRO_L1";
echo "# $REVER_INTRO_L2";
echo "# $REVER_INTRO_L3";
echo "#";
echo "# Do not edit this file manually. Its content";
echo "# is generated with rever.sh script.";
echo "";
echo "VERSION_MAJOR = $FW_MAJOR";
echo "VERSION_MINOR = $FW_MINOR";
echo "PATCHLEVEL = $FW_PATCH";
echo "VERSION_TWEAK = $NB_COMMIT_SINCE_LAST_TAG";
echo "EXTRAVERSION = $BRANCH_NAME";
} > "${FILE_PATH}_tmp"
fi

# Generated for a base project
if [ "$OUTPUT_FILE_FORMAT" = "base" ]; then
# Change filename chars to UPPER and non-alphanum to UNDERSCORES...
BUILD_LOCK=$(echo "${BASENAME}" | awk 'BEGIN { getline; print toupper($0) }' | sed 's/[^[:alnum:]\r\t]/_/g')

MACRO_PREFIX="${BUILD_LOCK#_}"
MACRO_PREFIX="${MACRO_PREFIX%%_*}"

# Modify the tmp version file
{ echo "/**";
echo " * @file $BASENAME";
echo " * @brief version information of project build";
echo " *";
echo " * Generated with $REVER_SCRIPT_NAME $REVER_VERSION";
echo " * $REVER_INTRO_L1";
echo " * $REVER_INTRO_L2";
echo " * $REVER_INTRO_L3";
echo " *";
echo " * Do not edit this file manually. Its content";
echo " * is generated with rever.sh script.";
echo " */";
echo "#ifndef ${BUILD_LOCK}__";
echo "#define ${BUILD_LOCK}__";
echo "";
echo "/* Project version */";
echo "#define ""$MACRO_PREFIX""_MAJOR $FW_MAJOR";
echo "#define ""$MACRO_PREFIX""_MINOR $FW_MINOR";
echo "#define ""$MACRO_PREFIX""_PATCH $FW_PATCH";
echo ""
echo "/* Git repo info */";
echo "#define ""$MACRO_PREFIX""_BRANCH_NAME \"$BRANCH_NAME\"";
echo "#define ""$MACRO_PREFIX""_NB_COMMITS_SINCE_LAST_TAG $NB_COMMIT_SINCE_LAST_TAG";
echo "#define ""$MACRO_PREFIX""_COMMIT_SHORT_SHA \"$COMMIT_SHA\"";
echo ""
echo "/* Build date time (UTC) */";
echo "#define ""$MACRO_PREFIX""_BUILD_DAY $DAY";
echo "#define ""$MACRO_PREFIX""_BUILD_MONTH $MONTH";
echo "#define ""$MACRO_PREFIX""_BUILD_YEAR $YEAR";
echo "#define ""$MACRO_PREFIX""_BUILD_HOUR $HOUR";
echo "";
echo "#endif /* ${BUILD_LOCK}__ */";
} > "${FILE_PATH}_tmp${EXTENSION}"
fi
# Change filename chars to UPPER and non-alphanum to UNDERSCORES...
BUILD_LOCK=$(echo "${BASENAME}" | awk 'BEGIN { getline; print toupper($0) }' | sed 's/[^[:alnum:]\r\t]/_/g')

MACRO_PREFIX="${BUILD_LOCK#_}"
MACRO_PREFIX="${MACRO_PREFIX%%_*}"

# Modify the tmp version file
{ echo "/**";
echo " * @file $BASENAME";
echo " * @brief git based version information";
echo " *";
echo " * Generated with $PROJECT_VERSION_SCRIPT_NAME $PROJECT_VERSION_VERSION";
echo " * $PROJECT_VERSION_INTRO_L1";
echo " * $PROJECT_VERSION_INTRO_L2";
echo " * $PROJECT_VERSION_INTRO_L3";
echo " *";
echo " * Do not edit this file manually. Its content";
echo " * is generated with project-version.sh script.";
echo " */";
echo "#ifndef ${BUILD_LOCK}__";
echo "#define ${BUILD_LOCK}__";
echo "";
echo "/* Project version */";
echo "#define ""$MACRO_PREFIX""_MAJOR $FW_MAJOR";
echo "#define ""$MACRO_PREFIX""_MINOR $FW_MINOR";
echo "#define ""$MACRO_PREFIX""_PATCH $FW_PATCH";
echo ""
echo "/* Git repo info */";
echo "#define ""$MACRO_PREFIX""_BRANCH_NAME \"$BRANCH_NAME\"";
echo "#define ""$MACRO_PREFIX""_NB_COMMITS_SINCE_LAST_TAG $NB_COMMIT_SINCE_LAST_TAG";
echo "#define ""$MACRO_PREFIX""_COMMIT_SHORT_SHA \"$COMMIT_SHA\"";
echo ""
echo "/* Build date time (UTC) */";
echo "#define ""$MACRO_PREFIX""_BUILD_DAY $DAY";
echo "#define ""$MACRO_PREFIX""_BUILD_MONTH $MONTH";
echo "#define ""$MACRO_PREFIX""_BUILD_YEAR $YEAR";
echo "#define ""$MACRO_PREFIX""_BUILD_HOUR $HOUR";
echo "";
echo "#endif /* ${BUILD_LOCK}__ */";
} > "${FILE_PATH}_tmp${EXTENSION}"

if cmp -s "${FILE_PATH}" "${FILE_PATH}_tmp${EXTENSION}"
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ -z "$FILE2" ]; then
exit 1
fi

# Function to extract values from rever.sh script
# Function to extract values from project-version.sh script
extract_from_script() {
var_name=$1
grep "^$var_name" "$FILE1" | cut -d '=' -f 2 | tr -d ' \t'
Expand All @@ -28,10 +28,10 @@ extract_from_header() {
grep "^#define[ \t]\+$var_name" "$FILE2" | awk '{print $3}'
}

# Extract values from rever.sh script
VERSION_MAJOR_FILE1=$(extract_from_script "REVER_MAJOR")
VERSION_MINOR_FILE1=$(extract_from_script "REVER_MINOR")
VERSION_PATCH_FILE1=$(extract_from_script "REVER_PATCH")
# Extract values from project-version.sh script
VERSION_MAJOR_FILE1=$(extract_from_script "PROJECT_VERSION_MAJOR")
VERSION_MINOR_FILE1=$(extract_from_script "PROJECT_VERSION_MINOR")
VERSION_PATCH_FILE1=$(extract_from_script "PROJECT_VERSION_PATCH")

# Extract values from generated header file
VERSION_MAJOR_FILE2=$(extract_from_header "VERSION_MAJOR")
Expand Down

0 comments on commit d678d04

Please sign in to comment.