blob: 4bd255cbfb473746ee8cdcd2984509b01c061ac4 [file] [log] [blame]
Colin Crossf24a22a2019-01-31 14:12:44 -08001// 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
15package java
16
17import (
Paul Duffin1b033f52019-06-10 14:15:04 +010018 "fmt"
19
Colin Crossf24a22a2019-01-31 14:12:44 -080020 "android/soong/android"
Anton Hanssonb3cbd612020-10-06 12:04:34 +010021 "android/soong/genrule"
Colin Crossf24a22a2019-01-31 14:12:44 -080022)
23
24func init() {
25 android.RegisterSingletonType("hiddenapi", hiddenAPISingletonFactory)
Artur Satayevb5df8a02020-02-19 16:39:59 +000026 android.RegisterSingletonType("hiddenapi_index", hiddenAPIIndexSingletonFactory)
Paul Duffin1b033f52019-06-10 14:15:04 +010027 android.RegisterModuleType("hiddenapi_flags", hiddenAPIFlagsFactory)
Colin Crossf24a22a2019-01-31 14:12:44 -080028}
29
30type hiddenAPISingletonPathsStruct struct {
Colin Crossf24a22a2019-01-31 14:12:44 -080031 flags android.OutputPath
Artur Satayevb5df8a02020-02-19 16:39:59 +000032 index android.OutputPath
Colin Crossf24a22a2019-01-31 14:12:44 -080033 metadata android.OutputPath
Artur Satayevb5df8a02020-02-19 16:39:59 +000034 stubFlags android.OutputPath
Colin Crossf24a22a2019-01-31 14:12:44 -080035}
36
37var hiddenAPISingletonPathsKey = android.NewOnceKey("hiddenAPISingletonPathsKey")
38
39// hiddenAPISingletonPaths creates all the paths for singleton files the first time it is called, which may be
40// from a ModuleContext that needs to reference a file that will be created by a singleton rule that hasn't
41// yet been created.
42func hiddenAPISingletonPaths(ctx android.PathContext) hiddenAPISingletonPathsStruct {
43 return ctx.Config().Once(hiddenAPISingletonPathsKey, func() interface{} {
44 return hiddenAPISingletonPathsStruct{
Colin Crossf24a22a2019-01-31 14:12:44 -080045 flags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-flags.csv"),
Artur Satayevb5df8a02020-02-19 16:39:59 +000046 index: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-index.csv"),
Andrei Onea47841972020-08-10 17:23:52 +010047 metadata: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-unsupported.csv"),
Artur Satayevb5df8a02020-02-19 16:39:59 +000048 stubFlags: android.PathForOutput(ctx, "hiddenapi", "hiddenapi-stub-flags.txt"),
Colin Crossf24a22a2019-01-31 14:12:44 -080049 }
50 }).(hiddenAPISingletonPathsStruct)
51}
52
Colin Crossf24a22a2019-01-31 14:12:44 -080053func hiddenAPISingletonFactory() android.Singleton {
Colin Crossed023ec2019-02-19 12:38:45 -080054 return &hiddenAPISingleton{}
Colin Crossf24a22a2019-01-31 14:12:44 -080055}
56
Colin Crossed023ec2019-02-19 12:38:45 -080057type hiddenAPISingleton struct {
58 flags, metadata android.Path
59}
Colin Crossf24a22a2019-01-31 14:12:44 -080060
61// hiddenAPI singleton rules
Colin Crossed023ec2019-02-19 12:38:45 -080062func (h *hiddenAPISingleton) GenerateBuildActions(ctx android.SingletonContext) {
Colin Crossf24a22a2019-01-31 14:12:44 -080063 // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true
64 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
65 return
66 }
67
68 stubFlagsRule(ctx)
69
Bill Peckhambae47492021-01-08 09:34:44 -080070 // If there is a prebuilt hiddenapi dir, generate rules to use the
71 // files within. Generally, we build the hiddenapi files from source
72 // during the build, ensuring consistency. It's possible, in a split
73 // build (framework and vendor) scenario, for the vendor build to use
74 // prebuilt hiddenapi files from the framework build. In this scenario,
75 // the framework and vendor builds must use the same source to ensure
76 // consistency.
77
78 if ctx.Config().PrebuiltHiddenApiDir(ctx) != "" {
79 h.flags = prebuiltFlagsRule(ctx)
80 return
81 }
82
Colin Crossf24a22a2019-01-31 14:12:44 -080083 // These rules depend on files located in frameworks/base, skip them if running in a tree that doesn't have them.
Jiyong Park09cb6292019-07-15 15:29:23 +090084 if ctx.Config().FrameworksBaseDirExists(ctx) {
Colin Crossed023ec2019-02-19 12:38:45 -080085 h.flags = flagsRule(ctx)
86 h.metadata = metadataRule(ctx)
Colin Crossf24a22a2019-01-31 14:12:44 -080087 } else {
Colin Crossed023ec2019-02-19 12:38:45 -080088 h.flags = emptyFlagsRule(ctx)
89 }
90}
91
92// Export paths to Make. INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
93// Both paths are used to call dist-for-goals.
94func (h *hiddenAPISingleton) MakeVars(ctx android.MakeVarsContext) {
95 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
96 return
97 }
98
99 ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", h.flags.String())
100
101 if h.metadata != nil {
102 ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_GREYLIST_METADATA", h.metadata.String())
Colin Crossf24a22a2019-01-31 14:12:44 -0800103 }
104}
105
106// stubFlagsRule creates the rule to build hiddenapi-stub-flags.txt out of dex jars from stub modules and boot image
107// modules.
108func stubFlagsRule(ctx android.SingletonContext) {
Anton Hanssona2adc372020-07-03 15:31:32 +0100109 var publicStubModules []string
110 var systemStubModules []string
111 var testStubModules []string
112 var corePlatformStubModules []string
113
114 if ctx.Config().AlwaysUsePrebuiltSdks() {
115 // Build configuration mandates using prebuilt stub modules
116 publicStubModules = append(publicStubModules, "sdk_public_current_android")
117 systemStubModules = append(systemStubModules, "sdk_system_current_android")
118 testStubModules = append(testStubModules, "sdk_test_current_android")
119 } else {
120 // Use stub modules built from source
121 publicStubModules = append(publicStubModules, "android_stubs_current")
122 systemStubModules = append(systemStubModules, "android_system_stubs_current")
123 testStubModules = append(testStubModules, "android_test_stubs_current")
Paul Duffin719fed42019-02-28 16:15:44 +0000124 }
Anton Hanssona2adc372020-07-03 15:31:32 +0100125 // We do not have prebuilts of the core platform api yet
126 corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs")
Paul Duffin719fed42019-02-28 16:15:44 +0000127
128 // Add the android.test.base to the set of stubs only if the android.test.base module is on
129 // the boot jars list as the runtime will only enforce hiddenapi access against modules on
130 // that list.
Anton Hanssona2adc372020-07-03 15:31:32 +0100131 if inList("android.test.base", ctx.Config().BootJars()) {
132 if ctx.Config().AlwaysUsePrebuiltSdks() {
133 publicStubModules = append(publicStubModules, "sdk_public_current_android.test.base")
134 } else {
135 publicStubModules = append(publicStubModules, "android.test.base.stubs")
136 }
Colin Crossf24a22a2019-01-31 14:12:44 -0800137 }
138
139 // Allow products to define their own stubs for custom product jars that apps can use.
140 publicStubModules = append(publicStubModules, ctx.Config().ProductHiddenAPIStubs()...)
141 systemStubModules = append(systemStubModules, ctx.Config().ProductHiddenAPIStubsSystem()...)
142 testStubModules = append(testStubModules, ctx.Config().ProductHiddenAPIStubsTest()...)
Allen Hairde816cf2019-02-25 16:37:42 -0800143 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") {
144 publicStubModules = append(publicStubModules, "jacoco-stubs")
145 }
Colin Crossf24a22a2019-01-31 14:12:44 -0800146
147 publicStubPaths := make(android.Paths, len(publicStubModules))
148 systemStubPaths := make(android.Paths, len(systemStubModules))
149 testStubPaths := make(android.Paths, len(testStubModules))
150 corePlatformStubPaths := make(android.Paths, len(corePlatformStubModules))
151
152 moduleListToPathList := map[*[]string]android.Paths{
153 &publicStubModules: publicStubPaths,
154 &systemStubModules: systemStubPaths,
155 &testStubModules: testStubPaths,
156 &corePlatformStubModules: corePlatformStubPaths,
157 }
158
159 var bootDexJars android.Paths
160
161 ctx.VisitAllModules(func(module android.Module) {
162 // Collect dex jar paths for the modules listed above.
163 if j, ok := module.(Dependency); ok {
164 name := ctx.ModuleName(module)
165 for moduleList, pathList := range moduleListToPathList {
166 if i := android.IndexList(name, *moduleList); i != -1 {
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000167 pathList[i] = j.DexJarBuildPath()
Colin Crossf24a22a2019-01-31 14:12:44 -0800168 }
169 }
170 }
171
172 // Collect dex jar paths for modules that had hiddenapi encode called on them.
173 if h, ok := module.(hiddenAPIIntf); ok {
174 if jar := h.bootDexJar(); jar != nil {
Jiyong Park4ed468c2019-12-19 02:11:10 +0000175 // For a java lib included in an APEX, only take the one built for
176 // the platform variant, and skip the variants for APEXes.
177 // Otherwise, the hiddenapi tool will complain about duplicated classes
Colin Cross56a83212020-09-15 18:30:11 -0700178 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
179 if !apexInfo.IsForPlatform() {
180 return
Jiyong Park7f7766d2019-07-25 22:02:35 +0900181 }
Liz Kammer5ca3a622020-08-05 15:40:41 -0700182
Colin Crossf24a22a2019-01-31 14:12:44 -0800183 bootDexJars = append(bootDexJars, jar)
184 }
185 }
186 })
187
188 var missingDeps []string
189 // Ensure all modules were converted to paths
190 for moduleList, pathList := range moduleListToPathList {
191 for i := range pathList {
192 if pathList[i] == nil {
Paul Duffin7f48eef2020-12-03 11:15:58 +0000193 moduleName := (*moduleList)[i]
194 pathList[i] = android.PathForOutput(ctx, "missing/module", moduleName)
Colin Crossf24a22a2019-01-31 14:12:44 -0800195 if ctx.Config().AllowMissingDependencies() {
Paul Duffin7f48eef2020-12-03 11:15:58 +0000196 missingDeps = append(missingDeps, moduleName)
Colin Crossf24a22a2019-01-31 14:12:44 -0800197 } else {
198 ctx.Errorf("failed to find dex jar path for module %q",
Paul Duffin7f48eef2020-12-03 11:15:58 +0000199 moduleName)
Colin Crossf24a22a2019-01-31 14:12:44 -0800200 }
201 }
202 }
203 }
204
205 // Singleton rule which applies hiddenapi on all boot class path dex files.
Colin Crossf1a035e2020-11-16 17:32:30 -0800206 rule := android.NewRuleBuilder(pctx, ctx)
Colin Crossf24a22a2019-01-31 14:12:44 -0800207
208 outputPath := hiddenAPISingletonPaths(ctx).stubFlags
209 tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp")
210
211 rule.MissingDeps(missingDeps)
212
213 rule.Command().
Martin Stjernholm7260d062019-12-09 21:47:14 +0000214 Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")).
Colin Crossf24a22a2019-01-31 14:12:44 -0800215 Text("list").
Colin Cross69f59a32019-02-15 10:39:37 -0800216 FlagForEachInput("--boot-dex=", bootDexJars).
217 FlagWithInputList("--public-stub-classpath=", publicStubPaths, ":").
Andrei Oneae04da072019-03-01 17:44:13 +0000218 FlagWithInputList("--system-stub-classpath=", systemStubPaths, ":").
219 FlagWithInputList("--test-stub-classpath=", testStubPaths, ":").
Colin Cross69f59a32019-02-15 10:39:37 -0800220 FlagWithInputList("--core-platform-stub-classpath=", corePlatformStubPaths, ":").
221 FlagWithOutput("--out-api-flags=", tempPath)
Colin Crossf24a22a2019-01-31 14:12:44 -0800222
223 commitChangeForRestat(rule, tempPath, outputPath)
224
Colin Crossf1a035e2020-11-16 17:32:30 -0800225 rule.Build("hiddenAPIStubFlagsFile", "hiddenapi stub flags")
Colin Crossf24a22a2019-01-31 14:12:44 -0800226}
227
Bill Peckhambae47492021-01-08 09:34:44 -0800228func prebuiltFlagsRule(ctx android.SingletonContext) android.Path {
229 outputPath := hiddenAPISingletonPaths(ctx).flags
230 inputPath := android.PathForSource(ctx, ctx.Config().PrebuiltHiddenApiDir(ctx), "hiddenapi-flags.csv")
231
232 ctx.Build(pctx, android.BuildParams{
233 Rule: android.Cp,
234 Output: outputPath,
235 Input: inputPath,
236 })
237
238 return outputPath
239}
240
Colin Crossf24a22a2019-01-31 14:12:44 -0800241// flagsRule creates a rule to build hiddenapi-flags.csv out of flags.csv files generated for boot image modules and
Aleksei Kalinovf0f5cdc2020-07-28 13:44:24 +0000242// the unsupported API.
Colin Crossed023ec2019-02-19 12:38:45 -0800243func flagsRule(ctx android.SingletonContext) android.Path {
Colin Crossf24a22a2019-01-31 14:12:44 -0800244 var flagsCSV android.Paths
Anton Hanssonb3cbd612020-10-06 12:04:34 +0100245 var combinedRemovedApis android.Path
Colin Crossf24a22a2019-01-31 14:12:44 -0800246
247 ctx.VisitAllModules(func(module android.Module) {
248 if h, ok := module.(hiddenAPIIntf); ok {
249 if csv := h.flagsCSV(); csv != nil {
250 flagsCSV = append(flagsCSV, csv)
251 }
Anton Hanssonb3cbd612020-10-06 12:04:34 +0100252 } else if g, ok := module.(*genrule.Module); ok {
253 if ctx.ModuleName(module) == "combined-removed-dex" {
254 if len(g.GeneratedSourceFiles()) != 1 || combinedRemovedApis != nil {
255 ctx.Errorf("Expected 1 combined-removed-dex module that generates 1 output file.")
256 }
257 combinedRemovedApis = g.GeneratedSourceFiles()[0]
Artur Satayevc7fb5c92020-03-25 16:48:49 +0000258 }
Colin Crossf24a22a2019-01-31 14:12:44 -0800259 }
260 })
261
Anton Hanssonb3cbd612020-10-06 12:04:34 +0100262 if combinedRemovedApis == nil {
263 ctx.Errorf("Failed to find combined-removed-dex.")
264 }
Colin Crossf24a22a2019-01-31 14:12:44 -0800265
Colin Crossf1a035e2020-11-16 17:32:30 -0800266 rule := android.NewRuleBuilder(pctx, ctx)
Colin Crossf24a22a2019-01-31 14:12:44 -0800267
268 outputPath := hiddenAPISingletonPaths(ctx).flags
269 tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp")
270
271 stubFlags := hiddenAPISingletonPaths(ctx).stubFlags
272
273 rule.Command().
Colin Cross69f59a32019-02-15 10:39:37 -0800274 Tool(android.PathForSource(ctx, "frameworks/base/tools/hiddenapi/generate_hiddenapi_lists.py")).
275 FlagWithInput("--csv ", stubFlags).
276 Inputs(flagsCSV).
Aleksei Kalinovf0f5cdc2020-07-28 13:44:24 +0000277 FlagWithInput("--unsupported ",
Andrei Oneaca790812020-08-04 15:34:35 +0100278 android.PathForSource(ctx, "frameworks/base/config/hiddenapi-unsupported.txt")).
Mathew Inwooda44e8c52020-10-20 15:23:04 +0100279 FlagWithInput("--unsupported ", combinedRemovedApis).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed").
Mathew Inwoodc1be2f82021-01-13 15:49:17 +0000280 FlagWithInput("--max-target-r ",
281 android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-r-loprio.txt")).FlagWithArg("--tag ", "lo-prio").
Aleksei Kalinovf0f5cdc2020-07-28 13:44:24 +0000282 FlagWithInput("--max-target-q ",
Andrei Oneaca790812020-08-04 15:34:35 +0100283 android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-q.txt")).
Aleksei Kalinovf0f5cdc2020-07-28 13:44:24 +0000284 FlagWithInput("--max-target-p ",
Andrei Oneaca790812020-08-04 15:34:35 +0100285 android.PathForSource(ctx, "frameworks/base/config/hiddenapi-max-target-p.txt")).
Mathew Inwooda44e8c52020-10-20 15:23:04 +0100286 FlagWithInput("--max-target-o ", android.PathForSource(
Mathew Inwood1ef4ba92020-11-10 14:49:43 +0000287 ctx, "frameworks/base/config/hiddenapi-max-target-o.txt")).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio").
Aleksei Kalinovf0f5cdc2020-07-28 13:44:24 +0000288 FlagWithInput("--blocked ",
Andrei Oneaca790812020-08-04 15:34:35 +0100289 android.PathForSource(ctx, "frameworks/base/config/hiddenapi-force-blocked.txt")).
Mathew Inwooda44e8c52020-10-20 15:23:04 +0100290 FlagWithInput("--unsupported ", android.PathForSource(
291 ctx, "frameworks/base/config/hiddenapi-unsupported-packages.txt")).Flag("--packages ").
Colin Cross69f59a32019-02-15 10:39:37 -0800292 FlagWithOutput("--output ", tempPath)
Colin Crossf24a22a2019-01-31 14:12:44 -0800293
294 commitChangeForRestat(rule, tempPath, outputPath)
295
Colin Crossf1a035e2020-11-16 17:32:30 -0800296 rule.Build("hiddenAPIFlagsFile", "hiddenapi flags")
Colin Crossed023ec2019-02-19 12:38:45 -0800297
298 return outputPath
Colin Crossf24a22a2019-01-31 14:12:44 -0800299}
300
301// emptyFlagsRule creates a rule to build an empty hiddenapi-flags.csv, which is needed by master-art-host builds that
302// have a partial manifest without frameworks/base but still need to build a boot image.
Colin Crossed023ec2019-02-19 12:38:45 -0800303func emptyFlagsRule(ctx android.SingletonContext) android.Path {
Colin Crossf1a035e2020-11-16 17:32:30 -0800304 rule := android.NewRuleBuilder(pctx, ctx)
Colin Crossf24a22a2019-01-31 14:12:44 -0800305
306 outputPath := hiddenAPISingletonPaths(ctx).flags
307
Colin Cross69f59a32019-02-15 10:39:37 -0800308 rule.Command().Text("rm").Flag("-f").Output(outputPath)
309 rule.Command().Text("touch").Output(outputPath)
Colin Crossf24a22a2019-01-31 14:12:44 -0800310
Colin Crossf1a035e2020-11-16 17:32:30 -0800311 rule.Build("emptyHiddenAPIFlagsFile", "empty hiddenapi flags")
Colin Crossed023ec2019-02-19 12:38:45 -0800312
313 return outputPath
Colin Crossf24a22a2019-01-31 14:12:44 -0800314}
315
Andrei Onea47841972020-08-10 17:23:52 +0100316// metadataRule creates a rule to build hiddenapi-unsupported.csv out of the metadata.csv files generated for boot image
Colin Crossf24a22a2019-01-31 14:12:44 -0800317// modules.
Colin Crossed023ec2019-02-19 12:38:45 -0800318func metadataRule(ctx android.SingletonContext) android.Path {
Colin Crossf24a22a2019-01-31 14:12:44 -0800319 var metadataCSV android.Paths
320
321 ctx.VisitAllModules(func(module android.Module) {
322 if h, ok := module.(hiddenAPIIntf); ok {
323 if csv := h.metadataCSV(); csv != nil {
324 metadataCSV = append(metadataCSV, csv)
325 }
326 }
327 })
328
Colin Crossf1a035e2020-11-16 17:32:30 -0800329 rule := android.NewRuleBuilder(pctx, ctx)
Colin Crossf24a22a2019-01-31 14:12:44 -0800330
331 outputPath := hiddenAPISingletonPaths(ctx).metadata
332
333 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800334 BuiltTool("merge_csv").
Artur Satayev79fac052020-01-20 19:11:33 +0000335 FlagWithOutput("--output=", outputPath).
336 Inputs(metadataCSV)
Colin Crossf24a22a2019-01-31 14:12:44 -0800337
Colin Crossf1a035e2020-11-16 17:32:30 -0800338 rule.Build("hiddenAPIGreylistMetadataFile", "hiddenapi greylist metadata")
Colin Crossed023ec2019-02-19 12:38:45 -0800339
340 return outputPath
Colin Crossf24a22a2019-01-31 14:12:44 -0800341}
342
343// commitChangeForRestat adds a command to a rule that updates outputPath from tempPath if they are different. It
344// also marks the rule as restat and marks the tempPath as a temporary file that should not be considered an output of
345// the rule.
346func commitChangeForRestat(rule *android.RuleBuilder, tempPath, outputPath android.WritablePath) {
347 rule.Restat()
Colin Cross69f59a32019-02-15 10:39:37 -0800348 rule.Temporary(tempPath)
Colin Crossf24a22a2019-01-31 14:12:44 -0800349 rule.Command().
350 Text("(").
351 Text("if").
Colin Cross69f59a32019-02-15 10:39:37 -0800352 Text("cmp -s").Input(tempPath).Output(outputPath).Text(";").
Colin Crossf24a22a2019-01-31 14:12:44 -0800353 Text("then").
Colin Cross69f59a32019-02-15 10:39:37 -0800354 Text("rm").Input(tempPath).Text(";").
Colin Crossf24a22a2019-01-31 14:12:44 -0800355 Text("else").
Colin Cross69f59a32019-02-15 10:39:37 -0800356 Text("mv").Input(tempPath).Output(outputPath).Text(";").
Colin Crossf24a22a2019-01-31 14:12:44 -0800357 Text("fi").
358 Text(")")
359}
Paul Duffin1b033f52019-06-10 14:15:04 +0100360
361type hiddenAPIFlagsProperties struct {
362 // name of the file into which the flags will be copied.
363 Filename *string
364}
365
366type hiddenAPIFlags struct {
367 android.ModuleBase
368
369 properties hiddenAPIFlagsProperties
370
371 outputFilePath android.OutputPath
372}
373
374func (h *hiddenAPIFlags) GenerateAndroidBuildActions(ctx android.ModuleContext) {
375 filename := String(h.properties.Filename)
376
377 inputPath := hiddenAPISingletonPaths(ctx).flags
378 h.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath
379
380 // This ensures that outputFilePath has the correct name for others to
381 // use, as the source file may have a different name.
382 ctx.Build(pctx, android.BuildParams{
383 Rule: android.Cp,
384 Output: h.outputFilePath,
385 Input: inputPath,
386 })
387}
388
389func (h *hiddenAPIFlags) OutputFiles(tag string) (android.Paths, error) {
390 switch tag {
391 case "":
392 return android.Paths{h.outputFilePath}, nil
393 default:
394 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
395 }
396}
397
398// hiddenapi-flags provides access to the hiddenapi-flags.csv file generated during the build.
399func hiddenAPIFlagsFactory() android.Module {
400 module := &hiddenAPIFlags{}
401 module.AddProperties(&module.properties)
402 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
403 return module
404}
Artur Satayevb5df8a02020-02-19 16:39:59 +0000405
406func hiddenAPIIndexSingletonFactory() android.Singleton {
407 return &hiddenAPIIndexSingleton{}
408}
409
410type hiddenAPIIndexSingleton struct {
411 index android.Path
412}
413
414func (h *hiddenAPIIndexSingleton) GenerateBuildActions(ctx android.SingletonContext) {
415 // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true
416 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
417 return
418 }
419
Bill Peckhambae47492021-01-08 09:34:44 -0800420 if ctx.Config().PrebuiltHiddenApiDir(ctx) != "" {
421 outputPath := hiddenAPISingletonPaths(ctx).index
422 inputPath := android.PathForSource(ctx, ctx.Config().PrebuiltHiddenApiDir(ctx), "hiddenapi-index.csv")
423
424 ctx.Build(pctx, android.BuildParams{
425 Rule: android.Cp,
426 Output: outputPath,
427 Input: inputPath,
428 })
429
430 h.index = outputPath
431 return
432 }
433
Artur Satayevb5df8a02020-02-19 16:39:59 +0000434 indexes := android.Paths{}
435 ctx.VisitAllModules(func(module android.Module) {
436 if h, ok := module.(hiddenAPIIntf); ok {
437 if h.indexCSV() != nil {
438 indexes = append(indexes, h.indexCSV())
439 }
440 }
441 })
442
Colin Crossf1a035e2020-11-16 17:32:30 -0800443 rule := android.NewRuleBuilder(pctx, ctx)
Artur Satayevb5df8a02020-02-19 16:39:59 +0000444 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800445 BuiltTool("merge_csv").
Artur Satayevb5df8a02020-02-19 16:39:59 +0000446 FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties").
447 FlagWithOutput("--output=", hiddenAPISingletonPaths(ctx).index).
448 Inputs(indexes)
Colin Crossf1a035e2020-11-16 17:32:30 -0800449 rule.Build("singleton-merged-hiddenapi-index", "Singleton merged Hidden API index")
Artur Satayevb5df8a02020-02-19 16:39:59 +0000450
451 h.index = hiddenAPISingletonPaths(ctx).index
452}
453
454func (h *hiddenAPIIndexSingleton) MakeVars(ctx android.MakeVarsContext) {
455 if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
456 return
457 }
458
459 ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_INDEX", h.index.String())
460}