diff options
Diffstat (limited to 'java/hiddenapi.go')
-rw-r--r-- | java/hiddenapi.go | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/java/hiddenapi.go b/java/hiddenapi.go index f8e41c458..208ced769 100644 --- a/java/hiddenapi.go +++ b/java/hiddenapi.go @@ -15,8 +15,6 @@ package java import ( - "strings" - "github.com/google/blueprint" "android/soong/android" @@ -29,8 +27,8 @@ var hiddenAPIGenerateCSVRule = pctx.AndroidStaticRule("hiddenAPIGenerateCSV", bl type hiddenAPI struct { // The name of the module as it would be used in the boot jars configuration, e.g. without any - // prebuilt_ prefix (if it is a prebuilt), without any "-hiddenapi" suffix if it just provides - // annotations and without any ".impl" suffix if it is a java_sdk_library implementation library. + // prebuilt_ prefix (if it is a prebuilt) and without any ".impl" suffix if it is a + // java_sdk_library implementation library. configurationName string // True if the module containing this structure contributes to the hiddenapi information or has @@ -49,11 +47,6 @@ type hiddenAPI struct { // annotation information. primary bool - // True if the module only contains additional annotations and so does not require hiddenapi - // information to be encoded in its dex file and should not be used to generate the - // hiddenAPISingletonPathsStruct.stubFlags file. - annotationsOnly bool - // The path to the dex jar that is in the boot class path. If this is nil then the associated // module is not a boot jar, but could be one of the <x>-hiddenapi modules that provide additional // annotations for the <x> boot dex jar but which do not actually provide a boot dex jar @@ -119,55 +112,67 @@ type hiddenAPIIntf interface { var _ hiddenAPIIntf = (*hiddenAPI)(nil) // Initialize the hiddenapi structure -func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext, name string) { +func (h *hiddenAPI) initHiddenAPI(ctx android.BaseModuleContext, configurationName string) { // If hiddenapi processing is disabled treat this as inactive. if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { return } - // Modules whose names are of the format <x>-hiddenapi provide hiddenapi information for the boot - // jar module <x>. Otherwise, the module provides information for itself. Either way extract the - // configurationName of the boot jar module. - configurationName := strings.TrimSuffix(name, "-hiddenapi") h.configurationName = configurationName // It is important that hiddenapi information is only gathered for/from modules that are actually // on the boot jars list because the runtime only enforces access to the hidden API for the // bootclassloader. If information is gathered for modules not on the list then that will cause // failures in the CtsHiddenApiBlocklist... tests. - h.active = inList(configurationName, ctx.Config().BootJars()) + module := ctx.Module() + h.active = isModuleInBootClassPath(ctx, module) if !h.active { // The rest of the properties will be ignored if active is false. return } - // If this module has a suffix of -hiddenapi then it only provides additional annotation - // information for a module on the boot jars list. - h.annotationsOnly = strings.HasSuffix(name, "-hiddenapi") - // Determine whether this module is the primary module or not. primary := true // A prebuilt module is only primary if it is preferred and conversely a source module is only // primary if it has not been replaced by a prebuilt module. - module := ctx.Module() if pi, ok := module.(android.PrebuiltInterface); ok { if p := pi.Prebuilt(); p != nil { primary = p.UsePrebuilt() } } else { - // The only module that will pass a different name to its module name to this method is the - // implementation library of a java_sdk_library. It has a configuration name of <x> the same - // as its parent java_sdk_library but a module name of <x>.impl. It is not the primary module, - // the java_sdk_library with the name of <x> is. - primary = name == ctx.ModuleName() + // The only module that will pass a different configurationName to its module name to this + // method is the implementation library of a java_sdk_library. It has a configuration name of + // <x> the same as its parent java_sdk_library but a module name of <x>.impl. It is not the + // primary module, the java_sdk_library with the name of <x> is. + primary = configurationName == ctx.ModuleName() // A source module that has been replaced by a prebuilt can never be the primary module. - primary = primary && !module.IsReplacedByPrebuilt() + if module.IsReplacedByPrebuilt() { + ctx.VisitDirectDepsWithTag(android.PrebuiltDepTag, func(prebuilt android.Module) { + if h, ok := prebuilt.(hiddenAPIIntf); ok && h.bootDexJar() != nil { + primary = false + } else { + ctx.ModuleErrorf( + "hiddenapi has determined that the source module %q should be ignored as it has been"+ + " replaced by the prebuilt module %q but unfortunately it does not provide a"+ + " suitable boot dex jar", ctx.ModuleName(), ctx.OtherModuleName(prebuilt)) + } + }) + } } h.primary = primary } +func isModuleInBootClassPath(ctx android.BaseModuleContext, module android.Module) bool { + // Get the configured non-updatable and updatable boot jars. + nonUpdatableBootJars := ctx.Config().NonUpdatableBootJars() + updatableBootJars := ctx.Config().UpdatableBootJars() + active := isModuleInConfiguredList(ctx, module, nonUpdatableBootJars) || + isModuleInConfiguredList(ctx, module, updatableBootJars) + return active +} + // hiddenAPIExtractAndEncode is called by any module that could contribute to the hiddenapi // processing. // @@ -191,15 +196,13 @@ func (h *hiddenAPI) hiddenAPIExtractAndEncode(ctx android.ModuleContext, dexJar h.hiddenAPIExtractInformation(ctx, dexJar, implementationJar) - if !h.annotationsOnly { - hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", h.configurationName+".jar").OutputPath + hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", h.configurationName+".jar").OutputPath - // Create a copy of the dex jar which has been encoded with hiddenapi flags. - hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexJar, uncompressDex) + // Create a copy of the dex jar which has been encoded with hiddenapi flags. + hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexJar, uncompressDex) - // Use the encoded dex jar from here onwards. - dexJar = hiddenAPIJar - } + // Use the encoded dex jar from here onwards. + dexJar = hiddenAPIJar return dexJar } @@ -262,6 +265,7 @@ func (h *hiddenAPI) hiddenAPIExtractInformation(ctx android.ModuleContext, dexJa rule.Command(). BuiltTool("merge_csv"). Flag("--zip_input"). + Flag("--key_field signature"). FlagWithOutput("--output=", indexCSV). Inputs(classesJars) rule.Build("merged-hiddenapi-index", "Merged Hidden API index") |