diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 64 | 
1 files changed, 27 insertions, 37 deletions
| diff --git a/java/java.go b/java/java.go index a00e26f83..63c4416bc 100644 --- a/java/java.go +++ b/java/java.go @@ -2607,10 +2607,10 @@ func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorConte  type javaCommonAttributes struct {  	*javaResourcesAttributes -	Srcs        bazel.LabelListAttribute -	Plugins     bazel.LabelListAttribute -	Javacopts   bazel.StringListAttribute -	Common_srcs bazel.LabelListAttribute +	*kotlinAttributes +	Srcs      bazel.LabelListAttribute +	Plugins   bazel.LabelListAttribute +	Javacopts bazel.StringListAttribute  }  type javaDependencyLabels struct { @@ -2637,8 +2637,8 @@ type javaAidlLibraryAttributes struct {  // depending on the module type.  type bp2BuildJavaInfo struct {  	// separates dependencies into dynamic dependencies and static dependencies. -	DepLabels     *javaDependencyLabels -	hasKotlinSrcs bool +	DepLabels *javaDependencyLabels +	hasKotlin bool  }  // convertLibraryAttrsBp2Build returns a javaCommonAttributes struct with @@ -2785,9 +2785,17 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)  	depLabels.Deps = deps  	depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps) +	hasKotlin := !kotlinSrcs.IsEmpty() +	if len(m.properties.Common_srcs) != 0 { +		hasKotlin = true +		commonAttrs.kotlinAttributes = &kotlinAttributes{ +			bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)), +		} +	} +  	bp2BuildInfo := &bp2BuildJavaInfo{ -		DepLabels:     depLabels, -		hasKotlinSrcs: !kotlinSrcs.IsEmpty(), +		DepLabels: depLabels, +		hasKotlin: hasKotlin,  	}  	return commonAttrs, bp2BuildInfo @@ -2800,6 +2808,10 @@ type javaLibraryAttributes struct {  	Neverlink bazel.BoolAttribute  } +type kotlinAttributes struct { +	Common_srcs bazel.LabelListAttribute +} +  func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {  	commonAttrs, bp2BuildInfo := m.convertLibraryAttrsBp2Build(ctx)  	depLabels := bp2BuildInfo.DepLabels @@ -2828,17 +2840,15 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {  	}  	name := m.Name() -	if !bp2BuildInfo.hasKotlinSrcs && len(m.properties.Common_srcs) == 0 { +	if !bp2BuildInfo.hasKotlin {  		props = bazel.BazelTargetModuleProperties{  			Rule_class:        "java_library",  			Bzl_load_location: "//build/bazel/rules/java:library.bzl",  		}  	} else { -		attrs.javaCommonAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)) -  		props = bazel.BazelTargetModuleProperties{  			Rule_class:        "kt_jvm_library", -			Bzl_load_location: "@rules_kotlin//kotlin:jvm_library.bzl", +			Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl",  		}  	} @@ -2926,39 +2936,19 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {  		Jvm_flags:    jvmFlags,  	} -	if !bp2BuildInfo.hasKotlinSrcs && len(m.properties.Common_srcs) == 0 { +	if !bp2BuildInfo.hasKotlin {  		attrs.javaCommonAttributes = commonAttrs  		attrs.Deps = deps  	} else {  		ktName := m.Name() + "_kt"  		ktProps := bazel.BazelTargetModuleProperties{  			Rule_class:        "kt_jvm_library", -			Bzl_load_location: "@rules_kotlin//kotlin:jvm_library.bzl", -		} -		ktAttrs := &javaLibraryAttributes{ -			Deps: deps, -			javaCommonAttributes: &javaCommonAttributes{ -				Srcs:      commonAttrs.Srcs, -				Plugins:   commonAttrs.Plugins, -				Javacopts: commonAttrs.Javacopts, -			}, -		} - -		if len(m.properties.Common_srcs) != 0 { -			ktAttrs.javaCommonAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)) +			Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl",  		} -		// kt_jvm_library does not support resource_strip_prefix, if this attribute -		// is set, than javaResourcesAttributes needs to be set in the -		// javaCommonAttributes of the java_binary target -		if commonAttrs.javaResourcesAttributes != nil { -			if commonAttrs.javaResourcesAttributes.Resource_strip_prefix != nil { -				attrs.javaCommonAttributes = &javaCommonAttributes{ -					javaResourcesAttributes: commonAttrs.javaResourcesAttributes, -				} -			} else { -				ktAttrs.javaCommonAttributes.javaResourcesAttributes = commonAttrs.javaResourcesAttributes -			} +		ktAttrs := &javaLibraryAttributes{ +			Deps:                 deps, +			javaCommonAttributes: commonAttrs,  		}  		ctx.CreateBazelTargetModule(ktProps, android.CommonAttributes{Name: ktName}, ktAttrs) |