diff --git a/cereal b/cereal index bd31b25aac..7de3c7111e 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit bd31b25aacc5b39f36cedcb0dabd05db471da59f +Subproject commit 7de3c7111e78d87f9c43e2861a3e18aa59fde956 diff --git a/common/params.cc b/common/params.cc index 3ce2505243..eb75705ca3 100644 --- a/common/params.cc +++ b/common/params.cc @@ -125,6 +125,7 @@ std::unordered_map keys = { {"ForcePowerDown", PERSISTENT}, {"GitBranch", PERSISTENT}, {"GitCommit", PERSISTENT}, + {"GitCommitDate", PERSISTENT}, {"GitDiff", PERSISTENT}, {"GithubSshKeys", PERSISTENT}, {"GithubUsername", PERSISTENT}, diff --git a/selfdrive/manager/manager.py b/selfdrive/manager/manager.py index 50ba73f18c..bf1eeb8fd0 100755 --- a/selfdrive/manager/manager.py +++ b/selfdrive/manager/manager.py @@ -19,7 +19,7 @@ from openpilot.selfdrive.athena.registration import register, UNREGISTERED_DONGL from openpilot.common.swaglog import cloudlog, add_file_handler from openpilot.system.version import is_dirty, get_commit, get_version, get_origin, get_short_branch, \ get_normalized_origin, terms_version, training_version, \ - is_tested_branch, is_release_branch + is_tested_branch, is_release_branch, get_commit_date @@ -66,6 +66,7 @@ def manager_init() -> None: params.put("TermsVersion", terms_version) params.put("TrainingVersion", training_version) params.put("GitCommit", get_commit()) + params.put("GitCommitDate", get_commit_date()) params.put("GitBranch", get_short_branch()) params.put("GitRemote", get_origin()) params.put_bool("IsTestedBranch", is_tested_branch()) diff --git a/system/loggerd/logger.cc b/system/loggerd/logger.cc index 2fc6492ad4..7a829a2f1f 100644 --- a/system/loggerd/logger.cc +++ b/system/loggerd/logger.cc @@ -44,6 +44,7 @@ kj::Array logger_build_init_data() { std::map params_map = params.readAll(); init.setGitCommit(params_map["GitCommit"]); + init.setGitCommitDate(params_map["GitCommitDate"]); init.setGitBranch(params_map["GitBranch"]); init.setGitRemote(params_map["GitRemote"]); init.setPassive(false); diff --git a/system/loggerd/tests/test_loggerd.py b/system/loggerd/tests/test_loggerd.py index 0cd8548809..963978926d 100755 --- a/system/loggerd/tests/test_loggerd.py +++ b/system/loggerd/tests/test_loggerd.py @@ -107,6 +107,7 @@ class TestLoggerd: # param, initData field, value ("DongleId", "dongleId", dongle), ("GitCommit", "gitCommit", "commit"), + ("GitCommitDate", "gitCommitDate", "date"), ("GitBranch", "gitBranch", "branch"), ("GitRemote", "gitRemote", "remote"), ] diff --git a/system/version.py b/system/version.py index 980a4fcc7c..e34458f16f 100755 --- a/system/version.py +++ b/system/version.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import os import subprocess -from typing import List, Optional, Callable, TypeVar +from typing import List, Callable, TypeVar from functools import lru_cache from openpilot.common.basedir import BASEDIR @@ -22,7 +22,7 @@ def run_cmd(cmd: List[str]) -> str: return subprocess.check_output(cmd, encoding='utf8').strip() -def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[str]: +def run_cmd_default(cmd: List[str], default: str = "") -> str: try: return run_cmd(cmd) except subprocess.CalledProcessError: @@ -31,17 +31,22 @@ def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[s @cache def get_commit(branch: str = "HEAD") -> str: - return run_cmd_default(["git", "rev-parse", branch]) or "" + return run_cmd_default(["git", "rev-parse", branch]) + + +@cache +def get_commit_date(commit: str = "HEAD") -> str: + return run_cmd_default(["git", "show", "--no-patch", "--format='%ct %ci'", commit]) @cache def get_short_branch() -> str: - return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "HEAD"]) or "" + return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "HEAD"]) @cache def get_branch() -> str: - return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]) or "" + return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]) @cache @@ -51,7 +56,7 @@ def get_origin() -> str: tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"]) return run_cmd(["git", "config", "remote." + tracking_remote + ".url"]) except subprocess.CalledProcessError: # Not on a branch, fallback - return run_cmd_default(["git", "config", "--get", "remote.origin.url"]) or "" + return run_cmd_default(["git", "config", "--get", "remote.origin.url"]) @cache @@ -132,3 +137,4 @@ if __name__ == "__main__": print(f"Branch: {get_branch()}") print(f"Short branch: {get_short_branch()}") print(f"Prebuilt: {is_prebuilt()}") + print(f"Commit date: {get_commit_date()}")