Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -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 ( |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 18 | "github.com/google/blueprint" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var hiddenAPIGenerateCSVRule = pctx.AndroidStaticRule("hiddenAPIGenerateCSV", blueprint.RuleParams{ |
Andrei Onea | 23fea04 | 2020-08-12 16:48:23 +0100 | [diff] [blame] | 24 | Command: "${config.Class2NonSdkList} --stub-api-flags ${stubAPIFlags} $in $outFlag $out", |
| 25 | CommandDeps: []string{"${config.Class2NonSdkList}"}, |
David Brazdil | 0f670a2 | 2019-01-18 16:30:03 +0000 | [diff] [blame] | 26 | }, "outFlag", "stubAPIFlags") |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 27 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 28 | type hiddenAPI struct { |
Paul Duffin | f75e527 | 2021-02-09 14:34:25 +0000 | [diff] [blame] | 29 | // True if the module containing this structure contributes to the hiddenapi information or has |
| 30 | // that information encoded within it. |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 31 | active bool |
| 32 | |
Paul Duffin | ff774a0 | 2021-01-29 12:53:15 +0000 | [diff] [blame] | 33 | // The path to the dex jar that is in the boot class path. If this is nil then the associated |
| 34 | // module is not a boot jar, but could be one of the <x>-hiddenapi modules that provide additional |
| 35 | // annotations for the <x> boot dex jar but which do not actually provide a boot dex jar |
| 36 | // themselves. |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 37 | // |
| 38 | // This must be the path to the unencoded dex jar as the encoded dex jar indirectly depends on |
| 39 | // this file so using the encoded dex jar here would result in a cycle in the ninja rules. |
Paul Duffin | ff774a0 | 2021-01-29 12:53:15 +0000 | [diff] [blame] | 40 | bootDexJarPath android.Path |
| 41 | |
Paul Duffin | 36187b2 | 2021-04-22 16:43:06 +0100 | [diff] [blame] | 42 | // The paths to the classes jars that contain classes and class members annotated with |
| 43 | // the UnsupportedAppUsage annotation that need to be extracted as part of the hidden API |
| 44 | // processing. |
| 45 | classesJarPaths android.Paths |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 46 | |
| 47 | // The compressed state of the dex file being encoded. This is used to ensure that the encoded |
| 48 | // dex file has the same state. |
| 49 | uncompressDexState *bool |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 52 | func (h *hiddenAPI) bootDexJar() android.Path { |
| 53 | return h.bootDexJarPath |
| 54 | } |
| 55 | |
Paul Duffin | 36187b2 | 2021-04-22 16:43:06 +0100 | [diff] [blame] | 56 | func (h *hiddenAPI) classesJars() android.Paths { |
| 57 | return h.classesJarPaths |
| 58 | } |
| 59 | |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 60 | func (h *hiddenAPI) uncompressDex() *bool { |
| 61 | return h.uncompressDexState |
| 62 | } |
| 63 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 64 | // hiddenAPIModule is the interface a module that embeds the hiddenAPI structure must implement. |
| 65 | type hiddenAPIModule interface { |
| 66 | android.Module |
| 67 | hiddenAPIIntf |
| 68 | } |
| 69 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 70 | type hiddenAPIIntf interface { |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 71 | bootDexJar() android.Path |
Paul Duffin | 36187b2 | 2021-04-22 16:43:06 +0100 | [diff] [blame] | 72 | classesJars() android.Paths |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 73 | uncompressDex() *bool |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | var _ hiddenAPIIntf = (*hiddenAPI)(nil) |
| 77 | |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 78 | // Initialize the hiddenapi structure |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 79 | // |
| 80 | // uncompressedDexState should be nil when the module is a prebuilt and so does not require hidden |
| 81 | // API encoding. |
| 82 | func (h *hiddenAPI) initHiddenAPI(ctx android.ModuleContext, dexJar, classesJar android.Path, uncompressedDexState *bool) { |
Paul Duffin | 74d18d1 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 83 | |
| 84 | // Save the classes jars even if this is not active as they may be used by modular hidden API |
| 85 | // processing. |
| 86 | classesJars := android.Paths{classesJar} |
| 87 | ctx.VisitDirectDepsWithTag(hiddenApiAnnotationsTag, func(dep android.Module) { |
| 88 | javaInfo := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) |
| 89 | classesJars = append(classesJars, javaInfo.ImplementationJars...) |
| 90 | }) |
| 91 | h.classesJarPaths = classesJars |
| 92 | |
| 93 | // Save the unencoded dex jar so it can be used when generating the |
| 94 | // hiddenAPISingletonPathsStruct.stubFlags file. |
| 95 | h.bootDexJarPath = dexJar |
| 96 | |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 97 | h.uncompressDexState = uncompressedDexState |
| 98 | |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 99 | // If hiddenapi processing is disabled treat this as inactive. |
| 100 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 101 | return |
| 102 | } |
| 103 | |
Paul Duffin | 74d18d1 | 2021-05-14 14:18:47 +0100 | [diff] [blame] | 104 | // The context module must implement hiddenAPIModule. |
| 105 | module := ctx.Module().(hiddenAPIModule) |
| 106 | |
Paul Duffin | b6f53c0 | 2021-05-14 07:52:42 +0100 | [diff] [blame] | 107 | // If the frameworks/base directories does not exist and no prebuilt hidden API flag files have |
| 108 | // been configured then it is not possible to do hidden API encoding. |
| 109 | if !ctx.Config().FrameworksBaseDirExists(ctx) && ctx.Config().PrebuiltHiddenApiDir(ctx) == "" { |
| 110 | return |
| 111 | } |
| 112 | |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 113 | // It is important that hiddenapi information is only gathered for/from modules that are actually |
| 114 | // on the boot jars list because the runtime only enforces access to the hidden API for the |
| 115 | // bootclassloader. If information is gathered for modules not on the list then that will cause |
| 116 | // failures in the CtsHiddenApiBlocklist... tests. |
Paul Duffin | 82b3fcf | 2021-02-12 15:42:46 +0000 | [diff] [blame] | 117 | h.active = isModuleInBootClassPath(ctx, module) |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Paul Duffin | 82b3fcf | 2021-02-12 15:42:46 +0000 | [diff] [blame] | 120 | func isModuleInBootClassPath(ctx android.BaseModuleContext, module android.Module) bool { |
| 121 | // Get the configured non-updatable and updatable boot jars. |
| 122 | nonUpdatableBootJars := ctx.Config().NonUpdatableBootJars() |
| 123 | updatableBootJars := ctx.Config().UpdatableBootJars() |
| 124 | active := isModuleInConfiguredList(ctx, module, nonUpdatableBootJars) || |
| 125 | isModuleInConfiguredList(ctx, module, updatableBootJars) |
| 126 | return active |
| 127 | } |
| 128 | |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 129 | // hiddenAPIEncodeDex is called by any module that needs to encode dex files. |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 130 | // |
| 131 | // It ignores any module that has not had initHiddenApi() called on it and which is not in the boot |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 132 | // jar list. In that case it simply returns the supplied dex jar path. |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 133 | // |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 134 | // Otherwise, it creates a copy of the supplied dex file into which it has encoded the hiddenapi |
| 135 | // flags and returns this instead of the supplied dex jar. |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 136 | func (h *hiddenAPI) hiddenAPIEncodeDex(ctx android.ModuleContext, dexJar android.OutputPath) android.OutputPath { |
Paul Duffin | 001e606 | 2021-05-14 01:13:55 +0100 | [diff] [blame] | 137 | |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 138 | if !h.active { |
| 139 | return dexJar |
| 140 | } |
Paul Duffin | d2aceca | 2019-02-28 16:13:20 +0000 | [diff] [blame] | 141 | |
Paul Duffin | 1bbd062 | 2021-05-14 15:52:25 +0100 | [diff] [blame] | 142 | // A nil uncompressDexState prevents the dex file from being encoded. |
| 143 | if h.uncompressDexState == nil { |
| 144 | ctx.ModuleErrorf("cannot encode dex file %s when uncompressDexState is nil", dexJar) |
| 145 | } |
| 146 | uncompressDex := *h.uncompressDexState |
| 147 | |
Paul Duffin | 66cdbf0 | 2021-05-14 16:35:06 +0100 | [diff] [blame] | 148 | hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", dexJar.Base()).OutputPath |
Paul Duffin | a2058f8 | 2020-06-24 16:22:38 +0100 | [diff] [blame] | 149 | |
Paul Duffin | f8f4af8 | 2021-02-12 15:42:20 +0000 | [diff] [blame] | 150 | // Create a copy of the dex jar which has been encoded with hiddenapi flags. |
| 151 | hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexJar, uncompressDex) |
Paul Duffin | 4103e92 | 2021-02-01 19:01:34 +0000 | [diff] [blame] | 152 | |
Paul Duffin | f8f4af8 | 2021-02-12 15:42:20 +0000 | [diff] [blame] | 153 | // Use the encoded dex jar from here onwards. |
| 154 | dexJar = hiddenAPIJar |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 155 | |
| 156 | return dexJar |
| 157 | } |
| 158 | |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 159 | // buildRuleToGenerateAnnotationFlags builds a ninja rule to generate the annotation-flags.csv file |
| 160 | // from the classes jars and stub-flags.csv files. |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 161 | // |
| 162 | // The annotation-flags.csv file contains mappings from Java signature to various flags derived from |
| 163 | // annotations in the source, e.g. whether it is public or the sdk version above which it can no |
| 164 | // longer be used. |
| 165 | // |
| 166 | // It is created by the Class2NonSdkList tool which processes the .class files in the class |
| 167 | // implementation jar looking for UnsupportedAppUsage and CovariantReturnType annotations. The |
| 168 | // tool also consumes the hiddenAPISingletonPathsStruct.stubFlags file in order to perform |
| 169 | // consistency checks on the information in the annotations and to filter out bridge methods |
| 170 | // that are already part of the public API. |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 171 | func buildRuleToGenerateAnnotationFlags(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, outputPath android.WritablePath) { |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 172 | ctx.Build(pctx, android.BuildParams{ |
| 173 | Rule: hiddenAPIGenerateCSVRule, |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 174 | Description: desc, |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 175 | Inputs: classesJars, |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 176 | Output: outputPath, |
David Brazdil | 0f670a2 | 2019-01-18 16:30:03 +0000 | [diff] [blame] | 177 | Implicit: stubFlagsCSV, |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 178 | Args: map[string]string{ |
David Brazdil | 0f670a2 | 2019-01-18 16:30:03 +0000 | [diff] [blame] | 179 | "outFlag": "--write-flags-csv", |
| 180 | "stubAPIFlags": stubFlagsCSV.String(), |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 181 | }, |
| 182 | }) |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 183 | } |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 184 | |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 185 | // buildRuleToGenerateMetadata builds a ninja rule to generate the metadata.csv file from |
| 186 | // the classes jars and stub-flags.csv files. |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 187 | // |
| 188 | // The metadata.csv file contains mappings from Java signature to the value of properties specified |
| 189 | // on UnsupportedAppUsage annotations in the source. |
| 190 | // |
| 191 | // Like the annotation-flags.csv file this is also created by the Class2NonSdkList in the same way. |
| 192 | // Although the two files could potentially be created in a single invocation of the |
| 193 | // Class2NonSdkList at the moment they are created using their own invocation, with the behavior |
| 194 | // being determined by the property that is used. |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 195 | func buildRuleToGenerateMetadata(ctx android.ModuleContext, desc string, classesJars android.Paths, stubFlagsCSV android.Path, metadataCSV android.WritablePath) { |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 196 | ctx.Build(pctx, android.BuildParams{ |
| 197 | Rule: hiddenAPIGenerateCSVRule, |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 198 | Description: desc, |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 199 | Inputs: classesJars, |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 200 | Output: metadataCSV, |
David Brazdil | 0f670a2 | 2019-01-18 16:30:03 +0000 | [diff] [blame] | 201 | Implicit: stubFlagsCSV, |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 202 | Args: map[string]string{ |
David Brazdil | 0f670a2 | 2019-01-18 16:30:03 +0000 | [diff] [blame] | 203 | "outFlag": "--write-metadata-csv", |
| 204 | "stubAPIFlags": stubFlagsCSV.String(), |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 205 | }, |
| 206 | }) |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 207 | } |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 208 | |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 209 | // buildRuleToGenerateIndex builds a ninja rule to generate the index.csv file from the classes |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 210 | // jars. |
Paul Duffin | afaa47c | 2021-05-14 13:04:04 +0100 | [diff] [blame] | 211 | // |
| 212 | // The index.csv file contains mappings from Java signature to source location information. |
| 213 | // |
| 214 | // It is created by the merge_csv tool which processes the class implementation jar, extracting |
| 215 | // all the files ending in .uau (which are CSV files) and merges them together. The .uau files are |
| 216 | // created by the unsupported app usage annotation processor during compilation of the class |
| 217 | // implementation jar. |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 218 | func buildRuleToGenerateIndex(ctx android.ModuleContext, desc string, classesJars android.Paths, indexCSV android.WritablePath) { |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 219 | rule := android.NewRuleBuilder(pctx, ctx) |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame] | 220 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 221 | BuiltTool("merge_csv"). |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 222 | Flag("--zip_input"). |
Paul Duffin | 2c36f24 | 2021-02-16 16:57:06 +0000 | [diff] [blame] | 223 | Flag("--key_field signature"). |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 224 | FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties"). |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 225 | FlagWithOutput("--output=", indexCSV). |
| 226 | Inputs(classesJars) |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 227 | rule.Build(desc, desc) |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | var hiddenAPIEncodeDexRule = pctx.AndroidStaticRule("hiddenAPIEncodeDex", blueprint.RuleParams{ |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame] | 231 | Command: `rm -rf $tmpDir && mkdir -p $tmpDir && mkdir $tmpDir/dex-input && mkdir $tmpDir/dex-output && |
Colin Cross | d783bbb | 2020-07-11 22:30:45 -0700 | [diff] [blame] | 232 | unzip -qoDD $in 'classes*.dex' -d $tmpDir/dex-input && |
Artur Satayev | b5df8a0 | 2020-02-19 16:39:59 +0000 | [diff] [blame] | 233 | for INPUT_DEX in $$(find $tmpDir/dex-input -maxdepth 1 -name 'classes*.dex' | sort); do |
| 234 | echo "--input-dex=$${INPUT_DEX}"; |
| 235 | echo "--output-dex=$tmpDir/dex-output/$$(basename $${INPUT_DEX})"; |
| 236 | done | xargs ${config.HiddenAPI} encode --api-flags=$flagsCsv $hiddenapiFlags && |
| 237 | ${config.SoongZipCmd} $soongZipFlags -o $tmpDir/dex.jar -C $tmpDir/dex-output -f "$tmpDir/dex-output/classes*.dex" && |
| 238 | ${config.MergeZipsCmd} -D -zipToNotStrip $tmpDir/dex.jar -stripFile "classes*.dex" -stripFile "**/*.uau" $out $tmpDir/dex.jar $in`, |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 239 | CommandDeps: []string{ |
| 240 | "${config.HiddenAPI}", |
| 241 | "${config.SoongZipCmd}", |
| 242 | "${config.MergeZipsCmd}", |
| 243 | }, |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 244 | }, "flagsCsv", "hiddenapiFlags", "tmpDir", "soongZipFlags") |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 245 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 246 | func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath, dexInput android.Path, |
Colin Cross | cd964b3 | 2019-01-18 22:03:02 -0800 | [diff] [blame] | 247 | uncompressDex bool) { |
| 248 | |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 249 | flagsCSV := hiddenAPISingletonPaths(ctx).flags |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 250 | |
Colin Cross | cd964b3 | 2019-01-18 22:03:02 -0800 | [diff] [blame] | 251 | // The encode dex rule requires unzipping and rezipping the classes.dex files, ensure that if it was uncompressed |
| 252 | // in the input it stays uncompressed in the output. |
| 253 | soongZipFlags := "" |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 254 | hiddenapiFlags := "" |
Nicolas Geoffray | 65fd8ba | 2019-01-21 23:20:23 +0000 | [diff] [blame] | 255 | tmpOutput := output |
| 256 | tmpDir := android.PathForModuleOut(ctx, "hiddenapi", "dex") |
Colin Cross | cd964b3 | 2019-01-18 22:03:02 -0800 | [diff] [blame] | 257 | if uncompressDex { |
| 258 | soongZipFlags = "-L 0" |
Nicolas Geoffray | 65fd8ba | 2019-01-21 23:20:23 +0000 | [diff] [blame] | 259 | tmpOutput = android.PathForModuleOut(ctx, "hiddenapi", "unaligned", "unaligned.jar") |
| 260 | tmpDir = android.PathForModuleOut(ctx, "hiddenapi", "unaligned") |
Colin Cross | cd964b3 | 2019-01-18 22:03:02 -0800 | [diff] [blame] | 261 | } |
Jiyong Park | 93e57a0 | 2020-02-21 16:04:53 +0900 | [diff] [blame] | 262 | |
| 263 | enforceHiddenApiFlagsToAllMembers := true |
Paul Duffin | b6f53c0 | 2021-05-14 07:52:42 +0100 | [diff] [blame] | 264 | |
Jiyong Park | 93e57a0 | 2020-02-21 16:04:53 +0900 | [diff] [blame] | 265 | // b/149353192: when a module is instrumented, jacoco adds synthetic members |
| 266 | // $jacocoData and $jacocoInit. Since they don't exist when building the hidden API flags, |
| 267 | // don't complain when we don't find hidden API flags for the synthetic members. |
Paul Duffin | c495d2b | 2020-05-19 21:07:52 +0100 | [diff] [blame] | 268 | if j, ok := ctx.Module().(interface { |
| 269 | shouldInstrument(android.BaseModuleContext) bool |
| 270 | }); ok && j.shouldInstrument(ctx) { |
Jiyong Park | 93e57a0 | 2020-02-21 16:04:53 +0900 | [diff] [blame] | 271 | enforceHiddenApiFlagsToAllMembers = false |
| 272 | } |
| 273 | |
| 274 | if !enforceHiddenApiFlagsToAllMembers { |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 275 | hiddenapiFlags = "--no-force-assign-all" |
| 276 | } |
Colin Cross | cd964b3 | 2019-01-18 22:03:02 -0800 | [diff] [blame] | 277 | |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 278 | ctx.Build(pctx, android.BuildParams{ |
| 279 | Rule: hiddenAPIEncodeDexRule, |
| 280 | Description: "hiddenapi encode dex", |
| 281 | Input: dexInput, |
Nicolas Geoffray | 65fd8ba | 2019-01-21 23:20:23 +0000 | [diff] [blame] | 282 | Output: tmpOutput, |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 283 | Implicit: flagsCSV, |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 284 | Args: map[string]string{ |
Colin Cross | f24a22a | 2019-01-31 14:12:44 -0800 | [diff] [blame] | 285 | "flagsCsv": flagsCSV.String(), |
David Brazdil | 91b4e3e | 2019-01-23 21:04:05 +0000 | [diff] [blame] | 286 | "tmpDir": tmpDir.String(), |
| 287 | "soongZipFlags": soongZipFlags, |
| 288 | "hiddenapiFlags": hiddenapiFlags, |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 289 | }, |
| 290 | }) |
| 291 | |
Nicolas Geoffray | 65fd8ba | 2019-01-21 23:20:23 +0000 | [diff] [blame] | 292 | if uncompressDex { |
| 293 | TransformZipAlign(ctx, output, tmpOutput) |
| 294 | } |
Colin Cross | 8faf8fc | 2019-01-16 15:15:52 -0800 | [diff] [blame] | 295 | } |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 296 | |
| 297 | type hiddenApiAnnotationsDependencyTag struct { |
| 298 | blueprint.BaseDependencyTag |
| 299 | } |
| 300 | |
| 301 | // Tag used to mark dependencies on java_library instances that contains Java source files whose |
| 302 | // sole purpose is to provide additional hiddenapi annotations. |
| 303 | var hiddenApiAnnotationsTag hiddenApiAnnotationsDependencyTag |
| 304 | |
| 305 | // Mark this tag so dependencies that use it are excluded from APEX contents. |
| 306 | func (t hiddenApiAnnotationsDependencyTag) ExcludeFromApexContents() {} |
| 307 | |
| 308 | var _ android.ExcludeFromApexContentsTag = hiddenApiAnnotationsTag |