blob: b9b935cd8fc82f589df2cd081eb148693501d3f2 [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)
Inseob Kim68b071e2024-04-22 15:44:12 +090040 current_policy.typeattributes = set(filter(lambda x: "base_typeattr_" not in x,
41 current_policy.typeattributes))
42 prebuilt_policy.typeattributes = set(filter(lambda x: "base_typeattr_" not in x,
43 prebuilt_policy.typeattributes))
Inseob Kim36d9d392023-09-04 17:40:03 +090044
45 results = ""
46 removed_types = prebuilt_policy.types - current_policy.types
Inseob Kim68b071e2024-04-22 15:44:12 +090047 added_types = current_policy.types - prebuilt_policy.types
Inseob Kim36d9d392023-09-04 17:40:03 +090048 removed_attributes = prebuilt_policy.typeattributes - current_policy.typeattributes
Inseob Kim68b071e2024-04-22 15:44:12 +090049 added_attributes = current_policy.typeattributes - prebuilt_policy.typeattributes
50
51 # TODO(b/330670954): remove this once all internal references are removed.
52 if "proc_compaction_proactiveness" in added_types:
53 added_types.remove("proc_compaction_proactiveness")
Inseob Kim36d9d392023-09-04 17:40:03 +090054
55 if removed_types:
56 results += "The following public types were removed:\n" + ", ".join(removed_types) + "\n"
57
Inseob Kim68b071e2024-04-22 15:44:12 +090058 if added_types:
59 results += "The following public types were added:\n" + ", ".join(added_types) + "\n"
60
Inseob Kim36d9d392023-09-04 17:40:03 +090061 if removed_attributes:
62 results += "The following public attributes were removed:\n" + ", ".join(removed_attributes) + "\n"
63
Inseob Kim68b071e2024-04-22 15:44:12 +090064 if added_attributes:
65 results += "The following public attributes were added:\n" + ", ".join(added_attributes) + "\n"
66
67 if results:
68 sys.exit(f'''{results}
69******************************
70You have tried to change system/sepolicy/public after vendor API freeze.
71To make these errors go away, you can guard types and attributes listed above,
72so they won't be included to the release build.
73
74See an example of how to guard them:
75 https://android-review.googlesource.com/3050544
76******************************
77''')
Inseob Kim36d9d392023-09-04 17:40:03 +090078
79if __name__ == '__main__':
80 do_main()