Merge "Bp2build support for sdk_version and java_version."

This commit is contained in:
Romain Jobredeaux
2023-04-13 20:53:07 +00:00
committed by Gerrit Code Review
16 changed files with 126 additions and 74 deletions

View File

@@ -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},
},
},
},
)

View File

@@ -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(

View File

@@ -21,6 +21,8 @@ import (
"android/soong/android"
"android/soong/bazel"
"android/soong/dexpreopt"
"github.com/google/blueprint/proptools"
)
type DeviceHostConverter struct {
@@ -191,7 +193,7 @@ func (d *DeviceHostConverter) AndroidMk() android.AndroidMkData {
}
type bazelDeviceHostConverterAttributes struct {
Deps bazel.LabelListAttribute
Exports bazel.LabelListAttribute
}
func (d *DeviceHostConverter) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
@@ -202,13 +204,15 @@ func (d *DeviceHostConverter) ConvertWithBp2build(ctx android.TopDownMutatorCont
},
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(),

View File

@@ -2740,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 {
@@ -2873,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
@@ -2890,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 {
@@ -2981,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,
@@ -3013,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)
@@ -3152,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(),

View File

@@ -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}
}