blob: d1d50e673ed90cc6697cae92682da9be785f5863 [file] [log] [blame]
Doug Zongker9296f092012-03-20 16:42:22 -07001#!/usr/bin/env python
2#
3# Copyright (C) 2012 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import sys
18import os
19
20try:
21 from hashlib import sha1
22except ImportError:
23 from sha import sha as sha1
24
Spandan Dasce69e9c2022-10-23 01:13:50 +000025import argparse
26
27parser = argparse.ArgumentParser()
28parser.add_argument("--board_info_txt", nargs="?", required=True)
29parser.add_argument("--board_info_check", nargs="*", required=True)
30args = parser.parse_args()
31
32if not args.board_info_txt:
Doug Zongker8f3670b2012-03-21 10:01:01 -070033 sys.exit(0)
34
Doug Zongker9296f092012-03-20 16:42:22 -070035build_info = {}
Spandan Dasce69e9c2022-10-23 01:13:50 +000036f = open(args.board_info_txt)
Doug Zongker9296f092012-03-20 16:42:22 -070037for line in f:
38 line = line.strip()
39 if line.startswith("require"):
40 key, value = line.split()[1].split("=", 1)
41 build_info[key] = value
42f.close()
43
44bad = False
45
Spandan Dasce69e9c2022-10-23 01:13:50 +000046for item in args.board_info_check:
Doug Zongker9296f092012-03-20 16:42:22 -070047 key, fn = item.split(":", 1)
48
49 values = build_info.get(key, None)
50 if not values:
51 continue
52 values = values.split("|")
53
54 f = open(fn, "rb")
55 digest = sha1(f.read()).hexdigest()
56 f.close()
57
58 versions = {}
59 try:
60 f = open(fn + ".sha1")
61 except IOError:
Spandan Dasce69e9c2022-10-23 01:13:50 +000062 if not bad: print()
63 print("*** Error opening \"%s.sha1\"; can't verify %s" % (fn, key))
Doug Zongker9296f092012-03-20 16:42:22 -070064 bad = True
65 continue
66 for line in f:
67 line = line.strip()
68 if not line or line.startswith("#"): continue
69 h, v = line.split()
70 versions[h] = v
71
72 if digest not in versions:
Spandan Dasce69e9c2022-10-23 01:13:50 +000073 if not bad: print()
74 print("*** SHA-1 hash of \"%s\" doesn't appear in \"%s.sha1\"" % (fn, fn))
Doug Zongker9296f092012-03-20 16:42:22 -070075 bad = True
76 continue
77
78 if versions[digest] not in values:
Spandan Dasce69e9c2022-10-23 01:13:50 +000079 if not bad: print()
80 print("*** \"%s\" is version %s; not any %s allowed by \"%s\"." % (
81 fn, versions[digest], key, args.board_info_txt))
Doug Zongker9296f092012-03-20 16:42:22 -070082 bad = True
83
84if bad:
Spandan Dasce69e9c2022-10-23 01:13:50 +000085 print()
Doug Zongker9296f092012-03-20 16:42:22 -070086 sys.exit(1)