diff options
Diffstat (limited to 'scripts/lib')
| -rw-r--r-- | scripts/lib/compatlayer/__init__.py | 163 | ||||
| -rw-r--r-- | scripts/lib/compatlayer/case.py | 7 | ||||
| -rw-r--r-- | scripts/lib/compatlayer/cases/__init__.py | 0 | ||||
| -rw-r--r-- | scripts/lib/compatlayer/cases/bsp.py | 26 | ||||
| -rw-r--r-- | scripts/lib/compatlayer/cases/common.py | 66 | ||||
| -rw-r--r-- | scripts/lib/compatlayer/cases/distro.py | 26 | ||||
| -rw-r--r-- | scripts/lib/compatlayer/context.py | 14 |
7 files changed, 302 insertions, 0 deletions
diff --git a/scripts/lib/compatlayer/__init__.py b/scripts/lib/compatlayer/__init__.py new file mode 100644 index 0000000000..b3a166aa9a --- /dev/null +++ b/scripts/lib/compatlayer/__init__.py | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | # Yocto Project compatibility layer tool | ||
| 2 | # | ||
| 3 | # Copyright (C) 2017 Intel Corporation | ||
| 4 | # Released under the MIT license (see COPYING.MIT) | ||
| 5 | |||
| 6 | import os | ||
| 7 | from enum import Enum | ||
| 8 | |||
| 9 | class LayerType(Enum): | ||
| 10 | BSP = 0 | ||
| 11 | DISTRO = 1 | ||
| 12 | SOFTWARE = 2 | ||
| 13 | ERROR_NO_LAYER_CONF = 98 | ||
| 14 | ERROR_BSP_DISTRO = 99 | ||
| 15 | |||
| 16 | def _get_configurations(path): | ||
| 17 | configs = [] | ||
| 18 | |||
| 19 | for f in os.listdir(path): | ||
| 20 | file_path = os.path.join(path, f) | ||
| 21 | if os.path.isfile(file_path) and f.endswith('.conf'): | ||
| 22 | configs.append(f[:-5]) # strip .conf | ||
| 23 | return configs | ||
| 24 | |||
| 25 | def _get_layer_collections(layer_path, lconf=None, data=None): | ||
| 26 | import bb.parse | ||
| 27 | import bb.data | ||
| 28 | |||
| 29 | if lconf is None: | ||
| 30 | lconf = os.path.join(layer_path, 'conf', 'layer.conf') | ||
| 31 | |||
| 32 | if data is None: | ||
| 33 | ldata = bb.data.init() | ||
| 34 | bb.parse.init_parser(ldata) | ||
| 35 | else: | ||
| 36 | ldata = data.createCopy() | ||
| 37 | |||
| 38 | ldata.setVar('LAYERDIR', layer_path) | ||
| 39 | try: | ||
| 40 | ldata = bb.parse.handle(lconf, ldata, include=True) | ||
| 41 | except BaseException as exc: | ||
| 42 | raise LayerError(exc) | ||
| 43 | ldata.expandVarref('LAYERDIR') | ||
| 44 | |||
| 45 | collections = (ldata.getVar('BBFILE_COLLECTIONS', True) or '').split() | ||
| 46 | if not collections: | ||
| 47 | name = os.path.basename(layer_path) | ||
| 48 | collections = [name] | ||
| 49 | |||
| 50 | collections = {c: {} for c in collections} | ||
| 51 | for name in collections: | ||
| 52 | priority = ldata.getVar('BBFILE_PRIORITY_%s' % name, True) | ||
| 53 | pattern = ldata.getVar('BBFILE_PATTERN_%s' % name, True) | ||
| 54 | depends = ldata.getVar('LAYERDEPENDS_%s' % name, True) | ||
| 55 | collections[name]['priority'] = priority | ||
| 56 | collections[name]['pattern'] = pattern | ||
| 57 | collections[name]['depends'] = depends | ||
| 58 | |||
| 59 | return collections | ||
| 60 | |||
| 61 | def _detect_layer(layer_path): | ||
| 62 | """ | ||
| 63 | Scans layer directory to detect what type of layer | ||
| 64 | is BSP, Distro or Software. | ||
| 65 | |||
| 66 | Returns a dictionary with layer name, type and path. | ||
| 67 | """ | ||
| 68 | |||
| 69 | layer = {} | ||
| 70 | layer_name = os.path.basename(layer_path) | ||
| 71 | |||
| 72 | layer['name'] = layer_name | ||
| 73 | layer['path'] = layer_path | ||
| 74 | layer['conf'] = {} | ||
| 75 | |||
| 76 | if not os.path.isfile(os.path.join(layer_path, 'conf', 'layer.conf')): | ||
| 77 | layer['type'] = LayerType.ERROR_NO_LAYER_CONF | ||
| 78 | return layer | ||
| 79 | |||
| 80 | machine_conf = os.path.join(layer_path, 'conf', 'machine') | ||
| 81 | distro_conf = os.path.join(layer_path, 'conf', 'distro') | ||
| 82 | |||
| 83 | is_bsp = False | ||
| 84 | is_distro = False | ||
| 85 | |||
| 86 | if os.path.isdir(machine_conf): | ||
| 87 | machines = _get_configurations(machine_conf) | ||
| 88 | if machines: | ||
| 89 | is_bsp = True | ||
| 90 | |||
| 91 | if os.path.isdir(distro_conf): | ||
| 92 | distros = _get_configurations(distro_conf) | ||
| 93 | if distros: | ||
| 94 | is_distro = True | ||
| 95 | |||
| 96 | if is_bsp and is_distro: | ||
| 97 | layer['type'] = LayerType.ERROR_BSP_DISTRO | ||
| 98 | elif is_bsp: | ||
| 99 | layer['type'] = LayerType.BSP | ||
| 100 | layer['conf']['machines'] = machines | ||
| 101 | elif is_distro: | ||
| 102 | layer['type'] = LayerType.DISTRO | ||
| 103 | layer['conf']['distros'] = distros | ||
| 104 | else: | ||
| 105 | layer['type'] = LayerType.SOFTWARE | ||
| 106 | |||
| 107 | layer['collections'] = _get_layer_collections(layer['path']) | ||
| 108 | |||
| 109 | return layer | ||
| 110 | |||
| 111 | def detect_layers(layer_directories): | ||
| 112 | layers = [] | ||
| 113 | |||
| 114 | for directory in layer_directories: | ||
| 115 | if directory[-1] == '/': | ||
| 116 | directory = directory[0:-1] | ||
| 117 | |||
| 118 | for root, dirs, files in os.walk(directory): | ||
| 119 | dir_name = os.path.basename(root) | ||
| 120 | conf_dir = os.path.join(root, 'conf') | ||
| 121 | if dir_name.startswith('meta-') and os.path.isdir(conf_dir): | ||
| 122 | layer = _detect_layer(root) | ||
| 123 | if layer: | ||
| 124 | layers.append(layer) | ||
| 125 | |||
| 126 | return layers | ||
| 127 | |||
| 128 | def add_layer(bblayersconf, layer): | ||
| 129 | with open(bblayersconf, 'a+') as f: | ||
| 130 | f.write("\nBBLAYERS += \"%s\"\n" % layer['path']) | ||
| 131 | |||
| 132 | def get_signatures(builddir, failsafe=False): | ||
| 133 | import subprocess | ||
| 134 | import re | ||
| 135 | |||
| 136 | sigs = {} | ||
| 137 | |||
| 138 | try: | ||
| 139 | cmd = 'bitbake ' | ||
| 140 | if failsafe: | ||
| 141 | cmd += '-k ' | ||
| 142 | cmd += '-S none world' | ||
| 143 | output = subprocess.check_output(cmd, shell=True, | ||
| 144 | stderr=subprocess.PIPE) | ||
| 145 | except subprocess.CalledProcessError as e: | ||
| 146 | import traceback | ||
| 147 | exc = traceback.format_exc() | ||
| 148 | msg = '%s\n%s\n' % (exc, e.output.decode('utf-8')) | ||
| 149 | raise RuntimeError(msg) | ||
| 150 | sigs_file = os.path.join(builddir, 'locked-sigs.inc') | ||
| 151 | |||
| 152 | sig_regex = re.compile("^(?P<task>.*:.*):(?P<hash>.*) .$") | ||
| 153 | with open(sigs_file, 'r') as f: | ||
| 154 | for line in f.readlines(): | ||
| 155 | line = line.strip() | ||
| 156 | s = sig_regex.match(line) | ||
| 157 | if s: | ||
| 158 | sigs[s.group('task')] = s.group('hash') | ||
| 159 | |||
| 160 | if not sigs: | ||
| 161 | raise RuntimeError('Can\'t load signatures from %s' % sigs_file) | ||
| 162 | |||
| 163 | return sigs | ||
diff --git a/scripts/lib/compatlayer/case.py b/scripts/lib/compatlayer/case.py new file mode 100644 index 0000000000..54ce78aa60 --- /dev/null +++ b/scripts/lib/compatlayer/case.py | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | # Copyright (C) 2017 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | from oeqa.core.case import OETestCase | ||
| 5 | |||
| 6 | class OECompatLayerTestCase(OETestCase): | ||
| 7 | pass | ||
diff --git a/scripts/lib/compatlayer/cases/__init__.py b/scripts/lib/compatlayer/cases/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/scripts/lib/compatlayer/cases/__init__.py | |||
diff --git a/scripts/lib/compatlayer/cases/bsp.py b/scripts/lib/compatlayer/cases/bsp.py new file mode 100644 index 0000000000..5d9bf93e4a --- /dev/null +++ b/scripts/lib/compatlayer/cases/bsp.py | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | # Copyright (C) 2017 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | import unittest | ||
| 5 | |||
| 6 | from compatlayer import LayerType | ||
| 7 | from compatlayer.case import OECompatLayerTestCase | ||
| 8 | |||
| 9 | class BSPCompatLayer(OECompatLayerTestCase): | ||
| 10 | @classmethod | ||
| 11 | def setUpClass(self): | ||
| 12 | if self.tc.layer['type'] != LayerType.BSP: | ||
| 13 | raise unittest.SkipTest("BSPCompatLayer: Layer %s isn't BSP one." %\ | ||
| 14 | self.tc.layer['name']) | ||
| 15 | |||
| 16 | def test_bsp_defines_machines(self): | ||
| 17 | self.assertTrue(self.tc.layer['conf']['machines'], | ||
| 18 | "Layer is BSP but doesn't defines machines.") | ||
| 19 | |||
| 20 | def test_bsp_no_set_machine(self): | ||
| 21 | from oeqa.utils.commands import get_bb_var | ||
| 22 | |||
| 23 | machine = get_bb_var('MACHINE') | ||
| 24 | self.assertEqual(self.td['bbvars']['MACHINE'], machine, | ||
| 25 | msg="Layer %s modified machine %s -> %s" % \ | ||
| 26 | (self.tc.layer['name'], self.td['bbvars']['MACHINE'], machine)) | ||
diff --git a/scripts/lib/compatlayer/cases/common.py b/scripts/lib/compatlayer/cases/common.py new file mode 100644 index 0000000000..4d328ec1f1 --- /dev/null +++ b/scripts/lib/compatlayer/cases/common.py | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | # Copyright (C) 2017 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | import os | ||
| 5 | import subprocess | ||
| 6 | import unittest | ||
| 7 | from compatlayer import get_signatures, LayerType | ||
| 8 | from compatlayer.case import OECompatLayerTestCase | ||
| 9 | |||
| 10 | class CommonCompatLayer(OECompatLayerTestCase): | ||
| 11 | def test_readme(self): | ||
| 12 | readme_file = os.path.join(self.tc.layer['path'], 'README') | ||
| 13 | self.assertTrue(os.path.isfile(readme_file), | ||
| 14 | msg="Layer doesn't contains README file.") | ||
| 15 | |||
| 16 | data = '' | ||
| 17 | with open(readme_file, 'r') as f: | ||
| 18 | data = f.read() | ||
| 19 | self.assertTrue(data, | ||
| 20 | msg="Layer contains README file but is empty.") | ||
| 21 | |||
| 22 | def test_parse(self): | ||
| 23 | try: | ||
| 24 | output = subprocess.check_output('bitbake -p', shell=True, | ||
| 25 | stderr=subprocess.PIPE) | ||
| 26 | except subprocess.CalledProcessError as e: | ||
| 27 | import traceback | ||
| 28 | exc = traceback.format_exc() | ||
| 29 | msg = 'Layer %s failed to parse.\n%s\n%s\n' % (self.tc.layer['name'], | ||
| 30 | exc, e.output.decode('utf-8')) | ||
| 31 | raise RuntimeError(msg) | ||
| 32 | |||
| 33 | def test_show_environment(self): | ||
| 34 | try: | ||
| 35 | output = subprocess.check_output('bitbake -e', shell=True, | ||
| 36 | stderr=subprocess.PIPE) | ||
| 37 | except subprocess.CalledProcessError as e: | ||
| 38 | import traceback | ||
| 39 | exc = traceback.format_exc() | ||
| 40 | msg = 'Layer %s failed to show environment.\n%s\n%s\n' % \ | ||
| 41 | (self.tc.layer['name'], exc, e.output.decode('utf-8')) | ||
| 42 | raise RuntimeError(msg) | ||
| 43 | |||
| 44 | def test_signatures(self): | ||
| 45 | if self.tc.layer['type'] == LayerType.SOFTWARE: | ||
| 46 | raise unittest.SkipTest("Layer %s isn't BSP or DISTRO one." \ | ||
| 47 | % self.tc.layer['name']) | ||
| 48 | |||
| 49 | sig_diff = {} | ||
| 50 | |||
| 51 | curr_sigs = get_signatures(self.td['builddir'], failsafe=True) | ||
| 52 | for task in self.td['sigs']: | ||
| 53 | if task not in curr_sigs: | ||
| 54 | continue | ||
| 55 | |||
| 56 | if self.td['sigs'][task] != curr_sigs[task]: | ||
| 57 | sig_diff[task] = '%s -> %s' % \ | ||
| 58 | (self.td['sigs'][task], curr_sigs[task]) | ||
| 59 | |||
| 60 | detail = '' | ||
| 61 | if sig_diff: | ||
| 62 | for task in sig_diff: | ||
| 63 | detail += "%s changed %s\n" % (task, sig_diff[task]) | ||
| 64 | self.assertFalse(bool(sig_diff), "Layer %s changed signatures.\n%s" % \ | ||
| 65 | (self.tc.layer['name'], detail)) | ||
| 66 | |||
diff --git a/scripts/lib/compatlayer/cases/distro.py b/scripts/lib/compatlayer/cases/distro.py new file mode 100644 index 0000000000..523acc1e78 --- /dev/null +++ b/scripts/lib/compatlayer/cases/distro.py | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | # Copyright (C) 2017 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | import unittest | ||
| 5 | |||
| 6 | from compatlayer import LayerType | ||
| 7 | from compatlayer.case import OECompatLayerTestCase | ||
| 8 | |||
| 9 | class DistroCompatLayer(OECompatLayerTestCase): | ||
| 10 | @classmethod | ||
| 11 | def setUpClass(self): | ||
| 12 | if self.tc.layer['type'] != LayerType.DISTRO: | ||
| 13 | raise unittest.SkipTest("DistroCompatLayer: Layer %s isn't Distro one." %\ | ||
| 14 | self.tc.layer['name']) | ||
| 15 | |||
| 16 | def test_distro_defines_distros(self): | ||
| 17 | self.assertTrue(self.tc.layer['conf']['distros'], | ||
| 18 | "Layer is BSP but doesn't defines machines.") | ||
| 19 | |||
| 20 | def test_distro_no_set_distros(self): | ||
| 21 | from oeqa.utils.commands import get_bb_var | ||
| 22 | |||
| 23 | distro = get_bb_var('DISTRO') | ||
| 24 | self.assertEqual(self.td['bbvars']['DISTRO'], distro, | ||
| 25 | msg="Layer %s modified distro %s -> %s" % \ | ||
| 26 | (self.tc.layer['name'], self.td['bbvars']['DISTRO'], distro)) | ||
diff --git a/scripts/lib/compatlayer/context.py b/scripts/lib/compatlayer/context.py new file mode 100644 index 0000000000..4932238798 --- /dev/null +++ b/scripts/lib/compatlayer/context.py | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | # Copyright (C) 2017 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | import os | ||
| 5 | import sys | ||
| 6 | import glob | ||
| 7 | import re | ||
| 8 | |||
| 9 | from oeqa.core.context import OETestContext | ||
| 10 | |||
| 11 | class CompatLayerTestContext(OETestContext): | ||
| 12 | def __init__(self, td=None, logger=None, layer=None): | ||
| 13 | super(CompatLayerTestContext, self).__init__(td, logger) | ||
| 14 | self.layer = layer | ||
