updated: add branch switching (#25200)

* switch param

* add to ui

* fix that

* fetch for new branch

Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: cc3857eb62
taco
Adeeb Shihadeh 3 years ago committed by GitHub
parent 89a11b1ca5
commit 95df2c9b48
  1. 2
      common/params.cc
  2. 3
      selfdrive/manager/manager.py
  3. 20
      selfdrive/ui/qt/offroad/settings.cc
  4. 1
      selfdrive/ui/qt/offroad/settings.h
  5. 20
      selfdrive/updated.py

@ -126,6 +126,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"IsOnroad", PERSISTENT}, {"IsOnroad", PERSISTENT},
{"IsRHD", PERSISTENT}, {"IsRHD", PERSISTENT},
{"IsTakingSnapshot", CLEAR_ON_MANAGER_START}, {"IsTakingSnapshot", CLEAR_ON_MANAGER_START},
{"IsTestedBranch", CLEAR_ON_MANAGER_START},
{"IsUpdateAvailable", CLEAR_ON_MANAGER_START}, {"IsUpdateAvailable", CLEAR_ON_MANAGER_START},
{"JoystickDebugMode", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF}, {"JoystickDebugMode", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF},
{"LaikadEphemeris", PERSISTENT | DONT_LOG}, {"LaikadEphemeris", PERSISTENT | DONT_LOG},
@ -154,6 +155,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"SnoozeUpdate", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF}, {"SnoozeUpdate", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF},
{"SshEnabled", PERSISTENT}, {"SshEnabled", PERSISTENT},
{"SubscriberInfo", PERSISTENT}, {"SubscriberInfo", PERSISTENT},
{"SwitchToBranch", CLEAR_ON_MANAGER_START},
{"TermsVersion", PERSISTENT}, {"TermsVersion", PERSISTENT},
{"Timezone", PERSISTENT}, {"Timezone", PERSISTENT},
{"TrainingVersion", PERSISTENT}, {"TrainingVersion", PERSISTENT},

@ -20,7 +20,7 @@ from selfdrive.manager.process_config import managed_processes
from selfdrive.athena.registration import register, UNREGISTERED_DONGLE_ID from selfdrive.athena.registration import register, UNREGISTERED_DONGLE_ID
from system.swaglog import cloudlog, add_file_handler from system.swaglog import cloudlog, add_file_handler
from system.version import is_dirty, get_commit, get_version, get_origin, get_short_branch, \ 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")) sys.path.append(os.path.join(BASEDIR, "pyextra"))
@ -78,6 +78,7 @@ def manager_init() -> None:
params.put("GitCommit", get_commit(default="")) params.put("GitCommit", get_commit(default=""))
params.put("GitBranch", get_short_branch(default="")) params.put("GitBranch", get_short_branch(default=""))
params.put("GitRemote", get_origin(default="")) params.put("GitRemote", get_origin(default=""))
params.put_bool("IsTestedBranch", is_tested_branch())
# set dongle id # set dongle id
reg_res = register(show_spinner=True) reg_res = register(show_spinner=True)

@ -24,6 +24,7 @@
#include "selfdrive/ui/ui.h" #include "selfdrive/ui/ui.h"
#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/util.h"
#include "selfdrive/ui/qt/qt_window.h" #include "selfdrive/ui/qt/qt_window.h"
#include "selfdrive/ui/qt/widgets/input.h"
TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
// param, title, desc, icon // param, title, desc, icon
@ -253,7 +254,19 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) {
} }
std::system("pkill -1 -f selfdrive.updated"); 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")); auto uninstallBtn = new ButtonControl(tr("Uninstall %1").arg(getBrand()), tr("UNINSTALL"));
connect(uninstallBtn, &ButtonControl::clicked, [&]() { connect(uninstallBtn, &ButtonControl::clicked, [&]() {
@ -263,8 +276,11 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) {
}); });
connect(uiState(), &UIState::offroadTransition, uninstallBtn, &QPushButton::setEnabled); 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) { for (QWidget* w : widgets) {
if (w == branchSwitcherBtn && params.getBool("IsTestedBranch")) {
continue;
}
addItem(w); addItem(w);
} }

@ -71,6 +71,7 @@ private:
LabelControl *versionLbl; LabelControl *versionLbl;
LabelControl *lastUpdateLbl; LabelControl *lastUpdateLbl;
ButtonControl *updateBtn; ButtonControl *updateBtn;
ButtonControl *branchSwitcherBtn;
Params params; Params params;
QFileSystemWatcher *fs_watch; QFileSystemWatcher *fs_watch;

@ -311,21 +311,29 @@ def fetch_update(wait_helper: WaitTimeHelper) -> bool:
cur_hash = run(["git", "rev-parse", "HEAD"], OVERLAY_MERGED).rstrip() cur_hash = run(["git", "rev-parse", "HEAD"], OVERLAY_MERGED).rstrip()
upstream_hash = run(["git", "rev-parse", "@{u}"], 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) 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}") cloudlog.info(f"comparing {cur_hash} to {upstream_hash}")
if new_version or git_fetch_result: if new_version or git_fetch_result:
cloudlog.info("Running update") cloudlog.info("Running update")
if new_version: if new_version:
cloudlog.info("git reset in progress") cloudlog.info("git reset in progress")
r = [ cmds = [
run(["git", "reset", "--hard", "@{u}"], OVERLAY_MERGED, low_priority=True), ["git", "reset", "--hard", "@{u}"],
run(["git", "clean", "-xdf"], OVERLAY_MERGED, low_priority=True ), ["git", "clean", "-xdf"],
run(["git", "submodule", "init"], OVERLAY_MERGED, low_priority=True), ["git", "submodule", "init"],
run(["git", "submodule", "update"], OVERLAY_MERGED, low_priority=True), ["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)) cloudlog.info("git reset success: %s", '\n'.join(r))
if AGNOS: if AGNOS:

Loading…
Cancel
Save