From 0d19282ba2d68b0baa187e9632d27493bf5f5eef Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Thu, 2 May 2024 22:34:34 +0100 Subject: [PATCH 1/2] fix: remove python dependency for a build script --- src/Makefile | 2 +- src/build-scripts/hydrafw-version | 19 ++++++++++++++++++ src/build-scripts/hydrafw-version.py | 30 ---------------------------- 3 files changed, 20 insertions(+), 31 deletions(-) create mode 100755 src/build-scripts/hydrafw-version delete mode 100644 src/build-scripts/hydrafw-version.py diff --git a/src/Makefile b/src/Makefile index 874fa5ca..f8bc2cee 100644 --- a/src/Makefile +++ b/src/Makefile @@ -341,7 +341,7 @@ FORCE: %.hdr: FORCE $(OUT_LOG) echo Creating ./common/hydrafw_version.hdr $(OUT_CMD) rm -f $(OBJDIR)/common.o - $(OUT_CMD) $(PYTHON) build-scripts/hydrafw-version.py ./common/hydrafw_version.hdr + $(OUT_CMD) build-scripts/hydrafw-version ./common/hydrafw_version.hdr %.dfu: %.hex $(LDSCRIPT) $(OUT_LOG) echo Creating $@ diff --git a/src/build-scripts/hydrafw-version b/src/build-scripts/hydrafw-version new file mode 100755 index 00000000..c1f398a6 --- /dev/null +++ b/src/build-scripts/hydrafw-version @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +if [ $# -eq 1 ] +then + exec > $1 # directing stdout to the file passed as argument + vermagic=$(git describe --tags --always --dirty --long) + if [[ -n "$GITHUB_CI_PR_SHA" ]]; then + # if GITHUB_CI_PR_SHA is set, then it's GitHub Actions build, so workaround to set a valid tag is required + sha_id=${GITHUB_CI_PR_SHA:0:7} + vermagic=$(echo ${vermagic} | sed "s/-g.*$/-g${sha_id}/") + fi + echo "#define HYDRAFW_GIT_TAG \"$vermagic\"" + echo "#define HYDRAFW_CHECKIN_DATE \"$(git show -s --pretty=format:%ai | cut -d' ' -f1)\"" +else + echo "usage: $0 outfile.txt" + exit 1 +fi diff --git a/src/build-scripts/hydrafw-version.py b/src/build-scripts/hydrafw-version.py deleted file mode 100644 index 1f3bd6aa..00000000 --- a/src/build-scripts/hydrafw-version.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import os -import re -from optparse import OptionParser -from datetime import * -from git import * - -if __name__=="__main__": - usage = """ -%prog outfile.txt""" - -parser = OptionParser(usage=usage) -(options, args) = parser.parse_args() -if len(args)==1: - sys.stdout = open(args[0], 'w') - git=Repo(search_parent_directories=True).git - vermagic=git.describe(tags=True,always=True,dirty=True,long=True) - if os.environ.get("GITHUB_CI_PR_SHA", "") != "": - # if GITHUB_CI_PR_SHA is set, then it's GitHub Actions build, so workaround to set a valid tag is required - sha_id=os.environ["GITHUB_CI_PR_SHA"][:7] - print('#define HYDRAFW_GIT_TAG "' + re.sub('-g.*$', '-g' + sha_id, vermagic) + '"') - else: - # If it's local build, then set "normal" tag - print('#define HYDRAFW_GIT_TAG "' + vermagic + '"') - print('#define HYDRAFW_CHECKIN_DATE "' + git.show(['-s', '--pretty=format:%ai']).partition(' ')[0] + '"') -else: - parser.print_help() - sys.exit(1) From 392dfc921dd714373225f84f4f64b85855a3510e Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Thu, 2 May 2024 22:46:50 +0100 Subject: [PATCH 2/2] fix: remove python dependency for revision build script --- src/Makefile | 2 +- src/build-scripts/hydrafw-revision | 14 ++++++++++++++ src/build-scripts/hydrafw-revision.py | 13 ------------- 3 files changed, 15 insertions(+), 14 deletions(-) create mode 100755 src/build-scripts/hydrafw-revision delete mode 100644 src/build-scripts/hydrafw-revision.py diff --git a/src/Makefile b/src/Makefile index f8bc2cee..50e4a519 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ export STM32F4XX ?= 1 # Set to 1 HYDRAFW_NFC to include HydraNFC extension support export HYDRAFW_NFC ?= 1 export HYDRAFW_DEBUG ?= 0 -export FW_REVISION := $(shell $(PYTHON) build-scripts/hydrafw-revision.py) +export FW_REVISION := $(shell build-scripts/hydrafw-revision) HYDRAFW_OPTS = diff --git a/src/build-scripts/hydrafw-revision b/src/build-scripts/hydrafw-revision new file mode 100755 index 00000000..8a1f56ca --- /dev/null +++ b/src/build-scripts/hydrafw-revision @@ -0,0 +1,14 @@ +#!/bin/bash + +# Get the version description from git +version=$(git describe --tags --always --dirty --long) + +# Use regex to match version pattern v(x.x) +if [[ $version =~ v([0-9]+\.[0-9]+).* ]] +then + # If match found, print the version + echo ${BASH_REMATCH[1]} +else + # Print 0.0 if no match is found + echo "0.0" +fi diff --git a/src/build-scripts/hydrafw-revision.py b/src/build-scripts/hydrafw-revision.py deleted file mode 100644 index 1c70982e..00000000 --- a/src/build-scripts/hydrafw-revision.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python3 - -from git import * -import re - -r = re.compile("v(\d+\.\d+).*") - -git=Repo(search_parent_directories=True).git -version = git.describe(tags=True,always=True,dirty=True,long=True) -if r.search(version): - print(r.search(version).group(1)) -else: - print("0.0")