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