summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go57
1 files changed, 32 insertions, 25 deletions
diff --git a/java/java.go b/java/java.go
index d400b0cfb..a98762cf1 100644
--- a/java/java.go
+++ b/java/java.go
@@ -456,7 +456,9 @@ func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext,
ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
ctx.AddVariationDependencies(nil, sdkLibTag, sdkDep.classpath...)
if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
- ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries...)
+ ctx.AddVariationDependencies(nil, proguardRaiseTag,
+ android.JavaApiLibraryNames(ctx.Config(), config.LegacyCorePlatformBootclasspathLibraries)...,
+ )
}
if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...)
@@ -813,7 +815,10 @@ func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberCo
// If the min_sdk_version was set then add the canonical representation of the API level to the
// snapshot.
if j.deviceProperties.Min_sdk_version != nil {
- canonical := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String())
+ canonical, err := android.ReplaceFinalizedCodenames(ctx.SdkModuleContext().Config(), j.minSdkVersion.String())
+ if err != nil {
+ ctx.ModuleErrorf("%s", err)
+ }
p.MinSdkVersion = proptools.StringPtr(canonical)
}
@@ -2705,8 +2710,13 @@ func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorConte
var resources bazel.LabelList
var resourceStripPrefix *string
+ if m.properties.Java_resources != nil && len(m.properties.Java_resource_dirs) > 0 {
+ ctx.ModuleErrorf("bp2build doesn't support both java_resources and java_resource_dirs being set on the same module.")
+ }
+
if m.properties.Java_resources != nil {
resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources))
+ resourceStripPrefix = proptools.StringPtr(ctx.ModuleDir())
}
//TODO(b/179889880) handle case where glob includes files outside package
@@ -2740,9 +2750,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 {
@@ -2835,7 +2847,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName)
})
- apexAvailableTags := android.ApexAvailableTags(ctx.Module())
+ apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx, ctx.Module())
if !aidlSrcs.IsEmpty() {
aidlLibName := m.Name() + "_aidl_library"
@@ -2873,10 +2885,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
@@ -2890,7 +2898,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 {
@@ -2963,14 +2973,14 @@ type kotlinAttributes struct {
func ktJvmLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties {
return bazel.BazelTargetModuleProperties{
Rule_class: "kt_jvm_library",
- Bzl_load_location: "//build/bazel/rules/kotlin:rules.bzl",
+ Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl",
}
}
func javaLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties {
return bazel.BazelTargetModuleProperties{
Rule_class: "java_library",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
+ Bzl_load_location: "//build/bazel/rules/java:library.bzl",
}
}
@@ -2981,19 +2991,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,
@@ -3013,6 +3013,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)
@@ -3085,7 +3089,7 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
props := bazel.BazelTargetModuleProperties{
Rule_class: "java_binary",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
+ Bzl_load_location: "@rules_java//java:defs.bzl",
}
binAttrs := &javaBinaryHostAttributes{
Runtime_deps: runtimeDeps,
@@ -3141,7 +3145,7 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
}
props := bazel.BazelTargetModuleProperties{
Rule_class: "java_import",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
+ Bzl_load_location: "//build/bazel/rules/java:import.bzl",
}
name := android.RemoveOptionalPrebuiltPrefix(i.Name())
@@ -3152,6 +3156,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(),