blob: 176766331adea03ce210f8795dece4289b1c2adc [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import datetime
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006import os
7import re
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009from oeqa.selftest.case import OESelftestTestCase
Patrick Williams45852732022-04-02 08:58:32 -050010from oeqa.utils.commands import get_bb_vars
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011
12
13class 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 Geissler82c905d2020-04-13 13:39:40 -050056 if distro_specific and re.search(r"%s/%s/[a-z0-9]{2}/[a-z0-9]{2}$" % (self.sstate_path, self.hostdistro), root):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050057 for f in files:
58 if re.search(filename_regex, f):
59 result.append(f)
Andrew Geissler82c905d2020-04-13 13:39:40 -050060 if distro_nonspecific and re.search(r"%s/[a-z0-9]{2}/[a-z0-9]{2}$" % self.sstate_path, root):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050061 for f in files:
62 if re.search(filename_regex, f):
63 result.append(f)
64 return result