Inseob Kim | 36d9d39 | 2023-09-04 17:40:03 +0900 | [diff] [blame] | 1 | # 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 | |
| 15 | from optparse import OptionParser |
| 16 | import mini_parser |
| 17 | import os |
| 18 | import sys |
| 19 | |
| 20 | def 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 Kim | 68b071e | 2024-04-22 15:44:12 +0900 | [diff] [blame^] | 40 | 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 Kim | 36d9d39 | 2023-09-04 17:40:03 +0900 | [diff] [blame] | 44 | |
| 45 | results = "" |
| 46 | removed_types = prebuilt_policy.types - current_policy.types |
Inseob Kim | 68b071e | 2024-04-22 15:44:12 +0900 | [diff] [blame^] | 47 | added_types = current_policy.types - prebuilt_policy.types |
Inseob Kim | 36d9d39 | 2023-09-04 17:40:03 +0900 | [diff] [blame] | 48 | removed_attributes = prebuilt_policy.typeattributes - current_policy.typeattributes |
Inseob Kim | 68b071e | 2024-04-22 15:44:12 +0900 | [diff] [blame^] | 49 | 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 Kim | 36d9d39 | 2023-09-04 17:40:03 +0900 | [diff] [blame] | 54 | |
| 55 | if removed_types: |
| 56 | results += "The following public types were removed:\n" + ", ".join(removed_types) + "\n" |
| 57 | |
Inseob Kim | 68b071e | 2024-04-22 15:44:12 +0900 | [diff] [blame^] | 58 | if added_types: |
| 59 | results += "The following public types were added:\n" + ", ".join(added_types) + "\n" |
| 60 | |
Inseob Kim | 36d9d39 | 2023-09-04 17:40:03 +0900 | [diff] [blame] | 61 | if removed_attributes: |
| 62 | results += "The following public attributes were removed:\n" + ", ".join(removed_attributes) + "\n" |
| 63 | |
Inseob Kim | 68b071e | 2024-04-22 15:44:12 +0900 | [diff] [blame^] | 64 | 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 | ****************************** |
| 70 | You have tried to change system/sepolicy/public after vendor API freeze. |
| 71 | To make these errors go away, you can guard types and attributes listed above, |
| 72 | so they won't be included to the release build. |
| 73 | |
| 74 | See an example of how to guard them: |
| 75 | https://android-review.googlesource.com/3050544 |
| 76 | ****************************** |
| 77 | ''') |
Inseob Kim | 36d9d39 | 2023-09-04 17:40:03 +0900 | [diff] [blame] | 78 | |
| 79 | if __name__ == '__main__': |
| 80 | do_main() |