forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_manifest_userdata.py
executable file
·87 lines (69 loc) · 2.44 KB
/
check_manifest_userdata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
from pathlib import Path
from pprint import pprint
import logging
import sys
from west.manifest import Manifest
import pykwalify.core
HERE = Path(__file__).parent
SCRIPTS = HERE.parent
SCHEMA = str(SCRIPTS / 'manifest-userdata-schema.yml')
def userdata_error_message(project):
userdata = project.userdata
if not (isinstance(userdata, dict) and 'ncs' in userdata):
return None
try:
pykwalify.core.Core(source_data=userdata,
schema_files=[SCHEMA]).validate()
except pykwalify.errors.SchemaError as se:
return se.msg
else:
return None
def get_upstream_sha(project):
if not project.userdata:
return None
if not 'ncs' in project.userdata:
return None
return project.userdata['ncs']['upstream-sha']
def main():
# Silence validation errors from pykwalify, which are logged at
# logging.ERROR level. We want to handle those ourselves as
# needed.
logging.getLogger('pykwalify').setLevel(logging.CRITICAL)
manifest = Manifest.from_topdir()
errors = False
for project in manifest.projects:
print(f'checking {project.name} userdata... ', end='')
sys.stdout.flush()
if project.name == 'manifest':
if project.userdata:
print('error: there should be no self: userdata: ', end='')
pprint(project.userdata)
print('To fix, remove this value.')
errors = True
else:
print('OK')
continue
error_message = userdata_error_message(project)
if error_message:
print(error_message)
print('project userdata:')
pprint(project.userdata)
errors = True
continue
upstream_sha = get_upstream_sha(project)
if not upstream_sha:
print('OK')
continue
if not project.is_ancestor_of(upstream_sha,
'refs/heads/manifest-rev'):
print(f'error: invalid "upstream-sha: {upstream_sha}"\n'
"This must be the ancestor of the project's current revision "
f'({project.revision}) which is the upstream merge-base.\n'
'To fix, update the upstream-sha value to the correct commit.')
errors = True
continue
print('OK')
sys.exit(errors)
if __name__ == '__main__':
main()