From 9594f8f1a88a5a5f371a4a534efcb8e3bd855bec Mon Sep 17 00:00:00 2001 From: Yue Tao Date: Wed, 13 Apr 2022 14:44:19 +0800 Subject: [PATCH] Determine the SW_VERSION at run time Distro layer package 'python-keyring' has a dependency on flock layer package 'tsconfig'. This is s violation of the layering policy, preventing successful layerd builds. Get the SW_VERSION via parsing the /etc/build.info file instead of the tsconfig.tsconfig python module at run time. We do this so that python-keyring no longer has a runtime dependency on tsconfig. Test Plan: Pass: build python-keyring Pass: put the codes in a test.py. get the SW_VERSION variable by run the test.py in an environment in which build-info is installed. Pass: trigger exception if removing /etc/build.info, or no SW_VERSION in the file. Closes-Bug: https://bugs.launchpad.net/starlingx/+bug/1968611 Signed-off-by: Yue Tao Change-Id: I7f0c4eaae7aacf5bcbef082817dc99a62600a162 --- .../deb_patches/debian-depend-tsconfig.patch | 13 ------ .../python-keyring/debian/deb_patches/series | 1 - ...Determine-the-SW_VERSION-at-run-time.patch | 46 +++++++++++++++++++ .../debian/patches/keyring_path_change.patch | 23 ---------- security/python-keyring/debian/patches/series | 2 +- 5 files changed, 47 insertions(+), 38 deletions(-) delete mode 100644 security/python-keyring/debian/deb_patches/debian-depend-tsconfig.patch delete mode 100644 security/python-keyring/debian/deb_patches/series create mode 100644 security/python-keyring/debian/patches/0001-Determine-the-SW_VERSION-at-run-time.patch delete mode 100644 security/python-keyring/debian/patches/keyring_path_change.patch diff --git a/security/python-keyring/debian/deb_patches/debian-depend-tsconfig.patch b/security/python-keyring/debian/deb_patches/debian-depend-tsconfig.patch deleted file mode 100644 index 06f9f854f..000000000 --- a/security/python-keyring/debian/deb_patches/debian-depend-tsconfig.patch +++ /dev/null @@ -1,13 +0,0 @@ -The source patch keyring_path_change.patch import -tsconfig, so add tsconfig to Depends - ---- a/debian/control -+++ b/debian/control -@@ -20,6 +20,7 @@ Package: python3-keyring - Architecture: all - Depends: python3-jeepney (>= 0.4.2), - python3-secretstorage (>= 3.2), -+ tsconfig - ${misc:Depends}, - ${python3:Depends} - Suggests: gnome-keyring, libkf5wallet-bin, python3-dbus, python3-keyrings.alt diff --git a/security/python-keyring/debian/deb_patches/series b/security/python-keyring/debian/deb_patches/series deleted file mode 100644 index bcc061558..000000000 --- a/security/python-keyring/debian/deb_patches/series +++ /dev/null @@ -1 +0,0 @@ -debian-depend-tsconfig.patch diff --git a/security/python-keyring/debian/patches/0001-Determine-the-SW_VERSION-at-run-time.patch b/security/python-keyring/debian/patches/0001-Determine-the-SW_VERSION-at-run-time.patch new file mode 100644 index 000000000..c3767c9f4 --- /dev/null +++ b/security/python-keyring/debian/patches/0001-Determine-the-SW_VERSION-at-run-time.patch @@ -0,0 +1,46 @@ +From 6cceddb03a3cad7a09a70d0c2fdc901d9758c025 Mon Sep 17 00:00:00 2001 +From: Yue Tao +Date: Wed, 20 Apr 2022 14:29:27 +0800 +Subject: [PATCH] Determine the SW_VERSION at run time + +Get the SW_VERSION via parsing the /etc/build.info file instead of +tsconfig.tsconfig module at run time to break python-keyring run depends +on tsconfig. + +Signed-off-by: Yue Tao +--- + keyring/util/platform_.py | 18 +++++++++++++++++- + 1 file changed, 17 insertions(+), 1 deletion(-) + +diff --git a/keyring/util/platform_.py b/keyring/util/platform_.py +index bb4d297..5eebd70 100644 +--- a/keyring/util/platform_.py ++++ b/keyring/util/platform_.py +@@ -21,7 +21,23 @@ def _data_root_Linux(): + Use freedesktop.org Base Dir Specfication to determine storage + location. + """ +- fallback = os.path.expanduser('/opt/platform/.keyring/') ++ build_info = "/etc/build.info" ++ try: ++ with open(build_info, 'r') as binfo: ++ lines = list(line for line in (p.strip() for p in binfo) if line) ++ except Exception as e: ++ print(e, file=sys.stderr) ++ raise IOError ++ ++ sw_version = None ++ for entry in lines: ++ if entry.startswith('SW_VERSION='): ++ sw_version = entry.split("=")[1].strip('"') ++ break ++ if sw_version == None: ++ raise ValueError(f"No SW_VERSION found in {build_info}") ++ keyring_dir = os.path.join('/opt/platform/.keyring', sw_version) ++ fallback = os.path.expanduser(keyring_dir) + root = os.environ.get('XDG_DATA_HOME', None) or fallback + return os.path.join(root, 'python_keyring') + +-- +2.25.1 + diff --git a/security/python-keyring/debian/patches/keyring_path_change.patch b/security/python-keyring/debian/patches/keyring_path_change.patch deleted file mode 100644 index 8aecd304b..000000000 --- a/security/python-keyring/debian/patches/keyring_path_change.patch +++ /dev/null @@ -1,23 +0,0 @@ ---- - keyring/util/platform_.py | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - ---- a/keyring/util/platform_.py -+++ b/keyring/util/platform_.py -@@ -1,5 +1,6 @@ - import os - import platform -+from tsconfig.tsconfig import SW_VERSION - - - def _settings_root_XP(): -@@ -21,7 +22,8 @@ def _data_root_Linux(): - Use freedesktop.org Base Dir Specfication to determine storage - location. - """ -- fallback = os.path.expanduser('/opt/platform/.keyring/') -+ keyring_dir = os.path.join('/opt/platform/.keyring', SW_VERSION) -+ fallback = os.path.expanduser(keyring_dir) - root = os.environ.get('XDG_DATA_HOME', None) or fallback - return os.path.join(root, 'python_keyring') - diff --git a/security/python-keyring/debian/patches/series b/security/python-keyring/debian/patches/series index d40f47b09..23e8ae60e 100644 --- a/security/python-keyring/debian/patches/series +++ b/security/python-keyring/debian/patches/series @@ -1,2 +1,2 @@ no_keyring_password.patch -keyring_path_change.patch +0001-Determine-the-SW_VERSION-at-run-time.patch