Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | import datetime |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6 | import os |
| 7 | import re |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9 | from oeqa.selftest.case import OESelftestTestCase |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 10 | from oeqa.utils.commands import get_bb_vars |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | |
| 12 | |
| 13 | class SStateBase(OESelftestTestCase): |
| 14 | |
| 15 | def setUpLocal(self): |
| 16 | super(SStateBase, self).setUpLocal() |
| 17 | self.temp_sstate_location = None |
| 18 | needed_vars = ['SSTATE_DIR', 'NATIVELSBSTRING', 'TCLIBC', 'TUNE_ARCH', |
| 19 | 'TOPDIR', 'TARGET_VENDOR', 'TARGET_OS'] |
| 20 | bb_vars = get_bb_vars(needed_vars) |
| 21 | self.sstate_path = bb_vars['SSTATE_DIR'] |
| 22 | self.hostdistro = bb_vars['NATIVELSBSTRING'] |
| 23 | self.tclibc = bb_vars['TCLIBC'] |
| 24 | self.tune_arch = bb_vars['TUNE_ARCH'] |
| 25 | self.topdir = bb_vars['TOPDIR'] |
| 26 | self.target_vendor = bb_vars['TARGET_VENDOR'] |
| 27 | self.target_os = bb_vars['TARGET_OS'] |
| 28 | self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro) |
| 29 | |
| 30 | # Creates a special sstate configuration with the option to add sstate mirrors |
| 31 | def config_sstate(self, temp_sstate_location=False, add_local_mirrors=[]): |
| 32 | self.temp_sstate_location = temp_sstate_location |
| 33 | |
| 34 | if self.temp_sstate_location: |
| 35 | temp_sstate_path = os.path.join(self.builddir, "temp_sstate_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')) |
| 36 | config_temp_sstate = "SSTATE_DIR = \"%s\"" % temp_sstate_path |
| 37 | self.append_config(config_temp_sstate) |
| 38 | self.track_for_cleanup(temp_sstate_path) |
| 39 | bb_vars = get_bb_vars(['SSTATE_DIR', 'NATIVELSBSTRING']) |
| 40 | self.sstate_path = bb_vars['SSTATE_DIR'] |
| 41 | self.hostdistro = bb_vars['NATIVELSBSTRING'] |
| 42 | self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro) |
| 43 | |
| 44 | if add_local_mirrors: |
| 45 | config_set_sstate_if_not_set = 'SSTATE_MIRRORS ?= ""' |
| 46 | self.append_config(config_set_sstate_if_not_set) |
| 47 | for local_mirror in add_local_mirrors: |
| 48 | self.assertFalse(os.path.join(local_mirror) == os.path.join(self.sstate_path), msg='Cannot add the current sstate path as a sstate mirror') |
| 49 | config_sstate_mirror = "SSTATE_MIRRORS += \"file://.* file:///%s/PATH\"" % local_mirror |
| 50 | self.append_config(config_sstate_mirror) |
| 51 | |
| 52 | # Returns a list containing sstate files |
| 53 | def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True): |
| 54 | result = [] |
| 55 | for root, dirs, files in os.walk(self.sstate_path): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 56 | if distro_specific and re.search(r"%s/%s/[a-z0-9]{2}/[a-z0-9]{2}$" % (self.sstate_path, self.hostdistro), root): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 57 | for f in files: |
| 58 | if re.search(filename_regex, f): |
| 59 | result.append(f) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 60 | if distro_nonspecific and re.search(r"%s/[a-z0-9]{2}/[a-z0-9]{2}$" % self.sstate_path, root): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 61 | for f in files: |
| 62 | if re.search(filename_regex, f): |
| 63 | result.append(f) |
| 64 | return result |