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