From 0d19282ba2d68b0baa187e9632d27493bf5f5eef Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Thu, 2 May 2024 22:34:34 +0100 Subject: [PATCH] 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)