Skip to content

Commit

Permalink
Git Info in Makefile (#141)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Rubacha <[email protected]>
Co-authored-by: Jake-Hensley <[email protected]>
  • Loading branch information
3 people authored Jan 18, 2025
1 parent 8692b02 commit 24bfd17
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
fi
35 changes: 35 additions & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "shep_tasks.h"

#include "assert.h"
#include "string.h"

/* USER CODE END Includes */

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24bfd17

Please sign in to comment.