Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 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 ( |
Paul Duffin | 1b033f5 | 2019-06-10 14:15:04 +0100 | [diff] [blame] | 18 | "fmt" |
| 19 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | android.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory) |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame^] | 25 | android.RegisterSingletonType("hiddenapi_index", hiddenAPIIndexSingletonFactory) |
Paul Duffin | 1b033f5 | 2019-06-10 14:15:04 +0100 | [diff] [blame] | 26 | android.RegisterModuleType("hiddenapi_flags", hiddenAPIFlagsFactory) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | type hiddenAPISingletonPathsStruct struct { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 30 | flags android.OutputPath |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame^] | 31 | index android.OutputPath |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 32 | metadata android.OutputPath |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame^] | 33 | stubFlags android.OutputPath |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | var hiddenAPISingletonPathsKey = android.NewOnceKey("hiddenAPISingletonPathsKey") |
| 37 | |
| 38 | // hiddenAPISingletonPaths creates all the paths for singleton files the first time it is called, which may be |
| 39 | // from a ModuleContext that needs to reference a file that will be created by a singleton rule that hasn't |
| 40 | // yet been created. |
| 41 | func hiddenAPISingletonPaths(ctx android.PathContext) hiddenAPISingletonPathsStruct { |
| 42 | return ctx.Config().Once(hiddenAPISingletonPathsKey, func() interface{} { |
| 43 | return hiddenAPISingletonPathsStruct{ |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 44 | flags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-flags.csv"), |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame^] | 45 | index: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-index.csv"), |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 46 | metadata: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-greylist.csv"), |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame^] | 47 | stubFlags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-stub-flags.txt"), |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 48 | } |
| 49 | }).(hiddenAPISingletonPathsStruct) |
| 50 | } |
| 51 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 52 | func hiddenAPISingletonFactory() android.Singleton { |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 53 | return &hiddenAPISingleton{} |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 56 | type hiddenAPISingleton struct { |
| 57 | flags, metadata android.Path |
| 58 | } |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 59 | |
| 60 | // hiddenAPI singleton rules |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 61 | func (h *hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 62 | // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true |
| 63 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | stubFlagsRule(ctx) |
| 68 | |
| 69 | // These rules depend on files located in frameworks/base, skip them if running in a tree that doesn't have them. |
Jiyong Park | 09cb629 | 2019-07-15 15:29:23 +0900 | [diff] [blame] | 70 | if ctx.Config().FrameworksBaseDirExists(ctx) { |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 71 | h.flags = flagsRule(ctx) |
| 72 | h.metadata = metadataRule(ctx) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 73 | } else { |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 74 | h.flags = emptyFlagsRule(ctx) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Export paths to Make. INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/. |
| 79 | // Both paths are used to call dist-for-goals. |
| 80 | func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) { |
| 81 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String()) |
| 86 | |
| 87 | if h.metadata != nil { |
| 88 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_GREYLIST_METADATA", h.metadata.String()) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | // stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image |
| 93 | // modules. |
| 94 | func stubFlagsRule(ctx android.SingletonContext) { |
| 95 | // Public API stubs |
| 96 | publicStubModules := []string{ |
| 97 | "android_stubs_current", |
Paul Duffin | 719fed4 | 2019-02-28 16:15:44 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // Add the android.test.base to the set of stubs only if the android.test.base module is on |
| 101 | // the boot jars list as the runtime will only enforce hiddenapi access against modules on |
| 102 | // that list. |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 103 | if inList("android.test.base", ctx.Config().BootJars()) && !ctx.Config().UnbundledBuildUsePrebuiltSdks() { |
Paul Duffin | 719fed4 | 2019-02-28 16:15:44 +0000 | [diff] [blame] | 104 | publicStubModules = append(publicStubModules, "android.test.base.stubs") |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | // System API stubs |
| 108 | systemStubModules := []string{ |
| 109 | "android_system_stubs_current", |
| 110 | } |
| 111 | |
| 112 | // Test API stubs |
| 113 | testStubModules := []string{ |
| 114 | "android_test_stubs_current", |
| 115 | } |
| 116 | |
| 117 | // Core Platform API stubs |
| 118 | corePlatformStubModules := []string{ |
| 119 | "core.platform.api.stubs", |
| 120 | } |
| 121 | |
| 122 | // Allow products to define their own stubs for custom product jars that apps can use. |
| 123 | publicStubModules = append(publicStubModules, ctx.Config().ProductHiddenAPIStubs()...) |
| 124 | systemStubModules = append(systemStubModules, ctx.Config().ProductHiddenAPIStubsSystem()...) |
| 125 | testStubModules = append(testStubModules, ctx.Config().ProductHiddenAPIStubsTest()...) |
Allen Hair | de816cf | 2019-02-25 16:37:42 -0800 | [diff] [blame] | 126 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") { |
| 127 | publicStubModules = append(publicStubModules, "jacoco-stubs") |
| 128 | } |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 129 | |
| 130 | publicStubPaths := make(android.Paths, len(publicStubModules)) |
| 131 | systemStubPaths := make(android.Paths, len(systemStubModules)) |
| 132 | testStubPaths := make(android.Paths, len(testStubModules)) |
| 133 | corePlatformStubPaths := make(android.Paths, len(corePlatformStubModules)) |
| 134 | |
| 135 | moduleListToPathList := map[*[]string]android.Paths{ |
| 136 | &publicStubModules: publicStubPaths, |
| 137 | &systemStubModules: systemStubPaths, |
| 138 | &testStubModules: testStubPaths, |
| 139 | &corePlatformStubModules: corePlatformStubPaths, |
| 140 | } |
| 141 | |
| 142 | var bootDexJars android.Paths |
| 143 | |
| 144 | ctx.VisitAllModules(func(module android.Module) { |
| 145 | // Collect dex jar paths for the modules listed above. |
| 146 | if j, ok := module.(Dependency); ok { |
| 147 | name := ctx.ModuleName(module) |
| 148 | for moduleList, pathList := range moduleListToPathList { |
| 149 | if i := android.IndexList(name, *moduleList); i != -1 { |
| 150 | pathList[i] = j.DexJar() |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Collect dex jar paths for modules that had hiddenapi encode called on them. |
| 156 | if h, ok := module.(hiddenAPIIntf); ok { |
| 157 | if jar := h.bootDexJar(); jar != nil { |
Jiyong Park | 4ed468c | 2019-12-19 02:11:10 +0000 | [diff] [blame] | 158 | // For a java lib included in an APEX, only take the one built for |
| 159 | // the platform variant, and skip the variants for APEXes. |
| 160 | // Otherwise, the hiddenapi tool will complain about duplicated classes |
| 161 | if a, ok := module.(android.ApexModule); ok { |
| 162 | if android.InAnyApex(module.Name()) && !a.IsForPlatform() { |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 163 | return |
| 164 | } |
| 165 | } |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 166 | bootDexJars = append(bootDexJars, jar) |
| 167 | } |
| 168 | } |
| 169 | }) |
| 170 | |
| 171 | var missingDeps []string |
| 172 | // Ensure all modules were converted to paths |
| 173 | for moduleList, pathList := range moduleListToPathList { |
| 174 | for i := range pathList { |
| 175 | if pathList[i] == nil { |
Colin Cross | caa0e1e | 2019-04-02 13:03:46 -0700 | [diff] [blame] | 176 | pathList[i] = android.PathForOutput(ctx, "missing") |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 177 | if ctx.Config().AllowMissingDependencies() { |
| 178 | missingDeps = append(missingDeps, (*moduleList)[i]) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 179 | } else { |
| 180 | ctx.Errorf("failed to find dex jar path for module %q", |
| 181 | (*moduleList)[i]) |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // Singleton rule which applies hiddenapi on all boot class path dex files. |
| 188 | rule := android.NewRuleBuilder() |
| 189 | |
| 190 | outputPath := hiddenAPISingletonPaths(ctx).stubFlags |
| 191 | tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp") |
| 192 | |
| 193 | rule.MissingDeps(missingDeps) |
| 194 | |
| 195 | rule.Command(). |
Martin Stjernholm | 7260d06 | 2019-12-09 21:47:14 +0000 | [diff] [blame] | 196 | Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 197 | Text("list"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 198 | FlagForEachInput("--boot-dex=", bootDexJars). |
| 199 | FlagWithInputList("--public-stub-classpath=", publicStubPaths, ":"). |
Andrei Onea | e04da07 | 2019-03-01 17:44:13 +0000 | [diff] [blame] | 200 | FlagWithInputList("--system-stub-classpath=", systemStubPaths, ":"). |
| 201 | FlagWithInputList("--test-stub-classpath=", testStubPaths, ":"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 202 | FlagWithInputList("--core-platform-stub-classpath=", corePlatformStubPaths, ":"). |
| 203 | FlagWithOutput("--out-api-flags=", tempPath) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 204 | |
| 205 | commitChangeForRestat(rule, tempPath, outputPath) |
| 206 | |
| 207 | rule.Build(pctx, ctx, "hiddenAPIStubFlagsFile", "hiddenapi stub flags") |
| 208 | } |
| 209 | |
| 210 | // flagsRule creates a rule to build hiddenapi-flags.csv out of flags.csv files generated for boot image modules and |
| 211 | // the greylists. |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 212 | func flagsRule(ctx android.SingletonContext) android.Path { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 213 | var flagsCSV android.Paths |
| 214 | |
| 215 | var greylistIgnoreConflicts android.Path |
| 216 | |
| 217 | ctx.VisitAllModules(func(module android.Module) { |
| 218 | if h, ok := module.(hiddenAPIIntf); ok { |
| 219 | if csv := h.flagsCSV(); csv != nil { |
| 220 | flagsCSV = append(flagsCSV, csv) |
| 221 | } |
| 222 | } else if ds, ok := module.(*Droidstubs); ok && ctx.ModuleName(module) == "hiddenapi-lists-docs" { |
| 223 | greylistIgnoreConflicts = ds.removedDexApiFile |
| 224 | } |
| 225 | }) |
| 226 | |
| 227 | if greylistIgnoreConflicts == nil { |
| 228 | ctx.Errorf("failed to find removed_dex_api_filename from hiddenapi-lists-docs module") |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 229 | return nil |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | rule := android.NewRuleBuilder() |
| 233 | |
| 234 | outputPath := hiddenAPISingletonPaths(ctx).flags |
| 235 | tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp") |
| 236 | |
| 237 | stubFlags := hiddenAPISingletonPaths(ctx).stubFlags |
| 238 | |
| 239 | rule.Command(). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 240 | Tool(android.PathForSource(ctx, "frameworks/base/tools/hiddenapi/generate_hiddenapi_lists.py")). |
| 241 | FlagWithInput("--csv ", stubFlags). |
| 242 | Inputs(flagsCSV). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 243 | FlagWithInput("--greylist ", |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 244 | android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist.txt")). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 245 | FlagWithInput("--greylist-ignore-conflicts ", |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 246 | greylistIgnoreConflicts). |
Artur Satayev | c5b4f99 | 2019-11-20 10:40:36 +0000 | [diff] [blame] | 247 | FlagWithInput("--greylist-max-q ", |
| 248 | android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-max-q.txt")). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 249 | FlagWithInput("--greylist-max-p ", |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 250 | android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-max-p.txt")). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 251 | FlagWithInput("--greylist-max-o-ignore-conflicts ", |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 252 | android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-max-o.txt")). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 253 | FlagWithInput("--blacklist ", |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 254 | android.PathForSource(ctx, "frameworks/base/config/hiddenapi-force-blacklist.txt")). |
Andrei Onea | 896237b | 2019-03-29 13:45:58 +0000 | [diff] [blame] | 255 | FlagWithInput("--greylist-packages ", |
| 256 | android.PathForSource(ctx, "frameworks/base/config/hiddenapi-greylist-packages.txt")). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 257 | FlagWithOutput("--output ", tempPath) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 258 | |
| 259 | commitChangeForRestat(rule, tempPath, outputPath) |
| 260 | |
| 261 | rule.Build(pctx, ctx, "hiddenAPIFlagsFile", "hiddenapi flags") |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 262 | |
| 263 | return outputPath |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | // emptyFlagsRule creates a rule to build an empty hiddenapi-flags.csv, which is needed by master-art-host builds that |
| 267 | // have a partial manifest without frameworks/base but still need to build a boot image. |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 268 | func emptyFlagsRule(ctx android.SingletonContext) android.Path { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 269 | rule := android.NewRuleBuilder() |
| 270 | |
| 271 | outputPath := hiddenAPISingletonPaths(ctx).flags |
| 272 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 273 | rule.Command().Text("rm").Flag("-f").Output(outputPath) |
| 274 | rule.Command().Text("touch").Output(outputPath) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 275 | |
| 276 | rule.Build(pctx, ctx, "emptyHiddenAPIFlagsFile", "empty hiddenapi flags") |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 277 | |
| 278 | return outputPath |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // metadataRule creates a rule to build hiddenapi-greylist.csv out of the metadata.csv files generated for boot image |
| 282 | // modules. |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 283 | func metadataRule(ctx android.SingletonContext) android.Path { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 284 | var metadataCSV android.Paths |
| 285 | |
| 286 | ctx.VisitAllModules(func(module android.Module) { |
| 287 | if h, ok := module.(hiddenAPIIntf); ok { |
| 288 | if csv := h.metadataCSV(); csv != nil { |
| 289 | metadataCSV = append(metadataCSV, csv) |
| 290 | } |
| 291 | } |
| 292 | }) |
| 293 | |
| 294 | rule := android.NewRuleBuilder() |
| 295 | |
| 296 | outputPath := hiddenAPISingletonPaths(ctx).metadata |
| 297 | |
| 298 | rule.Command(). |
Artur Satayev | b01dd44 | 2020-01-20 17:53:31 +0000 | [diff] [blame] | 299 | BuiltTool(ctx, "merge_csv"). |
Artur Satayev | 79fac05 | 2020-01-20 19:11:33 +0000 | [diff] [blame] | 300 | FlagWithOutput("--output=", outputPath). |
| 301 | Inputs(metadataCSV) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 302 | |
| 303 | rule.Build(pctx, ctx, "hiddenAPIGreylistMetadataFile", "hiddenapi greylist metadata") |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 304 | |
| 305 | return outputPath |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | // commitChangeForRestat adds a command to a rule that updates outputPath from tempPath if they are different. It |
| 309 | // also marks the rule as restat and marks the tempPath as a temporary file that should not be considered an output of |
| 310 | // the rule. |
| 311 | func commitChangeForRestat(rule *android.RuleBuilder, tempPath, outputPath android.WritablePath) { |
| 312 | rule.Restat() |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 313 | rule.Temporary(tempPath) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 314 | rule.Command(). |
| 315 | Text("("). |
| 316 | Text("if"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 317 | Text("cmp -s").Input(tempPath).Output(outputPath).Text(";"). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 318 | Text("then"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 319 | Text("rm").Input(tempPath).Text(";"). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 320 | Text("else"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 321 | Text("mv").Input(tempPath).Output(outputPath).Text(";"). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 322 | Text("fi"). |
| 323 | Text(")") |
| 324 | } |
Paul Duffin | 1b033f5 | 2019-06-10 14:15:04 +0100 | [diff] [blame] | 325 | |
| 326 | type hiddenAPIFlagsProperties struct { |
| 327 | // name of the file into which the flags will be copied. |
| 328 | Filename *string |
| 329 | } |
| 330 | |
| 331 | type hiddenAPIFlags struct { |
| 332 | android.ModuleBase |
| 333 | |
| 334 | properties hiddenAPIFlagsProperties |
| 335 | |
| 336 | outputFilePath android.OutputPath |
| 337 | } |
| 338 | |
| 339 | func (h *hiddenAPIFlags) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 340 | filename := String(h.properties.Filename) |
| 341 | |
| 342 | inputPath := hiddenAPISingletonPaths(ctx).flags |
| 343 | h.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath |
| 344 | |
| 345 | // This ensures that outputFilePath has the correct name for others to |
| 346 | // use, as the source file may have a different name. |
| 347 | ctx.Build(pctx, android.BuildParams{ |
| 348 | Rule: android.Cp, |
| 349 | Output: h.outputFilePath, |
| 350 | Input: inputPath, |
| 351 | }) |
| 352 | } |
| 353 | |
| 354 | func (h *hiddenAPIFlags) OutputFiles(tag string) (android.Paths, error) { |
| 355 | switch tag { |
| 356 | case "": |
| 357 | return android.Paths{h.outputFilePath}, nil |
| 358 | default: |
| 359 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // hiddenapi-flags provides access to the hiddenapi-flags.csv file generated during the build. |
| 364 | func hiddenAPIFlagsFactory() android.Module { |
| 365 | module := &hiddenAPIFlags{} |
| 366 | module.AddProperties(&module.properties) |
| 367 | android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) |
| 368 | return module |
| 369 | } |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame^] | 370 | |
| 371 | func hiddenAPIIndexSingletonFactory() android.Singleton { |
| 372 | return &hiddenAPIIndexSingleton{} |
| 373 | } |
| 374 | |
| 375 | type hiddenAPIIndexSingleton struct { |
| 376 | index android.Path |
| 377 | } |
| 378 | |
| 379 | func (h *hiddenAPIIndexSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 380 | // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true |
| 381 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | indexes := android.Paths{} |
| 386 | ctx.VisitAllModules(func(module android.Module) { |
| 387 | if h, ok := module.(hiddenAPIIntf); ok { |
| 388 | if h.indexCSV() != nil { |
| 389 | indexes = append(indexes, h.indexCSV()) |
| 390 | } |
| 391 | } |
| 392 | }) |
| 393 | |
| 394 | rule := android.NewRuleBuilder() |
| 395 | rule.Command(). |
| 396 | BuiltTool(ctx, "merge_csv"). |
| 397 | FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties"). |
| 398 | FlagWithOutput("--output=", hiddenAPISingletonPaths(ctx).index). |
| 399 | Inputs(indexes) |
| 400 | rule.Build(pctx, ctx, "singleton-merged-hiddenapi-index", "Singleton merged Hidden API index") |
| 401 | |
| 402 | h.index = hiddenAPISingletonPaths(ctx).index |
| 403 | } |
| 404 | |
| 405 | func (h *hiddenAPIIndexSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 406 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 407 | return |
| 408 | } |
| 409 | |
| 410 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_INDEX", h.index.String()) |
| 411 | } |