From 24bfd17bf002ce74a5e3cab0244491d4c59ab576 Mon Sep 17 00:00:00 2001 From: Dylan Donahue <98500199+dyldonahue@users.noreply.github.com> Date: Sat, 18 Jan 2025 12:35:22 -0500 Subject: [PATCH] Git Info in Makefile (#141) Co-authored-by: Jack Rubacha Co-authored-by: Jake-Hensley --- .github/workflows/build-check.yml | 8 +++---- Core/Src/main.c | 35 +++++++++++++++++++++++++++++++ Drivers/Embedded-Base | 2 +- Makefile | 26 +++++++++++++++++++++++ 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-check.yml b/.github/workflows/build-check.yml index 5ee76bbc..2390778a 100644 --- a/.github/workflows/build-check.yml +++ b/.github/workflows/build-check.yml @@ -3,18 +3,16 @@ on: [push] jobs: run-build: runs-on: ubuntu-latest - container: - image: ghcr.io/northeastern-electric-racing/embedded-base:main timeout-minutes: 10 steps: - name: Checkout code uses: actions/checkout@v4 with: submodules: recursive - + fetch-depth: 0 - name: Execute Make run: | - if ! make; then + if ! docker compose run --rm ner-gcc-arm make -j `nproc`; then echo "The application has failed to build." exit 1 # This will cause the workflow to fail - fi \ No newline at end of file + fi diff --git a/Core/Src/main.c b/Core/Src/main.c index 3df7929b..199bb058 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -25,6 +25,7 @@ #include "shep_tasks.h" #include "assert.h" +#include "string.h" /* USER CODE END Includes */ @@ -1185,6 +1186,37 @@ void watchdog_pet(void) } +struct __attribute__((__packed__)) git_version_data { + uint8_t git_major_version; + uint8_t git_minor_version; + uint8_t git_patch_version; + bool git_is_upstream_clean; + bool git_is_local_clean; + } git_version_data; + + struct __attribute__((__packed__)) git_hash_data { + uint32_t git_shorthash; + uint32_t git_authorhash; + } git_hash_data; + +/** + * @brief Sends git version infomation as a can message + */ +void send_git_version_message() { + //const struct git_hash_data git_hash_data2 = {GIT_SHORTHASH , GIT_AUTHORHASH}; + const struct git_version_data git_version_data2 = {GIT_MAJOR_VERSION , GIT_MINOR_VERSION, GIT_PATCH_VERSION, GIT_IS_UPSTREAM_CLEAN, GIT_IS_LOCAL_CLEAN}; + + can_msg_t msg1 = { .id = 0x698, .len = sizeof(git_version_data2)}; + //can_msg_t msg2 = { .id = 0x699, .len = sizeof(git_hash_data2)}; + + memcpy(&msg1.data, &git_version_data2, sizeof(git_version_data2)); + //memcpy(&msg2.data, &git_hash_data2, sizeof(git_hash_data2)); + + queue_can_msg(msg1); + //queue_can_msg(msg2); + +} + /* USER CODE END 4 */ /* USER CODE BEGIN Header_StartDefaultTask */ @@ -1220,6 +1252,9 @@ void StartDefaultTask(void *argument) segment_is_balancing()); compute_send_fault_status_message(bmsdata); + send_git_version_message(); + + HAL_IWDG_Refresh(&hiwdg); osDelay(1000); diff --git a/Drivers/Embedded-Base b/Drivers/Embedded-Base index f6ffa63e..83258635 160000 --- a/Drivers/Embedded-Base +++ b/Drivers/Embedded-Base @@ -1 +1 @@ -Subproject commit f6ffa63e1dc78f1cdff5c0196e2a43e901b8d0f6 +Subproject commit 83258635fc749ac72adb4b52e61f4f1a42e1842f diff --git a/Makefile b/Makefile index 32ae496f..bf8eede5 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,32 @@ ###################################### TARGET = shepherd2 +###################################### +# git +###################################### +GIT_MAJOR_VERSION := $(shell git describe --tags --abbrev=0 | cut -c2- | cut -d'.' -f1) +GIT_MINOR_VERSION := $(shell git describe --tags --abbrev=0 | cut -c2- | cut -d'.' -f2) +GIT_PATCH_VERSION := $(shell git describe --tags --abbrev=0 | cut -c2- | cut -d'.' -f3) +GIT_IS_UPSTREAM_CLEAN := $(shell bash -c 'git merge-base --is-ancestor HEAD @{u} && echo 0 || echo 1') +GIT_IS_LOCAL_CLEAN := $(shell bash -c 'test -z "$$(git status --porcelain)" && echo 0 || echo 1') +GIT_SHORTHASH := $(shell git rev-parse --short=8 HEAD) +GIT_AUTHORHASH := $(shell bash -c 'git log -n 1 --format=%h --author=$(git config --get user.name)') + + +all: + @echo "VERSION: $(GIT_MAJOR_VERSION).$(GIT_MINOR_VERSION).$(GIT_PATCH_VERSION)" + @echo "UNPUSHED CHANGES: $(GIT_IS_UPSTREAM_CLEAN)" + @echo "UNCOMMITTED CHANGES: $(GIT_IS_LOCAL_CLEAN)" + @echo "COMMIT HASH: $(GIT_SHORTHASH)" + @echo "AUTHOR HASH: $(GIT_AUTHORHASH)" + +CFLAGS += -DGIT_MAJOR_VERSION=$(GIT_MAJOR_VERSION) \ + -DGIT_MINOR_VERSION=$(GIT_MINOR_VERSION) \ + -DGIT_PATCH_VERSION=$(GIT_PATCH_VERSION) \ + -DGIT_IS_UPSTREAM_CLEAN=$(GIT_IS_UPSTREAM_CLEAN) \ + -DGIT_IS_LOCAL_CLEAN=$(GIT_IS_LOCAL_CLEAN) \ + -DGIT_SHORTHASH=$(GIT_SHORTHASH) \ + -DGIT_AUTHORHASH=$(GIT_AUTHORHASH) ###################################### # building variables