From 95df2c9b485f20259bb672769a3a00b4791ef4dd Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 18 Jul 2022 21:18:10 -0700 Subject: [PATCH] updated: add branch switching (#25200) * switch param * add to ui * fix that * fetch for new branch Co-authored-by: Comma Device old-commit-hash: cc3857eb62cd169be05a4cb22c844a8b2ec94139 --- common/params.cc | 2 ++ selfdrive/manager/manager.py | 3 ++- selfdrive/ui/qt/offroad/settings.cc | 20 ++++++++++++++++++-- selfdrive/ui/qt/offroad/settings.h | 1 + selfdrive/ui/qt/widgets/controls.h | 4 ++-- selfdrive/updated.py | 20 ++++++++++++++------ 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/common/params.cc b/common/params.cc index 77be6f36b1..1ead28d6cd 100644 --- a/common/params.cc +++ b/common/params.cc @@ -126,6 +126,7 @@ std::unordered_map keys = { {"IsOnroad", PERSISTENT}, {"IsRHD", PERSISTENT}, {"IsTakingSnapshot", CLEAR_ON_MANAGER_START}, + {"IsTestedBranch", CLEAR_ON_MANAGER_START}, {"IsUpdateAvailable", CLEAR_ON_MANAGER_START}, {"JoystickDebugMode", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF}, {"LaikadEphemeris", PERSISTENT | DONT_LOG}, @@ -154,6 +155,7 @@ std::unordered_map keys = { {"SnoozeUpdate", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF}, {"SshEnabled", PERSISTENT}, {"SubscriberInfo", PERSISTENT}, + {"SwitchToBranch", CLEAR_ON_MANAGER_START}, {"TermsVersion", PERSISTENT}, {"Timezone", PERSISTENT}, {"TrainingVersion", PERSISTENT}, diff --git a/selfdrive/manager/manager.py b/selfdrive/manager/manager.py index 140c7f1d44..9c370cb3d8 100755 --- a/selfdrive/manager/manager.py +++ b/selfdrive/manager/manager.py @@ -20,7 +20,7 @@ from selfdrive.manager.process_config import managed_processes from selfdrive.athena.registration import register, UNREGISTERED_DONGLE_ID from system.swaglog import cloudlog, add_file_handler from system.version import is_dirty, get_commit, get_version, get_origin, get_short_branch, \ - terms_version, training_version + terms_version, training_version, is_tested_branch sys.path.append(os.path.join(BASEDIR, "pyextra")) @@ -78,6 +78,7 @@ def manager_init() -> None: params.put("GitCommit", get_commit(default="")) params.put("GitBranch", get_short_branch(default="")) params.put("GitRemote", get_origin(default="")) + params.put_bool("IsTestedBranch", is_tested_branch()) # set dongle id reg_res = register(show_spinner=True) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 7b6be919e0..65b9e3e4cc 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -24,6 +24,7 @@ #include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/qt_window.h" +#include "selfdrive/ui/qt/widgets/input.h" TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { // param, title, desc, icon @@ -253,7 +254,19 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) { } std::system("pkill -1 -f selfdrive.updated"); }); - + connect(uiState(), &UIState::offroadTransition, updateBtn, &QPushButton::setEnabled); + + branchSwitcherBtn = new ButtonControl(tr("Switch Branch"), tr("ENTER")); + connect(branchSwitcherBtn, &ButtonControl::clicked, [=]() { + QString branch = InputDialog::getText(tr("Enter name of new branch"), this); + if (branch.isEmpty()) { + params.remove("SwitchToBranch"); + } else { + params.put("SwitchToBranch", branch.toStdString()); + } + std::system("pkill -1 -f selfdrive.updated"); + }); + connect(uiState(), &UIState::offroadTransition, branchSwitcherBtn, &QPushButton::setEnabled); auto uninstallBtn = new ButtonControl(tr("Uninstall %1").arg(getBrand()), tr("UNINSTALL")); connect(uninstallBtn, &ButtonControl::clicked, [&]() { @@ -263,8 +276,11 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) { }); connect(uiState(), &UIState::offroadTransition, uninstallBtn, &QPushButton::setEnabled); - QWidget *widgets[] = {versionLbl, lastUpdateLbl, updateBtn, gitBranchLbl, gitCommitLbl, osVersionLbl, uninstallBtn}; + QWidget *widgets[] = {versionLbl, lastUpdateLbl, updateBtn, branchSwitcherBtn, gitBranchLbl, gitCommitLbl, osVersionLbl, uninstallBtn}; for (QWidget* w : widgets) { + if (w == branchSwitcherBtn && params.getBool("IsTestedBranch")) { + continue; + } addItem(w); } diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index 160f10f99f..45efe255cf 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -71,6 +71,7 @@ private: LabelControl *versionLbl; LabelControl *lastUpdateLbl; ButtonControl *updateBtn; + ButtonControl *branchSwitcherBtn; Params params; QFileSystemWatcher *fs_watch; diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index aed99edae8..4245a9c04a 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -24,9 +24,9 @@ signals: protected: void paintEvent(QPaintEvent *event) override; void resizeEvent(QResizeEvent* event) override; - void mouseReleaseEvent(QMouseEvent *event) override { + void mouseReleaseEvent(QMouseEvent *event) override { if (rect().contains(event->pos())) { - emit clicked(); + emit clicked(); } } QString lastText_, elidedText_; diff --git a/selfdrive/updated.py b/selfdrive/updated.py index bdec383f52..34ab338bb1 100755 --- a/selfdrive/updated.py +++ b/selfdrive/updated.py @@ -311,21 +311,29 @@ def fetch_update(wait_helper: WaitTimeHelper) -> bool: cur_hash = run(["git", "rev-parse", "HEAD"], OVERLAY_MERGED).rstrip() upstream_hash = run(["git", "rev-parse", "@{u}"], OVERLAY_MERGED).rstrip() - new_version: bool = cur_hash != upstream_hash + new_version = cur_hash != upstream_hash git_fetch_result = check_git_fetch_result(git_fetch_output) + new_branch = Params().get("SwitchToBranch", encoding='utf8') + if new_branch is not None: + new_version = True + cloudlog.info(f"comparing {cur_hash} to {upstream_hash}") if new_version or git_fetch_result: cloudlog.info("Running update") if new_version: cloudlog.info("git reset in progress") - r = [ - run(["git", "reset", "--hard", "@{u}"], OVERLAY_MERGED, low_priority=True), - run(["git", "clean", "-xdf"], OVERLAY_MERGED, low_priority=True ), - run(["git", "submodule", "init"], OVERLAY_MERGED, low_priority=True), - run(["git", "submodule", "update"], OVERLAY_MERGED, low_priority=True), + cmds = [ + ["git", "reset", "--hard", "@{u}"], + ["git", "clean", "-xdf"], + ["git", "submodule", "init"], + ["git", "submodule", "update"], ] + if new_branch is not None: + cloudlog.info(f"switching to branch {repr(new_branch)}") + cmds.insert(0, ["git", "checkout", "-f", new_branch]) + r = [run(cmd, OVERLAY_MERGED, low_priority=True) for cmd in cmds] cloudlog.info("git reset success: %s", '\n'.join(r)) if AGNOS: