diff --git a/applications/main/momentum_app/momentum_app.c b/applications/main/momentum_app/momentum_app.c index 7bfd7d5c0..e0d97d1e9 100644 --- a/applications/main/momentum_app/momentum_app.c +++ b/applications/main/momentum_app/momentum_app.c @@ -351,13 +351,15 @@ MomentumApp* momentum_app_alloc() { app->dolphin_angry = stats.butthurt; furi_record_close(RECORD_DOLPHIN); + // Will be "(version) (commit or date)" app->version_tag = furi_string_alloc_set(version_get_version(NULL)); - size_t separator = furi_string_search_char(app->version_tag, '-', strlen("mntm-")); - Canvas* canvas = gui_direct_draw_acquire(app->gui); // Need canvas to calculate text length + size_t separator = furi_string_size(app->version_tag); + // Need canvas to calculate text length + Canvas* canvas = gui_direct_draw_acquire(app->gui); canvas_set_font(canvas, FontPrimary); - if(separator != FURI_STRING_FAILURE) { - // Change second - to space - furi_string_set_char(app->version_tag, separator, ' '); + if(furi_string_equal(app->version_tag, "mntm-dev")) { + // Add space, add commit sha + furi_string_cat_printf(app->version_tag, " %s", version_get_githash(NULL)); // Make uppercase for(size_t i = 0; i < furi_string_size(app->version_tag); ++i) { furi_string_set_char( @@ -369,7 +371,6 @@ MomentumApp* momentum_app_alloc() { furi_string_left(app->version_tag, furi_string_size(app->version_tag) - 1); } } else { - separator = furi_string_size(app->version_tag); // Make uppercase, add space, add build date furi_string_replace(app->version_tag, "mntm", "MNTM"); furi_string_cat_printf(app->version_tag, " %s", version_get_builddate(NULL)); diff --git a/applications/settings/about/about.c b/applications/settings/about/about.c index 071384efa..710668fc4 100644 --- a/applications/settings/about/about.c +++ b/applications/settings/about/about.c @@ -171,21 +171,24 @@ static DialogMessageButton about_screen_fw_version(DialogsApp* dialogs, DialogMe } else { uint16_t api_major, api_minor; furi_hal_info_get_api_version(&api_major, &api_minor); - furi_string_set(buffer, version_get_version(ver)); - size_t sha_pos = furi_string_search_char(buffer, '-', strlen("mntm-")); - if(sha_pos != FURI_STRING_FAILURE) { - // Strip commit sha if present (non-release) - furi_string_left(buffer, sha_pos); - } furi_string_cat_printf( buffer, - " %s\n%s F%d:%d.%d %s\nmomentum-fw.dev", + "%s [%s]\n%s%s [%d.%d] %s\n[%d] ", + version_get_version(ver), version_get_builddate(ver), + version_get_dirty_flag(ver) ? "[!] " : "", version_get_githash(ver), - version_get_target(ver), api_major, api_minor, - c2_ver ? c2_ver->StackTypeString : ""); + c2_ver ? c2_ver->StackTypeString : "", + version_get_target(ver)); + if(!strcmp(version_get_version(ver), "mntm-dev") && + strcmp(version_get_gitbranch(ver), "dev")) { + // Not a tag but not dev branch, show custom branch + furi_string_cat(buffer, version_get_gitbranch(ver)); + } else { + furi_string_cat(buffer, "momentum-fw.dev"); + } } dialog_message_set_header(message, "Firmware Info:", 0, 0, AlignLeft, AlignTop); diff --git a/fbt_options.py b/fbt_options.py index 3da9c78bc..a31b56ace 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -31,13 +31,17 @@ if not os.environ.get("DIST_SUFFIX"): ) try: - local_branch = git("symbolic-ref", "HEAD", "--short") - ref = git("config", "--get", f"branch.{local_branch}.merge") + # For tags, dist name is just the tag name: mntm-(ver) + DIST_SUFFIX = git("describe", "--tags", "--abbrev=0", "--exact-match") except Exception: - ref = "refs/heads/detached" - branch_name = re.sub("refs/\w+/", "", ref) - commit_sha = git("rev-parse", "HEAD")[:8] - DIST_SUFFIX = "mntm-" + branch_name.replace("/", "_") + "-" + commit_sha + # If not a tag, dist name is: mntm-(branch)-(commmit) + branch_name = git("rev-parse", "--abbrev-ref", "HEAD").removeprefix("mntm-") + commit_sha = git("rev-parse", "HEAD")[:8] + DIST_SUFFIX = f"mntm-{branch_name}-{commit_sha}" + # Dist name is only for naming of output files + DIST_SUFFIX = DIST_SUFFIX.replace("/", "-") + # Instead, FW version uses tag name (mntm-xxx), or "mntm-dev" if not a tag (see scripts/version.py) + # You can get commit and branch info in firmware with appropriate version_get_*() calls # Skip external apps by default SKIP_EXTERNAL = False diff --git a/scripts/fbt_tools/fbt_version.py b/scripts/fbt_tools/fbt_version.py index 1f98206cb..0dd5d0feb 100644 --- a/scripts/fbt_tools/fbt_version.py +++ b/scripts/fbt_tools/fbt_version.py @@ -32,8 +32,6 @@ def generate(env): "${TARGET.dir.posix}", "--dir", "${ROOT_DIR}", - "--suffix", - "${DIST_SUFFIX}", ] ], "${VERSIONCOMSTR}", diff --git a/scripts/get_env.py b/scripts/get_env.py index 81f29b205..8d76e97fa 100755 --- a/scripts/get_env.py +++ b/scripts/get_env.py @@ -60,10 +60,13 @@ def get_details(event, args): data["commit_sha"] = data["commit_hash"][:8] data["branch_name"] = re.sub("refs/\w+/", "", ref) data["suffix"] = ( - "mntm-" + data["branch_name"].replace("/", "_") + "-" + data["commit_sha"] + "mntm-" + + data["branch_name"].removeprefix("mntm-").replace("/", "-") + + "-" + + data["commit_sha"] ) if ref.startswith("refs/tags/"): - data["suffix"] = data["branch_name"].replace("/", "_") + data["suffix"] = data["branch_name"].replace("/", "-") return data diff --git a/scripts/version.py b/scripts/version.py index bf2777a2d..9d226f83a 100755 --- a/scripts/version.py +++ b/scripts/version.py @@ -1,4 +1,5 @@ #!/usb/bin/env python3 + import json import os import subprocess @@ -10,9 +11,8 @@ from flipper.app import App class GitVersion: REVISION_SUFFIX_LENGTH = 8 - def __init__(self, source_dir, suffix): + def __init__(self, source_dir): self.source_dir = source_dir - self.suffix = suffix def get_version_info(self): commit = ( @@ -22,20 +22,26 @@ class GitVersion: dirty = False try: - self._exec_git("diff --quiet") + self._exec_git("diff HEAD --quiet") # Check both staged and not except subprocess.CalledProcessError as e: if e.returncode == 1: dirty = True + try: + tag = self._exec_git("describe --tags --abbrev=0 --exact-match") + except subprocess.CalledProcessError: + tag = "" + # If WORKFLOW_BRANCH_OR_TAG is set in environment, is has precedence # (set by CI) branch = ( os.environ.get("WORKFLOW_BRANCH_OR_TAG", None) - or self._exec_git("rev-parse --abbrev-ref HEAD") + or tag + or self._exec_git("rev-parse --abbrev-ref HEAD").removeprefix("mntm-") or "unknown" ) - version = self.suffix or os.environ.get("DIST_SUFFIX", None) or "unknown" + version = tag or "mntm-dev" if "SOURCE_DATE_EPOCH" in os.environ: commit_date = datetime.utcfromtimestamp( @@ -52,18 +58,33 @@ class GitVersion: "GIT_BRANCH": branch, "VERSION": version, "BUILD_DIRTY": dirty and 1 or 0, - "GIT_ORIGIN": self._get_git_origin(), + "GIT_ORIGIN": ",".join(self._get_git_origins()), "GIT_COMMIT_DATE": commit_date, } - def _get_git_origin(self): + def _get_git_origins(self): try: branch = self._exec_git("branch --show-current") remote = self._exec_git(f"config branch.{branch}.remote") origin = self._exec_git(f"remote get-url {remote}") - return origin + return set([origin]) except subprocess.CalledProcessError: - return "" + try: + remotes = self._exec_git("remote -v") + except subprocess.CalledProcessError: + remotes = "" + origins = set() + for line in remotes.split("\n"): + if not line: + continue + _, destination = line.split("\t") + url, _ = destination.split(" ") + origins.add(url) + break + if len(origins) == 1: + return origins + else: + return set(["https://github.com/Next-Flip/Momentum-Firmware"]) def _exec_git(self, args): cmd = ["git"] @@ -100,13 +121,10 @@ class Main(App): required=True, ) self.parser_generate.add_argument("--dir", dest="sourcedir", required=True) - self.parser_generate.add_argument("--suffix", dest="suffix", required=True) self.parser_generate.set_defaults(func=self.generate) def generate(self): - current_info = GitVersion( - self.args.sourcedir, self.args.suffix - ).get_version_info() + current_info = GitVersion(self.args.sourcedir).get_version_info() build_date = ( date.today()