Merge changes from topic "no-srcs-no-deps" am: d93afba1e6
am: d218781011
am: beb28cd9ad
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1995730 Change-Id: I8c8c7b973ffc6a6dfd91c35dc96e73c42bf30577 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
17
java/app.go
17
java/app.go
@@ -1456,7 +1456,8 @@ func androidAppCertificateBp2Build(ctx android.TopDownMutatorContext, module *An
|
||||
}
|
||||
|
||||
type bazelAndroidAppAttributes struct {
|
||||
*javaLibraryAttributes
|
||||
*javaCommonAttributes
|
||||
Deps bazel.LabelListAttribute
|
||||
Manifest bazel.Label
|
||||
Custom_package *string
|
||||
Resource_files bazel.LabelListAttribute
|
||||
@@ -1466,7 +1467,16 @@ type bazelAndroidAppAttributes struct {
|
||||
|
||||
// ConvertWithBp2build is used to convert android_app to Bazel.
|
||||
func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
libAttrs := a.convertLibraryAttrsBp2Build(ctx)
|
||||
commonAttrs, depLabels := a.convertLibraryAttrsBp2Build(ctx)
|
||||
|
||||
deps := depLabels.Deps
|
||||
if !commonAttrs.Srcs.IsEmpty() {
|
||||
deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
|
||||
} else if !deps.IsEmpty() || !depLabels.StaticDeps.IsEmpty() {
|
||||
ctx.ModuleErrorf("android_app has dynamic or static dependencies but no sources." +
|
||||
" Bazel does not allow direct dependencies without sources nor exported" +
|
||||
" dependencies on android_binary rule.")
|
||||
}
|
||||
|
||||
manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||
|
||||
@@ -1489,7 +1499,8 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
}
|
||||
|
||||
attrs := &bazelAndroidAppAttributes{
|
||||
libAttrs,
|
||||
commonAttrs,
|
||||
deps,
|
||||
android.BazelLabelForModuleSrcSingle(ctx, manifest),
|
||||
// TODO(b/209576404): handle package name override by product variable PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
|
||||
a.overridableAppProperties.Package_name,
|
||||
|
125
java/java.go
125
java/java.go
@@ -2023,13 +2023,23 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
|
||||
}
|
||||
}
|
||||
|
||||
type javaLibraryAttributes struct {
|
||||
type javaCommonAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Deps bazel.LabelListAttribute
|
||||
Javacopts bazel.StringListAttribute
|
||||
}
|
||||
|
||||
func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) *javaLibraryAttributes {
|
||||
type javaDependencyLabels struct {
|
||||
// Dependencies which DO NOT contribute to the API visible to upstream dependencies.
|
||||
Deps bazel.LabelListAttribute
|
||||
// Dependencies which DO contribute to the API visible to upstream dependencies.
|
||||
StaticDeps bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
// convertLibraryAttrsBp2Build converts a few shared attributes from java_* modules
|
||||
// and also separates dependencies into dynamic dependencies and static dependencies.
|
||||
// Each corresponding Bazel target type, can have a different method for handling
|
||||
// dynamic vs. static dependencies, and so these are returned to the calling function.
|
||||
func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) (*javaCommonAttributes, *javaDependencyLabels) {
|
||||
var srcs bazel.LabelListAttribute
|
||||
archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
|
||||
for axis, configToProps := range archVariantProps {
|
||||
@@ -2048,40 +2058,68 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
|
||||
protoSrcPartition: android.ProtoSrcLabelPartition,
|
||||
})
|
||||
|
||||
attrs := &javaLibraryAttributes{
|
||||
commonAttrs := &javaCommonAttributes{
|
||||
Srcs: srcPartitions[javaSrcPartition],
|
||||
}
|
||||
|
||||
if m.properties.Javacflags != nil {
|
||||
attrs.Javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)
|
||||
commonAttrs.Javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)
|
||||
}
|
||||
|
||||
depLabels := &javaDependencyLabels{}
|
||||
|
||||
var deps bazel.LabelList
|
||||
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.Label{Label: "//prebuilts/sdk:public_current_android_sdk_java_import"})
|
||||
}
|
||||
if m.properties.Libs != nil {
|
||||
deps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Libs))
|
||||
}
|
||||
|
||||
var staticDeps bazel.LabelList
|
||||
if m.properties.Static_libs != nil {
|
||||
//TODO(b/217236083) handle static libs similarly to Soong
|
||||
deps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Static_libs))
|
||||
staticDeps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Static_libs))
|
||||
}
|
||||
|
||||
protoDeps := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition])
|
||||
if protoDeps != nil {
|
||||
deps.Add(protoDeps)
|
||||
}
|
||||
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
|
||||
// listed directly in the srcs of a java_library, and the classes produced
|
||||
// by protoc are included directly in the resulting JAR. Thus upstream dependencies
|
||||
// that depend on a java_library with proto sources can link directly to the protobuf API,
|
||||
// and so this should be a static dependency.
|
||||
staticDeps.Add(protoDepLabel)
|
||||
|
||||
attrs.Deps = bazel.MakeLabelListAttribute(deps)
|
||||
depLabels.Deps = bazel.MakeLabelListAttribute(deps)
|
||||
depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
|
||||
|
||||
return attrs
|
||||
return commonAttrs, depLabels
|
||||
}
|
||||
|
||||
type javaLibraryAttributes struct {
|
||||
*javaCommonAttributes
|
||||
Deps bazel.LabelListAttribute
|
||||
Exports bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
|
||||
attrs := m.convertLibraryAttrsBp2Build(ctx)
|
||||
commonAttrs, depLabels := m.convertLibraryAttrsBp2Build(ctx)
|
||||
|
||||
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 !depLabels.Deps.IsEmpty() {
|
||||
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
|
||||
}
|
||||
|
||||
attrs := &javaLibraryAttributes{
|
||||
javaCommonAttributes: commonAttrs,
|
||||
Deps: deps,
|
||||
Exports: depLabels.StaticDeps,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "java_library",
|
||||
@@ -2092,15 +2130,30 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
|
||||
}
|
||||
|
||||
type javaBinaryHostAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Deps bazel.LabelListAttribute
|
||||
Main_class string
|
||||
Jvm_flags bazel.StringListAttribute
|
||||
Javacopts bazel.StringListAttribute
|
||||
*javaCommonAttributes
|
||||
Deps bazel.LabelListAttribute
|
||||
Runtime_deps bazel.LabelListAttribute
|
||||
Main_class string
|
||||
Jvm_flags bazel.StringListAttribute
|
||||
}
|
||||
|
||||
// JavaBinaryHostBp2Build is for java_binary_host bp2build.
|
||||
func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
||||
commonAttrs, depLabels := m.convertLibraryAttrsBp2Build(ctx)
|
||||
|
||||
deps := depLabels.Deps
|
||||
deps.Append(depLabels.StaticDeps)
|
||||
if m.binaryProperties.Jni_libs != nil {
|
||||
deps.Append(bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs)))
|
||||
}
|
||||
|
||||
var runtimeDeps bazel.LabelListAttribute
|
||||
if commonAttrs.Srcs.IsEmpty() {
|
||||
// if there are no sources, then the dependencies can only be used at runtime
|
||||
runtimeDeps = deps
|
||||
deps = bazel.LabelListAttribute{}
|
||||
}
|
||||
|
||||
mainClass := ""
|
||||
if m.binaryProperties.Main_class != nil {
|
||||
mainClass = *m.binaryProperties.Main_class
|
||||
@@ -2112,26 +2165,12 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
||||
}
|
||||
mainClass = mainClassInManifest
|
||||
}
|
||||
srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs))
|
||||
|
||||
attrs := &javaBinaryHostAttributes{
|
||||
Srcs: srcs,
|
||||
Main_class: mainClass,
|
||||
}
|
||||
|
||||
if m.properties.Javacflags != nil {
|
||||
attrs.Javacopts = bazel.MakeStringListAttribute(m.properties.Javacflags)
|
||||
}
|
||||
|
||||
// Attribute deps
|
||||
deps := []string{}
|
||||
if m.properties.Static_libs != nil {
|
||||
deps = append(deps, m.properties.Static_libs...)
|
||||
}
|
||||
if m.binaryProperties.Jni_libs != nil {
|
||||
deps = append(deps, m.binaryProperties.Jni_libs...)
|
||||
}
|
||||
if len(deps) > 0 {
|
||||
attrs.Deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, deps))
|
||||
javaCommonAttributes: commonAttrs,
|
||||
Deps: deps,
|
||||
Runtime_deps: runtimeDeps,
|
||||
Main_class: mainClass,
|
||||
}
|
||||
|
||||
// Attribute jvm_flags
|
||||
|
@@ -58,27 +58,32 @@ type PluginProperties struct {
|
||||
}
|
||||
|
||||
type pluginAttributes struct {
|
||||
*javaLibraryAttributes
|
||||
Processor_class *string
|
||||
Target_compatible_with bazel.LabelListAttribute
|
||||
*javaCommonAttributes
|
||||
Deps bazel.LabelListAttribute
|
||||
Processor_class *string
|
||||
}
|
||||
|
||||
// ConvertWithBp2build is used to convert android_app to Bazel.
|
||||
func (p *Plugin) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
libAttrs := p.convertLibraryAttrsBp2Build(ctx)
|
||||
attrs := &pluginAttributes{
|
||||
libAttrs,
|
||||
nil,
|
||||
bazel.LabelListAttribute{},
|
||||
pluginName := p.Name()
|
||||
commonAttrs, depLabels := p.convertLibraryAttrsBp2Build(ctx)
|
||||
|
||||
deps := depLabels.Deps
|
||||
deps.Append(depLabels.StaticDeps)
|
||||
|
||||
var processorClass *string
|
||||
if p.pluginProperties.Processor_class != nil {
|
||||
processorClass = p.pluginProperties.Processor_class
|
||||
}
|
||||
|
||||
if p.pluginProperties.Processor_class != nil {
|
||||
attrs.Processor_class = p.pluginProperties.Processor_class
|
||||
attrs := &pluginAttributes{
|
||||
javaCommonAttributes: commonAttrs,
|
||||
Deps: deps,
|
||||
Processor_class: processorClass,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "java_plugin",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: p.Name()}, attrs)
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: pluginName}, attrs)
|
||||
}
|
||||
|
Reference in New Issue
Block a user