blob: bed11fe39a1138f14dbd25561760a665c29f5e32 [file] [log] [blame]
Paul Duffinc6bb7cf2021-04-08 17:49:27 +01001// Copyright (C) 2021 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "android/soong/android"
19)
20
21// Contains support for processing hiddenAPI in a modular fashion.
22
Paul Duffin702210b2021-04-08 20:12:41 +010023// HiddenAPIAugmentationProperties contains paths to the files that can be used to augment the information
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010024// obtained from annotations within the source code in order to create the complete set of flags
25// that should be applied to the dex implementation jars on the bootclasspath.
26//
27// Each property contains a list of paths. With the exception of the Unsupported_packages the paths
28// of each property reference a plain text file that contains a java signature per line. The flags
29// for each of those signatures will be updated in a property specific way.
30//
31// The Unsupported_packages property contains a list of paths, each of which is a plain text file
32// with one Java package per line. All members of all classes within that package (but not nested
33// packages) will be updated in a property specific way.
Paul Duffin702210b2021-04-08 20:12:41 +010034type HiddenAPIAugmentationProperties struct {
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010035 // Marks each signature in the referenced files as being unsupported.
Paul Duffin702210b2021-04-08 20:12:41 +010036 Unsupported []string `android:"path"`
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010037
38 // Marks each signature in the referenced files as being unsupported because it has been removed.
39 // Any conflicts with other flags are ignored.
Paul Duffin702210b2021-04-08 20:12:41 +010040 Removed []string `android:"path"`
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010041
42 // Marks each signature in the referenced files as being supported only for targetSdkVersion <= R
43 // and low priority.
Paul Duffin702210b2021-04-08 20:12:41 +010044 Max_target_r_low_priority []string `android:"path"`
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010045
46 // Marks each signature in the referenced files as being supported only for targetSdkVersion <= Q.
Paul Duffin702210b2021-04-08 20:12:41 +010047 Max_target_q []string `android:"path"`
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010048
49 // Marks each signature in the referenced files as being supported only for targetSdkVersion <= P.
Paul Duffin702210b2021-04-08 20:12:41 +010050 Max_target_p []string `android:"path"`
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010051
52 // Marks each signature in the referenced files as being supported only for targetSdkVersion <= O
53 // and low priority. Any conflicts with other flags are ignored.
Paul Duffin702210b2021-04-08 20:12:41 +010054 Max_target_o_low_priority []string `android:"path"`
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010055
56 // Marks each signature in the referenced files as being blocked.
Paul Duffin702210b2021-04-08 20:12:41 +010057 Blocked []string `android:"path"`
Paul Duffinc6bb7cf2021-04-08 17:49:27 +010058
59 // Marks each signature in every package in the referenced files as being unsupported.
Paul Duffin702210b2021-04-08 20:12:41 +010060 Unsupported_packages []string `android:"path"`
61}
62
63func (p *HiddenAPIAugmentationProperties) hiddenAPIAugmentationInfo(ctx android.ModuleContext) hiddenAPIAugmentationInfo {
64 paths := func(paths []string) android.Paths { return android.PathsForModuleSrc(ctx, paths) }
65 return hiddenAPIAugmentationInfo{
66 Unsupported: paths(p.Unsupported),
67 Removed: paths(p.Removed),
68 Max_target_r_low_priority: paths(p.Max_target_r_low_priority),
69 Max_target_q: paths(p.Max_target_q),
70 Max_target_p: paths(p.Max_target_p),
71 Max_target_o_low_priority: paths(p.Max_target_o_low_priority),
72 Blocked: paths(p.Blocked),
73 Unsupported_packages: paths(p.Unsupported_packages),
74 }
75}
76
77// hiddenAPIAugmentationInfo contains paths resolved from HiddenAPIAugmentationProperties
78type hiddenAPIAugmentationInfo struct {
79 // See HiddenAPIAugmentationProperties.Unsupported
80 Unsupported android.Paths
81
82 // See HiddenAPIAugmentationProperties.Removed
83 Removed android.Paths
84
85 // See HiddenAPIAugmentationProperties.Max_target_r_low_priority
86 Max_target_r_low_priority android.Paths
87
88 // See HiddenAPIAugmentationProperties.Max_target_q
89 Max_target_q android.Paths
90
91 // See HiddenAPIAugmentationProperties.Max_target_p
92 Max_target_p android.Paths
93
94 // See HiddenAPIAugmentationProperties.Max_target_o_low_priority
95 Max_target_o_low_priority android.Paths
96
97 // See HiddenAPIAugmentationProperties.Blocked
98 Blocked android.Paths
99
100 // See HiddenAPIAugmentationProperties.Unsupported_packages
Paul Duffinc6bb7cf2021-04-08 17:49:27 +0100101 Unsupported_packages android.Paths
102}
Paul Duffin702210b2021-04-08 20:12:41 +0100103
104// ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the
105// flags from all the modules, the stub flags, augmented with some additional configuration files.
106//
107// baseFlagsPath is the path to the flags file containing all the information from the stubs plus
108// an entry for every single member in the dex implementation jars of the individual modules. Every
109// signature in any of the other files MUST be included in this file.
110//
111// moduleSpecificFlagsPaths are the paths to the flags files generated by each module using
112// information from the baseFlagsPath as well as from annotations within the source.
113//
114// augmentationInfo is a struct containing paths to files that augment the information provided by
115// the moduleSpecificFlagsPaths.
116// ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the
117// flags from all the modules, the stub flags, augmented with some additional configuration files.
118//
119// baseFlagsPath is the path to the flags file containing all the information from the stubs plus
120// an entry for every single member in the dex implementation jars of the individual modules. Every
121// signature in any of the other files MUST be included in this file.
122//
123// moduleSpecificFlagsPaths are the paths to the flags files generated by each module using
124// information from the baseFlagsPath as well as from annotations within the source.
125//
126// augmentationInfo is a struct containing paths to files that augment the information provided by
127// the moduleSpecificFlagsPaths.
128func ruleToGenerateHiddenApiFlags(ctx android.BuilderContext, outputPath android.WritablePath, baseFlagsPath android.Path, moduleSpecificFlagsPaths android.Paths, augmentationInfo hiddenAPIAugmentationInfo) {
129 tempPath := android.PathForOutput(ctx, outputPath.Rel()+".tmp")
130 rule := android.NewRuleBuilder(pctx, ctx)
131 command := rule.Command().
132 BuiltTool("generate_hiddenapi_lists").
133 FlagWithInput("--csv ", baseFlagsPath).
134 Inputs(moduleSpecificFlagsPaths).
135 FlagWithOutput("--output ", tempPath)
136
137 for _, path := range augmentationInfo.Unsupported {
138 command.FlagWithInput("--unsupported ", path)
139 }
140
141 for _, path := range augmentationInfo.Removed {
142 command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed")
143 }
144
145 for _, path := range augmentationInfo.Max_target_r_low_priority {
146 command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio")
147 }
148
149 for _, path := range augmentationInfo.Max_target_q {
150 command.FlagWithInput("--max-target-q ", path)
151 }
152
153 for _, path := range augmentationInfo.Max_target_p {
154 command.FlagWithInput("--max-target-p ", path)
155 }
156
157 for _, path := range augmentationInfo.Max_target_o_low_priority {
158 command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio")
159 }
160
161 for _, path := range augmentationInfo.Blocked {
162 command.FlagWithInput("--blocked ", path)
163 }
164
165 for _, path := range augmentationInfo.Unsupported_packages {
166 command.FlagWithInput("--unsupported ", path).Flag("--packages ")
167 }
168
169 commitChangeForRestat(rule, tempPath, outputPath)
170
171 rule.Build("hiddenAPIFlagsFile", "hiddenapi flags")
172}