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 ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | func init() { |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 22 | RegisterHiddenApiSingletonComponents(android.InitRegistrationContext) |
| 23 | } |
| 24 | |
| 25 | func RegisterHiddenApiSingletonComponents(ctx android.RegistrationContext) { |
| 26 | ctx.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 27 | } |
| 28 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 29 | var PrepareForTestWithHiddenApiBuildComponents = android.FixtureRegisterWithContext(RegisterHiddenApiSingletonComponents) |
| 30 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 31 | type hiddenAPISingletonPathsStruct struct { |
Paul Duffin | ff774a0 | 2021-01-29 12:53:15 +0000 | [diff] [blame] | 32 | // The path to the CSV file that contains the flags that will be encoded into the dex boot jars. |
| 33 | // |
| 34 | // It is created by the generate_hiddenapi_lists.py tool that is passed the stubFlags along with |
| 35 | // a number of additional files that are used to augment the information in the stubFlags with |
| 36 | // manually curated data. |
| 37 | flags android.OutputPath |
| 38 | |
| 39 | // The path to the CSV index file that contains mappings from Java signature to source location |
| 40 | // information for all Java elements annotated with the UnsupportedAppUsage annotation in the |
| 41 | // source of all the boot jars. |
| 42 | // |
| 43 | // It is created by the merge_csv tool which merges all the hiddenAPI.indexCSVPath files that have |
| 44 | // been created by the rest of the build. That includes the index files generated for |
| 45 | // <x>-hiddenapi modules. |
| 46 | index android.OutputPath |
| 47 | |
| 48 | // The path to the CSV metadata file that contains mappings from Java signature to the value of |
| 49 | // properties specified on UnsupportedAppUsage annotations in the source of all the boot jars. |
| 50 | // |
| 51 | // It is created by the merge_csv tool which merges all the hiddenAPI.metadataCSVPath files that |
| 52 | // have been created by the rest of the build. That includes the metadata files generated for |
| 53 | // <x>-hiddenapi modules. |
| 54 | metadata android.OutputPath |
| 55 | |
| 56 | // The path to the CSV metadata file that contains mappings from Java signature to flags obtained |
| 57 | // from the public, system and test API stubs. |
| 58 | // |
| 59 | // This is created by the hiddenapi tool which is given dex files for the public, system and test |
| 60 | // API stubs (including product specific stubs) along with dex boot jars, so does not include |
| 61 | // <x>-hiddenapi modules. For each API surface (i.e. public, system, test) it records which |
| 62 | // members in the dex boot jars match a member in the dex stub jars for that API surface and then |
| 63 | // outputs a file containing the signatures of all members in the dex boot jars along with the |
| 64 | // flags that indicate which API surface it belongs, if any. |
| 65 | // |
| 66 | // e.g. a dex member that matches a member in the public dex stubs would have flags |
| 67 | // "public-api,system-api,test-api" set (as system and test are both supersets of public). A dex |
| 68 | // member that didn't match a member in any of the dex stubs is still output it just has an empty |
| 69 | // set of flags. |
| 70 | // |
| 71 | // The notion of matching is quite complex, it is not restricted to just exact matching but also |
| 72 | // follows the Java inheritance rules. e.g. if a method is public then all overriding/implementing |
| 73 | // methods are also public. If an interface method is public and a class inherits an |
| 74 | // implementation of that method from a super class then that super class method is also public. |
| 75 | // That ensures that any method that can be called directly by an App through a public method is |
| 76 | // visible to that App. |
| 77 | // |
| 78 | // Propagating the visibility of members across the inheritance hierarchy at build time will cause |
| 79 | // problems when modularizing and unbundling as it that propagation can cross module boundaries. |
| 80 | // e.g. Say that a private framework class implements a public interface and inherits an |
| 81 | // implementation of one of its methods from a core platform ART class. In that case the ART |
| 82 | // implementation method needs to be marked as public which requires the build to have access to |
| 83 | // the framework implementation classes at build time. The work to rectify this is being tracked |
| 84 | // at http://b/178693149. |
| 85 | // |
| 86 | // This file (or at least those items marked as being in the public-api) is used by hiddenapi when |
| 87 | // creating the metadata and flags for the individual modules in order to perform consistency |
| 88 | // checks and filter out bridge methods that are part of the public API. The latter relies on the |
| 89 | // propagation of visibility across the inheritance hierarchy. |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame] | 90 | stubFlags android.OutputPath |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | var hiddenAPISingletonPathsKey = android.NewOnceKey("hiddenAPISingletonPathsKey") |
| 94 | |
| 95 | // hiddenAPISingletonPaths creates all the paths for singleton files the first time it is called, which may be |
| 96 | // from a ModuleContext that needs to reference a file that will be created by a singleton rule that hasn't |
| 97 | // yet been created. |
| 98 | func hiddenAPISingletonPaths(ctx android.PathContext) hiddenAPISingletonPathsStruct { |
| 99 | return ctx.Config().Once(hiddenAPISingletonPathsKey, func() interface{} { |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 100 | // Make the paths relative to the out/soong/hiddenapi directory instead of to the out/soong/ |
| 101 | // directory. This ensures that if they are used as java_resources they do not end up in a |
| 102 | // hiddenapi directory in the resulting APK. |
| 103 | hiddenapiDir := android.PathForOutput(ctx, "hiddenapi") |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 104 | return hiddenAPISingletonPathsStruct{ |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 105 | flags: hiddenapiDir.Join(ctx, "hiddenapi-flags.csv"), |
| 106 | index: hiddenapiDir.Join(ctx, "hiddenapi-index.csv"), |
| 107 | metadata: hiddenapiDir.Join(ctx, "hiddenapi-unsupported.csv"), |
| 108 | stubFlags: hiddenapiDir.Join(ctx, "hiddenapi-stub-flags.txt"), |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 109 | } |
| 110 | }).(hiddenAPISingletonPathsStruct) |
| 111 | } |
| 112 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 113 | func hiddenAPISingletonFactory() android.Singleton { |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 114 | return &hiddenAPISingleton{} |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 117 | type hiddenAPISingleton struct { |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame^] | 118 | flags android.Path |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 119 | } |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 120 | |
| 121 | // hiddenAPI singleton rules |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 122 | func (h *hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 123 | // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true |
| 124 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | stubFlagsRule(ctx) |
| 129 | |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 130 | // If there is a prebuilt hiddenapi dir, generate rules to use the |
| 131 | // files within. Generally, we build the hiddenapi files from source |
| 132 | // during the build, ensuring consistency. It's possible, in a split |
| 133 | // build (framework and vendor) scenario, for the vendor build to use |
| 134 | // prebuilt hiddenapi files from the framework build. In this scenario, |
| 135 | // the framework and vendor builds must use the same source to ensure |
| 136 | // consistency. |
| 137 | |
| 138 | if ctx.Config().PrebuiltHiddenApiDir(ctx) != "" { |
| 139 | h.flags = prebuiltFlagsRule(ctx) |
Paul Duffin | 22c7431 | 2021-04-12 16:39:39 +0100 | [diff] [blame] | 140 | prebuiltIndexRule(ctx) |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 141 | return |
| 142 | } |
| 143 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 144 | // 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] | 145 | if ctx.Config().FrameworksBaseDirExists(ctx) { |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 146 | h.flags = flagsRule(ctx) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 147 | } else { |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 148 | h.flags = emptyFlagsRule(ctx) |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Export paths to Make. INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/. |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 153 | func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) { |
| 154 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 155 | return |
| 156 | } |
| 157 | |
| 158 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String()) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image |
| 162 | // modules. |
| 163 | func stubFlagsRule(ctx android.SingletonContext) { |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 164 | var publicStubModules []string |
| 165 | var systemStubModules []string |
| 166 | var testStubModules []string |
| 167 | var corePlatformStubModules []string |
| 168 | |
| 169 | if ctx.Config().AlwaysUsePrebuiltSdks() { |
| 170 | // Build configuration mandates using prebuilt stub modules |
| 171 | publicStubModules = append(publicStubModules, "sdk_public_current_android") |
| 172 | systemStubModules = append(systemStubModules, "sdk_system_current_android") |
| 173 | testStubModules = append(testStubModules, "sdk_test_current_android") |
| 174 | } else { |
| 175 | // Use stub modules built from source |
| 176 | publicStubModules = append(publicStubModules, "android_stubs_current") |
| 177 | systemStubModules = append(systemStubModules, "android_system_stubs_current") |
| 178 | testStubModules = append(testStubModules, "android_test_stubs_current") |
Paul Duffin | 719fed4 | 2019-02-28 16:15:44 +0000 | [diff] [blame] | 179 | } |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 180 | // We do not have prebuilts of the core platform api yet |
| 181 | corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs") |
Paul Duffin | 719fed4 | 2019-02-28 16:15:44 +0000 | [diff] [blame] | 182 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 183 | // Allow products to define their own stubs for custom product jars that apps can use. |
| 184 | publicStubModules = append(publicStubModules, ctx.Config().ProductHiddenAPIStubs()...) |
| 185 | systemStubModules = append(systemStubModules, ctx.Config().ProductHiddenAPIStubsSystem()...) |
| 186 | testStubModules = append(testStubModules, ctx.Config().ProductHiddenAPIStubsTest()...) |
Allen Hair | de816cf | 2019-02-25 16:37:42 -0800 | [diff] [blame] | 187 | if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") { |
| 188 | publicStubModules = append(publicStubModules, "jacoco-stubs") |
| 189 | } |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 190 | |
| 191 | publicStubPaths := make(android.Paths, len(publicStubModules)) |
| 192 | systemStubPaths := make(android.Paths, len(systemStubModules)) |
| 193 | testStubPaths := make(android.Paths, len(testStubModules)) |
| 194 | corePlatformStubPaths := make(android.Paths, len(corePlatformStubModules)) |
| 195 | |
| 196 | moduleListToPathList := map[*[]string]android.Paths{ |
| 197 | &publicStubModules: publicStubPaths, |
| 198 | &systemStubModules: systemStubPaths, |
| 199 | &testStubModules: testStubPaths, |
| 200 | &corePlatformStubModules: corePlatformStubPaths, |
| 201 | } |
| 202 | |
| 203 | var bootDexJars android.Paths |
| 204 | |
| 205 | ctx.VisitAllModules(func(module android.Module) { |
| 206 | // Collect dex jar paths for the modules listed above. |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 207 | if j, ok := module.(UsesLibraryDependency); ok { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 208 | name := ctx.ModuleName(module) |
| 209 | for moduleList, pathList := range moduleListToPathList { |
| 210 | if i := android.IndexList(name, *moduleList); i != -1 { |
Ulyana Trafimovich | 5539e7b | 2020-06-04 14:08:17 +0000 | [diff] [blame] | 211 | pathList[i] = j.DexJarBuildPath() |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // Collect dex jar paths for modules that had hiddenapi encode called on them. |
| 217 | if h, ok := module.(hiddenAPIIntf); ok { |
| 218 | if jar := h.bootDexJar(); jar != nil { |
| 219 | bootDexJars = append(bootDexJars, jar) |
| 220 | } |
| 221 | } |
| 222 | }) |
| 223 | |
| 224 | var missingDeps []string |
| 225 | // Ensure all modules were converted to paths |
| 226 | for moduleList, pathList := range moduleListToPathList { |
| 227 | for i := range pathList { |
| 228 | if pathList[i] == nil { |
Paul Duffin | 7f48eef | 2020-12-03 11:15:58 +0000 | [diff] [blame] | 229 | moduleName := (*moduleList)[i] |
| 230 | pathList[i] = android.PathForOutput(ctx, "missing/module", moduleName) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 231 | if ctx.Config().AllowMissingDependencies() { |
Paul Duffin | 7f48eef | 2020-12-03 11:15:58 +0000 | [diff] [blame] | 232 | missingDeps = append(missingDeps, moduleName) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 233 | } else { |
| 234 | ctx.Errorf("failed to find dex jar path for module %q", |
Paul Duffin | 7f48eef | 2020-12-03 11:15:58 +0000 | [diff] [blame] | 235 | moduleName) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // Singleton rule which applies hiddenapi on all boot class path dex files. |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 242 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 243 | |
| 244 | outputPath := hiddenAPISingletonPaths(ctx).stubFlags |
| 245 | tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp") |
| 246 | |
| 247 | rule.MissingDeps(missingDeps) |
| 248 | |
| 249 | rule.Command(). |
Martin Stjernholm | 7260d06 | 2019-12-09 21:47:14 +0000 | [diff] [blame] | 250 | Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 251 | Text("list"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 252 | FlagForEachInput("--boot-dex=", bootDexJars). |
| 253 | FlagWithInputList("--public-stub-classpath=", publicStubPaths, ":"). |
Andrei Onea | e04da07 | 2019-03-01 17:44:13 +0000 | [diff] [blame] | 254 | FlagWithInputList("--system-stub-classpath=", systemStubPaths, ":"). |
| 255 | FlagWithInputList("--test-stub-classpath=", testStubPaths, ":"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 256 | FlagWithInputList("--core-platform-stub-classpath=", corePlatformStubPaths, ":"). |
| 257 | FlagWithOutput("--out-api-flags=", tempPath) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 258 | |
| 259 | commitChangeForRestat(rule, tempPath, outputPath) |
| 260 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 261 | rule.Build("hiddenAPIStubFlagsFile", "hiddenapi stub flags") |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Paul Duffin | dd63d6d | 2021-02-03 18:34:00 +0000 | [diff] [blame] | 264 | // Checks to see whether the supplied module variant is in the list of boot jars. |
| 265 | // |
| 266 | // This is similar to logic in getBootImageJar() so any changes needed here are likely to be needed |
| 267 | // there too. |
| 268 | // |
| 269 | // TODO(b/179354495): Avoid having to perform this type of check or if necessary dedup it. |
Paul Duffin | 82b3fcf | 2021-02-12 15:42:46 +0000 | [diff] [blame] | 270 | func isModuleInConfiguredList(ctx android.BaseModuleContext, module android.Module, configuredBootJars android.ConfiguredJarList) bool { |
| 271 | name := ctx.OtherModuleName(module) |
Paul Duffin | dd63d6d | 2021-02-03 18:34:00 +0000 | [diff] [blame] | 272 | |
| 273 | // Strip a prebuilt_ prefix so that this can match a prebuilt module that has not been renamed. |
| 274 | name = android.RemoveOptionalPrebuiltPrefix(name) |
| 275 | |
| 276 | // Ignore any module that is not listed in the boot image configuration. |
| 277 | index := configuredBootJars.IndexOfJar(name) |
| 278 | if index == -1 { |
| 279 | return false |
| 280 | } |
| 281 | |
| 282 | // It is an error if the module is not an ApexModule. |
| 283 | if _, ok := module.(android.ApexModule); !ok { |
Paul Duffin | 82b3fcf | 2021-02-12 15:42:46 +0000 | [diff] [blame] | 284 | ctx.ModuleErrorf("is configured in boot jars but does not support being added to an apex") |
Paul Duffin | dd63d6d | 2021-02-03 18:34:00 +0000 | [diff] [blame] | 285 | return false |
| 286 | } |
| 287 | |
Paul Duffin | 82b3fcf | 2021-02-12 15:42:46 +0000 | [diff] [blame] | 288 | apexInfo := ctx.OtherModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
Paul Duffin | dd63d6d | 2021-02-03 18:34:00 +0000 | [diff] [blame] | 289 | |
| 290 | // Now match the apex part of the boot image configuration. |
| 291 | requiredApex := configuredBootJars.Apex(index) |
| 292 | if requiredApex == "platform" { |
| 293 | if len(apexInfo.InApexes) != 0 { |
| 294 | // A platform variant is required but this is for an apex so ignore it. |
| 295 | return false |
| 296 | } |
| 297 | } else if !apexInfo.InApexByBaseName(requiredApex) { |
| 298 | // An apex variant for a specific apex is required but this is the wrong apex. |
| 299 | return false |
| 300 | } |
| 301 | |
| 302 | return true |
| 303 | } |
| 304 | |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 305 | func prebuiltFlagsRule(ctx android.SingletonContext) android.Path { |
| 306 | outputPath := hiddenAPISingletonPaths(ctx).flags |
| 307 | inputPath := android.PathForSource(ctx, ctx.Config().PrebuiltHiddenApiDir(ctx), "hiddenapi-flags.csv") |
| 308 | |
| 309 | ctx.Build(pctx, android.BuildParams{ |
| 310 | Rule: android.Cp, |
| 311 | Output: outputPath, |
| 312 | Input: inputPath, |
| 313 | }) |
| 314 | |
| 315 | return outputPath |
| 316 | } |
| 317 | |
Paul Duffin | 22c7431 | 2021-04-12 16:39:39 +0100 | [diff] [blame] | 318 | func prebuiltIndexRule(ctx android.SingletonContext) { |
| 319 | outputPath := hiddenAPISingletonPaths(ctx).index |
| 320 | inputPath := android.PathForSource(ctx, ctx.Config().PrebuiltHiddenApiDir(ctx), "hiddenapi-index.csv") |
| 321 | |
| 322 | ctx.Build(pctx, android.BuildParams{ |
| 323 | Rule: android.Cp, |
| 324 | Output: outputPath, |
| 325 | Input: inputPath, |
| 326 | }) |
| 327 | } |
| 328 | |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 329 | // flagsRule is a placeholder that simply returns the location of the file, the generation of the |
| 330 | // ninja rules is done in generateHiddenAPIBuildActions. |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 331 | func flagsRule(ctx android.SingletonContext) android.Path { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 332 | outputPath := hiddenAPISingletonPaths(ctx).flags |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 333 | return outputPath |
| 334 | } |
| 335 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 336 | // emptyFlagsRule creates a rule to build an empty hiddenapi-flags.csv, which is needed by master-art-host builds that |
| 337 | // 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] | 338 | func emptyFlagsRule(ctx android.SingletonContext) android.Path { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 339 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 340 | |
| 341 | outputPath := hiddenAPISingletonPaths(ctx).flags |
| 342 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 343 | rule.Command().Text("rm").Flag("-f").Output(outputPath) |
| 344 | rule.Command().Text("touch").Output(outputPath) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 345 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 346 | rule.Build("emptyHiddenAPIFlagsFile", "empty hiddenapi flags") |
Colin Cross | ed023ec | 2019-02-19 12:38:45 -0800 | [diff] [blame] | 347 | |
| 348 | return outputPath |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 349 | } |
| 350 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 351 | // commitChangeForRestat adds a command to a rule that updates outputPath from tempPath if they are different. It |
| 352 | // also marks the rule as restat and marks the tempPath as a temporary file that should not be considered an output of |
| 353 | // the rule. |
| 354 | func commitChangeForRestat(rule *android.RuleBuilder, tempPath, outputPath android.WritablePath) { |
| 355 | rule.Restat() |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 356 | rule.Temporary(tempPath) |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 357 | rule.Command(). |
| 358 | Text("("). |
| 359 | Text("if"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 360 | Text("cmp -s").Input(tempPath).Output(outputPath).Text(";"). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 361 | Text("then"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 362 | Text("rm").Input(tempPath).Text(";"). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 363 | Text("else"). |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 364 | Text("mv").Input(tempPath).Output(outputPath).Text(";"). |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 365 | Text("fi"). |
| 366 | Text(")") |
| 367 | } |