diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/aar.go | 21 | ||||
| -rwxr-xr-x | java/app.go | 3 | ||||
| -rw-r--r-- | java/base.go | 2 | ||||
| -rw-r--r-- | java/config/config.go | 2 | ||||
| -rw-r--r-- | java/core-libraries/Android.bp | 42 | ||||
| -rw-r--r-- | java/core-libraries/TxtStubLibraries.bp | 156 | ||||
| -rw-r--r-- | java/device_host_converter.go | 34 | ||||
| -rw-r--r-- | java/java.go | 152 | ||||
| -rw-r--r-- | java/java_test.go | 44 | ||||
| -rw-r--r-- | java/proto.go | 13 | ||||
| -rw-r--r-- | java/sdk.go | 9 | ||||
| -rw-r--r-- | java/testing.go | 26 |
12 files changed, 432 insertions, 72 deletions
diff --git a/java/aar.go b/java/aar.go index 47e6efae3..f1b137de1 100644 --- a/java/aar.go +++ b/java/aar.go @@ -1015,9 +1015,10 @@ type bazelAndroidLibrary struct { } type bazelAndroidLibraryImport struct { - Aar bazel.Label - Deps bazel.LabelListAttribute - Exports bazel.LabelListAttribute + Aar bazel.Label + Deps bazel.LabelListAttribute + Exports bazel.LabelListAttribute + Sdk_version bazel.StringAttribute } func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) *bazelAapt { @@ -1059,9 +1060,10 @@ func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) { }, android.CommonAttributes{Name: name}, &bazelAndroidLibraryImport{ - Aar: aars.Includes[0], - Deps: bazel.MakeLabelListAttribute(deps), - Exports: bazel.MakeLabelListAttribute(exports), + Aar: aars.Includes[0], + Deps: bazel.MakeLabelListAttribute(deps), + Exports: bazel.MakeLabelListAttribute(exports), + Sdk_version: bazel.StringAttribute{Value: a.properties.Sdk_version}, }, ) @@ -1073,6 +1075,9 @@ func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) { javaLibraryAttributes: &javaLibraryAttributes{ Neverlink: bazel.BoolAttribute{Value: &neverlink}, Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), + javaCommonAttributes: &javaCommonAttributes{ + Sdk_version: bazel.StringAttribute{Value: a.properties.Sdk_version}, + }, }, }, ) @@ -1119,6 +1124,10 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) javaLibraryAttributes: &javaLibraryAttributes{ Neverlink: bazel.BoolAttribute{Value: &neverlink}, Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), + javaCommonAttributes: &javaCommonAttributes{ + Sdk_version: bazel.StringAttribute{Value: a.deviceProperties.Sdk_version}, + Java_version: bazel.StringAttribute{Value: a.properties.Java_version}, + }, }, }, ) diff --git a/java/app.go b/java/app.go index 52caf6d38..03e233059 100755 --- a/java/app.go +++ b/java/app.go @@ -1565,6 +1565,9 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) { appAttrs.bazelAapt = &bazelAapt{Manifest: aapt.Manifest} appAttrs.Deps = bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + ktName}) + appAttrs.javaCommonAttributes = &javaCommonAttributes{ + Sdk_version: commonAttrs.Sdk_version, + } } ctx.CreateBazelTargetModule( diff --git a/java/base.go b/java/base.go index 1bcff2ed5..991132321 100644 --- a/java/base.go +++ b/java/base.go @@ -1923,7 +1923,7 @@ type moduleWithSdkDep interface { func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) { switch name { - case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs", + case android.SdkCore.JavaLibraryName(ctx.Config()), "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs", "stub-annotations", "private-stub-annotations-jar", "core-lambda-stubs", "core-generated-annotation-stubs": return javaCore, true diff --git a/java/config/config.go b/java/config/config.go index 13670ee38..b82a137e7 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -95,11 +95,13 @@ func init() { "-JXX:TieredStopAtLevel=1", "-JDcom.android.tools.r8.emitRecordAnnotationsInDex", "-JDcom.android.tools.r8.emitPermittedSubclassesAnnotationsInDex", + "-JDcom.android.tools.r8.emitRecordAnnotationsExInDex", }, dexerJavaVmFlagsList...)) exportedVars.ExportStringListStaticVariable("R8Flags", append([]string{ "-JXmx2048M", "-JDcom.android.tools.r8.emitRecordAnnotationsInDex", "-JDcom.android.tools.r8.emitPermittedSubclassesAnnotationsInDex", + "-JDcom.android.tools.r8.emitRecordAnnotationsExInDex", }, dexerJavaVmFlagsList...)) exportedVars.ExportStringListStaticVariable("CommonJdkFlags", []string{ diff --git a/java/core-libraries/Android.bp b/java/core-libraries/Android.bp index b9332dda5..958f4cead 100644 --- a/java/core-libraries/Android.bp +++ b/java/core-libraries/Android.bp @@ -79,16 +79,25 @@ java_library { ], } +// Defaults module to strip out android annotations +java_defaults { + name: "system-modules-no-annotations", + sdk_version: "none", + system_modules: "none", + jarjar_rules: "jarjar-strip-annotations-rules.txt", +} + // Same as core-current-stubs-for-system-modules, but android annotations are // stripped. java_library { name: "core-current-stubs-for-system-modules-no-annotations", visibility: ["//development/sdk"], + defaults: [ + "system-modules-no-annotations", + ], static_libs: [ "core-current-stubs-for-system-modules", ], - sdk_version: "none", - system_modules: "none", dists: [ { // Legacy dist location for the public file. @@ -100,7 +109,6 @@ java_library { targets: dist_targets, }, ], - jarjar_rules: "jarjar-strip-annotations-rules.txt", } // Used when compiling higher-level code against core.current.stubs. @@ -158,16 +166,16 @@ java_library { java_library { name: "core-module-lib-stubs-for-system-modules-no-annotations", visibility: ["//visibility:private"], + defaults: [ + "system-modules-no-annotations", + ], static_libs: [ "core-module-lib-stubs-for-system-modules", ], - sdk_version: "none", - system_modules: "none", dist: { dest: "system-modules/module-lib/core-for-system-modules-no-annotations.jar", targets: dist_targets, }, - jarjar_rules: "jarjar-strip-annotations-rules.txt", } // Used when compiling higher-level code with sdk_version "module_current" @@ -212,16 +220,16 @@ java_library { java_library { name: "legacy.core.platform.api.no.annotations.stubs", visibility: core_platform_visibility, + defaults: [ + "system-modules-no-annotations", + ], hostdex: true, compile_dex: true, - sdk_version: "none", - system_modules: "none", static_libs: [ "legacy.core.platform.api.stubs", ], patch_module: "java.base", - jarjar_rules: "jarjar-strip-annotations-rules.txt", } java_library { @@ -247,16 +255,16 @@ java_library { java_library { name: "stable.core.platform.api.no.annotations.stubs", visibility: core_platform_visibility, + defaults: [ + "system-modules-no-annotations", + ], hostdex: true, compile_dex: true, - sdk_version: "none", - system_modules: "none", static_libs: [ "stable.core.platform.api.stubs", ], patch_module: "java.base", - jarjar_rules: "jarjar-strip-annotations-rules.txt", } // Used when compiling higher-level code against *.core.platform.api.stubs. @@ -307,12 +315,6 @@ java_system_modules { // the UnsupportedAppUsage, CorePlatformApi and IntraCoreApi // annotations. "art.module.api.annotations.for.system.modules", - - // Make nullability annotations available when compiling public stubs. - // They are provided as a separate library because while the - // annotations are not themselves part of the public API provided by - // this module they are used in the stubs. - "stub-annotations", ], } @@ -349,3 +351,7 @@ java_system_modules { "art-module-intra-core-api-stubs-system-modules-lib", ], } + +build = [ + "TxtStubLibraries.bp", +] diff --git a/java/core-libraries/TxtStubLibraries.bp b/java/core-libraries/TxtStubLibraries.bp new file mode 100644 index 000000000..813187e54 --- /dev/null +++ b/java/core-libraries/TxtStubLibraries.bp @@ -0,0 +1,156 @@ +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file contains java_system_modules provided by the SDK. +// These system modules transitively depend on core stub libraries generated from .txt files. + +// Same as core-public-stubs-system-modules, but the stubs are generated from .txt files +java_system_modules { + name: "core-public-stubs-system-modules.from-text", + visibility: ["//visibility:public"], + libs: [ + "core-current-stubs-for-system-modules-no-annotations.from-text", + ], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +java_library { + name: "core-current-stubs-for-system-modules-no-annotations.from-text", + visibility: ["//visibility:private"], + defaults: [ + "system-modules-no-annotations", + ], + static_libs: [ + "core.current.stubs.from-text", + "core-lambda-stubs.from-text", + ], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +// Same as core-module-lib-stubs-system-modules, but the stubs are generated from .txt files +java_system_modules { + name: "core-module-lib-stubs-system-modules.from-text", + visibility: ["//visibility:public"], + libs: [ + "core-module-lib-stubs-for-system-modules-no-annotations.from-text", + ], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +java_library { + name: "core-module-lib-stubs-for-system-modules-no-annotations.from-text", + visibility: ["//visibility:private"], + defaults: [ + "system-modules-no-annotations", + ], + static_libs: [ + "core.module_lib.stubs.from-text", + "core-lambda-stubs.from-text", + ], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +java_library { + name: "core.module_lib.stubs.from-text", + static_libs: [ + "art.module.public.api.stubs.module_lib.from-text", + + // Replace the following with the module-lib correspondence when Conscrypt or i18N module + // provides @SystemApi(MODULE_LIBRARIES). Currently, assume that only ART module provides + // @SystemApi(MODULE_LIBRARIES). + "conscrypt.module.public.api.stubs.from-text", + "i18n.module.public.api.stubs.from-text", + ], + sdk_version: "none", + system_modules: "none", + visibility: ["//visibility:private"], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +// Same as legacy-core-platform-api-stubs-system-modules, but the stubs are generated from .txt files +java_system_modules { + name: "legacy-core-platform-api-stubs-system-modules.from-text", + visibility: core_platform_visibility, + libs: [ + "legacy.core.platform.api.no.annotations.stubs.from-text", + "core-lambda-stubs.from-text", + ], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +java_library { + name: "legacy.core.platform.api.no.annotations.stubs.from-text", + visibility: core_platform_visibility, + defaults: [ + "system-modules-no-annotations", + ], + hostdex: true, + compile_dex: true, + + static_libs: [ + "legacy.core.platform.api.stubs.from-text", + ], + patch_module: "java.base", + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +// Same as stable-core-platform-api-stubs-system-modules, but the stubs are generated from .txt files +java_system_modules { + name: "stable-core-platform-api-stubs-system-modules.from-text", + visibility: core_platform_visibility, + libs: [ + "stable.core.platform.api.no.annotations.stubs.from-text", + "core-lambda-stubs.from-text", + ], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +java_library { + name: "stable.core.platform.api.no.annotations.stubs.from-text", + visibility: core_platform_visibility, + defaults: [ + "system-modules-no-annotations", + ], + hostdex: true, + compile_dex: true, + + static_libs: [ + "stable.core.platform.api.stubs.from-text", + ], + patch_module: "java.base", + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} + +java_api_library { + name: "core-lambda-stubs.from-text", + api_surface: "toolchain", + api_contributions: [ + "art.module.toolchain.api.api.contribution", + ], + libs: [ + // LambdaMetaFactory depends on CallSite etc. which is part of the Core API surface + "core.current.stubs.from-text", + ], + // TODO: Enable after stub generation from .txt file is available + enabled: false, +} diff --git a/java/device_host_converter.go b/java/device_host_converter.go index 4abdcc6e9..3581040f8 100644 --- a/java/device_host_converter.go +++ b/java/device_host_converter.go @@ -19,12 +19,16 @@ import ( "io" "android/soong/android" + "android/soong/bazel" "android/soong/dexpreopt" + + "github.com/google/blueprint/proptools" ) type DeviceHostConverter struct { android.ModuleBase android.DefaultableModuleBase + android.BazelModuleBase properties DeviceHostConverterProperties @@ -76,6 +80,7 @@ func HostForDeviceFactory() android.Module { module.AddProperties(&module.properties) InitJavaModule(module, android.DeviceSupported) + android.InitBazelModule(module) return module } @@ -186,3 +191,32 @@ func (d *DeviceHostConverter) AndroidMk() android.AndroidMkData { }, } } + +type bazelDeviceHostConverterAttributes struct { + Exports bazel.LabelListAttribute +} + +func (d *DeviceHostConverter) ConvertWithBp2build(ctx android.TopDownMutatorContext) { + ctx.CreateBazelTargetModule( + bazel.BazelTargetModuleProperties{ + Rule_class: "java_host_for_device", + Bzl_load_location: "//build/bazel/rules/java:host_for_device.bzl", + }, + android.CommonAttributes{Name: d.Name()}, + &bazelDeviceHostConverterAttributes{ + Exports: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, d.properties.Libs)), + }, + ) + neverLinkAttrs := &javaLibraryAttributes{ + Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + d.Name()}), + Neverlink: bazel.BoolAttribute{Value: proptools.BoolPtr(true)}, + javaCommonAttributes: &javaCommonAttributes{ + Sdk_version: bazel.StringAttribute{Value: proptools.StringPtr("none")}, + }, + } + ctx.CreateBazelTargetModule( + javaLibraryBazelTargetModuleProperties(), + android.CommonAttributes{Name: d.Name() + "-neverlink"}, + neverLinkAttrs) + +} diff --git a/java/java.go b/java/java.go index 499a6b6cd..2de4ea97e 100644 --- a/java/java.go +++ b/java/java.go @@ -388,6 +388,8 @@ var ( jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true} r8LibraryJarTag = dependencyTag{name: "r8-libraryjar", runtimeLinked: true} syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"} + javaApiContributionTag = dependencyTag{name: "java-api-contribution"} + depApiSrcsTag = dependencyTag{name: "dep-api-srcs"} jniInstallTag = installDependencyTag{name: "jni install"} binaryInstallTag = installDependencyTag{name: "binary install"} usesLibReqTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, false) @@ -1609,6 +1611,13 @@ func (ap *JavaApiContribution) GenerateAndroidBuildActions(ctx android.ModuleCon }) } +type JavaApiLibraryDepsInfo struct { + JavaInfo + StubsSrcJar android.Path +} + +var JavaApiLibraryDepsProvider = blueprint.NewProvider(JavaApiLibraryDepsInfo{}) + type ApiLibrary struct { android.ModuleBase android.DefaultableModuleBase @@ -1618,8 +1627,10 @@ type ApiLibrary struct { properties JavaApiLibraryProperties - stubsSrcJar android.WritablePath - stubsJar android.WritablePath + stubsSrcJar android.WritablePath + stubsJar android.WritablePath + stubsJarWithoutStaticLibs android.WritablePath + extractedSrcJar android.WritablePath // .dex of stubs, used for hiddenapi processing dexJarFile OptionalDexJarPath } @@ -1645,8 +1656,13 @@ type JavaApiLibraryProperties struct { Libs []string // List of java libs that this module has static dependencies to and will be - // passed in metalava invocation + // merge zipped after metalava invocation Static_libs []string + + // Java Api library to provide the full API surface text files and jar file. + // If this property is set, the provided full API surface text files and + // jar file are passed to metalava invocation. + Dep_api_srcs *string } func ApiLibraryFactory() android.Module { @@ -1725,7 +1741,36 @@ func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBui } } -var javaApiContributionTag = dependencyTag{name: "java-api-contribution"} +// This method extracts the stub java files from the srcjar file provided from dep_api_srcs module +// and replaces the java stubs generated by invoking metalava in this module. +// This method is used because metalava can generate compilable from-text stubs only when +// the codebase encompasses all classes listed in the input API text file, but a class can extend +// a class that is not within the same API domain. +func (al *ApiLibrary) extractApiSrcs(ctx android.ModuleContext, rule *android.RuleBuilder, stubsDir android.OptionalPath, depApiSrcsSrcJar android.Path) { + generatedStubsList := android.PathForModuleOut(ctx, "metalava", "sources.txt") + unzippedSrcJarDir := android.PathForModuleOut(ctx, "metalava", "unzipDir") + + rule.Command(). + BuiltTool("list_files"). + Text(stubsDir.String()). + FlagWithOutput("--out ", generatedStubsList). + FlagWithArg("--extensions ", ".java"). + FlagWithArg("--root ", unzippedSrcJarDir.String()) + + rule.Command(). + Text("unzip"). + Flag("-q"). + Input(depApiSrcsSrcJar). + FlagWithArg("-d ", unzippedSrcJarDir.String()) + + rule.Command(). + BuiltTool("soong_zip"). + Flag("-srcjar"). + Flag("-write_if_changed"). + FlagWithArg("-C ", unzippedSrcJarDir.String()). + FlagWithInput("-l ", generatedStubsList). + FlagWithOutput("-o ", al.stubsSrcJar) +} func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { apiContributions := al.properties.Api_contributions @@ -1734,6 +1779,9 @@ func (al *ApiLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { } ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...) ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...) + if al.properties.Dep_api_srcs != nil { + ctx.AddVariationDependencies(nil, depApiSrcsTag, String(al.properties.Dep_api_srcs)) + } } func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -1754,6 +1802,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { var srcFiles android.Paths var classPaths android.Paths var staticLibs android.Paths + var depApiSrcsStubsSrcJar android.Path ctx.VisitDirectDeps(func(dep android.Module) { tag := ctx.OtherModuleDependencyTag(dep) switch tag { @@ -1770,6 +1819,10 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { case staticLibTag: provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) staticLibs = append(staticLibs, provider.HeaderJars...) + case depApiSrcsTag: + provider := ctx.OtherModuleProvider(dep, JavaApiLibraryDepsProvider).(JavaApiLibraryDepsInfo) + classPaths = append(classPaths, provider.HeaderJars...) + depApiSrcsStubsSrcJar = provider.StubsSrcJar } }) @@ -1780,21 +1833,31 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { srcFiles = append(srcFiles, android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), api)) } + if srcFiles == nil { + ctx.ModuleErrorf("Error: %s has an empty api file.", ctx.ModuleName()) + } + cmd := metalavaStubCmd(ctx, rule, srcFiles, homeDir) al.stubsFlags(ctx, cmd, stubsDir) al.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar") - rule.Command(). - BuiltTool("soong_zip"). - Flag("-write_if_changed"). - Flag("-jar"). - FlagWithOutput("-o ", al.stubsSrcJar). - FlagWithArg("-C ", stubsDir.String()). - FlagWithArg("-D ", stubsDir.String()) + + if depApiSrcsStubsSrcJar != nil { + al.extractApiSrcs(ctx, rule, stubsDir, depApiSrcsStubsSrcJar) + } else { + rule.Command(). + BuiltTool("soong_zip"). + Flag("-write_if_changed"). + Flag("-jar"). + FlagWithOutput("-o ", al.stubsSrcJar). + FlagWithArg("-C ", stubsDir.String()). + FlagWithArg("-D ", stubsDir.String()) + } rule.Build("metalava", "metalava merged") - compiledStubs := android.PathForModuleOut(ctx, ctx.ModuleName(), "stubs.jar") + + al.stubsJarWithoutStaticLibs = android.PathForModuleOut(ctx, ctx.ModuleName(), "stubs.jar") al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), fmt.Sprintf("%s.jar", ctx.ModuleName())) var flags javaBuilderFlags @@ -1802,14 +1865,14 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { flags.javacFlags = strings.Join(al.properties.Javacflags, " ") flags.classpath = classpath(classPaths) - TransformJavaToClasses(ctx, compiledStubs, 0, android.Paths{}, + TransformJavaToClasses(ctx, al.stubsJarWithoutStaticLibs, 0, android.Paths{}, android.Paths{al.stubsSrcJar}, flags, android.Paths{}) builder := android.NewRuleBuilder(pctx, ctx) builder.Command(). BuiltTool("merge_zips"). Output(al.stubsJar). - Inputs(android.Paths{compiledStubs}). + Inputs(android.Paths{al.stubsJarWithoutStaticLibs}). Inputs(staticLibs) builder.Build("merge_zips", "merge jar files") @@ -1835,6 +1898,13 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { ImplementationJars: android.PathsIfNonNil(al.stubsJar), AidlIncludeDirs: android.Paths{}, }) + + ctx.SetProvider(JavaApiLibraryDepsProvider, JavaApiLibraryDepsInfo{ + JavaInfo: JavaInfo{ + HeaderJars: android.PathsIfNonNil(al.stubsJar), + }, + StubsSrcJar: al.stubsSrcJar, + }) } func (al *ApiLibrary) DexJarBuildPath() OptionalDexJarPath { @@ -2670,9 +2740,11 @@ func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorConte type javaCommonAttributes struct { *javaResourcesAttributes *kotlinAttributes - Srcs bazel.LabelListAttribute - Plugins bazel.LabelListAttribute - Javacopts bazel.StringListAttribute + Srcs bazel.LabelListAttribute + Plugins bazel.LabelListAttribute + Javacopts bazel.StringListAttribute + Sdk_version bazel.StringAttribute + Java_version bazel.StringAttribute } type javaDependencyLabels struct { @@ -2772,7 +2844,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "aidl_library", - Bzl_load_location: "//build/bazel/rules/aidl:library.bzl", + Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl", }, android.CommonAttributes{Name: aidlLibName}, &aidlLibraryAttributes{ @@ -2787,7 +2859,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: "java_aidl_library", - Bzl_load_location: "//build/bazel/rules/java:aidl_library.bzl", + Bzl_load_location: "//build/bazel/rules/java:java_aidl_library.bzl", }, android.CommonAttributes{Name: javaAidlLibName}, &javaAidlLibraryAttributes{ @@ -2803,10 +2875,6 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) if m.properties.Javacflags != nil { javacopts = append(javacopts, m.properties.Javacflags...) } - if m.properties.Java_version != nil { - javaVersion := normalizeJavaVersion(ctx, *m.properties.Java_version).String() - javacopts = append(javacopts, fmt.Sprintf("-source %s -target %s", javaVersion, javaVersion)) - } epEnabled := m.properties.Errorprone.Enabled //TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable @@ -2820,7 +2888,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) Plugins: bazel.MakeLabelListAttribute( android.BazelLabelForModuleDeps(ctx, m.properties.Plugins), ), - Javacopts: bazel.MakeStringListAttribute(javacopts), + Javacopts: bazel.MakeStringListAttribute(javacopts), + Java_version: bazel.StringAttribute{Value: m.properties.Java_version}, + Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version}, } for axis, configToProps := range archVariantProps { @@ -2837,10 +2907,6 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) } } - if m.properties.Static_libs != nil { - staticDeps.Append(android.BazelLabelForModuleDeps(ctx, android.LastUniqueStrings(android.CopyOf(m.properties.Static_libs)))) - } - protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition]) // Soong does not differentiate between a java_library and the Bazel equivalent of // a java_proto_library + proto_library pair. Instead, in Soong proto sources are @@ -2852,7 +2918,18 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) depLabels := &javaDependencyLabels{} depLabels.Deps = deps - depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps) + + for axis, configToProps := range archVariantProps { + for config, _props := range configToProps { + if archProps, ok := _props.(*CommonProperties); ok { + archStaticLibs := android.BazelLabelForModuleDeps( + ctx, + android.LastUniqueStrings(android.CopyOf(archProps.Static_libs))) + depLabels.StaticDeps.SetSelectValue(axis, config, archStaticLibs) + } + } + } + depLabels.StaticDeps.Value.Append(staticDeps) hasKotlin := !kotlinSrcs.IsEmpty() commonAttrs.kotlinAttributes = &kotlinAttributes{ @@ -2904,19 +2981,9 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { deps := depLabels.Deps if !commonAttrs.Srcs.IsEmpty() { deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them - - sdkVersion := m.SdkVersion(ctx) - if sdkVersion.Kind == android.SdkPublic && sdkVersion.ApiLevel == android.FutureApiLevel { - // TODO(b/220869005) remove forced dependency on current public android.jar - deps.Add(bazel.MakeLabelAttribute("//prebuilts/sdk:public_current_android_sdk_java_import")) - } else if sdkVersion.Kind == android.SdkSystem && sdkVersion.ApiLevel == android.FutureApiLevel { - // TODO(b/215230098) remove forced dependency on current public android.jar - deps.Add(bazel.MakeLabelAttribute("//prebuilts/sdk:system_current_android_sdk_java_import")) - } } else if !deps.IsEmpty() { ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") } - var props bazel.BazelTargetModuleProperties attrs := &javaLibraryAttributes{ javaCommonAttributes: commonAttrs, @@ -2936,6 +3003,10 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { neverLinkAttrs := &javaLibraryAttributes{ Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), Neverlink: bazel.BoolAttribute{Value: &neverlinkProp}, + javaCommonAttributes: &javaCommonAttributes{ + Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version}, + Java_version: bazel.StringAttribute{Value: m.properties.Java_version}, + }, } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name + "-neverlink"}, neverLinkAttrs) @@ -3075,6 +3146,9 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) { neverlinkAttrs := &javaLibraryAttributes{ Neverlink: bazel.BoolAttribute{Value: &neverlink}, Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), + javaCommonAttributes: &javaCommonAttributes{ + Sdk_version: bazel.StringAttribute{Value: proptools.StringPtr("none")}, + }, } ctx.CreateBazelTargetModule( javaLibraryBazelTargetModuleProperties(), diff --git a/java/java_test.go b/java/java_test.go index 68b749b6d..553b762ee 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2209,6 +2209,50 @@ func TestJavaApiLibraryStaticLibsLink(t *testing.T) { } } +func TestJavaApiLibraryDepApiSrcs(t *testing.T) { + provider_bp_a := ` + java_api_contribution { + name: "foo1", + api_file: "foo1.txt", + } + ` + provider_bp_b := ` + java_api_contribution { + name: "foo2", + api_file: "foo2.txt", + } + ` + lib_bp_a := ` + java_api_library { + name: "lib1", + api_surface: "public", + api_contributions: ["foo1", "foo2"], + } + ` + + ctx, _ := testJavaWithFS(t, ` + java_api_library { + name: "bar1", + api_surface: "public", + api_contributions: ["foo1"], + dep_api_srcs: "lib1", + } + `, + map[string][]byte{ + "a/Android.bp": []byte(provider_bp_a), + "b/Android.bp": []byte(provider_bp_b), + "c/Android.bp": []byte(lib_bp_a), + }) + + m := ctx.ModuleForTests("bar1", "android_common") + manifest := m.Output("metalava.sbox.textproto") + sboxProto := android.RuleBuilderSboxProtoForTests(t, manifest) + manifestCommand := sboxProto.Commands[0].GetCommand() + + android.AssertStringDoesContain(t, "Command expected to contain module srcjar file", manifestCommand, "bar1-stubs.srcjar") + android.AssertStringDoesContain(t, "Command expected to contain output files list text file flag", manifestCommand, "--out __SBOX_SANDBOX_DIR__/out/sources.txt") +} + func TestTradefedOptions(t *testing.T) { result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, ` java_test_host { diff --git a/java/proto.go b/java/proto.go index 5280077f1..c732d9842 100644 --- a/java/proto.go +++ b/java/proto.go @@ -143,7 +143,9 @@ func protoFlags(ctx android.ModuleContext, j *CommonProperties, p *android.Proto } type protoAttributes struct { - Deps bazel.LabelListAttribute + Deps bazel.LabelListAttribute + Sdk_version bazel.StringAttribute + Java_version bazel.StringAttribute } func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs bazel.LabelListAttribute) *bazel.Label { @@ -175,8 +177,11 @@ func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs baze } protoLabel := bazel.Label{Label: ":" + m.Name() + "_proto"} - var protoAttrs protoAttributes - protoAttrs.Deps.SetValue(bazel.LabelList{Includes: []bazel.Label{protoLabel}}) + protoAttrs := &protoAttributes{ + Deps: bazel.MakeSingleLabelListAttribute(protoLabel), + Java_version: bazel.StringAttribute{Value: m.properties.Java_version}, + Sdk_version: bazel.StringAttribute{Value: m.deviceProperties.Sdk_version}, + } name := m.Name() + suffix @@ -186,7 +191,7 @@ func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs baze Bzl_load_location: "//build/bazel/rules/java:proto.bzl", }, android.CommonAttributes{Name: name}, - &protoAttrs) + protoAttrs) return &bazel.Label{Label: ":" + name} } diff --git a/java/sdk.go b/java/sdk.go index 72a50067c..8b4918add 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -148,10 +148,11 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) toModule := func(module string, aidl android.Path) sdkDep { // Select the kind of system modules needed for the sdk version. systemModulesKind := systemModuleKind(sdkVersion.Kind, android.FutureApiLevel) + systemModules := android.JavaApiLibraryName(ctx.Config(), fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind)) return sdkDep{ useModule: true, - bootclasspath: []string{module, config.DefaultLambdaStubsLibrary}, - systemModules: fmt.Sprintf("core-%s-stubs-system-modules", systemModulesKind), + bootclasspath: []string{module, android.JavaApiLibraryName(ctx.Config(), config.DefaultLambdaStubsLibrary)}, + systemModules: systemModules, java9Classpath: []string{module}, frameworkResModule: "framework-res", aidl: android.OptionalPathForPath(aidl), @@ -196,8 +197,8 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) case android.SdkCore: return sdkDep{ useModule: true, - bootclasspath: []string{"core.current.stubs", config.DefaultLambdaStubsLibrary}, - systemModules: "core-public-stubs-system-modules", + bootclasspath: []string{android.SdkCore.JavaLibraryName(ctx.Config()), android.JavaApiLibraryName(ctx.Config(), config.DefaultLambdaStubsLibrary)}, + systemModules: android.JavaApiLibraryName(ctx.Config(), "core-public-stubs-system-modules"), noFrameworksLibs: true, } case android.SdkModule: diff --git a/java/testing.go b/java/testing.go index 63d7dba69..0764d264a 100644 --- a/java/testing.go +++ b/java/testing.go @@ -368,6 +368,7 @@ func gatherRequiredDepsForTest() string { "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs", + "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8", @@ -387,6 +388,27 @@ func gatherRequiredDepsForTest() string { `, extra) } + extraApiLibraryModules := map[string]string{ + "android_stubs_current.from-text": "api/current.txt", + "android_system_stubs_current.from-text": "api/system-current.txt", + "android_test_stubs_current.from-text": "api/test-current.txt", + "android_module_lib_stubs_current.from-text": "api/module-lib-current.txt", + "android_system_server_stubs_current.from-text": "api/system-server-current.txt", + "core.current.stubs.from-text": "api/current.txt", + "legacy.core.platform.api.stubs.from-text": "api/current.txt", + "stable.core.platform.api.stubs.from-text": "api/current.txt", + "core-lambda-stubs.from-text": "api/current.txt", + } + + for libName, apiFile := range extraApiLibraryModules { + bp += fmt.Sprintf(` + java_api_library { + name: "%s", + api_files: ["%s"], + } + `, libName, apiFile) + } + bp += ` java_library { name: "framework", @@ -409,6 +431,10 @@ func gatherRequiredDepsForTest() string { "core-module-lib-stubs-system-modules", "legacy-core-platform-api-stubs-system-modules", "stable-core-platform-api-stubs-system-modules", + "core-public-stubs-system-modules.from-text", + "core-module-lib-stubs-system-modules.from-text", + "legacy-core-platform-api-stubs-system-modules.from-text", + "stable-core-platform-api-stubs-system-modules.from-text", } for _, extra := range systemModules { |