Skip to content

Commit

Permalink
Added dirty build flag to version structure & interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hedger committed Apr 12, 2022
1 parent f9b5970 commit e482e2f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 10 deletions.
3 changes: 2 additions & 1 deletion applications/about/about.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ static DialogMessageButton fw_version_screen(DialogsApp* dialogs, DialogMessage*
} else {
string_cat_printf(
buffer,
"%s [%s]\n%s [%s]\n[%d] %s",
"%s [%s]\n%s%s [%s]\n[%d] %s",
version_get_version(ver),
version_get_builddate(ver),
version_get_dirty_flag(ver) ? "[!] " : "",
version_get_githash(ver),
version_get_gitbranchnum(ver),
version_get_target(ver),
Expand Down
3 changes: 2 additions & 1 deletion applications/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ void cli_motd() {
const Version* firmware_version = furi_hal_version_get_firmware_version();
if(firmware_version) {
printf(
"Firmware version: %s %s (%s built on %s)\r\n",
"Firmware version: %s %s (%s%s built on %s)\r\n",
version_get_gitbranch(firmware_version),
version_get_version(firmware_version),
version_get_githash(firmware_version),
version_get_dirty_flag(firmware_version) ? "-dirty" : "",
version_get_builddate(firmware_version));
}
}
Expand Down
3 changes: 2 additions & 1 deletion applications/desktop/views/desktop_view_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void desktop_debug_render(Canvas* canvas, void* model) {
snprintf(
buffer,
sizeof(buffer),
"%s [%s]",
"%s%s [%s]",
version_get_dirty_flag(ver) ? "[!] " : "",
version_get_githash(ver),
version_get_gitbranchnum(ver));
canvas_draw_str(canvas, 5, 39 + STATUS_BAR_Y_SHIFT, buffer);
Expand Down
3 changes: 2 additions & 1 deletion core/flipper.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ static void flipper_print_version(const char* target, const Version* version) {
TAG,
"\r\n\t%s version:\t%s\r\n"
"\tBuild date:\t\t%s\r\n"
"\tGit Commit:\t\t%s (%s)\r\n"
"\tGit Commit:\t\t%s (%s)%s\r\n"
"\tGit Branch:\t\t%s",
target,
version_get_version(version),
version_get_builddate(version),
version_get_githash(version),
version_get_gitbranchnum(version),
version_get_dirty_flag(version) ? " (dirty)" : "",
version_get_gitbranch(version));
} else {
FURI_LOG_I(TAG, "No build info for %s", target);
Expand Down
6 changes: 5 additions & 1 deletion firmware/targets/f7/furi_hal/furi_hal_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ void furi_hal_info_get(FuriHalInfoValueCallback out, void* context) {
const Version* firmware_version = furi_hal_version_get_firmware_version();
if(firmware_version) {
out("firmware_commit", version_get_githash(firmware_version), false, context);
out("firmware_commit_dirty",
version_get_dirty_flag(firmware_version) ? "true" : "false",
false,
context);
out("firmware_branch", version_get_gitbranch(firmware_version), false, context);
out("firmware_branch_num", version_get_gitbranchnum(firmware_version), false, context);
out("firmware_version", version_get_version(firmware_version), false, context);
Expand Down Expand Up @@ -127,4 +131,4 @@ void furi_hal_info_get(FuriHalInfoValueCallback out, void* context) {
out("protobuf_version_minor", string_get_cstr(value), true, context);

string_clear(value);
}
}
6 changes: 6 additions & 0 deletions lib/toolbox/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct Version {
const char* build_date;
const char* version;
const uint8_t target;
const bool build_is_dirty;
};

/* version of current running firmware (bootloader/flipper) */
Expand All @@ -21,6 +22,7 @@ static const Version version = {
#endif
,
.target = TARGET,
.build_is_dirty = BUILD_DIRTY,
};

const Version* version_get(void) {
Expand Down Expand Up @@ -49,4 +51,8 @@ const char* version_get_version(const Version* v) {

uint8_t version_get_target(const Version* v) {
return v ? v->target : version.target;
}

bool version_get_dirty_flag(const Version* v) {
return v ? v->build_is_dirty : version.build_is_dirty;
}
12 changes: 11 additions & 1 deletion lib/toolbox/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -72,6 +73,15 @@ const char* version_get_version(const Version* v);
*/
uint8_t version_get_target(const Version* v);

/** Get flag indicating if this build is "dirty" (source code had uncommited changes)
*
* @param v pointer to Version data. NULL for currently running
* software.
*
* @return build date
*/
bool version_get_dirty_flag(const Version* v);

#ifdef __cplusplus
}
#endif
#endif
14 changes: 10 additions & 4 deletions make/git.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ GIT_BRANCH_NUM := $(shell git rev-list --count HEAD || echo 'nan')
BUILD_DATE := $(shell date '+%d-%m-%Y' || echo 'unknown')
BUILD_TIME := $(shell date '+%H:%M:%S' || echo 'unknown')
VERSION := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null || echo 'unknown')
GIT_CLEAN_BUILD := $(shell git diff --quiet || echo '-dirty')
GIT_DIRTY_BUILD := $(shell git diff --quiet || echo $$?)

GIT_DIRTY_SUFFIX :=
ifeq ($(GIT_DIRTY_BUILD), 1)
GIT_DIRTY_SUFFIX := '-dirty'
endif

CFLAGS += \
-DGIT_COMMIT=\"$(GIT_COMMIT)\" \
-DGIT_BRANCH=\"$(GIT_BRANCH)\" \
-DGIT_BRANCH_NUM=\"$(GIT_BRANCH_NUM)\" \
-DBUILD_DATE=\"$(BUILD_DATE)\" \
-DVERSION=\"$(VERSION)\" \
-DTARGET=$(HARDWARE_TARGET)
-DTARGET=$(HARDWARE_TARGET) \
-DBUILD_DIRTY=$(GIT_DIRTY_BUILD)

# if suffix is set in environment (by Github), use it
ifeq (${DIST_SUFFIX},)
DIST_SUFFIX := local-$(GIT_COMMIT)$(GIT_CLEAN_BUILD)
DIST_SUFFIX := local-$(GIT_COMMIT)$(GIT_DIRTY_SUFFIX)
else
DIST_SUFFIX := ${DIST_SUFFIX}
DIST_SUFFIX := ${DIST_SUFFIX}$(GIT_DIRTY_SUFFIX)
endif

#VERSION_STRING := $(VERSION) ($(GIT_BRANCH) @ $(GIT_COMMIT)), built $(BUILD_DATE) $(BUILD_TIME)
Expand Down

0 comments on commit e482e2f

Please sign in to comment.