summaryrefslogtreecommitdiffstats
path: root/scripts/lib/checklayer
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/checklayer')
-rw-r--r--scripts/lib/checklayer/__init__.py59
-rw-r--r--scripts/lib/checklayer/cases/bsp.py4
-rw-r--r--scripts/lib/checklayer/cases/common.py70
-rw-r--r--scripts/lib/checklayer/cases/distro.py2
4 files changed, 120 insertions, 15 deletions
diff --git a/scripts/lib/checklayer/__init__.py b/scripts/lib/checklayer/__init__.py
index e69a10f452..86aadf39a6 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
124def detect_layers(layer_directories, no_auto): 129def detect_layers(layer_directories, no_auto):
@@ -156,6 +161,27 @@ def _find_layer(depend, layers):
156 return layer 161 return layer
157 return None 162 return None
158 163
164def 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
159def get_layer_dependencies(layer, layers, logger): 185def 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.' % \
@@ -261,7 +287,7 @@ def check_command(error_msg, cmd, cwd=None):
261 raise RuntimeError(msg) 287 raise RuntimeError(msg)
262 return output 288 return output
263 289
264def get_signatures(builddir, failsafe=False, machine=None): 290def get_signatures(builddir, failsafe=False, machine=None, extravars=None):
265 import re 291 import re
266 292
267 # some recipes needs to be excluded like meta-world-pkgdata 293 # some recipes needs to be excluded like meta-world-pkgdata
@@ -272,13 +298,16 @@ def get_signatures(builddir, failsafe=False, machine=None):
272 sigs = {} 298 sigs = {}
273 tune2tasks = {} 299 tune2tasks = {}
274 300
275 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 += ' '
276 if machine: 305 if machine:
277 cmd += 'MACHINE=%s ' % machine 306 cmd += 'MACHINE=%s ' % machine
278 cmd += 'bitbake ' 307 cmd += 'bitbake '
279 if failsafe: 308 if failsafe:
280 cmd += '-k ' 309 cmd += '-k '
281 cmd += '-S none world' 310 cmd += '-S lockedsigs world'
282 sigs_file = os.path.join(builddir, 'locked-sigs.inc') 311 sigs_file = os.path.join(builddir, 'locked-sigs.inc')
283 if os.path.exists(sigs_file): 312 if os.path.exists(sigs_file):
284 os.unlink(sigs_file) 313 os.unlink(sigs_file)
@@ -295,8 +324,8 @@ def get_signatures(builddir, failsafe=False, machine=None):
295 else: 324 else:
296 raise 325 raise
297 326
298 sig_regex = re.compile("^(?P<task>.*:.*):(?P<hash>.*) .$") 327 sig_regex = re.compile(r"^(?P<task>.*:.*):(?P<hash>.*) .$")
299 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*")
300 current_tune = None 329 current_tune = None
301 with open(sigs_file, 'r') as f: 330 with open(sigs_file, 'r') as f:
302 for line in f.readlines(): 331 for line in f.readlines():
@@ -423,3 +452,15 @@ def compare_signatures(old_sigs, curr_sigs):
423 msg.extend([' ' + line for line in output.splitlines()]) 452 msg.extend([' ' + line for line in output.splitlines()])
424 msg.append('') 453 msg.append('')
425 return '\n'.join(msg) 454 return '\n'.join(msg)
455
456
457def get_git_toplevel(directory):
458 """
459 Try and find the top of the git repository that directory might be in.
460 Returns the top-level directory, or None.
461 """
462 cmd = ["git", "-C", directory, "rev-parse", "--show-toplevel"]
463 try:
464 return subprocess.check_output(cmd, text=True).strip()
465 except:
466 return None
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
11class BSPCheckLayer(OECheckLayerTestCase): 11class 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 fdfb5d18cd..ddead69a7b 100644
--- a/scripts/lib/checklayer/cases/common.py
+++ b/scripts/lib/checklayer/cases/common.py
@@ -7,11 +7,14 @@ import glob
7import os 7import os
8import unittest 8import unittest
9import re 9import re
10from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures 10from checklayer import get_signatures, LayerType, check_command, compare_signatures, get_git_toplevel
11from checklayer.case import OECheckLayerTestCase 11from checklayer.case import OECheckLayerTestCase
12 12
13class CommonCheckLayer(OECheckLayerTestCase): 13class CommonCheckLayer(OECheckLayerTestCase):
14 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
15 # 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).
16 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]*'))
17 self.assertTrue(len(readme_files) > 0, 20 self.assertTrue(len(readme_files) > 0,
@@ -31,12 +34,44 @@ class CommonCheckLayer(OECheckLayerTestCase):
31 if re.search('README', data, re.IGNORECASE): 34 if re.search('README', data, re.IGNORECASE):
32 return 35 return
33 36
34 self.assertIn('maintainer', data) 37 self.assertIn('maintainer', data.lower())
35 self.assertIn('patch',data) 38 self.assertIn('patch', data.lower())
36 # Check that there is an email address in the README 39 # Check that there is an email address in the README
37 email_regex = re.compile(r"[^@]+@[^@]+") 40 email_regex = re.compile(r"[^@]+@[^@]+")
38 self.assertTrue(email_regex.match(data)) 41 self.assertTrue(email_regex.match(data))
39 42
43 def find_file_by_name(self, globs):
44 """
45 Utility function to find a file that matches the specified list of
46 globs, in either the layer directory itself or the repository top-level
47 directory.
48 """
49 directories = [self.tc.layer["path"]]
50 toplevel = get_git_toplevel(directories[0])
51 if toplevel:
52 directories.append(toplevel)
53
54 for path in directories:
55 for name in globs:
56 files = glob.glob(os.path.join(path, name))
57 if files:
58 return sorted(files)[0]
59 return None
60
61 def test_security(self):
62 """
63 Test that the layer has a SECURITY.md (or similar) file, either in the
64 layer itself or at the top of the containing git repository.
65 """
66 if self.tc.layer["type"] == LayerType.CORE:
67 raise unittest.SkipTest("Core layer's SECURITY is top level")
68
69 filename = self.find_file_by_name(("SECURITY", "SECURITY.*"))
70 self.assertTrue(filename, msg="Layer doesn't contain a SECURITY.md file.")
71
72 size = os.path.getsize(filename)
73 self.assertGreater(size, 0, msg=f"{filename} has no content.")
74
40 def test_parse(self): 75 def test_parse(self):
41 check_command('Layer %s failed to parse.' % self.tc.layer['name'], 76 check_command('Layer %s failed to parse.' % self.tc.layer['name'],
42 'bitbake -p') 77 'bitbake -p')
@@ -54,6 +89,35 @@ class CommonCheckLayer(OECheckLayerTestCase):
54 ''' 89 '''
55 get_signatures(self.td['builddir'], failsafe=False) 90 get_signatures(self.td['builddir'], failsafe=False)
56 91
92 def test_world_inherit_class(self):
93 '''
94 This also does "bitbake -S none world" along with inheriting "yocto-check-layer"
95 class, which can do additional per-recipe test cases.
96 '''
97 msg = []
98 try:
99 get_signatures(self.td['builddir'], failsafe=False, machine=None, extravars='BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS INHERIT" INHERIT="yocto-check-layer"')
100 except RuntimeError as ex:
101 msg.append(str(ex))
102 if msg:
103 msg.insert(0, 'Layer %s failed additional checks from yocto-check-layer.bbclass\nSee below log for specific recipe parsing errors:\n' % \
104 self.tc.layer['name'])
105 self.fail('\n'.join(msg))
106
107 def test_patches_upstream_status(self):
108 import sys
109 sys.path.append(os.path.join(sys.path[0], '../../../../meta/lib/'))
110 import oe.qa
111 patches = []
112 for dirpath, dirs, files in os.walk(self.tc.layer['path']):
113 for filename in files:
114 if filename.endswith(".patch"):
115 ppath = os.path.join(dirpath, filename)
116 if oe.qa.check_upstream_status(ppath):
117 patches.append(ppath)
118 self.assertEqual(len(patches), 0 , \
119 msg="Found following patches with malformed or missing upstream status:\n%s" % '\n'.join([str(patch) for patch in patches]))
120
57 def test_signatures(self): 121 def test_signatures(self):
58 if self.tc.layer['type'] == LayerType.SOFTWARE and \ 122 if self.tc.layer['type'] == LayerType.SOFTWARE and \
59 not self.tc.test_software_layer_signatures: 123 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
11class DistroCheckLayer(OECheckLayerTestCase): 11class 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