diff options
Diffstat (limited to 'scripts/lib/checklayer')
-rw-r--r-- | scripts/lib/checklayer/__init__.py | 58 | ||||
-rw-r--r-- | scripts/lib/checklayer/cases/bsp.py | 4 | ||||
-rw-r--r-- | scripts/lib/checklayer/cases/common.py | 46 | ||||
-rw-r--r-- | scripts/lib/checklayer/cases/distro.py | 2 |
4 files changed, 94 insertions, 16 deletions
diff --git a/scripts/lib/checklayer/__init__.py b/scripts/lib/checklayer/__init__.py index fe545607bb..62ecdfe390 100644 --- a/scripts/lib/checklayer/__init__.py +++ b/scripts/lib/checklayer/__init__.py | |||
@@ -16,6 +16,7 @@ class LayerType(Enum): | |||
16 | BSP = 0 | 16 | BSP = 0 |
17 | DISTRO = 1 | 17 | DISTRO = 1 |
18 | SOFTWARE = 2 | 18 | SOFTWARE = 2 |
19 | CORE = 3 | ||
19 | ERROR_NO_LAYER_CONF = 98 | 20 | ERROR_NO_LAYER_CONF = 98 |
20 | ERROR_BSP_DISTRO = 99 | 21 | ERROR_BSP_DISTRO = 99 |
21 | 22 | ||
@@ -43,7 +44,7 @@ def _get_layer_collections(layer_path, lconf=None, data=None): | |||
43 | 44 | ||
44 | ldata.setVar('LAYERDIR', layer_path) | 45 | ldata.setVar('LAYERDIR', layer_path) |
45 | try: | 46 | try: |
46 | ldata = bb.parse.handle(lconf, ldata, include=True) | 47 | ldata = bb.parse.handle(lconf, ldata, include=True, baseconfig=True) |
47 | except: | 48 | except: |
48 | raise RuntimeError("Parsing of layer.conf from layer: %s failed" % layer_path) | 49 | raise RuntimeError("Parsing of layer.conf from layer: %s failed" % layer_path) |
49 | ldata.expandVarref('LAYERDIR') | 50 | ldata.expandVarref('LAYERDIR') |
@@ -106,7 +107,13 @@ def _detect_layer(layer_path): | |||
106 | if distros: | 107 | if distros: |
107 | is_distro = True | 108 | is_distro = True |
108 | 109 | ||
109 | if is_bsp and is_distro: | 110 | layer['collections'] = _get_layer_collections(layer['path']) |
111 | |||
112 | if layer_name == "meta" and "core" in layer['collections']: | ||
113 | layer['type'] = LayerType.CORE | ||
114 | layer['conf']['machines'] = machines | ||
115 | layer['conf']['distros'] = distros | ||
116 | elif is_bsp and is_distro: | ||
110 | layer['type'] = LayerType.ERROR_BSP_DISTRO | 117 | layer['type'] = LayerType.ERROR_BSP_DISTRO |
111 | elif is_bsp: | 118 | elif is_bsp: |
112 | layer['type'] = LayerType.BSP | 119 | layer['type'] = LayerType.BSP |
@@ -117,8 +124,6 @@ def _detect_layer(layer_path): | |||
117 | else: | 124 | else: |
118 | layer['type'] = LayerType.SOFTWARE | 125 | layer['type'] = LayerType.SOFTWARE |
119 | 126 | ||
120 | layer['collections'] = _get_layer_collections(layer['path']) | ||
121 | |||
122 | return layer | 127 | return layer |
123 | 128 | ||
124 | def detect_layers(layer_directories, no_auto): | 129 | def detect_layers(layer_directories, no_auto): |
@@ -146,7 +151,7 @@ def detect_layers(layer_directories, no_auto): | |||
146 | 151 | ||
147 | return layers | 152 | return layers |
148 | 153 | ||
149 | def _find_layer_depends(depend, layers): | 154 | def _find_layer(depend, layers): |
150 | for layer in layers: | 155 | for layer in layers: |
151 | if 'collections' not in layer: | 156 | if 'collections' not in layer: |
152 | continue | 157 | continue |
@@ -156,7 +161,28 @@ def _find_layer_depends(depend, layers): | |||
156 | return layer | 161 | return layer |
157 | return None | 162 | return None |
158 | 163 | ||
159 | def add_layer_dependencies(bblayersconf, layer, layers, logger): | 164 | def sanity_check_layers(layers, logger): |
165 | """ | ||
166 | Check that we didn't find duplicate collection names, as the layer that will | ||
167 | be used is non-deterministic. The precise check is duplicate collections | ||
168 | with different patterns, as the same pattern being repeated won't cause | ||
169 | problems. | ||
170 | """ | ||
171 | import collections | ||
172 | |||
173 | passed = True | ||
174 | seen = collections.defaultdict(set) | ||
175 | for layer in layers: | ||
176 | for name, data in layer.get("collections", {}).items(): | ||
177 | seen[name].add(data["pattern"]) | ||
178 | |||
179 | for name, patterns in seen.items(): | ||
180 | if len(patterns) > 1: | ||
181 | passed = False | ||
182 | logger.error("Collection %s found multiple times: %s" % (name, ", ".join(patterns))) | ||
183 | return passed | ||
184 | |||
185 | def get_layer_dependencies(layer, layers, logger): | ||
160 | def recurse_dependencies(depends, layer, layers, logger, ret = []): | 186 | def recurse_dependencies(depends, layer, layers, logger, ret = []): |
161 | logger.debug('Processing dependencies %s for layer %s.' % \ | 187 | logger.debug('Processing dependencies %s for layer %s.' % \ |
162 | (depends, layer['name'])) | 188 | (depends, layer['name'])) |
@@ -166,7 +192,7 @@ def add_layer_dependencies(bblayersconf, layer, layers, logger): | |||
166 | if depend == 'core': | 192 | if depend == 'core': |
167 | continue | 193 | continue |
168 | 194 | ||
169 | layer_depend = _find_layer_depends(depend, layers) | 195 | layer_depend = _find_layer(depend, layers) |
170 | if not layer_depend: | 196 | if not layer_depend: |
171 | logger.error('Layer %s depends on %s and isn\'t found.' % \ | 197 | logger.error('Layer %s depends on %s and isn\'t found.' % \ |
172 | (layer['name'], depend)) | 198 | (layer['name'], depend)) |
@@ -203,6 +229,11 @@ def add_layer_dependencies(bblayersconf, layer, layers, logger): | |||
203 | layer_depends = recurse_dependencies(depends, layer, layers, logger, layer_depends) | 229 | layer_depends = recurse_dependencies(depends, layer, layers, logger, layer_depends) |
204 | 230 | ||
205 | # Note: [] (empty) is allowed, None is not! | 231 | # Note: [] (empty) is allowed, None is not! |
232 | return layer_depends | ||
233 | |||
234 | def add_layer_dependencies(bblayersconf, layer, layers, logger): | ||
235 | |||
236 | layer_depends = get_layer_dependencies(layer, layers, logger) | ||
206 | if layer_depends is None: | 237 | if layer_depends is None: |
207 | return False | 238 | return False |
208 | else: | 239 | else: |
@@ -256,7 +287,7 @@ def check_command(error_msg, cmd, cwd=None): | |||
256 | raise RuntimeError(msg) | 287 | raise RuntimeError(msg) |
257 | return output | 288 | return output |
258 | 289 | ||
259 | def get_signatures(builddir, failsafe=False, machine=None): | 290 | def get_signatures(builddir, failsafe=False, machine=None, extravars=None): |
260 | import re | 291 | import re |
261 | 292 | ||
262 | # some recipes needs to be excluded like meta-world-pkgdata | 293 | # some recipes needs to be excluded like meta-world-pkgdata |
@@ -267,13 +298,16 @@ def get_signatures(builddir, failsafe=False, machine=None): | |||
267 | sigs = {} | 298 | sigs = {} |
268 | tune2tasks = {} | 299 | tune2tasks = {} |
269 | 300 | ||
270 | cmd = 'BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE BB_SIGNATURE_HANDLER" BB_SIGNATURE_HANDLER="OEBasicHash" ' | 301 | cmd = 'BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS BB_SIGNATURE_HANDLER" BB_SIGNATURE_HANDLER="OEBasicHash" ' |
302 | if extravars: | ||
303 | cmd += extravars | ||
304 | cmd += ' ' | ||
271 | if machine: | 305 | if machine: |
272 | cmd += 'MACHINE=%s ' % machine | 306 | cmd += 'MACHINE=%s ' % machine |
273 | cmd += 'bitbake ' | 307 | cmd += 'bitbake ' |
274 | if failsafe: | 308 | if failsafe: |
275 | cmd += '-k ' | 309 | cmd += '-k ' |
276 | cmd += '-S none world' | 310 | cmd += '-S lockedsigs world' |
277 | sigs_file = os.path.join(builddir, 'locked-sigs.inc') | 311 | sigs_file = os.path.join(builddir, 'locked-sigs.inc') |
278 | if os.path.exists(sigs_file): | 312 | if os.path.exists(sigs_file): |
279 | os.unlink(sigs_file) | 313 | os.unlink(sigs_file) |
@@ -290,8 +324,8 @@ def get_signatures(builddir, failsafe=False, machine=None): | |||
290 | else: | 324 | else: |
291 | raise | 325 | raise |
292 | 326 | ||
293 | sig_regex = re.compile("^(?P<task>.*:.*):(?P<hash>.*) .$") | 327 | sig_regex = re.compile(r"^(?P<task>.*:.*):(?P<hash>.*) .$") |
294 | tune_regex = re.compile("(^|\s)SIGGEN_LOCKEDSIGS_t-(?P<tune>\S*)\s*=\s*") | 328 | tune_regex = re.compile(r"(^|\s)SIGGEN_LOCKEDSIGS_t-(?P<tune>\S*)\s*=\s*") |
295 | current_tune = None | 329 | current_tune = None |
296 | with open(sigs_file, 'r') as f: | 330 | with open(sigs_file, 'r') as f: |
297 | for line in f.readlines(): | 331 | for line in f.readlines(): |
diff --git a/scripts/lib/checklayer/cases/bsp.py b/scripts/lib/checklayer/cases/bsp.py index 7fd56f5d36..b76163fb56 100644 --- a/scripts/lib/checklayer/cases/bsp.py +++ b/scripts/lib/checklayer/cases/bsp.py | |||
@@ -11,7 +11,7 @@ from checklayer.case import OECheckLayerTestCase | |||
11 | class BSPCheckLayer(OECheckLayerTestCase): | 11 | class BSPCheckLayer(OECheckLayerTestCase): |
12 | @classmethod | 12 | @classmethod |
13 | def setUpClass(self): | 13 | def setUpClass(self): |
14 | if self.tc.layer['type'] != LayerType.BSP: | 14 | if self.tc.layer['type'] not in (LayerType.BSP, LayerType.CORE): |
15 | raise unittest.SkipTest("BSPCheckLayer: Layer %s isn't BSP one." %\ | 15 | raise unittest.SkipTest("BSPCheckLayer: Layer %s isn't BSP one." %\ |
16 | self.tc.layer['name']) | 16 | self.tc.layer['name']) |
17 | 17 | ||
@@ -153,7 +153,7 @@ class BSPCheckLayer(OECheckLayerTestCase): | |||
153 | # do_build can be ignored: it is know to have | 153 | # do_build can be ignored: it is know to have |
154 | # different signatures in some cases, for example in | 154 | # different signatures in some cases, for example in |
155 | # the allarch ca-certificates due to RDEPENDS=openssl. | 155 | # the allarch ca-certificates due to RDEPENDS=openssl. |
156 | # That particular dependency is whitelisted via | 156 | # That particular dependency is marked via |
157 | # SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, but still shows up | 157 | # SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, but still shows up |
158 | # in the sstate signature hash because filtering it | 158 | # in the sstate signature hash because filtering it |
159 | # out would be hard and running do_build multiple | 159 | # out would be hard and running do_build multiple |
diff --git a/scripts/lib/checklayer/cases/common.py b/scripts/lib/checklayer/cases/common.py index b82304e361..97b16f78c8 100644 --- a/scripts/lib/checklayer/cases/common.py +++ b/scripts/lib/checklayer/cases/common.py | |||
@@ -6,15 +6,19 @@ | |||
6 | import glob | 6 | import glob |
7 | import os | 7 | import os |
8 | import unittest | 8 | import unittest |
9 | import re | ||
9 | from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures | 10 | from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures |
10 | from checklayer.case import OECheckLayerTestCase | 11 | from checklayer.case import OECheckLayerTestCase |
11 | 12 | ||
12 | class CommonCheckLayer(OECheckLayerTestCase): | 13 | class CommonCheckLayer(OECheckLayerTestCase): |
13 | def test_readme(self): | 14 | def test_readme(self): |
15 | if self.tc.layer['type'] == LayerType.CORE: | ||
16 | raise unittest.SkipTest("Core layer's README is top level") | ||
17 | |||
14 | # The top-level README file may have a suffix (like README.rst or README.txt). | 18 | # The top-level README file may have a suffix (like README.rst or README.txt). |
15 | readme_files = glob.glob(os.path.join(self.tc.layer['path'], '[Rr][Ee][Aa][Dd][Mm][Ee]*')) | 19 | readme_files = glob.glob(os.path.join(self.tc.layer['path'], '[Rr][Ee][Aa][Dd][Mm][Ee]*')) |
16 | self.assertTrue(len(readme_files) > 0, | 20 | self.assertTrue(len(readme_files) > 0, |
17 | msg="Layer doesn't contains README file.") | 21 | msg="Layer doesn't contain a README file.") |
18 | 22 | ||
19 | # There might be more than one file matching the file pattern above | 23 | # There might be more than one file matching the file pattern above |
20 | # (for example, README.rst and README-COPYING.rst). The one with the shortest | 24 | # (for example, README.rst and README-COPYING.rst). The one with the shortest |
@@ -26,6 +30,16 @@ class CommonCheckLayer(OECheckLayerTestCase): | |||
26 | self.assertTrue(data, | 30 | self.assertTrue(data, |
27 | msg="Layer contains a README file but it is empty.") | 31 | msg="Layer contains a README file but it is empty.") |
28 | 32 | ||
33 | # If a layer's README references another README, then the checks below are not valid | ||
34 | if re.search('README', data, re.IGNORECASE): | ||
35 | return | ||
36 | |||
37 | self.assertIn('maintainer', data.lower()) | ||
38 | self.assertIn('patch', data.lower()) | ||
39 | # Check that there is an email address in the README | ||
40 | email_regex = re.compile(r"[^@]+@[^@]+") | ||
41 | self.assertTrue(email_regex.match(data)) | ||
42 | |||
29 | def test_parse(self): | 43 | def test_parse(self): |
30 | check_command('Layer %s failed to parse.' % self.tc.layer['name'], | 44 | check_command('Layer %s failed to parse.' % self.tc.layer['name'], |
31 | 'bitbake -p') | 45 | 'bitbake -p') |
@@ -43,6 +57,36 @@ class CommonCheckLayer(OECheckLayerTestCase): | |||
43 | ''' | 57 | ''' |
44 | get_signatures(self.td['builddir'], failsafe=False) | 58 | get_signatures(self.td['builddir'], failsafe=False) |
45 | 59 | ||
60 | def test_world_inherit_class(self): | ||
61 | ''' | ||
62 | This also does "bitbake -S none world" along with inheriting "yocto-check-layer" | ||
63 | class, which can do additional per-recipe test cases. | ||
64 | ''' | ||
65 | msg = [] | ||
66 | try: | ||
67 | get_signatures(self.td['builddir'], failsafe=False, machine=None, extravars='BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS INHERIT" INHERIT="yocto-check-layer"') | ||
68 | except RuntimeError as ex: | ||
69 | msg.append(str(ex)) | ||
70 | if msg: | ||
71 | msg.insert(0, 'Layer %s failed additional checks from yocto-check-layer.bbclass\nSee below log for specific recipe parsing errors:\n' % \ | ||
72 | self.tc.layer['name']) | ||
73 | self.fail('\n'.join(msg)) | ||
74 | |||
75 | @unittest.expectedFailure | ||
76 | def test_patches_upstream_status(self): | ||
77 | import sys | ||
78 | sys.path.append(os.path.join(sys.path[0], '../../../../meta/lib/')) | ||
79 | import oe.qa | ||
80 | patches = [] | ||
81 | for dirpath, dirs, files in os.walk(self.tc.layer['path']): | ||
82 | for filename in files: | ||
83 | if filename.endswith(".patch"): | ||
84 | ppath = os.path.join(dirpath, filename) | ||
85 | if oe.qa.check_upstream_status(ppath): | ||
86 | patches.append(ppath) | ||
87 | self.assertEqual(len(patches), 0 , \ | ||
88 | msg="Found following patches with malformed or missing upstream status:\n%s" % '\n'.join([str(patch) for patch in patches])) | ||
89 | |||
46 | def test_signatures(self): | 90 | def test_signatures(self): |
47 | if self.tc.layer['type'] == LayerType.SOFTWARE and \ | 91 | if self.tc.layer['type'] == LayerType.SOFTWARE and \ |
48 | not self.tc.test_software_layer_signatures: | 92 | not self.tc.test_software_layer_signatures: |
diff --git a/scripts/lib/checklayer/cases/distro.py b/scripts/lib/checklayer/cases/distro.py index f0bee5493c..a35332451c 100644 --- a/scripts/lib/checklayer/cases/distro.py +++ b/scripts/lib/checklayer/cases/distro.py | |||
@@ -11,7 +11,7 @@ from checklayer.case import OECheckLayerTestCase | |||
11 | class DistroCheckLayer(OECheckLayerTestCase): | 11 | class DistroCheckLayer(OECheckLayerTestCase): |
12 | @classmethod | 12 | @classmethod |
13 | def setUpClass(self): | 13 | def setUpClass(self): |
14 | if self.tc.layer['type'] != LayerType.DISTRO: | 14 | if self.tc.layer['type'] not in (LayerType.DISTRO, LayerType.CORE): |
15 | raise unittest.SkipTest("DistroCheckLayer: Layer %s isn't Distro one." %\ | 15 | raise unittest.SkipTest("DistroCheckLayer: Layer %s isn't Distro one." %\ |
16 | self.tc.layer['name']) | 16 | self.tc.layer['name']) |
17 | 17 | ||