Patrick Williams | c124f4f | 2015-09-15 14:41:29 -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.base import oeSelfTest |
| 9 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer |
| 10 | |
| 11 | |
| 12 | class SStateBase(oeSelfTest): |
| 13 | |
| 14 | def setUpLocal(self): |
| 15 | self.temp_sstate_location = None |
| 16 | self.sstate_path = get_bb_var('SSTATE_DIR') |
| 17 | self.distro = get_bb_var('NATIVELSBSTRING') |
| 18 | self.distro_specific_sstate = os.path.join(self.sstate_path, self.distro) |
| 19 | |
| 20 | # Creates a special sstate configuration with the option to add sstate mirrors |
| 21 | def config_sstate(self, temp_sstate_location=False, add_local_mirrors=[]): |
| 22 | self.temp_sstate_location = temp_sstate_location |
| 23 | |
| 24 | if self.temp_sstate_location: |
| 25 | temp_sstate_path = os.path.join(self.builddir, "temp_sstate_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')) |
| 26 | config_temp_sstate = "SSTATE_DIR = \"%s\"" % temp_sstate_path |
| 27 | self.append_config(config_temp_sstate) |
| 28 | self.track_for_cleanup(temp_sstate_path) |
| 29 | self.sstate_path = get_bb_var('SSTATE_DIR') |
| 30 | self.distro = get_bb_var('NATIVELSBSTRING') |
| 31 | self.distro_specific_sstate = os.path.join(self.sstate_path, self.distro) |
| 32 | |
| 33 | if add_local_mirrors: |
| 34 | config_set_sstate_if_not_set = 'SSTATE_MIRRORS ?= ""' |
| 35 | self.append_config(config_set_sstate_if_not_set) |
| 36 | for local_mirror in add_local_mirrors: |
| 37 | self.assertFalse(os.path.join(local_mirror) == os.path.join(self.sstate_path), msg='Cannot add the current sstate path as a sstate mirror') |
| 38 | config_sstate_mirror = "SSTATE_MIRRORS += \"file://.* file:///%s/PATH\"" % local_mirror |
| 39 | self.append_config(config_sstate_mirror) |
| 40 | |
| 41 | # Returns a list containing sstate files |
| 42 | def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True): |
| 43 | result = [] |
| 44 | for root, dirs, files in os.walk(self.sstate_path): |
| 45 | if distro_specific and re.search("%s/[a-z0-9]{2}$" % self.distro, root): |
| 46 | for f in files: |
| 47 | if re.search(filename_regex, f): |
| 48 | result.append(f) |
| 49 | if distro_nonspecific and re.search("%s/[a-z0-9]{2}$" % self.sstate_path, root): |
| 50 | for f in files: |
| 51 | if re.search(filename_regex, f): |
| 52 | result.append(f) |
| 53 | return result |