blob: e73bb9488410539866ded2da0b62b4c8dc8b4d37 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007import datetime
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008import os
9import re
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011from oeqa.selftest.case import OESelftestTestCase
Patrick Williams45852732022-04-02 08:58:32 -050012from oeqa.utils.commands import get_bb_vars
Brad Bishopd7bf8c12018-02-25 22:55:05 -050013
14
15class SStateBase(OESelftestTestCase):
16
17 def setUpLocal(self):
18 super(SStateBase, self).setUpLocal()
19 self.temp_sstate_location = None
20 needed_vars = ['SSTATE_DIR', 'NATIVELSBSTRING', 'TCLIBC', 'TUNE_ARCH',
21 'TOPDIR', 'TARGET_VENDOR', 'TARGET_OS']
22 bb_vars = get_bb_vars(needed_vars)
23 self.sstate_path = bb_vars['SSTATE_DIR']
24 self.hostdistro = bb_vars['NATIVELSBSTRING']
25 self.tclibc = bb_vars['TCLIBC']
26 self.tune_arch = bb_vars['TUNE_ARCH']
27 self.topdir = bb_vars['TOPDIR']
28 self.target_vendor = bb_vars['TARGET_VENDOR']
29 self.target_os = bb_vars['TARGET_OS']
30 self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro)
31
32 # Creates a special sstate configuration with the option to add sstate mirrors
33 def config_sstate(self, temp_sstate_location=False, add_local_mirrors=[]):
34 self.temp_sstate_location = temp_sstate_location
35
36 if self.temp_sstate_location:
37 temp_sstate_path = os.path.join(self.builddir, "temp_sstate_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
38 config_temp_sstate = "SSTATE_DIR = \"%s\"" % temp_sstate_path
39 self.append_config(config_temp_sstate)
40 self.track_for_cleanup(temp_sstate_path)
41 bb_vars = get_bb_vars(['SSTATE_DIR', 'NATIVELSBSTRING'])
42 self.sstate_path = bb_vars['SSTATE_DIR']
43 self.hostdistro = bb_vars['NATIVELSBSTRING']
44 self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro)
45
46 if add_local_mirrors:
47 config_set_sstate_if_not_set = 'SSTATE_MIRRORS ?= ""'
48 self.append_config(config_set_sstate_if_not_set)
49 for local_mirror in add_local_mirrors:
50 self.assertFalse(os.path.join(local_mirror) == os.path.join(self.sstate_path), msg='Cannot add the current sstate path as a sstate mirror')
51 config_sstate_mirror = "SSTATE_MIRRORS += \"file://.* file:///%s/PATH\"" % local_mirror
52 self.append_config(config_sstate_mirror)
53
54 # Returns a list containing sstate files
55 def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True):
56 result = []
57 for root, dirs, files in os.walk(self.sstate_path):
Andrew Geissler82c905d2020-04-13 13:39:40 -050058 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 -050059 for f in files:
60 if re.search(filename_regex, f):
61 result.append(f)
Andrew Geissler82c905d2020-04-13 13:39:40 -050062 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 -050063 for f in files:
64 if re.search(filename_regex, f):
65 result.append(f)
66 return result