Bp2build support for sdk_version and java_version.
This CL adds java_version and sdk_version support to bp2build
converters for
- java library
- java binary
- android library
- android binary
- android library import
Although java import doesn't support java_version and sdk_version, the
neverlink java_library wrapper around a java_import must specify a
sdk_version when targetting a device. "none" is used by convention.
Change-Id: I22a69dea2e351858368df69ed6a703b568d613ea
Bug: 215230098
Test: Presubmits
diff --git a/java/aar.go b/java/aar.go
index 47e6efa..f1b137d 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -1015,9 +1015,10 @@
}
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 @@
},
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 @@
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 @@
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 52caf6d..03e2330 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1565,6 +1565,9 @@
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/device_host_converter.go b/java/device_host_converter.go
index 656c866..3581040 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -21,6 +21,8 @@
"android/soong/android"
"android/soong/bazel"
"android/soong/dexpreopt"
+
+ "github.com/google/blueprint/proptools"
)
type DeviceHostConverter struct {
@@ -191,7 +193,7 @@
}
type bazelDeviceHostConverterAttributes struct {
- Deps bazel.LabelListAttribute
+ Exports bazel.LabelListAttribute
}
func (d *DeviceHostConverter) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
@@ -202,13 +204,15 @@
},
android.CommonAttributes{Name: d.Name()},
&bazelDeviceHostConverterAttributes{
- Deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, d.properties.Libs)),
+ Exports: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, d.properties.Libs)),
},
)
- neverlinkProp := true
neverLinkAttrs := &javaLibraryAttributes{
Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + d.Name()}),
- Neverlink: bazel.BoolAttribute{Value: &neverlinkProp},
+ Neverlink: bazel.BoolAttribute{Value: proptools.BoolPtr(true)},
+ javaCommonAttributes: &javaCommonAttributes{
+ Sdk_version: bazel.StringAttribute{Value: proptools.StringPtr("none")},
+ },
}
ctx.CreateBazelTargetModule(
javaLibraryBazelTargetModuleProperties(),
diff --git a/java/java.go b/java/java.go
index 403f503..d235103 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2738,9 +2738,11 @@
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 {
@@ -2871,10 +2873,6 @@
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
@@ -2888,7 +2886,9 @@
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 {
@@ -2979,19 +2979,9 @@
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,
@@ -3011,6 +3001,10 @@
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)
@@ -3150,6 +3144,9 @@
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/proto.go b/java/proto.go
index 5280077..c732d98 100644
--- a/java/proto.go
+++ b/java/proto.go
@@ -143,7 +143,9 @@
}
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 @@
}
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 @@
Bzl_load_location: "//build/bazel/rules/java:proto.bzl",
},
android.CommonAttributes{Name: name},
- &protoAttrs)
+ protoAttrs)
return &bazel.Label{Label: ":" + name}
}