Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 1 | // Copyright (C) 2021 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 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 19 | "github.com/google/blueprint" |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | // Contains support for processing hiddenAPI in a modular fashion. |
| 23 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 24 | // HiddenAPIFlagFileProperties contains paths to the flag files that can be used to augment the |
| 25 | // information obtained from annotations within the source code in order to create the complete set |
| 26 | // of flags that should be applied to the dex implementation jars on the bootclasspath. |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 27 | // |
| 28 | // Each property contains a list of paths. With the exception of the Unsupported_packages the paths |
| 29 | // of each property reference a plain text file that contains a java signature per line. The flags |
| 30 | // for each of those signatures will be updated in a property specific way. |
| 31 | // |
| 32 | // The Unsupported_packages property contains a list of paths, each of which is a plain text file |
| 33 | // with one Java package per line. All members of all classes within that package (but not nested |
| 34 | // packages) will be updated in a property specific way. |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 35 | type HiddenAPIFlagFileProperties struct { |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 36 | // Marks each signature in the referenced files as being unsupported. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 37 | Unsupported []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 38 | |
| 39 | // Marks each signature in the referenced files as being unsupported because it has been removed. |
| 40 | // Any conflicts with other flags are ignored. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 41 | Removed []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 42 | |
| 43 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= R |
| 44 | // and low priority. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 45 | Max_target_r_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 46 | |
| 47 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= Q. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 48 | Max_target_q []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 49 | |
| 50 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= P. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 51 | Max_target_p []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 52 | |
| 53 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= O |
| 54 | // and low priority. Any conflicts with other flags are ignored. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 55 | Max_target_o_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 56 | |
| 57 | // Marks each signature in the referenced files as being blocked. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 58 | Blocked []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 59 | |
| 60 | // Marks each signature in every package in the referenced files as being unsupported. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 61 | Unsupported_packages []string `android:"path"` |
| 62 | } |
| 63 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 64 | func (p *HiddenAPIFlagFileProperties) hiddenAPIFlagFileInfo(ctx android.ModuleContext) hiddenAPIFlagFileInfo { |
| 65 | info := hiddenAPIFlagFileInfo{categoryToPaths: map[*hiddenAPIFlagFileCategory]android.Paths{}} |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 66 | for _, category := range hiddenAPIFlagFileCategories { |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 67 | paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p)) |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 68 | info.categoryToPaths[category] = paths |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 69 | } |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 70 | return info |
| 71 | } |
| 72 | |
| 73 | type hiddenAPIFlagFileCategory struct { |
| 74 | // propertyName is the name of the property for this category. |
| 75 | propertyName string |
| 76 | |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 77 | // propertyValueReader retrieves the value of the property for this category from the set of |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 78 | // properties. |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 79 | propertyValueReader func(properties *HiddenAPIFlagFileProperties) []string |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 80 | |
| 81 | // commandMutator adds the appropriate command line options for this category to the supplied |
| 82 | // command |
| 83 | commandMutator func(command *android.RuleBuilderCommand, path android.Path) |
| 84 | } |
| 85 | |
| 86 | var hiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 87 | // See HiddenAPIFlagFileProperties.Unsupported |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 88 | { |
| 89 | propertyName: "unsupported", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 90 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 91 | return properties.Unsupported |
| 92 | }, |
| 93 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 94 | command.FlagWithInput("--unsupported ", path) |
| 95 | }, |
| 96 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 97 | // See HiddenAPIFlagFileProperties.Removed |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 98 | { |
| 99 | propertyName: "removed", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 100 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 101 | return properties.Removed |
| 102 | }, |
| 103 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 104 | command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") |
| 105 | }, |
| 106 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 107 | // See HiddenAPIFlagFileProperties.Max_target_r_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 108 | { |
| 109 | propertyName: "max_target_r_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 110 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 111 | return properties.Max_target_r_low_priority |
| 112 | }, |
| 113 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 114 | command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") |
| 115 | }, |
| 116 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 117 | // See HiddenAPIFlagFileProperties.Max_target_q |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 118 | { |
| 119 | propertyName: "max_target_q", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 120 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 121 | return properties.Max_target_q |
| 122 | }, |
| 123 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 124 | command.FlagWithInput("--max-target-q ", path) |
| 125 | }, |
| 126 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 127 | // See HiddenAPIFlagFileProperties.Max_target_p |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 128 | { |
| 129 | propertyName: "max_target_p", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 130 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 131 | return properties.Max_target_p |
| 132 | }, |
| 133 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 134 | command.FlagWithInput("--max-target-p ", path) |
| 135 | }, |
| 136 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 137 | // See HiddenAPIFlagFileProperties.Max_target_o_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 138 | { |
| 139 | propertyName: "max_target_o_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 140 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 141 | return properties.Max_target_o_low_priority |
| 142 | }, |
| 143 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 144 | command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") |
| 145 | }, |
| 146 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 147 | // See HiddenAPIFlagFileProperties.Blocked |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 148 | { |
| 149 | propertyName: "blocked", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 150 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 151 | return properties.Blocked |
| 152 | }, |
| 153 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 154 | command.FlagWithInput("--blocked ", path) |
| 155 | }, |
| 156 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 157 | // See HiddenAPIFlagFileProperties.Unsupported_packages |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 158 | { |
| 159 | propertyName: "unsupported_packages", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame^] | 160 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 161 | return properties.Unsupported_packages |
| 162 | }, |
| 163 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 164 | command.FlagWithInput("--unsupported ", path).Flag("--packages ") |
| 165 | }, |
| 166 | }, |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 169 | // hiddenAPIFlagFileInfo contains paths resolved from HiddenAPIFlagFileProperties |
| 170 | type hiddenAPIFlagFileInfo struct { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 171 | // categoryToPaths maps from the flag file category to the paths containing information for that |
| 172 | // category. |
| 173 | categoryToPaths map[*hiddenAPIFlagFileCategory]android.Paths |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 174 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 175 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 176 | func (i *hiddenAPIFlagFileInfo) append(other hiddenAPIFlagFileInfo) { |
| 177 | for _, category := range hiddenAPIFlagFileCategories { |
| 178 | i.categoryToPaths[category] = append(i.categoryToPaths[category], other.categoryToPaths[category]...) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | var hiddenAPIFlagFileInfoProvider = blueprint.NewProvider(hiddenAPIFlagFileInfo{}) |
| 183 | |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 184 | // ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the |
| 185 | // flags from all the modules, the stub flags, augmented with some additional configuration files. |
| 186 | // |
| 187 | // baseFlagsPath is the path to the flags file containing all the information from the stubs plus |
| 188 | // an entry for every single member in the dex implementation jars of the individual modules. Every |
| 189 | // signature in any of the other files MUST be included in this file. |
| 190 | // |
| 191 | // moduleSpecificFlagsPaths are the paths to the flags files generated by each module using |
| 192 | // information from the baseFlagsPath as well as from annotations within the source. |
| 193 | // |
| 194 | // augmentationInfo is a struct containing paths to files that augment the information provided by |
| 195 | // the moduleSpecificFlagsPaths. |
| 196 | // ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the |
| 197 | // flags from all the modules, the stub flags, augmented with some additional configuration files. |
| 198 | // |
| 199 | // baseFlagsPath is the path to the flags file containing all the information from the stubs plus |
| 200 | // an entry for every single member in the dex implementation jars of the individual modules. Every |
| 201 | // signature in any of the other files MUST be included in this file. |
| 202 | // |
| 203 | // moduleSpecificFlagsPaths are the paths to the flags files generated by each module using |
| 204 | // information from the baseFlagsPath as well as from annotations within the source. |
| 205 | // |
| 206 | // augmentationInfo is a struct containing paths to files that augment the information provided by |
| 207 | // the moduleSpecificFlagsPaths. |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 208 | func ruleToGenerateHiddenApiFlags(ctx android.BuilderContext, outputPath android.WritablePath, baseFlagsPath android.Path, moduleSpecificFlagsPaths android.Paths, augmentationInfo hiddenAPIFlagFileInfo) { |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 209 | tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp") |
| 210 | rule := android.NewRuleBuilder(pctx, ctx) |
| 211 | command := rule.Command(). |
| 212 | BuiltTool("generate_hiddenapi_lists"). |
| 213 | FlagWithInput("--csv ", baseFlagsPath). |
| 214 | Inputs(moduleSpecificFlagsPaths). |
| 215 | FlagWithOutput("--output ", tempPath) |
| 216 | |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 217 | // Add the options for the different categories of flag files. |
| 218 | for _, category := range hiddenAPIFlagFileCategories { |
| 219 | paths := augmentationInfo.categoryToPaths[category] |
| 220 | for _, path := range paths { |
| 221 | category.commandMutator(command, path) |
| 222 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | commitChangeForRestat(rule, tempPath, outputPath) |
| 226 | |
| 227 | rule.Build("hiddenAPIFlagsFile", "hiddenapi flags") |
| 228 | } |