From 1fb0cb59a61bcbee96d6b3e287979f9545a0d38a Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 16 Jul 2024 02:59:02 +0000 Subject: [PATCH] Scons: Build sunnypilot elements with added GPG keys --- .gitlab-ci.yml | 2 ++ SConstruct | 47 ++++++++++++++++++++++++++++++ selfdrive/ui/SConscript | 6 ++++ selfdrive/ui/sunnypilot/SConscript | 10 +++++++ 4 files changed, 65 insertions(+) create mode 100644 selfdrive/ui/sunnypilot/SConscript diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 21958355c5..de50202454 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -129,6 +129,8 @@ build: --exclude='**/selfdrive/ui/**/*.h' --exclude='**/selfdrive/ui/qt/offroad/sunnypilot/' --exclude='**/.git/' + --exclude='**/SConstruct' + --exclude='**/SConscript' --delete-excluded --chown=comma:comma ${BUILD_DIR}/ ${OUTPUT_DIR}/ diff --git a/SConstruct b/SConstruct index da70e4e587..13da37c7a8 100644 --- a/SConstruct +++ b/SConstruct @@ -7,6 +7,8 @@ import numpy as np import SCons.Errors +from openpilot.common.basedir import BASEDIR + SCons.Warnings.warningAsException(True) # pending upstream fix - https://github.com/SCons/scons/issues/4461 @@ -16,6 +18,45 @@ TICI = os.path.isfile('/TICI') AGNOS = TICI UBUNTU_FOCAL = int(subprocess.check_output('[ -f /etc/os-release ] && . /etc/os-release && [ "$ID" = "ubuntu" ] && [ "$VERSION_ID" = "20.04" ] && echo 1 || echo 0', shell=True, encoding='utf-8').rstrip()) Export('UBUNTU_FOCAL') +_DEBUG = False + +def is_internal_developer(debug=False): + def collect_required_gpg_key_ids(keys_dir): + try: + key_ids = [f.split('.')[0] for f in os.listdir(keys_dir) if f.endswith(".gpg")] + if debug: + print(f"SP: Required GPG key IDs: {key_ids}") + return key_ids + except OSError as e: + if debug: + print(f"SP: Failed to read GPG key IDs from {keys_dir}. Error: {e}") + return [] + + def is_key_available(required_gpg_key_ids): + for key_id in required_gpg_key_ids: + try: + result = subprocess.check_output(['gpg', '--list-keys', key_id], stderr=subprocess.STDOUT) + if key_id in result.decode(): + if debug: + print(f"SP: GPG key {key_id} is available.") + return True + except subprocess.CalledProcessError as e: + if debug: + print(f"SP: Failed to list GPG key {key_id}. Error:", e.output.decode().strip()) + return False + + keys_dir = os.path.join(BASEDIR, ".git-crypt/keys/default/0") + required_gpg_key_ids = collect_required_gpg_key_ids(keys_dir) + + sunnypilot = is_key_available(required_gpg_key_ids) + + if sunnypilot: + print("SP: Confirmed sunnypilot internal developer.") + print("SP: Loading sunnypilot elements ...") + elif debug: + print("SP: None of the required GPG keys are available.") + + return sunnypilot Decider('MD5-timestamp') @@ -72,6 +113,12 @@ AddOption('--minimal', default=os.path.exists(File('#.lfsconfig').abspath), # minimal by default on release branch (where there's no LFS) help='the minimum build to run openpilot. no tests, tools, etc.') +AddOption('--sunnypilot', + action='store_true', + dest='sunnypilot', + default=is_internal_developer(_DEBUG), # check if the current user is a sunnypilot developer + help='build sunnypilot elements and other sunnypilot-specific items that are meant for internal development') + ## Architecture name breakdown (arch) ## - larch64: linux tici aarch64 ## - aarch64: linux pc aarch64 diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index e1233b5cbc..f4f5a13919 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -17,6 +17,12 @@ if arch == "Darwin": # FIXME: remove this once we're on 5.15 (24.04) qt_env['CXXFLAGS'] += ["-Wno-deprecated-declarations"] +sp_widgets_src = [] +sp_qt_src = [] +if GetOption('sunnypilot'): + SConscript(['sunnypilot/SConscript']) + Import('sp_widgets_src', 'sp_qt_src') + qt_util = qt_env.Library("qt_util", ["#selfdrive/ui/qt/api.cc", "#selfdrive/ui/qt/util.cc"], LIBS=base_libs) widgets_src = ["ui.cc", "qt/widgets/input.cc", "qt/widgets/wifi.cc", "qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/widgets/controls.cc", diff --git a/selfdrive/ui/sunnypilot/SConscript b/selfdrive/ui/sunnypilot/SConscript new file mode 100644 index 0000000000..4431fc3ea0 --- /dev/null +++ b/selfdrive/ui/sunnypilot/SConscript @@ -0,0 +1,10 @@ +widgets_src = [] + +network_src = [] + +qt_src = [] + +sp_widgets_src = widgets_src + network_src +sp_qt_src = qt_src + +Export('sp_widgets_src', 'sp_qt_src')