diff --git a/.circleci/config.yml b/.circleci/config.yml index bfa30c4..da6c232 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -36,8 +36,11 @@ jobs: command: | export SOFTWARE_VERSION=$(cat src/Config.h | grep -w SOFTWARE_VERSION | cut -d'"' -f 2 | cut -d'\' -f 1) strings bin/arduino_firmware.hex.bin | grep $SOFTWARE_VERSION - mkdir bin/$SOFTWARE_VERSION + export SHORT_COMMIT_SHA=$(echo $CIRCLE_SHA1 | cut -c1-8) + export COMMIT_SUFFIX=$(strings bin/arduino_firmware.hex.bin | grep $SHORT_COMMIT_SHA) + export NEW_FW_DIR=bin/$SOFTWARE_VERSION$COMMIT_SUFFIX + mkdir $NEW_FW_DIR rm bin/*.bin - mv bin/*.hex bin/$SOFTWARE_VERSION + mv bin/*.hex $NEW_FW_DIR - store_artifacts: path: bin diff --git a/.gitignore b/.gitignore index 83b0baf..05e4a07 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ bin src.ino.cpp src.ino.mega.hex src.ino.with_bootloader.mega.hex +src/CommitSHA.h diff --git a/Makefile b/Makefile index 82210a3..e9ba559 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,11 @@ FBARDUINO_FIRMWARE_LIB_BUILD_DIR ?= $(BUILD_DIR)/libraries ARDUINO_INSTALL_DIR ?= $(HOME)/arduino-1.8.11 +# Get current commit SHA +COMMIT_SHA := $(shell git -C $(FBARDUINO_FIRMWARE_SRC_DIR)/.. rev-parse --short=8 HEAD) +MODIFIER := $(shell echo $$(if [ -z "$$(git -C $(FBARDUINO_FIRMWARE_SRC_DIR)/.. status -s -uall)" ];then echo "";else echo "+";fi)) +CREATE_COMMIT_SHA_H := $(shell echo "\#ifndef COMMIT_SHA_H_\n\#define COMMIT_SHA_H_\n\#define SOFTWARE_COMMIT \"-$(COMMIT_SHA)$(MODIFIER)\"\n\#endif" > $(FBARDUINO_FIRMWARE_SRC_DIR)/CommitSHA.h) + # Files to be tracked for make to know to rebuild. COPY_INO := $(shell cp $(FBARDUINO_FIRMWARE_SRC_DIR)/src.ino $(FBARDUINO_FIRMWARE_SRC_DIR)/src.ino.cpp) CXX_SRC := $(wildcard $(FBARDUINO_FIRMWARE_SRC_DIR)/*.cpp) @@ -42,7 +47,7 @@ include lib/targets/farmduino_k14.Makefile include lib/targets/farmduino_k15.Makefile include lib/targets/express_k10.Makefile -.PHONY: all clean force_clean remove_ino_copy \ +.PHONY: all clean strings_test force_clean remove_temp \ dep_core dep_core_clean \ dep_Servo dep_Servo_clean \ dep_SPI dep_SPI_clean \ @@ -57,9 +62,9 @@ DEPS := $(DEP_CORE) $(DEP_SPI) $(DEP_Servo) $(DEP_EEPROM) DEPS_OBJ := $(DEP_SPI_OBJ) $(DEP_Servo_OBJ) $(DEP_EEPROM_OBJ) DEPS_CFLAGS := $(DEP_CORE_CFLAGS) $(DEP_SPI_CFLAGS) $(DEP_Servo_CFLAGS) $(DEP_EEPROM_CFLAGS) -all: $(BIN_DIR) $(DEPS) target_ramps_v14 target_farmduino_v10 target_farmduino_k14 target_farmduino_k15 target_express_k10 remove_ino_copy +all: $(BIN_DIR) $(DEPS) target_ramps_v14 target_farmduino_v10 target_farmduino_k14 target_farmduino_k15 target_express_k10 remove_temp -clean: remove_ino_copy target_ramps_v14_clean target_farmduino_v10_clean target_farmduino_k14_clean target_farmduino_k15_clean target_express_k10_clean +clean: remove_temp target_ramps_v14_clean target_farmduino_v10_clean target_farmduino_k14_clean target_farmduino_k15_clean target_express_k10_clean strings_test: all $(OBJ_COPY) -I ihex $(TARGET_ramps_v14_HEX) -O binary $(TARGET_ramps_v14_HEX).bin @@ -73,11 +78,12 @@ strings_test: all @strings $(TARGET_farmduino_k15_HEX).bin | grep -q ".H.genesisK15" @strings $(TARGET_express_k10_HEX).bin | grep -q ".E.expressK10" -force_clean: remove_ino_copy +force_clean: remove_temp $(RM) -r $(BUILD_DIR) $(BIN_DIR) $(BIN_DIR): $(MKDIR_P) $(BIN_DIR) -remove_ino_copy: +remove_temp: $(RM) $(FBARDUINO_FIRMWARE_SRC_DIR)/src.ino.cpp + $(RM) $(FBARDUINO_FIRMWARE_SRC_DIR)/CommitSHA.h diff --git a/src/Config.h b/src/Config.h index 3b01feb..0f5dab7 100644 --- a/src/Config.h +++ b/src/Config.h @@ -259,3 +259,9 @@ enum MdlSpiEncoders #if defined(FARMDUINO_EXP_V20) && !defined(SOFTWARE_VERSION_SUFFIX) #define SOFTWARE_VERSION_SUFFIX ".E.expressK10\0" #endif + +#ifndef FARMBOT_BOARD_ID +#define SOFTWARE_COMMIT "" +#else +#include "CommitSHA.h" +#endif diff --git a/src/F83Handler.cpp b/src/F83Handler.cpp index 3aea3e6..fa2321b 100644 --- a/src/F83Handler.cpp +++ b/src/F83Handler.cpp @@ -35,6 +35,7 @@ int F83Handler::execute(Command *command) Serial.print("R83 "); Serial.print(SOFTWARE_VERSION); Serial.print(SOFTWARE_VERSION_SUFFIX); + Serial.print(SOFTWARE_COMMIT); //Serial.print("\r\n"); CurrentState::getInstance()->printQAndNewLine();