blob: 72c8fde33d5c475e2c0aa5e066a1a33c91ff13a4 [file] [log] [blame]
Inseob Kim36d9d392023-09-04 17:40:03 +09001# Copyright 2023 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from optparse import OptionParser
16import mini_parser
17import os
18import sys
19
20def do_main():
21 usage = "sepolicy_freeze_test "
22 usage += "-c current_cil -p prebuilt_cil [--help]"
23 parser = OptionParser(usage=usage)
24 parser.add_option("-c", "--current", dest="current", metavar="FILE")
25 parser.add_option("-p", "--prebuilt", dest="prebuilt", metavar="FILE")
26
27 (options, args) = parser.parse_args()
28
29 if not options.current or not options.prebuilt:
30 sys.exit("Must specify both current and prebuilt\n" + parser.usage)
31 if not os.path.exists(options.current):
32 sys.exit("Current policy " + options.current + " does not exist\n"
33 + parser.usage)
34 if not os.path.exists(options.prebuilt):
35 sys.exit("Prebuilt policy " + options.prebuilt + " does not exist\n"
36 + parser.usage)
37
38 current_policy = mini_parser.MiniCilParser(options.current)
39 prebuilt_policy = mini_parser.MiniCilParser(options.prebuilt)
40
41 results = ""
42 removed_types = prebuilt_policy.types - current_policy.types
43 removed_attributes = prebuilt_policy.typeattributes - current_policy.typeattributes
44 removed_attributes = set(filter(lambda x: "base_typeattr_" not in x, removed_attributes))
45
46 if removed_types:
47 results += "The following public types were removed:\n" + ", ".join(removed_types) + "\n"
48
49 if removed_attributes:
50 results += "The following public attributes were removed:\n" + ", ".join(removed_attributes) + "\n"
51
52 if len(results) > 0:
53 sys.exit(results)
54
55if __name__ == '__main__':
56 do_main()