blob: 83d3ab277ff8fb0e20fe603ea787f8671a4be643 [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
25build_info = {}
26f = open(sys.argv[1])
27for line in f:
28 line = line.strip()
29 if line.startswith("require"):
30 key, value = line.split()[1].split("=", 1)
31 build_info[key] = value
32f.close()
33
34bad = False
35
36for item in sys.argv[2:]:
37 key, fn = item.split(":", 1)
38
39 values = build_info.get(key, None)
40 if not values:
41 continue
42 values = values.split("|")
43
44 f = open(fn, "rb")
45 digest = sha1(f.read()).hexdigest()
46 f.close()
47
48 versions = {}
49 try:
50 f = open(fn + ".sha1")
51 except IOError:
52 if not bad: print
53 print "*** Error opening \"%s.sha1\"; can't verify %s" % (fn, key)
54 bad = True
55 continue
56 for line in f:
57 line = line.strip()
58 if not line or line.startswith("#"): continue
59 h, v = line.split()
60 versions[h] = v
61
62 if digest not in versions:
63 if not bad: print
64 print "*** SHA-1 hash of \"%s\" doesn't appear in \"%s.sha1\"" % (fn, fn)
65 bad = True
66 continue
67
68 if versions[digest] not in values:
69 if not bad: print
70 print "*** \"%s\" is version %s; not any %s allowed by \"%s\"." % (
71 fn, versions[digest], key, sys.argv[1])
72 bad = True
73
74if bad:
75 print
76 sys.exit(1)