blob: f72340ab88163ee1fe514ef4aadcafa037a5e9bb [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 Kima6a37262024-03-12 11:25:14 +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 Kima6a37262024-03-12 11:25:14 +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 Kima6a37262024-03-12 11:25:14 +090049 added_attributes = current_policy.typeattributes - prebuilt_policy.typeattributes
Inseob Kim36d9d392023-09-04 17:40:03 +090050
51 if removed_types:
52 results += "The following public types were removed:\n" + ", ".join(removed_types) + "\n"
53
Inseob Kima6a37262024-03-12 11:25:14 +090054 if added_types:
55 results += "The following public types were added:\n" + ", ".join(added_types) + "\n"
56
Inseob Kim36d9d392023-09-04 17:40:03 +090057 if removed_attributes:
58 results += "The following public attributes were removed:\n" + ", ".join(removed_attributes) + "\n"
59
Inseob Kima6a37262024-03-12 11:25:14 +090060 if added_attributes:
61 results += "The following public attributes were added:\n" + ", ".join(added_attributes) + "\n"
62
63 if results:
64 sys.exit(f'''{results}
65******************************
66You have tried to change system/sepolicy/public after vendor API freeze.
67To make these errors go away, you have two choices:
68 1. You can flag-guard types and attributes listed above, so they won't be
69 included to the release build. See examples of how to flag-guard them:
70 https://android-review.googlesource.com/2854391
71 https://android-review.googlesource.com/2967637
72 2. You can update prebuilts by executing the following command:
73 $ cd $ANDROID_BUILD_TOP
74 $ cp -r system/sepolicy/public system/sepolicy/private \\
75 system/sepolicy/prebuilts/api/$(get_build_var BOARD_API_LEVEL)
76 To submit the revised prebuilts to the main Android repository,
77 you will need approval.
78******************************
79''')
Inseob Kim36d9d392023-09-04 17:40:03 +090080
81if __name__ == '__main__':
82 do_main()