Skip to content

Commit

Permalink
Merge pull request #4432 from gudnimg/fix-compiler-warning-sha
Browse files Browse the repository at this point in the history
Fix `FW_COMMIT_HASH` compiler warning
  • Loading branch information
3d-gussner authored Oct 11, 2023
2 parents a90086b + fe893f8 commit 0b5cf40
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
submodules: true
fetch-depth: 0

- name: Checkout ${{ github.event.ref }}
uses: actions/checkout@v3
if: ${{ !github.event.pull_request }}
with:
ref: ${{ github.event.ref }}
submodules: true
fetch-depth: 0

- name: Cache Dependencies
uses: actions/cache@v3.0.11
Expand Down Expand Up @@ -126,13 +128,15 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
submodules: true
fetch-depth: 0

- name: Checkout ${{ github.event.ref }}
uses: actions/checkout@v3
if: ${{ !github.event.pull_request }}
with:
ref: ${{ github.event.ref }}
submodules: true
fetch-depth: 0

- name: Cache Dependencies
uses: actions/cache@v3.0.11
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if (NO_TAG_IS_FATAL)
else()
MESSAGE(STATUS "Git was not found or an error occurred parsing the tag. Falling back to Configuration.h values (${PROJECT_VERSION}).")
endif()
set(FW_COMMIT_HASH "0") # Clear it, the code expects a binary...
set(FW_COMMIT_HASH ${FW_COMMIT_HASH_UNKNOWN}) # Clear it, the code expects a binary...
set(PROJECT_VERSION_TIMESTAMP "0")
endif()

Expand Down Expand Up @@ -367,7 +367,8 @@ function(add_base_binary variant_name)
target_compile_definitions(
${variant_name}
PRIVATE CMAKE_CONTROL FW_REPOSITORY="${PROJECT_REPOSITORY}"
FW_COMMIT_HASH=0x${FW_COMMIT_HASH}
FW_COMMIT_HASH="${FW_COMMIT_HASH}"
FW_COMMIT_HASH_LENGTH=${FW_COMMIT_HASH_LENGTH}
FW_MAJOR=${PROJECT_VERSION_MAJOR}
FW_MINOR=${PROJECT_VERSION_MINOR}
FW_REVISION=${PROJECT_VERSION_REV}
Expand Down Expand Up @@ -438,7 +439,7 @@ function(fw_add_variant variant_name)
add_custom_target(
check_lang_${variant_name}_${LANG}
COMMENT "Checking ${variant_name} language ${LANG}"
COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-check.py --map ${LANG_MAP} ${PO_FILE}
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_SOURCE_DIR}/lang/lang-check.py --map ${LANG_MAP} ${PO_FILE}
DEPENDS ${LANG_MAP} ${PO_FILE}
USES_TERMINAL
)
Expand Down Expand Up @@ -510,7 +511,7 @@ function(fw_add_variant variant_name)
add_custom_command(
OUTPUT ${FW_LANG_FINAL}.bin
COMMAND ${CMAKE_OBJCOPY} -O binary ${FW_LANG_BASE} ${FW_LANG_FINAL}.bin
COMMAND ${CMAKE_SOURCE_DIR}/lang/lang-patchsec.py ${FW_LANG_BASE} ${LANG_BIN}
COMMAND "${Python3_EXECUTABLE}" ${CMAKE_SOURCE_DIR}/lang/lang-patchsec.py ${FW_LANG_BASE} ${LANG_BIN}
${FW_LANG_FINAL}.bin
DEPENDS ${FW_LANG_BASE} ${LANG_BIN}
COMMENT "Generating ${FW_LANG_FINAL}.bin"
Expand Down
3 changes: 2 additions & 1 deletion Firmware/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ extern const char _sPrinterMmuName[] PROGMEM;

// The full version string and repository source are set via cmake
#ifndef CMAKE_CONTROL
#define FW_COMMIT_HASH 0
#define FW_COMMIT_HASH_LENGTH 1
#define FW_COMMIT_HASH "0"
#define FW_REPOSITORY "Unknown"
#define FW_VERSION_FULL FW_VERSION "-unknown"
#endif
Expand Down
8 changes: 7 additions & 1 deletion Firmware/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const uint16_t FW_VERSION_NR[4] PROGMEM = {
FW_TWEAK,
};

const uint32_t FW_VERSION_HASH PROGMEM = FW_COMMIT_HASH;
const char FW_VERSION_HASH[] PROGMEM = FW_COMMIT_HASH;
static_assert(sizeof(FW_VERSION_HASH) == FW_COMMIT_HASH_LENGTH + 1);

const char* FW_VERSION_HASH_P()
{
return FW_VERSION_HASH;
}

const char* FW_VERSION_STR_P()
{
Expand Down
6 changes: 3 additions & 3 deletions Firmware/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <stdint.h>

extern const uint16_t FW_VERSION_NR[4];
extern const char* FW_VERSION_STR_P();
const char* FW_VERSION_STR_P();

extern const uint32_t FW_VERSION_HASH PROGMEM;
static inline uint32_t FW_VERSION_HASH_P() { return (uint32_t)pgm_read_dword(&FW_VERSION_HASH); }
extern const char FW_VERSION_HASH[];
const char* FW_VERSION_HASH_P();

// Definition of a firmware flavor numerical values.
// To keep it short as possible
Expand Down
16 changes: 14 additions & 2 deletions cmake/ProjectVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,30 @@ ENDIF()

set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_REV}.${PROJECT_VERSION_TWEAK}")

# Define a constant length for the commit hash
set(FW_COMMIT_HASH_LENGTH 9)

# Create fallback value with constant length
string(REPEAT "0" ${FW_COMMIT_HASH_LENGTH} FW_COMMIT_HASH_UNKNOWN)

function(resolve_version_variables)
if(FW_COMMIT_DSC)
return()
endif()
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
git_head_commit_data(FW_COMMIT_HASH "%h")

# Get the full commit hash
git_head_commit_data(FW_COMMIT_HASH "%H")

# Keep only the first 'FW_COMMIT_HASH_LENGTH' characters
string(SUBSTRING "${FW_COMMIT_HASH}" 0 ${FW_COMMIT_HASH_LENGTH} FW_COMMIT_HASH)

set(ERRORS "GIT-NOTFOUND" "HEAD-FORMAT-NOTFOUND")
if(FW_COMMIT_HASH IN_LIST ERRORS)
# git not available, set fallback values
set(FW_COMMIT_HASH "UNKNOWN")
set(FW_COMMIT_HASH ${FW_COMMIT_HASH_UNKNOWN})
set(FW_COMMIT_DSC "v${PROJECT_VERSION}-${FW_COMMIT_HASH}")
string(TIMESTAMP FW_COMMIT_DATE "%s")
else()
Expand Down

0 comments on commit 0b5cf40

Please sign in to comment.