From b749347fa5cc9cd4018a8ebae0b6df37c2afa70e Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Wed, 28 Aug 2024 11:55:52 -0700 Subject: [PATCH] Make the java static_libs property configurable Bug: 362579941 Test: m nothing --no-skip-soong-tests Change-Id: Iccc93cf14753aae1adb26c6eedd00aabf1c2f6a6 --- java/aar.go | 4 ++-- java/base.go | 17 ++++++++++------- java/droiddoc.go | 4 ++-- java/generated_java_library.go | 8 -------- java/java.go | 20 ++++++++++---------- java/rro.go | 10 +++++++--- java/sdk_library.go | 32 ++++++++++++++++++-------------- java/sdk_library_test.go | 15 +++++++-------- java/testing.go | 12 ++++++++++++ 9 files changed, 68 insertions(+), 54 deletions(-) diff --git a/java/aar.go b/java/aar.go index 42866f8b6..0639e6426 100644 --- a/java/aar.go +++ b/java/aar.go @@ -970,7 +970,7 @@ type AARImportProperties struct { // Defaults to sdk_version if not set. See sdk_version for possible values. Min_sdk_version *string // List of java static libraries that the included ARR (android library prebuilts) has dependencies to. - Static_libs []string + Static_libs proptools.Configurable[[]string] // List of java libraries that the included ARR (android library prebuilts) has dependencies to. Libs []string // If set to true, run Jetifier against .aar file. Defaults to false. @@ -1100,7 +1100,7 @@ func (a *AARImport) DepsMutator(ctx android.BottomUpMutatorContext) { } ctx.AddVariationDependencies(nil, libTag, a.properties.Libs...) - ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs...) + ctx.AddVariationDependencies(nil, staticLibTag, a.properties.Static_libs.GetOrDefault(ctx, nil)...) a.usesLibrary.deps(ctx, false) } diff --git a/java/base.go b/java/base.go index 75b552fd6..bc956bda8 100644 --- a/java/base.go +++ b/java/base.go @@ -81,7 +81,7 @@ type CommonProperties struct { Libs []string `android:"arch_variant"` // list of java libraries that will be compiled into the resulting jar - Static_libs []string `android:"arch_variant"` + Static_libs proptools.Configurable[[]string] `android:"arch_variant"` // list of java libraries that should not be used to build this module Exclude_static_libs []string `android:"arch_variant"` @@ -836,6 +836,10 @@ func (j *Module) AvailableFor(what string) bool { return j.ApexModuleBase.AvailableFor(what) } +func (j *Module) staticLibs(ctx android.BaseModuleContext) []string { + return android.RemoveListFromList(j.properties.Static_libs.GetOrDefault(ctx, nil), j.properties.Exclude_static_libs) +} + func (j *Module) deps(ctx android.BottomUpMutatorContext) { if ctx.Device() { j.linter.deps(ctx) @@ -852,8 +856,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { libDeps := ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) - j.properties.Static_libs = android.RemoveListFromList(j.properties.Static_libs, j.properties.Exclude_static_libs) - ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...) + ctx.AddVariationDependencies(nil, staticLibTag, j.staticLibs(ctx)...) // Add dependency on libraries that provide additional hidden api annotations. ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...) @@ -935,7 +938,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") } - if j.useCompose() { + if j.useCompose(ctx) { ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag, "androidx.compose.compiler_compiler-hosted") } @@ -1839,8 +1842,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath j.outputFile = outputFile.WithoutRel() } -func (j *Module) useCompose() bool { - return android.InList("androidx.compose.runtime_runtime", j.properties.Static_libs) +func (j *Module) useCompose(ctx android.BaseModuleContext) bool { + return android.InList("androidx.compose.runtime_runtime", j.staticLibs(ctx)) } func collectDepProguardSpecInfo(ctx android.ModuleContext) (transitiveProguardFlags, transitiveUnconditionalExportedFlags []*android.DepSet[android.Path]) { @@ -2097,7 +2100,7 @@ func (j *Module) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) } dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...) dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...) - dpInfo.Static_libs = append(dpInfo.Static_libs, j.properties.Static_libs...) + dpInfo.Static_libs = append(dpInfo.Static_libs, j.staticLibs(ctx)...) dpInfo.Libs = append(dpInfo.Libs, j.properties.Libs...) } diff --git a/java/droiddoc.go b/java/droiddoc.go index f81c5bac5..2929bb8d9 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -54,7 +54,7 @@ type JavadocProperties struct { Filter_packages []string // list of java libraries that will be in the classpath. - Libs []string `android:"arch_variant"` + Libs proptools.Configurable[[]string] `android:"arch_variant"` // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true. Installable *bool @@ -274,7 +274,7 @@ func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { } } - ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) + ctx.AddVariationDependencies(nil, libTag, j.properties.Libs.GetOrDefault(ctx, nil)...) } func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags { diff --git a/java/generated_java_library.go b/java/generated_java_library.go index d5e6d8fec..79f1b6f08 100644 --- a/java/generated_java_library.go +++ b/java/generated_java_library.go @@ -70,14 +70,6 @@ func (module *GeneratedJavaLibraryModule) AddSharedLibrary(name string) { module.Library.properties.Libs = append(module.Library.properties.Libs, name) } -// Add a java shared library as a dependency, as if they had said `libs: [ "name" ]` -func (module *GeneratedJavaLibraryModule) AddStaticLibrary(name string) { - if module.depsMutatorDone { - panic("GeneratedJavaLibraryModule.AddStaticLibrary called after DepsMutator") - } - module.Library.properties.Static_libs = append(module.Library.properties.Static_libs, name) -} - func (module *GeneratedJavaLibraryModule) DepsMutator(ctx android.BottomUpMutatorContext) { module.callbacks.DepsMutator(module, ctx) module.depsMutatorDone = true diff --git a/java/java.go b/java/java.go index 8cc108541..93b2976f2 100644 --- a/java/java.go +++ b/java/java.go @@ -1994,11 +1994,11 @@ type JavaApiLibraryProperties struct { // List of shared java libs that this module has dependencies to and // should be passed as classpath in javac invocation - Libs []string + Libs proptools.Configurable[[]string] // List of java libs that this module has static dependencies to and will be // merge zipped after metalava invocation - Static_libs []string + Static_libs proptools.Configurable[[]string] // Version of previously released API file for compatibility check. Previous_api *string `android:"path"` @@ -2174,8 +2174,8 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { } } - ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...) - ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...) + ctx.AddVariationDependencies(nil, libTag, al.properties.Libs.GetOrDefault(ctx, nil)...) + ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs.GetOrDefault(ctx, nil)...) for _, aconfigDeclarationsName := range al.properties.Aconfig_declarations { ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfigDeclarationsName) @@ -2406,16 +2406,16 @@ func (al *ApiLibrary) TargetSdkVersion(ctx android.EarlyModuleContext) android.A func (al *ApiLibrary) IDEInfo(ctx android.BaseModuleContext, i *android.IdeInfo) { i.Deps = append(i.Deps, al.ideDeps(ctx)...) - i.Libs = append(i.Libs, al.properties.Libs...) - i.Static_libs = append(i.Static_libs, al.properties.Static_libs...) + i.Libs = append(i.Libs, al.properties.Libs.GetOrDefault(ctx, nil)...) + i.Static_libs = append(i.Static_libs, al.properties.Static_libs.GetOrDefault(ctx, nil)...) i.SrcJars = append(i.SrcJars, al.stubsSrcJar.String()) } // deps of java_api_library for module_bp_java_deps.json func (al *ApiLibrary) ideDeps(ctx android.BaseModuleContext) []string { ret := []string{} - ret = append(ret, al.properties.Libs...) - ret = append(ret, al.properties.Static_libs...) + ret = append(ret, al.properties.Libs.GetOrDefault(ctx, nil)...) + ret = append(ret, al.properties.Static_libs.GetOrDefault(ctx, nil)...) if al.properties.System_modules != nil { ret = append(ret, proptools.String(al.properties.System_modules)) } @@ -2459,7 +2459,7 @@ type ImportProperties struct { Libs []string // List of static java libs that this module has dependencies to - Static_libs []string + Static_libs proptools.Configurable[[]string] // List of files to remove from the jar file(s) Exclude_files []string @@ -2600,7 +2600,7 @@ func (j *Import) setStrictUpdatabilityLinting(bool) { func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) - ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...) + ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs.GetOrDefault(ctx, nil)...) if ctx.Device() && Bool(j.dexProperties.Compile_dex) { sdkDeps(ctx, android.SdkContext(j), j.dexer) diff --git a/java/rro.go b/java/rro.go index 0fc6e1c6f..8bb9be2eb 100644 --- a/java/rro.go +++ b/java/rro.go @@ -17,7 +17,11 @@ package java // This file contains the module implementations for runtime_resource_overlay and // override_runtime_resource_overlay. -import "android/soong/android" +import ( + "android/soong/android" + + "github.com/google/blueprint/proptools" +) func init() { RegisterRuntimeResourceOverlayBuildComponents(android.InitRegistrationContext) @@ -71,7 +75,7 @@ type RuntimeResourceOverlayProperties struct { Min_sdk_version *string // list of android_library modules whose resources are extracted and linked against statically - Static_libs []string + Static_libs proptools.Configurable[[]string] // list of android_app modules whose resources are extracted and linked against Resource_libs []string @@ -120,7 +124,7 @@ func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) ctx.AddDependency(ctx.Module(), certificateTag, cert) } - ctx.AddVariationDependencies(nil, staticLibTag, r.properties.Static_libs...) + ctx.AddVariationDependencies(nil, staticLibTag, r.properties.Static_libs.GetOrDefault(ctx, nil)...) ctx.AddVariationDependencies(nil, libTag, r.properties.Resource_libs...) for _, aconfig_declaration := range r.aaptProperties.Flags_packages { diff --git a/java/sdk_library.go b/java/sdk_library.go index 98b65dd55..b7aa4e56d 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1744,11 +1744,13 @@ func childModuleVisibility(childVisibility []string) []string { func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) { visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility) + staticLibs := module.properties.Static_libs.Clone() + staticLibs.AppendSimpleValue(module.sdkLibraryProperties.Impl_only_static_libs) props := struct { Name *string Visibility []string Libs []string - Static_libs []string + Static_libs proptools.Configurable[[]string] Apex_available []string Stem *string }{ @@ -1757,7 +1759,7 @@ func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) Libs: append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...), - Static_libs: append(module.properties.Static_libs, module.sdkLibraryProperties.Impl_only_static_libs...), + Static_libs: staticLibs, // Pass the apex_available settings down so that the impl library can be statically // embedded within a library that is added to an APEX. Needed for updatable-media. Apex_available: module.ApexAvailable(), @@ -1863,7 +1865,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC Sdk_version *string Api_surface *string System_modules *string - Libs []string + Libs proptools.Configurable[[]string] Output_javadoc_comments *bool Arg_files []string Args *string @@ -1907,10 +1909,11 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC props.Installable = proptools.BoolPtr(false) // A droiddoc module has only one Libs property and doesn't distinguish between // shared libs and static libs. So we need to add both of these libs to Libs property. - props.Libs = module.properties.Libs - props.Libs = append(props.Libs, module.properties.Static_libs...) - props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) - props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) + props.Libs = proptools.NewConfigurable[[]string](nil, nil) + props.Libs.AppendSimpleValue(module.properties.Libs) + props.Libs.Append(module.properties.Static_libs) + props.Libs.AppendSimpleValue(module.sdkLibraryProperties.Stub_only_libs) + props.Libs.AppendSimpleValue(module.scopeToProperties[apiScope].Libs) props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs props.Java_version = module.properties.Java_version @@ -2024,7 +2027,7 @@ func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, Name *string Visibility []string Api_contributions []string - Libs []string + Libs proptools.Configurable[[]string] Static_libs []string System_modules *string Enable_validation *bool @@ -2056,11 +2059,12 @@ func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, props.Api_contributions = apiContributions // Ensure that stub-annotations is added to the classpath before any other libs - props.Libs = []string{"stub-annotations"} - props.Libs = append(props.Libs, module.properties.Libs...) - props.Libs = append(props.Libs, module.properties.Static_libs...) - props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) - props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) + props.Libs = proptools.NewConfigurable[[]string](nil, nil) + props.Libs.AppendSimpleValue([]string{"stub-annotations"}) + props.Libs.AppendSimpleValue(module.properties.Libs) + props.Libs.Append(module.properties.Static_libs) + props.Libs.AppendSimpleValue(module.sdkLibraryProperties.Stub_only_libs) + props.Libs.AppendSimpleValue(module.scopeToProperties[apiScope].Libs) props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs props.System_modules = module.deviceProperties.System_modules @@ -2370,7 +2374,7 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookCont // Add the impl_only_libs and impl_only_static_libs *after* we're done using them in submodules. module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) - module.properties.Static_libs = append(module.properties.Static_libs, module.sdkLibraryProperties.Impl_only_static_libs...) + module.properties.Static_libs.AppendSimpleValue(module.sdkLibraryProperties.Impl_only_static_libs) } func (module *SdkLibrary) InitSdkLibraryProperties() { diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 485776b99..c345958ae 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -1528,7 +1528,8 @@ func TestJavaSdkLibrary_StubOnlyLibs_PassedToDroidstubs(t *testing.T) { // The foo.stubs.source should depend on bar-lib fooStubsSources := result.ModuleForTests("foo.stubs.source", "android_common").Module().(*Droidstubs) - android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs, "bar-lib") + eval := fooStubsSources.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext)) + android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs.GetOrDefault(eval, nil), "bar-lib") } func TestJavaSdkLibrary_Scope_Libs_PassedToDroidstubs(t *testing.T) { @@ -1554,7 +1555,8 @@ func TestJavaSdkLibrary_Scope_Libs_PassedToDroidstubs(t *testing.T) { // The foo.stubs.source should depend on bar-lib fooStubsSources := result.ModuleForTests("foo.stubs.source", "android_common").Module().(*Droidstubs) - android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs, "bar-lib") + eval := fooStubsSources.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext)) + android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs.GetOrDefault(eval, nil), "bar-lib") } func TestJavaSdkLibrary_ApiLibrary(t *testing.T) { @@ -1705,18 +1707,15 @@ func TestSdkLibraryExportableStubsLibrary(t *testing.T) { exportableSourceStubsLibraryModuleName := apiScopePublic.exportableSourceStubsLibraryModuleName("foo") // Check modules generation - topLevelModule := result.ModuleForTests(exportableStubsLibraryModuleName, "android_common") + result.ModuleForTests(exportableStubsLibraryModuleName, "android_common") result.ModuleForTests(exportableSourceStubsLibraryModuleName, "android_common") // Check static lib dependency android.AssertBoolEquals(t, "exportable top level stubs library module depends on the"+ "exportable source stubs library module", true, - CheckModuleHasDependency(t, result.TestContext, exportableStubsLibraryModuleName, - "android_common", exportableSourceStubsLibraryModuleName), + CheckModuleHasDependencyWithTag(t, result.TestContext, exportableStubsLibraryModuleName, + "android_common", staticLibTag, exportableSourceStubsLibraryModuleName), ) - android.AssertArrayString(t, "exportable source stub library is a static lib of the"+ - "top level exportable stubs library", []string{exportableSourceStubsLibraryModuleName}, - topLevelModule.Module().(*Library).properties.Static_libs) } // For java libraries depending on java_sdk_library(_import) via libs, assert that diff --git a/java/testing.go b/java/testing.go index 03dcee667..ab4ad6d64 100644 --- a/java/testing.go +++ b/java/testing.go @@ -632,6 +632,18 @@ func CheckModuleHasDependency(t *testing.T, ctx *android.TestContext, name, vari return false } +// CheckModuleHasDependency returns true if the module depends on the expected dependency. +func CheckModuleHasDependencyWithTag(t *testing.T, ctx *android.TestContext, name, variant string, desiredTag blueprint.DependencyTag, expected string) bool { + module := ctx.ModuleForTests(name, variant).Module() + found := false + ctx.VisitDirectDepsWithTags(module, func(m blueprint.Module, tag blueprint.DependencyTag) { + if tag == desiredTag && m.Name() == expected { + found = true + } + }) + return found +} + // CheckPlatformBootclasspathModules returns the apex:module pair for the modules depended upon by // the platform-bootclasspath module. func CheckPlatformBootclasspathModules(t *testing.T, result *android.TestResult, name string, expected []string) {