Remove ConvertWithBp2build implementations
Remove the ConvertWithBp2build implementations from all the module types, along with the related code. Bug: 315353489 Test: m blueprint_tests Change-Id: I212672286686a318893bc7348ddd5a5ec51e77a7
This commit is contained in:
parent
e51c6e4109
commit
8ff105860d
168 changed files with 64 additions and 39712 deletions
|
@ -11,7 +11,6 @@ bootstrap_go_package {
|
|||
"sbox_proto",
|
||||
"soong",
|
||||
"soong-android",
|
||||
"soong-bazel",
|
||||
],
|
||||
srcs: [
|
||||
"aconfig_declarations.go",
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
@ -27,7 +26,6 @@ import (
|
|||
type DeclarationsModule struct {
|
||||
android.ModuleBase
|
||||
android.DefaultableModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
// Properties for "aconfig_declarations"
|
||||
properties struct {
|
||||
|
@ -53,7 +51,6 @@ func DeclarationsFactory() android.Module {
|
|||
android.InitAndroidModule(module)
|
||||
android.InitDefaultableModule(module)
|
||||
module.AddProperties(&module.properties)
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
@ -232,26 +229,3 @@ func mergeAconfigFiles(ctx android.ModuleContext, inputs android.Paths) android.
|
|||
|
||||
return android.Paths{output}
|
||||
}
|
||||
|
||||
type bazelAconfigDeclarationsAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Package string
|
||||
}
|
||||
|
||||
func (module *DeclarationsModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
if ctx.ModuleType() != "aconfig_declarations" {
|
||||
return
|
||||
}
|
||||
srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, module.properties.Srcs))
|
||||
|
||||
attrs := bazelAconfigDeclarationsAttributes{
|
||||
Srcs: srcs,
|
||||
Package: module.properties.Package,
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "aconfig_declarations",
|
||||
Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_declarations.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package aconfig
|
|||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
|
@ -24,7 +23,6 @@ import (
|
|||
type ValueSetModule struct {
|
||||
android.ModuleBase
|
||||
android.DefaultableModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
properties struct {
|
||||
// aconfig_values modules
|
||||
|
@ -38,7 +36,6 @@ func ValueSetFactory() android.Module {
|
|||
android.InitAndroidModule(module)
|
||||
android.InitDefaultableModule(module)
|
||||
module.AddProperties(&module.properties)
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
@ -91,23 +88,3 @@ func (module *ValueSetModule) GenerateAndroidBuildActions(ctx android.ModuleCont
|
|||
AvailablePackages: packages,
|
||||
})
|
||||
}
|
||||
|
||||
type bazelAconfigValueSetAttributes struct {
|
||||
Values bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
func (module *ValueSetModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
if ctx.ModuleType() != "aconfig_value_set" {
|
||||
return
|
||||
}
|
||||
|
||||
attrs := bazelAconfigValueSetAttributes{
|
||||
Values: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, module.properties.Values)),
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "aconfig_value_set",
|
||||
Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_value_set.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package aconfig
|
|||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
|
@ -24,7 +23,6 @@ import (
|
|||
type ValuesModule struct {
|
||||
android.ModuleBase
|
||||
android.DefaultableModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
properties struct {
|
||||
// aconfig files, relative to this Android.bp file
|
||||
|
@ -41,7 +39,6 @@ func ValuesFactory() android.Module {
|
|||
android.InitAndroidModule(module)
|
||||
android.InitDefaultableModule(module)
|
||||
module.AddProperties(&module.properties)
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
@ -69,27 +66,3 @@ func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContex
|
|||
}
|
||||
ctx.SetProvider(valuesProviderKey, providerData)
|
||||
}
|
||||
|
||||
type bazelAconfigValuesAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Package string
|
||||
}
|
||||
|
||||
func (module *ValuesModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
if ctx.ModuleType() != "aconfig_values" {
|
||||
return
|
||||
}
|
||||
|
||||
srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, module.properties.Srcs))
|
||||
|
||||
attrs := bazelAconfigValuesAttributes{
|
||||
Srcs: srcs,
|
||||
Package: module.properties.Package,
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "aconfig_values",
|
||||
Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_values.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package codegen
|
|||
import (
|
||||
"android/soong/aconfig"
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/cc"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
|
@ -144,41 +143,3 @@ func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContex
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
type bazelCcAconfigLibraryAttributes struct {
|
||||
cc.SdkAttributes
|
||||
Aconfig_declarations bazel.LabelAttribute
|
||||
Dynamic_deps bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
// Convert the cc_aconfig_library module to bazel.
|
||||
//
|
||||
// This method is called from cc.ConvertWithBp2build to actually convert the
|
||||
// cc_aconfig_library module. This is necessary since the factory method of this
|
||||
// module type returns a cc library and the bp2build conversion is called on the
|
||||
// cc library type.
|
||||
|
||||
func (this *CcAconfigLibraryCallbacks) GeneratorBp2build(ctx android.Bp2buildMutatorContext, module *cc.Module) bool {
|
||||
if ctx.ModuleType() != "cc_aconfig_library" {
|
||||
return false
|
||||
}
|
||||
|
||||
attrs := bazelCcAconfigLibraryAttributes{
|
||||
SdkAttributes: cc.Bp2BuildParseSdkAttributes(module),
|
||||
Aconfig_declarations: *bazel.MakeLabelAttribute(android.BazelLabelForModuleDepSingle(ctx, this.properties.Aconfig_declarations).Label),
|
||||
Dynamic_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, []string{baseLibDep})),
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_aconfig_library",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_aconfig_library.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
android.CommonAttributes{
|
||||
Name: ctx.ModuleName(),
|
||||
Tags: android.ApexAvailableTagsWithoutTestApexes(ctx, module),
|
||||
},
|
||||
&attrs)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
|
||||
"android/soong/aconfig"
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/java"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
|
@ -101,56 +100,3 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuild
|
|||
func isModeSupported(mode string) bool {
|
||||
return android.InList(mode, aconfigSupportedModes)
|
||||
}
|
||||
|
||||
type bazelJavaAconfigLibraryAttributes struct {
|
||||
Aconfig_declarations bazel.LabelAttribute
|
||||
Sdk_version *string
|
||||
Libs bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) Bp2build(ctx android.Bp2buildMutatorContext, module *java.GeneratedJavaLibraryModule) {
|
||||
if ctx.ModuleType() != "java_aconfig_library" {
|
||||
return
|
||||
}
|
||||
|
||||
// By default, soong builds the aconfig java library with private_current, however
|
||||
// bazel currently doesn't support it so we default it to system_current. One reason
|
||||
// is that the dependency of all java_aconfig_library aconfig-annotations-lib is
|
||||
// built with system_current. For the java aconfig library itself it doesn't really
|
||||
// matter whether it uses private API or system API because the only module it uses
|
||||
// is DeviceConfig which is in system, and the rdeps of the java aconfig library
|
||||
// won't change its sdk version either, so this should be fine.
|
||||
// Ideally we should only use the default value if it is not set by the user, but
|
||||
// bazel only supports a limited sdk versions, for example, the java_aconfig_library
|
||||
// modules in framework/base use core_platform which is not supported by bazel yet.
|
||||
// TODO(b/302148527): change soong to default to system_current as well.
|
||||
sdkVersion := "system_current"
|
||||
|
||||
var libs bazel.LabelListAttribute
|
||||
archVariantProps := module.GetArchVariantProperties(ctx, &java.CommonProperties{})
|
||||
for axis, configToProps := range archVariantProps {
|
||||
for config, p := range configToProps {
|
||||
if archProps, ok := p.(*java.CommonProperties); ok {
|
||||
var libLabels []bazel.Label
|
||||
for _, d := range archProps.Libs {
|
||||
neverlinkLabel := android.BazelLabelForModuleDepSingle(ctx, d)
|
||||
neverlinkLabel.Label = neverlinkLabel.Label + "-neverlink"
|
||||
libLabels = append(libLabels, neverlinkLabel)
|
||||
}
|
||||
libs.SetSelectValue(axis, config, (bazel.MakeLabelList(libLabels)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attrs := bazelJavaAconfigLibraryAttributes{
|
||||
Aconfig_declarations: *bazel.MakeLabelAttribute(android.BazelLabelForModuleDepSingle(ctx, callbacks.properties.Aconfig_declarations).Label),
|
||||
Sdk_version: &sdkVersion,
|
||||
Libs: libs,
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "java_aconfig_library",
|
||||
Bzl_load_location: "//build/bazel/rules/java:java_aconfig_library.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: ctx.ModuleName()}, &attrs)
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ package aidl_library
|
|||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
@ -53,57 +51,9 @@ type aidlLibraryProperties struct {
|
|||
|
||||
type AidlLibrary struct {
|
||||
android.ModuleBase
|
||||
android.BazelModuleBase
|
||||
properties aidlLibraryProperties
|
||||
}
|
||||
|
||||
type bazelAidlLibraryAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Hdrs bazel.LabelListAttribute
|
||||
Strip_import_prefix *string
|
||||
Deps bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
func (lib *AidlLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
srcs := bazel.MakeLabelListAttribute(
|
||||
android.BazelLabelForModuleSrc(
|
||||
ctx,
|
||||
lib.properties.Srcs,
|
||||
),
|
||||
)
|
||||
|
||||
hdrs := bazel.MakeLabelListAttribute(
|
||||
android.BazelLabelForModuleSrc(
|
||||
ctx,
|
||||
lib.properties.Hdrs,
|
||||
),
|
||||
)
|
||||
|
||||
tags := []string{"apex_available=//apex_available:anyapex"}
|
||||
deps := bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, lib.properties.Deps))
|
||||
|
||||
attrs := &bazelAidlLibraryAttributes{
|
||||
Srcs: srcs,
|
||||
Hdrs: hdrs,
|
||||
Strip_import_prefix: lib.properties.Strip_import_prefix,
|
||||
Deps: deps,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "aidl_library",
|
||||
Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
android.CommonAttributes{
|
||||
Name: lib.Name(),
|
||||
Tags: bazel.MakeStringListAttribute(tags),
|
||||
},
|
||||
attrs,
|
||||
)
|
||||
}
|
||||
|
||||
type AidlLibraryInfo struct {
|
||||
// The direct aidl files of the module
|
||||
Srcs android.Paths
|
||||
|
@ -170,7 +120,6 @@ func AidlLibraryFactory() android.Module {
|
|||
module := &AidlLibrary{}
|
||||
module.AddProperties(&module.properties)
|
||||
android.InitAndroidModule(module)
|
||||
android.InitBazelModule(module)
|
||||
return module
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ package android
|
|||
import (
|
||||
"reflect"
|
||||
|
||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
@ -118,11 +117,6 @@ type DefaultsVisibilityProperties struct {
|
|||
|
||||
type DefaultsModuleBase struct {
|
||||
DefaultableModuleBase
|
||||
|
||||
// Included to support setting bazel_module.label for multiple Soong modules to the same Bazel
|
||||
// target. This is primarily useful for modules that were architecture specific and instead are
|
||||
// handled in Bazel as a select().
|
||||
BazelModuleBase
|
||||
}
|
||||
|
||||
// The common pattern for defaults modules is to register separate instances of
|
||||
|
@ -165,7 +159,6 @@ func (d *DefaultsModuleBase) isDefaults() bool {
|
|||
type DefaultsModule interface {
|
||||
Module
|
||||
Defaults
|
||||
Bazelable
|
||||
}
|
||||
|
||||
func (d *DefaultsModuleBase) properties() []interface{} {
|
||||
|
@ -178,13 +171,6 @@ func (d *DefaultsModuleBase) productVariableProperties() interface{} {
|
|||
|
||||
func (d *DefaultsModuleBase) GenerateAndroidBuildActions(ctx ModuleContext) {}
|
||||
|
||||
// ConvertWithBp2build to fulfill Bazelable interface; however, at this time defaults module are
|
||||
// *NOT* converted with bp2build
|
||||
func (defaultable *DefaultsModuleBase) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
// Defaults types are never convertible.
|
||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
|
||||
}
|
||||
|
||||
func InitDefaultsModule(module DefaultsModule) {
|
||||
commonProperties := &commonProperties{}
|
||||
|
||||
|
@ -194,8 +180,6 @@ func InitDefaultsModule(module DefaultsModule) {
|
|||
&ApexProperties{},
|
||||
&distProperties{})
|
||||
|
||||
// Bazel module must be initialized _before_ Defaults to be included in cc_defaults module.
|
||||
InitBazelModule(module)
|
||||
initAndroidModuleBase(module)
|
||||
initProductVariableModule(module)
|
||||
initArchModule(module)
|
||||
|
@ -225,60 +209,10 @@ func InitDefaultsModule(module DefaultsModule) {
|
|||
|
||||
var _ Defaults = (*DefaultsModuleBase)(nil)
|
||||
|
||||
// applyNamespacedVariableDefaults only runs in bp2build mode for
|
||||
// defaultable/defaults modules. Its purpose is to merge namespaced product
|
||||
// variable props from defaults deps, even if those defaults are custom module
|
||||
// types created from soong_config_module_type, e.g. one that's wrapping a
|
||||
// cc_defaults or java_defaults.
|
||||
func applyNamespacedVariableDefaults(defaultDep Defaults, ctx TopDownMutatorContext) {
|
||||
var dep, b Bazelable
|
||||
|
||||
dep, ok := defaultDep.(Bazelable)
|
||||
if !ok {
|
||||
if depMod, ok := defaultDep.(Module); ok {
|
||||
// Track that this dependency hasn't been converted to bp2build yet.
|
||||
ctx.AddUnconvertedBp2buildDep(depMod.Name())
|
||||
return
|
||||
} else {
|
||||
panic("Expected default dep to be a Module.")
|
||||
}
|
||||
}
|
||||
|
||||
b, ok = ctx.Module().(Bazelable)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// namespacedVariableProps is a map from namespaces (e.g. acme, android,
|
||||
// vendor_foo) to a slice of soong_config_variable struct pointers,
|
||||
// containing properties for that particular module.
|
||||
src := dep.namespacedVariableProps()
|
||||
dst := b.namespacedVariableProps()
|
||||
if dst == nil {
|
||||
dst = make(namespacedVariableProperties)
|
||||
}
|
||||
|
||||
// Propagate all soong_config_variable structs from the dep. We'll merge the
|
||||
// actual property values later in variable.go.
|
||||
for namespace := range src {
|
||||
if dst[namespace] == nil {
|
||||
dst[namespace] = []interface{}{}
|
||||
}
|
||||
for _, i := range src[namespace] {
|
||||
dst[namespace] = append(dst[namespace], i)
|
||||
}
|
||||
}
|
||||
|
||||
b.setNamespacedVariableProps(dst)
|
||||
}
|
||||
|
||||
func (defaultable *DefaultableModuleBase) applyDefaults(ctx TopDownMutatorContext,
|
||||
defaultsList []Defaults) {
|
||||
|
||||
for _, defaults := range defaultsList {
|
||||
if ctx.Config().BuildMode == Bp2build {
|
||||
applyNamespacedVariableDefaults(defaults, ctx)
|
||||
}
|
||||
for _, prop := range defaultable.defaultableProperties {
|
||||
if prop == defaultable.defaultableVariableProperties {
|
||||
defaultable.applyDefaultVariableProperties(ctx, defaults, prop)
|
||||
|
|
|
@ -15,15 +15,9 @@
|
|||
package android
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -39,181 +33,6 @@ func RegisterFilegroupBuildComponents(ctx RegistrationContext) {
|
|||
ctx.RegisterModuleType("filegroup_defaults", FileGroupDefaultsFactory)
|
||||
}
|
||||
|
||||
var convertedProtoLibrarySuffix = "_bp2build_converted"
|
||||
|
||||
// IsFilegroup checks that a module is a filegroup type
|
||||
func IsFilegroup(ctx bazel.OtherModuleContext, m blueprint.Module) bool {
|
||||
return ctx.OtherModuleType(m) == "filegroup"
|
||||
}
|
||||
|
||||
var (
|
||||
// ignoring case, checks for proto or protos as an independent word in the name, whether at the
|
||||
// beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
|
||||
filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")
|
||||
filegroupLikelyAidlPattern = regexp.MustCompile("(?i)(^|[^a-z])aidl(s)?([^a-z]|$)")
|
||||
|
||||
ProtoSrcLabelPartition = bazel.LabelPartition{
|
||||
Extensions: []string{".proto"},
|
||||
LabelMapper: isFilegroupWithPattern(filegroupLikelyProtoPattern),
|
||||
}
|
||||
AidlSrcLabelPartition = bazel.LabelPartition{
|
||||
Extensions: []string{".aidl"},
|
||||
LabelMapper: isFilegroupWithPattern(filegroupLikelyAidlPattern),
|
||||
}
|
||||
)
|
||||
|
||||
func isFilegroupWithPattern(pattern *regexp.Regexp) bazel.LabelMapper {
|
||||
return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
|
||||
m, exists := ctx.ModuleFromName(label.OriginalModuleName)
|
||||
labelStr := label.Label
|
||||
if !exists || !IsFilegroup(ctx, m) {
|
||||
return labelStr, false
|
||||
}
|
||||
likelyMatched := pattern.MatchString(label.OriginalModuleName)
|
||||
return labelStr, likelyMatched
|
||||
}
|
||||
}
|
||||
|
||||
// https://docs.bazel.build/versions/master/be/general.html#filegroup
|
||||
type bazelFilegroupAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Applicable_licenses bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
type bazelAidlLibraryAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Strip_import_prefix *string
|
||||
}
|
||||
|
||||
// ConvertWithBp2build performs bp2build conversion of filegroup
|
||||
func (fg *fileGroup) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
srcs := bazel.MakeLabelListAttribute(
|
||||
BazelLabelForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs))
|
||||
|
||||
// For Bazel compatibility, don't generate the filegroup if there is only 1
|
||||
// source file, and that the source file is named the same as the module
|
||||
// itself. In Bazel, eponymous filegroups like this would be an error.
|
||||
//
|
||||
// Instead, dependents on this single-file filegroup can just depend
|
||||
// on the file target, instead of rule target, directly.
|
||||
//
|
||||
// You may ask: what if a filegroup has multiple files, and one of them
|
||||
// shares the name? The answer: we haven't seen that in the wild, and
|
||||
// should lock Soong itself down to prevent the behavior. For now,
|
||||
// we raise an error if bp2build sees this problem.
|
||||
for _, f := range srcs.Value.Includes {
|
||||
if f.Label == fg.Name() {
|
||||
if len(srcs.Value.Includes) > 1 {
|
||||
ctx.ModuleErrorf("filegroup '%s' cannot contain a file with the same name", fg.Name())
|
||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_SRC_NAME_COLLISION, "")
|
||||
} else {
|
||||
panic("This situation should have been handled by FileGroupFactory's call to InitBazelModuleAsHandcrafted")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Convert module that has only AIDL files to aidl_library
|
||||
// If the module has a mixed bag of AIDL and non-AIDL files, split the filegroup manually
|
||||
// and then convert
|
||||
if fg.ShouldConvertToAidlLibrary(ctx) {
|
||||
tags := []string{"apex_available=//apex_available:anyapex"}
|
||||
attrs := &bazelAidlLibraryAttributes{
|
||||
Srcs: srcs,
|
||||
Strip_import_prefix: fg.properties.Path,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "aidl_library",
|
||||
Bzl_load_location: "//build/bazel/rules/aidl:aidl_library.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
CommonAttributes{
|
||||
Name: fg.Name(),
|
||||
Tags: bazel.MakeStringListAttribute(tags),
|
||||
},
|
||||
attrs)
|
||||
} else {
|
||||
if fg.ShouldConvertToProtoLibrary(ctx) {
|
||||
pkgToSrcs := partitionSrcsByPackage(ctx.ModuleDir(), bazel.MakeLabelList(srcs.Value.Includes))
|
||||
if len(pkgToSrcs) > 1 {
|
||||
ctx.ModuleErrorf("TODO: Add bp2build support for multiple package .protosrcs in filegroup")
|
||||
return
|
||||
}
|
||||
pkg := SortedKeys(pkgToSrcs)[0]
|
||||
attrs := &ProtoAttrs{
|
||||
Srcs: bazel.MakeLabelListAttribute(pkgToSrcs[pkg]),
|
||||
Strip_import_prefix: fg.properties.Path,
|
||||
}
|
||||
|
||||
tags := []string{
|
||||
"apex_available=//apex_available:anyapex",
|
||||
// TODO(b/246997908): we can remove this tag if we could figure out a solution for this bug.
|
||||
"manual",
|
||||
}
|
||||
if pkg != ctx.ModuleDir() {
|
||||
// Since we are creating the proto_library in a subpackage, create an import_prefix relative to the current package
|
||||
if rel, err := filepath.Rel(ctx.ModuleDir(), pkg); err != nil {
|
||||
ctx.ModuleErrorf("Could not get relative path for %v %v", pkg, err)
|
||||
} else if rel != "." {
|
||||
attrs.Import_prefix = &rel
|
||||
// Strip the package prefix
|
||||
attrs.Strip_import_prefix = proptools.StringPtr("")
|
||||
}
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
||||
CommonAttributes{
|
||||
Name: fg.Name() + "_proto",
|
||||
Dir: proptools.StringPtr(pkg),
|
||||
Tags: bazel.MakeStringListAttribute(tags),
|
||||
},
|
||||
attrs)
|
||||
|
||||
// Create an alias in the current dir. The actual target might exist in a different package, but rdeps
|
||||
// can reliabily use this alias
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{Rule_class: "alias"},
|
||||
CommonAttributes{
|
||||
Name: fg.Name() + convertedProtoLibrarySuffix,
|
||||
// TODO(b/246997908): we can remove this tag if we could figure out a solution for this bug.
|
||||
Tags: bazel.MakeStringListAttribute(tags),
|
||||
},
|
||||
&bazelAliasAttributes{
|
||||
Actual: bazel.MakeLabelAttribute("//" + pkg + ":" + fg.Name() + "_proto"),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// TODO(b/242847534): Still convert to a filegroup because other unconverted
|
||||
// modules may depend on the filegroup
|
||||
attrs := &bazelFilegroupAttributes{
|
||||
Srcs: srcs,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "filegroup",
|
||||
Bzl_load_location: "//build/bazel/rules:filegroup.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, CommonAttributes{Name: fg.Name()}, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
type FileGroupPath interface {
|
||||
GetPath(ctx Bp2buildMutatorContext) string
|
||||
}
|
||||
|
||||
func (fg *fileGroup) GetPath(ctx Bp2buildMutatorContext) string {
|
||||
if fg.properties.Path != nil {
|
||||
return *fg.properties.Path
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type fileGroupProperties struct {
|
||||
// srcs lists files that will be included in this filegroup
|
||||
Srcs []string `android:"path"`
|
||||
|
@ -233,18 +52,12 @@ type fileGroupProperties struct {
|
|||
|
||||
type fileGroup struct {
|
||||
ModuleBase
|
||||
BazelModuleBase
|
||||
DefaultableModuleBase
|
||||
FileGroupAsLibrary
|
||||
FileGroupPath
|
||||
properties fileGroupProperties
|
||||
srcs Paths
|
||||
}
|
||||
|
||||
var _ MixedBuildBuildable = (*fileGroup)(nil)
|
||||
var _ SourceFileProducer = (*fileGroup)(nil)
|
||||
var _ FileGroupAsLibrary = (*fileGroup)(nil)
|
||||
var _ FileGroupPath = (*fileGroup)(nil)
|
||||
|
||||
// filegroup contains a list of files that are referenced by other modules
|
||||
// properties (such as "srcs") using the syntax ":<name>". filegroup are
|
||||
|
@ -253,17 +66,6 @@ func FileGroupFactory() Module {
|
|||
module := &fileGroup{}
|
||||
module.AddProperties(&module.properties)
|
||||
InitAndroidModule(module)
|
||||
InitBazelModule(module)
|
||||
AddBazelHandcraftedHook(module, func(ctx LoadHookContext) string {
|
||||
// If there is a single src with the same name as the filegroup module name,
|
||||
// then don't generate this filegroup. It will be OK for other targets
|
||||
// to depend on this source file by name directly.
|
||||
fg := ctx.Module().(*fileGroup)
|
||||
if len(fg.properties.Srcs) == 1 && fg.Name() == fg.properties.Srcs[0] {
|
||||
return fg.Name()
|
||||
}
|
||||
return ""
|
||||
})
|
||||
InitDefaultableModule(module)
|
||||
return module
|
||||
}
|
||||
|
@ -303,101 +105,6 @@ func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) {
|
|||
}
|
||||
}
|
||||
|
||||
func (fg *fileGroup) QueueBazelCall(ctx BaseModuleContext) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
|
||||
bazelCtx.QueueBazelRequest(
|
||||
fg.GetBazelLabel(ctx, fg),
|
||||
cquery.GetOutputFiles,
|
||||
configKey{arch: Common.String(), osType: CommonOS})
|
||||
}
|
||||
|
||||
func (fg *fileGroup) IsMixedBuildSupported(ctx BaseModuleContext) bool {
|
||||
// TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups
|
||||
return false
|
||||
}
|
||||
|
||||
func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
// This is a short-term solution because we rely on info from Android.bp to handle
|
||||
// a converted module. This will block when we want to remove Android.bp for all
|
||||
// converted modules at some point.
|
||||
// TODO(b/242847534): Implement a long-term solution in which we don't need to rely
|
||||
// on info form Android.bp for modules that are already converted to Bazel
|
||||
relativeRoot := ctx.ModuleDir()
|
||||
if fg.properties.Path != nil {
|
||||
relativeRoot = filepath.Join(relativeRoot, *fg.properties.Path)
|
||||
}
|
||||
|
||||
filePaths, err := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), configKey{arch: Common.String(), osType: CommonOS})
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
bazelOuts := make(Paths, 0, len(filePaths))
|
||||
for _, p := range filePaths {
|
||||
bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, relativeRoot, p))
|
||||
}
|
||||
fg.srcs = bazelOuts
|
||||
}
|
||||
|
||||
func (fg *fileGroup) ShouldConvertToAidlLibrary(ctx BazelConversionPathContext) bool {
|
||||
return fg.shouldConvertToLibrary(ctx, ".aidl")
|
||||
}
|
||||
|
||||
func (fg *fileGroup) ShouldConvertToProtoLibrary(ctx BazelConversionPathContext) bool {
|
||||
return fg.shouldConvertToLibrary(ctx, ".proto")
|
||||
}
|
||||
|
||||
func (fg *fileGroup) shouldConvertToLibrary(ctx BazelConversionPathContext, suffix string) bool {
|
||||
if len(fg.properties.Srcs) == 0 || !fg.ShouldConvertWithBp2build(ctx) {
|
||||
return false
|
||||
}
|
||||
for _, src := range fg.properties.Srcs {
|
||||
if !strings.HasSuffix(src, suffix) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (fg *fileGroup) GetAidlLibraryLabel(ctx BazelConversionPathContext) string {
|
||||
return fg.getFileGroupAsLibraryLabel(ctx)
|
||||
}
|
||||
|
||||
func (fg *fileGroup) GetProtoLibraryLabel(ctx BazelConversionPathContext) string {
|
||||
return fg.getFileGroupAsLibraryLabel(ctx) + convertedProtoLibrarySuffix
|
||||
}
|
||||
|
||||
func (fg *fileGroup) getFileGroupAsLibraryLabel(ctx BazelConversionPathContext) string {
|
||||
if ctx.OtherModuleDir(fg.module) == ctx.ModuleDir() {
|
||||
return ":" + fg.Name()
|
||||
} else {
|
||||
return fg.GetBazelLabel(ctx, fg)
|
||||
}
|
||||
}
|
||||
|
||||
// Given a name in srcs prop, check to see if the name references a filegroup
|
||||
// and the filegroup is converted to aidl_library
|
||||
func IsConvertedToAidlLibrary(ctx BazelConversionPathContext, name string) bool {
|
||||
if fg, ok := ToFileGroupAsLibrary(ctx, name); ok {
|
||||
return fg.ShouldConvertToAidlLibrary(ctx)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ToFileGroupAsLibrary(ctx BazelConversionPathContext, name string) (FileGroupAsLibrary, bool) {
|
||||
if module, ok := ctx.ModuleFromName(name); ok {
|
||||
if IsFilegroup(ctx, module) {
|
||||
if fg, ok := module.(FileGroupAsLibrary); ok {
|
||||
return fg, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// Defaults
|
||||
type FileGroupDefaults struct {
|
||||
ModuleBase
|
||||
|
|
|
@ -40,17 +40,8 @@ func TestFileGroupWithPathProp(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
outBaseDir := "outputbase"
|
||||
result := GroupFixturePreparers(
|
||||
PrepareForTestWithFilegroup,
|
||||
FixtureModifyConfig(func(config Config) {
|
||||
config.BazelContext = MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToOutputFiles: map[string][]string{
|
||||
"//:baz": []string{"a/b/c/d/test.aidl"},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, testCase.bp)
|
||||
|
||||
fg := result.Module("baz", "").(*fileGroup)
|
||||
|
|
|
@ -15,12 +15,7 @@
|
|||
package android
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
|
||||
"android/soong/bazel"
|
||||
)
|
||||
|
||||
type licenseKindDependencyTag struct {
|
||||
|
@ -53,54 +48,13 @@ type licenseProperties struct {
|
|||
Visibility []string
|
||||
}
|
||||
|
||||
var _ Bazelable = &licenseModule{}
|
||||
|
||||
type licenseModule struct {
|
||||
ModuleBase
|
||||
DefaultableModuleBase
|
||||
BazelModuleBase
|
||||
|
||||
properties licenseProperties
|
||||
}
|
||||
|
||||
type bazelLicenseAttributes struct {
|
||||
License_kinds []string
|
||||
Copyright_notice *string
|
||||
License_text bazel.LabelAttribute
|
||||
Package_name *string
|
||||
Visibility []string
|
||||
}
|
||||
|
||||
func (m *licenseModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
attrs := &bazelLicenseAttributes{
|
||||
License_kinds: m.properties.License_kinds,
|
||||
Copyright_notice: m.properties.Copyright_notice,
|
||||
Package_name: m.properties.Package_name,
|
||||
Visibility: m.properties.Visibility,
|
||||
}
|
||||
|
||||
// TODO(asmundak): Soong supports multiple license texts while Bazel's license
|
||||
// rule does not. Have android_license create a genrule to concatenate multiple
|
||||
// license texts.
|
||||
if len(m.properties.License_text) > 1 && ctx.Config().IsEnvTrue("BP2BUILD_VERBOSE") {
|
||||
fmt.Fprintf(os.Stderr, "warning: using only the first license_text item from //%s:%s\n",
|
||||
ctx.ModuleDir(), m.Name())
|
||||
}
|
||||
if len(m.properties.License_text) >= 1 {
|
||||
attrs.License_text.SetValue(BazelLabelForModuleSrcSingle(ctx, m.properties.License_text[0]))
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "android_license",
|
||||
Bzl_load_location: "//build/bazel/rules/license:license.bzl",
|
||||
},
|
||||
CommonAttributes{
|
||||
Name: m.Name(),
|
||||
},
|
||||
attrs)
|
||||
}
|
||||
|
||||
func (m *licenseModule) DepsMutator(ctx BottomUpMutatorContext) {
|
||||
for i, license := range m.properties.License_kinds {
|
||||
for j := i + 1; j < len(m.properties.License_kinds); j++ {
|
||||
|
@ -131,14 +85,13 @@ func LicenseFactory() Module {
|
|||
module := &licenseModule{}
|
||||
|
||||
base := module.base()
|
||||
module.AddProperties(&base.nameProperties, &module.properties, &base.commonProperties.BazelConversionStatus)
|
||||
module.AddProperties(&base.nameProperties, &module.properties)
|
||||
|
||||
// The visibility property needs to be checked and parsed by the visibility module.
|
||||
setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility)
|
||||
|
||||
initAndroidModuleBase(module)
|
||||
InitDefaultableModule(module)
|
||||
InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
package android
|
||||
|
||||
import "android/soong/bazel"
|
||||
|
||||
func init() {
|
||||
RegisterLicenseKindBuildComponents(InitRegistrationContext)
|
||||
}
|
||||
|
@ -34,39 +32,13 @@ type licenseKindProperties struct {
|
|||
Visibility []string
|
||||
}
|
||||
|
||||
var _ Bazelable = &licenseKindModule{}
|
||||
|
||||
type licenseKindModule struct {
|
||||
ModuleBase
|
||||
DefaultableModuleBase
|
||||
BazelModuleBase
|
||||
|
||||
properties licenseKindProperties
|
||||
}
|
||||
|
||||
type bazelLicenseKindAttributes struct {
|
||||
Conditions []string
|
||||
Url string
|
||||
Visibility []string
|
||||
}
|
||||
|
||||
func (m *licenseKindModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
attrs := &bazelLicenseKindAttributes{
|
||||
Conditions: m.properties.Conditions,
|
||||
Url: m.properties.Url,
|
||||
Visibility: m.properties.Visibility,
|
||||
}
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "license_kind",
|
||||
Bzl_load_location: "@rules_license//rules:license_kind.bzl",
|
||||
},
|
||||
CommonAttributes{
|
||||
Name: m.Name(),
|
||||
},
|
||||
attrs)
|
||||
}
|
||||
|
||||
func (m *licenseKindModule) DepsMutator(ctx BottomUpMutatorContext) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
@ -79,14 +51,13 @@ func LicenseKindFactory() Module {
|
|||
module := &licenseKindModule{}
|
||||
|
||||
base := module.base()
|
||||
module.AddProperties(&base.nameProperties, &module.properties, &base.commonProperties.BazelConversionStatus)
|
||||
module.AddProperties(&base.nameProperties, &module.properties)
|
||||
|
||||
// The visibility property needs to be checked and parsed by the visibility module.
|
||||
setPrimaryVisibilityProperty(module, "visibility", &module.properties.Visibility)
|
||||
|
||||
initAndroidModuleBase(module)
|
||||
InitDefaultableModule(module)
|
||||
InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
package android
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"android/soong/bazel"
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
@ -40,52 +37,12 @@ type packageProperties struct {
|
|||
Default_applicable_licenses []string
|
||||
}
|
||||
|
||||
type bazelPackageAttributes struct {
|
||||
Default_visibility []string
|
||||
Default_package_metadata bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
type packageModule struct {
|
||||
ModuleBase
|
||||
BazelModuleBase
|
||||
|
||||
properties packageProperties
|
||||
}
|
||||
|
||||
var _ Bazelable = &packageModule{}
|
||||
|
||||
func (p *packageModule) ConvertWithBp2build(ctx Bp2buildMutatorContext) {
|
||||
defaultPackageMetadata := bazel.MakeLabelListAttribute(BazelLabelForModuleDeps(ctx, p.properties.Default_applicable_licenses))
|
||||
// If METADATA file exists in the package, add it to package(default_package_metadata=) using a
|
||||
// filegroup(name="default_metadata_file") which can be accessed later on each module in Bazel
|
||||
// using attribute "applicable_licenses".
|
||||
// Attribute applicable_licenses of filegroup "default_metadata_file" has to be set to [],
|
||||
// otherwise Bazel reports cyclic reference error.
|
||||
if existed, _, _ := ctx.Config().fs.Exists(filepath.Join(ctx.ModuleDir(), "METADATA")); existed {
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "filegroup",
|
||||
},
|
||||
CommonAttributes{Name: "default_metadata_file"},
|
||||
&bazelFilegroupAttributes{
|
||||
Srcs: bazel.MakeLabelListAttribute(BazelLabelForModuleSrc(ctx, []string{"METADATA"})),
|
||||
Applicable_licenses: bazel.LabelListAttribute{Value: bazel.LabelList{Includes: []bazel.Label{}}, EmitEmptyList: true},
|
||||
})
|
||||
defaultPackageMetadata.Value.Add(&bazel.Label{Label: ":default_metadata_file"})
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "package",
|
||||
},
|
||||
CommonAttributes{},
|
||||
&bazelPackageAttributes{
|
||||
Default_package_metadata: defaultPackageMetadata,
|
||||
// FIXME(asmundak): once b/221436821 is resolved
|
||||
Default_visibility: []string{"//visibility:public"},
|
||||
})
|
||||
}
|
||||
|
||||
func (p *packageModule) GenerateAndroidBuildActions(ModuleContext) {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
@ -102,7 +59,7 @@ func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModule
|
|||
func PackageFactory() Module {
|
||||
module := &packageModule{}
|
||||
|
||||
module.AddProperties(&module.properties, &module.commonProperties.BazelConversionStatus)
|
||||
module.AddProperties(&module.properties)
|
||||
|
||||
// The name is the relative path from build root to the directory containing this
|
||||
// module. Set that name at the earliest possible moment that information is available
|
||||
|
@ -119,7 +76,5 @@ func PackageFactory() Module {
|
|||
// its checking and parsing phases so make it the primary licenses property.
|
||||
setPrimaryLicensesProperty(module, "default_applicable_licenses", &module.properties.Default_applicable_licenses)
|
||||
|
||||
InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
|
279
android/proto.go
279
android/proto.go
|
@ -15,11 +15,7 @@
|
|||
package android
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"android/soong/bazel"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
@ -154,278 +150,3 @@ func ProtoRule(rule *RuleBuilder, protoFile Path, flags ProtoFlags, deps Paths,
|
|||
rule.Command().
|
||||
BuiltTool("dep_fixer").Flag(depFile.String())
|
||||
}
|
||||
|
||||
// Bp2buildProtoInfo contains information necessary to pass on to language specific conversion.
|
||||
type Bp2buildProtoInfo struct {
|
||||
Type *string
|
||||
Proto_libs bazel.LabelList
|
||||
Transitive_proto_libs bazel.LabelList
|
||||
}
|
||||
|
||||
type ProtoAttrs struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Import_prefix *string
|
||||
Strip_import_prefix *string
|
||||
Deps bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
// For each package in the include_dirs property a proto_library target should
|
||||
// be added to the BUILD file in that package and a mapping should be added here
|
||||
var includeDirsToProtoDeps = map[string]string{
|
||||
"external/protobuf/src": "//external/protobuf:libprotobuf-proto",
|
||||
}
|
||||
|
||||
// Partitions srcs by the pkg it is in
|
||||
// srcs has been created using `TransformSubpackagePaths`
|
||||
// This function uses existence of Android.bp/BUILD files to create a label that is compatible with the package structure of bp2build workspace
|
||||
func partitionSrcsByPackage(currentDir string, srcs bazel.LabelList) map[string]bazel.LabelList {
|
||||
getPackageFromLabel := func(label string) string {
|
||||
// Remove any preceding //
|
||||
label = strings.TrimPrefix(label, "//")
|
||||
split := strings.Split(label, ":")
|
||||
if len(split) == 1 {
|
||||
// e.g. foo.proto
|
||||
return currentDir
|
||||
} else if split[0] == "" {
|
||||
// e.g. :foo.proto
|
||||
return currentDir
|
||||
} else {
|
||||
return split[0]
|
||||
}
|
||||
}
|
||||
|
||||
pkgToSrcs := map[string]bazel.LabelList{}
|
||||
for _, src := range srcs.Includes {
|
||||
pkg := getPackageFromLabel(src.Label)
|
||||
list := pkgToSrcs[pkg]
|
||||
list.Add(&src)
|
||||
pkgToSrcs[pkg] = list
|
||||
}
|
||||
return pkgToSrcs
|
||||
}
|
||||
|
||||
// Bp2buildProtoProperties converts proto properties, creating a proto_library and returning the
|
||||
// information necessary for language-specific handling.
|
||||
func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs bazel.LabelListAttribute) (Bp2buildProtoInfo, bool) {
|
||||
var info Bp2buildProtoInfo
|
||||
if srcs.IsEmpty() {
|
||||
return info, false
|
||||
}
|
||||
|
||||
var protoLibraries bazel.LabelList
|
||||
var transitiveProtoLibraries bazel.LabelList
|
||||
var directProtoSrcs bazel.LabelList
|
||||
|
||||
// For filegroups that should be converted to proto_library just collect the
|
||||
// labels of converted proto_library targets.
|
||||
for _, protoSrc := range srcs.Value.Includes {
|
||||
src := protoSrc.OriginalModuleName
|
||||
if fg, ok := ToFileGroupAsLibrary(ctx, src); ok &&
|
||||
fg.ShouldConvertToProtoLibrary(ctx) {
|
||||
protoLibraries.Add(&bazel.Label{
|
||||
Label: fg.GetProtoLibraryLabel(ctx),
|
||||
})
|
||||
} else {
|
||||
directProtoSrcs.Add(&protoSrc)
|
||||
}
|
||||
}
|
||||
|
||||
name := m.Name() + "_proto"
|
||||
|
||||
depsFromFilegroup := protoLibraries
|
||||
var canonicalPathFromRoot bool
|
||||
|
||||
if len(directProtoSrcs.Includes) > 0 {
|
||||
pkgToSrcs := partitionSrcsByPackage(ctx.ModuleDir(), directProtoSrcs)
|
||||
protoIncludeDirs := []string{}
|
||||
for _, pkg := range SortedStringKeys(pkgToSrcs) {
|
||||
srcs := pkgToSrcs[pkg]
|
||||
attrs := ProtoAttrs{
|
||||
Srcs: bazel.MakeLabelListAttribute(srcs),
|
||||
}
|
||||
attrs.Deps.Append(bazel.MakeLabelListAttribute(depsFromFilegroup))
|
||||
|
||||
for axis, configToProps := range m.GetArchVariantProperties(ctx, &ProtoProperties{}) {
|
||||
for _, rawProps := range configToProps {
|
||||
var props *ProtoProperties
|
||||
var ok bool
|
||||
if props, ok = rawProps.(*ProtoProperties); !ok {
|
||||
ctx.ModuleErrorf("Could not cast ProtoProperties to expected type")
|
||||
}
|
||||
if axis == bazel.NoConfigAxis {
|
||||
info.Type = props.Proto.Type
|
||||
|
||||
canonicalPathFromRoot = proptools.BoolDefault(props.Proto.Canonical_path_from_root, canonicalPathFromRootDefault)
|
||||
if !canonicalPathFromRoot {
|
||||
// an empty string indicates to strips the package path
|
||||
path := ""
|
||||
attrs.Strip_import_prefix = &path
|
||||
}
|
||||
|
||||
for _, dir := range props.Proto.Include_dirs {
|
||||
if dep, ok := includeDirsToProtoDeps[dir]; ok {
|
||||
attrs.Deps.Add(bazel.MakeLabelAttribute(dep))
|
||||
} else {
|
||||
protoIncludeDirs = append(protoIncludeDirs, dir)
|
||||
}
|
||||
}
|
||||
|
||||
// proto.local_include_dirs are similar to proto.include_dirs, except that it is relative to the module directory
|
||||
for _, dir := range props.Proto.Local_include_dirs {
|
||||
relativeToTop := pathForModuleSrc(ctx, dir).String()
|
||||
protoIncludeDirs = append(protoIncludeDirs, relativeToTop)
|
||||
}
|
||||
|
||||
} else if props.Proto.Type != info.Type && props.Proto.Type != nil {
|
||||
ctx.ModuleErrorf("Cannot handle arch-variant types for protos at this time.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if p, ok := m.module.(PkgPathInterface); ok && p.PkgPath(ctx) != nil {
|
||||
// python_library with pkg_path
|
||||
// proto_library for this module should have the pkg_path as the import_prefix
|
||||
attrs.Import_prefix = p.PkgPath(ctx)
|
||||
attrs.Strip_import_prefix = proptools.StringPtr("")
|
||||
}
|
||||
|
||||
tags := ApexAvailableTagsWithoutTestApexes(ctx, ctx.Module())
|
||||
|
||||
moduleDir := ctx.ModuleDir()
|
||||
if !canonicalPathFromRoot {
|
||||
// Since we are creating the proto_library in a subpackage, set the import_prefix relative to the current package
|
||||
if rel, err := filepath.Rel(moduleDir, pkg); err != nil {
|
||||
ctx.ModuleErrorf("Could not get relative path for %v %v", pkg, err)
|
||||
} else if rel != "." {
|
||||
attrs.Import_prefix = &rel
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - b/246997908: Handle potential orphaned proto_library targets
|
||||
// To create proto_library targets in the same package, we split the .proto files
|
||||
// This means that if a proto_library in a subpackage imports another proto_library from the parent package
|
||||
// (or a different subpackage), it will not find it.
|
||||
// The CcProtoGen action itself runs fine because we construct the correct ProtoInfo,
|
||||
// but the FileDescriptorSet of each proto_library might not be compile-able
|
||||
//
|
||||
// Add manual tag if either
|
||||
// 1. .proto files are in more than one package
|
||||
// 2. proto.include_dirs is not empty
|
||||
if len(SortedStringKeys(pkgToSrcs)) > 1 || len(protoIncludeDirs) > 0 {
|
||||
tags.Append(bazel.MakeStringListAttribute([]string{"manual"}))
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
||||
CommonAttributes{Name: name, Dir: proptools.StringPtr(pkg), Tags: tags},
|
||||
&attrs,
|
||||
)
|
||||
|
||||
l := ""
|
||||
if pkg == moduleDir { // same package that the original module lives in
|
||||
l = ":" + name
|
||||
} else {
|
||||
l = "//" + pkg + ":" + name
|
||||
}
|
||||
protoLibraries.Add(&bazel.Label{
|
||||
Label: l,
|
||||
})
|
||||
}
|
||||
// Partitioning by packages can create dupes of protoIncludeDirs, so dedupe it first.
|
||||
protoLibrariesInIncludeDir := createProtoLibraryTargetsForIncludeDirs(ctx, SortedUniqueStrings(protoIncludeDirs))
|
||||
transitiveProtoLibraries.Append(protoLibrariesInIncludeDir)
|
||||
}
|
||||
|
||||
info.Proto_libs = protoLibraries
|
||||
info.Transitive_proto_libs = transitiveProtoLibraries
|
||||
|
||||
return info, true
|
||||
}
|
||||
|
||||
// PkgPathInterface is used as a type assertion in bp2build to get pkg_path property of python_library_host
|
||||
type PkgPathInterface interface {
|
||||
PkgPath(ctx BazelConversionContext) *string
|
||||
}
|
||||
|
||||
var (
|
||||
protoIncludeDirGeneratedSuffix = ".include_dir_bp2build_generated_proto"
|
||||
protoIncludeDirsBp2buildKey = NewOnceKey("protoIncludeDirsBp2build")
|
||||
)
|
||||
|
||||
func getProtoIncludeDirsBp2build(config Config) *sync.Map {
|
||||
return config.Once(protoIncludeDirsBp2buildKey, func() interface{} {
|
||||
return &sync.Map{}
|
||||
}).(*sync.Map)
|
||||
}
|
||||
|
||||
// key for dynamically creating proto_library per proto.include_dirs
|
||||
type protoIncludeDirKey struct {
|
||||
dir string
|
||||
subpackgeInDir string
|
||||
}
|
||||
|
||||
// createProtoLibraryTargetsForIncludeDirs creates additional proto_library targets for .proto files in includeDirs
|
||||
// Since Bazel imposes a constratint that the proto_library must be in the same package as the .proto file, this function
|
||||
// might create the targets in a subdirectory of `includeDir`
|
||||
// Returns the labels of the proto_library targets
|
||||
func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, includeDirs []string) bazel.LabelList {
|
||||
var ret bazel.LabelList
|
||||
for _, dir := range includeDirs {
|
||||
if exists, _, _ := ctx.Config().fs.Exists(filepath.Join(dir, "Android.bp")); !exists {
|
||||
ctx.ModuleErrorf("TODO: Add support for proto.include_dir: %v. This directory does not contain an Android.bp file", dir)
|
||||
}
|
||||
dirMap := getProtoIncludeDirsBp2build(ctx.Config())
|
||||
// Find all proto file targets in this dir
|
||||
protoLabelsInDir := BazelLabelForSrcPatternExcludes(ctx, dir, "**/*.proto", []string{})
|
||||
// Partition the labels by package and subpackage(s)
|
||||
protoLabelelsPartitionedByPkg := partitionSrcsByPackage(dir, protoLabelsInDir)
|
||||
for _, pkg := range SortedStringKeys(protoLabelelsPartitionedByPkg) {
|
||||
label := strings.ReplaceAll(dir, "/", ".") + protoIncludeDirGeneratedSuffix
|
||||
ret.Add(&bazel.Label{
|
||||
Label: "//" + pkg + ":" + label,
|
||||
})
|
||||
key := protoIncludeDirKey{dir: dir, subpackgeInDir: pkg}
|
||||
if _, exists := dirMap.LoadOrStore(key, true); exists {
|
||||
// A proto_library has already been created for this package relative to this include dir
|
||||
continue
|
||||
}
|
||||
srcs := protoLabelelsPartitionedByPkg[pkg]
|
||||
rel, err := filepath.Rel(dir, pkg)
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("Could not create a proto_library in pkg %v due to %v\n", pkg, err)
|
||||
}
|
||||
// Create proto_library
|
||||
attrs := ProtoAttrs{
|
||||
Srcs: bazel.MakeLabelListAttribute(srcs),
|
||||
Strip_import_prefix: proptools.StringPtr(""),
|
||||
}
|
||||
if rel != "." {
|
||||
attrs.Import_prefix = proptools.StringPtr(rel)
|
||||
}
|
||||
|
||||
// If a specific directory is listed in proto.include_dirs of two separate modules (one host-specific and another device-specific),
|
||||
// we do not want to create the proto_library with target_compatible_with of the first visited of these two modules
|
||||
// As a workarounds, delete `target_compatible_with`
|
||||
alwaysEnabled := bazel.BoolAttribute{}
|
||||
alwaysEnabled.Value = proptools.BoolPtr(true)
|
||||
// Add android and linux explicitly so that fillcommonbp2buildmoduleattrs can override these configs
|
||||
// When we extend b support for other os'es (darwin/windows), we should add those configs here as well
|
||||
alwaysEnabled.SetSelectValue(bazel.OsConfigurationAxis, bazel.OsAndroid, proptools.BoolPtr(true))
|
||||
alwaysEnabled.SetSelectValue(bazel.OsConfigurationAxis, bazel.OsLinux, proptools.BoolPtr(true))
|
||||
|
||||
ctx.CreateBazelTargetModuleWithRestrictions(
|
||||
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
||||
CommonAttributes{
|
||||
Name: label,
|
||||
Dir: proptools.StringPtr(pkg),
|
||||
// This proto_library is used to construct a ProtoInfo
|
||||
// But it might not be buildable on its own
|
||||
Tags: bazel.MakeStringListAttribute([]string{"manual"}),
|
||||
},
|
||||
&attrs,
|
||||
alwaysEnabled,
|
||||
)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
|
@ -187,7 +187,6 @@ func (*soongConfigModuleTypeImport) GenerateAndroidBuildActions(ModuleContext) {
|
|||
|
||||
type soongConfigModuleTypeModule struct {
|
||||
ModuleBase
|
||||
BazelModuleBase
|
||||
properties soongconfig.ModuleTypeProperties
|
||||
}
|
||||
|
||||
|
@ -395,10 +394,6 @@ func loadSoongConfigModuleTypeDefinition(ctx LoadHookContext, from string) map[s
|
|||
return (map[string]blueprint.ModuleFactory)(nil)
|
||||
}
|
||||
|
||||
if ctx.Config().BuildMode == Bp2build {
|
||||
ctx.Config().Bp2buildSoongConfigDefinitions.AddVars(mtDef)
|
||||
}
|
||||
|
||||
globalModuleTypes := ctx.moduleFactories()
|
||||
|
||||
factories := make(map[string]blueprint.ModuleFactory)
|
||||
|
@ -406,7 +401,7 @@ func loadSoongConfigModuleTypeDefinition(ctx LoadHookContext, from string) map[s
|
|||
for name, moduleType := range mtDef.ModuleTypes {
|
||||
factory := globalModuleTypes[moduleType.BaseModuleType]
|
||||
if factory != nil {
|
||||
factories[name] = configModuleFactory(factory, moduleType, ctx.Config().BuildMode == Bp2build)
|
||||
factories[name] = configModuleFactory(factory, moduleType)
|
||||
} else {
|
||||
reportErrors(ctx, from,
|
||||
fmt.Errorf("missing global module type factory for %q", moduleType.BaseModuleType))
|
||||
|
@ -474,7 +469,7 @@ var _ soongconfig.SoongConfig = (*tracingConfig)(nil)
|
|||
|
||||
// configModuleFactory takes an existing soongConfigModuleFactory and a
|
||||
// ModuleType to create a new ModuleFactory that uses a custom loadhook.
|
||||
func configModuleFactory(factory blueprint.ModuleFactory, moduleType *soongconfig.ModuleType, bp2build bool) blueprint.ModuleFactory {
|
||||
func configModuleFactory(factory blueprint.ModuleFactory, moduleType *soongconfig.ModuleType) blueprint.ModuleFactory {
|
||||
// Defer creation of conditional properties struct until the first call from the factory
|
||||
// method. That avoids having to make a special call to the factory to create the properties
|
||||
// structs from which the conditional properties struct is created. This is needed in order to
|
||||
|
@ -515,40 +510,22 @@ func configModuleFactory(factory blueprint.ModuleFactory, moduleType *soongconfi
|
|||
conditionalProps := proptools.CloneEmptyProperties(conditionalFactoryProps)
|
||||
props = append(props, conditionalProps.Interface())
|
||||
|
||||
if bp2build {
|
||||
// The loadhook is different for bp2build, since we don't want to set a specific
|
||||
// set of property values based on a vendor var -- we want __all of them__ to
|
||||
// generate select statements, so we put the entire soong_config_variables
|
||||
// struct, together with the namespace representing those variables, while
|
||||
// creating the custom module with the factory.
|
||||
AddLoadHook(module, func(ctx LoadHookContext) {
|
||||
if m, ok := module.(Bazelable); ok {
|
||||
m.SetBaseModuleType(moduleType.BaseModuleType)
|
||||
// Instead of applying all properties, keep the entire conditionalProps struct as
|
||||
// part of the custom module so dependent modules can create the selects accordingly
|
||||
m.setNamespacedVariableProps(namespacedVariableProperties{
|
||||
moduleType.ConfigNamespace: []interface{}{conditionalProps.Interface()},
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// Regular Soong operation wraps the existing module factory with a
|
||||
// conditional on Soong config variables by reading the product
|
||||
// config variables from Make.
|
||||
AddLoadHook(module, func(ctx LoadHookContext) {
|
||||
tracingConfig := newTracingConfig(ctx.Config().VendorConfig(moduleType.ConfigNamespace))
|
||||
newProps, err := soongconfig.PropertiesToApply(moduleType, conditionalProps, tracingConfig)
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("%s", err)
|
||||
return
|
||||
}
|
||||
for _, ps := range newProps {
|
||||
ctx.AppendProperties(ps)
|
||||
}
|
||||
// Regular Soong operation wraps the existing module factory with a
|
||||
// conditional on Soong config variables by reading the product
|
||||
// config variables from Make.
|
||||
AddLoadHook(module, func(ctx LoadHookContext) {
|
||||
tracingConfig := newTracingConfig(ctx.Config().VendorConfig(moduleType.ConfigNamespace))
|
||||
newProps, err := soongconfig.PropertiesToApply(moduleType, conditionalProps, tracingConfig)
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("%s", err)
|
||||
return
|
||||
}
|
||||
for _, ps := range newProps {
|
||||
ctx.AppendProperties(ps)
|
||||
}
|
||||
|
||||
module.(Module).base().commonProperties.SoongConfigTrace = tracingConfig.getTrace()
|
||||
})
|
||||
}
|
||||
module.(Module).base().commonProperties.SoongConfigTrace = tracingConfig.getTrace()
|
||||
})
|
||||
return module, props
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ bootstrap_go_package {
|
|||
"soong-aconfig",
|
||||
"soong-aconfig-codegen",
|
||||
"soong-android",
|
||||
"soong-bazel",
|
||||
"soong-bpf",
|
||||
"soong-cc",
|
||||
"soong-filesystem",
|
||||
|
@ -28,7 +27,6 @@ bootstrap_go_package {
|
|||
"apex_sdk_member.go",
|
||||
"apex_singleton.go",
|
||||
"builder.go",
|
||||
"bp2build.go",
|
||||
"deapexer.go",
|
||||
"key.go",
|
||||
"prebuilt.go",
|
||||
|
|
|
@ -139,9 +139,6 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, moduleDir st
|
|||
archStr := fi.module.Target().Arch.ArchType.String()
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
|
||||
}
|
||||
} else if fi.isBazelPrebuilt && fi.arch != "" {
|
||||
// This apexFile comes from Bazel
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", fi.arch)
|
||||
}
|
||||
if fi.jacocoReportClassesFile != nil {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR :=", fi.jacocoReportClassesFile.String())
|
||||
|
@ -185,21 +182,17 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, moduleDir st
|
|||
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_android_app_set.mk")
|
||||
case nativeSharedLib, nativeExecutable, nativeTest:
|
||||
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", fi.stem())
|
||||
if fi.isBazelPrebuilt {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", fi.unstrippedBuiltFile)
|
||||
} else {
|
||||
if ccMod, ok := fi.module.(*cc.Module); ok {
|
||||
if ccMod.UnstrippedOutputFile() != nil {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String())
|
||||
}
|
||||
ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
|
||||
if ccMod.CoverageOutputFile().Valid() {
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String())
|
||||
}
|
||||
} else if rustMod, ok := fi.module.(*rust.Module); ok {
|
||||
if rustMod.UnstrippedOutputFile() != nil {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", rustMod.UnstrippedOutputFile().String())
|
||||
}
|
||||
if ccMod, ok := fi.module.(*cc.Module); ok {
|
||||
if ccMod.UnstrippedOutputFile() != nil {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", ccMod.UnstrippedOutputFile().String())
|
||||
}
|
||||
ccMod.AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
|
||||
if ccMod.CoverageOutputFile().Valid() {
|
||||
fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE :=", ccMod.CoverageOutputFile().String())
|
||||
}
|
||||
} else if rustMod, ok := fi.module.(*rust.Module); ok {
|
||||
if rustMod.UnstrippedOutputFile() != nil {
|
||||
fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", rustMod.UnstrippedOutputFile().String())
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_cc_rust_prebuilt.mk")
|
||||
|
|
518
apex/apex.go
518
apex/apex.go
|
@ -25,13 +25,10 @@ import (
|
|||
"strings"
|
||||
|
||||
"android/soong/aconfig"
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bpf"
|
||||
"android/soong/cc"
|
||||
prebuilt_etc "android/soong/etc"
|
||||
|
@ -389,7 +386,6 @@ type apexBundle struct {
|
|||
android.ModuleBase
|
||||
android.DefaultableModuleBase
|
||||
android.OverridableModuleBase
|
||||
android.BazelModuleBase
|
||||
multitree.ExportableModuleBase
|
||||
|
||||
// Properties
|
||||
|
@ -547,10 +543,6 @@ type apexFile struct {
|
|||
|
||||
multilib string
|
||||
|
||||
isBazelPrebuilt bool
|
||||
unstrippedBuiltFile android.Path
|
||||
arch string
|
||||
|
||||
// TODO(jiyong): remove this
|
||||
module android.Module
|
||||
}
|
||||
|
@ -1821,119 +1813,6 @@ func (f fsType) string() string {
|
|||
}
|
||||
}
|
||||
|
||||
var _ android.MixedBuildBuildable = (*apexBundle)(nil)
|
||||
|
||||
func (a *apexBundle) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *apexBundle) QueueBazelCall(ctx android.BaseModuleContext) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(a.GetBazelLabel(ctx, a), cquery.GetApexInfo, android.GetConfigKey(ctx))
|
||||
}
|
||||
|
||||
// GetBazelLabel returns the bazel label of this apexBundle, or the label of the
|
||||
// override_apex module overriding this apexBundle. An apexBundle can be
|
||||
// overridden by different override_apex modules (e.g. Google or Go variants),
|
||||
// which is handled by the overrides mutators.
|
||||
func (a *apexBundle) GetBazelLabel(ctx android.BazelConversionPathContext, module blueprint.Module) string {
|
||||
return a.BazelModuleBase.GetBazelLabel(ctx, a)
|
||||
}
|
||||
|
||||
func (a *apexBundle) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
||||
if !a.commonBuildActions(ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
a.setPayloadFsType(ctx)
|
||||
a.setSystemLibLink(ctx)
|
||||
a.compatSymlinks = makeCompatSymlinks(a.BaseModuleName(), ctx)
|
||||
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
outputs, err := bazelCtx.GetApexInfo(a.GetBazelLabel(ctx, a), android.GetConfigKey(ctx))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
a.installDir = android.PathForModuleInstall(ctx, "apex")
|
||||
|
||||
// Set the output file to .apex or .capex depending on the compression configuration.
|
||||
a.setCompression(ctx)
|
||||
if a.isCompressed {
|
||||
a.outputApexFile = android.PathForBazelOutRelative(ctx, ctx.ModuleDir(), outputs.SignedCompressedOutput)
|
||||
} else {
|
||||
a.outputApexFile = android.PathForBazelOutRelative(ctx, ctx.ModuleDir(), outputs.SignedOutput)
|
||||
}
|
||||
a.outputFile = a.outputApexFile
|
||||
|
||||
if len(outputs.TidyFiles) > 0 {
|
||||
tidyFiles := android.PathsForBazelOut(ctx, outputs.TidyFiles)
|
||||
a.outputFile = android.AttachValidationActions(ctx, a.outputFile, tidyFiles)
|
||||
}
|
||||
|
||||
// TODO(b/257829940): These are used by the apex_keys_text singleton; would probably be a clearer
|
||||
// interface if these were set in a provider rather than the module itself
|
||||
a.publicKeyFile = android.PathForBazelOut(ctx, outputs.BundleKeyInfo[0])
|
||||
a.privateKeyFile = android.PathForBazelOut(ctx, outputs.BundleKeyInfo[1])
|
||||
a.containerCertificateFile = android.PathForBazelOut(ctx, outputs.ContainerKeyInfo[0])
|
||||
a.containerPrivateKeyFile = android.PathForBazelOut(ctx, outputs.ContainerKeyInfo[1])
|
||||
|
||||
// Ensure ApexMkInfo.install_to_system make module names are installed as
|
||||
// part of a bundled build.
|
||||
a.makeModulesToInstall = append(a.makeModulesToInstall, outputs.MakeModulesToInstall...)
|
||||
|
||||
a.bundleModuleFile = android.PathForBazelOut(ctx, outputs.BundleFile)
|
||||
a.nativeApisUsedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.SymbolsUsedByApex))
|
||||
a.nativeApisBackedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.BackingLibs))
|
||||
// TODO(b/239084755): Generate the java api using.xml file from Bazel.
|
||||
a.javaApisUsedByModuleFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.JavaSymbolsUsedByApex))
|
||||
a.installedFilesFile = android.ModuleOutPath(android.PathForBazelOut(ctx, outputs.InstalledFiles))
|
||||
installSuffix := imageApexSuffix
|
||||
if a.isCompressed {
|
||||
installSuffix = imageCapexSuffix
|
||||
}
|
||||
a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile,
|
||||
a.compatSymlinks...)
|
||||
|
||||
// filesInfo in mixed mode must retrieve all information about the apex's
|
||||
// contents completely from the Starlark providers. It should never rely on
|
||||
// Android.bp information, as they might not exist for fully migrated
|
||||
// dependencies.
|
||||
//
|
||||
// Prevent accidental writes to filesInfo in the earlier parts Soong by
|
||||
// asserting it to be nil.
|
||||
if a.filesInfo != nil {
|
||||
panic(
|
||||
fmt.Errorf("internal error: filesInfo must be nil for an apex handled by Bazel. " +
|
||||
"Did something else set filesInfo before this line of code?"))
|
||||
}
|
||||
for _, f := range outputs.PayloadFilesInfo {
|
||||
fileInfo := apexFile{
|
||||
isBazelPrebuilt: true,
|
||||
|
||||
builtFile: android.PathForBazelOut(ctx, f["built_file"]),
|
||||
unstrippedBuiltFile: android.PathForBazelOut(ctx, f["unstripped_built_file"]),
|
||||
androidMkModuleName: f["make_module_name"],
|
||||
installDir: f["install_dir"],
|
||||
class: classes[f["class"]],
|
||||
customStem: f["basename"],
|
||||
moduleDir: f["package"],
|
||||
}
|
||||
|
||||
arch := f["arch"]
|
||||
fileInfo.arch = arch
|
||||
if len(arch) > 0 {
|
||||
fileInfo.multilib = "lib32"
|
||||
if strings.HasSuffix(arch, "64") {
|
||||
fileInfo.multilib = "lib64"
|
||||
}
|
||||
}
|
||||
|
||||
a.filesInfo = append(a.filesInfo, fileInfo)
|
||||
}
|
||||
a.apexKeysPath = writeApexKeys(ctx, a)
|
||||
}
|
||||
|
||||
func (a *apexBundle) setCompression(ctx android.ModuleContext) {
|
||||
if a.testOnlyShouldForceCompression() {
|
||||
a.isCompressed = true
|
||||
|
@ -2587,7 +2466,6 @@ func newApexBundle() *apexBundle {
|
|||
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
||||
android.InitDefaultableModule(module)
|
||||
android.InitOverridableModule(module, &module.overridableProperties.Overrides)
|
||||
android.InitBazelModule(module)
|
||||
multitree.InitExportableModule(module)
|
||||
return module
|
||||
}
|
||||
|
@ -2635,7 +2513,6 @@ func DefaultsFactory() android.Module {
|
|||
type OverrideApex struct {
|
||||
android.ModuleBase
|
||||
android.OverrideModuleBase
|
||||
android.BazelModuleBase
|
||||
}
|
||||
|
||||
func (o *OverrideApex) GenerateAndroidBuildActions(_ android.ModuleContext) {
|
||||
|
@ -2651,104 +2528,9 @@ func OverrideApexFactory() android.Module {
|
|||
|
||||
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
|
||||
android.InitOverrideModule(m)
|
||||
android.InitBazelModule(m)
|
||||
return m
|
||||
}
|
||||
|
||||
func (o *OverrideApex) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
if ctx.ModuleType() != "override_apex" {
|
||||
return
|
||||
}
|
||||
|
||||
baseApexModuleName := o.OverrideModuleBase.GetOverriddenModuleName()
|
||||
baseModule, baseApexExists := ctx.ModuleFromName(baseApexModuleName)
|
||||
if !baseApexExists {
|
||||
panic(fmt.Errorf("Base apex module doesn't exist: %s", baseApexModuleName))
|
||||
}
|
||||
|
||||
a, baseModuleIsApex := baseModule.(*apexBundle)
|
||||
if !baseModuleIsApex {
|
||||
panic(fmt.Errorf("Base module is not apex module: %s", baseApexModuleName))
|
||||
}
|
||||
attrs, props, commonAttrs := convertWithBp2build(a, ctx)
|
||||
|
||||
// We just want the name, not module reference.
|
||||
baseApexName := strings.TrimPrefix(baseApexModuleName, ":")
|
||||
attrs.Base_apex_name = &baseApexName
|
||||
|
||||
for _, p := range o.GetProperties() {
|
||||
overridableProperties, ok := p.(*overridableProperties)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
// Manifest is either empty or a file in the directory of base APEX and is not overridable.
|
||||
// After it is converted in convertWithBp2build(baseApex, ctx),
|
||||
// the attrs.Manifest.Value.Label is the file path relative to the directory
|
||||
// of base apex. So the following code converts it to a label that looks like
|
||||
// <package of base apex>:<path of manifest file> if base apex and override
|
||||
// apex are not in the same package.
|
||||
baseApexPackage := ctx.OtherModuleDir(a)
|
||||
overrideApexPackage := ctx.ModuleDir()
|
||||
if baseApexPackage != overrideApexPackage {
|
||||
attrs.Manifest.Value.Label = "//" + baseApexPackage + ":" + attrs.Manifest.Value.Label
|
||||
}
|
||||
|
||||
// Key
|
||||
if overridableProperties.Key != nil {
|
||||
attrs.Key = bazel.LabelAttribute{}
|
||||
attrs.Key.SetValue(android.BazelLabelForModuleDepSingle(ctx, *overridableProperties.Key))
|
||||
}
|
||||
|
||||
// Certificate
|
||||
if overridableProperties.Certificate == nil {
|
||||
// If overridableProperties.Certificate is nil, clear this out as
|
||||
// well with zeroed structs, so the override_apex does not use the
|
||||
// base apex's certificate.
|
||||
attrs.Certificate = bazel.LabelAttribute{}
|
||||
attrs.Certificate_name = bazel.StringAttribute{}
|
||||
} else {
|
||||
attrs.Certificate, attrs.Certificate_name = android.BazelStringOrLabelFromProp(ctx, overridableProperties.Certificate)
|
||||
}
|
||||
|
||||
// Prebuilts
|
||||
if overridableProperties.Prebuilts != nil {
|
||||
prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, overridableProperties.Prebuilts)
|
||||
attrs.Prebuilts = bazel.MakeLabelListAttribute(prebuiltsLabelList)
|
||||
}
|
||||
|
||||
// Compressible
|
||||
if overridableProperties.Compressible != nil {
|
||||
attrs.Compressible = bazel.BoolAttribute{Value: overridableProperties.Compressible}
|
||||
}
|
||||
|
||||
// Package name
|
||||
//
|
||||
// e.g. com.android.adbd's package name is com.android.adbd, but
|
||||
// com.google.android.adbd overrides the package name to com.google.android.adbd
|
||||
//
|
||||
// TODO: this can be overridden from the product configuration, see
|
||||
// getOverrideManifestPackageName and
|
||||
// PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES.
|
||||
//
|
||||
// Instead of generating the BUILD files differently based on the product config
|
||||
// at the point of conversion, this should be handled by the BUILD file loading
|
||||
// from the soong_injection's product_vars, so product config is decoupled from bp2build.
|
||||
if overridableProperties.Package_name != "" {
|
||||
attrs.Package_name = &overridableProperties.Package_name
|
||||
}
|
||||
|
||||
// Logging parent
|
||||
if overridableProperties.Logging_parent != "" {
|
||||
attrs.Logging_parent = &overridableProperties.Logging_parent
|
||||
}
|
||||
}
|
||||
|
||||
commonAttrs.Name = o.Name()
|
||||
|
||||
ctx.CreateBazelTargetModule(props, commonAttrs, &attrs)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Vality check routines
|
||||
//
|
||||
|
@ -3203,306 +2985,6 @@ func rBcpPackages() map[string][]string {
|
|||
}
|
||||
}
|
||||
|
||||
// For Bazel / bp2build
|
||||
|
||||
type bazelApexBundleAttributes struct {
|
||||
Manifest bazel.LabelAttribute
|
||||
Android_manifest bazel.LabelAttribute
|
||||
File_contexts bazel.LabelAttribute
|
||||
Canned_fs_config bazel.LabelAttribute
|
||||
Key bazel.LabelAttribute
|
||||
Certificate bazel.LabelAttribute // used when the certificate prop is a module
|
||||
Certificate_name bazel.StringAttribute // used when the certificate prop is a string
|
||||
Min_sdk_version bazel.StringAttribute
|
||||
Updatable bazel.BoolAttribute
|
||||
Installable bazel.BoolAttribute
|
||||
Binaries bazel.LabelListAttribute
|
||||
Prebuilts bazel.LabelListAttribute
|
||||
Native_shared_libs_32 bazel.LabelListAttribute
|
||||
Native_shared_libs_64 bazel.LabelListAttribute
|
||||
Compressible bazel.BoolAttribute
|
||||
Package_name *string
|
||||
Logging_parent *string
|
||||
Tests bazel.LabelListAttribute
|
||||
Base_apex_name *string
|
||||
Apex_available_name *string
|
||||
Variant_version *string
|
||||
}
|
||||
|
||||
type convertedNativeSharedLibs struct {
|
||||
Native_shared_libs_32 bazel.LabelListAttribute
|
||||
Native_shared_libs_64 bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
const (
|
||||
minSdkVersionPropName = "Min_sdk_version"
|
||||
)
|
||||
|
||||
// ConvertWithBp2build performs bp2build conversion of an apex
|
||||
func (a *apexBundle) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
// We only convert apex and apex_test modules at this time
|
||||
if ctx.ModuleType() != "apex" && ctx.ModuleType() != "apex_test" {
|
||||
return
|
||||
}
|
||||
|
||||
attrs, props, commonAttrs := convertWithBp2build(a, ctx)
|
||||
commonAttrs.Name = a.Name()
|
||||
ctx.CreateBazelTargetModule(props, commonAttrs, &attrs)
|
||||
}
|
||||
|
||||
func convertWithBp2build(a *apexBundle, ctx android.Bp2buildMutatorContext) (bazelApexBundleAttributes, bazel.BazelTargetModuleProperties, android.CommonAttributes) {
|
||||
var manifestLabelAttribute bazel.LabelAttribute
|
||||
manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, proptools.StringDefault(a.properties.Manifest, "apex_manifest.json")))
|
||||
|
||||
var androidManifestLabelAttribute bazel.LabelAttribute
|
||||
if a.properties.AndroidManifest != nil {
|
||||
androidManifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.AndroidManifest))
|
||||
}
|
||||
|
||||
var fileContextsLabelAttribute bazel.LabelAttribute
|
||||
if a.properties.File_contexts == nil {
|
||||
// See buildFileContexts(), if file_contexts is not specified the default one is used, which is //system/sepolicy/apex:<module name>-file_contexts
|
||||
fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, a.Name()+"-file_contexts"))
|
||||
} else if strings.HasPrefix(*a.properties.File_contexts, ":") {
|
||||
// File_contexts is a module
|
||||
fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
|
||||
} else {
|
||||
// File_contexts is a file
|
||||
fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.File_contexts))
|
||||
}
|
||||
|
||||
var cannedFsConfigAttribute bazel.LabelAttribute
|
||||
if a.properties.Canned_fs_config != nil {
|
||||
cannedFsConfigAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Canned_fs_config))
|
||||
}
|
||||
|
||||
productVariableProps, errs := android.ProductVariableProperties(ctx, a)
|
||||
for _, err := range errs {
|
||||
ctx.ModuleErrorf("ProductVariableProperties error: %s", err)
|
||||
}
|
||||
// TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
|
||||
// given it's coming via config, we probably don't want to put it in here.
|
||||
var minSdkVersion bazel.StringAttribute
|
||||
if a.properties.Min_sdk_version != nil {
|
||||
minSdkVersion.SetValue(*a.properties.Min_sdk_version)
|
||||
}
|
||||
if props, ok := productVariableProps[minSdkVersionPropName]; ok {
|
||||
for c, p := range props {
|
||||
if val, ok := p.(*string); ok {
|
||||
minSdkVersion.SetSelectValue(c.ConfigurationAxis(), c.SelectKey(), val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var keyLabelAttribute bazel.LabelAttribute
|
||||
if a.overridableProperties.Key != nil {
|
||||
keyLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.overridableProperties.Key))
|
||||
}
|
||||
|
||||
// Certificate
|
||||
certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableProperties.Certificate)
|
||||
|
||||
nativeSharedLibs := &convertedNativeSharedLibs{
|
||||
Native_shared_libs_32: bazel.LabelListAttribute{},
|
||||
Native_shared_libs_64: bazel.LabelListAttribute{},
|
||||
}
|
||||
|
||||
// https://cs.android.com/android/platform/superproject/+/master:build/soong/android/arch.go;l=698;drc=f05b0d35d2fbe51be9961ce8ce8031f840295c68
|
||||
// https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=2549;drc=ec731a83e3e2d80a1254e32fd4ad7ef85e262669
|
||||
// In Soong, decodeMultilib, used to get multilib, return "first" if defaultMultilib is set to "common".
|
||||
// Since apex sets defaultMultilib to be "common", equivalent compileMultilib in bp2build for apex should be "first"
|
||||
compileMultilib := "first"
|
||||
if a.CompileMultilib() != nil {
|
||||
compileMultilib = *a.CompileMultilib()
|
||||
}
|
||||
|
||||
// properties.Native_shared_libs is treated as "both"
|
||||
convertBothLibs(ctx, compileMultilib, a.properties.Native_shared_libs, nativeSharedLibs)
|
||||
convertBothLibs(ctx, compileMultilib, a.properties.Multilib.Both.Native_shared_libs, nativeSharedLibs)
|
||||
convert32Libs(ctx, compileMultilib, a.properties.Multilib.Lib32.Native_shared_libs, nativeSharedLibs)
|
||||
convert64Libs(ctx, compileMultilib, a.properties.Multilib.Lib64.Native_shared_libs, nativeSharedLibs)
|
||||
convertFirstLibs(ctx, compileMultilib, a.properties.Multilib.First.Native_shared_libs, nativeSharedLibs)
|
||||
|
||||
prebuilts := a.overridableProperties.Prebuilts
|
||||
prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, prebuilts)
|
||||
prebuiltsLabelListAttribute := bazel.MakeLabelListAttribute(prebuiltsLabelList)
|
||||
|
||||
binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
|
||||
binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
|
||||
|
||||
var testsAttrs bazel.LabelListAttribute
|
||||
if a.testApex && len(a.properties.ApexNativeDependencies.Tests) > 0 {
|
||||
tests := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Tests)
|
||||
testsAttrs = bazel.MakeLabelListAttribute(tests)
|
||||
}
|
||||
|
||||
var updatableAttribute bazel.BoolAttribute
|
||||
if a.properties.Updatable != nil {
|
||||
updatableAttribute.Value = a.properties.Updatable
|
||||
}
|
||||
|
||||
var installableAttribute bazel.BoolAttribute
|
||||
if a.properties.Installable != nil {
|
||||
installableAttribute.Value = a.properties.Installable
|
||||
}
|
||||
|
||||
var compressibleAttribute bazel.BoolAttribute
|
||||
if a.overridableProperties.Compressible != nil {
|
||||
compressibleAttribute.Value = a.overridableProperties.Compressible
|
||||
}
|
||||
|
||||
var packageName *string
|
||||
if a.overridableProperties.Package_name != "" {
|
||||
packageName = &a.overridableProperties.Package_name
|
||||
}
|
||||
|
||||
var loggingParent *string
|
||||
if a.overridableProperties.Logging_parent != "" {
|
||||
loggingParent = &a.overridableProperties.Logging_parent
|
||||
}
|
||||
|
||||
attrs := bazelApexBundleAttributes{
|
||||
Manifest: manifestLabelAttribute,
|
||||
Android_manifest: androidManifestLabelAttribute,
|
||||
File_contexts: fileContextsLabelAttribute,
|
||||
Canned_fs_config: cannedFsConfigAttribute,
|
||||
Min_sdk_version: minSdkVersion,
|
||||
Key: keyLabelAttribute,
|
||||
Certificate: certificate,
|
||||
Certificate_name: certificateName,
|
||||
Updatable: updatableAttribute,
|
||||
Installable: installableAttribute,
|
||||
Native_shared_libs_32: nativeSharedLibs.Native_shared_libs_32,
|
||||
Native_shared_libs_64: nativeSharedLibs.Native_shared_libs_64,
|
||||
Binaries: binariesLabelListAttribute,
|
||||
Prebuilts: prebuiltsLabelListAttribute,
|
||||
Compressible: compressibleAttribute,
|
||||
Package_name: packageName,
|
||||
Logging_parent: loggingParent,
|
||||
Tests: testsAttrs,
|
||||
Apex_available_name: a.properties.Apex_available_name,
|
||||
Variant_version: a.properties.Variant_version,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "apex",
|
||||
Bzl_load_location: "//build/bazel/rules/apex:apex.bzl",
|
||||
}
|
||||
|
||||
commonAttrs := android.CommonAttributes{}
|
||||
if a.testApex {
|
||||
commonAttrs.Testonly = proptools.BoolPtr(true)
|
||||
// Set the api_domain of the test apex
|
||||
attrs.Base_apex_name = proptools.StringPtr(cc.GetApiDomain(a.Name()))
|
||||
}
|
||||
|
||||
return attrs, props, commonAttrs
|
||||
}
|
||||
|
||||
// The following conversions are based on this table where the rows are the compile_multilib
|
||||
// values and the columns are the properties.Multilib.*.Native_shared_libs. Each cell
|
||||
// represents how the libs should be compiled for a 64-bit/32-bit device: 32 means it
|
||||
// should be compiled as 32-bit, 64 means it should be compiled as 64-bit, none means it
|
||||
// should not be compiled.
|
||||
// multib/compile_multilib, 32, 64, both, first
|
||||
// 32, 32/32, none/none, 32/32, none/32
|
||||
// 64, none/none, 64/none, 64/none, 64/none
|
||||
// both, 32/32, 64/none, 32&64/32, 64/32
|
||||
// first, 32/32, 64/none, 64/32, 64/32
|
||||
|
||||
func convert32Libs(ctx android.Bp2buildMutatorContext, compileMultilb string,
|
||||
libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
|
||||
switch compileMultilb {
|
||||
case "both", "32":
|
||||
makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "first":
|
||||
make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "64":
|
||||
// Incompatible, ignore
|
||||
default:
|
||||
invalidCompileMultilib(ctx, compileMultilb)
|
||||
}
|
||||
}
|
||||
|
||||
func convert64Libs(ctx android.Bp2buildMutatorContext, compileMultilb string,
|
||||
libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
|
||||
switch compileMultilb {
|
||||
case "both", "64", "first":
|
||||
make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "32":
|
||||
// Incompatible, ignore
|
||||
default:
|
||||
invalidCompileMultilib(ctx, compileMultilb)
|
||||
}
|
||||
}
|
||||
|
||||
func convertBothLibs(ctx android.Bp2buildMutatorContext, compileMultilb string,
|
||||
libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
|
||||
switch compileMultilb {
|
||||
case "both":
|
||||
makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "first":
|
||||
makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "32":
|
||||
makeNoConfig32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "64":
|
||||
make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
default:
|
||||
invalidCompileMultilib(ctx, compileMultilb)
|
||||
}
|
||||
}
|
||||
|
||||
func convertFirstLibs(ctx android.Bp2buildMutatorContext, compileMultilb string,
|
||||
libs []string, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
libsLabelList := android.BazelLabelForModuleDeps(ctx, libs)
|
||||
switch compileMultilb {
|
||||
case "both", "first":
|
||||
makeFirstSharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "32":
|
||||
make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
case "64":
|
||||
make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
default:
|
||||
invalidCompileMultilib(ctx, compileMultilb)
|
||||
}
|
||||
}
|
||||
|
||||
func makeFirstSharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
make32SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
make64SharedLibsAttributes(libsLabelList, nativeSharedLibs)
|
||||
}
|
||||
|
||||
func makeNoConfig32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
list := bazel.LabelListAttribute{}
|
||||
list.SetSelectValue(bazel.NoConfigAxis, "", libsLabelList)
|
||||
nativeSharedLibs.Native_shared_libs_32.Append(list)
|
||||
}
|
||||
|
||||
func make32SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
makeSharedLibsAttributes("x86", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
|
||||
makeSharedLibsAttributes("arm", libsLabelList, &nativeSharedLibs.Native_shared_libs_32)
|
||||
}
|
||||
|
||||
func make64SharedLibsAttributes(libsLabelList bazel.LabelList, nativeSharedLibs *convertedNativeSharedLibs) {
|
||||
makeSharedLibsAttributes("x86_64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
|
||||
makeSharedLibsAttributes("arm64", libsLabelList, &nativeSharedLibs.Native_shared_libs_64)
|
||||
}
|
||||
|
||||
func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
|
||||
labelListAttr *bazel.LabelListAttribute) {
|
||||
list := bazel.LabelListAttribute{}
|
||||
list.SetSelectValue(bazel.ArchConfigurationAxis, config, libsLabelList)
|
||||
labelListAttr.Append(list)
|
||||
}
|
||||
|
||||
func invalidCompileMultilib(ctx android.Bp2buildMutatorContext, value string) {
|
||||
ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
|
||||
}
|
||||
|
||||
func (a *apexBundle) IsTestApex() bool {
|
||||
return a.testApex
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2022 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package apex
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// This file contains the bp2build integration for the apex package.
|
||||
|
||||
// Export constants as Starlark using bp2build to Bazel.
|
||||
func BazelApexToolchainVars() (string, error) {
|
||||
marshalled, err := json.Marshal(apexAvailBaseline)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
content := []string{
|
||||
"# GENERATED BY SOONG. DO NOT EDIT.",
|
||||
"default_manifest_version = " + android.DefaultUpdatableModuleVersion, // constants.go is different in every branch.
|
||||
"apex_available_baseline = json.decode('''" + string(marshalled) + "''')",
|
||||
}
|
||||
return strings.Join(content, "\n"), nil
|
||||
}
|
|
@ -1,545 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package apex
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/android/allowlists"
|
||||
"android/soong/bazel/cquery"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestApexImageInMixedBuilds(t *testing.T) {
|
||||
bp := `
|
||||
apex_key{
|
||||
name: "foo_key",
|
||||
}
|
||||
|
||||
apex {
|
||||
name: "foo",
|
||||
key: "foo_key",
|
||||
updatable: true,
|
||||
min_sdk_version: "31",
|
||||
file_contexts: ":myapex-file_contexts",
|
||||
bazel_module: { label: "//:foo" },
|
||||
}`
|
||||
|
||||
outputBaseDir := "out/bazel"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForApexTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outputBaseDir,
|
||||
LabelToApexInfo: map[string]cquery.ApexInfo{
|
||||
"//:foo": cquery.ApexInfo{
|
||||
// ApexInfo Starlark provider.
|
||||
SignedOutput: "signed_out.apex",
|
||||
SignedCompressedOutput: "signed_out.capex",
|
||||
UnsignedOutput: "unsigned_out.apex",
|
||||
BundleKeyInfo: []string{"public_key", "private_key"},
|
||||
ContainerKeyInfo: []string{"container_cert", "container_private"},
|
||||
SymbolsUsedByApex: "foo_using.txt",
|
||||
JavaSymbolsUsedByApex: "foo_using.xml",
|
||||
BundleFile: "apex_bundle.zip",
|
||||
InstalledFiles: "installed-files.txt",
|
||||
RequiresLibs: []string{"//path/c:c", "//path/d:d"},
|
||||
|
||||
// unused
|
||||
PackageName: "pkg_name",
|
||||
ProvidesLibs: []string{"a", "b"},
|
||||
|
||||
// ApexMkInfo Starlark provider
|
||||
PayloadFilesInfo: []map[string]string{
|
||||
{
|
||||
"built_file": "bazel-out/adbd",
|
||||
"install_dir": "bin",
|
||||
"class": "nativeExecutable",
|
||||
"make_module_name": "adbd",
|
||||
"basename": "adbd",
|
||||
"package": "foo",
|
||||
},
|
||||
},
|
||||
MakeModulesToInstall: []string{"c"}, // d deliberately omitted
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
|
||||
m := result.ModuleForTests("foo", "android_common_foo").Module()
|
||||
ab, ok := m.(*apexBundle)
|
||||
|
||||
if !ok {
|
||||
t.Fatalf("Expected module to be an apexBundle, was not")
|
||||
}
|
||||
|
||||
// TODO: refactor to android.AssertStringEquals
|
||||
if w, g := "out/bazel/execroot/__main__/public_key", ab.publicKeyFile.String(); w != g {
|
||||
t.Errorf("Expected public key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/private_key", ab.privateKeyFile.String(); w != g {
|
||||
t.Errorf("Expected private key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/container_cert", ab.containerCertificateFile.String(); w != g {
|
||||
t.Errorf("Expected public container key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/container_private", ab.containerPrivateKeyFile.String(); w != g {
|
||||
t.Errorf("Expected private container key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/signed_out.apex", ab.outputFile.String(); w != g {
|
||||
t.Errorf("Expected output file %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/foo_using.txt", ab.nativeApisUsedByModuleFile.String(); w != g {
|
||||
t.Errorf("Expected output file %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/foo_using.xml", ab.javaApisUsedByModuleFile.String(); w != g {
|
||||
t.Errorf("Expected output file %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/installed-files.txt", ab.installedFilesFile.String(); w != g {
|
||||
t.Errorf("Expected installed-files.txt %q, got %q", w, g)
|
||||
}
|
||||
|
||||
mkData := android.AndroidMkDataForTest(t, result.TestContext, m)
|
||||
var builder strings.Builder
|
||||
mkData.Custom(&builder, "foo", "BAZEL_TARGET_", "", mkData)
|
||||
|
||||
data := builder.String()
|
||||
if w := "ALL_MODULES.$(my_register_name).BUNDLE := out/bazel/execroot/__main__/apex_bundle.zip"; !strings.Contains(data, w) {
|
||||
t.Errorf("Expected %q in androidmk data, but did not find %q", w, data)
|
||||
}
|
||||
if w := "$(call dist-for-goals,checkbuild,out/bazel/execroot/__main__/installed-files.txt:foo-installed-files.txt)"; !strings.Contains(data, w) {
|
||||
t.Errorf("Expected %q in androidmk data, but did not find %q", w, data)
|
||||
}
|
||||
|
||||
// make modules to be installed to system
|
||||
if len(ab.makeModulesToInstall) != 1 && ab.makeModulesToInstall[0] != "c" {
|
||||
t.Errorf("Expected makeModulesToInstall slice to only contain 'c', got %q", ab.makeModulesToInstall)
|
||||
}
|
||||
if w := "LOCAL_REQUIRED_MODULES := adbd.foo c"; !strings.Contains(data, w) {
|
||||
t.Errorf("Expected %q in androidmk data, but did not find it in %q", w, data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApexImageCreatesFilesInfoForMake(t *testing.T) {
|
||||
bp := `
|
||||
apex_key{
|
||||
name: "foo_key",
|
||||
}
|
||||
|
||||
apex {
|
||||
name: "foo",
|
||||
key: "foo_key",
|
||||
updatable: true,
|
||||
min_sdk_version: "31",
|
||||
file_contexts: ":myapex-file_contexts",
|
||||
bazel_module: { label: "//:foo" },
|
||||
}`
|
||||
|
||||
outputBaseDir := "out/bazel"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForApexTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outputBaseDir,
|
||||
LabelToApexInfo: map[string]cquery.ApexInfo{
|
||||
"//:foo": {
|
||||
// ApexInfo Starlark provider. Necessary for the test.
|
||||
SignedOutput: "signed_out.apex",
|
||||
BundleKeyInfo: []string{"public_key", "private_key"},
|
||||
ContainerKeyInfo: []string{"container_cert", "container_private"},
|
||||
|
||||
// ApexMkInfo Starlark provider
|
||||
PayloadFilesInfo: []map[string]string{
|
||||
{
|
||||
"arch": "arm64",
|
||||
"basename": "libcrypto.so",
|
||||
"built_file": "bazel-out/64/libcrypto.so",
|
||||
"class": "nativeSharedLib",
|
||||
"install_dir": "lib64",
|
||||
"make_module_name": "libcrypto",
|
||||
"package": "foo/bar",
|
||||
"unstripped_built_file": "bazel-out/64/unstripped_libcrypto.so",
|
||||
},
|
||||
{
|
||||
"arch": "arm",
|
||||
"basename": "libcrypto.so",
|
||||
"built_file": "bazel-out/32/libcrypto.so",
|
||||
"class": "nativeSharedLib",
|
||||
"install_dir": "lib",
|
||||
"make_module_name": "libcrypto",
|
||||
"package": "foo/bar",
|
||||
},
|
||||
{
|
||||
"arch": "arm64",
|
||||
"basename": "adbd",
|
||||
"built_file": "bazel-out/adbd",
|
||||
"class": "nativeExecutable",
|
||||
"install_dir": "bin",
|
||||
"make_module_name": "adbd",
|
||||
"package": "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
|
||||
m := result.ModuleForTests("foo", "android_common_foo").Module()
|
||||
ab, ok := m.(*apexBundle)
|
||||
|
||||
if !ok {
|
||||
t.Fatalf("Expected module to be an apexBundle, was not")
|
||||
}
|
||||
|
||||
expectedFilesInfo := []apexFile{
|
||||
{
|
||||
androidMkModuleName: "libcrypto",
|
||||
builtFile: android.PathForTesting("out/bazel/execroot/__main__/bazel-out/64/libcrypto.so"),
|
||||
class: nativeSharedLib,
|
||||
customStem: "libcrypto.so",
|
||||
installDir: "lib64",
|
||||
moduleDir: "foo/bar",
|
||||
arch: "arm64",
|
||||
unstrippedBuiltFile: android.PathForTesting("out/bazel/execroot/__main__/bazel-out/64/unstripped_libcrypto.so"),
|
||||
},
|
||||
{
|
||||
androidMkModuleName: "libcrypto",
|
||||
builtFile: android.PathForTesting("out/bazel/execroot/__main__/bazel-out/32/libcrypto.so"),
|
||||
class: nativeSharedLib,
|
||||
customStem: "libcrypto.so",
|
||||
installDir: "lib",
|
||||
moduleDir: "foo/bar",
|
||||
arch: "arm",
|
||||
},
|
||||
{
|
||||
androidMkModuleName: "adbd",
|
||||
builtFile: android.PathForTesting("out/bazel/execroot/__main__/bazel-out/adbd"),
|
||||
class: nativeExecutable,
|
||||
customStem: "adbd",
|
||||
installDir: "bin",
|
||||
moduleDir: "foo",
|
||||
arch: "arm64",
|
||||
},
|
||||
}
|
||||
|
||||
if len(ab.filesInfo) != len(expectedFilesInfo) {
|
||||
t.Errorf("Expected %d entries in ab.filesInfo, but got %d", len(ab.filesInfo), len(expectedFilesInfo))
|
||||
}
|
||||
|
||||
for idx, f := range ab.filesInfo {
|
||||
expected := expectedFilesInfo[idx]
|
||||
android.AssertSame(t, "different class", expected.class, f.class)
|
||||
android.AssertStringEquals(t, "different built file", expected.builtFile.String(), f.builtFile.String())
|
||||
android.AssertStringEquals(t, "different custom stem", expected.customStem, f.customStem)
|
||||
android.AssertStringEquals(t, "different install dir", expected.installDir, f.installDir)
|
||||
android.AssertStringEquals(t, "different make module name", expected.androidMkModuleName, f.androidMkModuleName)
|
||||
android.AssertStringEquals(t, "different moduleDir", expected.moduleDir, f.moduleDir)
|
||||
android.AssertStringEquals(t, "different arch", expected.arch, f.arch)
|
||||
if expected.unstrippedBuiltFile != nil {
|
||||
if f.unstrippedBuiltFile == nil {
|
||||
t.Errorf("expected an unstripped built file path.")
|
||||
}
|
||||
android.AssertStringEquals(t, "different unstripped built file", expected.unstrippedBuiltFile.String(), f.unstrippedBuiltFile.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompressedApexImageInMixedBuilds(t *testing.T) {
|
||||
bp := `
|
||||
apex_key{
|
||||
name: "foo_key",
|
||||
}
|
||||
apex {
|
||||
name: "foo",
|
||||
key: "foo_key",
|
||||
updatable: true,
|
||||
min_sdk_version: "31",
|
||||
file_contexts: ":myapex-file_contexts",
|
||||
bazel_module: { label: "//:foo" },
|
||||
test_only_force_compression: true, // force compression
|
||||
}`
|
||||
|
||||
outputBaseDir := "out/bazel"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForApexTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outputBaseDir,
|
||||
LabelToApexInfo: map[string]cquery.ApexInfo{
|
||||
"//:foo": cquery.ApexInfo{
|
||||
SignedOutput: "signed_out.apex",
|
||||
SignedCompressedOutput: "signed_out.capex",
|
||||
BundleKeyInfo: []string{"public_key", "private_key"},
|
||||
ContainerKeyInfo: []string{"container_cert", "container_private"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
|
||||
m := result.ModuleForTests("foo", "android_common_foo").Module()
|
||||
ab, ok := m.(*apexBundle)
|
||||
if !ok {
|
||||
t.Fatalf("Expected module to be an apexBundle, was not")
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/signed_out.capex", ab.outputFile.String(); w != g {
|
||||
t.Errorf("Expected output file to be compressed apex %q, got %q", w, g)
|
||||
}
|
||||
|
||||
mkData := android.AndroidMkDataForTest(t, result.TestContext, m)
|
||||
var builder strings.Builder
|
||||
mkData.Custom(&builder, "foo", "BAZEL_TARGET_", "", mkData)
|
||||
|
||||
data := builder.String()
|
||||
|
||||
expectedAndroidMk := []string{
|
||||
"LOCAL_PREBUILT_MODULE_FILE := out/bazel/execroot/__main__/signed_out.capex",
|
||||
|
||||
// Check that the source install file is the capex. The dest is not important.
|
||||
"LOCAL_SOONG_INSTALL_PAIRS := out/bazel/execroot/__main__/signed_out.capex:",
|
||||
}
|
||||
for _, androidMk := range expectedAndroidMk {
|
||||
if !strings.Contains(data, androidMk) {
|
||||
t.Errorf("Expected %q in androidmk data, but did not find %q", androidMk, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverrideApexImageInMixedBuilds(t *testing.T) {
|
||||
originalBp := `
|
||||
apex_key{
|
||||
name: "foo_key",
|
||||
}
|
||||
apex_key{
|
||||
name: "override_foo_key",
|
||||
}
|
||||
apex {
|
||||
name: "foo",
|
||||
key: "foo_key",
|
||||
updatable: true,
|
||||
min_sdk_version: "31",
|
||||
package_name: "pkg_name",
|
||||
file_contexts: ":myapex-file_contexts",
|
||||
%s
|
||||
}`
|
||||
overrideBp := `
|
||||
override_apex {
|
||||
name: "override_foo",
|
||||
key: "override_foo_key",
|
||||
package_name: "override_pkg_name",
|
||||
base: "foo",
|
||||
%s
|
||||
}
|
||||
`
|
||||
|
||||
originalApexBpDir := "original"
|
||||
originalApexName := "foo"
|
||||
overrideApexBpDir := "override"
|
||||
overrideApexName := "override_foo"
|
||||
|
||||
defaultApexLabel := fmt.Sprintf("//%s:%s", originalApexBpDir, originalApexName)
|
||||
defaultOverrideApexLabel := fmt.Sprintf("//%s:%s", overrideApexBpDir, overrideApexName)
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
bazelModuleProp string
|
||||
apexLabel string
|
||||
overrideBazelModuleProp string
|
||||
overrideApexLabel string
|
||||
bp2buildConfiguration android.Bp2BuildConversionAllowlist
|
||||
}{
|
||||
{
|
||||
desc: "both explicit labels",
|
||||
bazelModuleProp: `bazel_module: { label: "//:foo" },`,
|
||||
apexLabel: "//:foo",
|
||||
overrideBazelModuleProp: `bazel_module: { label: "//:override_foo" },`,
|
||||
overrideApexLabel: "//:override_foo",
|
||||
bp2buildConfiguration: android.NewBp2BuildAllowlist(),
|
||||
},
|
||||
{
|
||||
desc: "both explicitly allowed",
|
||||
bazelModuleProp: `bazel_module: { bp2build_available: true },`,
|
||||
apexLabel: defaultApexLabel,
|
||||
overrideBazelModuleProp: `bazel_module: { bp2build_available: true },`,
|
||||
overrideApexLabel: defaultOverrideApexLabel,
|
||||
bp2buildConfiguration: android.NewBp2BuildAllowlist(),
|
||||
},
|
||||
{
|
||||
desc: "original allowed by dir, override allowed by name",
|
||||
apexLabel: defaultApexLabel,
|
||||
overrideApexLabel: defaultOverrideApexLabel,
|
||||
bp2buildConfiguration: android.NewBp2BuildAllowlist().SetDefaultConfig(
|
||||
map[string]allowlists.BazelConversionConfigEntry{
|
||||
originalApexBpDir: allowlists.Bp2BuildDefaultTrue,
|
||||
}).SetModuleAlwaysConvertList([]string{
|
||||
overrideApexName,
|
||||
}),
|
||||
},
|
||||
{
|
||||
desc: "both allowed by name",
|
||||
apexLabel: defaultApexLabel,
|
||||
overrideApexLabel: defaultOverrideApexLabel,
|
||||
bp2buildConfiguration: android.NewBp2BuildAllowlist().SetModuleAlwaysConvertList([]string{
|
||||
originalApexName,
|
||||
overrideApexName,
|
||||
}),
|
||||
},
|
||||
{
|
||||
desc: "override allowed by name",
|
||||
apexLabel: defaultApexLabel,
|
||||
overrideApexLabel: defaultOverrideApexLabel,
|
||||
bp2buildConfiguration: android.NewBp2BuildAllowlist().SetModuleAlwaysConvertList([]string{
|
||||
overrideApexName,
|
||||
}),
|
||||
},
|
||||
{
|
||||
desc: "override allowed by dir",
|
||||
apexLabel: defaultApexLabel,
|
||||
overrideApexLabel: defaultOverrideApexLabel,
|
||||
bp2buildConfiguration: android.NewBp2BuildAllowlist().SetDefaultConfig(
|
||||
map[string]allowlists.BazelConversionConfigEntry{
|
||||
overrideApexBpDir: allowlists.Bp2BuildDefaultTrue,
|
||||
}).SetModuleAlwaysConvertList([]string{}),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
outputBaseDir := "out/bazel"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForApexTest,
|
||||
android.FixtureAddTextFile(filepath.Join(originalApexBpDir, "Android.bp"), fmt.Sprintf(originalBp, tc.bazelModuleProp)),
|
||||
android.FixtureAddTextFile(filepath.Join(overrideApexBpDir, "Android.bp"), fmt.Sprintf(overrideBp, tc.overrideBazelModuleProp)),
|
||||
android.FixtureModifyContext(func(ctx *android.TestContext) {
|
||||
ctx.RegisterBp2BuildConfig(tc.bp2buildConfiguration)
|
||||
}),
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outputBaseDir,
|
||||
LabelToApexInfo: map[string]cquery.ApexInfo{
|
||||
tc.apexLabel: cquery.ApexInfo{
|
||||
// ApexInfo Starlark provider
|
||||
SignedOutput: "signed_out.apex",
|
||||
UnsignedOutput: "unsigned_out.apex",
|
||||
BundleKeyInfo: []string{"public_key", "private_key"},
|
||||
ContainerKeyInfo: []string{"container_cert", "container_private"},
|
||||
SymbolsUsedByApex: "foo_using.txt",
|
||||
JavaSymbolsUsedByApex: "foo_using.xml",
|
||||
BundleFile: "apex_bundle.zip",
|
||||
InstalledFiles: "installed-files.txt",
|
||||
RequiresLibs: []string{"//path/c:c", "//path/d:d"},
|
||||
|
||||
// unused
|
||||
PackageName: "pkg_name",
|
||||
ProvidesLibs: []string{"a", "b"},
|
||||
|
||||
// ApexMkInfo Starlark provider
|
||||
MakeModulesToInstall: []string{"c"}, // d deliberately omitted
|
||||
},
|
||||
tc.overrideApexLabel: cquery.ApexInfo{
|
||||
// ApexInfo Starlark provider
|
||||
SignedOutput: "override_signed_out.apex",
|
||||
UnsignedOutput: "override_unsigned_out.apex",
|
||||
BundleKeyInfo: []string{"override_public_key", "override_private_key"},
|
||||
ContainerKeyInfo: []string{"override_container_cert", "override_container_private"},
|
||||
SymbolsUsedByApex: "override_foo_using.txt",
|
||||
JavaSymbolsUsedByApex: "override_foo_using.xml",
|
||||
BundleFile: "override_apex_bundle.zip",
|
||||
InstalledFiles: "override_installed-files.txt",
|
||||
RequiresLibs: []string{"//path/c:c", "//path/d:d"},
|
||||
|
||||
// unused
|
||||
PackageName: "override_pkg_name",
|
||||
ProvidesLibs: []string{"a", "b"},
|
||||
|
||||
// ApexMkInfo Starlark provider
|
||||
MakeModulesToInstall: []string{"c"}, // d deliberately omitted
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTest(t)
|
||||
|
||||
m := result.ModuleForTests("foo", "android_common_override_foo_foo").Module()
|
||||
ab, ok := m.(*apexBundle)
|
||||
if !ok {
|
||||
t.Fatalf("Expected module to be an apexBundle, was not")
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_public_key", ab.publicKeyFile.String(); w != g {
|
||||
t.Errorf("Expected public key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_private_key", ab.privateKeyFile.String(); w != g {
|
||||
t.Errorf("Expected private key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_container_cert", ab.containerCertificateFile; g != nil && w != g.String() {
|
||||
t.Errorf("Expected public container key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_container_private", ab.containerPrivateKeyFile; g != nil && w != g.String() {
|
||||
t.Errorf("Expected private container key %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_signed_out.apex", ab.outputFile.String(); w != g {
|
||||
t.Errorf("Expected output file %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_foo_using.txt", ab.nativeApisUsedByModuleFile.String(); w != g {
|
||||
t.Errorf("Expected output file %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_foo_using.xml", ab.javaApisUsedByModuleFile.String(); w != g {
|
||||
t.Errorf("Expected output file %q, got %q", w, g)
|
||||
}
|
||||
|
||||
if w, g := "out/bazel/execroot/__main__/override_installed-files.txt", ab.installedFilesFile.String(); w != g {
|
||||
t.Errorf("Expected installed-files.txt %q, got %q", w, g)
|
||||
}
|
||||
|
||||
mkData := android.AndroidMkDataForTest(t, result.TestContext, m)
|
||||
var builder strings.Builder
|
||||
mkData.Custom(&builder, "override_foo", "BAZEL_TARGET_", "", mkData)
|
||||
|
||||
data := builder.String()
|
||||
if w := "ALL_MODULES.$(my_register_name).BUNDLE := out/bazel/execroot/__main__/override_apex_bundle.zip"; !strings.Contains(data, w) {
|
||||
t.Errorf("Expected %q in androidmk data, but did not find %q", w, data)
|
||||
}
|
||||
if w := "$(call dist-for-goals,checkbuild,out/bazel/execroot/__main__/override_installed-files.txt:override_foo-installed-files.txt)"; !strings.Contains(data, w) {
|
||||
t.Errorf("Expected %q in androidmk data, but did not find %q", w, data)
|
||||
}
|
||||
|
||||
// make modules to be installed to system
|
||||
if len(ab.makeModulesToInstall) != 1 || ab.makeModulesToInstall[0] != "c" {
|
||||
t.Errorf("Expected makeModulestoInstall slice to only contain 'c', got %q", ab.makeModulesToInstall)
|
||||
}
|
||||
if w := "LOCAL_REQUIRED_MODULES := c"; !strings.Contains(data, w) {
|
||||
t.Errorf("Expected %q in androidmk data, but did not find it in %q", w, data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
42
apex/key.go
42
apex/key.go
|
@ -18,8 +18,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
|
@ -35,7 +33,6 @@ func registerApexKeyBuildComponents(ctx android.RegistrationContext) {
|
|||
|
||||
type apexKey struct {
|
||||
android.ModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
properties apexKeyProperties
|
||||
|
||||
|
@ -58,7 +55,6 @@ func ApexKeyFactory() android.Module {
|
|||
module := &apexKey{}
|
||||
module.AddProperties(&module.properties)
|
||||
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
||||
android.InitBazelModule(module)
|
||||
return module
|
||||
}
|
||||
|
||||
|
@ -159,41 +155,3 @@ func writeApexKeys(ctx android.ModuleContext, module android.Module) android.Wri
|
|||
android.WriteFileRuleVerbatim(ctx, path, entry.String())
|
||||
return path
|
||||
}
|
||||
|
||||
// For Bazel / bp2build
|
||||
|
||||
type bazelApexKeyAttributes struct {
|
||||
Public_key bazel.LabelAttribute
|
||||
Public_key_name bazel.StringAttribute
|
||||
|
||||
Private_key bazel.LabelAttribute
|
||||
Private_key_name bazel.StringAttribute
|
||||
}
|
||||
|
||||
// ConvertWithBp2build performs conversion apexKey for bp2build
|
||||
func (m *apexKey) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
apexKeyBp2BuildInternal(ctx, m)
|
||||
}
|
||||
|
||||
func apexKeyBp2BuildInternal(ctx android.Bp2buildMutatorContext, module *apexKey) {
|
||||
privateKeyLabelAttribute, privateKeyNameAttribute :=
|
||||
android.BazelStringOrLabelFromProp(ctx, module.properties.Private_key)
|
||||
|
||||
publicKeyLabelAttribute, publicKeyNameAttribute :=
|
||||
android.BazelStringOrLabelFromProp(ctx, module.properties.Public_key)
|
||||
|
||||
attrs := &bazelApexKeyAttributes{
|
||||
Private_key: privateKeyLabelAttribute,
|
||||
Private_key_name: privateKeyNameAttribute,
|
||||
|
||||
Public_key: publicKeyLabelAttribute,
|
||||
Public_key_name: publicKeyNameAttribute,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "apex_key",
|
||||
Bzl_load_location: "//build/bazel/rules/apex:apex_key.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
|
||||
}
|
||||
|
|
|
@ -40,64 +40,8 @@ bootstrap_go_package {
|
|||
"soong-ui-metrics",
|
||||
],
|
||||
testSrcs: [
|
||||
"go_conversion_test.go",
|
||||
"aar_conversion_test.go",
|
||||
"aconfig_conversion_test.go",
|
||||
"aidl_library_conversion_test.go",
|
||||
"android_app_certificate_conversion_test.go",
|
||||
"android_app_conversion_test.go",
|
||||
"android_test_conversion_test.go",
|
||||
"apex_conversion_test.go",
|
||||
"apex_key_conversion_test.go",
|
||||
"build_conversion_test.go",
|
||||
"bp2build_product_config_test.go",
|
||||
"bzl_conversion_test.go",
|
||||
"cc_binary_conversion_test.go",
|
||||
"cc_library_conversion_test.go",
|
||||
"cc_library_headers_conversion_test.go",
|
||||
"cc_library_shared_conversion_test.go",
|
||||
"cc_library_static_conversion_test.go",
|
||||
"cc_object_conversion_test.go",
|
||||
"cc_prebuilt_library_conversion_test.go",
|
||||
"cc_prebuilt_library_shared_test.go",
|
||||
"cc_prebuilt_library_static_test.go",
|
||||
"cc_prebuilt_object_conversion_test.go",
|
||||
"cc_test_conversion_test.go",
|
||||
"cc_yasm_conversion_test.go",
|
||||
"conversion_test.go",
|
||||
"droiddoc_exported_dir_conversion_test.go",
|
||||
"fdo_profile_conversion_test.go",
|
||||
"filegroup_conversion_test.go",
|
||||
"genrule_conversion_test.go",
|
||||
"gensrcs_conversion_test.go",
|
||||
"java_binary_host_conversion_test.go",
|
||||
"java_host_for_device_conversion_test.go",
|
||||
"java_import_conversion_test.go",
|
||||
"java_library_conversion_test.go",
|
||||
"java_library_host_conversion_test.go",
|
||||
"java_plugin_conversion_test.go",
|
||||
"java_proto_conversion_test.go",
|
||||
"java_sdk_library_conversion_test.go",
|
||||
"java_sdk_library_import_conversion_test.go",
|
||||
"java_test_host_conversion_test.go",
|
||||
"license_conversion_test.go",
|
||||
"license_kind_conversion_test.go",
|
||||
"linker_config_conversion_test.go",
|
||||
"package_conversion_test.go",
|
||||
"performance_test.go",
|
||||
"platform_compat_config_conversion_test.go",
|
||||
"prebuilt_etc_conversion_test.go",
|
||||
"python_binary_conversion_test.go",
|
||||
"python_library_conversion_test.go",
|
||||
"python_test_conversion_test.go",
|
||||
"rust_binary_conversion_test.go",
|
||||
"rust_ffi_conversion_test.go",
|
||||
"rust_library_conversion_test.go",
|
||||
"rust_proc_macro_conversion_test.go",
|
||||
"rust_protobuf_conversion_test.go",
|
||||
"sh_conversion_test.go",
|
||||
"sh_test_conversion_test.go",
|
||||
"soong_config_module_type_conversion_test.go",
|
||||
],
|
||||
pluginFor: [
|
||||
"soong_build",
|
||||
|
|
|
@ -1,249 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runAndroidLibraryImportTestWithRegistrationCtxFunc(t *testing.T, registrationCtxFunc func(ctx android.RegistrationContext), tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "android_library_import"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.AARImportFactory
|
||||
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
|
||||
}
|
||||
|
||||
func runAndroidLibraryImportTest(t *testing.T, tc Bp2buildTestCase) {
|
||||
runAndroidLibraryImportTestWithRegistrationCtxFunc(t, func(ctx android.RegistrationContext) {}, tc)
|
||||
}
|
||||
|
||||
func TestConvertAndroidLibrary(t *testing.T) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
||||
Description: "Android Library - simple example",
|
||||
ModuleTypeUnderTest: "android_library",
|
||||
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"lib.java": "",
|
||||
"arm.java": "",
|
||||
"x86.java": "",
|
||||
"res/res.png": "",
|
||||
"manifest/AndroidManifest.xml": "",
|
||||
},
|
||||
StubbedBuildDefinitions: []string{"static_lib_dep"},
|
||||
Blueprint: simpleModule("android_library", "static_lib_dep") + `
|
||||
android_library {
|
||||
name: "TestLib",
|
||||
srcs: ["lib.java"],
|
||||
arch: {
|
||||
arm: {
|
||||
srcs: ["arm.java"],
|
||||
},
|
||||
x86: {
|
||||
srcs: ["x86.java"],
|
||||
}
|
||||
},
|
||||
manifest: "manifest/AndroidManifest.xml",
|
||||
static_libs: ["static_lib_dep"],
|
||||
sdk_version: "current",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget(
|
||||
"android_library",
|
||||
"TestLib",
|
||||
AttrNameToString{
|
||||
"srcs": `["lib.java"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["arm.java"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["x86.java"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"manifest": `"manifest/AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"deps": `[":static_lib_dep"]`,
|
||||
"exports": `[":static_lib_dep"]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
}),
|
||||
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestConvertAndroidLibraryWithNoSources(t *testing.T) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
||||
Description: "Android Library - modules will deps when there are no sources",
|
||||
ModuleTypeUnderTest: "android_library",
|
||||
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
},
|
||||
Blueprint: simpleModule("android_library", "lib_dep") + `
|
||||
android_library {
|
||||
name: "TestLib",
|
||||
srcs: [],
|
||||
manifest: "AndroidManifest.xml",
|
||||
libs: ["lib_dep"],
|
||||
sdk_version: "current",
|
||||
}
|
||||
`,
|
||||
StubbedBuildDefinitions: []string{"lib_dep"},
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget(
|
||||
"android_library",
|
||||
"TestLib",
|
||||
AttrNameToString{
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
},
|
||||
),
|
||||
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestConvertAndroidLibraryImport(t *testing.T) {
|
||||
runAndroidLibraryImportTestWithRegistrationCtxFunc(t,
|
||||
func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("android_library", java.AndroidLibraryFactory)
|
||||
},
|
||||
Bp2buildTestCase{
|
||||
Description: "Android Library Import",
|
||||
StubbedBuildDefinitions: []string{"static_lib_dep", "static_import_dep", "static_import_dep-neverlink"},
|
||||
// Bazel's aar_import can only export *_import targets, so we expect
|
||||
// only "static_import_dep" in exports, but both "static_lib_dep" and
|
||||
// "static_import_dep" in deps
|
||||
Blueprint: simpleModule("android_library", "static_lib_dep") + `
|
||||
android_library_import {
|
||||
name: "TestImport",
|
||||
aars: ["import.aar"],
|
||||
static_libs: ["static_lib_dep", "static_import_dep"],
|
||||
sdk_version: "current",
|
||||
}
|
||||
|
||||
android_library_import {
|
||||
name: "static_import_dep",
|
||||
aars: ["import.aar"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget(
|
||||
"aar_import",
|
||||
"TestImport",
|
||||
AttrNameToString{
|
||||
"aar": `"import.aar"`,
|
||||
"deps": `[
|
||||
":static_lib_dep",
|
||||
":static_import_dep",
|
||||
]`,
|
||||
"exports": `[":static_import_dep"]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
},
|
||||
),
|
||||
MakeNeverlinkDuplicateTarget("android_library", "TestImport"),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestConvertAndroidLibraryKotlin(t *testing.T) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
||||
Description: "Android Library with .kt srcs and common_srcs attribute",
|
||||
ModuleTypeUnderTest: "android_library",
|
||||
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"AndroidManifest.xml": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_library {
|
||||
name: "TestLib",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
common_srcs: ["c.kt"],
|
||||
sdk_version: "current",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget(
|
||||
"android_library",
|
||||
"TestLib",
|
||||
AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"common_srcs": `["c.kt"]`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
}),
|
||||
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestConvertAndroidLibraryKotlinCflags(t *testing.T) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, Bp2buildTestCase{
|
||||
Description: "Android Library with .kt srcs and kotlincflags ",
|
||||
ModuleTypeUnderTest: "android_library",
|
||||
ModuleTypeUnderTestFactory: java.AndroidLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"AndroidManifest.xml": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_library {
|
||||
name: "TestLib",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
kotlincflags: ["-flag1", "-flag2"],
|
||||
sdk_version: "current",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget(
|
||||
"android_library",
|
||||
"TestLib",
|
||||
AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"kotlincflags": `[
|
||||
"-flag1",
|
||||
"-flag2",
|
||||
]`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
}),
|
||||
MakeNeverlinkDuplicateTarget("android_library", "TestLib"),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAarImportFailsToConvertNoAars(t *testing.T) {
|
||||
runAndroidLibraryImportTest(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "Android Library Import with no aars does not convert.",
|
||||
Blueprint: `
|
||||
android_library_import {
|
||||
name: "no_aar_import",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{},
|
||||
})
|
||||
}
|
|
@ -1,254 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/aconfig/codegen"
|
||||
"testing"
|
||||
|
||||
"android/soong/aconfig"
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func registerAconfigModuleTypes(ctx android.RegistrationContext) {
|
||||
aconfig.RegisterBuildComponents(ctx)
|
||||
codegen.RegisterBuildComponents(ctx)
|
||||
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
}
|
||||
|
||||
func TestAconfigDeclarations(t *testing.T) {
|
||||
bp := `
|
||||
aconfig_declarations {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"foo1.aconfig",
|
||||
"test/foo2.aconfig",
|
||||
],
|
||||
package: "com.android.foo",
|
||||
}
|
||||
`
|
||||
expectedBazelTarget := MakeBazelTargetNoRestrictions(
|
||||
"aconfig_declarations",
|
||||
"foo",
|
||||
AttrNameToString{
|
||||
"srcs": `[
|
||||
"foo1.aconfig",
|
||||
"test/foo2.aconfig",
|
||||
]`,
|
||||
"package": `"com.android.foo"`,
|
||||
},
|
||||
)
|
||||
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: []string{expectedBazelTarget},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAconfigValues(t *testing.T) {
|
||||
bp := `
|
||||
aconfig_values {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"foo1.textproto",
|
||||
],
|
||||
package: "com.android.foo",
|
||||
}
|
||||
aconfig_value_set {
|
||||
name: "bar",
|
||||
values: [
|
||||
"foo"
|
||||
]
|
||||
}
|
||||
`
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"aconfig_values",
|
||||
"foo",
|
||||
AttrNameToString{
|
||||
"srcs": `["foo1.textproto"]`,
|
||||
"package": `"com.android.foo"`,
|
||||
},
|
||||
),
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"aconfig_value_set",
|
||||
"bar",
|
||||
AttrNameToString{
|
||||
"values": `[":foo"]`,
|
||||
},
|
||||
)}
|
||||
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcAconfigLibrary(t *testing.T) {
|
||||
bp := `
|
||||
aconfig_declarations {
|
||||
name: "foo_aconfig_declarations",
|
||||
srcs: [
|
||||
"foo1.aconfig",
|
||||
],
|
||||
package: "com.android.foo",
|
||||
}
|
||||
cc_library {
|
||||
name: "server_configurable_flags",
|
||||
srcs: ["bar.cc"],
|
||||
}
|
||||
cc_aconfig_library {
|
||||
name: "foo",
|
||||
aconfig_declarations: "foo_aconfig_declarations",
|
||||
}
|
||||
`
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"aconfig_declarations",
|
||||
"foo_aconfig_declarations",
|
||||
AttrNameToString{
|
||||
"srcs": `["foo1.aconfig"]`,
|
||||
"package": `"com.android.foo"`,
|
||||
},
|
||||
),
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"cc_aconfig_library",
|
||||
"foo",
|
||||
AttrNameToString{
|
||||
"aconfig_declarations": `":foo_aconfig_declarations"`,
|
||||
"dynamic_deps": `[":server_configurable_flags"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
},
|
||||
)}
|
||||
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
StubbedBuildDefinitions: []string{"server_configurable_flags"},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaAconfigLibrary(t *testing.T) {
|
||||
bp := `
|
||||
aconfig_declarations {
|
||||
name: "foo_aconfig_declarations",
|
||||
srcs: [
|
||||
"foo1.aconfig",
|
||||
],
|
||||
package: "com.android.foo",
|
||||
}
|
||||
java_library {
|
||||
name: "foo_java_library",
|
||||
srcs: ["foo.java"],
|
||||
sdk_version: "current",
|
||||
}
|
||||
java_aconfig_library {
|
||||
name: "foo",
|
||||
aconfig_declarations: "foo_aconfig_declarations",
|
||||
libs: ["foo_java_library"],
|
||||
mode: "test",
|
||||
}
|
||||
`
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"aconfig_declarations",
|
||||
"foo_aconfig_declarations",
|
||||
AttrNameToString{
|
||||
"srcs": `["foo1.aconfig"]`,
|
||||
"package": `"com.android.foo"`,
|
||||
},
|
||||
),
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"java_library",
|
||||
"foo_java_library",
|
||||
AttrNameToString{
|
||||
"srcs": `["foo.java"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
},
|
||||
),
|
||||
MakeNeverlinkDuplicateTarget("java_library", "foo_java_library"),
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"java_aconfig_library",
|
||||
"foo",
|
||||
AttrNameToString{
|
||||
"aconfig_declarations": `":foo_aconfig_declarations"`,
|
||||
"libs": `[":foo_java_library-neverlink"]`,
|
||||
"sdk_version": `"system_current"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
},
|
||||
)}
|
||||
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaAconfigLibraryAsTaggedOutput(t *testing.T) {
|
||||
bp := `
|
||||
aconfig_declarations {
|
||||
name: "foo_aconfig_declarations",
|
||||
srcs: [
|
||||
"foo.aconfig",
|
||||
],
|
||||
package: "com.android.foo",
|
||||
}
|
||||
java_library {
|
||||
name: "foo_library",
|
||||
srcs: [":foo_aconfig_library{.generated_srcjars}"],
|
||||
sdk_version: "current",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
java_aconfig_library {
|
||||
name: "foo_aconfig_library",
|
||||
aconfig_declarations: "foo_aconfig_declarations",
|
||||
mode: "test",
|
||||
}
|
||||
`
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"aconfig_declarations",
|
||||
"foo_aconfig_declarations",
|
||||
AttrNameToString{
|
||||
"srcs": `["foo.aconfig"]`,
|
||||
"package": `"com.android.foo"`,
|
||||
},
|
||||
),
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"java_aconfig_library",
|
||||
"foo_aconfig_library",
|
||||
AttrNameToString{
|
||||
"aconfig_declarations": `":foo_aconfig_declarations"`,
|
||||
"sdk_version": `"system_current"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
},
|
||||
),
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"java_library",
|
||||
"foo_library",
|
||||
AttrNameToString{
|
||||
"srcs": `[":foo_aconfig_library.generated_srcjars"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
},
|
||||
),
|
||||
MakeNeverlinkDuplicateTarget("java_library", "foo_library"),
|
||||
}
|
||||
|
||||
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/aidl_library"
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
func runAidlLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "aidl_library"
|
||||
(&tc).ModuleTypeUnderTestFactory = aidl_library.AidlLibraryFactory
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
|
||||
}
|
||||
|
||||
func TestAidlLibrary(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
bp string
|
||||
expectedBazelAttrs AttrNameToString
|
||||
}{
|
||||
{
|
||||
name: "aidl_library with strip_import_prefix",
|
||||
bp: `
|
||||
aidl_library {
|
||||
name: "foo",
|
||||
srcs: ["aidl/foo.aidl"],
|
||||
hdrs: ["aidl/header.aidl"],
|
||||
strip_import_prefix: "aidl",
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `["aidl/foo.aidl"]`,
|
||||
"hdrs": `["aidl/header.aidl"]`,
|
||||
"strip_import_prefix": `"aidl"`,
|
||||
"tags": `["apex_available=//apex_available:anyapex"]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "aidl_library without strip_import_prefix",
|
||||
bp: `
|
||||
aidl_library {
|
||||
name: "foo",
|
||||
srcs: ["aidl/foo.aidl"],
|
||||
hdrs: ["aidl/header.aidl"],
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `["aidl/foo.aidl"]`,
|
||||
"hdrs": `["aidl/header.aidl"]`,
|
||||
"tags": `["apex_available=//apex_available:anyapex"]`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
|
||||
}
|
||||
runAidlLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: test.name,
|
||||
Blueprint: test.bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAidlLibraryWithDeps(t *testing.T) {
|
||||
bp := `
|
||||
aidl_library {
|
||||
name: "bar",
|
||||
srcs: ["Bar.aidl"],
|
||||
hdrs: ["aidl/BarHeader.aidl"],
|
||||
}
|
||||
aidl_library {
|
||||
name: "foo",
|
||||
srcs: ["aidl/Foo.aidl"],
|
||||
hdrs: ["aidl/FooHeader.aidl"],
|
||||
strip_import_prefix: "aidl",
|
||||
deps: ["bar"],
|
||||
}`
|
||||
|
||||
t.Run("aidl_library with deps", func(t *testing.T) {
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions("aidl_library", "bar", AttrNameToString{
|
||||
"srcs": `["Bar.aidl"]`,
|
||||
"hdrs": `["aidl/BarHeader.aidl"]`,
|
||||
"tags": `["apex_available=//apex_available:anyapex"]`,
|
||||
}),
|
||||
MakeBazelTargetNoRestrictions("aidl_library", "foo", AttrNameToString{
|
||||
"srcs": `["aidl/Foo.aidl"]`,
|
||||
"hdrs": `["aidl/FooHeader.aidl"]`,
|
||||
"strip_import_prefix": `"aidl"`,
|
||||
"deps": `[":bar"]`,
|
||||
"tags": `["apex_available=//apex_available:anyapex"]`,
|
||||
}),
|
||||
}
|
||||
runAidlLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "aidl_library with deps",
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runAndroidAppCertificateTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerAndroidAppCertificateModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerAndroidAppCertificateModuleTypes(ctx android.RegistrationContext) {
|
||||
}
|
||||
|
||||
func TestAndroidAppCertificateSimple(t *testing.T) {
|
||||
runAndroidAppCertificateTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app certificate - simple example",
|
||||
ModuleTypeUnderTest: "android_app_certificate",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppCertificateFactory,
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
android_app_certificate {
|
||||
name: "com.android.apogee.cert",
|
||||
certificate: "chamber_of_secrets_dir",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("android_app_certificate", "com.android.apogee.cert", AttrNameToString{
|
||||
"certificate": `"chamber_of_secrets_dir"`,
|
||||
}),
|
||||
}})
|
||||
}
|
|
@ -1,518 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/java"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runAndroidAppTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerAndroidAppModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerAndroidAppModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
|
||||
}
|
||||
|
||||
func TestMinimalAndroidApp(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app - simple example",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"app.java": "",
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
"assets/asset.png": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "TestApp",
|
||||
srcs: ["app.java"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
shrink: true,
|
||||
optimize: true,
|
||||
obfuscate: true,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"srcs": `["app.java"]`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"assets": `["assets/asset.png"]`,
|
||||
"assets_dir": `"assets"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppAllSupportedFields(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app - all supported fields",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"app.java": "",
|
||||
"resa/res.png": "",
|
||||
"resb/res.png": "",
|
||||
"manifest/AndroidManifest.xml": "",
|
||||
"assets_/asset.png": "",
|
||||
},
|
||||
StubbedBuildDefinitions: []string{"static_lib_dep", "jni_lib"},
|
||||
Blueprint: simpleModule("android_app", "static_lib_dep") +
|
||||
simpleModule("cc_library_shared", "jni_lib") + `
|
||||
android_app {
|
||||
name: "TestApp",
|
||||
srcs: ["app.java"],
|
||||
sdk_version: "current",
|
||||
package_name: "com.google",
|
||||
resource_dirs: ["resa", "resb"],
|
||||
manifest: "manifest/AndroidManifest.xml",
|
||||
static_libs: ["static_lib_dep"],
|
||||
java_version: "7",
|
||||
certificate: "foocert",
|
||||
required: ["static_lib_dep"],
|
||||
asset_dirs: ["assets_"],
|
||||
optimize: {
|
||||
enabled: true,
|
||||
optimize: false,
|
||||
proguard_flags_files: ["proguard.flags"],
|
||||
shrink: false,
|
||||
obfuscate: false,
|
||||
ignore_warnings: true,
|
||||
},
|
||||
jni_libs: ["jni_lib"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"srcs": `["app.java"]`,
|
||||
"manifest": `"manifest/AndroidManifest.xml"`,
|
||||
"resource_files": `[
|
||||
"resa/res.png",
|
||||
"resb/res.png",
|
||||
]`,
|
||||
"assets": `["assets_/asset.png"]`,
|
||||
"assets_dir": `"assets_"`,
|
||||
"custom_package": `"com.google"`,
|
||||
"deps": `[
|
||||
":static_lib_dep",
|
||||
":jni_lib",
|
||||
]`,
|
||||
"java_version": `"7"`,
|
||||
"sdk_version": `"current"`,
|
||||
"certificate_name": `"foocert"`,
|
||||
"proguard_specs": `[
|
||||
"proguard.flags",
|
||||
":TestApp_proguard_flags",
|
||||
]`,
|
||||
}),
|
||||
MakeBazelTarget("genrule", "TestApp_proguard_flags", AttrNameToString{
|
||||
"outs": `["TestApp_proguard.flags"]`,
|
||||
"cmd": `"echo -ignorewarning -dontshrink -dontoptimize -dontobfuscate > $(OUTS)"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppArchVariantSrcs(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app - arch variant srcs",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"arm.java": "",
|
||||
"x86.java": "",
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "TestApp",
|
||||
sdk_version: "current",
|
||||
arch: {
|
||||
arm: {
|
||||
srcs: ["arm.java"],
|
||||
},
|
||||
x86: {
|
||||
srcs: ["x86.java"],
|
||||
}
|
||||
},
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"srcs": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["arm.java"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["x86.java"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppCertIsModule(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app - cert is module",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"foocert"},
|
||||
Blueprint: simpleModule("filegroup", "foocert") + `
|
||||
android_app {
|
||||
name: "TestApp",
|
||||
certificate: ":foocert",
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"certificate": `":foocert"`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppCertIsSrcFile(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app - cert is src file",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"foocert": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "TestApp",
|
||||
certificate: "foocert",
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"certificate": `"foocert"`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppCertIsNotSrcOrModule(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app - cert is not src or module",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
// deliberate empty
|
||||
},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "TestApp",
|
||||
certificate: "foocert",
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"certificate_name": `"foocert"`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppLibs(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with libs",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"barLib"},
|
||||
Blueprint: simpleModule("java_library", "barLib") + `
|
||||
android_app {
|
||||
name: "foo",
|
||||
libs: ["barLib"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"deps": `[":barLib-neverlink"]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppKotlinSrcs(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with kotlin sources and common_srcs",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"res/res.png": "",
|
||||
},
|
||||
StubbedBuildDefinitions: []string{"foocert", "barLib"},
|
||||
Blueprint: simpleModule("filegroup", "foocert") +
|
||||
simpleModule("java_library", "barLib") + `
|
||||
android_app {
|
||||
name: "foo",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
certificate: ":foocert",
|
||||
manifest: "fooManifest.xml",
|
||||
libs: ["barLib"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"deps": `[":barLib-neverlink"]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
}),
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"deps": `[":foo_kt"]`,
|
||||
"certificate": `":foocert"`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppCommonSrcs(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with common_srcs",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"res/res.png": "",
|
||||
},
|
||||
StubbedBuildDefinitions: []string{"barLib"},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "foo",
|
||||
srcs: ["a.java"],
|
||||
common_srcs: ["b.kt"],
|
||||
manifest: "fooManifest.xml",
|
||||
libs: ["barLib"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
java_library{
|
||||
name: "barLib",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
|
||||
"srcs": `["a.java"]`,
|
||||
"common_srcs": `["b.kt"]`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"deps": `[":barLib-neverlink"]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
}),
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"deps": `[":foo_kt"]`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppKotlinCflags(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with kotlincflags",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"res/res.png": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "foo",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
manifest: "fooManifest.xml",
|
||||
kotlincflags: ["-flag1", "-flag2"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"kotlincflags": `[
|
||||
"-flag1",
|
||||
"-flag2",
|
||||
]`,
|
||||
"sdk_version": `"current"`, // use as default
|
||||
}),
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"deps": `[":foo_kt"]`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"sdk_version": `"current"`,
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppManifestSdkVersionsProvided(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with value for min_sdk_version",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "foo",
|
||||
sdk_version: "current",
|
||||
min_sdk_version: "24",
|
||||
target_sdk_version: "29",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"manifest_values": `{
|
||||
"minSdkVersion": "24",
|
||||
"targetSdkVersion": "29",
|
||||
}`,
|
||||
"sdk_version": `"current"`,
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppMinAndTargetSdkDefaultToSdkVersion(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with value for sdk_version",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "foo",
|
||||
sdk_version: "30",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `[]`,
|
||||
"sdk_version": `"30"`,
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestFrameworkResConversion(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Framework Res custom conversion",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"res/values/attrs.xml": "",
|
||||
"resource_zip.zip": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
name: "framework-res",
|
||||
resource_zips: [
|
||||
"resource_zip.zip",
|
||||
],
|
||||
certificate: "platform",
|
||||
}
|
||||
|
||||
filegroup {
|
||||
name: "framework-res-package-jar",
|
||||
srcs: [":framework-res{.export-package.apk}"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("framework_resources", "framework-res", AttrNameToString{
|
||||
"certificate_name": `"platform"`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/values/attrs.xml"]`,
|
||||
"resource_zips": `["resource_zip.zip"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
}),
|
||||
MakeBazelTargetNoRestrictions("filegroup", "framework-res-package-jar", AttrNameToString{
|
||||
"srcs": `[":framework-res.export-package.apk"]`,
|
||||
}),
|
||||
}})
|
||||
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runAndroidTestTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerAndroidTestModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerAndroidTestModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
}
|
||||
|
||||
func TestMinimalAndroidTest(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android test - simple example",
|
||||
ModuleTypeUnderTest: "android_test",
|
||||
ModuleTypeUnderTestFactory: java.AndroidTestFactory,
|
||||
Filesystem: map[string]string{
|
||||
"app.java": "",
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
"assets/asset.png": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_test {
|
||||
name: "TestApp",
|
||||
srcs: ["app.java"],
|
||||
sdk_version: "current",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_test", "TestApp", AttrNameToString{
|
||||
"srcs": `["app.java"]`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"assets": `["assets/asset.png"]`,
|
||||
"assets_dir": `"assets"`,
|
||||
// no need for optimize = False because it's false for
|
||||
// android_test by default
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidTest_OptimizationEnabled(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android test - simple example",
|
||||
ModuleTypeUnderTest: "android_test",
|
||||
ModuleTypeUnderTestFactory: java.AndroidTestFactory,
|
||||
Filesystem: map[string]string{
|
||||
"app.java": "",
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
"assets/asset.png": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_test {
|
||||
name: "TestApp",
|
||||
srcs: ["app.java"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: true,
|
||||
shrink: true,
|
||||
optimize: true,
|
||||
obfuscate: true,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_test", "TestApp", AttrNameToString{
|
||||
"srcs": `["app.java"]`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"assets": `["assets/asset.png"]`,
|
||||
"assets_dir": `"assets"`,
|
||||
// optimize = True because it's false for android_test by
|
||||
// default
|
||||
"optimize": `True`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestMinimalAndroidTestHelperApp(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android test helper app - simple example",
|
||||
ModuleTypeUnderTest: "android_test_helper_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidTestHelperAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"app.java": "",
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
"assets/asset.png": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_test_helper_app {
|
||||
name: "TestApp",
|
||||
srcs: ["app.java"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
shrink: true,
|
||||
optimize: true,
|
||||
obfuscate: true,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"srcs": `["app.java"]`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"assets": `["assets/asset.png"]`,
|
||||
"assets_dir": `"assets"`,
|
||||
"testonly": `True`,
|
||||
// no need for optimize = True because it's true for
|
||||
// android_test_helper_app by default
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidTestHelperApp_OptimizationDisabled(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android test helper app - simple example",
|
||||
ModuleTypeUnderTest: "android_test_helper_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidTestHelperAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"app.java": "",
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
"assets/asset.png": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_test_helper_app {
|
||||
name: "TestApp",
|
||||
srcs: ["app.java"],
|
||||
sdk_version: "current",
|
||||
optimize: {
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("android_binary", "TestApp", AttrNameToString{
|
||||
"srcs": `["app.java"]`,
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"assets": `["assets/asset.png"]`,
|
||||
"assets_dir": `"assets"`,
|
||||
"testonly": `True`,
|
||||
// optimize = False because it's true for
|
||||
// android_test_helper_app by default
|
||||
"optimize": `False`,
|
||||
}),
|
||||
}})
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,101 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/apex"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerApexKeyModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerApexKeyModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}
|
||||
|
||||
func TestApexKeySimple_KeysAreSrcFilesInSameDir(t *testing.T) {
|
||||
runApexKeyTestCase(t, Bp2buildTestCase{
|
||||
Description: "apex key - keys are src files, use key attributes",
|
||||
ModuleTypeUnderTest: "apex_key",
|
||||
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
|
||||
Filesystem: map[string]string{
|
||||
"com.android.apogee.avbpubkey": "",
|
||||
"com.android.apogee.pem": "",
|
||||
},
|
||||
Blueprint: `
|
||||
apex_key {
|
||||
name: "com.android.apogee.key",
|
||||
public_key: "com.android.apogee.avbpubkey",
|
||||
private_key: "com.android.apogee.pem",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
|
||||
"private_key": `"com.android.apogee.pem"`,
|
||||
"public_key": `"com.android.apogee.avbpubkey"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestApexKeySimple_KeysAreSrcFilesNotInDir(t *testing.T) {
|
||||
runApexKeyTestCase(t, Bp2buildTestCase{
|
||||
Description: "apex key - keys are not src or module, use key_name attributes",
|
||||
ModuleTypeUnderTest: "apex_key",
|
||||
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
|
||||
Filesystem: map[string]string{
|
||||
// deliberately left empty
|
||||
},
|
||||
Blueprint: `
|
||||
apex_key {
|
||||
name: "com.android.apogee.key",
|
||||
public_key: "com.android.apogee.avbpubkey",
|
||||
private_key: "com.android.apogee.pem",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
|
||||
"private_key_name": `"com.android.apogee.pem"`,
|
||||
"public_key_name": `"com.android.apogee.avbpubkey"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestApexKey_KeysAreModules(t *testing.T) {
|
||||
runApexKeyTestCase(t, Bp2buildTestCase{
|
||||
Description: "apex key - keys are modules, use key attributes",
|
||||
ModuleTypeUnderTest: "apex_key",
|
||||
ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"com.android.apogee.avbpubkey", "com.android.apogee.pem"},
|
||||
Blueprint: `
|
||||
apex_key {
|
||||
name: "com.android.apogee.key",
|
||||
public_key: ":com.android.apogee.avbpubkey",
|
||||
private_key: ":com.android.apogee.pem",
|
||||
}
|
||||
` + simpleModule("filegroup", "com.android.apogee.avbpubkey") +
|
||||
simpleModule("filegroup", "com.android.apogee.pem"),
|
||||
ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
|
||||
"private_key": `":com.android.apogee.pem"`,
|
||||
"public_key": `":com.android.apogee.avbpubkey"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
}),
|
||||
}})
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/starlark_import"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/google/blueprint/proptools"
|
||||
"go.starlark.net/starlark"
|
||||
)
|
||||
|
||||
func createStarlarkValue(t *testing.T, code string) starlark.Value {
|
||||
t.Helper()
|
||||
result, err := starlark.ExecFile(&starlark.Thread{}, "main.bzl", "x = "+code, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
return result["x"]
|
||||
}
|
||||
|
||||
func createStarlarkProductVariablesMap(t *testing.T, code string) map[string]starlark.Value {
|
||||
t.Helper()
|
||||
rawValue := createStarlarkValue(t, code)
|
||||
value, err := starlark_import.Unmarshal[map[string]starlark.Value](rawValue)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func TestStarlarkMapToProductVariables(t *testing.T) {
|
||||
thirty := 30
|
||||
cases := []struct {
|
||||
starlark string
|
||||
result android.ProductVariables
|
||||
}{
|
||||
{
|
||||
starlark: `{"CompressedApex": True}`,
|
||||
result: android.ProductVariables{CompressedApex: proptools.BoolPtr(true)},
|
||||
},
|
||||
{
|
||||
starlark: `{"ApexGlobalMinSdkVersionOverride": "Tiramisu"}`,
|
||||
result: android.ProductVariables{ApexGlobalMinSdkVersionOverride: proptools.StringPtr("Tiramisu")},
|
||||
},
|
||||
{
|
||||
starlark: `{"ProductManufacturer": "Google"}`,
|
||||
result: android.ProductVariables{ProductManufacturer: "Google"},
|
||||
},
|
||||
{
|
||||
starlark: `{"Unbundled_build_apps": ["app1", "app2"]}`,
|
||||
result: android.ProductVariables{Unbundled_build_apps: []string{"app1", "app2"}},
|
||||
},
|
||||
{
|
||||
starlark: `{"Platform_sdk_version": 30}`,
|
||||
result: android.ProductVariables{Platform_sdk_version: &thirty},
|
||||
},
|
||||
{
|
||||
starlark: `{"HostFakeSnapshotEnabled": True}`,
|
||||
result: android.ProductVariables{HostFakeSnapshotEnabled: true},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range cases {
|
||||
productVariables, err := starlarkMapToProductVariables(createStarlarkProductVariablesMap(t,
|
||||
testCase.starlark))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
testCase.result.Native_coverage = proptools.BoolPtr(false)
|
||||
if !reflect.DeepEqual(testCase.result, productVariables) {
|
||||
expected, err := json.Marshal(testCase.result)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
actual, err := json.Marshal(productVariables)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
expectedStr := string(expected)
|
||||
actualStr := string(actual)
|
||||
t.Errorf("expected %q, but got %q", expectedStr, actualStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSystemPartitionDeps(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
|
||||
}, Bp2buildTestCase{
|
||||
ExtraFixturePreparer: android.GroupFixturePreparers(
|
||||
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||
deviceProduct := "aosp_arm64"
|
||||
variables.DeviceProduct = &deviceProduct
|
||||
partitionVars := &variables.PartitionVarsForBazelMigrationOnlyDoNotUse
|
||||
partitionVars.ProductDirectory = "build/make/target/product/"
|
||||
partitionVars.ProductPackages = []string{"foo"}
|
||||
var systemVars android.PartitionQualifiedVariablesType
|
||||
systemVars.BuildingImage = true
|
||||
partitionVars.PartitionQualifiedVariables = map[string]android.PartitionQualifiedVariablesType{
|
||||
"system": systemVars,
|
||||
}
|
||||
}),
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
// MockBazelContext will pretend everything is mixed-builds allowlisted.
|
||||
// The default is noopBazelContext, which does the opposite.
|
||||
config.BazelContext = android.MockBazelContext{}
|
||||
}),
|
||||
),
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{`android_product(
|
||||
name = "aosp_arm64",
|
||||
soong_variables = _soong_variables,
|
||||
)`, `partition(
|
||||
name = "system_image",
|
||||
base_staging_dir = "//build/bazel/bazel_sandwich:system_staging_dir",
|
||||
base_staging_dir_file_list = "//build/bazel/bazel_sandwich:system_staging_dir_file_list",
|
||||
root_dir = "//build/bazel/bazel_sandwich:root_staging_dir",
|
||||
selinux_file_contexts = "//build/bazel/bazel_sandwich:selinux_file_contexts",
|
||||
image_properties = """
|
||||
building_system_image=true
|
||||
erofs_sparse_flag=-s
|
||||
extfs_sparse_flag=-s
|
||||
f2fs_sparse_flag=-S
|
||||
skip_fsck=true
|
||||
squashfs_sparse_flag=-s
|
||||
system_disable_sparse=true
|
||||
|
||||
""",
|
||||
deps = [
|
||||
"//:foo",
|
||||
],
|
||||
|
||||
type = "system",
|
||||
)`, `partition_diff_test(
|
||||
name = "system_image_test",
|
||||
partition1 = "//build/bazel/bazel_sandwich:make_system_image",
|
||||
partition2 = ":system_image",
|
||||
)`, `run_test_in_build(
|
||||
name = "run_system_image_test",
|
||||
test = ":system_image_test",
|
||||
)`},
|
||||
Dir: "build/make/target/product/aosp_arm64",
|
||||
RunBp2buildProductConfig: true,
|
||||
})
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bpf"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runBpfTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "bpf"
|
||||
(&tc).ModuleTypeUnderTestFactory = bpf.BpfFactory
|
||||
RunBp2BuildTestCase(t, registerBpfModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerBpfModuleTypes(ctx android.RegistrationContext) {}
|
||||
|
||||
func TestBpfSupportedAttrs(t *testing.T) {
|
||||
runBpfTestCase(t, Bp2buildTestCase{
|
||||
Description: "Bpf module only converts supported attributes",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
bpf {
|
||||
name: "bpfTestOut.o",
|
||||
srcs: ["bpfTestSrcOne.c",
|
||||
"bpfTestSrcTwo.c"],
|
||||
btf: true,
|
||||
cflags: ["-bpfCflagOne",
|
||||
"-bpfCflagTwo"],
|
||||
include_dirs: ["ia/ib/ic"],
|
||||
sub_dir: "sa/ab",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("bpf", "bpfTestOut.o", AttrNameToString{
|
||||
"absolute_includes": `["ia/ib/ic"]`,
|
||||
"btf": `True`,
|
||||
"copts": `[
|
||||
"-bpfCflagOne",
|
||||
"-bpfCflagTwo",
|
||||
]`,
|
||||
"srcs": `[
|
||||
"bpfTestSrcOne.c",
|
||||
"bpfTestSrcTwo.c",
|
||||
]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,241 +0,0 @@
|
|||
// Copyright 2020 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
func setUp() {
|
||||
var err error
|
||||
buildDir, err = ioutil.TempDir("", "bazel_queryview_test")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func tearDown() {
|
||||
os.RemoveAll(buildDir)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
run := func() int {
|
||||
setUp()
|
||||
defer tearDown()
|
||||
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
os.Exit(run())
|
||||
}
|
||||
|
||||
func TestGenerateModuleRuleShims(t *testing.T) {
|
||||
moduleTypeFactories := map[string]android.ModuleFactory{
|
||||
"custom": customModuleFactoryBase,
|
||||
"custom_test": customTestModuleFactoryBase,
|
||||
"custom_defaults": customDefaultsModuleFactoryBasic,
|
||||
}
|
||||
ruleShims := CreateRuleShims(moduleTypeFactories)
|
||||
|
||||
if len(ruleShims) != 1 {
|
||||
t.Errorf("Expected to generate 1 rule shim, but got %d", len(ruleShims))
|
||||
}
|
||||
|
||||
ruleShim := ruleShims["bp2build"]
|
||||
expectedRules := []string{
|
||||
"custom",
|
||||
"custom_defaults",
|
||||
"custom_test_",
|
||||
}
|
||||
|
||||
if len(ruleShim.rules) != len(expectedRules) {
|
||||
t.Errorf("Expected %d rules, but got %d", len(expectedRules), len(ruleShim.rules))
|
||||
}
|
||||
|
||||
for i, rule := range ruleShim.rules {
|
||||
if rule != expectedRules[i] {
|
||||
t.Errorf("Expected rule shim to contain %s, but got %s", expectedRules[i], rule)
|
||||
}
|
||||
}
|
||||
expectedBzl := `load("//build/bazel/queryview_rules:providers.bzl", "SoongModuleInfo")
|
||||
|
||||
def _custom_impl(ctx):
|
||||
return [SoongModuleInfo()]
|
||||
|
||||
custom = rule(
|
||||
implementation = _custom_impl,
|
||||
attrs = {
|
||||
"soong_module_name": attr.string(mandatory = True),
|
||||
"soong_module_variant": attr.string(),
|
||||
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
||||
"api": attr.string(),
|
||||
"arch_paths": attr.string_list(),
|
||||
"arch_paths_exclude": attr.string_list(),
|
||||
# bazel_module start
|
||||
# "label": attr.string(),
|
||||
# "bp2build_available": attr.bool(),
|
||||
# bazel_module end
|
||||
"bool_prop": attr.bool(),
|
||||
"bool_ptr_prop": attr.bool(),
|
||||
"dir": attr.string(),
|
||||
"does_not_convert_to_bazel": attr.bool(),
|
||||
"embedded_prop": attr.string(),
|
||||
"int64_ptr_prop": attr.int(),
|
||||
# nested_props start
|
||||
# "nested_prop": attr.string(),
|
||||
# nested_props end
|
||||
# nested_props_ptr start
|
||||
# "nested_prop": attr.string(),
|
||||
# nested_props_ptr end
|
||||
"one_to_many_prop": attr.bool(),
|
||||
"other_embedded_prop": attr.string(),
|
||||
"string_list_prop": attr.string_list(),
|
||||
"string_literal_prop": attr.string(),
|
||||
"string_prop": attr.string(),
|
||||
"string_ptr_prop": attr.string(),
|
||||
"test_config_setting": attr.bool(),
|
||||
},
|
||||
)
|
||||
|
||||
def _custom_defaults_impl(ctx):
|
||||
return [SoongModuleInfo()]
|
||||
|
||||
custom_defaults = rule(
|
||||
implementation = _custom_defaults_impl,
|
||||
attrs = {
|
||||
"soong_module_name": attr.string(mandatory = True),
|
||||
"soong_module_variant": attr.string(),
|
||||
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
||||
"api": attr.string(),
|
||||
"arch_paths": attr.string_list(),
|
||||
"arch_paths_exclude": attr.string_list(),
|
||||
"bool_prop": attr.bool(),
|
||||
"bool_ptr_prop": attr.bool(),
|
||||
"dir": attr.string(),
|
||||
"does_not_convert_to_bazel": attr.bool(),
|
||||
"embedded_prop": attr.string(),
|
||||
"int64_ptr_prop": attr.int(),
|
||||
# nested_props start
|
||||
# "nested_prop": attr.string(),
|
||||
# nested_props end
|
||||
# nested_props_ptr start
|
||||
# "nested_prop": attr.string(),
|
||||
# nested_props_ptr end
|
||||
"one_to_many_prop": attr.bool(),
|
||||
"other_embedded_prop": attr.string(),
|
||||
"string_list_prop": attr.string_list(),
|
||||
"string_literal_prop": attr.string(),
|
||||
"string_prop": attr.string(),
|
||||
"string_ptr_prop": attr.string(),
|
||||
"test_config_setting": attr.bool(),
|
||||
},
|
||||
)
|
||||
|
||||
def _custom_test__impl(ctx):
|
||||
return [SoongModuleInfo()]
|
||||
|
||||
custom_test_ = rule(
|
||||
implementation = _custom_test__impl,
|
||||
attrs = {
|
||||
"soong_module_name": attr.string(mandatory = True),
|
||||
"soong_module_variant": attr.string(),
|
||||
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
|
||||
"api": attr.string(),
|
||||
"arch_paths": attr.string_list(),
|
||||
"arch_paths_exclude": attr.string_list(),
|
||||
"bool_prop": attr.bool(),
|
||||
"bool_ptr_prop": attr.bool(),
|
||||
"dir": attr.string(),
|
||||
"does_not_convert_to_bazel": attr.bool(),
|
||||
"embedded_prop": attr.string(),
|
||||
"int64_ptr_prop": attr.int(),
|
||||
# nested_props start
|
||||
# "nested_prop": attr.string(),
|
||||
# nested_props end
|
||||
# nested_props_ptr start
|
||||
# "nested_prop": attr.string(),
|
||||
# nested_props_ptr end
|
||||
"one_to_many_prop": attr.bool(),
|
||||
"other_embedded_prop": attr.string(),
|
||||
"string_list_prop": attr.string_list(),
|
||||
"string_literal_prop": attr.string(),
|
||||
"string_prop": attr.string(),
|
||||
"string_ptr_prop": attr.string(),
|
||||
"test_config_setting": attr.bool(),
|
||||
# test_prop start
|
||||
# "test_string_prop": attr.string(),
|
||||
# test_prop end
|
||||
},
|
||||
)
|
||||
`
|
||||
|
||||
if ruleShim.content != expectedBzl {
|
||||
t.Errorf(
|
||||
"Expected the generated rule shim bzl to be:\n%s\nbut got:\n%s",
|
||||
expectedBzl,
|
||||
ruleShim.content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateSoongModuleBzl(t *testing.T) {
|
||||
ruleShims := map[string]RuleShim{
|
||||
"file1": RuleShim{
|
||||
rules: []string{"a", "b"},
|
||||
content: "irrelevant",
|
||||
},
|
||||
"file2": RuleShim{
|
||||
rules: []string{"c", "d"},
|
||||
content: "irrelevant",
|
||||
},
|
||||
}
|
||||
files := CreateBazelFiles(ruleShims, make(map[string]BazelTargets), QueryView)
|
||||
|
||||
var actualSoongModuleBzl BazelFile
|
||||
for _, f := range files {
|
||||
if f.Basename == "soong_module.bzl" {
|
||||
actualSoongModuleBzl = f
|
||||
}
|
||||
}
|
||||
|
||||
expectedLoad := `load("//build/bazel/queryview_rules:file1.bzl", "a", "b")
|
||||
load("//build/bazel/queryview_rules:file2.bzl", "c", "d")
|
||||
`
|
||||
expectedRuleMap := `soong_module_rule_map = {
|
||||
"a": a,
|
||||
"b": b,
|
||||
"c": c,
|
||||
"d": d,
|
||||
}`
|
||||
if !strings.Contains(actualSoongModuleBzl.Contents, expectedLoad) {
|
||||
t.Errorf(
|
||||
"Generated soong_module.bzl:\n\n%s\n\n"+
|
||||
"Could not find the load statement in the generated soong_module.bzl:\n%s",
|
||||
actualSoongModuleBzl.Contents,
|
||||
expectedLoad)
|
||||
}
|
||||
|
||||
if !strings.Contains(actualSoongModuleBzl.Contents, expectedRuleMap) {
|
||||
t.Errorf(
|
||||
"Generated soong_module.bzl:\n\n%s\n\n"+
|
||||
"Could not find the module -> rule map in the generated soong_module.bzl:\n%s",
|
||||
actualSoongModuleBzl.Contents,
|
||||
expectedRuleMap)
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,486 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
const (
|
||||
// See cc/testing.go for more context
|
||||
soongCcLibraryHeadersPreamble = `
|
||||
cc_defaults {
|
||||
name: "linux_bionic_supported",
|
||||
}`
|
||||
)
|
||||
|
||||
func TestCcLibraryHeadersLoadStatement(t *testing.T) {
|
||||
testCases := []struct {
|
||||
bazelTargets BazelTargets
|
||||
expectedLoadStatements string
|
||||
}{
|
||||
{
|
||||
bazelTargets: BazelTargets{
|
||||
BazelTarget{
|
||||
name: "cc_library_headers_target",
|
||||
ruleClass: "cc_library_headers",
|
||||
// Note: no bzlLoadLocation for native rules
|
||||
},
|
||||
},
|
||||
expectedLoadStatements: ``,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
actual := testCase.bazelTargets.LoadStatements()
|
||||
expected := testCase.expectedLoadStatements
|
||||
if actual != expected {
|
||||
t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func registerCcLibraryHeadersModuleTypes(ctx android.RegistrationContext) {
|
||||
cc.RegisterCCBuildComponents(ctx)
|
||||
cc.RegisterLibraryHeadersBuildComponents(ctx)
|
||||
ctx.RegisterModuleType("cc_library_shared", cc.LibrarySharedFactory)
|
||||
}
|
||||
|
||||
func runCcLibraryHeadersTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerCcLibraryHeadersModuleTypes, tc)
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersSimple(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers test",
|
||||
Filesystem: map[string]string{
|
||||
"dir-1/dir1a.h": "",
|
||||
"dir-1/dir1b.h": "",
|
||||
"dir-2/dir2a.h": "",
|
||||
"dir-2/dir2b.h": "",
|
||||
"arch_arm64_exported_include_dir/a.h": "",
|
||||
"arch_x86_exported_include_dir/b.h": "",
|
||||
"arch_x86_64_exported_include_dir/c.h": "",
|
||||
},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_library_headers {
|
||||
name: "foo_headers",
|
||||
export_include_dirs: ["dir-1", "dir-2"],
|
||||
|
||||
arch: {
|
||||
arm64: {
|
||||
// We expect dir-1 headers to be dropped, because dir-1 is already in export_include_dirs
|
||||
export_include_dirs: ["arch_arm64_exported_include_dir", "dir-1"],
|
||||
},
|
||||
x86: {
|
||||
export_include_dirs: ["arch_x86_exported_include_dir"],
|
||||
},
|
||||
x86_64: {
|
||||
export_include_dirs: ["arch_x86_64_exported_include_dir"],
|
||||
},
|
||||
},
|
||||
sdk_version: "current",
|
||||
min_sdk_version: "29",
|
||||
|
||||
// TODO: Also support export_header_lib_headers
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"export_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["arch_arm64_exported_include_dir"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["arch_x86_exported_include_dir"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86_64": ["arch_x86_64_exported_include_dir"],
|
||||
"//conditions:default": [],
|
||||
}) + [
|
||||
"dir-1",
|
||||
"dir-2",
|
||||
]`,
|
||||
"sdk_version": `"current"`,
|
||||
"min_sdk_version": `"29"`,
|
||||
"deps": `select({
|
||||
"//build/bazel/rules/apex:unbundled_app": ["//build/bazel/rules/cc:ndk_sysroot"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// header_libs has "variant_prepend" tag. In bp2build output,
|
||||
// variant info(select) should go before general info.
|
||||
func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers test with os-specific header_libs props",
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"android-lib", "base-lib", "darwin-lib",
|
||||
"linux-lib", "linux_bionic-lib", "windows-lib"},
|
||||
Blueprint: soongCcLibraryPreamble + `
|
||||
cc_library_headers {
|
||||
name: "android-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "base-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "darwin-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "linux-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "linux_bionic-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "windows-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "foo_headers",
|
||||
header_libs: ["base-lib"],
|
||||
export_header_lib_headers: ["base-lib"],
|
||||
target: {
|
||||
android: {
|
||||
header_libs: ["android-lib"],
|
||||
export_header_lib_headers: ["android-lib"],
|
||||
},
|
||||
darwin: {
|
||||
header_libs: ["darwin-lib"],
|
||||
export_header_lib_headers: ["darwin-lib"],
|
||||
},
|
||||
linux_bionic: {
|
||||
header_libs: ["linux_bionic-lib"],
|
||||
export_header_lib_headers: ["linux_bionic-lib"],
|
||||
},
|
||||
linux_glibc: {
|
||||
header_libs: ["linux-lib"],
|
||||
export_header_lib_headers: ["linux-lib"],
|
||||
},
|
||||
windows: {
|
||||
header_libs: ["windows-lib"],
|
||||
export_header_lib_headers: ["windows-lib"],
|
||||
},
|
||||
},
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": [":android-lib"],
|
||||
"//build/bazel_common_rules/platforms/os:darwin": [":darwin-lib"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_bionic": [":linux_bionic-lib"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_glibc": [":linux-lib"],
|
||||
"//build/bazel_common_rules/platforms/os:windows": [":windows-lib"],
|
||||
"//conditions:default": [],
|
||||
}) + [":base-lib"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersOsSpecficHeaderLibsExportHeaderLibHeaders(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers test with os-specific header_libs and export_header_lib_headers props",
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"android-lib", "exported-lib"},
|
||||
Blueprint: soongCcLibraryPreamble + `
|
||||
cc_library_headers {
|
||||
name: "android-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "exported-lib",
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "foo_headers",
|
||||
target: {
|
||||
android: {
|
||||
header_libs: ["android-lib", "exported-lib"],
|
||||
export_header_lib_headers: ["exported-lib"]
|
||||
},
|
||||
},
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": [":exported-lib"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersArchAndTargetExportSystemIncludes(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers test with arch-specific and target-specific export_system_include_dirs props",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: soongCcLibraryPreamble + `cc_library_headers {
|
||||
name: "foo_headers",
|
||||
export_system_include_dirs: [
|
||||
"shared_include_dir",
|
||||
],
|
||||
target: {
|
||||
android: {
|
||||
export_system_include_dirs: [
|
||||
"android_include_dir",
|
||||
],
|
||||
},
|
||||
linux_glibc: {
|
||||
export_system_include_dirs: [
|
||||
"linux_include_dir",
|
||||
],
|
||||
},
|
||||
darwin: {
|
||||
export_system_include_dirs: [
|
||||
"darwin_include_dir",
|
||||
],
|
||||
},
|
||||
},
|
||||
arch: {
|
||||
arm: {
|
||||
export_system_include_dirs: [
|
||||
"arm_include_dir",
|
||||
],
|
||||
},
|
||||
x86_64: {
|
||||
export_system_include_dirs: [
|
||||
"x86_64_include_dir",
|
||||
],
|
||||
},
|
||||
},
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"export_system_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["android_include_dir"],
|
||||
"//build/bazel_common_rules/platforms/os:darwin": ["darwin_include_dir"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_glibc": ["linux_include_dir"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["arm_include_dir"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86_64": ["x86_64_include_dir"],
|
||||
"//conditions:default": [],
|
||||
}) + ["shared_include_dir"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersNoCrtIgnored(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers test",
|
||||
Filesystem: map[string]string{
|
||||
"lib-1/lib1a.h": "",
|
||||
"lib-1/lib1b.h": "",
|
||||
"lib-2/lib2a.h": "",
|
||||
"lib-2/lib2b.h": "",
|
||||
"dir-1/dir1a.h": "",
|
||||
"dir-1/dir1b.h": "",
|
||||
"dir-2/dir2a.h": "",
|
||||
"dir-2/dir2b.h": "",
|
||||
"arch_arm64_exported_include_dir/a.h": "",
|
||||
"arch_x86_exported_include_dir/b.h": "",
|
||||
"arch_x86_64_exported_include_dir/c.h": "",
|
||||
},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_library_headers {
|
||||
name: "lib-1",
|
||||
export_include_dirs: ["lib-1"],
|
||||
no_libcrt: true,
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "lib-1", AttrNameToString{
|
||||
"export_includes": `["lib-1"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersExportedStaticLibHeadersReexported(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers exported_static_lib_headers is reexported",
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_library_headers {
|
||||
name: "foo_headers",
|
||||
export_static_lib_headers: ["foo_export"],
|
||||
static_libs: ["foo_export", "foo_no_reexport"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
` + simpleModule("cc_library_headers", "foo_export") +
|
||||
simpleModule("cc_library_headers", "foo_no_reexport"),
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `[":foo_export"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersExportedSharedLibHeadersReexported(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers exported_shared_lib_headers is reexported",
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_library_headers {
|
||||
name: "foo_headers",
|
||||
export_shared_lib_headers: ["foo_export"],
|
||||
shared_libs: ["foo_export", "foo_no_reexport"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
` + simpleModule("cc_library_headers", "foo_export") +
|
||||
simpleModule("cc_library_headers", "foo_no_reexport"),
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `[":foo_export"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersExportedHeaderLibHeadersReexported(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers exported_header_lib_headers is reexported",
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_library_headers {
|
||||
name: "foo_headers",
|
||||
export_header_lib_headers: ["foo_export"],
|
||||
header_libs: ["foo_export", "foo_no_reexport"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
` + simpleModule("cc_library_headers", "foo_export") +
|
||||
simpleModule("cc_library_headers", "foo_no_reexport"),
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `[":foo_export"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryHeadersWholeStaticLibsReexported(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers whole_static_libs is reexported",
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"foo_export"},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_library_headers {
|
||||
name: "foo_headers",
|
||||
whole_static_libs: ["foo_export"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
` + simpleModule("cc_library_headers", "foo_export"),
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `[":foo_export"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltCcLibraryHeadersWholeStaticLibsReexported(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers whole_static_libs is reexported",
|
||||
Filesystem: map[string]string{
|
||||
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
||||
},
|
||||
StubbedBuildDefinitions: []string{"foo_export"},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_prebuilt_library_headers {
|
||||
name: "foo_headers",
|
||||
whole_static_libs: ["foo_export"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
` + simpleModule("cc_library_headers", "foo_export"),
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `[":foo_export"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltCcLibraryHeadersPreferredRdepUpdated(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers prebuilt preferred is used as rdep",
|
||||
StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
|
||||
Filesystem: map[string]string{
|
||||
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
||||
},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_prebuilt_library_headers {
|
||||
name: "foo_headers",
|
||||
whole_static_libs: ["foo_export"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
prefer: true,
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "foo",
|
||||
header_libs: ["foo_headers"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
` + simpleModule("cc_library_headers", "foo_export"),
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `[":foo_export"]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"implementation_deps": `[":foo_headers"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltCcLibraryHeadersRdepUpdated(t *testing.T) {
|
||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_headers not preferred is not used for rdep",
|
||||
StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
|
||||
Filesystem: map[string]string{
|
||||
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
||||
},
|
||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||
cc_prebuilt_library_headers {
|
||||
name: "foo_headers",
|
||||
whole_static_libs: ["foo_export"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
prefer: false,
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "foo",
|
||||
header_libs: ["foo_headers"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
` + simpleModule("cc_library_headers", "foo_export"),
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||
"deps": `[":foo_export"]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"implementation_deps": `["//foo/bar:foo_headers"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,478 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func registerCcObjectModuleTypes(ctx android.RegistrationContext) {
|
||||
// Always register cc_defaults module factory
|
||||
ctx.RegisterModuleType("cc_defaults", func() android.Module { return cc.DefaultsFactory() })
|
||||
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
|
||||
}
|
||||
|
||||
func runCcObjectTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "cc_object"
|
||||
(&tc).ModuleTypeUnderTestFactory = cc.ObjectFactory
|
||||
RunBp2BuildTestCase(t, registerCcObjectModuleTypes, tc)
|
||||
}
|
||||
|
||||
func TestCcObjectSimple(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "simple cc_object generates cc_object with include header dep",
|
||||
Filesystem: map[string]string{
|
||||
"a/b/foo.h": "",
|
||||
"a/b/bar.h": "",
|
||||
"a/b/exclude.c": "",
|
||||
"a/b/c.c": "",
|
||||
},
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
local_include_dirs: ["include"],
|
||||
system_shared_libs: [],
|
||||
cflags: [
|
||||
"-Wno-gcc-compat",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
srcs: [
|
||||
"a/b/*.c"
|
||||
],
|
||||
exclude_srcs: ["a/b/exclude.c"],
|
||||
sdk_version: "current",
|
||||
min_sdk_version: "29",
|
||||
crt: true,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `[
|
||||
"-fno-addrsig",
|
||||
"-Wno-gcc-compat",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
]`,
|
||||
"local_includes": `[
|
||||
"include",
|
||||
".",
|
||||
]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
"sdk_version": `"current"`,
|
||||
"min_sdk_version": `"29"`,
|
||||
"crt": "True",
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectDefaults(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: [
|
||||
"a/b/*.h",
|
||||
"a/b/c.c"
|
||||
],
|
||||
|
||||
defaults: ["foo_defaults"],
|
||||
}
|
||||
|
||||
cc_defaults {
|
||||
name: "foo_defaults",
|
||||
defaults: ["foo_bar_defaults"],
|
||||
}
|
||||
|
||||
cc_defaults {
|
||||
name: "foo_bar_defaults",
|
||||
cflags: [
|
||||
"-Werror",
|
||||
],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `[
|
||||
"-Werror",
|
||||
"-fno-addrsig",
|
||||
]`,
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestCcObjectCcObjetDepsInObjs(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object with cc_object deps in objs props",
|
||||
Filesystem: map[string]string{
|
||||
"a/b/c.c": "",
|
||||
"x/y/z.c": "",
|
||||
},
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["a/b/c.c"],
|
||||
objs: ["bar"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
|
||||
cc_object {
|
||||
name: "bar",
|
||||
system_shared_libs: [],
|
||||
srcs: ["x/y/z.c"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "bar", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"srcs": `["x/y/z.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}), MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"objs": `[":bar"]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectIncludeBuildDirFalse(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object with include_build_dir: false",
|
||||
Filesystem: map[string]string{
|
||||
"a/b/c.c": "",
|
||||
"x/y/z.c": "",
|
||||
},
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["a/b/c.c"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectProductVariable(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object with product variable",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
include_build_directory: false,
|
||||
product_variables: {
|
||||
platform_sdk_version: {
|
||||
asflags: ["-DPLATFORM_SDK_VERSION=%d"],
|
||||
},
|
||||
},
|
||||
srcs: ["src.S"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"asflags": `select({
|
||||
"//build/bazel/product_config/config_settings:platform_sdk_version": ["-DPLATFORM_SDK_VERSION=$(Platform_sdk_version)"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"srcs_as": `["src.S"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectCflagsOneArch(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting cflags for one arch",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["a.cpp"],
|
||||
arch: {
|
||||
x86: {
|
||||
cflags: ["-fPIC"], // string list
|
||||
},
|
||||
arm: {
|
||||
srcs: ["arch/arm/file.cpp"], // label list
|
||||
},
|
||||
},
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["-fPIC"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"srcs": `["a.cpp"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["arch/arm/file.cpp"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectCflagsFourArch(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting cflags for 4 architectures",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
system_shared_libs: [],
|
||||
srcs: ["base.cpp"],
|
||||
arch: {
|
||||
x86: {
|
||||
srcs: ["x86.cpp"],
|
||||
cflags: ["-fPIC"],
|
||||
},
|
||||
x86_64: {
|
||||
srcs: ["x86_64.cpp"],
|
||||
cflags: ["-fPIC"],
|
||||
},
|
||||
arm: {
|
||||
srcs: ["arm.cpp"],
|
||||
cflags: ["-Wall"],
|
||||
},
|
||||
arm64: {
|
||||
srcs: ["arm64.cpp"],
|
||||
cflags: ["-Wall"],
|
||||
},
|
||||
},
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["-Wall"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["-Wall"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["-fPIC"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86_64": ["-fPIC"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"srcs": `["base.cpp"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["arm.cpp"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["arm64.cpp"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["x86.cpp"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86_64": ["x86_64.cpp"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectLinkerScript(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting linker_script",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
srcs: ["base.cpp"],
|
||||
linker_script: "bunny.lds",
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"linker_script": `"bunny.lds"`,
|
||||
"srcs": `["base.cpp"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting deps and linker_script across archs",
|
||||
StubbedBuildDefinitions: []string{"x86_obj", "x86_64_obj", "arm_obj"},
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
srcs: ["base.cpp"],
|
||||
arch: {
|
||||
x86: {
|
||||
objs: ["x86_obj"],
|
||||
linker_script: "x86.lds",
|
||||
},
|
||||
x86_64: {
|
||||
objs: ["x86_64_obj"],
|
||||
linker_script: "x86_64.lds",
|
||||
},
|
||||
arm: {
|
||||
objs: ["arm_obj"],
|
||||
linker_script: "arm.lds",
|
||||
},
|
||||
},
|
||||
include_build_directory: false,
|
||||
}
|
||||
|
||||
cc_object {
|
||||
name: "x86_obj",
|
||||
system_shared_libs: [],
|
||||
srcs: ["x86.cpp"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
|
||||
cc_object {
|
||||
name: "x86_64_obj",
|
||||
system_shared_libs: [],
|
||||
srcs: ["x86_64.cpp"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
|
||||
cc_object {
|
||||
name: "arm_obj",
|
||||
system_shared_libs: [],
|
||||
srcs: ["arm.cpp"],
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"objs": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": [":arm_obj"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": [":x86_obj"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86_64": [":x86_64_obj"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"linker_script": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "arm.lds",
|
||||
"//build/bazel_common_rules/platforms/arch:x86": "x86.lds",
|
||||
"//build/bazel_common_rules/platforms/arch:x86_64": "x86_64.lds",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
"srcs": `["base.cpp"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_object setting srcs based on linux and bionic archs",
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
srcs: ["base.cpp"],
|
||||
target: {
|
||||
linux_arm64: {
|
||||
srcs: ["linux_arm64.cpp",]
|
||||
},
|
||||
linux_x86: {
|
||||
srcs: ["linux_x86.cpp",]
|
||||
},
|
||||
bionic_arm64: {
|
||||
srcs: ["bionic_arm64.cpp",]
|
||||
},
|
||||
},
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `["-fno-addrsig"]`,
|
||||
"srcs": `["base.cpp"] + select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"linux_arm64.cpp",
|
||||
"bionic_arm64.cpp",
|
||||
],
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_x86": ["linux_x86.cpp"],
|
||||
"//build/bazel_common_rules/platforms/os_arch:linux_bionic_arm64": [
|
||||
"linux_arm64.cpp",
|
||||
"bionic_arm64.cpp",
|
||||
],
|
||||
"//build/bazel_common_rules/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"],
|
||||
"//build/bazel_common_rules/platforms/os_arch:linux_musl_arm64": ["linux_arm64.cpp"],
|
||||
"//build/bazel_common_rules/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectHeaderLib(t *testing.T) {
|
||||
runCcObjectTestCase(t, Bp2buildTestCase{
|
||||
Description: "simple cc_object generates cc_object with include header dep",
|
||||
Filesystem: map[string]string{
|
||||
"a/b/foo.h": "",
|
||||
"a/b/bar.h": "",
|
||||
"a/b/exclude.c": "",
|
||||
"a/b/c.c": "",
|
||||
},
|
||||
Blueprint: `cc_object {
|
||||
name: "foo",
|
||||
header_libs: ["libheaders"],
|
||||
system_shared_libs: [],
|
||||
cflags: [
|
||||
"-Wno-gcc-compat",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
srcs: [
|
||||
"a/b/*.c"
|
||||
],
|
||||
exclude_srcs: ["a/b/exclude.c"],
|
||||
sdk_version: "current",
|
||||
min_sdk_version: "29",
|
||||
}
|
||||
|
||||
cc_library_headers {
|
||||
name: "libheaders",
|
||||
export_include_dirs: ["include"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_object", "foo", AttrNameToString{
|
||||
"copts": `[
|
||||
"-fno-addrsig",
|
||||
"-Wno-gcc-compat",
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
]`,
|
||||
"deps": `[":libheaders"]`,
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["a/b/c.c"]`,
|
||||
"system_dynamic_deps": `[]`,
|
||||
"sdk_version": `"current"`,
|
||||
"min_sdk_version": `"29"`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_headers", "libheaders", AttrNameToString{
|
||||
"export_includes": `["include"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func runCcPrebuiltBinaryTestCase(t *testing.T, testCase Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
description := fmt.Sprintf("cc_prebuilt_binary: %s", testCase.Description)
|
||||
testCase.ModuleTypeUnderTest = "cc_prebuilt_binary"
|
||||
testCase.ModuleTypeUnderTestFactory = cc.PrebuiltBinaryFactory
|
||||
testCase.Description = description
|
||||
t.Run(description, func(t *testing.T) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCaseSimple(t, testCase)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltBinary(t *testing.T) {
|
||||
runCcPrebuiltBinaryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "simple",
|
||||
Filesystem: map[string]string{
|
||||
"bin": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_binary {
|
||||
name: "bintest",
|
||||
srcs: ["bin"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
|
||||
"src": `"bin"`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltBinaryWithStrip(t *testing.T) {
|
||||
runCcPrebuiltBinaryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "with strip",
|
||||
Filesystem: map[string]string{
|
||||
"bin": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_binary {
|
||||
name: "bintest",
|
||||
srcs: ["bin"],
|
||||
strip: { all: true },
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`, ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
|
||||
"src": `"bin"`,
|
||||
"strip": `{
|
||||
"all": True,
|
||||
}`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltBinaryWithArchVariance(t *testing.T) {
|
||||
runCcPrebuiltBinaryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"bina": "",
|
||||
"binb": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_binary {
|
||||
name: "bintest",
|
||||
arch: {
|
||||
arm64: { srcs: ["bina"], },
|
||||
arm: { srcs: ["binb"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`, ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
|
||||
"src": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "binb",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "bina",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltBinaryMultipleSrcsFails(t *testing.T) {
|
||||
runCcPrebuiltBinaryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "fails because multiple sources",
|
||||
Filesystem: map[string]string{
|
||||
"bina": "",
|
||||
"binb": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_binary {
|
||||
name: "bintest",
|
||||
srcs: ["bina", "binb"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: nosrcs test
|
|
@ -1,412 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func runCcPrebuiltLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "cc_prebuilt_library"
|
||||
(&tc).ModuleTypeUnderTestFactory = cc.PrebuiltLibraryFactory
|
||||
RunBp2BuildTestCaseSimple(t, tc)
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticAndSharedSimple(t *testing.T) {
|
||||
runCcPrebuiltLibraryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library static and shared simple",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"alwayslink": "True",
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryWithArchVariance(t *testing.T) {
|
||||
runCcPrebuiltLibraryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
arch: {
|
||||
arm64: { srcs: ["libf.so"], },
|
||||
arm: { srcs: ["libg.so"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
|
||||
"static_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
|
||||
"alwayslink": "True",
|
||||
"static_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`}),
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryAdditionalAttrs(t *testing.T) {
|
||||
runCcPrebuiltLibraryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library additional attributes",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"testdir/1/include.h": "",
|
||||
"testdir/2/other.h": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
export_include_dirs: ["testdir/1/"],
|
||||
export_system_include_dirs: ["testdir/2/"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `["testdir/1/"]`,
|
||||
"export_system_includes": `["testdir/2/"]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `["testdir/1/"]`,
|
||||
"export_system_includes": `["testdir/2/"]`,
|
||||
"alwayslink": "True",
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
"export_includes": `["testdir/1/"]`,
|
||||
"export_system_includes": `["testdir/2/"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedStanzaFails(t *testing.T) {
|
||||
runCcPrebuiltLibraryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library with shared stanza fails because multiple sources",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
shared: {
|
||||
srcs: ["libg.so"],
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticStanzaFails(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library with static stanza fails because multiple sources",
|
||||
ModuleTypeUnderTest: "cc_prebuilt_library",
|
||||
ModuleTypeUnderTestFactory: cc.PrebuiltLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
static: {
|
||||
srcs: ["libg.so"],
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedAndStaticStanzas(t *testing.T) {
|
||||
runCcPrebuiltLibraryTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library with both shared and static stanzas",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
static: {
|
||||
srcs: ["libf.so"],
|
||||
},
|
||||
shared: {
|
||||
srcs: ["libg.so"],
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"alwayslink": "True",
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libg.so"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// TODO(b/228623543): When this bug is fixed, enable this test
|
||||
//func TestPrebuiltLibraryOnlyShared(t *testing.T) {
|
||||
// runCcPrebuiltLibraryTestCase(t,
|
||||
// bp2buildTestCase{
|
||||
// description: "prebuilt library shared only",
|
||||
// filesystem: map[string]string{
|
||||
// "libf.so": "",
|
||||
// },
|
||||
// blueprint: `
|
||||
//cc_prebuilt_library {
|
||||
// name: "libtest",
|
||||
// srcs: ["libf.so"],
|
||||
// static: {
|
||||
// enabled: false,
|
||||
// },
|
||||
// bazel_module: { bp2build_available: true },
|
||||
//}`,
|
||||
// expectedBazelTargets: []string{
|
||||
// makeBazelTarget("cc_prebuilt_library_shared", "libtest", attrNameToString{
|
||||
// "shared_library": `"libf.so"`,
|
||||
// }),
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
|
||||
// TODO(b/228623543): When this bug is fixed, enable this test
|
||||
//func TestPrebuiltLibraryOnlyStatic(t *testing.T) {
|
||||
// runCcPrebuiltLibraryTestCase(t,
|
||||
// bp2buildTestCase{
|
||||
// description: "prebuilt library static only",
|
||||
// filesystem: map[string]string{
|
||||
// "libf.so": "",
|
||||
// },
|
||||
// blueprint: `
|
||||
//cc_prebuilt_library {
|
||||
// name: "libtest",
|
||||
// srcs: ["libf.so"],
|
||||
// shared: {
|
||||
// enabled: false,
|
||||
// },
|
||||
// bazel_module: { bp2build_available: true },
|
||||
//}`,
|
||||
// expectedBazelTargets: []string{
|
||||
// makeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", attrNameToString{
|
||||
// "static_library": `"libf.so"`,
|
||||
// }),
|
||||
// makeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_always", attrNameToString{
|
||||
// "static_library": `"libf.so"`,
|
||||
// "alwayslink": "True",
|
||||
// }),
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
|
||||
func TestPrebuiltLibraryWithExportIncludesArchVariant(t *testing.T) {
|
||||
runCcPrebuiltLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_prebuilt_library correctly translates export_includes with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
arch: {
|
||||
arm: { export_include_dirs: ["testdir/1/"], },
|
||||
arm64: { export_include_dirs: ["testdir/2/"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
"export_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
|
||||
"alwayslink": "True",
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryWithExportSystemIncludesArchVariant(t *testing.T) {
|
||||
runCcPrebuiltLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_prebuilt_ibrary correctly translates export_system_includes with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
arch: {
|
||||
arm: { export_system_include_dirs: ["testdir/1/"], },
|
||||
arm64: { export_system_include_dirs: ["testdir/2/"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
"export_system_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_system_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_bp2build_cc_library_static_alwayslink", AttrNameToString{
|
||||
"alwayslink": "True",
|
||||
"static_library": `"libf.so"`,
|
||||
"export_system_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltNdkStlConversion(t *testing.T) {
|
||||
registerNdkStlModuleTypes := func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("ndk_prebuilt_static_stl", cc.NdkPrebuiltStaticStlFactory)
|
||||
ctx.RegisterModuleType("ndk_prebuilt_shared_stl", cc.NdkPrebuiltSharedStlFactory)
|
||||
}
|
||||
RunBp2BuildTestCase(t, registerNdkStlModuleTypes, Bp2buildTestCase{
|
||||
Description: "TODO",
|
||||
Blueprint: `
|
||||
ndk_prebuilt_static_stl {
|
||||
name: "ndk_libfoo_static",
|
||||
export_include_dirs: ["dir1", "dir2"],
|
||||
}
|
||||
ndk_prebuilt_shared_stl {
|
||||
name: "ndk_libfoo_shared",
|
||||
export_include_dirs: ["dir1", "dir2"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "ndk_libfoo_static", AttrNameToString{
|
||||
"static_library": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm": "current/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libfoo_static.a",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": "current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libfoo_static.a",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_riscv64": "current/sources/cxx-stl/llvm-libc++/libs/riscv64/libfoo_static.a",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_x86": "current/sources/cxx-stl/llvm-libc++/libs/x86/libfoo_static.a",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_x86_64": "current/sources/cxx-stl/llvm-libc++/libs/x86_64/libfoo_static.a",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
"export_system_includes": `[
|
||||
"dir1",
|
||||
"dir2",
|
||||
]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "ndk_libfoo_shared", AttrNameToString{
|
||||
"shared_library": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm": "current/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libfoo_shared.so",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": "current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libfoo_shared.so",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_riscv64": "current/sources/cxx-stl/llvm-libc++/libs/riscv64/libfoo_shared.so",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_x86": "current/sources/cxx-stl/llvm-libc++/libs/x86/libfoo_shared.so",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_x86_64": "current/sources/cxx-stl/llvm-libc++/libs/x86_64/libfoo_shared.so",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
"export_system_includes": `[
|
||||
"dir1",
|
||||
"dir2",
|
||||
]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,165 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func runCcPrebuiltLibrarySharedTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Parallel()
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "cc_prebuilt_library_shared"
|
||||
(&tc).ModuleTypeUnderTestFactory = cc.PrebuiltSharedLibraryFactory
|
||||
RunBp2BuildTestCaseSimple(t, tc)
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedSimple(t *testing.T) {
|
||||
runCcPrebuiltLibrarySharedTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library shared simple",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedWithArchVariance(t *testing.T) {
|
||||
runCcPrebuiltLibrarySharedTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library shared with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
arch: {
|
||||
arm64: { srcs: ["libf.so"], },
|
||||
arm: { srcs: ["libg.so"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedAdditionalAttrs(t *testing.T) {
|
||||
runCcPrebuiltLibrarySharedTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library shared additional attributes",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"testdir/1/include.h": "",
|
||||
"testdir/2/other.h": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
export_include_dirs: ["testdir/1/"],
|
||||
export_system_include_dirs: ["testdir/2/"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
"export_includes": `["testdir/1/"]`,
|
||||
"export_system_includes": `["testdir/2/"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedWithExportIncludesArchVariant(t *testing.T) {
|
||||
runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_prebuilt_library_shared correctly translates export_includes with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
arch: {
|
||||
arm: { export_include_dirs: ["testdir/1/"], },
|
||||
arm64: { export_include_dirs: ["testdir/2/"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
"export_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedWithExportSystemIncludesArchVariant(t *testing.T) {
|
||||
runCcPrebuiltLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_prebuilt_library_shared correctly translates export_system_includes with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
arch: {
|
||||
arm: { export_system_include_dirs: ["testdir/1/"], },
|
||||
arm64: { export_system_include_dirs: ["testdir/2/"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
"export_system_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func TestSharedPrebuiltLibrary(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library shared simple",
|
||||
ModuleTypeUnderTest: "cc_prebuilt_library_shared",
|
||||
ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `"libf.so"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library shared with arch variance",
|
||||
ModuleTypeUnderTest: "cc_prebuilt_library_shared",
|
||||
ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
arch: {
|
||||
arm64: { srcs: ["libf.so"], },
|
||||
arm: { srcs: ["libg.so"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{
|
||||
"shared_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestSharedPrebuiltLibrarySharedStanzaFails(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library shared with shared stanza fails because multiple sources",
|
||||
ModuleTypeUnderTest: "cc_prebuilt_library_shared",
|
||||
ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
shared: {
|
||||
srcs: ["libg.so"],
|
||||
},
|
||||
bazel_module: { bp2build_available: true},
|
||||
}`,
|
||||
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
||||
})
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func runCcPrebuiltLibraryStaticTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Parallel()
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "cc_prebuilt_library_static"
|
||||
(&tc).ModuleTypeUnderTestFactory = cc.PrebuiltStaticLibraryFactory
|
||||
RunBp2BuildTestCaseSimple(t, tc)
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticSimple(t *testing.T) {
|
||||
runCcPrebuiltLibraryStaticTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library static simple",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"alwayslink": "True",
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticWithArchVariance(t *testing.T) {
|
||||
runCcPrebuiltLibraryStaticTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
arch: {
|
||||
arm64: { srcs: ["libf.so"], },
|
||||
arm: { srcs: ["libg.so"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
||||
"static_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
||||
"alwayslink": "True",
|
||||
"static_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticAdditionalAttrs(t *testing.T) {
|
||||
runCcPrebuiltLibraryStaticTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library additional attributes",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"testdir/1/include.h": "",
|
||||
"testdir/2/other.h": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
export_include_dirs: ["testdir/1/"],
|
||||
export_system_include_dirs: ["testdir/2/"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `["testdir/1/"]`,
|
||||
"export_system_includes": `["testdir/2/"]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `["testdir/1/"]`,
|
||||
"export_system_includes": `["testdir/2/"]`,
|
||||
"alwayslink": "True",
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticWithExportIncludesArchVariant(t *testing.T) {
|
||||
runCcPrebuiltLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_prebuilt_library_static correctly translates export_includes with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
arch: {
|
||||
arm: { export_include_dirs: ["testdir/1/"], },
|
||||
arm64: { export_include_dirs: ["testdir/2/"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
||||
"alwayslink": "True",
|
||||
"static_library": `"libf.so"`,
|
||||
"export_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticWithExportSystemIncludesArchVariant(t *testing.T) {
|
||||
runCcPrebuiltLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_prebuilt_library_static correctly translates export_system_includes with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
arch: {
|
||||
arm: { export_system_include_dirs: ["testdir/1/"], },
|
||||
arm64: { export_system_include_dirs: ["testdir/2/"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"export_system_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
||||
"alwayslink": "True",
|
||||
"static_library": `"libf.so"`,
|
||||
"export_system_includes": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["testdir/1/"],
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": ["testdir/2/"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func TestStaticPrebuiltLibrary(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library static simple",
|
||||
ModuleTypeUnderTest: "cc_prebuilt_library_static",
|
||||
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
||||
"static_library": `"libf.so"`,
|
||||
"alwayslink": "True",
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestStaticPrebuiltLibraryWithArchVariance(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library static with arch variance",
|
||||
ModuleTypeUnderTest: "cc_prebuilt_library_static",
|
||||
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
arch: {
|
||||
arm64: { srcs: ["libf.so"], },
|
||||
arm: { srcs: ["libg.so"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest", AttrNameToString{
|
||||
"static_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`}),
|
||||
MakeBazelTarget("cc_prebuilt_library_static", "libtest_alwayslink", AttrNameToString{
|
||||
"alwayslink": "True",
|
||||
"static_library": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "libg.so",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "libf.so",
|
||||
"//conditions:default": None,
|
||||
})`}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestStaticPrebuiltLibraryStaticStanzaFails(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "prebuilt library with static stanza fails because multiple sources",
|
||||
ModuleTypeUnderTest: "cc_prebuilt_library_static",
|
||||
ModuleTypeUnderTestFactory: cc.PrebuiltStaticLibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"libf.so": "",
|
||||
"libg.so": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_library_static {
|
||||
name: "libtest",
|
||||
srcs: ["libf.so"],
|
||||
static: {
|
||||
srcs: ["libg.so"],
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryStaticConvertLex(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Description: "cc_library_static with lex files",
|
||||
ModuleTypeUnderTest: "cc_library_static",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryStaticFactory,
|
||||
Filesystem: map[string]string{
|
||||
"foo.c": "",
|
||||
"bar.cc": "",
|
||||
"foo1.l": "",
|
||||
"bar1.ll": "",
|
||||
"foo2.l": "",
|
||||
"bar2.ll": "",
|
||||
},
|
||||
Blueprint: `cc_library_static {
|
||||
name: "foo_lib",
|
||||
srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
|
||||
lex: { flags: ["--foo_flags"] },
|
||||
include_build_directory: false,
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("genlex", "foo_lib_genlex_l", AttrNameToString{
|
||||
"srcs": `[
|
||||
"foo1.l",
|
||||
"foo2.l",
|
||||
]`,
|
||||
"lexopts": `["--foo_flags"]`,
|
||||
}),
|
||||
MakeBazelTarget("genlex", "foo_lib_genlex_ll", AttrNameToString{
|
||||
"srcs": `[
|
||||
"bar1.ll",
|
||||
"bar2.ll",
|
||||
]`,
|
||||
"lexopts": `["--foo_flags"]`,
|
||||
}),
|
||||
MakeBazelTarget("cc_library_static", "foo_lib", AttrNameToString{
|
||||
"srcs": `[
|
||||
"bar.cc",
|
||||
":foo_lib_genlex_ll",
|
||||
]`,
|
||||
"srcs_c": `[
|
||||
"foo.c",
|
||||
":foo_lib_genlex_l",
|
||||
]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func runCcPrebuiltObjectTestCase(t *testing.T, testCase Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
description := fmt.Sprintf("cc_prebuilt_object: %s", testCase.Description)
|
||||
testCase.ModuleTypeUnderTest = "cc_prebuilt_object"
|
||||
testCase.ModuleTypeUnderTestFactory = cc.PrebuiltObjectFactory
|
||||
testCase.Description = description
|
||||
t.Run(description, func(t *testing.T) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCaseSimple(t, testCase)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltObject(t *testing.T) {
|
||||
runCcPrebuiltObjectTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "simple",
|
||||
Filesystem: map[string]string{
|
||||
"obj.o": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_object {
|
||||
name: "objtest",
|
||||
srcs: ["obj.o"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_object", "objtest", AttrNameToString{
|
||||
"src": `"obj.o"`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltObjectWithArchVariance(t *testing.T) {
|
||||
runCcPrebuiltObjectTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "with arch variance",
|
||||
Filesystem: map[string]string{
|
||||
"obja.o": "",
|
||||
"objb.o": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_object {
|
||||
name: "objtest",
|
||||
arch: {
|
||||
arm64: { srcs: ["obja.o"], },
|
||||
arm: { srcs: ["objb.o"], },
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`, ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_prebuilt_object", "objtest", AttrNameToString{
|
||||
"src": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "objb.o",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "obja.o",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltObjectMultipleSrcsFails(t *testing.T) {
|
||||
runCcPrebuiltObjectTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Description: "fails because multiple sources",
|
||||
Filesystem: map[string]string{
|
||||
"obja": "",
|
||||
"objb": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_prebuilt_object {
|
||||
name: "objtest",
|
||||
srcs: ["obja.o", "objb.o"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: nosrcs test
|
|
@ -1,633 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/genrule"
|
||||
)
|
||||
|
||||
type ccTestBp2buildTestCase struct {
|
||||
description string
|
||||
blueprint string
|
||||
filesystem map[string]string
|
||||
targets []testBazelTarget
|
||||
stubbedBuildDefinitions []string
|
||||
}
|
||||
|
||||
func registerCcTestModuleTypes(ctx android.RegistrationContext) {
|
||||
cc.RegisterCCBuildComponents(ctx)
|
||||
ctx.RegisterModuleType("cc_binary", cc.BinaryFactory)
|
||||
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
|
||||
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
|
||||
ctx.RegisterModuleType("cc_test_library", cc.TestLibraryFactory)
|
||||
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
|
||||
}
|
||||
|
||||
func runCcTestTestCase(t *testing.T, testCase ccTestBp2buildTestCase) {
|
||||
t.Helper()
|
||||
moduleTypeUnderTest := "cc_test"
|
||||
description := fmt.Sprintf("%s %s", moduleTypeUnderTest, testCase.description)
|
||||
t.Run(description, func(t *testing.T) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerCcTestModuleTypes, Bp2buildTestCase{
|
||||
ExpectedBazelTargets: generateBazelTargetsForTest(testCase.targets, android.HostAndDeviceSupported),
|
||||
Filesystem: testCase.filesystem,
|
||||
ModuleTypeUnderTest: moduleTypeUnderTest,
|
||||
ModuleTypeUnderTestFactory: cc.TestFactory,
|
||||
Description: description,
|
||||
Blueprint: testCase.blueprint,
|
||||
StubbedBuildDefinitions: testCase.stubbedBuildDefinitions,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestBasicCcTest(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "basic cc_test with commonly used attributes",
|
||||
stubbedBuildDefinitions: []string{"libbuildversion", "libprotobuf-cpp-lite", "libprotobuf-cpp-full",
|
||||
"foolib", "hostlib", "data_mod", "cc_bin", "cc_lib", "cc_test_lib2", "libgtest_main", "libgtest"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
host_supported: true,
|
||||
srcs: ["test.cpp"],
|
||||
target: {
|
||||
android: {
|
||||
srcs: ["android.cpp"],
|
||||
shared_libs: ["foolib"],
|
||||
},
|
||||
linux: {
|
||||
srcs: ["linux.cpp"],
|
||||
},
|
||||
host: {
|
||||
static_libs: ["hostlib"],
|
||||
},
|
||||
},
|
||||
static_libs: ["cc_test_lib1"],
|
||||
shared_libs: ["cc_test_lib2"],
|
||||
data: [":data_mod", "file.txt"],
|
||||
data_bins: [":cc_bin"],
|
||||
data_libs: [":cc_lib"],
|
||||
cflags: ["-Wall"],
|
||||
}
|
||||
|
||||
cc_test_library {
|
||||
name: "cc_test_lib1",
|
||||
host_supported: true,
|
||||
include_build_directory: false,
|
||||
}
|
||||
` + simpleModule("cc_library", "foolib") +
|
||||
simpleModule("cc_library_static", "hostlib") +
|
||||
simpleModule("genrule", "data_mod") +
|
||||
simpleModule("cc_binary", "cc_bin") +
|
||||
simpleModule("cc_library", "cc_lib") +
|
||||
simpleModule("cc_test_library", "cc_test_lib2") +
|
||||
simpleModule("cc_library_static", "libgtest_main") +
|
||||
simpleModule("cc_library_static", "libgtest"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_library_shared", "cc_test_lib1", AttrNameToString{}},
|
||||
{"cc_library_static", "cc_test_lib1_bp2build_cc_library_static", AttrNameToString{}},
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"copts": `["-Wall"]`,
|
||||
"data": `[
|
||||
":data_mod",
|
||||
"file.txt",
|
||||
":cc_bin",
|
||||
":cc_lib",
|
||||
]`,
|
||||
"deps": `[
|
||||
":cc_test_lib1_bp2build_cc_library_static",
|
||||
":libgtest_main",
|
||||
":libgtest",
|
||||
] + select({
|
||||
"//build/bazel_common_rules/platforms/os:darwin": [":hostlib"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_bionic": [":hostlib"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_glibc": [":hostlib"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_musl": [":hostlib"],
|
||||
"//build/bazel_common_rules/platforms/os:windows": [":hostlib"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"local_includes": `["."]`,
|
||||
"dynamic_deps": `[":cc_test_lib2"] + select({
|
||||
"//build/bazel_common_rules/platforms/os:android": [":foolib"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"srcs": `["test.cpp"] + select({
|
||||
"//build/bazel_common_rules/platforms/os:android": [
|
||||
"linux.cpp",
|
||||
"android.cpp",
|
||||
],
|
||||
"//build/bazel_common_rules/platforms/os:linux_bionic": ["linux.cpp"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_glibc": ["linux.cpp"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_musl": ["linux.cpp"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"runs_on": `[
|
||||
"host_without_device",
|
||||
"device",
|
||||
]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestBasicCcTestGtestIsolatedDisabled(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test with disabled gtest and isolated props",
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
host_supported: true,
|
||||
srcs: ["test.cpp"],
|
||||
gtest: false,
|
||||
isolated: false,
|
||||
}
|
||||
`,
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"gtest": "False",
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"runs_on": `[
|
||||
"host_without_device",
|
||||
"device",
|
||||
]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_TestOptions_Tags(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test with test_options.tags converted to tags",
|
||||
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
host_supported: true,
|
||||
srcs: ["test.cpp"],
|
||||
test_options: { tags: ["no-remote"] },
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_main") +
|
||||
simpleModule("cc_library_static", "libgtest"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"tags": `["no-remote"]`,
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"deps": `[
|
||||
":libgtest_main",
|
||||
":libgtest",
|
||||
]`,
|
||||
"runs_on": `[
|
||||
"host_without_device",
|
||||
"device",
|
||||
]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_TestConfig(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that sets a test_config",
|
||||
filesystem: map[string]string{
|
||||
"test_config.xml": "",
|
||||
},
|
||||
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
test_config: "test_config.xml",
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_main") +
|
||||
simpleModule("cc_library_static", "libgtest"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"test_config": `"test_config.xml"`,
|
||||
"deps": `[
|
||||
":libgtest_main",
|
||||
":libgtest",
|
||||
]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_TestConfigAndroidTestXML(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that defaults to test config AndroidTest.xml",
|
||||
filesystem: map[string]string{
|
||||
"AndroidTest.xml": "",
|
||||
"DynamicConfig.xml": "",
|
||||
},
|
||||
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_main") +
|
||||
simpleModule("cc_library_static", "libgtest"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"test_config": `"AndroidTest.xml"`,
|
||||
"dynamic_config": `"DynamicConfig.xml"`,
|
||||
"deps": `[
|
||||
":libgtest_main",
|
||||
":libgtest",
|
||||
]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_TestConfigTemplateOptions(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that sets test config template attributes",
|
||||
filesystem: map[string]string{
|
||||
"test_config_template.xml": "",
|
||||
},
|
||||
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
test_config_template: "test_config_template.xml",
|
||||
auto_gen_config: true,
|
||||
isolated: true,
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
|
||||
simpleModule("cc_library", "liblog"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"auto_generate_test_config": "True",
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"template_configs": `[
|
||||
"'<target_preparer class=\"com.android.tradefed.targetprep.RootTargetPreparer\">\\n <option name=\"force-root\" value=\"false\" />\\n </target_preparer>'",
|
||||
"'<option name=\"not-shardable\" value=\"true\" />'",
|
||||
]`,
|
||||
"template_install_base": `"/data/local/tmp"`,
|
||||
"template_test_config": `"test_config_template.xml"`,
|
||||
"deps": `[":libgtest_isolated_main"]`,
|
||||
"dynamic_deps": `[":liblog"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_WithExplicitGTestDepInAndroidBp(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that lists libgtest in Android.bp should not have dups of libgtest in BUILD file",
|
||||
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
static_libs: ["libgtest"],
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_main") +
|
||||
simpleModule("cc_library_static", "libgtest"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"deps": `[
|
||||
":libgtest",
|
||||
":libgtest_main",
|
||||
]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestCcTest_WithIsolatedTurnedOn(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that sets `isolated: true` should run with ligtest_isolated_main instead of libgtest_main",
|
||||
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
isolated: true,
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
|
||||
simpleModule("cc_library", "liblog"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"deps": `[":libgtest_isolated_main"]`,
|
||||
"dynamic_deps": `[":liblog"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestCcTest_GtestExplicitlySpecifiedInAndroidBp(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "If `gtest` is explicit in Android.bp, it should be explicit in BUILD files as well",
|
||||
stubbedBuildDefinitions: []string{"libgtest_main", "libgtest"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest_with_gtest",
|
||||
gtest: true,
|
||||
}
|
||||
cc_test {
|
||||
name: "mytest_with_no_gtest",
|
||||
gtest: false,
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_main") +
|
||||
simpleModule("cc_library_static", "libgtest"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest_with_gtest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"deps": `[
|
||||
":libgtest_main",
|
||||
":libgtest",
|
||||
]`,
|
||||
"gtest": "True",
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
{"cc_test", "mytest_with_no_gtest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"gtest": "False",
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_DisableMemtagHeap(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that disable memtag_heap",
|
||||
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
isolated: true,
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
memtag_heap: false,
|
||||
},
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
|
||||
simpleModule("cc_library", "liblog"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"deps": `[":libgtest_isolated_main"]`,
|
||||
"dynamic_deps": `[":liblog"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `["android_cfi"] + select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": ["-memtag_heap"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_RespectArm64MemtagHeap(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that disable memtag_heap",
|
||||
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
isolated: true,
|
||||
target: {
|
||||
android_arm64: {
|
||||
sanitize: {
|
||||
memtag_heap: false,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
|
||||
simpleModule("cc_library", "liblog"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"deps": `[":libgtest_isolated_main"]`,
|
||||
"dynamic_deps": `[":liblog"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": ["-memtag_heap"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_IgnoreNoneArm64MemtagHeap(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that disable memtag_heap",
|
||||
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
isolated: true,
|
||||
arch: {
|
||||
x86: {
|
||||
sanitize: {
|
||||
memtag_heap: false,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
|
||||
simpleModule("cc_library", "liblog"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"deps": `[":libgtest_isolated_main"]`,
|
||||
"dynamic_deps": `[":liblog"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"memtag_heap",
|
||||
"diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcTest_Arm64MemtagHeapOverrideNoConfigOne(t *testing.T) {
|
||||
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||
description: "cc test that disable memtag_heap",
|
||||
stubbedBuildDefinitions: []string{"libgtest_isolated_main", "liblog"},
|
||||
blueprint: `
|
||||
cc_test {
|
||||
name: "mytest",
|
||||
srcs: ["test.cpp"],
|
||||
isolated: true,
|
||||
sanitize: {
|
||||
memtag_heap: true,
|
||||
},
|
||||
target: {
|
||||
android_arm64: {
|
||||
sanitize: {
|
||||
memtag_heap: false,
|
||||
diag: {
|
||||
memtag_heap: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
` + simpleModule("cc_library_static", "libgtest_isolated_main") +
|
||||
simpleModule("cc_library", "liblog"),
|
||||
targets: []testBazelTarget{
|
||||
{"cc_test", "mytest", AttrNameToString{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["test.cpp"]`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"deps": `[":libgtest_isolated_main"]`,
|
||||
"dynamic_deps": `[":liblog"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"features": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": [
|
||||
"-memtag_heap",
|
||||
"-diag_memtag_heap",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,179 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func runYasmTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerYasmModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerYasmModuleTypes(ctx android.RegistrationContext) {
|
||||
cc.RegisterCCBuildComponents(ctx)
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory)
|
||||
ctx.RegisterModuleType("cc_prebuilt_library_static", cc.PrebuiltStaticLibraryFactory)
|
||||
ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory)
|
||||
}
|
||||
|
||||
func TestYasmSimple(t *testing.T) {
|
||||
runYasmTestCase(t, Bp2buildTestCase{
|
||||
Description: "Simple yasm test",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"main.cpp": "",
|
||||
"myfile.asm": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
srcs: ["main.cpp", "myfile.asm"],
|
||||
}`,
|
||||
ExpectedBazelTargets: append([]string{
|
||||
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
||||
"include_dirs": `["."]`,
|
||||
"srcs": `["myfile.asm"]`,
|
||||
}),
|
||||
}, makeCcLibraryTargets("foo", map[string]string{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `[
|
||||
"main.cpp",
|
||||
":foo_yasm",
|
||||
]`,
|
||||
})...),
|
||||
})
|
||||
}
|
||||
|
||||
func TestYasmWithIncludeDirs(t *testing.T) {
|
||||
runYasmTestCase(t, Bp2buildTestCase{
|
||||
Description: "Simple yasm test",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"main.cpp": "",
|
||||
"myfile.asm": "",
|
||||
"include1/foo/myinclude.inc": "",
|
||||
"include2/foo/myinclude2.inc": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
local_include_dirs: ["include1/foo"],
|
||||
export_include_dirs: ["include2/foo"],
|
||||
srcs: ["main.cpp", "myfile.asm"],
|
||||
}`,
|
||||
ExpectedBazelTargets: append([]string{
|
||||
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
||||
"include_dirs": `[
|
||||
"include1/foo",
|
||||
".",
|
||||
"include2/foo",
|
||||
]`,
|
||||
"srcs": `["myfile.asm"]`,
|
||||
}),
|
||||
}, makeCcLibraryTargets("foo", map[string]string{
|
||||
"local_includes": `[
|
||||
"include1/foo",
|
||||
".",
|
||||
]`,
|
||||
"export_includes": `["include2/foo"]`,
|
||||
"srcs": `[
|
||||
"main.cpp",
|
||||
":foo_yasm",
|
||||
]`,
|
||||
})...),
|
||||
})
|
||||
}
|
||||
|
||||
func TestYasmConditionalBasedOnArch(t *testing.T) {
|
||||
runYasmTestCase(t, Bp2buildTestCase{
|
||||
Description: "Simple yasm test",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"main.cpp": "",
|
||||
"myfile.asm": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
srcs: ["main.cpp"],
|
||||
arch: {
|
||||
x86: {
|
||||
srcs: ["myfile.asm"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: append([]string{
|
||||
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
||||
"include_dirs": `["."]`,
|
||||
"srcs": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["myfile.asm"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
}, makeCcLibraryTargets("foo", map[string]string{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `["main.cpp"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:x86": [":foo_yasm"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
})...),
|
||||
})
|
||||
}
|
||||
|
||||
func TestYasmPartiallyConditional(t *testing.T) {
|
||||
runYasmTestCase(t, Bp2buildTestCase{
|
||||
Description: "Simple yasm test",
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
"main.cpp": "",
|
||||
"myfile.asm": "",
|
||||
"mysecondfile.asm": "",
|
||||
},
|
||||
Blueprint: `
|
||||
cc_library {
|
||||
name: "foo",
|
||||
srcs: ["main.cpp", "myfile.asm"],
|
||||
arch: {
|
||||
x86: {
|
||||
srcs: ["mysecondfile.asm"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: append([]string{
|
||||
MakeBazelTarget("yasm", "foo_yasm", map[string]string{
|
||||
"include_dirs": `["."]`,
|
||||
"srcs": `["myfile.asm"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["mysecondfile.asm"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
}, makeCcLibraryTargets("foo", map[string]string{
|
||||
"local_includes": `["."]`,
|
||||
"srcs": `[
|
||||
"main.cpp",
|
||||
":foo_yasm",
|
||||
]`,
|
||||
})...),
|
||||
})
|
||||
}
|
|
@ -8,11 +8,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/apex"
|
||||
"android/soong/cc"
|
||||
cc_config "android/soong/cc/config"
|
||||
java_config "android/soong/java/config"
|
||||
rust_config "android/soong/rust/config"
|
||||
"android/soong/starlark_fmt"
|
||||
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
@ -33,23 +28,6 @@ func createSoongInjectionDirFiles(ctx *CodegenContext, metrics CodegenMetrics) (
|
|||
files = append(files, newFile("android", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
|
||||
files = append(files, newFile("android", "constants.bzl", android.BazelCcToolchainVars(cfg)))
|
||||
|
||||
files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
|
||||
files = append(files, newFile("cc_toolchain", "config_constants.bzl", cc_config.BazelCcToolchainVars(cfg)))
|
||||
files = append(files, newFile("cc_toolchain", "sanitizer_constants.bzl", cc.BazelCcSanitizerToolchainVars(cfg)))
|
||||
|
||||
files = append(files, newFile("java_toolchain", GeneratedBuildFileName, "")) // Creates a //java_toolchain package.
|
||||
files = append(files, newFile("java_toolchain", "constants.bzl", java_config.BazelJavaToolchainVars(cfg)))
|
||||
|
||||
files = append(files, newFile("rust_toolchain", GeneratedBuildFileName, "")) // Creates a //rust_toolchain package.
|
||||
files = append(files, newFile("rust_toolchain", "constants.bzl", rust_config.BazelRustToolchainVars(cfg)))
|
||||
|
||||
files = append(files, newFile("apex_toolchain", GeneratedBuildFileName, "")) // Creates a //apex_toolchain package.
|
||||
apexToolchainVars, err := apex.BazelApexToolchainVars()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, newFile("apex_toolchain", "constants.bzl", apexToolchainVars))
|
||||
|
||||
if buf, err := json.MarshalIndent(metrics.convertedModuleWithType, "", " "); err != nil {
|
||||
return []BazelFile{}, err
|
||||
} else {
|
||||
|
|
|
@ -17,8 +17,6 @@ package bp2build
|
|||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
type bazelFilepath struct {
|
||||
|
@ -80,148 +78,3 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
|
||||
testConfig := android.TestConfig("", make(map[string]string), "", make(map[string][]byte))
|
||||
codegenCtx := NewCodegenContext(testConfig, android.NewTestContext(testConfig).Context, Bp2Build, "")
|
||||
files, err := createSoongInjectionDirFiles(codegenCtx, CreateCodegenMetrics())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedFilePaths := []bazelFilepath{
|
||||
{
|
||||
dir: "android",
|
||||
basename: GeneratedBuildFileName,
|
||||
},
|
||||
{
|
||||
dir: "android",
|
||||
basename: "constants.bzl",
|
||||
},
|
||||
{
|
||||
dir: "cc_toolchain",
|
||||
basename: GeneratedBuildFileName,
|
||||
},
|
||||
{
|
||||
dir: "cc_toolchain",
|
||||
basename: "config_constants.bzl",
|
||||
},
|
||||
{
|
||||
dir: "cc_toolchain",
|
||||
basename: "sanitizer_constants.bzl",
|
||||
},
|
||||
{
|
||||
dir: "java_toolchain",
|
||||
basename: GeneratedBuildFileName,
|
||||
},
|
||||
{
|
||||
dir: "java_toolchain",
|
||||
basename: "constants.bzl",
|
||||
},
|
||||
{
|
||||
dir: "rust_toolchain",
|
||||
basename: GeneratedBuildFileName,
|
||||
},
|
||||
{
|
||||
dir: "rust_toolchain",
|
||||
basename: "constants.bzl",
|
||||
},
|
||||
{
|
||||
dir: "apex_toolchain",
|
||||
basename: GeneratedBuildFileName,
|
||||
},
|
||||
{
|
||||
dir: "apex_toolchain",
|
||||
basename: "constants.bzl",
|
||||
},
|
||||
{
|
||||
dir: "metrics",
|
||||
basename: "converted_modules.json",
|
||||
},
|
||||
{
|
||||
dir: "metrics",
|
||||
basename: "BUILD.bazel",
|
||||
},
|
||||
{
|
||||
dir: "metrics",
|
||||
basename: "converted_modules_path_map.json",
|
||||
},
|
||||
{
|
||||
dir: "metrics",
|
||||
basename: "converted_modules_path_map.bzl",
|
||||
},
|
||||
{
|
||||
dir: "product_config",
|
||||
basename: "soong_config_variables.bzl",
|
||||
},
|
||||
{
|
||||
dir: "product_config",
|
||||
basename: "arch_configuration.bzl",
|
||||
},
|
||||
{
|
||||
dir: "api_levels",
|
||||
basename: GeneratedBuildFileName,
|
||||
},
|
||||
{
|
||||
dir: "api_levels",
|
||||
basename: "api_levels.json",
|
||||
},
|
||||
{
|
||||
dir: "api_levels",
|
||||
basename: "platform_versions.bzl",
|
||||
},
|
||||
{
|
||||
dir: "allowlists",
|
||||
basename: GeneratedBuildFileName,
|
||||
},
|
||||
{
|
||||
dir: "allowlists",
|
||||
basename: "mixed_build_prod_allowlist.txt",
|
||||
},
|
||||
{
|
||||
dir: "allowlists",
|
||||
basename: "mixed_build_staging_allowlist.txt",
|
||||
},
|
||||
}
|
||||
|
||||
less := func(a bazelFilepath, b bazelFilepath) bool {
|
||||
return a.dir+"/"+a.basename < b.dir+"/"+b.basename
|
||||
}
|
||||
|
||||
fileToFilepath := func(a BazelFile) bazelFilepath {
|
||||
return bazelFilepath{basename: a.Basename, dir: a.Dir}
|
||||
}
|
||||
|
||||
sort.Slice(expectedFilePaths, func(i, j int) bool {
|
||||
return less(expectedFilePaths[i], expectedFilePaths[j])
|
||||
})
|
||||
sort.Slice(files, func(i, j int) bool {
|
||||
return less(fileToFilepath(files[i]), fileToFilepath(files[j]))
|
||||
})
|
||||
|
||||
i := 0
|
||||
j := 0
|
||||
for i < len(expectedFilePaths) && j < len(files) {
|
||||
expectedFile, actualFile := expectedFilePaths[i], files[j]
|
||||
|
||||
if actualFile.Dir == expectedFile.dir && actualFile.Basename == expectedFile.basename {
|
||||
i++
|
||||
j++
|
||||
} else if less(expectedFile, fileToFilepath(actualFile)) {
|
||||
t.Errorf("Did not find expected file %s/%s", expectedFile.dir, expectedFile.basename)
|
||||
i++
|
||||
} else {
|
||||
t.Errorf("Found unexpected file %s/%s", actualFile.Dir, actualFile.Basename)
|
||||
j++
|
||||
}
|
||||
}
|
||||
for i < len(expectedFilePaths) {
|
||||
expectedFile := expectedFilePaths[i]
|
||||
t.Errorf("Did not find expected file %s/%s", expectedFile.dir, expectedFile.basename)
|
||||
i++
|
||||
}
|
||||
for j < len(files) {
|
||||
actualFile := files[j]
|
||||
t.Errorf("Found unexpected file %s/%s", actualFile.Dir, actualFile.Basename)
|
||||
j++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func TestDroiddocExportedDir(t *testing.T) {
|
||||
bp := `
|
||||
droiddoc_exported_dir {
|
||||
name: "test-module",
|
||||
path: "docs",
|
||||
}
|
||||
`
|
||||
p := regexp.MustCompile(`\t*\|`)
|
||||
dedent := func(s string) string {
|
||||
return p.ReplaceAllString(s, "")
|
||||
}
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions(
|
||||
"droiddoc_exported_dir",
|
||||
"test-module",
|
||||
AttrNameToString{
|
||||
"dir": `"docs"`,
|
||||
"srcs": dedent(`[
|
||||
| "docs/android/1.txt",
|
||||
| "docs/android/nested-1/2.txt",
|
||||
| "//docs/android/nested-2:3.txt",
|
||||
| "//docs/android/nested-2:Android.bp",
|
||||
| ]`),
|
||||
}),
|
||||
//note we are not excluding Android.bp files from subpackages for now
|
||||
}
|
||||
RunBp2BuildTestCase(t, java.RegisterDocsBuildComponents, Bp2buildTestCase{
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
Filesystem: map[string]string{
|
||||
"docs/android/1.txt": "",
|
||||
"docs/android/nested-1/2.txt": "",
|
||||
"docs/android/nested-2/Android.bp": "",
|
||||
"docs/android/nested-2/3.txt": "",
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
)
|
||||
|
||||
func runFdoProfileTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "fdo_profile"
|
||||
(&tc).ModuleTypeUnderTestFactory = cc.FdoProfileFactory
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
|
||||
}
|
||||
|
||||
func TestFdoProfile(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
bp string
|
||||
expectedBazelAttrs AttrNameToString
|
||||
}{
|
||||
{
|
||||
name: "fdo_profile with arch-specific profiles",
|
||||
bp: `
|
||||
fdo_profile {
|
||||
name: "foo",
|
||||
arch: {
|
||||
arm: {
|
||||
profile: "foo_arm.afdo",
|
||||
},
|
||||
arm64: {
|
||||
profile: "foo_arm64.afdo",
|
||||
}
|
||||
}
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"profile": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "foo_arm.afdo",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "foo_arm64.afdo",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "fdo_profile with arch-agnostic profile",
|
||||
bp: `
|
||||
fdo_profile {
|
||||
name: "foo",
|
||||
profile: "foo.afdo",
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"profile": `"foo.afdo"`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
expectedBazelTargets := []string{
|
||||
// TODO(b/276287371): Add device-only restriction back to fdo_profile targets
|
||||
MakeBazelTargetNoRestrictions("fdo_profile", "foo", test.expectedBazelAttrs),
|
||||
}
|
||||
runFdoProfileTestCase(t, Bp2buildTestCase{
|
||||
Description: test.name,
|
||||
Blueprint: test.bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
func runFilegroupTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "filegroup"
|
||||
(&tc).ModuleTypeUnderTestFactory = android.FileGroupFactory
|
||||
RunBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
|
||||
|
||||
func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: "filegroup - same name as file, with one file",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["foo"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{},
|
||||
ExpectedHandcraftedModules: []string{"foo"}},
|
||||
)
|
||||
}
|
||||
|
||||
func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: "filegroup - same name as file, with multiple files",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["foo", "bar"],
|
||||
}
|
||||
`,
|
||||
ExpectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilegroupWithAidlSrcs(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
bp string
|
||||
expectedBazelAttrs AttrNameToString
|
||||
}{
|
||||
{
|
||||
name: "filegroup with only aidl srcs",
|
||||
bp: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["aidl/foo.aidl"],
|
||||
path: "aidl",
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `["aidl/foo.aidl"]`,
|
||||
"strip_import_prefix": `"aidl"`,
|
||||
"tags": `["apex_available=//apex_available:anyapex"]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "filegroup without path",
|
||||
bp: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["aidl/foo.aidl"],
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `["aidl/foo.aidl"]`,
|
||||
"tags": `["apex_available=//apex_available:anyapex"]`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions("aidl_library", "foo", test.expectedBazelAttrs),
|
||||
}
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: test.name,
|
||||
Blueprint: test.bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilegroupWithAidlAndNonAidlSrcs(t *testing.T) {
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: "filegroup with aidl and non-aidl srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"aidl/foo.aidl",
|
||||
"buf.proto",
|
||||
],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
|
||||
"srcs": `[
|
||||
"aidl/foo.aidl",
|
||||
"buf.proto",
|
||||
]`}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestFilegroupWithProtoSrcs(t *testing.T) {
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: "filegroup with proto and non-proto srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["proto/foo.proto"],
|
||||
path: "proto",
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("proto_library", "foo_proto", AttrNameToString{
|
||||
"srcs": `["proto/foo.proto"]`,
|
||||
"strip_import_prefix": `"proto"`,
|
||||
"tags": `[
|
||||
"apex_available=//apex_available:anyapex",
|
||||
"manual",
|
||||
]`,
|
||||
}),
|
||||
MakeBazelTargetNoRestrictions("alias", "foo_bp2build_converted", AttrNameToString{
|
||||
"actual": `"//.:foo_proto"`,
|
||||
"tags": `[
|
||||
"apex_available=//apex_available:anyapex",
|
||||
"manual",
|
||||
]`,
|
||||
}),
|
||||
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
|
||||
"srcs": `["proto/foo.proto"]`}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestFilegroupWithProtoAndNonProtoSrcs(t *testing.T) {
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: "filegroup with proto and non-proto srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"foo.proto",
|
||||
"buf.cpp",
|
||||
],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("filegroup", "foo", AttrNameToString{
|
||||
"srcs": `[
|
||||
"foo.proto",
|
||||
"buf.cpp",
|
||||
]`}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestFilegroupWithProtoInDifferentPackage(t *testing.T) {
|
||||
runFilegroupTestCase(t, Bp2buildTestCase{
|
||||
Description: "filegroup with .proto in different package",
|
||||
Filesystem: map[string]string{
|
||||
"subdir/Android.bp": "",
|
||||
},
|
||||
Blueprint: `
|
||||
filegroup {
|
||||
name: "foo",
|
||||
srcs: ["subdir/foo.proto"],
|
||||
}`,
|
||||
Dir: "subdir", // check in subdir
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("proto_library", "foo_proto", AttrNameToString{
|
||||
"srcs": `["//subdir:foo.proto"]`,
|
||||
"import_prefix": `"subdir"`,
|
||||
"strip_import_prefix": `""`,
|
||||
"tags": `[
|
||||
"apex_available=//apex_available:anyapex",
|
||||
"manual",
|
||||
]`}),
|
||||
}})
|
||||
}
|
|
@ -1,959 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/genrule"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func registerGenruleModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("genrule_defaults", func() android.Module { return genrule.DefaultsFactory() })
|
||||
ctx.RegisterModuleType("cc_binary", func() android.Module { return cc.BinaryFactory() })
|
||||
ctx.RegisterModuleType("soong_namespace", func() android.Module { return android.NamespaceFactory() })
|
||||
}
|
||||
|
||||
func runGenruleTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "genrule"
|
||||
(&tc).ModuleTypeUnderTestFactory = genrule.GenRuleFactory
|
||||
RunBp2BuildTestCase(t, registerGenruleModuleTypes, tc)
|
||||
}
|
||||
|
||||
func otherGenruleBp(genruleTarget string) map[string]string {
|
||||
return map[string]string{
|
||||
"other/Android.bp": fmt.Sprintf(`%s {
|
||||
name: "foo.tool",
|
||||
out: ["foo_tool.out"],
|
||||
srcs: ["foo_tool.in"],
|
||||
cmd: "cp $(in) $(out)",
|
||||
}
|
||||
%s {
|
||||
name: "other.tool",
|
||||
out: ["other_tool.out"],
|
||||
srcs: ["other_tool.in"],
|
||||
cmd: "cp $(in) $(out)",
|
||||
}`, genruleTarget, genruleTarget),
|
||||
"other/file.txt": "",
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleCliVariableReplacement(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
genDir string
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
genDir: "$(RULEDIR)",
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
genDir: "$(RULEDIR)",
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
genDir: "$(RULEDIR)",
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
genDir: "$(RULEDIR)",
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `%s {
|
||||
name: "foo.tool",
|
||||
out: ["foo_tool.out"],
|
||||
srcs: ["foo_tool.in"],
|
||||
cmd: "cp $(in) $(out)",
|
||||
}
|
||||
|
||||
%s {
|
||||
name: "foo",
|
||||
out: ["foo.out"],
|
||||
srcs: ["foo.in"],
|
||||
tools: [":foo.tool"],
|
||||
cmd: "$(location :foo.tool) --genDir=$(genDir) arg $(in) $(out)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": fmt.Sprintf(`"$(location :foo.tool) --genDir=%s arg $(SRCS) $(OUTS)"`, tc.genDir),
|
||||
"outs": `["foo.out"]`,
|
||||
"srcs": `["foo.in"]`,
|
||||
"tools": `[":foo.tool"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType),
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
StubbedBuildDefinitions: []string{"foo.tool", "other.tool"},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleLocationsLabel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `%s {
|
||||
name: "foo.tools",
|
||||
out: ["foo_tool.out", "foo_tool2.out"],
|
||||
srcs: ["foo_tool.in"],
|
||||
cmd: "cp $(in) $(out)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
%s {
|
||||
name: "foo",
|
||||
out: ["foo.out"],
|
||||
srcs: ["foo.in"],
|
||||
tools: [":foo.tools"],
|
||||
cmd: "$(locations :foo.tools) -s $(out) $(in)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
fooAttrs := AttrNameToString{
|
||||
"cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`,
|
||||
"outs": `["foo.out"]`,
|
||||
"srcs": `["foo.in"]`,
|
||||
"tools": `[":foo.tools"]`,
|
||||
}
|
||||
fooToolsAttrs := AttrNameToString{
|
||||
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
||||
"outs": `[
|
||||
"foo_tool.out",
|
||||
"foo_tool2.out",
|
||||
]`,
|
||||
"srcs": `["foo_tool.in"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", fooAttrs, tc.hod),
|
||||
makeBazelTargetHostOrDevice("genrule", "foo.tools", fooToolsAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType),
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleLocationsAbsoluteLabel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `%s {
|
||||
name: "foo",
|
||||
out: ["foo.out"],
|
||||
srcs: ["foo.in"],
|
||||
tool_files: [":foo.tool"],
|
||||
cmd: "$(locations :foo.tool) -s $(out) $(in)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
|
||||
"outs": `["foo.out"]`,
|
||||
"srcs": `["foo.in"]`,
|
||||
"tools": `["//other:foo.tool"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
Filesystem: otherGenruleBp(tc.moduleType),
|
||||
StubbedBuildDefinitions: []string{"//other:foo.tool"},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `%s {
|
||||
name: "foo",
|
||||
out: ["foo.out"],
|
||||
srcs: [":other.tool", "other/file.txt",],
|
||||
tool_files: [":foo.tool"],
|
||||
cmd: "$(locations :foo.tool) $(location other/file.txt) -s $(out) $(location :other.tool)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `"$(locations //other:foo.tool) $(location //other:file.txt) -s $(OUTS) $(location //other:other.tool)"`,
|
||||
"outs": `["foo.out"]`,
|
||||
"srcs": `[
|
||||
"//other:other.tool",
|
||||
"//other:file.txt",
|
||||
]`,
|
||||
"tools": `["//other:foo.tool"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
Filesystem: otherGenruleBp(tc.moduleType),
|
||||
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `%s {
|
||||
name: "foo",
|
||||
out: ["foo.out"],
|
||||
srcs: ["foo.in"],
|
||||
tool_files: [":foo.tool", ":other.tool"],
|
||||
cmd: "$(location) -s $(out) $(in)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`,
|
||||
"outs": `["foo.out"]`,
|
||||
"srcs": `["foo.in"]`,
|
||||
"tools": `[
|
||||
"//other:foo.tool",
|
||||
"//other:other.tool",
|
||||
]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
Filesystem: otherGenruleBp(tc.moduleType),
|
||||
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `%s {
|
||||
name: "foo",
|
||||
out: ["foo.out"],
|
||||
srcs: ["foo.in"],
|
||||
tool_files: [":foo.tool", ":other.tool"],
|
||||
cmd: "$(locations) -s $(out) $(in)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
|
||||
"outs": `["foo.out"]`,
|
||||
"srcs": `["foo.in"]`,
|
||||
"tools": `[
|
||||
"//other:foo.tool",
|
||||
"//other:other.tool",
|
||||
]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
Filesystem: otherGenruleBp(tc.moduleType),
|
||||
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleWithoutToolsOrToolFiles(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `%s {
|
||||
name: "foo",
|
||||
out: ["foo.out"],
|
||||
srcs: ["foo.in"],
|
||||
cmd: "cp $(in) $(out)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
||||
"outs": `["foo.out"]`,
|
||||
"srcs": `["foo.in"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleBp2BuildInlinesDefaults(t *testing.T) {
|
||||
testCases := []Bp2buildTestCase{
|
||||
{
|
||||
Description: "genrule applies properties from a genrule_defaults dependency if not specified",
|
||||
Blueprint: `genrule_defaults {
|
||||
name: "gen_defaults",
|
||||
cmd: "do-something $(in) $(out)",
|
||||
}
|
||||
genrule {
|
||||
name: "gen",
|
||||
out: ["out"],
|
||||
srcs: ["in1"],
|
||||
defaults: ["gen_defaults"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
||||
"cmd": `"do-something $(SRCS) $(OUTS)"`,
|
||||
"outs": `["out"]`,
|
||||
"srcs": `["in1"]`,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "genrule does merges properties from a genrule_defaults dependency, latest-first",
|
||||
Blueprint: `genrule_defaults {
|
||||
name: "gen_defaults",
|
||||
out: ["out-from-defaults"],
|
||||
srcs: ["in-from-defaults"],
|
||||
cmd: "cmd-from-defaults",
|
||||
}
|
||||
genrule {
|
||||
name: "gen",
|
||||
out: ["out"],
|
||||
srcs: ["in1"],
|
||||
defaults: ["gen_defaults"],
|
||||
cmd: "do-something $(in) $(out)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
||||
"cmd": `"do-something $(SRCS) $(OUTS)"`,
|
||||
"outs": `[
|
||||
"out-from-defaults",
|
||||
"out",
|
||||
]`,
|
||||
"srcs": `[
|
||||
"in-from-defaults",
|
||||
"in1",
|
||||
]`,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "genrule applies properties from list of genrule_defaults",
|
||||
Blueprint: `genrule_defaults {
|
||||
name: "gen_defaults1",
|
||||
cmd: "cp $(in) $(out)",
|
||||
}
|
||||
|
||||
genrule_defaults {
|
||||
name: "gen_defaults2",
|
||||
srcs: ["in1"],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "gen",
|
||||
out: ["out"],
|
||||
defaults: ["gen_defaults1", "gen_defaults2"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
||||
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
||||
"outs": `["out"]`,
|
||||
"srcs": `["in1"]`,
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "genrule applies properties from genrule_defaults transitively",
|
||||
Blueprint: `genrule_defaults {
|
||||
name: "gen_defaults1",
|
||||
defaults: ["gen_defaults2"],
|
||||
cmd: "cmd1 $(in) $(out)", // overrides gen_defaults2's cmd property value.
|
||||
}
|
||||
|
||||
genrule_defaults {
|
||||
name: "gen_defaults2",
|
||||
defaults: ["gen_defaults3"],
|
||||
cmd: "cmd2 $(in) $(out)",
|
||||
out: ["out-from-2"],
|
||||
srcs: ["in1"],
|
||||
}
|
||||
|
||||
genrule_defaults {
|
||||
name: "gen_defaults3",
|
||||
out: ["out-from-3"],
|
||||
srcs: ["srcs-from-3"],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "gen",
|
||||
out: ["out"],
|
||||
defaults: ["gen_defaults1"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
||||
"cmd": `"cmd1 $(SRCS) $(OUTS)"`,
|
||||
"outs": `[
|
||||
"out-from-3",
|
||||
"out-from-2",
|
||||
"out",
|
||||
]`,
|
||||
"srcs": `[
|
||||
"srcs-from-3",
|
||||
"in1",
|
||||
]`,
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.Description, func(t *testing.T) {
|
||||
runGenruleTestCase(t, testCase)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCcGenruleArchAndExcludeSrcs(t *testing.T) {
|
||||
name := "cc_genrule with arch"
|
||||
bp := `
|
||||
cc_genrule {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"foo1.in",
|
||||
"foo2.in",
|
||||
],
|
||||
exclude_srcs: ["foo2.in"],
|
||||
arch: {
|
||||
arm: {
|
||||
srcs: [
|
||||
"foo1_arch.in",
|
||||
"foo2_arch.in",
|
||||
],
|
||||
exclude_srcs: ["foo2_arch.in"],
|
||||
},
|
||||
},
|
||||
cmd: "cat $(in) > $(out)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
expectedBazelAttrs := AttrNameToString{
|
||||
"srcs": `["foo1.in"] + select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["foo1_arch.in"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"cmd": `"cat $(SRCS) > $(OUTS)"`,
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions("genrule", "foo", expectedBazelAttrs),
|
||||
}
|
||||
|
||||
t.Run(name, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: "cc_genrule",
|
||||
ModuleTypeUnderTestFactory: cc.GenRuleFactory,
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestGenruleWithExportIncludeDirs(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
dir := "baz"
|
||||
|
||||
bp := `%s {
|
||||
name: "foo",
|
||||
out: ["foo.out.h"],
|
||||
srcs: ["foo.in"],
|
||||
cmd: "cp $(in) $(out)",
|
||||
export_include_dirs: ["foo", "bar", "."],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
||||
"outs": `["foo.out.h"]`,
|
||||
"srcs": `["foo.in"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
makeBazelTargetHostOrDevice("cc_library_headers", "foo__header_library", AttrNameToString{
|
||||
"hdrs": `[":foo"]`,
|
||||
"export_includes": `[
|
||||
"foo",
|
||||
"baz/foo",
|
||||
"bar",
|
||||
"baz/bar",
|
||||
".",
|
||||
"baz",
|
||||
]`,
|
||||
},
|
||||
tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
Filesystem: map[string]string{
|
||||
filepath.Join(dir, "Android.bp"): fmt.Sprintf(bp, tc.moduleType),
|
||||
},
|
||||
Dir: dir,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleWithSoongConfigVariableConfiguredCmd(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `
|
||||
soong_config_module_type {
|
||||
name: "my_genrule",
|
||||
module_type: "%s",
|
||||
config_namespace: "my_namespace",
|
||||
bool_variables: ["my_variable"],
|
||||
properties: ["cmd"],
|
||||
}
|
||||
|
||||
my_genrule {
|
||||
name: "foo",
|
||||
out: ["foo.txt"],
|
||||
cmd: "echo 'no variable' > $(out)",
|
||||
soong_config_variables: {
|
||||
my_variable: {
|
||||
cmd: "echo 'with variable' > $(out)",
|
||||
},
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `select({
|
||||
"//build/bazel/product_config/config_settings:my_namespace__my_variable": "echo 'with variable' > $(OUTS)",
|
||||
"//conditions:default": "echo 'no variable' > $(OUTS)",
|
||||
})`,
|
||||
"outs": `["foo.txt"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
|
||||
Bp2buildTestCase{
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleWithProductVariableConfiguredCmd(t *testing.T) {
|
||||
testCases := []struct {
|
||||
moduleType string
|
||||
factory android.ModuleFactory
|
||||
hod android.HostOrDeviceSupported
|
||||
}{
|
||||
{
|
||||
moduleType: "genrule",
|
||||
factory: genrule.GenRuleFactory,
|
||||
},
|
||||
{
|
||||
moduleType: "cc_genrule",
|
||||
factory: cc.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule",
|
||||
factory: java.GenRuleFactory,
|
||||
hod: android.DeviceSupported,
|
||||
},
|
||||
{
|
||||
moduleType: "java_genrule_host",
|
||||
factory: java.GenRuleFactoryHost,
|
||||
hod: android.HostSupported,
|
||||
},
|
||||
}
|
||||
|
||||
bp := `
|
||||
|
||||
%s {
|
||||
name: "foo",
|
||||
out: ["foo.txt"],
|
||||
cmd: "echo 'no variable' > $(out)",
|
||||
product_variables: {
|
||||
debuggable: {
|
||||
cmd: "echo 'with variable' > $(out)",
|
||||
},
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`
|
||||
|
||||
for _, tc := range testCases {
|
||||
moduleAttrs := AttrNameToString{
|
||||
"cmd": `select({
|
||||
"//build/bazel/product_config/config_settings:debuggable": "echo 'with variable' > $(OUTS)",
|
||||
"//conditions:default": "echo 'no variable' > $(OUTS)",
|
||||
})`,
|
||||
"outs": `["foo.txt"]`,
|
||||
}
|
||||
|
||||
expectedBazelTargets := []string{
|
||||
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
||||
}
|
||||
|
||||
t.Run(tc.moduleType, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
|
||||
Bp2buildTestCase{
|
||||
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
||||
ModuleTypeUnderTest: tc.moduleType,
|
||||
ModuleTypeUnderTestFactory: tc.factory,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenruleWithModulesInNamespaces(t *testing.T) {
|
||||
bp := `
|
||||
genrule {
|
||||
name: "mygenrule",
|
||||
cmd: "echo $(location //mynamespace:mymodule) > $(out)",
|
||||
srcs: ["//mynamespace:mymodule"],
|
||||
out: ["myout"],
|
||||
}
|
||||
`
|
||||
fs := map[string]string{
|
||||
"mynamespace/Android.bp": `soong_namespace {}`,
|
||||
"mynamespace/dir/Android.bp": `cc_binary {name: "mymodule"}`,
|
||||
}
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions("genrule", "mygenrule", AttrNameToString{
|
||||
// The fully qualified soong label is <namespace>:<module_name>
|
||||
// - here the prefix is mynamespace
|
||||
// The fully qualifed bazel label is <package>:<module_name>
|
||||
// - here the prefix is mynamespace/dir, since there is a BUILD file at each level of this FS path
|
||||
"cmd": `"echo $(location //mynamespace/dir:mymodule) > $(OUTS)"`,
|
||||
"outs": `["myout"]`,
|
||||
"srcs": `["//mynamespace/dir:mymodule"]`,
|
||||
}),
|
||||
}
|
||||
|
||||
t.Run("genrule that uses module from a different namespace", func(t *testing.T) {
|
||||
runGenruleTestCase(t, Bp2buildTestCase{
|
||||
Blueprint: bp,
|
||||
Filesystem: fs,
|
||||
ModuleTypeUnderTest: "genrule",
|
||||
ModuleTypeUnderTestFactory: genrule.GenRuleFactory,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
StubbedBuildDefinitions: []string{"//mynamespace/dir:mymodule"},
|
||||
})
|
||||
})
|
||||
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
// Copyright 2020 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/genrule"
|
||||
)
|
||||
|
||||
func registerModulesForGensrcsTests(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}
|
||||
|
||||
func TestGensrcs(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
bp string
|
||||
expectedBazelAttrs AttrNameToString
|
||||
stubbedBuildDefinitions []string
|
||||
}{
|
||||
{
|
||||
name: "gensrcs with common usage of properties",
|
||||
bp: `
|
||||
gensrcs {
|
||||
name: "foo",
|
||||
srcs: ["test/input.txt", ":external_files"],
|
||||
tool_files: ["program.py"],
|
||||
cmd: "$(location program.py) $(in) $(out) $(location foo/file.txt) $(location :external_files)",
|
||||
data: ["foo/file.txt", ":external_files"],
|
||||
output_extension: "out",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
filegroup {
|
||||
name: "external_files",
|
||||
}`,
|
||||
stubbedBuildDefinitions: []string{"external_files"},
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `[
|
||||
"test/input.txt",
|
||||
":external_files",
|
||||
]`,
|
||||
"tools": `["program.py"]`,
|
||||
"output_extension": `"out"`,
|
||||
"cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files)"`,
|
||||
"data": `[
|
||||
"foo/file.txt",
|
||||
":external_files",
|
||||
]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "gensrcs with out_extension unset",
|
||||
bp: `
|
||||
gensrcs {
|
||||
name: "foo",
|
||||
srcs: ["input.txt"],
|
||||
cmd: "cat $(in) > $(out)",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
expectedBazelAttrs: AttrNameToString{
|
||||
"srcs": `["input.txt"]`,
|
||||
"cmd": `"cat $(SRC) > $(OUT)"`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
expectedBazelTargets := []string{
|
||||
MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
|
||||
}
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, registerModulesForGensrcsTests,
|
||||
Bp2buildTestCase{
|
||||
ModuleTypeUnderTest: "gensrcs",
|
||||
ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
|
||||
Blueprint: test.bp,
|
||||
ExpectedBazelTargets: expectedBazelTargets,
|
||||
StubbedBuildDefinitions: test.stubbedBuildDefinitions,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/blueprint/bootstrap"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
func runGoTests(t *testing.T, tc Bp2buildTestCase) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
tCtx := ctx.(*android.TestContext)
|
||||
bootstrap.RegisterGoModuleTypes(tCtx.Context.Context) // android.TestContext --> android.Context --> blueprint.Context
|
||||
}, tc)
|
||||
}
|
||||
|
||||
func TestConvertGoPackage(t *testing.T) {
|
||||
bp := `
|
||||
bootstrap_go_package {
|
||||
name: "foo",
|
||||
pkgPath: "android/foo",
|
||||
deps: [
|
||||
"bar",
|
||||
],
|
||||
srcs: [
|
||||
"foo1.go",
|
||||
"foo2.go",
|
||||
],
|
||||
linux: {
|
||||
srcs: [
|
||||
"foo_linux.go",
|
||||
],
|
||||
testSrcs: [
|
||||
"foo_linux_test.go",
|
||||
],
|
||||
},
|
||||
darwin: {
|
||||
srcs: [
|
||||
"foo_darwin.go",
|
||||
],
|
||||
testSrcs: [
|
||||
"foo_darwin_test.go",
|
||||
],
|
||||
},
|
||||
testSrcs: [
|
||||
"foo1_test.go",
|
||||
"foo2_test.go",
|
||||
],
|
||||
}
|
||||
`
|
||||
depBp := `
|
||||
bootstrap_go_package {
|
||||
name: "bar",
|
||||
}
|
||||
`
|
||||
t.Parallel()
|
||||
runGoTests(t, Bp2buildTestCase{
|
||||
Description: "Convert bootstrap_go_package to go_library",
|
||||
ModuleTypeUnderTest: "bootrstap_go_package",
|
||||
Blueprint: bp,
|
||||
Filesystem: map[string]string{
|
||||
"bar/Android.bp": depBp, // Put dep in Android.bp to reduce boilerplate in ExpectedBazelTargets
|
||||
},
|
||||
ExpectedBazelTargets: []string{makeBazelTargetHostOrDevice("go_library", "foo",
|
||||
AttrNameToString{
|
||||
"deps": `["//bar:bar"]`,
|
||||
"importpath": `"android/foo"`,
|
||||
"srcs": `[
|
||||
"foo1.go",
|
||||
"foo2.go",
|
||||
] + select({
|
||||
"//build/bazel_common_rules/platforms/os:darwin": ["foo_darwin.go"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_glibc": ["foo_linux.go"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
android.HostSupported,
|
||||
),
|
||||
makeBazelTargetHostOrDevice("go_test", "foo-test",
|
||||
AttrNameToString{
|
||||
"embed": `[":foo"]`,
|
||||
"srcs": `[
|
||||
"foo1_test.go",
|
||||
"foo2_test.go",
|
||||
] + select({
|
||||
"//build/bazel_common_rules/platforms/os:darwin": ["foo_darwin_test.go"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_glibc": ["foo_linux_test.go"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
},
|
||||
android.HostSupported,
|
||||
)},
|
||||
})
|
||||
}
|
||||
|
||||
func TestConvertGoBinaryWithTransitiveDeps(t *testing.T) {
|
||||
bp := `
|
||||
blueprint_go_binary {
|
||||
name: "foo",
|
||||
srcs: ["main.go"],
|
||||
deps: ["bar"],
|
||||
}
|
||||
`
|
||||
depBp := `
|
||||
bootstrap_go_package {
|
||||
name: "bar",
|
||||
deps: ["baz"],
|
||||
}
|
||||
bootstrap_go_package {
|
||||
name: "baz",
|
||||
}
|
||||
`
|
||||
t.Parallel()
|
||||
runGoTests(t, Bp2buildTestCase{
|
||||
Description: "Convert blueprint_go_binary to go_binary",
|
||||
Blueprint: bp,
|
||||
Filesystem: map[string]string{
|
||||
"bar/Android.bp": depBp, // Put dep in Android.bp to reduce boilerplate in ExpectedBazelTargets
|
||||
},
|
||||
ExpectedBazelTargets: []string{makeBazelTargetHostOrDevice("go_binary", "foo",
|
||||
AttrNameToString{
|
||||
"deps": `[
|
||||
"//bar:bar",
|
||||
"//bar:baz",
|
||||
]`,
|
||||
"srcs": `["main.go"]`,
|
||||
},
|
||||
android.HostSupported,
|
||||
)},
|
||||
})
|
||||
}
|
||||
|
||||
func TestConvertGoBinaryWithTestSrcs(t *testing.T) {
|
||||
bp := `
|
||||
blueprint_go_binary {
|
||||
name: "foo",
|
||||
srcs: ["main.go"],
|
||||
testSrcs: ["main_test.go"],
|
||||
}
|
||||
`
|
||||
t.Parallel()
|
||||
runGoTests(t, Bp2buildTestCase{
|
||||
Description: "Convert blueprint_go_binary with testSrcs",
|
||||
Blueprint: bp,
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTargetHostOrDevice("go_binary", "foo",
|
||||
AttrNameToString{
|
||||
"deps": `[]`,
|
||||
"embed": `[":foo-source"]`,
|
||||
},
|
||||
android.HostSupported,
|
||||
),
|
||||
makeBazelTargetHostOrDevice("go_source", "foo-source",
|
||||
AttrNameToString{
|
||||
"deps": `[]`,
|
||||
"srcs": `["main.go"]`,
|
||||
},
|
||||
android.HostSupported,
|
||||
),
|
||||
makeBazelTargetHostOrDevice("go_test", "foo-test",
|
||||
AttrNameToString{
|
||||
"embed": `[":foo-source"]`,
|
||||
"srcs": `["main_test.go"]`,
|
||||
},
|
||||
android.HostSupported,
|
||||
),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestConvertGoBinaryWithSrcInDifferentPackage(t *testing.T) {
|
||||
bp := `
|
||||
blueprint_go_binary {
|
||||
name: "foo",
|
||||
srcs: ["subdir/main.go"],
|
||||
}
|
||||
`
|
||||
t.Parallel()
|
||||
runGoTests(t, Bp2buildTestCase{
|
||||
Description: "Convert blueprint_go_binary with src in different package",
|
||||
Blueprint: bp,
|
||||
Filesystem: map[string]string{
|
||||
"subdir/Android.bp": "",
|
||||
},
|
||||
ExpectedBazelTargets: []string{makeBazelTargetHostOrDevice("go_binary", "foo",
|
||||
AttrNameToString{
|
||||
"deps": `[]`,
|
||||
"srcs": `["//subdir:main.go"]`,
|
||||
},
|
||||
android.HostSupported,
|
||||
)},
|
||||
})
|
||||
}
|
|
@ -1,338 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_binary_host"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.BinaryHostFactory
|
||||
tc.StubbedBuildDefinitions = append(tc.StubbedBuildDefinitions, "//other:jni-lib-1")
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory)
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
ctx.RegisterModuleType("java_import_host", java.ImportFactory)
|
||||
}, tc)
|
||||
}
|
||||
|
||||
var testFs = map[string]string{
|
||||
"test.mf": "Main-Class: com.android.test.MainClass",
|
||||
"other/Android.bp": `cc_library_host_shared {
|
||||
name: "jni-lib-1",
|
||||
stl: "none",
|
||||
}`,
|
||||
}
|
||||
|
||||
func TestJavaBinaryHost(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
|
||||
Filesystem: testFs,
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host-1",
|
||||
srcs: ["a.java", "b.java"],
|
||||
exclude_srcs: ["b.java"],
|
||||
manifest: "test.mf",
|
||||
jni_libs: ["jni-lib-1"],
|
||||
javacflags: ["-Xdoclint:all/protected"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
java_version: "8",
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_library", "java-binary-host-1_lib", AttrNameToString{
|
||||
"srcs": `["a.java"]`,
|
||||
"deps": `["//other:jni-lib-1"]`,
|
||||
"java_version": `"8"`,
|
||||
"javacopts": `["-Xdoclint:all/protected"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other/jni-lib-1"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"runtime_deps": `[":java-binary-host-1_lib"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostRuntimeDeps(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with srcs, exclude_srcs, jni_libs, javacflags, and manifest.",
|
||||
Filesystem: testFs,
|
||||
StubbedBuildDefinitions: []string{"java-dep-1"},
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host-1",
|
||||
static_libs: ["java-dep-1"],
|
||||
manifest: "test.mf",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "java-dep-1",
|
||||
srcs: ["a.java"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"runtime_deps": `[":java-dep-1"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostLibs(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with srcs, libs.",
|
||||
Filesystem: testFs,
|
||||
StubbedBuildDefinitions: []string{"java-lib-dep-1", "java-lib-dep-1-neverlink"},
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host-libs",
|
||||
libs: ["java-lib-dep-1"],
|
||||
manifest: "test.mf",
|
||||
srcs: ["a.java"],
|
||||
}
|
||||
|
||||
java_import_host{
|
||||
name: "java-lib-dep-1",
|
||||
jars: ["foo.jar"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_library", "java-binary-host-libs_lib", AttrNameToString{
|
||||
"srcs": `["a.java"]`,
|
||||
"deps": `[":java-lib-dep-1-neverlink"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_binary", "java-binary-host-libs", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"runtime_deps": `[":java-binary-host-libs_lib"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostKotlinSrcs(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with srcs, libs.",
|
||||
Filesystem: testFs,
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host",
|
||||
manifest: "test.mf",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"runtime_deps": `[":java-binary-host_lib"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostKotlinCommonSrcs(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with common_srcs",
|
||||
Filesystem: testFs,
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host",
|
||||
manifest: "test.mf",
|
||||
srcs: ["a.java"],
|
||||
common_srcs: ["b.kt"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
||||
"srcs": `["a.java"]`,
|
||||
"common_srcs": `["b.kt"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"runtime_deps": `[":java-binary-host_lib"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostKotlinWithResourceDir(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with srcs, libs, resource dir .",
|
||||
Filesystem: map[string]string{
|
||||
"test.mf": "Main-Class: com.android.test.MainClass",
|
||||
"res/a.res": "",
|
||||
"res/dir1/b.res": "",
|
||||
},
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host",
|
||||
manifest: "test.mf",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
java_resource_dirs: ["res"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"resources": `[
|
||||
"res/a.res",
|
||||
"res/dir1/b.res",
|
||||
]`,
|
||||
"resource_strip_prefix": `"res"`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"runtime_deps": `[":java-binary-host_lib"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostKotlinWithResources(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with srcs, libs, resources.",
|
||||
Filesystem: map[string]string{
|
||||
"adir/test.mf": "Main-Class: com.android.test.MainClass",
|
||||
"adir/res/a.res": "",
|
||||
"adir/res/b.res": "",
|
||||
"adir/Android.bp": `java_binary_host {
|
||||
name: "java-binary-host",
|
||||
manifest: "test.mf",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
java_resources: ["res/a.res", "res/b.res"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
},
|
||||
Dir: "adir",
|
||||
Blueprint: "",
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"resources": `[
|
||||
"res/a.res",
|
||||
"res/b.res",
|
||||
]`,
|
||||
"resource_strip_prefix": `"adir"`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"runtime_deps": `[":java-binary-host_lib"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaBinaryHostKotlinCflags(t *testing.T) {
|
||||
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_binary_host with kotlincflags",
|
||||
Filesystem: testFs,
|
||||
Blueprint: `java_binary_host {
|
||||
name: "java-binary-host",
|
||||
manifest: "test.mf",
|
||||
srcs: ["a.kt"],
|
||||
kotlincflags: ["-flag1", "-flag2"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("kt_jvm_library", "java-binary-host_lib", AttrNameToString{
|
||||
"srcs": `["a.kt"]`,
|
||||
"kotlincflags": `[
|
||||
"-flag1",
|
||||
"-flag2",
|
||||
]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
||||
"main_class": `"com.android.test.MainClass"`,
|
||||
"runtime_deps": `[":java-binary-host_lib"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_host_for_device"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.HostForDeviceFactory
|
||||
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
|
||||
}
|
||||
|
||||
func runJavaHostForDeviceTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
runJavaHostForDeviceTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaHostForDevice(t *testing.T) {
|
||||
runJavaHostForDeviceTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_host_for_device test",
|
||||
Blueprint: `java_host_for_device {
|
||||
name: "java-lib-1",
|
||||
libs: ["java-lib-2"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "java-lib-2",
|
||||
srcs: ["b.java"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
sdk_version: "current",
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_host_for_device", "java-lib-1", AttrNameToString{
|
||||
"exports": `[":java-lib-2"]`,
|
||||
}),
|
||||
MakeNeverlinkDuplicateTargetWithAttrs("java_library", "java-lib-1", AttrNameToString{
|
||||
"sdk_version": `"none"`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-lib-2", AttrNameToString{
|
||||
"srcs": `["b.java"]`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeNeverlinkDuplicateTarget("java_library", "java-lib-2"),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runJavaImportTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_import"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.ImportFactory
|
||||
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
|
||||
}
|
||||
|
||||
func runJavaImportTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerJavaImportModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerJavaImportModuleTypes(ctx android.RegistrationContext) {
|
||||
}
|
||||
|
||||
func TestJavaImportMinimal(t *testing.T) {
|
||||
runJavaImportTestCase(t, Bp2buildTestCase{
|
||||
Description: "Java import - simple example",
|
||||
ModuleTypeUnderTest: "java_import",
|
||||
ModuleTypeUnderTestFactory: java.ImportFactory,
|
||||
Filesystem: map[string]string{
|
||||
"import.jar": "",
|
||||
},
|
||||
Blueprint: `
|
||||
java_import {
|
||||
name: "example_import",
|
||||
jars: ["import.jar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_import", "example_import", AttrNameToString{
|
||||
"jars": `["import.jar"]`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
|
||||
"exports": `[":example_import"]`,
|
||||
"neverlink": `True`,
|
||||
"sdk_version": `"none"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestJavaImportArchVariant(t *testing.T) {
|
||||
runJavaImportTestCase(t, Bp2buildTestCase{
|
||||
Description: "Java import - simple example",
|
||||
ModuleTypeUnderTest: "java_import",
|
||||
ModuleTypeUnderTestFactory: java.ImportFactory,
|
||||
Filesystem: map[string]string{
|
||||
"import.jar": "",
|
||||
},
|
||||
Blueprint: `
|
||||
java_import {
|
||||
name: "example_import",
|
||||
target: {
|
||||
android: {
|
||||
jars: ["android.jar"],
|
||||
},
|
||||
linux_glibc: {
|
||||
jars: ["linux.jar"],
|
||||
},
|
||||
},
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_import", "example_import", AttrNameToString{
|
||||
"jars": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["android.jar"],
|
||||
"//build/bazel_common_rules/platforms/os:linux_glibc": ["linux.jar"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
|
||||
"exports": `[":example_import"]`,
|
||||
"neverlink": `True`,
|
||||
"sdk_version": `"none"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestJavaImportHost(t *testing.T) {
|
||||
runJavaImportTestCase(t, Bp2buildTestCase{
|
||||
Description: "Java import host- simple example",
|
||||
ModuleTypeUnderTest: "java_import_host",
|
||||
ModuleTypeUnderTestFactory: java.ImportFactory,
|
||||
Filesystem: map[string]string{
|
||||
"import.jar": "",
|
||||
},
|
||||
Blueprint: `
|
||||
java_import_host {
|
||||
name: "example_import",
|
||||
jars: ["import.jar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_import", "example_import", AttrNameToString{
|
||||
"jars": `["import.jar"]`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
|
||||
"exports": `[":example_import"]`,
|
||||
"neverlink": `True`,
|
||||
"sdk_version": `"none"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestJavaImportSameNameAsJavaLibrary(t *testing.T) {
|
||||
runJavaImportTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
||||
Description: "java_import has the same name as other package java_library's",
|
||||
Filesystem: map[string]string{
|
||||
"foo/bar/Android.bp": simpleModule("java_library", "test_lib"),
|
||||
"test.jar": "",
|
||||
},
|
||||
Blueprint: `java_import {
|
||||
name: "test_lib",
|
||||
jars: ["test.jar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_import", "test_lib", AttrNameToString{
|
||||
"jars": `["test.jar"]`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "test_lib-neverlink", AttrNameToString{
|
||||
"exports": `[":test_lib"]`,
|
||||
"neverlink": `True`,
|
||||
"sdk_version": `"none"`,
|
||||
}),
|
||||
},
|
||||
}, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
})
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,84 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaLibraryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_library_host"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.LibraryHostFactory
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
|
||||
}
|
||||
|
||||
func TestJavaLibraryHost(t *testing.T) {
|
||||
runJavaLibraryHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_library_host with srcs, exclude_srcs and libs",
|
||||
Blueprint: `java_library_host {
|
||||
name: "java-lib-host-1",
|
||||
srcs: ["a.java", "b.java"],
|
||||
exclude_srcs: ["b.java"],
|
||||
libs: ["java-lib-host-2"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
java_library_host {
|
||||
name: "java-lib-host-2",
|
||||
srcs: ["c.java"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
java_version: "9",
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_library", "java-lib-host-1", AttrNameToString{
|
||||
"srcs": `["a.java"]`,
|
||||
"deps": `[":java-lib-host-2-neverlink"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-lib-host-1-neverlink", AttrNameToString{
|
||||
"exports": `[":java-lib-host-1"]`,
|
||||
"neverlink": `True`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-lib-host-2", AttrNameToString{
|
||||
"java_version": `"9"`,
|
||||
"srcs": `["c.java"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-lib-host-2-neverlink", AttrNameToString{
|
||||
"exports": `[":java-lib-host-2"]`,
|
||||
"neverlink": `True`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"java_version": `"9"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaPluginTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_plugin"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.PluginFactory
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
}, tc)
|
||||
}
|
||||
|
||||
func TestJavaPlugin(t *testing.T) {
|
||||
runJavaPluginTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_plugin with srcs, libs, static_libs",
|
||||
StubbedBuildDefinitions: []string{"java-lib-1", "java-lib-2"},
|
||||
Blueprint: `java_plugin {
|
||||
name: "java-plug-1",
|
||||
srcs: ["a.java", "b.java"],
|
||||
libs: ["java-lib-1"],
|
||||
static_libs: ["java-lib-2"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
java_version: "7",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "java-lib-1",
|
||||
srcs: ["b.java"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "java-lib-2",
|
||||
srcs: ["c.java"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"deps": `[
|
||||
":java-lib-1-neverlink",
|
||||
":java-lib-2",
|
||||
]`,
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.java",
|
||||
]`,
|
||||
"java_version": `"7"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaPluginNoSrcs(t *testing.T) {
|
||||
runJavaPluginTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_plugin without srcs converts (static) libs to deps",
|
||||
StubbedBuildDefinitions: []string{"java-lib-1", "java-lib-2"},
|
||||
Blueprint: `java_plugin {
|
||||
name: "java-plug-1",
|
||||
libs: ["java-lib-1"],
|
||||
static_libs: ["java-lib-2"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "java-lib-1",
|
||||
srcs: ["b.java"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "java-lib-2",
|
||||
srcs: ["c.java"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_plugin", "java-plug-1", AttrNameToString{
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"deps": `[
|
||||
":java-lib-1-neverlink",
|
||||
":java-lib-2",
|
||||
]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,238 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaProtoTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_library_static"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.LibraryFactory
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
|
||||
}
|
||||
|
||||
func TestJavaProto(t *testing.T) {
|
||||
testCases := []struct {
|
||||
protoType string
|
||||
javaLibraryType string
|
||||
javaLibraryNameExtension string
|
||||
}{
|
||||
{
|
||||
protoType: "nano",
|
||||
javaLibraryType: "java_nano_proto_library",
|
||||
javaLibraryNameExtension: "java_proto_nano",
|
||||
},
|
||||
{
|
||||
protoType: "micro",
|
||||
javaLibraryType: "java_micro_proto_library",
|
||||
javaLibraryNameExtension: "java_proto_micro",
|
||||
},
|
||||
{
|
||||
protoType: "lite",
|
||||
javaLibraryType: "java_lite_proto_library",
|
||||
javaLibraryNameExtension: "java_proto_lite",
|
||||
},
|
||||
{
|
||||
protoType: "stream",
|
||||
javaLibraryType: "java_stream_proto_library",
|
||||
javaLibraryNameExtension: "java_proto_stream",
|
||||
},
|
||||
{
|
||||
protoType: "full",
|
||||
javaLibraryType: "java_proto_library",
|
||||
javaLibraryNameExtension: "java_proto",
|
||||
},
|
||||
}
|
||||
|
||||
bp := `java_library_static {
|
||||
name: "java-protos",
|
||||
proto: {
|
||||
type: "%s",
|
||||
},
|
||||
srcs: ["a.proto"],
|
||||
sdk_version: "current",
|
||||
}`
|
||||
|
||||
protoLibrary := MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
|
||||
"srcs": `["a.proto"]`,
|
||||
})
|
||||
|
||||
for _, tc := range testCases {
|
||||
javaLibraryName := fmt.Sprintf("java-protos_%s", tc.javaLibraryNameExtension)
|
||||
|
||||
runJavaProtoTestCase(t, Bp2buildTestCase{
|
||||
Description: fmt.Sprintf("java_proto %s", tc.protoType),
|
||||
Blueprint: fmt.Sprintf(bp, tc.protoType),
|
||||
ExpectedBazelTargets: []string{
|
||||
protoLibrary,
|
||||
MakeBazelTarget(
|
||||
tc.javaLibraryType,
|
||||
javaLibraryName,
|
||||
AttrNameToString{
|
||||
"deps": `[":java-protos_proto"]`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
|
||||
"exports": fmt.Sprintf(`[":%s"]`, javaLibraryName),
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeNeverlinkDuplicateTarget("java_library", "java-protos"),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestJavaProtoDefault(t *testing.T) {
|
||||
runJavaProtoTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_library proto default",
|
||||
Blueprint: `java_library_static {
|
||||
name: "java-protos",
|
||||
srcs: ["a.proto"],
|
||||
java_version: "7",
|
||||
sdk_version: "current",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
|
||||
"srcs": `["a.proto"]`,
|
||||
}),
|
||||
MakeBazelTarget(
|
||||
"java_lite_proto_library",
|
||||
"java-protos_java_proto_lite",
|
||||
AttrNameToString{
|
||||
"deps": `[":java-protos_proto"]`,
|
||||
"java_version": `"7"`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
|
||||
"exports": `[":java-protos_java_proto_lite"]`,
|
||||
"java_version": `"7"`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeNeverlinkDuplicateTargetWithAttrs(
|
||||
"java_library",
|
||||
"java-protos",
|
||||
AttrNameToString{
|
||||
"java_version": `"7"`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaLibsAndOnlyProtoSrcs(t *testing.T) {
|
||||
runJavaProtoTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_library that has only proto srcs",
|
||||
StubbedBuildDefinitions: []string{"java-lib-1", "java-lib-2"},
|
||||
Blueprint: `java_library_static {
|
||||
name: "java-protos",
|
||||
srcs: ["a.proto"],
|
||||
libs: ["java-lib-1"],
|
||||
static_libs: ["java-lib-2"],
|
||||
java_version: "7",
|
||||
sdk_version: "current",
|
||||
}
|
||||
|
||||
java_library_static {
|
||||
name: "java-lib-1",
|
||||
}
|
||||
|
||||
java_library_static {
|
||||
name: "java-lib-2",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
|
||||
"srcs": `["a.proto"]`,
|
||||
}),
|
||||
MakeBazelTarget(
|
||||
"java_lite_proto_library",
|
||||
"java-protos_java_proto_lite",
|
||||
AttrNameToString{
|
||||
"deps": `[":java-protos_proto"]`,
|
||||
"additional_proto_deps": `[
|
||||
":java-lib-1-neverlink",
|
||||
":java-lib-2",
|
||||
]`,
|
||||
"java_version": `"7"`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
|
||||
"exports": `[
|
||||
":java-lib-2",
|
||||
":java-protos_java_proto_lite",
|
||||
]`,
|
||||
"java_version": `"7"`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeNeverlinkDuplicateTargetWithAttrs(
|
||||
"java_library",
|
||||
"java-protos",
|
||||
AttrNameToString{
|
||||
"java_version": `"7"`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaProtoPlugin(t *testing.T) {
|
||||
runJavaProtoTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_library proto plugin",
|
||||
StubbedBuildDefinitions: []string{"protoc-gen-test-plugin"},
|
||||
Blueprint: `java_library_static {
|
||||
name: "java-protos",
|
||||
srcs: ["a.proto"],
|
||||
proto: {
|
||||
plugin: "test-plugin",
|
||||
},
|
||||
sdk_version: "current",
|
||||
}
|
||||
|
||||
java_library_static {
|
||||
name: "protoc-gen-test-plugin",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("proto_library", "java-protos_proto", AttrNameToString{
|
||||
"srcs": `["a.proto"]`,
|
||||
}),
|
||||
MakeBazelTarget(
|
||||
"java_lite_proto_library",
|
||||
"java-protos_java_proto_lite",
|
||||
AttrNameToString{
|
||||
"deps": `[":java-protos_proto"]`,
|
||||
"plugin": `":protoc-gen-test-plugin"`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
|
||||
"exports": `[":java-protos_java_proto_lite"]`,
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
MakeNeverlinkDuplicateTargetWithAttrs(
|
||||
"java_library",
|
||||
"java-protos",
|
||||
AttrNameToString{
|
||||
"sdk_version": `"current"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_sdk_library"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.SdkLibraryFactory
|
||||
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
|
||||
}
|
||||
|
||||
func runJavaSdkLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {})
|
||||
}
|
||||
|
||||
func TestJavaSdkLibraryApiSurfaceGeneral(t *testing.T) {
|
||||
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "limited java_sdk_library for api surfaces, general conversion",
|
||||
Filesystem: map[string]string{
|
||||
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||
"api/current.txt": "",
|
||||
"api/system-current.txt": "",
|
||||
"api/test-current.txt": "",
|
||||
"api/module-lib-current.txt": "",
|
||||
"api/system-server-current.txt": "",
|
||||
"api/removed.txt": "",
|
||||
"api/system-removed.txt": "",
|
||||
"api/test-removed.txt": "",
|
||||
"api/module-lib-removed.txt": "",
|
||||
"api/system-server-removed.txt": "",
|
||||
},
|
||||
Blueprint: `java_sdk_library {
|
||||
name: "java-sdk-lib",
|
||||
srcs: ["a.java"],
|
||||
public: {enabled: true},
|
||||
system: {enabled: true},
|
||||
test: {enabled: true},
|
||||
module_lib: {enabled: true},
|
||||
system_server: {enabled: true},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
|
||||
"public": `"api/current.txt"`,
|
||||
"system": `"api/system-current.txt"`,
|
||||
"test": `"api/test-current.txt"`,
|
||||
"module_lib": `"api/module-lib-current.txt"`,
|
||||
"system_server": `"api/system-server-current.txt"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaSdkLibraryApiSurfacePublicDefault(t *testing.T) {
|
||||
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "limited java_sdk_library for api surfaces, public prop uses default value",
|
||||
Filesystem: map[string]string{
|
||||
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||
"api/current.txt": "",
|
||||
"api/system-current.txt": "",
|
||||
"api/test-current.txt": "",
|
||||
"api/module-lib-current.txt": "",
|
||||
"api/system-server-current.txt": "",
|
||||
"api/removed.txt": "",
|
||||
"api/system-removed.txt": "",
|
||||
"api/test-removed.txt": "",
|
||||
"api/module-lib-removed.txt": "",
|
||||
"api/system-server-removed.txt": "",
|
||||
},
|
||||
Blueprint: `java_sdk_library {
|
||||
name: "java-sdk-lib",
|
||||
srcs: ["a.java"],
|
||||
system: {enabled: false},
|
||||
test: {enabled: false},
|
||||
module_lib: {enabled: false},
|
||||
system_server: {enabled: false},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
|
||||
"public": `"api/current.txt"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaSdkLibraryApiSurfacePublicNotEnabled(t *testing.T) {
|
||||
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "limited java_sdk_library for api surfaces, public enable is false",
|
||||
Filesystem: map[string]string{
|
||||
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||
"api/current.txt": "",
|
||||
"api/removed.txt": "",
|
||||
},
|
||||
Blueprint: `java_sdk_library {
|
||||
name: "java-sdk-lib",
|
||||
srcs: ["a.java"],
|
||||
public: {enabled: false},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaSdkLibraryApiSurfaceNoScopeIsSet(t *testing.T) {
|
||||
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||
Description: "limited java_sdk_library for api surfaces, none of the api scopes is set",
|
||||
Filesystem: map[string]string{
|
||||
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||
"api/current.txt": "",
|
||||
"api/system-current.txt": "",
|
||||
"api/test-current.txt": "",
|
||||
"api/removed.txt": "",
|
||||
"api/system-removed.txt": "",
|
||||
"api/test-removed.txt": "",
|
||||
},
|
||||
Blueprint: `java_sdk_library {
|
||||
name: "java-sdk-lib",
|
||||
srcs: ["a.java"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
|
||||
"public": `"api/current.txt"`,
|
||||
"system": `"api/system-current.txt"`,
|
||||
"test": `"api/test-current.txt"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaSdkLibraryImportTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, java.RegisterSdkLibraryBuildComponents, tc)
|
||||
}
|
||||
|
||||
func TestJavaSdkLibraryImport(t *testing.T) {
|
||||
runJavaSdkLibraryImportTestCase(t, Bp2buildTestCase{
|
||||
Blueprint: `
|
||||
java_sdk_library_import {
|
||||
name : "foo",
|
||||
public: {
|
||||
current_api: "foo_current.txt",
|
||||
},
|
||||
system: {
|
||||
current_api: "system_foo_current.txt",
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_sdk_library", "foo", AttrNameToString{
|
||||
"public": `"foo_current.txt"`,
|
||||
"system": `"system_foo_current.txt"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaSdkLibraryImportPrebuiltPrefixRemoved(t *testing.T) {
|
||||
runJavaSdkLibraryImportTestCase(t, Bp2buildTestCase{
|
||||
Filesystem: map[string]string{
|
||||
"foobar/Android.bp": `
|
||||
java_sdk_library {
|
||||
name: "foo",
|
||||
srcs: ["**/*.java"],
|
||||
}
|
||||
`,
|
||||
"foobar/api/current.txt": "",
|
||||
"foobar/api/system-current.txt": "",
|
||||
"foobar/api/test-current.txt": "",
|
||||
"foobar/api/removed.txt": "",
|
||||
"foobar/api/system-removed.txt": "",
|
||||
"foobar/api/test-removed.txt": "",
|
||||
},
|
||||
Blueprint: `
|
||||
java_sdk_library_import {
|
||||
name : "foo",
|
||||
public: {
|
||||
current_api: "foo_current.txt",
|
||||
},
|
||||
system: {
|
||||
current_api: "system_foo_current.txt",
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_sdk_library", "foo", AttrNameToString{
|
||||
"public": `"foo_current.txt"`,
|
||||
"system": `"system_foo_current.txt"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runJavaTestHostTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "java_test_host"
|
||||
(&tc).ModuleTypeUnderTestFactory = java.TestHostFactory
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
}, tc)
|
||||
}
|
||||
|
||||
func TestJavaTestHostGeneral(t *testing.T) {
|
||||
runJavaTestHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_test_host general",
|
||||
Filesystem: map[string]string{},
|
||||
StubbedBuildDefinitions: []string{"lib_a", "static_libs_a"},
|
||||
Blueprint: `
|
||||
java_test_host {
|
||||
name: "java_test_host-1",
|
||||
srcs: ["a.java", "b.java"],
|
||||
libs: ["lib_a"],
|
||||
static_libs: ["static_libs_a"],
|
||||
exclude_srcs: ["b.java"],
|
||||
javacflags: ["-Xdoclint:all/protected"],
|
||||
java_version: "8",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "lib_a",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "static_libs_a",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_library", "java_test_host-1_lib", AttrNameToString{
|
||||
"deps": `[
|
||||
":lib_a-neverlink",
|
||||
":static_libs_a",
|
||||
]`,
|
||||
"java_version": `"8"`,
|
||||
"javacopts": `["-Xdoclint:all/protected"]`,
|
||||
"srcs": `["a.java"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
|
||||
"runtime_deps": `[":java_test_host-1_lib"]`,
|
||||
"deps": `[
|
||||
":lib_a-neverlink",
|
||||
":static_libs_a",
|
||||
]`,
|
||||
"srcs": `["a.java"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaTestHostNoSrcs(t *testing.T) {
|
||||
runJavaTestHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_test_host without srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
java_test_host {
|
||||
name: "java_test_host-1",
|
||||
libs: ["lib_a"],
|
||||
static_libs: ["static_libs_a"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "lib_a",
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "static_libs_a",
|
||||
}
|
||||
`,
|
||||
StubbedBuildDefinitions: []string{"lib_a", "static_libs_a"},
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
|
||||
"runtime_deps": `[
|
||||
":lib_a-neverlink",
|
||||
":static_libs_a",
|
||||
]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestJavaTestHostKotlinSrcs(t *testing.T) {
|
||||
runJavaTestHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "java_test_host with .kt in srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
java_test_host {
|
||||
name: "java_test_host-1",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_test", "java_test_host-1", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"runtime_deps": `[":java_test_host-1_lib"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
MakeBazelTarget("kt_jvm_library", "java_test_host-1_lib", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func registerLicenseModuleTypes(_ android.RegistrationContext) {}
|
||||
|
||||
func TestLicenseBp2Build(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
module string
|
||||
expected ExpectedRuleTarget
|
||||
}{
|
||||
{
|
||||
description: "license kind and text notice",
|
||||
module: `
|
||||
license {
|
||||
name: "my_license",
|
||||
license_kinds: [ "SPDX-license-identifier-Apache-2.0"],
|
||||
license_text: [ "NOTICE"],
|
||||
}`,
|
||||
expected: ExpectedRuleTarget{
|
||||
"android_license",
|
||||
"my_license",
|
||||
AttrNameToString{
|
||||
"license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
|
||||
"license_text": `"NOTICE"`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "visibility, package_name, copyright_notice",
|
||||
module: `
|
||||
license {
|
||||
name: "my_license",
|
||||
package_name: "my_package",
|
||||
visibility: [":__subpackages__"],
|
||||
copyright_notice: "Copyright © 2022",
|
||||
}`,
|
||||
expected: ExpectedRuleTarget{
|
||||
"android_license",
|
||||
"my_license",
|
||||
AttrNameToString{
|
||||
"copyright_notice": `"Copyright © 2022"`,
|
||||
"package_name": `"my_package"`,
|
||||
"visibility": `[":__subpackages__"]`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
RunBp2BuildTestCase(t,
|
||||
registerLicenseModuleTypes,
|
||||
Bp2buildTestCase{
|
||||
Description: test.description,
|
||||
ModuleTypeUnderTest: "license",
|
||||
ModuleTypeUnderTestFactory: android.LicenseFactory,
|
||||
Blueprint: test.module,
|
||||
ExpectedBazelTargets: []string{test.expected.String()},
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func registerLicenseKindModuleTypes(_ android.RegistrationContext) {}
|
||||
|
||||
func TestLicenseKindBp2Build(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
module string
|
||||
expected ExpectedRuleTarget
|
||||
}{
|
||||
{
|
||||
description: "license_kind",
|
||||
module: `
|
||||
license_kind {
|
||||
name: "my_license",
|
||||
conditions: [
|
||||
"by_exception_only",
|
||||
"not_allowed",
|
||||
],
|
||||
url: "https://spdx.org/licenses/0BSD",
|
||||
visibility: ["//visibility:public"],
|
||||
}`,
|
||||
expected: ExpectedRuleTarget{
|
||||
"license_kind",
|
||||
"my_license",
|
||||
AttrNameToString{
|
||||
"conditions": `[
|
||||
"by_exception_only",
|
||||
"not_allowed",
|
||||
]`,
|
||||
"url": `"https://spdx.org/licenses/0BSD"`,
|
||||
"visibility": `["//visibility:public"]`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
RunBp2BuildTestCase(t,
|
||||
registerLicenseKindModuleTypes,
|
||||
Bp2buildTestCase{
|
||||
Description: test.description,
|
||||
ModuleTypeUnderTest: "license_kind",
|
||||
ModuleTypeUnderTestFactory: android.LicenseKindFactory,
|
||||
Blueprint: test.module,
|
||||
ExpectedBazelTargets: []string{test.expected.String()},
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/linkerconfig"
|
||||
)
|
||||
|
||||
func runLinkerConfigTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "linker_config"
|
||||
(&tc).ModuleTypeUnderTestFactory = linkerconfig.LinkerConfigFactory
|
||||
RunBp2BuildTestCaseSimple(t, tc)
|
||||
}
|
||||
|
||||
func TestLinkerConfigConvertsSrc(t *testing.T) {
|
||||
runLinkerConfigTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Blueprint: `
|
||||
linker_config {
|
||||
name: "foo",
|
||||
src: "a.json",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{MakeBazelTarget("linker_config", "foo", AttrNameToString{
|
||||
"src": `"a.json"`,
|
||||
})},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestLinkerConfigNoSrc(t *testing.T) {
|
||||
runLinkerConfigTestCase(t,
|
||||
Bp2buildTestCase{
|
||||
Blueprint: `
|
||||
linker_config {
|
||||
name: "foo",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{},
|
||||
ExpectedErr: fmt.Errorf("Android.bp:2:1: module \"foo\": src: empty src is not supported"),
|
||||
})
|
||||
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/genrule"
|
||||
)
|
||||
|
||||
func registerDependentModules(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("license", android.LicenseFactory)
|
||||
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
|
||||
}
|
||||
|
||||
func TestPackage(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
modules string
|
||||
fs map[string]string
|
||||
expected []ExpectedRuleTarget
|
||||
}{
|
||||
{
|
||||
description: "with default applicable licenses",
|
||||
modules: `
|
||||
license {
|
||||
name: "my_license",
|
||||
visibility: [":__subpackages__"],
|
||||
license_kinds: ["SPDX-license-identifier-Apache-2.0"],
|
||||
license_text: ["NOTICE"],
|
||||
}
|
||||
|
||||
package {
|
||||
default_applicable_licenses: ["my_license"],
|
||||
}
|
||||
`,
|
||||
expected: []ExpectedRuleTarget{
|
||||
{
|
||||
"package",
|
||||
"",
|
||||
AttrNameToString{
|
||||
"default_package_metadata": `[":my_license"]`,
|
||||
"default_visibility": `["//visibility:public"]`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
{
|
||||
"android_license",
|
||||
"my_license",
|
||||
AttrNameToString{
|
||||
"license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
|
||||
"license_text": `"NOTICE"`,
|
||||
"visibility": `[":__subpackages__"]`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "package has METADATA file",
|
||||
fs: map[string]string{
|
||||
"METADATA": ``,
|
||||
},
|
||||
modules: `
|
||||
license {
|
||||
name: "my_license",
|
||||
visibility: [":__subpackages__"],
|
||||
license_kinds: ["SPDX-license-identifier-Apache-2.0"],
|
||||
license_text: ["NOTICE"],
|
||||
}
|
||||
|
||||
package {
|
||||
default_applicable_licenses: ["my_license"],
|
||||
}
|
||||
`,
|
||||
expected: []ExpectedRuleTarget{
|
||||
{
|
||||
"package",
|
||||
"",
|
||||
AttrNameToString{
|
||||
"default_package_metadata": `[
|
||||
":my_license",
|
||||
":default_metadata_file",
|
||||
]`,
|
||||
"default_visibility": `["//visibility:public"]`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
{
|
||||
"android_license",
|
||||
"my_license",
|
||||
AttrNameToString{
|
||||
"license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
|
||||
"license_text": `"NOTICE"`,
|
||||
"visibility": `[":__subpackages__"]`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
{
|
||||
"filegroup",
|
||||
"default_metadata_file",
|
||||
AttrNameToString{
|
||||
"applicable_licenses": `[]`,
|
||||
"srcs": `["METADATA"]`,
|
||||
},
|
||||
android.HostAndDeviceDefault,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
expected := make([]string, 0, len(test.expected))
|
||||
for _, e := range test.expected {
|
||||
expected = append(expected, e.String())
|
||||
}
|
||||
RunBp2BuildTestCase(t, registerDependentModules,
|
||||
Bp2buildTestCase{
|
||||
Description: test.description,
|
||||
ModuleTypeUnderTest: "package",
|
||||
ModuleTypeUnderTestFactory: android.PackageFactory,
|
||||
Blueprint: test.modules,
|
||||
ExpectedBazelTargets: expected,
|
||||
Filesystem: test.fs,
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func runPlatformCompatConfigTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
||||
ctx.RegisterModuleType("platform_compat_config", java.PlatformCompatConfigFactory)
|
||||
}, tc)
|
||||
}
|
||||
|
||||
func TestPlatformCompatConfig(t *testing.T) {
|
||||
runPlatformCompatConfigTestCase(t, Bp2buildTestCase{
|
||||
Description: "platform_compat_config - conversion test",
|
||||
Blueprint: `
|
||||
platform_compat_config {
|
||||
name: "foo",
|
||||
src: ":lib",
|
||||
}`,
|
||||
StubbedBuildDefinitions: []string{"//a/b:lib"},
|
||||
Filesystem: map[string]string{
|
||||
"a/b/Android.bp": `
|
||||
java_library {
|
||||
name: "lib",
|
||||
srcs: ["a.java"],
|
||||
}`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("platform_compat_config", "foo", AttrNameToString{
|
||||
"src": `"//a/b:lib"`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,396 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/etc"
|
||||
)
|
||||
|
||||
func runPrebuiltEtcTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "prebuilt_etc"
|
||||
(&tc).ModuleTypeUnderTestFactory = etc.PrebuiltEtcFactory
|
||||
RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc)
|
||||
}
|
||||
|
||||
func runPrebuiltRootHostTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "prebuilt_root_host"
|
||||
(&tc).ModuleTypeUnderTestFactory = etc.PrebuiltRootHostFactory
|
||||
RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerPrebuiltModuleTypes(ctx android.RegistrationContext) {
|
||||
}
|
||||
|
||||
func TestPrebuiltEtcSimple(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - simple example",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "apex_tz_version",
|
||||
src: "version/tz_version",
|
||||
filename: "tz_version",
|
||||
sub_dir: "tz",
|
||||
installable: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
|
||||
"filename": `"tz_version"`,
|
||||
"installable": `False`,
|
||||
"src": `"version/tz_version"`,
|
||||
"dir": `"etc/tz"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestPrebuiltEtcArchVariant(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - arch variant",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "apex_tz_version",
|
||||
src: "version/tz_version",
|
||||
filename: "tz_version",
|
||||
sub_dir: "tz",
|
||||
installable: false,
|
||||
arch: {
|
||||
arm: {
|
||||
src: "arm",
|
||||
},
|
||||
arm64: {
|
||||
src: "arm64",
|
||||
},
|
||||
}
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
|
||||
"filename": `"tz_version"`,
|
||||
"installable": `False`,
|
||||
"src": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "arm",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "arm64",
|
||||
"//conditions:default": "version/tz_version",
|
||||
})`,
|
||||
"dir": `"etc/tz"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestPrebuiltEtcArchAndTargetVariant(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - arch variant",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "apex_tz_version",
|
||||
src: "version/tz_version",
|
||||
filename: "tz_version",
|
||||
sub_dir: "tz",
|
||||
installable: false,
|
||||
arch: {
|
||||
arm: {
|
||||
src: "arm",
|
||||
},
|
||||
arm64: {
|
||||
src: "darwin_or_arm64",
|
||||
},
|
||||
},
|
||||
target: {
|
||||
darwin: {
|
||||
src: "darwin_or_arm64",
|
||||
}
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
|
||||
"filename": `"tz_version"`,
|
||||
"installable": `False`,
|
||||
"src": `select({
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm": "arm",
|
||||
"//build/bazel_common_rules/platforms/os_arch:android_arm64": "darwin_or_arm64",
|
||||
"//build/bazel_common_rules/platforms/os_arch:darwin_arm64": "darwin_or_arm64",
|
||||
"//build/bazel_common_rules/platforms/os_arch:darwin_x86_64": "darwin_or_arm64",
|
||||
"//build/bazel_common_rules/platforms/os_arch:linux_bionic_arm64": "darwin_or_arm64",
|
||||
"//conditions:default": "version/tz_version",
|
||||
})`,
|
||||
"dir": `"etc/tz"`,
|
||||
})}})
|
||||
}
|
||||
func TestPrebuiltEtcProductVariables(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt etc - product variables",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "apex_tz_version",
|
||||
src: "version/tz_version",
|
||||
filename: "tz_version",
|
||||
product_variables: {
|
||||
native_coverage: {
|
||||
src: "src1",
|
||||
},
|
||||
},
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
|
||||
"filename": `"tz_version"`,
|
||||
"src": `select({
|
||||
"//build/bazel/product_config/config_settings:native_coverage": "src1",
|
||||
"//conditions:default": "version/tz_version",
|
||||
})`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func runPrebuiltUsrShareTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
(&tc).ModuleTypeUnderTest = "prebuilt_usr_share"
|
||||
(&tc).ModuleTypeUnderTestFactory = etc.PrebuiltUserShareFactory
|
||||
RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerPrebuiltUsrShareModuleTypes(ctx android.RegistrationContext) {
|
||||
}
|
||||
|
||||
func TestPrebuiltUsrShareSimple(t *testing.T) {
|
||||
runPrebuiltUsrShareTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_usr_share - simple example",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_usr_share {
|
||||
name: "apex_tz_version",
|
||||
src: "version/tz_version",
|
||||
filename: "tz_version",
|
||||
sub_dir: "tz",
|
||||
installable: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
|
||||
"filename": `"tz_version"`,
|
||||
"installable": `False`,
|
||||
"src": `"version/tz_version"`,
|
||||
"dir": `"usr/share/tz"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestPrebuiltEtcNoSubdir(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - no subdir",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "apex_tz_version",
|
||||
src: "version/tz_version",
|
||||
filename: "tz_version",
|
||||
installable: false,
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "apex_tz_version", AttrNameToString{
|
||||
"filename": `"tz_version"`,
|
||||
"installable": `False`,
|
||||
"src": `"version/tz_version"`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFilenameAsProperty(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - filename is specified as a property ",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
src: "fooSrc",
|
||||
filename: "fooFileName",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename": `"fooFileName"`,
|
||||
"src": `"fooSrc"`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFileNameFromSrc(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - filename_from_src is true ",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
filename_from_src: true,
|
||||
src: "fooSrc",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename": `"fooSrc"`,
|
||||
"src": `"fooSrc"`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFileNameFromSrcMultipleSrcs(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - filename_from_src is true but there are multiple srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
filename_from_src: true,
|
||||
arch: {
|
||||
arm: {
|
||||
src: "barSrc",
|
||||
},
|
||||
arm64: {
|
||||
src: "bazSrc",
|
||||
},
|
||||
}
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename_from_src": `True`,
|
||||
"dir": `"etc"`,
|
||||
"src": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "barSrc",
|
||||
"//build/bazel_common_rules/platforms/arch:arm64": "bazSrc",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFilenameFromModuleName(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - neither filename nor filename_from_src are specified ",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename": `"foo"`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestPrebuiltEtcProductVariableArchSrcs(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt etc- SRcs from arch variant product variables",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
filename: "fooFilename",
|
||||
arch: {
|
||||
arm: {
|
||||
src: "armSrc",
|
||||
product_variables: {
|
||||
native_coverage: {
|
||||
src: "nativeCoverageArmSrc",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename": `"fooFilename"`,
|
||||
"dir": `"etc"`,
|
||||
"src": `select({
|
||||
"//build/bazel/product_config/config_settings:native_coverage-arm": "nativeCoverageArmSrc",
|
||||
"//build/bazel_common_rules/platforms/arch:arm": "armSrc",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestPrebuiltEtcProductVariableError(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
filename: "fooFilename",
|
||||
arch: {
|
||||
arm: {
|
||||
src: "armSrc",
|
||||
},
|
||||
},
|
||||
product_variables: {
|
||||
native_coverage: {
|
||||
src: "nativeCoverageArmSrc",
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedErr: fmt.Errorf("label attribute could not be collapsed"),
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltEtcNoConversionIfSrcEqualsName(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
filename: "fooFilename",
|
||||
src: "foo",
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrebuiltRootHostWithWildCardInSrc(t *testing.T) {
|
||||
runPrebuiltRootHostTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_root_host - src string has wild card",
|
||||
Filesystem: map[string]string{
|
||||
"prh.dat": "",
|
||||
},
|
||||
Blueprint: `
|
||||
prebuilt_root_host {
|
||||
name: "prh_test",
|
||||
src: "*.dat",
|
||||
filename_from_src: true,
|
||||
relative_install_path: "test/install/path",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "prh_test", AttrNameToString{
|
||||
"filename": `"prh.dat"`,
|
||||
"src": `"prh.dat"`,
|
||||
"dir": `"./test/install/path"`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
})}})
|
||||
}
|
|
@ -1,320 +0,0 @@
|
|||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/genrule"
|
||||
"android/soong/python"
|
||||
)
|
||||
|
||||
func runBp2BuildTestCaseWithPythonLibraries(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
|
||||
ctx.RegisterModuleType("python_library_host", python.PythonLibraryHostFactory)
|
||||
ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
|
||||
ctx.RegisterModuleType("python_defaults", python.DefaultsFactory)
|
||||
}, tc)
|
||||
}
|
||||
|
||||
func TestPythonBinaryHostSimple(t *testing.T) {
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "simple python_binary_host converts to a native py_binary",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
Filesystem: map[string]string{
|
||||
"a.py": "",
|
||||
"b/c.py": "",
|
||||
"b/d.py": "",
|
||||
"b/e.py": "",
|
||||
"files/data.txt": "",
|
||||
},
|
||||
StubbedBuildDefinitions: []string{"bar"},
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
main: "a.py",
|
||||
srcs: ["**/*.py"],
|
||||
exclude_srcs: ["b/e.py"],
|
||||
data: ["files/data.txt",],
|
||||
libs: ["bar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
python_library_host {
|
||||
name: "bar",
|
||||
srcs: ["b/e.py"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"data": `["files/data.txt"]`,
|
||||
"deps": `[":bar"]`,
|
||||
"main": `"a.py"`,
|
||||
"imports": `["."]`,
|
||||
"srcs": `[
|
||||
"a.py",
|
||||
"b/c.py",
|
||||
"b/d.py",
|
||||
]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryHostPy2(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t, Bp2buildTestCase{
|
||||
Description: "py2 python_binary_host",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
srcs: ["a.py"],
|
||||
version: {
|
||||
py2: {
|
||||
enabled: true,
|
||||
},
|
||||
py3: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"python_version": `"PY2"`,
|
||||
"imports": `["."]`,
|
||||
"srcs": `["a.py"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryHostPy3(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t, Bp2buildTestCase{
|
||||
Description: "py3 python_binary_host",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
srcs: ["a.py"],
|
||||
version: {
|
||||
py2: {
|
||||
enabled: false,
|
||||
},
|
||||
py3: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
// python_version is PY3 by default.
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"imports": `["."]`,
|
||||
"srcs": `["a.py"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryHostArchVariance(t *testing.T) {
|
||||
RunBp2BuildTestCaseSimple(t, Bp2buildTestCase{
|
||||
Description: "test arch variants",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
Filesystem: map[string]string{
|
||||
"dir/arm.py": "",
|
||||
"dir/x86.py": "",
|
||||
},
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo-arm",
|
||||
arch: {
|
||||
arm: {
|
||||
srcs: ["arm.py"],
|
||||
},
|
||||
x86: {
|
||||
srcs: ["x86.py"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo-arm", AttrNameToString{
|
||||
"imports": `["."]`,
|
||||
"srcs": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["arm.py"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["x86.py"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryMainIsNotSpecified(t *testing.T) {
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "python_binary_host main label in same package",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"imports": `["."]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryMainIsLabel(t *testing.T) {
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "python_binary_host main label in same package",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
StubbedBuildDefinitions: []string{"a"},
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
main: ":a",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "a",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"main": `":a"`,
|
||||
"imports": `["."]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryMainIsSubpackageFile(t *testing.T) {
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "python_binary_host main is subpackage file",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
Filesystem: map[string]string{
|
||||
"a/Android.bp": "",
|
||||
"a/b.py": "",
|
||||
},
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
main: "a/b.py",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"main": `"//a:b.py"`,
|
||||
"imports": `["."]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryMainIsSubDirFile(t *testing.T) {
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "python_binary_host main is file in sub directory that is not Bazel package",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
Filesystem: map[string]string{
|
||||
"a/b.py": "",
|
||||
},
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
main: "a/b.py",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"main": `"a/b.py"`,
|
||||
"imports": `["."]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonBinaryDuplicatesInRequired(t *testing.T) {
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "python_binary_host duplicates in required attribute of the module and its defaults",
|
||||
ModuleTypeUnderTest: "python_binary_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonBinaryHostFactory,
|
||||
StubbedBuildDefinitions: []string{"r1", "r2"},
|
||||
Blueprint: `python_binary_host {
|
||||
name: "foo",
|
||||
main: "a.py",
|
||||
defaults: ["d"],
|
||||
required: [
|
||||
"r1",
|
||||
],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
|
||||
python_defaults {
|
||||
name: "d",
|
||||
required: [
|
||||
"r1",
|
||||
"r2",
|
||||
],
|
||||
}` + simpleModule("genrule", "r1") +
|
||||
simpleModule("genrule", "r2"),
|
||||
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_binary", "foo", AttrNameToString{
|
||||
"main": `"a.py"`,
|
||||
"imports": `["."]`,
|
||||
"data": `[
|
||||
":r1",
|
||||
":r2",
|
||||
]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,392 +0,0 @@
|
|||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/python"
|
||||
)
|
||||
|
||||
// TODO(alexmarquez): Should be lifted into a generic Bp2Build file
|
||||
type PythonLibBp2Build func(ctx android.TopDownMutatorContext)
|
||||
|
||||
type pythonLibBp2BuildTestCase struct {
|
||||
description string
|
||||
filesystem map[string]string
|
||||
blueprint string
|
||||
expectedBazelTargets []testBazelTarget
|
||||
dir string
|
||||
expectedError error
|
||||
stubbedBuildDefinitions []string
|
||||
}
|
||||
|
||||
func convertPythonLibTestCaseToBp2build_Host(tc pythonLibBp2BuildTestCase) Bp2buildTestCase {
|
||||
for i := range tc.expectedBazelTargets {
|
||||
tc.expectedBazelTargets[i].attrs["target_compatible_with"] = `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`
|
||||
}
|
||||
|
||||
return convertPythonLibTestCaseToBp2build(tc)
|
||||
}
|
||||
|
||||
func convertPythonLibTestCaseToBp2build(tc pythonLibBp2BuildTestCase) Bp2buildTestCase {
|
||||
var bp2BuildTargets []string
|
||||
for _, t := range tc.expectedBazelTargets {
|
||||
bp2BuildTargets = append(bp2BuildTargets, MakeBazelTarget(t.typ, t.name, t.attrs))
|
||||
}
|
||||
// Copy the filesystem so that we can change stuff in it later without it
|
||||
// affecting the original pythonLibBp2BuildTestCase
|
||||
filesystemCopy := make(map[string]string)
|
||||
for k, v := range tc.filesystem {
|
||||
filesystemCopy[k] = v
|
||||
}
|
||||
return Bp2buildTestCase{
|
||||
Description: tc.description,
|
||||
Filesystem: filesystemCopy,
|
||||
Blueprint: tc.blueprint,
|
||||
ExpectedBazelTargets: bp2BuildTargets,
|
||||
Dir: tc.dir,
|
||||
ExpectedErr: tc.expectedError,
|
||||
StubbedBuildDefinitions: tc.stubbedBuildDefinitions,
|
||||
}
|
||||
}
|
||||
|
||||
func runPythonLibraryTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) {
|
||||
t.Helper()
|
||||
testCase := convertPythonLibTestCaseToBp2build(tc)
|
||||
testCase.Description = fmt.Sprintf(testCase.Description, "python_library")
|
||||
testCase.Blueprint = fmt.Sprintf(testCase.Blueprint, "python_library")
|
||||
for name, contents := range testCase.Filesystem {
|
||||
if strings.HasSuffix(name, "Android.bp") {
|
||||
testCase.Filesystem[name] = fmt.Sprintf(contents, "python_library")
|
||||
}
|
||||
}
|
||||
testCase.ModuleTypeUnderTest = "python_library"
|
||||
testCase.ModuleTypeUnderTestFactory = python.PythonLibraryFactory
|
||||
|
||||
RunBp2BuildTestCaseSimple(t, testCase)
|
||||
}
|
||||
|
||||
func runPythonLibraryHostTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) {
|
||||
t.Helper()
|
||||
testCase := convertPythonLibTestCaseToBp2build_Host(tc)
|
||||
testCase.Description = fmt.Sprintf(testCase.Description, "python_library_host")
|
||||
testCase.Blueprint = fmt.Sprintf(testCase.Blueprint, "python_library_host")
|
||||
for name, contents := range testCase.Filesystem {
|
||||
if strings.HasSuffix(name, "Android.bp") {
|
||||
testCase.Filesystem[name] = fmt.Sprintf(contents, "python_library_host")
|
||||
}
|
||||
}
|
||||
testCase.ModuleTypeUnderTest = "python_library_host"
|
||||
testCase.ModuleTypeUnderTestFactory = python.PythonLibraryHostFactory
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
|
||||
},
|
||||
testCase)
|
||||
}
|
||||
|
||||
func runPythonLibraryTestCases(t *testing.T, tc pythonLibBp2BuildTestCase) {
|
||||
t.Helper()
|
||||
runPythonLibraryTestCase(t, tc)
|
||||
runPythonLibraryHostTestCase(t, tc)
|
||||
}
|
||||
|
||||
func TestSimplePythonLib(t *testing.T) {
|
||||
testCases := []pythonLibBp2BuildTestCase{
|
||||
{
|
||||
description: "simple %s converts to a native py_library",
|
||||
filesystem: map[string]string{
|
||||
"a.py": "",
|
||||
"b/c.py": "",
|
||||
"b/d.py": "",
|
||||
"b/e.py": "",
|
||||
"files/data.txt": "",
|
||||
},
|
||||
stubbedBuildDefinitions: []string{"bar"},
|
||||
blueprint: `%s {
|
||||
name: "foo",
|
||||
srcs: ["**/*.py"],
|
||||
exclude_srcs: ["b/e.py"],
|
||||
data: ["files/data.txt",],
|
||||
libs: ["bar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
python_library {
|
||||
name: "bar",
|
||||
srcs: ["b/e.py"],
|
||||
}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: AttrNameToString{
|
||||
"data": `["files/data.txt"]`,
|
||||
"deps": `[":bar"]`,
|
||||
"srcs": `[
|
||||
"a.py",
|
||||
"b/c.py",
|
||||
"b/d.py",
|
||||
]`,
|
||||
"srcs_version": `"PY3"`,
|
||||
"imports": `["."]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "py2 %s converts to a native py_library",
|
||||
blueprint: `%s {
|
||||
name: "foo",
|
||||
srcs: ["a.py"],
|
||||
version: {
|
||||
py2: {
|
||||
enabled: true,
|
||||
},
|
||||
py3: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: AttrNameToString{
|
||||
"srcs": `["a.py"]`,
|
||||
"srcs_version": `"PY2"`,
|
||||
"imports": `["."]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "py3 %s converts to a native py_library",
|
||||
blueprint: `%s {
|
||||
name: "foo",
|
||||
srcs: ["a.py"],
|
||||
version: {
|
||||
py2: {
|
||||
enabled: false,
|
||||
},
|
||||
py3: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: AttrNameToString{
|
||||
"srcs": `["a.py"]`,
|
||||
"srcs_version": `"PY3"`,
|
||||
"imports": `["."]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "py2&3 %s converts to a native py_library",
|
||||
blueprint: `%s {
|
||||
name: "foo",
|
||||
srcs: ["a.py"],
|
||||
version: {
|
||||
py2: {
|
||||
enabled: true,
|
||||
},
|
||||
py3: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
// srcs_version is PY2ANDPY3 by default.
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: AttrNameToString{
|
||||
"srcs": `["a.py"]`,
|
||||
"imports": `["."]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "%s: pkg_path in a subdirectory of the same name converts correctly",
|
||||
dir: "mylib/subpackage",
|
||||
filesystem: map[string]string{
|
||||
"mylib/subpackage/a.py": "",
|
||||
"mylib/subpackage/Android.bp": `%s {
|
||||
name: "foo",
|
||||
srcs: ["a.py"],
|
||||
pkg_path: "mylib/subpackage",
|
||||
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
},
|
||||
blueprint: `%s {name: "bar"}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
// srcs_version is PY2ANDPY3 by default.
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: AttrNameToString{
|
||||
"srcs": `["a.py"]`,
|
||||
"imports": `["../.."]`,
|
||||
"srcs_version": `"PY3"`,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "%s: pkg_path in a subdirectory of a different name fails",
|
||||
dir: "mylib/subpackage",
|
||||
filesystem: map[string]string{
|
||||
"mylib/subpackage/a.py": "",
|
||||
"mylib/subpackage/Android.bp": `%s {
|
||||
name: "foo",
|
||||
srcs: ["a.py"],
|
||||
pkg_path: "mylib/subpackage2",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
},
|
||||
blueprint: `%s {name: "bar"}`,
|
||||
expectedError: fmt.Errorf("Currently, bp2build only supports pkg_paths that are the same as the folders the Android.bp file is in."),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
runPythonLibraryTestCases(t, tc)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPythonArchVariance(t *testing.T) {
|
||||
runPythonLibraryTestCases(t, pythonLibBp2BuildTestCase{
|
||||
description: "test %s arch variants",
|
||||
filesystem: map[string]string{
|
||||
"dir/arm.py": "",
|
||||
"dir/x86.py": "",
|
||||
},
|
||||
blueprint: `%s {
|
||||
name: "foo",
|
||||
arch: {
|
||||
arm: {
|
||||
srcs: ["arm.py"],
|
||||
},
|
||||
x86: {
|
||||
srcs: ["x86.py"],
|
||||
},
|
||||
},
|
||||
}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: AttrNameToString{
|
||||
"srcs": `select({
|
||||
"//build/bazel_common_rules/platforms/arch:arm": ["arm.py"],
|
||||
"//build/bazel_common_rules/platforms/arch:x86": ["x86.py"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"srcs_version": `"PY3"`,
|
||||
"imports": `["."]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonLibraryWithProtobufs(t *testing.T) {
|
||||
runPythonLibraryTestCases(t, pythonLibBp2BuildTestCase{
|
||||
description: "test %s protobuf",
|
||||
filesystem: map[string]string{
|
||||
"dir/mylib.py": "",
|
||||
"dir/myproto.proto": "",
|
||||
},
|
||||
blueprint: `%s {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"dir/mylib.py",
|
||||
"dir/myproto.proto",
|
||||
],
|
||||
}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
typ: "proto_library",
|
||||
name: "foo_proto",
|
||||
attrs: AttrNameToString{
|
||||
"srcs": `["dir/myproto.proto"]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
typ: "py_proto_library",
|
||||
name: "foo_py_proto",
|
||||
attrs: AttrNameToString{
|
||||
"deps": `[":foo_proto"]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: AttrNameToString{
|
||||
"srcs": `["dir/mylib.py"]`,
|
||||
"srcs_version": `"PY3"`,
|
||||
"imports": `["."]`,
|
||||
"deps": `[":foo_py_proto"]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonLibraryWithProtobufsAndPkgPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "test python_library protobuf with pkg_path",
|
||||
Filesystem: map[string]string{
|
||||
"dir/foo.proto": "",
|
||||
"dir/bar.proto": "", // bar contains "import dir/foo.proto"
|
||||
"dir/Android.bp": `
|
||||
python_library {
|
||||
name: "foo",
|
||||
pkg_path: "dir",
|
||||
srcs: [
|
||||
"foo.proto",
|
||||
"bar.proto",
|
||||
],
|
||||
bazel_module: {bp2build_available: true},
|
||||
}`,
|
||||
},
|
||||
Dir: "dir",
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
|
||||
"import_prefix": `"dir"`,
|
||||
"strip_import_prefix": `""`,
|
||||
"srcs": `[
|
||||
"foo.proto",
|
||||
"bar.proto",
|
||||
]`,
|
||||
}),
|
||||
MakeBazelTarget("py_proto_library", "foo_py_proto", AttrNameToString{
|
||||
"deps": `[":foo_proto"]`,
|
||||
}),
|
||||
MakeBazelTarget("py_library", "foo", AttrNameToString{
|
||||
"srcs_version": `"PY3"`,
|
||||
"imports": `[".."]`,
|
||||
"deps": `[":foo_py_proto"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/python"
|
||||
)
|
||||
|
||||
func TestPythonTestHostSimple(t *testing.T) {
|
||||
runBp2BuildTestCaseWithPythonLibraries(t, Bp2buildTestCase{
|
||||
Description: "simple python_test_host converts to a native py_test",
|
||||
ModuleTypeUnderTest: "python_test_host",
|
||||
ModuleTypeUnderTestFactory: python.PythonTestHostFactory,
|
||||
Filesystem: map[string]string{
|
||||
"a.py": "",
|
||||
"b/c.py": "",
|
||||
"b/d.py": "",
|
||||
"b/e.py": "",
|
||||
"files/data.txt": "",
|
||||
},
|
||||
StubbedBuildDefinitions: []string{"bar"},
|
||||
Blueprint: `python_test_host {
|
||||
name: "foo",
|
||||
main: "a.py",
|
||||
srcs: ["**/*.py"],
|
||||
exclude_srcs: ["b/e.py"],
|
||||
data: ["files/data.txt",],
|
||||
libs: ["bar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
python_library_host {
|
||||
name: "bar",
|
||||
srcs: ["b/e.py"],
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("py_test", "foo", AttrNameToString{
|
||||
"data": `["files/data.txt"]`,
|
||||
"deps": `[":bar"]`,
|
||||
"main": `"a.py"`,
|
||||
"imports": `["."]`,
|
||||
"srcs": `[
|
||||
"a.py",
|
||||
"b/c.py",
|
||||
"b/d.py",
|
||||
]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/rust"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runRustBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerRustBinaryModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerRustBinaryModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("rust_binary_host", rust.RustBinaryHostFactory)
|
||||
ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
|
||||
ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)
|
||||
|
||||
}
|
||||
|
||||
func TestRustBinaryHost(t *testing.T) {
|
||||
runRustBinaryTestCase(t, Bp2buildTestCase{
|
||||
Dir: "external/rust/crates/foo",
|
||||
Blueprint: "",
|
||||
Filesystem: map[string]string{
|
||||
"external/rust/crates/foo/src/lib.rs": "",
|
||||
"external/rust/crates/foo/src/helper.rs": "",
|
||||
"external/rust/crates/foo/Android.bp": `
|
||||
rust_binary_host {
|
||||
name: "libfoo",
|
||||
crate_name: "foo",
|
||||
srcs: ["src/main.rs"],
|
||||
edition: "2021",
|
||||
features: ["bah-enabled"],
|
||||
cfgs: ["baz"],
|
||||
rustlibs: ["libbar"],
|
||||
proc_macros: ["libbah"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
"external/rust/crates/bar/Android.bp": `
|
||||
rust_library_host {
|
||||
name: "libbar",
|
||||
crate_name: "bar",
|
||||
srcs: ["src/lib.rs"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
"external/rust/crates/bah/Android.bp": `
|
||||
rust_proc_macro {
|
||||
name: "libbah",
|
||||
crate_name: "bah",
|
||||
srcs: ["src/lib.rs"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTargetHostOrDevice("rust_binary", "libfoo", AttrNameToString{
|
||||
"crate_name": `"foo"`,
|
||||
"srcs": `[
|
||||
"src/helper.rs",
|
||||
"src/lib.rs",
|
||||
]`,
|
||||
"deps": `["//external/rust/crates/bar:libbar"]`,
|
||||
"proc_macro_deps": `["//external/rust/crates/bah:libbah"]`,
|
||||
"edition": `"2021"`,
|
||||
"crate_features": `["bah-enabled"]`,
|
||||
"rustc_flags": `["--cfg=baz"]`,
|
||||
}, android.HostSupported),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/rust"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runRustFfiTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerRustFfiModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerRustFfiModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("rust_ffi_static", rust.RustFFIStaticFactory)
|
||||
ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
|
||||
}
|
||||
|
||||
func TestRustFfiStatic(t *testing.T) {
|
||||
runRustFfiTestCase(t, Bp2buildTestCase{
|
||||
Dir: "external/rust/crates/foo",
|
||||
Blueprint: "",
|
||||
Filesystem: map[string]string{
|
||||
"external/rust/crates/foo/src/lib.rs": "",
|
||||
"external/rust/crates/foo/src/helper.rs": "",
|
||||
"external/rust/crates/foo/Android.bp": `
|
||||
rust_ffi_static {
|
||||
name: "libfoo",
|
||||
crate_name: "foo",
|
||||
host_supported: true,
|
||||
srcs: ["src/lib.rs"],
|
||||
edition: "2015",
|
||||
include_dirs: [
|
||||
"include",
|
||||
],
|
||||
rustlibs: ["libbar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
"external/rust/crates/bar/Android.bp": `
|
||||
rust_library {
|
||||
name: "libbar",
|
||||
crate_name: "bar",
|
||||
host_supported: true,
|
||||
srcs: ["src/lib.rs"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("rust_ffi_static", "libfoo", AttrNameToString{
|
||||
"crate_name": `"foo"`,
|
||||
"deps": `["//external/rust/crates/bar:libbar"]`,
|
||||
"srcs": `[
|
||||
"src/helper.rs",
|
||||
"src/lib.rs",
|
||||
]`,
|
||||
"edition": `"2015"`,
|
||||
"export_includes": `["include"]`,
|
||||
}),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/rust"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runRustLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerRustLibraryModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerRustLibraryModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
|
||||
ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
|
||||
}
|
||||
|
||||
func TestLibProtobuf(t *testing.T) {
|
||||
runRustLibraryTestCase(t, Bp2buildTestCase{
|
||||
Dir: "external/rust/crates/foo",
|
||||
Blueprint: "",
|
||||
Filesystem: map[string]string{
|
||||
"external/rust/crates/foo/src/lib.rs": "",
|
||||
"external/rust/crates/foo/Android.bp": `
|
||||
rust_library_host {
|
||||
name: "libprotobuf",
|
||||
crate_name: "protobuf",
|
||||
srcs: ["src/lib.rs"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
// TODO(b/290790800): Remove the restriction when rust toolchain for android is implemented
|
||||
makeBazelTargetHostOrDevice("rust_library", "libprotobuf", AttrNameToString{
|
||||
"crate_name": `"protobuf"`,
|
||||
"srcs": `["src/lib.rs"]`,
|
||||
"deps": `[":libprotobuf_build_script"]`,
|
||||
}, android.HostSupported),
|
||||
makeBazelTargetHostOrDevice("cargo_build_script", "libprotobuf_build_script", AttrNameToString{
|
||||
"srcs": `["build.rs"]`,
|
||||
}, android.HostSupported),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestRustLibrary(t *testing.T) {
|
||||
expectedAttrs := AttrNameToString{
|
||||
"crate_name": `"foo"`,
|
||||
"srcs": `[
|
||||
"src/helper.rs",
|
||||
"src/lib.rs",
|
||||
]`,
|
||||
"crate_features": `["bah-enabled"]`,
|
||||
"edition": `"2021"`,
|
||||
"rustc_flags": `["--cfg=baz"]`,
|
||||
}
|
||||
|
||||
runRustLibraryTestCase(t, Bp2buildTestCase{
|
||||
Dir: "external/rust/crates/foo",
|
||||
Blueprint: "",
|
||||
Filesystem: map[string]string{
|
||||
"external/rust/crates/foo/src/lib.rs": "",
|
||||
"external/rust/crates/foo/src/helper.rs": "",
|
||||
"external/rust/crates/foo/Android.bp": `
|
||||
rust_library {
|
||||
name: "libfoo",
|
||||
crate_name: "foo",
|
||||
host_supported: true,
|
||||
srcs: ["src/lib.rs"],
|
||||
edition: "2021",
|
||||
features: ["bah-enabled"],
|
||||
cfgs: ["baz"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
rust_library_host {
|
||||
name: "libfoo_host",
|
||||
crate_name: "foo",
|
||||
srcs: ["src/lib.rs"],
|
||||
edition: "2021",
|
||||
features: ["bah-enabled"],
|
||||
cfgs: ["baz"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTargetNoRestrictions("rust_library", "libfoo", expectedAttrs),
|
||||
makeBazelTargetHostOrDevice("rust_library", "libfoo_host", expectedAttrs, android.HostSupported),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/rust"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func rustRustProcMacroTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerRustProcMacroModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerRustProcMacroModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
|
||||
ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)
|
||||
}
|
||||
|
||||
func TestRustProcMacroLibrary(t *testing.T) {
|
||||
rustRustProcMacroTestCase(t, Bp2buildTestCase{
|
||||
Dir: "external/rust/crates/foo",
|
||||
Blueprint: "",
|
||||
Filesystem: map[string]string{
|
||||
"external/rust/crates/foo/src/lib.rs": "",
|
||||
"external/rust/crates/foo/src/helper.rs": "",
|
||||
"external/rust/crates/foo/Android.bp": `
|
||||
rust_proc_macro {
|
||||
name: "libfoo",
|
||||
crate_name: "foo",
|
||||
srcs: ["src/lib.rs"],
|
||||
edition: "2021",
|
||||
features: ["bah-enabled"],
|
||||
cfgs: ["baz"],
|
||||
rustlibs: ["libbar"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
"external/rust/crates/bar/src/lib.rs": "",
|
||||
"external/rust/crates/bar/Android.bp": `
|
||||
rust_library_host {
|
||||
name: "libbar",
|
||||
crate_name: "bar",
|
||||
srcs: ["src/lib.rs"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTargetHostOrDevice("rust_proc_macro", "libfoo", AttrNameToString{
|
||||
"crate_name": `"foo"`,
|
||||
"srcs": `[
|
||||
"src/helper.rs",
|
||||
"src/lib.rs",
|
||||
]`,
|
||||
"crate_features": `["bah-enabled"]`,
|
||||
"edition": `"2021"`,
|
||||
"rustc_flags": `["--cfg=baz"]`,
|
||||
"deps": `["//external/rust/crates/bar:libbar"]`,
|
||||
}, android.HostSupported),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/rust"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runRustProtobufTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, registerRustProtobufModuleTypes, tc)
|
||||
}
|
||||
|
||||
func registerRustProtobufModuleTypes(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("rust_protobuf_host", rust.RustProtobufHostFactory)
|
||||
ctx.RegisterModuleType("rust_protobuf", rust.RustProtobufHostFactory)
|
||||
}
|
||||
|
||||
func TestRustProtobufHostTestCase(t *testing.T) {
|
||||
runRustProtobufTestCase(t, Bp2buildTestCase{
|
||||
Dir: "external/rust/crates/foo",
|
||||
Blueprint: "",
|
||||
Filesystem: map[string]string{
|
||||
"external/rust/crates/foo/src/lib.rs": "",
|
||||
"external/rust/crates/foo/src/helper.rs": "",
|
||||
"external/rust/crates/foo/Android.bp": `
|
||||
rust_protobuf_host {
|
||||
name: "libfoo",
|
||||
crate_name: "foo",
|
||||
protos: ["src/foo.proto"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{
|
||||
"srcs": `["src/foo.proto"]`,
|
||||
}, android.HostSupported),
|
||||
makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{
|
||||
"crate_name": `"foo"`,
|
||||
"deps": `[":libfoo_proto"]`,
|
||||
}, android.HostSupported),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestRustProtobufTestCase(t *testing.T) {
|
||||
runRustProtobufTestCase(t, Bp2buildTestCase{
|
||||
Dir: "external/rust/crates/foo",
|
||||
Blueprint: "",
|
||||
Filesystem: map[string]string{
|
||||
"external/rust/crates/foo/src/lib.rs": "",
|
||||
"external/rust/crates/foo/src/helper.rs": "",
|
||||
"external/rust/crates/foo/Android.bp": `
|
||||
rust_protobuf {
|
||||
name: "libfoo",
|
||||
crate_name: "foo",
|
||||
protos: ["src/foo.proto"],
|
||||
bazel_module: { bp2build_available: true },
|
||||
}
|
||||
`,
|
||||
},
|
||||
ExpectedBazelTargets: []string{
|
||||
makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{
|
||||
"srcs": `["src/foo.proto"]`,
|
||||
}, android.HostSupported),
|
||||
makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{
|
||||
"crate_name": `"foo"`,
|
||||
"deps": `[":libfoo_proto"]`,
|
||||
}, android.HostSupported),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
// Copyright 2021 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/sh"
|
||||
)
|
||||
|
||||
func TestShBinaryLoadStatement(t *testing.T) {
|
||||
testCases := []struct {
|
||||
bazelTargets BazelTargets
|
||||
expectedLoadStatements string
|
||||
}{
|
||||
{
|
||||
bazelTargets: BazelTargets{
|
||||
BazelTarget{
|
||||
name: "sh_binary_target",
|
||||
ruleClass: "sh_binary",
|
||||
// Note: no bzlLoadLocation for native rules
|
||||
// TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules?
|
||||
},
|
||||
},
|
||||
expectedLoadStatements: ``,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
actual := testCase.bazelTargets.LoadStatements()
|
||||
expected := testCase.expectedLoadStatements
|
||||
if actual != expected {
|
||||
t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runShBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
t.Helper()
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
|
||||
}
|
||||
|
||||
func TestShBinarySimple(t *testing.T) {
|
||||
runShBinaryTestCase(t, Bp2buildTestCase{
|
||||
Description: "sh_binary test",
|
||||
ModuleTypeUnderTest: "sh_binary",
|
||||
ModuleTypeUnderTestFactory: sh.ShBinaryFactory,
|
||||
Blueprint: `sh_binary {
|
||||
name: "foo",
|
||||
src: "foo.sh",
|
||||
filename: "foo.exe",
|
||||
sub_dir: "sub",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_binary", "foo", AttrNameToString{
|
||||
"srcs": `["foo.sh"]`,
|
||||
"filename": `"foo.exe"`,
|
||||
"sub_dir": `"sub"`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
|
||||
func TestShBinaryDefaults(t *testing.T) {
|
||||
runShBinaryTestCase(t, Bp2buildTestCase{
|
||||
Description: "sh_binary test",
|
||||
ModuleTypeUnderTest: "sh_binary",
|
||||
ModuleTypeUnderTestFactory: sh.ShBinaryFactory,
|
||||
Blueprint: `sh_binary {
|
||||
name: "foo",
|
||||
src: "foo.sh",
|
||||
bazel_module: { bp2build_available: true },
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_binary", "foo", AttrNameToString{
|
||||
"srcs": `["foo.sh"]`,
|
||||
})},
|
||||
})
|
||||
}
|
|
@ -1,340 +0,0 @@
|
|||
// Copyright 2023 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bp2build
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/sh"
|
||||
)
|
||||
|
||||
func TestShTestSimple(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}, Bp2buildTestCase{
|
||||
Description: "sh_test test",
|
||||
ModuleTypeUnderTest: "sh_test",
|
||||
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
|
||||
ModuleTypeUnderTestFactory: sh.ShTestFactory,
|
||||
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
|
||||
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
|
||||
simpleModule("filegroup", "libc++") +
|
||||
simpleModule("filegroup", "libcrypto") + `sh_test{
|
||||
name: "sts-rootcanal-sidebins",
|
||||
src: "empty.sh",
|
||||
test_suites: [
|
||||
"sts",
|
||||
"sts-lite",
|
||||
],
|
||||
data_bins: [
|
||||
"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim"
|
||||
],
|
||||
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
|
||||
data_libs: ["libc++","libcrypto"],
|
||||
test_config: "art-gtests-target-install-apex.xml",
|
||||
test_config_template: ":art-run-test-target-template",
|
||||
auto_gen_config: false,
|
||||
test_options:{tags: ["no-remote"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
|
||||
"srcs": `["empty.sh"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"data": `[
|
||||
"android.hardware.bluetooth@1.1-service.sim.rc",
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
":libc++",
|
||||
":libcrypto",
|
||||
]`,
|
||||
"data_bins": `[
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
]`,
|
||||
"tags": `["no-remote"]`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
|
||||
func TestShTestHostSimple(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}, Bp2buildTestCase{
|
||||
Description: "sh_test_host test",
|
||||
ModuleTypeUnderTest: "sh_test_host",
|
||||
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
|
||||
ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
|
||||
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
|
||||
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
|
||||
simpleModule("filegroup", "libc++") +
|
||||
simpleModule("filegroup", "libcrypto") + `sh_test_host{
|
||||
name: "sts-rootcanal-sidebins",
|
||||
src: "empty.sh",
|
||||
test_suites: [
|
||||
"sts",
|
||||
"sts-lite",
|
||||
],
|
||||
data_bins: [
|
||||
"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim"
|
||||
],
|
||||
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
|
||||
data_libs: ["libc++","libcrypto"],
|
||||
test_config: "art-gtests-target-install-apex.xml",
|
||||
test_config_template: ":art-run-test-target-template",
|
||||
auto_gen_config: false,
|
||||
test_options:{tags: ["no-remote"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
|
||||
"srcs": `["empty.sh"]`,
|
||||
"runs_on": `["host_without_device"]`,
|
||||
"data": `[
|
||||
"android.hardware.bluetooth@1.1-service.sim.rc",
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
":libc++",
|
||||
":libcrypto",
|
||||
]`,
|
||||
"data_bins": `[
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
]`,
|
||||
"tags": `["no-remote"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
|
||||
func TestShTestAutogen(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}, Bp2buildTestCase{
|
||||
Description: "sh_test test",
|
||||
ModuleTypeUnderTest: "sh_test",
|
||||
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto", "art-run-test-target-template"},
|
||||
ModuleTypeUnderTestFactory: sh.ShTestFactory,
|
||||
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
|
||||
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
|
||||
simpleModule("filegroup", "libc++") +
|
||||
simpleModule("filegroup", "libcrypto") +
|
||||
simpleModule("filegroup", "art-run-test-target-template") + `sh_test{
|
||||
name: "sts-rootcanal-sidebins",
|
||||
src: "empty.sh",
|
||||
test_suites: [
|
||||
"sts",
|
||||
"sts-lite",
|
||||
],
|
||||
data_bins: [
|
||||
"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim"
|
||||
],
|
||||
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
|
||||
data_libs: ["libc++","libcrypto"],
|
||||
test_config: "art-gtests-target-install-apex.xml",
|
||||
test_config_template: ":art-run-test-target-template",
|
||||
auto_gen_config: true,
|
||||
test_options:{tags: ["no-remote"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
|
||||
"srcs": `["empty.sh"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"auto_generate_test_config": "True",
|
||||
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
||||
"template_test_config": `":art-run-test-target-template"`,
|
||||
"data": `[
|
||||
"android.hardware.bluetooth@1.1-service.sim.rc",
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
":libc++",
|
||||
":libcrypto",
|
||||
]`,
|
||||
"data_bins": `[
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
]`,
|
||||
"tags": `["no-remote"]`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
|
||||
func TestShTestHostAutogen(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}, Bp2buildTestCase{
|
||||
Description: "sh_test_host test",
|
||||
ModuleTypeUnderTest: "sh_test_host",
|
||||
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto", "art-run-test-target-template"},
|
||||
ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
|
||||
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
|
||||
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
|
||||
simpleModule("filegroup", "libc++") +
|
||||
simpleModule("filegroup", "libcrypto") +
|
||||
simpleModule("filegroup", "art-run-test-target-template") + `sh_test_host{
|
||||
name: "sts-rootcanal-sidebins",
|
||||
src: "empty.sh",
|
||||
test_suites: [
|
||||
"sts",
|
||||
"sts-lite",
|
||||
],
|
||||
data_bins: [
|
||||
"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim"
|
||||
],
|
||||
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
|
||||
data_libs: ["libc++","libcrypto"],
|
||||
test_config: "art-gtests-target-install-apex.xml",
|
||||
test_config_template: ":art-run-test-target-template",
|
||||
auto_gen_config: true,
|
||||
test_options:{tags: ["no-remote"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
|
||||
"srcs": `["empty.sh"]`,
|
||||
"runs_on": `["host_without_device"]`,
|
||||
"auto_generate_test_config": "True",
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
"template_test_config": `":art-run-test-target-template"`,
|
||||
"data": `[
|
||||
"android.hardware.bluetooth@1.1-service.sim.rc",
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
":libc++",
|
||||
":libcrypto",
|
||||
]`,
|
||||
"data_bins": `[
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
]`,
|
||||
"tags": `["no-remote"]`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
func TestShTestSimpleUnset(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}, Bp2buildTestCase{
|
||||
Description: "sh_test test",
|
||||
ModuleTypeUnderTest: "sh_test",
|
||||
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
|
||||
ModuleTypeUnderTestFactory: sh.ShTestFactory,
|
||||
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
|
||||
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
|
||||
simpleModule("filegroup", "libc++") +
|
||||
simpleModule("filegroup", "libcrypto") + `sh_test{
|
||||
name: "sts-rootcanal-sidebins",
|
||||
src: "empty.sh",
|
||||
test_suites: [
|
||||
"sts",
|
||||
"sts-lite",
|
||||
],
|
||||
data_bins: [
|
||||
"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim"
|
||||
],
|
||||
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
|
||||
data_libs: ["libc++","libcrypto"],
|
||||
test_options:{tags: ["no-remote"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
|
||||
"srcs": `["empty.sh"]`,
|
||||
"runs_on": `["device"]`,
|
||||
"data": `[
|
||||
"android.hardware.bluetooth@1.1-service.sim.rc",
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
":libc++",
|
||||
":libcrypto",
|
||||
]`,
|
||||
"data_bins": `[
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
]`,
|
||||
"tags": `["no-remote"]`,
|
||||
})},
|
||||
})
|
||||
}
|
||||
|
||||
func TestShTestHostSimpleUnset(t *testing.T) {
|
||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
}, Bp2buildTestCase{
|
||||
Description: "sh_test_host test",
|
||||
ModuleTypeUnderTest: "sh_test_host",
|
||||
ModuleTypeUnderTestFactory: sh.ShTestHostFactory,
|
||||
StubbedBuildDefinitions: []string{"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim", "libc++", "libcrypto"},
|
||||
Blueprint: simpleModule("filegroup", "android.hardware.bluetooth@1.1-service.sim") +
|
||||
simpleModule("filegroup", "android.hardware.bluetooth@1.1-impl-sim") +
|
||||
simpleModule("filegroup", "libc++") +
|
||||
simpleModule("filegroup", "libcrypto") + `sh_test_host{
|
||||
name: "sts-rootcanal-sidebins",
|
||||
src: "empty.sh",
|
||||
test_suites: [
|
||||
"sts",
|
||||
"sts-lite",
|
||||
],
|
||||
data_bins: [
|
||||
"android.hardware.bluetooth@1.1-service.sim",
|
||||
"android.hardware.bluetooth@1.1-impl-sim"
|
||||
],
|
||||
data: ["android.hardware.bluetooth@1.1-service.sim.rc"],
|
||||
data_libs: ["libc++","libcrypto"],
|
||||
test_options:{tags: ["no-remote"],
|
||||
},
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("sh_test", "sts-rootcanal-sidebins", AttrNameToString{
|
||||
"srcs": `["empty.sh"]`,
|
||||
"runs_on": `["host_without_device"]`,
|
||||
"data": `[
|
||||
"android.hardware.bluetooth@1.1-service.sim.rc",
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
":libc++",
|
||||
":libcrypto",
|
||||
]`,
|
||||
"data_bins": `[
|
||||
":android.hardware.bluetooth@1.1-service.sim",
|
||||
":android.hardware.bluetooth@1.1-impl-sim",
|
||||
]`,
|
||||
"tags": `["no-remote"]`,
|
||||
"target_compatible_with": `select({
|
||||
"//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
|
||||
"//conditions:default": [],
|
||||
})`,
|
||||
})},
|
||||
})
|
||||
}
|
File diff suppressed because it is too large
Load diff
66
bpf/bpf.go
66
bpf/bpf.go
|
@ -22,8 +22,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
"android/soong/cc"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
|
@ -98,7 +96,6 @@ type BpfProperties struct {
|
|||
|
||||
type bpf struct {
|
||||
android.ModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
properties BpfProperties
|
||||
|
||||
|
@ -245,35 +242,6 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
|
|||
}
|
||||
}
|
||||
|
||||
var _ android.MixedBuildBuildable = (*bpf)(nil)
|
||||
|
||||
func (bpf *bpf) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (bpf *bpf) QueueBazelCall(ctx android.BaseModuleContext) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(
|
||||
bpf.GetBazelLabel(ctx, bpf),
|
||||
cquery.GetOutputFiles,
|
||||
android.GetConfigKey(ctx))
|
||||
}
|
||||
|
||||
func (bpf *bpf) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
objPaths, err := bazelCtx.GetOutputFiles(bpf.GetBazelLabel(ctx, bpf), android.GetConfigKey(ctx))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
bazelOuts := android.Paths{}
|
||||
for _, p := range objPaths {
|
||||
bazelOuts = append(bazelOuts, android.PathForBazelOut(ctx, p))
|
||||
}
|
||||
bpf.objs = bazelOuts
|
||||
}
|
||||
|
||||
// Implements OutputFileFileProducer interface so that the obj output can be used in the data property
|
||||
// of other modules.
|
||||
func (bpf *bpf) OutputFiles(tag string) (android.Paths, error) {
|
||||
|
@ -297,39 +265,5 @@ func BpfFactory() android.Module {
|
|||
module.AddProperties(&module.properties)
|
||||
|
||||
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
|
||||
android.InitBazelModule(module)
|
||||
return module
|
||||
}
|
||||
|
||||
type bazelBpfAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Copts bazel.StringListAttribute
|
||||
Absolute_includes bazel.StringListAttribute
|
||||
Btf *bool
|
||||
// TODO(b/249528391): Add support for sub_dir
|
||||
}
|
||||
|
||||
// bpf bp2build converter
|
||||
func (b *bpf) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
if ctx.ModuleType() != "bpf" {
|
||||
return
|
||||
}
|
||||
|
||||
srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, b.properties.Srcs))
|
||||
copts := bazel.MakeStringListAttribute(b.properties.Cflags)
|
||||
absolute_includes := bazel.MakeStringListAttribute(b.properties.Include_dirs)
|
||||
btf := b.properties.Btf
|
||||
|
||||
attrs := bazelBpfAttributes{
|
||||
Srcs: srcs,
|
||||
Copts: copts,
|
||||
Absolute_includes: absolute_includes,
|
||||
Btf: btf,
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "bpf",
|
||||
Bzl_load_location: "//build/bazel/rules/bpf:bpf.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: b.Name()}, &attrs)
|
||||
}
|
||||
|
|
|
@ -71,26 +71,3 @@ func TestBpfSourceName(t *testing.T) {
|
|||
`\QAndroid.bp:2:3: module "bpf_invalid_name.o" variant "android_common": invalid character '_' in source name\E`)).
|
||||
RunTestWithBp(t, bp)
|
||||
}
|
||||
|
||||
func TestBpfWithBazel(t *testing.T) {
|
||||
bp := `
|
||||
bpf {
|
||||
name: "bpf.o",
|
||||
srcs: ["bpf.c"],
|
||||
bazel_module: { label: "//bpf" },
|
||||
}
|
||||
`
|
||||
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForBpfTest, android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "outputbase",
|
||||
LabelToOutputFiles: map[string][]string{
|
||||
"//bpf": []string{"bpf.o"}}}
|
||||
})).RunTestWithBp(t, bp)
|
||||
|
||||
output := result.Module("bpf.o", "android_common").(*bpf)
|
||||
|
||||
expectedOutputFiles := []string{"outputbase/execroot/__main__/bpf.o"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, output.objs.Strings())
|
||||
}
|
||||
|
|
|
@ -12,14 +12,12 @@ bootstrap_go_package {
|
|||
"soong-aconfig",
|
||||
"soong-aidl-library",
|
||||
"soong-android",
|
||||
"soong-bazel",
|
||||
"soong-cc-config",
|
||||
"soong-etc",
|
||||
"soong-fuzz",
|
||||
"soong-genrule",
|
||||
"soong-multitree",
|
||||
"soong-snapshot",
|
||||
"soong-sysprop-bp2build",
|
||||
"soong-testing",
|
||||
"soong-tradefed",
|
||||
],
|
||||
|
@ -28,7 +26,6 @@ bootstrap_go_package {
|
|||
"fdo_profile.go",
|
||||
"androidmk.go",
|
||||
"api_level.go",
|
||||
"bp2build.go",
|
||||
"builder.go",
|
||||
"cc.go",
|
||||
"ccdeps.go",
|
||||
|
|
10
cc/afdo.go
10
cc/afdo.go
|
@ -24,16 +24,6 @@ import (
|
|||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
// TODO(b/267229066): Remove globalAfdoProfileProjects after implementing bp2build converter for fdo_profile
|
||||
var (
|
||||
globalAfdoProfileProjects = []string{
|
||||
"vendor/google_data/pgo_profile/sampling/",
|
||||
"toolchain/pgo-profiles/sampling/",
|
||||
}
|
||||
)
|
||||
|
||||
var afdoProfileProjectsConfigKey = android.NewOnceKey("AfdoProfileProjects")
|
||||
|
||||
// This flag needs to be in both CFlags and LdFlags to ensure correct symbol ordering
|
||||
const afdoFlagsFormat = "-fprofile-sample-use=%s -fprofile-sample-accurate"
|
||||
|
||||
|
|
163
cc/binary.go
163
cc/binary.go
|
@ -17,13 +17,8 @@ package cc
|
|||
import (
|
||||
"path/filepath"
|
||||
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
type BinaryLinkerProperties struct {
|
||||
|
@ -71,14 +66,13 @@ func RegisterBinaryBuildComponents(ctx android.RegistrationContext) {
|
|||
|
||||
// cc_binary produces a binary that is runnable on a device.
|
||||
func BinaryFactory() android.Module {
|
||||
module, _ := newBinary(android.HostAndDeviceSupported, true)
|
||||
module.bazelHandler = &ccBinaryBazelHandler{module: module}
|
||||
module, _ := newBinary(android.HostAndDeviceSupported)
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
// cc_binary_host produces a binary that is runnable on a host.
|
||||
func BinaryHostFactory() android.Module {
|
||||
module, _ := newBinary(android.HostSupported, true)
|
||||
module, _ := newBinary(android.HostSupported)
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -196,10 +190,10 @@ func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||
// Individual module implementations which comprise a C++ binary should call this function,
|
||||
// set some fields on the result, and then call the Init function.
|
||||
func NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
||||
return newBinary(hod, true)
|
||||
return newBinary(hod)
|
||||
}
|
||||
|
||||
func newBinary(hod android.HostOrDeviceSupported, bazelable bool) (*Module, *binaryDecorator) {
|
||||
func newBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
||||
module := newModule(hod, android.MultilibFirst)
|
||||
binary := &binaryDecorator{
|
||||
baseLinker: NewBaseLinker(module.sanitize),
|
||||
|
@ -208,7 +202,6 @@ func newBinary(hod android.HostOrDeviceSupported, bazelable bool) (*Module, *bin
|
|||
module.compiler = NewBaseCompiler()
|
||||
module.linker = binary
|
||||
module.installer = binary
|
||||
module.bazelable = bazelable
|
||||
|
||||
// Allow module to be added as member of an sdk/module_exports.
|
||||
module.sdkMemberTypes = []android.SdkMemberType{
|
||||
|
@ -568,149 +561,3 @@ func (binary *binaryDecorator) verifyHostBionicLinker(ctx ModuleContext, in, lin
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
type ccBinaryBazelHandler struct {
|
||||
module *Module
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*ccBinaryBazelHandler)(nil)
|
||||
|
||||
func (handler *ccBinaryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(label, cquery.GetCcUnstrippedInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
}
|
||||
|
||||
func (handler *ccBinaryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
info, err := bazelCtx.GetCcUnstrippedInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var outputFilePath android.Path = android.PathForBazelOut(ctx, info.OutputFile)
|
||||
if len(info.TidyFiles) > 0 {
|
||||
handler.module.tidyFiles = android.PathsForBazelOut(ctx, info.TidyFiles)
|
||||
outputFilePath = android.AttachValidationActions(ctx, outputFilePath, handler.module.tidyFiles)
|
||||
}
|
||||
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
|
||||
handler.module.linker.(*binaryDecorator).unstrippedOutputFile = android.PathForBazelOut(ctx, info.UnstrippedOutput)
|
||||
|
||||
handler.module.setAndroidMkVariablesFromCquery(info.CcAndroidMkInfo)
|
||||
}
|
||||
|
||||
func binaryBp2buildAttrs(ctx android.Bp2buildMutatorContext, m *Module) binaryAttributes {
|
||||
baseAttrs := bp2BuildParseBaseProps(ctx, m)
|
||||
binaryLinkerAttrs := bp2buildBinaryLinkerProps(ctx, m)
|
||||
|
||||
if proptools.BoolDefault(binaryLinkerAttrs.Linkshared, true) {
|
||||
baseAttrs.implementationDynamicDeps.Add(baseAttrs.protoDependency)
|
||||
} else {
|
||||
baseAttrs.implementationDeps.Add(baseAttrs.protoDependency)
|
||||
}
|
||||
|
||||
// binaries don't have implementation_whole_archive_deps
|
||||
baseAttrs.wholeArchiveDeps.Append(baseAttrs.implementationWholeArchiveDeps)
|
||||
|
||||
attrs := binaryAttributes{
|
||||
binaryLinkerAttrs: binaryLinkerAttrs,
|
||||
|
||||
Srcs: baseAttrs.srcs,
|
||||
Srcs_c: baseAttrs.cSrcs,
|
||||
Srcs_as: baseAttrs.asSrcs,
|
||||
|
||||
Copts: baseAttrs.copts,
|
||||
Cppflags: baseAttrs.cppFlags,
|
||||
Conlyflags: baseAttrs.conlyFlags,
|
||||
Asflags: baseAttrs.asFlags,
|
||||
|
||||
Deps: baseAttrs.implementationDeps,
|
||||
Dynamic_deps: baseAttrs.implementationDynamicDeps,
|
||||
Whole_archive_deps: baseAttrs.wholeArchiveDeps,
|
||||
System_deps: baseAttrs.systemDynamicDeps,
|
||||
Runtime_deps: baseAttrs.runtimeDeps,
|
||||
|
||||
Local_includes: baseAttrs.localIncludes,
|
||||
Absolute_includes: baseAttrs.absoluteIncludes,
|
||||
Linkopts: baseAttrs.linkopts,
|
||||
Use_version_lib: baseAttrs.useVersionLib,
|
||||
Rtti: baseAttrs.rtti,
|
||||
Stl: baseAttrs.stl,
|
||||
Cpp_std: baseAttrs.cppStd,
|
||||
|
||||
Additional_linker_inputs: baseAttrs.additionalLinkerInputs,
|
||||
Additional_compiler_inputs: baseAttrs.additionalCompilerInputs,
|
||||
|
||||
Strip: stripAttributes{
|
||||
Keep_symbols: baseAttrs.stripKeepSymbols,
|
||||
Keep_symbols_and_debug_frame: baseAttrs.stripKeepSymbolsAndDebugFrame,
|
||||
Keep_symbols_list: baseAttrs.stripKeepSymbolsList,
|
||||
All: baseAttrs.stripAll,
|
||||
None: baseAttrs.stripNone,
|
||||
},
|
||||
|
||||
Features: baseAttrs.features,
|
||||
|
||||
SdkAttributes: Bp2BuildParseSdkAttributes(m),
|
||||
|
||||
Native_coverage: baseAttrs.Native_coverage,
|
||||
}
|
||||
|
||||
m.convertTidyAttributes(ctx, &attrs.tidyAttributes)
|
||||
|
||||
return attrs
|
||||
}
|
||||
|
||||
func binaryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||
// shared with cc_test
|
||||
binaryAttrs := binaryBp2buildAttrs(ctx, m)
|
||||
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_binary",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_binary.bzl",
|
||||
},
|
||||
android.CommonAttributes{Name: m.Name(), Tags: tags},
|
||||
&binaryAttrs)
|
||||
}
|
||||
|
||||
// binaryAttributes contains Bazel attributes corresponding to a cc binary
|
||||
type binaryAttributes struct {
|
||||
binaryLinkerAttrs
|
||||
Srcs bazel.LabelListAttribute
|
||||
Srcs_c bazel.LabelListAttribute
|
||||
Srcs_as bazel.LabelListAttribute
|
||||
|
||||
Copts bazel.StringListAttribute
|
||||
Cppflags bazel.StringListAttribute
|
||||
Conlyflags bazel.StringListAttribute
|
||||
Asflags bazel.StringListAttribute
|
||||
Additional_compiler_inputs bazel.LabelListAttribute
|
||||
|
||||
Deps bazel.LabelListAttribute
|
||||
Dynamic_deps bazel.LabelListAttribute
|
||||
Whole_archive_deps bazel.LabelListAttribute
|
||||
System_deps bazel.LabelListAttribute
|
||||
Runtime_deps bazel.LabelListAttribute
|
||||
|
||||
Local_includes bazel.StringListAttribute
|
||||
Absolute_includes bazel.StringListAttribute
|
||||
|
||||
Linkopts bazel.StringListAttribute
|
||||
Additional_linker_inputs bazel.LabelListAttribute
|
||||
Use_version_lib bazel.BoolAttribute
|
||||
|
||||
Rtti bazel.BoolAttribute
|
||||
Stl *string
|
||||
Cpp_std *string
|
||||
|
||||
Strip stripAttributes
|
||||
|
||||
Features bazel.StringListAttribute
|
||||
|
||||
SdkAttributes
|
||||
|
||||
tidyAttributes
|
||||
|
||||
Native_coverage *bool
|
||||
}
|
||||
|
|
|
@ -17,89 +17,9 @@ package cc
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
func TestCcBinaryWithBazel(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_binary {
|
||||
name: "foo",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "outputbase",
|
||||
LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{
|
||||
"//foo/bar:bar": cquery.CcUnstrippedInfo{
|
||||
OutputFile: "foo",
|
||||
UnstrippedOutput: "foo.unstripped",
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
|
||||
binMod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module()
|
||||
producer := binMod.(android.OutputFileProducer)
|
||||
outputFiles, err := producer.OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_binary outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{"outputbase/execroot/__main__/foo"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
|
||||
unStrippedFilePath := binMod.(*Module).UnstrippedOutputFile()
|
||||
expectedUnStrippedFile := "outputbase/execroot/__main__/foo.unstripped"
|
||||
android.AssertStringEquals(t, "Unstripped output file", expectedUnStrippedFile, unStrippedFilePath.String())
|
||||
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, binMod)[0]
|
||||
android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "cc_binary", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0])
|
||||
}
|
||||
|
||||
func TestCcBinaryWithBazelValidations(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_binary {
|
||||
name: "foo",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
tidy: true,
|
||||
}`
|
||||
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "outputbase",
|
||||
LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{
|
||||
"//foo/bar:bar": cquery.CcUnstrippedInfo{
|
||||
OutputFile: "foo",
|
||||
UnstrippedOutput: "foo.unstripped",
|
||||
TidyFiles: []string{"foo.c.tidy"},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := android.GroupFixturePreparers(
|
||||
prepareForCcTest,
|
||||
android.FixtureMergeEnv(map[string]string{
|
||||
"ALLOW_LOCAL_TIDY_TRUE": "1",
|
||||
}),
|
||||
).RunTestWithConfig(t, config).TestContext
|
||||
|
||||
binMod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module()
|
||||
producer := binMod.(android.OutputFileProducer)
|
||||
outputFiles, err := producer.OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_binary outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{"out/soong/.intermediates/foo/android_arm64_armv8-a/validated/foo"}
|
||||
android.AssertPathsRelativeToTopEquals(t, "output files", expectedOutputFiles, outputFiles)
|
||||
|
||||
unStrippedFilePath := binMod.(*Module).UnstrippedOutputFile()
|
||||
expectedUnStrippedFile := "outputbase/execroot/__main__/foo.unstripped"
|
||||
android.AssertStringEquals(t, "Unstripped output file", expectedUnStrippedFile, unStrippedFilePath.String())
|
||||
}
|
||||
|
||||
func TestBinaryLinkerScripts(t *testing.T) {
|
||||
t.Parallel()
|
||||
result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
|
||||
|
|
2127
cc/bp2build.go
2127
cc/bp2build.go
File diff suppressed because it is too large
Load diff
268
cc/cc.go
268
cc/cc.go
|
@ -25,15 +25,12 @@ import (
|
|||
"strings"
|
||||
|
||||
"android/soong/testing"
|
||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/aconfig"
|
||||
"android/soong/aidl_library"
|
||||
"android/soong/android"
|
||||
"android/soong/bazel/cquery"
|
||||
"android/soong/cc/config"
|
||||
"android/soong/fuzz"
|
||||
"android/soong/genrule"
|
||||
|
@ -592,7 +589,6 @@ type Generator interface {
|
|||
GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
|
||||
GeneratorSources(ctx ModuleContext) GeneratedSource
|
||||
GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps)
|
||||
GeneratorBp2build(ctx android.Bp2buildMutatorContext, module *Module) bool
|
||||
}
|
||||
|
||||
// compiler is the interface for a compiler helper object. Different module decorators may implement
|
||||
|
@ -831,19 +827,6 @@ func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
|
|||
return ok && ccDepTag == testPerSrcDepTag
|
||||
}
|
||||
|
||||
// bazelHandler is the interface for a helper object related to deferring to Bazel for
|
||||
// processing a cc module (during Bazel mixed builds). Individual module types should define
|
||||
// their own bazel handler if they support being handled by Bazel.
|
||||
type BazelHandler interface {
|
||||
// QueueBazelCall invokes request-queueing functions on the BazelContext
|
||||
//so that these requests are handled when Bazel's cquery is invoked.
|
||||
QueueBazelCall(ctx android.BaseModuleContext, label string)
|
||||
|
||||
// ProcessBazelQueryResponse uses information retrieved from Bazel to set properties
|
||||
// on the current module with given label.
|
||||
ProcessBazelQueryResponse(ctx android.ModuleContext, label string)
|
||||
}
|
||||
|
||||
// Module contains the properties and members used by all C/C++ module types, and implements
|
||||
// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
|
||||
// to construct the output file. Behavior can be customized with a Customizer, or "decorator",
|
||||
|
@ -861,15 +844,12 @@ type BazelHandler interface {
|
|||
type Module struct {
|
||||
fuzz.FuzzModule
|
||||
|
||||
android.BazelModuleBase
|
||||
|
||||
VendorProperties VendorProperties
|
||||
Properties BaseProperties
|
||||
|
||||
// initialize before calling Init
|
||||
hod android.HostOrDeviceSupported
|
||||
multilib android.Multilib
|
||||
bazelable bool
|
||||
testModule bool
|
||||
|
||||
// Allowable SdkMemberTypes of this module type.
|
||||
|
@ -880,11 +860,10 @@ type Module struct {
|
|||
// type-specific logic. These members may reference different objects or the same object.
|
||||
// Functions of these decorators will be invoked to initialize and register type-specific
|
||||
// build statements.
|
||||
generators []Generator
|
||||
compiler compiler
|
||||
linker linker
|
||||
installer installer
|
||||
bazelHandler BazelHandler
|
||||
generators []Generator
|
||||
compiler compiler
|
||||
linker linker
|
||||
installer installer
|
||||
|
||||
features []feature
|
||||
stl *stl
|
||||
|
@ -1288,9 +1267,6 @@ func (c *Module) Init() android.Module {
|
|||
}
|
||||
|
||||
android.InitAndroidArchModule(c, c.hod, c.multilib)
|
||||
if c.bazelable {
|
||||
android.InitBazelModule(c)
|
||||
}
|
||||
android.InitApexModule(c)
|
||||
android.InitDefaultableModule(c)
|
||||
|
||||
|
@ -1546,8 +1522,6 @@ func isBionic(name string) bool {
|
|||
}
|
||||
|
||||
func InstallToBootstrap(name string, config android.Config) bool {
|
||||
// NOTE: also update //build/bazel/rules/apex/cc.bzl#_installed_to_bootstrap
|
||||
// if this list is updated.
|
||||
if name == "libclang_rt.hwasan" || name == "libc_hwasan" {
|
||||
return true
|
||||
}
|
||||
|
@ -1943,170 +1917,6 @@ func GetSubnameProperty(actx android.ModuleContext, c LinkableInterface) string
|
|||
return subName
|
||||
}
|
||||
|
||||
var _ android.MixedBuildBuildable = (*Module)(nil)
|
||||
|
||||
func (c *Module) getBazelModuleLabel(ctx android.BaseModuleContext) string {
|
||||
var bazelModuleLabel string
|
||||
if c.typ() == fullLibrary && c.static() {
|
||||
// cc_library is a special case in bp2build; two targets are generated -- one for each
|
||||
// of the shared and static variants. The shared variant keeps the module name, but the
|
||||
// static variant uses a different suffixed name.
|
||||
bazelModuleLabel = bazelLabelForStaticModule(ctx, c)
|
||||
} else {
|
||||
bazelModuleLabel = c.GetBazelLabel(ctx, c)
|
||||
}
|
||||
labelNoPrebuilt := bazelModuleLabel
|
||||
if c.IsPrebuilt() {
|
||||
labelNoPrebuilt = android.RemoveOptionalPrebuiltPrefixFromBazelLabel(bazelModuleLabel)
|
||||
}
|
||||
return labelNoPrebuilt
|
||||
}
|
||||
|
||||
func (c *Module) QueueBazelCall(ctx android.BaseModuleContext) {
|
||||
c.bazelHandler.QueueBazelCall(ctx, c.getBazelModuleLabel(ctx))
|
||||
}
|
||||
|
||||
// IsMixedBuildSupported returns true if the module should be analyzed by Bazel
|
||||
// in any of the --bazel-mode(s).
|
||||
func (c *Module) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
|
||||
if !allEnabledSanitizersSupportedByBazel(ctx, c) {
|
||||
//TODO(b/278772861) support sanitizers in Bazel rules
|
||||
return false
|
||||
}
|
||||
if !imageVariantSupportedByBazel(c) {
|
||||
return false
|
||||
}
|
||||
if c.IsSdkVariant() {
|
||||
return false
|
||||
}
|
||||
return c.bazelHandler != nil
|
||||
}
|
||||
|
||||
func imageVariantSupportedByBazel(c *Module) bool {
|
||||
if c.IsLlndk() {
|
||||
return false
|
||||
}
|
||||
if c.InVendor() {
|
||||
return false
|
||||
}
|
||||
if c.InProduct() {
|
||||
return false
|
||||
}
|
||||
if c.InRamdisk() {
|
||||
return false
|
||||
}
|
||||
if c.InVendorRamdisk() {
|
||||
return false
|
||||
}
|
||||
if c.InRecovery() {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func allEnabledSanitizersSupportedByBazel(ctx android.BaseModuleContext, c *Module) bool {
|
||||
if c.sanitize == nil {
|
||||
return true
|
||||
}
|
||||
sanitizeProps := &c.sanitize.Properties.SanitizeMutated
|
||||
|
||||
unsupportedSanitizers := []*bool{
|
||||
sanitizeProps.Safestack,
|
||||
sanitizeProps.Scudo,
|
||||
BoolPtr(len(c.sanitize.Properties.Sanitize.Recover) > 0),
|
||||
}
|
||||
for _, san := range unsupportedSanitizers {
|
||||
if Bool(san) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for _, san := range Sanitizers {
|
||||
if san == intOverflow {
|
||||
// TODO(b/261058727): enable mixed builds for all modules with UBSan
|
||||
// Currently we can only support ubsan when minimum runtime is used.
|
||||
ubsanEnabled := Bool(sanitizeProps.Integer_overflow) || len(sanitizeProps.Misc_undefined) > 0
|
||||
if !ubsanEnabled || c.MinimalRuntimeNeeded() {
|
||||
continue
|
||||
}
|
||||
} else if san == cfi {
|
||||
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
||||
// Only allow cfi if this is an apex variant
|
||||
if !apexInfo.IsForPlatform() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if c.sanitize.isSanitizerEnabled(san) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func GetApexConfigKey(ctx android.BaseModuleContext) *android.ApexConfigKey {
|
||||
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
||||
if !apexInfo.IsForPlatform() {
|
||||
apexKey := android.ApexConfigKey{
|
||||
WithinApex: true,
|
||||
ApexSdkVersion: findApexSdkVersion(ctx, apexInfo).String(),
|
||||
ApiDomain: findApiDomain(apexInfo),
|
||||
}
|
||||
return &apexKey
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns the api domain of a module for an apexInfo group
|
||||
// Input:
|
||||
// ai.InApexModules: [com.android.foo, test_com.android.foo, com.google.android.foo]
|
||||
// Return:
|
||||
// com.android.foo
|
||||
|
||||
// If a module is included in multiple api domains (collated by min_sdk_version), it will return
|
||||
// the first match. The other matches have the same build actions since they share a min_sdk_version, so returning
|
||||
// the first match is fine.
|
||||
func findApiDomain(ai android.ApexInfo) string {
|
||||
// Remove any test apexes
|
||||
matches, _ := android.FilterList(ai.InApexModules, ai.TestApexes)
|
||||
// Remove any google apexes. Rely on naming convention.
|
||||
pred := func(s string) bool { return !strings.HasPrefix(s, "com.google") }
|
||||
matches = android.FilterListPred(matches, pred)
|
||||
if len(matches) > 0 {
|
||||
// Return the first match
|
||||
return android.SortedUniqueStrings(matches)[0]
|
||||
} else {
|
||||
// No apex in the tree has a dependency on this module
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
||||
bazelModuleLabel := c.getBazelModuleLabel(ctx)
|
||||
c.bazelHandler.ProcessBazelQueryResponse(ctx, bazelModuleLabel)
|
||||
|
||||
c.Properties.SubName = GetSubnameProperty(ctx, c)
|
||||
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
||||
if !apexInfo.IsForPlatform() {
|
||||
c.hideApexVariantFromMake = true
|
||||
}
|
||||
|
||||
c.makeLinkType = GetMakeLinkType(ctx, c)
|
||||
|
||||
mctx := &moduleContext{
|
||||
ModuleContext: ctx,
|
||||
moduleContextImpl: moduleContextImpl{
|
||||
mod: c,
|
||||
},
|
||||
}
|
||||
mctx.ctx = mctx
|
||||
|
||||
// TODO(b/244432500): Get the tradefed config from the bazel target instead
|
||||
// of generating it with Soong.
|
||||
c.maybeInstall(mctx, apexInfo)
|
||||
}
|
||||
|
||||
func moduleContextFromAndroidModuleContext(actx android.ModuleContext, c *Module) ModuleContext {
|
||||
ctx := &moduleContext{
|
||||
ModuleContext: actx,
|
||||
|
@ -2345,9 +2155,8 @@ func (c *Module) maybeUnhideFromMake() {
|
|||
}
|
||||
}
|
||||
|
||||
// maybeInstall is called at the end of both GenerateAndroidBuildActions and
|
||||
// ProcessBazelQueryResponse to run the install hooks for installable modules,
|
||||
// like binaries and tests.
|
||||
// maybeInstall is called at the end of both GenerateAndroidBuildActions to run the
|
||||
// install hooks for installable modules, like binaries and tests.
|
||||
func (c *Module) maybeInstall(ctx ModuleContext, apexInfo android.ApexInfo) {
|
||||
if !proptools.BoolDefault(c.Installable(), true) {
|
||||
// If the module has been specifically configure to not be installed then
|
||||
|
@ -2370,12 +2179,6 @@ func (c *Module) maybeInstall(ctx ModuleContext, apexInfo android.ApexInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Module) setAndroidMkVariablesFromCquery(info cquery.CcAndroidMkInfo) {
|
||||
c.Properties.AndroidMkSharedLibs = info.LocalSharedLibs
|
||||
c.Properties.AndroidMkStaticLibs = info.LocalStaticLibs
|
||||
c.Properties.AndroidMkWholeStaticLibs = info.LocalWholeStaticLibs
|
||||
}
|
||||
|
||||
func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
|
||||
if c.cachedToolchain == nil {
|
||||
c.cachedToolchain = config.FindToolchainWithContext(ctx)
|
||||
|
@ -4215,65 +4018,6 @@ func (c *Module) typ() moduleType {
|
|||
return unknownType
|
||||
}
|
||||
|
||||
// ConvertWithBp2build converts Module to Bazel for bp2build.
|
||||
func (c *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
if len(c.generators) > 0 {
|
||||
allConverted := true
|
||||
for _, generator := range c.generators {
|
||||
allConverted = allConverted && generator.GeneratorBp2build(ctx, c)
|
||||
}
|
||||
if allConverted {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
prebuilt := c.IsPrebuilt()
|
||||
switch c.typ() {
|
||||
case binary:
|
||||
if prebuilt {
|
||||
prebuiltBinaryBp2Build(ctx, c)
|
||||
} else {
|
||||
binaryBp2build(ctx, c)
|
||||
}
|
||||
case testBin:
|
||||
if !prebuilt {
|
||||
testBinaryBp2build(ctx, c)
|
||||
}
|
||||
case object:
|
||||
if prebuilt {
|
||||
prebuiltObjectBp2Build(ctx, c)
|
||||
} else {
|
||||
objectBp2Build(ctx, c)
|
||||
}
|
||||
case fullLibrary:
|
||||
if !prebuilt {
|
||||
libraryBp2Build(ctx, c)
|
||||
} else {
|
||||
prebuiltLibraryBp2Build(ctx, c)
|
||||
}
|
||||
case headerLibrary:
|
||||
libraryHeadersBp2Build(ctx, c)
|
||||
case staticLibrary:
|
||||
if prebuilt {
|
||||
prebuiltLibraryStaticBp2Build(ctx, c, false)
|
||||
} else {
|
||||
sharedOrStaticLibraryBp2Build(ctx, c, true)
|
||||
}
|
||||
case sharedLibrary:
|
||||
if prebuilt {
|
||||
prebuiltLibrarySharedBp2Build(ctx, c)
|
||||
} else {
|
||||
sharedOrStaticLibraryBp2Build(ctx, c, false)
|
||||
}
|
||||
case ndkPrebuiltStl:
|
||||
ndkPrebuiltStlBp2build(ctx, c)
|
||||
case ndkLibrary:
|
||||
ndkLibraryBp2build(ctx, c)
|
||||
default:
|
||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
|
||||
}
|
||||
}
|
||||
|
||||
// Defaults
|
||||
type Defaults struct {
|
||||
android.ModuleBase
|
||||
|
|
698
cc/cc_test.go
698
cc/cc_test.go
|
@ -26,7 +26,6 @@ import (
|
|||
|
||||
"android/soong/aidl_library"
|
||||
"android/soong/android"
|
||||
"android/soong/bazel/cquery"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -46,27 +45,15 @@ var prepareForCcTest = android.GroupFixturePreparers(
|
|||
}),
|
||||
)
|
||||
|
||||
var ccLibInApex = "cc_lib_in_apex"
|
||||
var apexVariationName = "apex28"
|
||||
var apexVersion = "28"
|
||||
|
||||
func registerTestMutators(ctx android.RegistrationContext) {
|
||||
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
||||
ctx.BottomUp("apex", testApexMutator).Parallel()
|
||||
ctx.BottomUp("mixed_builds_prep", mixedBuildsPrepareMutator).Parallel()
|
||||
})
|
||||
}
|
||||
|
||||
func mixedBuildsPrepareMutator(ctx android.BottomUpMutatorContext) {
|
||||
if m := ctx.Module(); m.Enabled() {
|
||||
if mixedBuildMod, ok := m.(android.MixedBuildBuildable); ok {
|
||||
if mixedBuildMod.IsMixedBuildSupported(ctx) && android.MixedBuildsEnabled(ctx) == android.MixedBuildEnabled {
|
||||
mixedBuildMod.QueueBazelCall(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testApexMutator(mctx android.BottomUpMutatorContext) {
|
||||
modules := mctx.CreateVariations(apexVariationName)
|
||||
apexInfo := android.ApexInfo{
|
||||
|
@ -2929,258 +2916,6 @@ func TestStaticLibDepExport(t *testing.T) {
|
|||
checkStaticLibs(t, []string{"lib1", "libc++_static", "libc++demangle", "libclang_rt.builtins"}, module)
|
||||
}
|
||||
|
||||
func TestLibDepAndroidMkExportInMixedBuilds(t *testing.T) {
|
||||
bp := `
|
||||
cc_library {
|
||||
name: "static_dep",
|
||||
}
|
||||
cc_library {
|
||||
name: "whole_static_dep",
|
||||
}
|
||||
cc_library {
|
||||
name: "shared_dep",
|
||||
}
|
||||
cc_library {
|
||||
name: "lib",
|
||||
bazel_module: { label: "//:lib" },
|
||||
static_libs: ["static_dep"],
|
||||
whole_static_libs: ["whole_static_dep"],
|
||||
shared_libs: ["shared_dep"],
|
||||
}
|
||||
cc_test {
|
||||
name: "test",
|
||||
bazel_module: { label: "//:test" },
|
||||
static_libs: ["static_dep"],
|
||||
whole_static_libs: ["whole_static_dep"],
|
||||
shared_libs: ["shared_dep"],
|
||||
gtest: false,
|
||||
sanitize: {
|
||||
// cc_test modules default to memtag_heap: true,
|
||||
// but this adds extra dependencies that we don't care about
|
||||
never: true,
|
||||
}
|
||||
}
|
||||
cc_binary {
|
||||
name: "binary",
|
||||
bazel_module: { label: "//:binary" },
|
||||
static_libs: ["static_dep"],
|
||||
whole_static_libs: ["whole_static_dep"],
|
||||
shared_libs: ["shared_dep"],
|
||||
}
|
||||
cc_library_headers {
|
||||
name: "lib_headers",
|
||||
bazel_module: { label: "//:lib_headers" },
|
||||
static_libs: ["static_dep"],
|
||||
whole_static_libs: ["whole_static_dep"],
|
||||
shared_libs: ["shared_dep"],
|
||||
}
|
||||
cc_prebuilt_library {
|
||||
name: "lib_prebuilt",
|
||||
bazel_module: { label: "//:lib_prebuilt" },
|
||||
static_libs: ["static_dep"],
|
||||
whole_static_libs: ["whole_static_dep"],
|
||||
shared_libs: ["shared_dep"],
|
||||
}
|
||||
`
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
moduleName string
|
||||
variant string
|
||||
androidMkInfo cquery.CcAndroidMkInfo
|
||||
}{
|
||||
{
|
||||
name: "shared lib",
|
||||
moduleName: "lib",
|
||||
variant: "android_arm64_armv8-a_shared",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "static lib",
|
||||
moduleName: "lib",
|
||||
variant: "android_arm64_armv8-a_static",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cc_test arm64",
|
||||
moduleName: "test",
|
||||
variant: "android_arm64_armv8-a",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cc_test arm",
|
||||
moduleName: "test",
|
||||
variant: "android_arm_armv7-a-neon",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cc_binary",
|
||||
moduleName: "binary",
|
||||
variant: "android_arm64_armv8-a",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "cc_library_headers",
|
||||
moduleName: "lib_headers",
|
||||
variant: "android_arm64_armv8-a",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prebuilt lib static",
|
||||
moduleName: "lib_prebuilt",
|
||||
variant: "android_arm64_armv8-a_static",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prebuilt lib shared",
|
||||
moduleName: "lib_prebuilt",
|
||||
variant: "android_arm64_armv8-a_shared",
|
||||
androidMkInfo: cquery.CcAndroidMkInfo{
|
||||
LocalStaticLibs: []string{"static_dep"},
|
||||
LocalWholeStaticLibs: []string{"whole_static_dep"},
|
||||
LocalSharedLibs: []string{"shared_dep"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
outputBaseDir := "out/bazel"
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForCcTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outputBaseDir,
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//:lib": cquery.CcInfo{
|
||||
CcAndroidMkInfo: tc.androidMkInfo,
|
||||
RootDynamicLibraries: []string{""},
|
||||
},
|
||||
"//:lib_bp2build_cc_library_static": cquery.CcInfo{
|
||||
CcAndroidMkInfo: tc.androidMkInfo,
|
||||
RootStaticArchives: []string{""},
|
||||
},
|
||||
"//:lib_headers": cquery.CcInfo{
|
||||
CcAndroidMkInfo: tc.androidMkInfo,
|
||||
OutputFiles: []string{""},
|
||||
},
|
||||
"//:lib_prebuilt": cquery.CcInfo{
|
||||
CcAndroidMkInfo: tc.androidMkInfo,
|
||||
},
|
||||
"//:lib_prebuilt_bp2build_cc_library_static": cquery.CcInfo{
|
||||
CcAndroidMkInfo: tc.androidMkInfo,
|
||||
},
|
||||
},
|
||||
LabelToCcBinary: map[string]cquery.CcUnstrippedInfo{
|
||||
"//:test__tf_internal": cquery.CcUnstrippedInfo{
|
||||
CcAndroidMkInfo: tc.androidMkInfo,
|
||||
},
|
||||
"//:binary": cquery.CcUnstrippedInfo{
|
||||
CcAndroidMkInfo: tc.androidMkInfo,
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
ctx := result.TestContext
|
||||
|
||||
module := ctx.ModuleForTests(tc.moduleName, tc.variant).Module().(*Module)
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, module)[0]
|
||||
if !reflect.DeepEqual(module.Properties.AndroidMkStaticLibs, tc.androidMkInfo.LocalStaticLibs) {
|
||||
t.Errorf("incorrect static_libs"+
|
||||
"\nactual: %v"+
|
||||
"\nexpected: %v",
|
||||
module.Properties.AndroidMkStaticLibs,
|
||||
tc.androidMkInfo.LocalStaticLibs,
|
||||
)
|
||||
}
|
||||
staticDepsDiffer, missingStaticDeps, additionalStaticDeps := android.ListSetDifference(
|
||||
entries.EntryMap["LOCAL_STATIC_LIBRARIES"],
|
||||
tc.androidMkInfo.LocalStaticLibs,
|
||||
)
|
||||
if staticDepsDiffer {
|
||||
t.Errorf(
|
||||
"expected LOCAL_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q",
|
||||
tc.androidMkInfo.LocalStaticLibs,
|
||||
entries.EntryMap["LOCAL_STATIC_LIBRARIES"],
|
||||
missingStaticDeps,
|
||||
additionalStaticDeps,
|
||||
)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(module.Properties.AndroidMkWholeStaticLibs, tc.androidMkInfo.LocalWholeStaticLibs) {
|
||||
t.Errorf("expected module.Properties.AndroidMkWholeStaticLibs to be %q, but was %q",
|
||||
tc.androidMkInfo.LocalWholeStaticLibs,
|
||||
module.Properties.AndroidMkWholeStaticLibs,
|
||||
)
|
||||
}
|
||||
wholeStaticDepsDiffer, missingWholeStaticDeps, additionalWholeStaticDeps := android.ListSetDifference(
|
||||
entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"],
|
||||
tc.androidMkInfo.LocalWholeStaticLibs,
|
||||
)
|
||||
if wholeStaticDepsDiffer {
|
||||
t.Errorf(
|
||||
"expected LOCAL_WHOLE_STATIC_LIBRARIES to be %q but was %q; missing: %q; extra %q",
|
||||
tc.androidMkInfo.LocalWholeStaticLibs,
|
||||
entries.EntryMap["LOCAL_WHOLE_STATIC_LIBRARIES"],
|
||||
missingWholeStaticDeps,
|
||||
additionalWholeStaticDeps,
|
||||
)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(module.Properties.AndroidMkSharedLibs, tc.androidMkInfo.LocalSharedLibs) {
|
||||
t.Errorf("incorrect shared_libs"+
|
||||
"\nactual: %v"+
|
||||
"\nexpected: %v",
|
||||
module.Properties.AndroidMkSharedLibs,
|
||||
tc.androidMkInfo.LocalSharedLibs,
|
||||
)
|
||||
}
|
||||
sharedDepsDiffer, missingSharedDeps, additionalSharedDeps := android.ListSetDifference(
|
||||
entries.EntryMap["LOCAL_SHARED_LIBRARIES"],
|
||||
tc.androidMkInfo.LocalSharedLibs,
|
||||
)
|
||||
if sharedDepsDiffer {
|
||||
t.Errorf(
|
||||
"expected LOCAL_SHARED_LIBRARIES to be %q but was %q; missing %q; extra %q",
|
||||
tc.androidMkInfo.LocalSharedLibs,
|
||||
entries.EntryMap["LOCAL_SHARED_LIBRARIES"],
|
||||
missingSharedDeps,
|
||||
additionalSharedDeps,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var compilerFlagsTestCases = []struct {
|
||||
in string
|
||||
out bool
|
||||
|
@ -3522,130 +3257,6 @@ func TestStubsForLibraryInMultipleApexes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMixedBuildUsesStubs(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_library_shared {
|
||||
name: "libFoo",
|
||||
bazel_module: { label: "//:libFoo" },
|
||||
srcs: ["foo.c"],
|
||||
stubs: {
|
||||
symbol_file: "foo.map.txt",
|
||||
versions: ["current"],
|
||||
},
|
||||
apex_available: ["bar", "a1"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libBar",
|
||||
srcs: ["bar.c"],
|
||||
shared_libs: ["libFoo"],
|
||||
apex_available: ["a1"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libA1",
|
||||
srcs: ["a1.c"],
|
||||
shared_libs: ["libFoo"],
|
||||
apex_available: ["a1"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libBarA1",
|
||||
srcs: ["bara1.c"],
|
||||
shared_libs: ["libFoo"],
|
||||
apex_available: ["bar", "a1"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libAnyApex",
|
||||
srcs: ["anyApex.c"],
|
||||
shared_libs: ["libFoo"],
|
||||
apex_available: ["//apex_available:anyapex"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libBaz",
|
||||
srcs: ["baz.c"],
|
||||
shared_libs: ["libFoo"],
|
||||
apex_available: ["baz"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libQux",
|
||||
srcs: ["qux.c"],
|
||||
shared_libs: ["libFoo"],
|
||||
apex_available: ["qux", "bar"],
|
||||
}`
|
||||
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForCcTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "out/bazel",
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//:libFoo": {
|
||||
RootDynamicLibraries: []string{"libFoo.so"},
|
||||
},
|
||||
"//:libFoo_stub_libs-current": {
|
||||
RootDynamicLibraries: []string{"libFoo_stub_libs-current.so"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
ctx := result.TestContext
|
||||
|
||||
variants := ctx.ModuleVariantsForTests("libFoo")
|
||||
expectedVariants := []string{
|
||||
"android_arm64_armv8-a_shared",
|
||||
"android_arm64_armv8-a_shared_current",
|
||||
"android_arm_armv7-a-neon_shared",
|
||||
"android_arm_armv7-a-neon_shared_current",
|
||||
}
|
||||
variantsMismatch := false
|
||||
if len(variants) != len(expectedVariants) {
|
||||
variantsMismatch = true
|
||||
} else {
|
||||
for _, v := range expectedVariants {
|
||||
if !inList(v, variants) {
|
||||
variantsMismatch = false
|
||||
}
|
||||
}
|
||||
}
|
||||
if variantsMismatch {
|
||||
t.Errorf("variants of libFoo expected:\n")
|
||||
for _, v := range expectedVariants {
|
||||
t.Errorf("%q\n", v)
|
||||
}
|
||||
t.Errorf(", but got:\n")
|
||||
for _, v := range variants {
|
||||
t.Errorf("%q\n", v)
|
||||
}
|
||||
}
|
||||
|
||||
linkAgainstFoo := []string{"libBarA1"}
|
||||
linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"}
|
||||
|
||||
libFooPath := "out/bazel/execroot/__main__/libFoo.so"
|
||||
for _, lib := range linkAgainstFoo {
|
||||
libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
|
||||
libFlags := libLinkRule.Args["libFlags"]
|
||||
if !strings.Contains(libFlags, libFooPath) {
|
||||
t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags)
|
||||
}
|
||||
}
|
||||
|
||||
libFooStubPath := "out/bazel/execroot/__main__/libFoo_stub_libs-current.so"
|
||||
for _, lib := range linkAgainstFooStubs {
|
||||
libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
|
||||
libFlags := libLinkRule.Args["libFlags"]
|
||||
if !strings.Contains(libFlags, libFooStubPath) {
|
||||
t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersioningMacro(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, tc := range []struct{ moduleName, expected string }{
|
||||
|
@ -4019,9 +3630,6 @@ func TestDefaults(t *testing.T) {
|
|||
shared: {
|
||||
srcs: ["baz.c"],
|
||||
},
|
||||
bazel_module: {
|
||||
bp2build_available: true,
|
||||
},
|
||||
}
|
||||
|
||||
cc_library_static {
|
||||
|
@ -5150,309 +4758,3 @@ func TestCcBuildBrokenClangCFlags(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDclaLibraryInApex(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_library_shared {
|
||||
name: "cc_lib_in_apex",
|
||||
srcs: ["foo.cc"],
|
||||
apex_available: ["myapex"],
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
label := "//foo/bar:bar"
|
||||
arch64 := "arm64_armv8-a"
|
||||
arch32 := "arm_armv7-a-neon"
|
||||
apexCfgKey := android.ApexConfigKey{
|
||||
WithinApex: true,
|
||||
ApexSdkVersion: "28",
|
||||
}
|
||||
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForCcTest,
|
||||
android.FixtureRegisterWithContext(registerTestMutators),
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "outputbase",
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
android.BuildMockBazelContextResultKey(label, arch32, android.Android, apexCfgKey): cquery.CcInfo{
|
||||
RootDynamicLibraries: []string{"foo.so"},
|
||||
},
|
||||
android.BuildMockBazelContextResultKey(label, arch64, android.Android, apexCfgKey): cquery.CcInfo{
|
||||
RootDynamicLibraries: []string{"foo.so"},
|
||||
},
|
||||
},
|
||||
BazelRequests: make(map[string]bool),
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
ctx := result.TestContext
|
||||
|
||||
// Test if the bazel request is queued correctly
|
||||
key := android.BuildMockBazelContextRequestKey(label, cquery.GetCcInfo, arch32, android.Android, apexCfgKey)
|
||||
if !ctx.Config().BazelContext.(android.MockBazelContext).BazelRequests[key] {
|
||||
t.Errorf("Bazel request was not queued: %s", key)
|
||||
}
|
||||
|
||||
sharedFoo := ctx.ModuleForTests(ccLibInApex, "android_arm_armv7-a-neon_shared_"+apexVariationName).Module()
|
||||
producer := sharedFoo.(android.OutputFileProducer)
|
||||
outputFiles, err := producer.OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{"outputbase/execroot/__main__/foo.so"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
}
|
||||
|
||||
func TestDisableSanitizerVariantsInMixedBuilds(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_library_static {
|
||||
name: "foo_ubsan_minimal",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo_ubsan_minimal" },
|
||||
sanitize: {
|
||||
all_undefined: true,
|
||||
integer_overflow: true,
|
||||
},
|
||||
}
|
||||
cc_library_static {
|
||||
name: "foo",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo" },
|
||||
sanitize: {
|
||||
address: true,
|
||||
hwaddress: true,
|
||||
fuzzer: true,
|
||||
integer_overflow: true,
|
||||
scs: true,
|
||||
},
|
||||
}
|
||||
cc_library_static {
|
||||
name: "foo_tsan",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo_tsan" },
|
||||
sanitize: {
|
||||
thread: true,
|
||||
},
|
||||
}
|
||||
cc_library_static {
|
||||
name: "foo_cfi",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo_cfi" },
|
||||
sanitize: {
|
||||
cfi: true,
|
||||
},
|
||||
}
|
||||
cc_library_static {
|
||||
name: "foo_memtag_stack",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo_memtag_stack" },
|
||||
sanitize: {
|
||||
memtag_stack: true,
|
||||
},
|
||||
}
|
||||
cc_library_static {
|
||||
name: "foo_memtag_heap",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo_memtag_heap" },
|
||||
sanitize: {
|
||||
memtag_heap: true,
|
||||
},
|
||||
}
|
||||
cc_library_static {
|
||||
name: "foo_safestack",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo_safestack" },
|
||||
sanitize: {
|
||||
safestack: true,
|
||||
},
|
||||
}
|
||||
cc_library_static {
|
||||
name: "foo_scudo",
|
||||
srcs: ["foo.cc"],
|
||||
bazel_module: { label: "//foo_scudo" },
|
||||
sanitize: {
|
||||
scudo: true,
|
||||
},
|
||||
}
|
||||
`
|
||||
testcases := []struct {
|
||||
name string
|
||||
variant string
|
||||
expectedOutputPaths []string
|
||||
}{
|
||||
{
|
||||
name: "foo_ubsan_minimal",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"outputbase/execroot/__main__/foo_ubsan_minimal.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"outputbase/execroot/__main__/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm_armv7-a-neon_static_asan_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm64_armv8-a_static_hwasan_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm64_armv8-a_static_fuzzer_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm64_armv8-a_static_fuzzer_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm_armv7-a-neon_static_asan_fuzzer_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm_armv7-a-neon_static_asan_fuzzer_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm64_armv8-a_static_hwasan_fuzzer_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_fuzzer_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm64_armv8-a_static_scs_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm64_armv8-a_static_scs_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm64_armv8-a_static_hwasan_scs_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo",
|
||||
variant: "android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo/android_arm64_armv8-a_static_hwasan_scs_fuzzer_apex28/foo.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_tsan",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"outputbase/execroot/__main__/foo_tsan.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_tsan",
|
||||
variant: "android_arm64_armv8-a_static_tsan_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo_tsan/android_arm64_armv8-a_static_tsan_apex28/foo_tsan.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_cfi",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"outputbase/execroot/__main__/foo_cfi.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_cfi",
|
||||
variant: "android_arm64_armv8-a_static_cfi_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"outputbase/execroot/__main__/foo_cfi.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_memtag_stack",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo_memtag_stack/android_arm64_armv8-a_static_apex28/foo_memtag_stack.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_memtag_heap",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo_memtag_heap/android_arm64_armv8-a_static_apex28/foo_memtag_heap.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_safestack",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo_safestack/android_arm64_armv8-a_static_apex28/foo_safestack.a",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "foo_scudo",
|
||||
variant: "android_arm64_armv8-a_static_apex28",
|
||||
expectedOutputPaths: []string{
|
||||
"out/soong/.intermediates/foo_scudo/android_arm64_armv8-a_static_apex28/foo_scudo.a",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := android.GroupFixturePreparers(
|
||||
prepareForCcTest,
|
||||
prepareForAsanTest,
|
||||
android.FixtureRegisterWithContext(registerTestMutators),
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "outputbase",
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo_ubsan_minimal": {
|
||||
RootStaticArchives: []string{"foo_ubsan_minimal.a"},
|
||||
},
|
||||
"//foo": {
|
||||
RootStaticArchives: []string{"foo.a"},
|
||||
},
|
||||
"//foo_tsan": {
|
||||
RootStaticArchives: []string{"foo_tsan.a"},
|
||||
},
|
||||
"//foo_cfi": {
|
||||
RootStaticArchives: []string{"foo_cfi.a"},
|
||||
},
|
||||
"//foo_memtag_stack": {
|
||||
RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
|
||||
},
|
||||
"//foo_memtag_heap": {
|
||||
RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
|
||||
},
|
||||
"//foo_safestack": {
|
||||
RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
|
||||
},
|
||||
"//foo_scudo": {
|
||||
RootStaticArchives: []string{"INVALID_ARCHIVE.a"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp).TestContext
|
||||
|
||||
for _, tc := range testcases {
|
||||
fooMod := ctx.ModuleForTests(tc.name, tc.variant).Module()
|
||||
outputFiles, err := fooMod.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
android.AssertPathsRelativeToTopEquals(t, "output files", tc.expectedOutputPaths, outputFiles)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -378,12 +378,6 @@ var (
|
|||
VisibilityDefaultFlag = "-fvisibility=default"
|
||||
)
|
||||
|
||||
// BazelCcToolchainVars generates bzl file content containing variables for
|
||||
// Bazel's cc_toolchain configuration.
|
||||
func BazelCcToolchainVars(config android.Config) string {
|
||||
return android.BazelToolchainVars(config, exportedVars)
|
||||
}
|
||||
|
||||
func ExportStringList(name string, value []string) {
|
||||
exportedVars.ExportStringList(name, value)
|
||||
}
|
||||
|
|
|
@ -16,10 +16,7 @@ package cc
|
|||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -32,7 +29,6 @@ func RegisterFdoProfileBuildComponents(ctx android.RegistrationContext) {
|
|||
|
||||
type fdoProfile struct {
|
||||
android.ModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
properties fdoProfileProperties
|
||||
}
|
||||
|
@ -41,50 +37,6 @@ type fdoProfileProperties struct {
|
|||
Profile *string `android:"arch_variant"`
|
||||
}
|
||||
|
||||
type bazelFdoProfileAttributes struct {
|
||||
Profile bazel.StringAttribute
|
||||
}
|
||||
|
||||
func (fp *fdoProfile) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
var profileAttr bazel.StringAttribute
|
||||
|
||||
archVariantProps := fp.GetArchVariantProperties(ctx, &fdoProfileProperties{})
|
||||
for axis, configToProps := range archVariantProps {
|
||||
for config, _props := range configToProps {
|
||||
if archProps, ok := _props.(*fdoProfileProperties); ok {
|
||||
if axis.String() == "arch" || axis.String() == "no_config" {
|
||||
if archProps.Profile != nil {
|
||||
profileAttr.SetSelectValue(axis, config, archProps.Profile)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ideally, cc_library_shared's fdo_profile attr can be a select statement so that we
|
||||
// don't lift the restriction here. However, in cc_library_shared macro, fdo_profile
|
||||
// is used as a string, we need to temporarily lift the host restriction until we can
|
||||
// pass use fdo_profile attr with select statement
|
||||
// https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/cc/cc_library_shared.bzl;l=127;drc=cc01bdfd39857eddbab04ef69ab6db22dcb1858a
|
||||
// TODO(b/276287371): Drop the restriction override after fdo_profile path is handled properly
|
||||
var noRestriction bazel.BoolAttribute
|
||||
noRestriction.SetSelectValue(bazel.NoConfigAxis, "", proptools.BoolPtr(true))
|
||||
|
||||
ctx.CreateBazelTargetModuleWithRestrictions(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Bzl_load_location: "//build/bazel/rules/fdo:fdo_profile.bzl",
|
||||
Rule_class: "fdo_profile",
|
||||
},
|
||||
android.CommonAttributes{
|
||||
Name: fp.Name(),
|
||||
},
|
||||
&bazelFdoProfileAttributes{
|
||||
Profile: profileAttr,
|
||||
},
|
||||
noRestriction,
|
||||
)
|
||||
}
|
||||
|
||||
// FdoProfileInfo is provided by FdoProfileProvider
|
||||
type FdoProfileInfo struct {
|
||||
Path android.Path
|
||||
|
@ -128,6 +80,5 @@ func FdoProfileFactory() android.Module {
|
|||
m := &fdoProfile{}
|
||||
m.AddProperties(&m.properties)
|
||||
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibBoth)
|
||||
android.InitBazelModule(m)
|
||||
return m
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ func PackageFuzzModule(ctx android.ModuleContext, fuzzPackagedModule fuzz.FuzzPa
|
|||
}
|
||||
|
||||
func NewFuzzer(hod android.HostOrDeviceSupported) *Module {
|
||||
module, binary := newBinary(hod, false)
|
||||
module, binary := newBinary(hod)
|
||||
baseInstallerPath := "fuzz"
|
||||
|
||||
binary.baseInstaller = NewBaseInstaller(baseInstallerPath, baseInstallerPath, InstallInData)
|
||||
|
|
67
cc/gen.go
67
cc/gen.go
|
@ -19,9 +19,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"android/soong/aidl_library"
|
||||
"android/soong/bazel"
|
||||
"android/soong/sysprop/bp2build"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
|
||||
"android/soong/android"
|
||||
|
@ -181,41 +178,6 @@ func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.Mod
|
|||
})
|
||||
}
|
||||
|
||||
type LexAttrs struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Lexopts bazel.StringListAttribute
|
||||
}
|
||||
|
||||
type LexNames struct {
|
||||
cSrcName bazel.LabelAttribute
|
||||
srcName bazel.LabelAttribute
|
||||
}
|
||||
|
||||
func bp2BuildLex(ctx android.Bp2buildMutatorContext, moduleName string, ca compilerAttributes) LexNames {
|
||||
names := LexNames{}
|
||||
if !ca.lSrcs.IsEmpty() {
|
||||
names.cSrcName = createLexTargetModule(ctx, moduleName+"_genlex_l", ca.lSrcs, ca.lexopts)
|
||||
}
|
||||
if !ca.llSrcs.IsEmpty() {
|
||||
names.srcName = createLexTargetModule(ctx, moduleName+"_genlex_ll", ca.llSrcs, ca.lexopts)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func createLexTargetModule(ctx android.Bp2buildMutatorContext, name string, srcs bazel.LabelListAttribute, opts bazel.StringListAttribute) bazel.LabelAttribute {
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "genlex",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:flex.bzl",
|
||||
},
|
||||
android.CommonAttributes{Name: name},
|
||||
&LexAttrs{
|
||||
Srcs: srcs,
|
||||
Lexopts: opts,
|
||||
})
|
||||
return bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + name}}
|
||||
}
|
||||
|
||||
func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Paths) {
|
||||
headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h")
|
||||
publicHeaderFile := android.PathForModuleGen(ctx, "sysprop/public", "include", syspropFile.Rel()+".h")
|
||||
|
@ -240,35 +202,6 @@ func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Pa
|
|||
return cppFile, headers.Paths()
|
||||
}
|
||||
|
||||
func bp2buildCcSysprop(ctx android.Bp2buildMutatorContext, moduleName string, minSdkVersion *string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
|
||||
labels := bp2build.SyspropLibraryLabels{
|
||||
SyspropLibraryLabel: moduleName + "_sysprop_library",
|
||||
CcStaticLibraryLabel: moduleName + "_cc_sysprop_library_static",
|
||||
}
|
||||
bp2build.Bp2buildBaseSyspropLibrary(ctx, labels.SyspropLibraryLabel, srcs)
|
||||
bp2build.Bp2buildSyspropCc(ctx, labels, minSdkVersion)
|
||||
return createLabelAttributeCorrespondingToSrcs(":"+labels.CcStaticLibraryLabel, srcs)
|
||||
}
|
||||
|
||||
// Creates a LabelAttribute for a given label where the value is only set for
|
||||
// the same config values that have values in a given LabelListAttribute
|
||||
func createLabelAttributeCorrespondingToSrcs(baseLabelName string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
|
||||
baseLabel := bazel.Label{Label: baseLabelName}
|
||||
label := bazel.LabelAttribute{}
|
||||
if !srcs.Value.IsNil() && !srcs.Value.IsEmpty() {
|
||||
label.Value = &baseLabel
|
||||
return &label
|
||||
}
|
||||
for axis, configToSrcs := range srcs.ConfigurableValues {
|
||||
for config, val := range configToSrcs {
|
||||
if !val.IsNil() && !val.IsEmpty() {
|
||||
label.SetSelectValue(axis, config, baseLabel)
|
||||
}
|
||||
}
|
||||
}
|
||||
return &label
|
||||
}
|
||||
|
||||
// Used to communicate information from the genSources method back to the library code that uses
|
||||
// it.
|
||||
type generatedSourceInfo struct {
|
||||
|
|
|
@ -28,9 +28,6 @@ func GeneratedCcLibraryModuleFactory(moduleName string, callbacks Generator) and
|
|||
staticAndSharedLibrarySdkMemberType,
|
||||
}
|
||||
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||
|
||||
module.generators = append(module.generators, callbacks)
|
||||
|
||||
return module.Init()
|
||||
|
|
|
@ -62,7 +62,6 @@ func GenRuleFactory() android.Module {
|
|||
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth)
|
||||
|
||||
android.InitApexModule(module)
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
|
763
cc/library.go
763
cc/library.go
|
@ -24,28 +24,11 @@ import (
|
|||
"sync"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/pathtools"
|
||||
"github.com/google/blueprint/proptools"
|
||||
)
|
||||
|
||||
var (
|
||||
alwaysLinkLibraries = map[string]bool{
|
||||
// Coverage libraries are _always_ added as a whole_static_dep. By converting as these as
|
||||
// alwayslink = True, we can add these as to deps (e.g. as a regular static dep) in Bazel
|
||||
// without any extra complications in cc_shared_library roots to prevent linking the same
|
||||
// library repeatedly.
|
||||
"libprofile-extras_ndk": true,
|
||||
"libprofile-extras": true,
|
||||
"libprofile-clang-extras_ndk": true,
|
||||
"libprofile-clang-extras_cfi_support": true,
|
||||
"libprofile-clang-extras": true,
|
||||
}
|
||||
)
|
||||
|
||||
// LibraryProperties is a collection of properties shared by cc library rules/cc.
|
||||
type LibraryProperties struct {
|
||||
// local file name to pass to the linker as -unexported_symbols_list
|
||||
|
@ -235,336 +218,6 @@ func RegisterLibraryBuildComponents(ctx android.RegistrationContext) {
|
|||
ctx.RegisterModuleType("cc_library_host_shared", LibraryHostSharedFactory)
|
||||
}
|
||||
|
||||
// TODO(b/199902614): Can this be factored to share with the other Attributes?
|
||||
// For bp2build conversion.
|
||||
type bazelCcLibraryAttributes struct {
|
||||
// Attributes pertaining to both static and shared variants.
|
||||
Srcs bazel.LabelListAttribute
|
||||
Srcs_c bazel.LabelListAttribute
|
||||
Srcs_as bazel.LabelListAttribute
|
||||
|
||||
Copts bazel.StringListAttribute
|
||||
Cppflags bazel.StringListAttribute
|
||||
Conlyflags bazel.StringListAttribute
|
||||
Asflags bazel.StringListAttribute
|
||||
|
||||
Hdrs bazel.LabelListAttribute
|
||||
|
||||
Deps bazel.LabelListAttribute
|
||||
Implementation_deps bazel.LabelListAttribute
|
||||
Dynamic_deps bazel.LabelListAttribute
|
||||
Implementation_dynamic_deps bazel.LabelListAttribute
|
||||
Whole_archive_deps bazel.LabelListAttribute
|
||||
Implementation_whole_archive_deps bazel.LabelListAttribute
|
||||
System_dynamic_deps bazel.LabelListAttribute
|
||||
|
||||
Export_includes bazel.StringListAttribute
|
||||
Export_system_includes bazel.StringListAttribute
|
||||
Local_includes bazel.StringListAttribute
|
||||
Absolute_includes bazel.StringListAttribute
|
||||
Linkopts bazel.StringListAttribute
|
||||
Rtti bazel.BoolAttribute
|
||||
|
||||
Stl *string
|
||||
Cpp_std *string
|
||||
C_std *string
|
||||
|
||||
// This is shared only.
|
||||
Additional_linker_inputs bazel.LabelListAttribute
|
||||
|
||||
// Common properties shared between both shared and static variants.
|
||||
Shared staticOrSharedAttributes
|
||||
Static staticOrSharedAttributes
|
||||
|
||||
Strip stripAttributes
|
||||
|
||||
Features bazel.StringListAttribute
|
||||
}
|
||||
|
||||
type aidlLibraryAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Include_dir *string
|
||||
Tags bazel.StringListAttribute
|
||||
}
|
||||
|
||||
type ccAidlLibraryAttributes struct {
|
||||
Deps bazel.LabelListAttribute
|
||||
Implementation_deps bazel.LabelListAttribute
|
||||
Implementation_dynamic_deps bazel.LabelListAttribute
|
||||
Tags bazel.StringListAttribute
|
||||
|
||||
SdkAttributes
|
||||
includesAttributes
|
||||
}
|
||||
|
||||
type stripAttributes struct {
|
||||
Keep_symbols bazel.BoolAttribute
|
||||
Keep_symbols_and_debug_frame bazel.BoolAttribute
|
||||
Keep_symbols_list bazel.StringListAttribute
|
||||
All bazel.BoolAttribute
|
||||
None bazel.BoolAttribute
|
||||
}
|
||||
|
||||
func stripAttrsFromLinkerAttrs(la *linkerAttributes) stripAttributes {
|
||||
return stripAttributes{
|
||||
Keep_symbols: la.stripKeepSymbols,
|
||||
Keep_symbols_and_debug_frame: la.stripKeepSymbolsAndDebugFrame,
|
||||
Keep_symbols_list: la.stripKeepSymbolsList,
|
||||
All: la.stripAll,
|
||||
None: la.stripNone,
|
||||
}
|
||||
}
|
||||
|
||||
func libraryBp2Build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||
sharedAttrs := bp2BuildParseSharedProps(ctx, m)
|
||||
staticAttrs := bp2BuildParseStaticProps(ctx, m)
|
||||
baseAttributes := bp2BuildParseBaseProps(ctx, m)
|
||||
compilerAttrs := baseAttributes.compilerAttributes
|
||||
linkerAttrs := baseAttributes.linkerAttributes
|
||||
exportedIncludes := bp2BuildParseExportedIncludes(ctx, m, &compilerAttrs.includes)
|
||||
|
||||
srcs := compilerAttrs.srcs
|
||||
|
||||
sharedAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
|
||||
staticAttrs.Deps.Add(baseAttributes.protoDependency)
|
||||
|
||||
asFlags := compilerAttrs.asFlags
|
||||
if compilerAttrs.asSrcs.IsEmpty() && sharedAttrs.Srcs_as.IsEmpty() && staticAttrs.Srcs_as.IsEmpty() {
|
||||
// Skip asflags for BUILD file simplicity if there are no assembly sources.
|
||||
asFlags = bazel.MakeStringListAttribute(nil)
|
||||
}
|
||||
|
||||
sharedFeatures := baseAttributes.features.Clone().Append(sharedAttrs.Features)
|
||||
sharedFeatures.DeduplicateAxesFromBase()
|
||||
staticFeatures := baseAttributes.features.Clone().Append(staticAttrs.Features)
|
||||
staticFeatures.DeduplicateAxesFromBase()
|
||||
|
||||
staticCommonAttrs := staticOrSharedAttributes{
|
||||
Srcs: *srcs.Clone().Append(staticAttrs.Srcs),
|
||||
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(staticAttrs.Srcs_c),
|
||||
Srcs_as: *compilerAttrs.asSrcs.Clone().Append(staticAttrs.Srcs_as),
|
||||
Copts: *compilerAttrs.copts.Clone().Append(staticAttrs.Copts),
|
||||
Hdrs: *compilerAttrs.hdrs.Clone().Append(staticAttrs.Hdrs),
|
||||
|
||||
Deps: *linkerAttrs.deps.Clone().Append(staticAttrs.Deps),
|
||||
Implementation_deps: *linkerAttrs.implementationDeps.Clone().Append(staticAttrs.Implementation_deps),
|
||||
Dynamic_deps: *linkerAttrs.dynamicDeps.Clone().Append(staticAttrs.Dynamic_deps),
|
||||
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(staticAttrs.Implementation_dynamic_deps),
|
||||
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
||||
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(staticAttrs.Whole_archive_deps),
|
||||
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(staticAttrs.System_dynamic_deps),
|
||||
Runtime_deps: linkerAttrs.runtimeDeps,
|
||||
SdkAttributes: Bp2BuildParseSdkAttributes(m),
|
||||
Native_coverage: baseAttributes.Native_coverage,
|
||||
Additional_compiler_inputs: compilerAttrs.additionalCompilerInputs,
|
||||
}
|
||||
|
||||
includeAttrs := includesAttributes{
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
Local_includes: compilerAttrs.localIncludes,
|
||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||
}
|
||||
|
||||
sharedCommonAttrs := staticOrSharedAttributes{
|
||||
Srcs: *srcs.Clone().Append(sharedAttrs.Srcs),
|
||||
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(sharedAttrs.Srcs_c),
|
||||
Srcs_as: *compilerAttrs.asSrcs.Clone().Append(sharedAttrs.Srcs_as),
|
||||
Copts: *compilerAttrs.copts.Clone().Append(sharedAttrs.Copts),
|
||||
Hdrs: *compilerAttrs.hdrs.Clone().Append(sharedAttrs.Hdrs),
|
||||
|
||||
Deps: *linkerAttrs.deps.Clone().Append(sharedAttrs.Deps),
|
||||
Implementation_deps: *linkerAttrs.implementationDeps.Clone().Append(sharedAttrs.Implementation_deps),
|
||||
Dynamic_deps: *linkerAttrs.dynamicDeps.Clone().Append(sharedAttrs.Dynamic_deps),
|
||||
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(sharedAttrs.Implementation_dynamic_deps),
|
||||
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(sharedAttrs.Whole_archive_deps),
|
||||
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
||||
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(sharedAttrs.System_dynamic_deps),
|
||||
Runtime_deps: linkerAttrs.runtimeDeps,
|
||||
SdkAttributes: Bp2BuildParseSdkAttributes(m),
|
||||
Native_coverage: baseAttributes.Native_coverage,
|
||||
Additional_compiler_inputs: compilerAttrs.additionalCompilerInputs,
|
||||
}
|
||||
|
||||
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
|
||||
staticOrSharedAttributes: staticCommonAttrs,
|
||||
includesAttributes: includeAttrs,
|
||||
|
||||
Cppflags: compilerAttrs.cppFlags,
|
||||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
|
||||
Features: *staticFeatures,
|
||||
}
|
||||
|
||||
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
|
||||
staticOrSharedAttributes: sharedCommonAttrs,
|
||||
includesAttributes: includeAttrs,
|
||||
|
||||
Cppflags: compilerAttrs.cppFlags,
|
||||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Linkopts: linkerAttrs.linkopts,
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
Use_version_lib: linkerAttrs.useVersionLib,
|
||||
|
||||
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
||||
|
||||
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
||||
Features: *sharedFeatures,
|
||||
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, m),
|
||||
|
||||
Fdo_profile: compilerAttrs.fdoProfile,
|
||||
}
|
||||
|
||||
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
||||
sharedTargetAttrs.Stubs_symbol_file = compilerAttrs.stubsSymbolFile
|
||||
}
|
||||
|
||||
sharedTargetAttrs.Stem = compilerAttrs.stem
|
||||
sharedTargetAttrs.Suffix = compilerAttrs.suffix
|
||||
|
||||
for axis, configToProps := range m.GetArchVariantProperties(ctx, &LibraryProperties{}) {
|
||||
for cfg, props := range configToProps {
|
||||
if props, ok := props.(*LibraryProperties); ok {
|
||||
if props.Inject_bssl_hash != nil {
|
||||
// This is an edge case applies only to libcrypto
|
||||
if m.Name() == "libcrypto" || m.Name() == "libcrypto_for_testing" {
|
||||
sharedTargetAttrs.Inject_bssl_hash.SetSelectValue(axis, cfg, props.Inject_bssl_hash)
|
||||
} else {
|
||||
ctx.PropertyErrorf("inject_bssl_hash", "only applies to libcrypto")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
staticProps := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_library_static",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_library_static.bzl",
|
||||
}
|
||||
sharedProps := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_library_shared",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_library_shared.bzl",
|
||||
}
|
||||
|
||||
if _, ok := alwaysLinkLibraries[m.Name()]; ok {
|
||||
staticTargetAttrs.Alwayslink = proptools.BoolPtr(true)
|
||||
}
|
||||
|
||||
var tagsForStaticVariant bazel.StringListAttribute
|
||||
if compilerAttrs.stubsSymbolFile == nil && len(compilerAttrs.stubsVersions.Value) == 0 {
|
||||
tagsForStaticVariant = android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||
}
|
||||
tagsForStaticVariant.Append(bazel.StringListAttribute{Value: staticAttrs.Apex_available})
|
||||
|
||||
tagsForSharedVariant := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||
tagsForSharedVariant.Append(bazel.StringListAttribute{Value: sharedAttrs.Apex_available})
|
||||
|
||||
ctx.CreateBazelTargetModuleWithRestrictions(staticProps,
|
||||
android.CommonAttributes{
|
||||
Name: m.Name() + "_bp2build_cc_library_static",
|
||||
Tags: tagsForStaticVariant,
|
||||
// TODO: b/303307456 - Remove this when data is properly supported in cc rules.
|
||||
SkipData: proptools.BoolPtr(true),
|
||||
},
|
||||
staticTargetAttrs, staticAttrs.Enabled)
|
||||
ctx.CreateBazelTargetModuleWithRestrictions(sharedProps,
|
||||
android.CommonAttributes{
|
||||
Name: m.Name(),
|
||||
Tags: tagsForSharedVariant,
|
||||
// TODO: b/303307456 - Remove this when data is properly supported in cc rules.
|
||||
SkipData: proptools.BoolPtr(true),
|
||||
},
|
||||
sharedTargetAttrs, sharedAttrs.Enabled)
|
||||
|
||||
createStubsBazelTargetIfNeeded(ctx, m, compilerAttrs, exportedIncludes, baseAttributes)
|
||||
}
|
||||
|
||||
func createStubsBazelTargetIfNeeded(ctx android.Bp2buildMutatorContext, m *Module, compilerAttrs compilerAttributes, exportedIncludes BazelIncludes, baseAttributes baseAttributes) {
|
||||
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
||||
stubSuitesProps := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_stub_suite",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_stub_library.bzl",
|
||||
}
|
||||
soname := m.Name() + ".so"
|
||||
stubSuitesAttrs := &bazelCcStubSuiteAttributes{
|
||||
Symbol_file: compilerAttrs.stubsSymbolFile,
|
||||
Versions: compilerAttrs.stubsVersions,
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Soname: &soname,
|
||||
Source_library_label: proptools.StringPtr(m.GetBazelLabel(ctx, m)),
|
||||
Deps: baseAttributes.deps,
|
||||
Api_surface: proptools.StringPtr("module-libapi"),
|
||||
}
|
||||
if _, isNdk := ctx.ModuleFromName(m.Name() + ".ndk"); isNdk {
|
||||
stubSuitesAttrs.Included_in_ndk = proptools.BoolPtr(true)
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(stubSuitesProps, android.CommonAttributes{
|
||||
Name: m.Name() + "_stub_libs",
|
||||
// TODO: b/303307456 - Remove this when data is properly supported in cc rules.
|
||||
SkipData: proptools.BoolPtr(true),
|
||||
},
|
||||
stubSuitesAttrs)
|
||||
|
||||
// Add alias for the stub shared_library in @api_surfaces repository
|
||||
currentModuleLibApiDir := ctx.Config().ApiSurfacesDir(android.ModuleLibApi, "current")
|
||||
actualLabelInMainWorkspace := bazel.Label{
|
||||
Label: fmt.Sprintf("@//%s:%s%s", ctx.ModuleDir(), m.Name(), stubsSuffix),
|
||||
}
|
||||
ctx.CreateBazelTargetAliasInDir(currentModuleLibApiDir, m.Name(), actualLabelInMainWorkspace)
|
||||
|
||||
// Add alias for headers exported by the stub library
|
||||
headerLabelInMainWorkspace := bazel.Label{
|
||||
// This label is generated from cc_stub_suite macro
|
||||
Label: fmt.Sprintf("@//%s:%s_stub_libs_%s_headers", ctx.ModuleDir(), m.Name(), android.ModuleLibApi.String()),
|
||||
}
|
||||
headerAlias := m.Name() + "_headers"
|
||||
ctx.CreateBazelTargetAliasInDir(currentModuleLibApiDir, headerAlias, headerLabelInMainWorkspace)
|
||||
}
|
||||
}
|
||||
|
||||
// wrapper struct to flatten the arch and os specific export_include_dirs
|
||||
// flattening is necessary since we want to export apis of all arches even when we build for x86 (e.g.)
|
||||
type bazelCcApiLibraryHeadersAttributes struct {
|
||||
bazelCcLibraryHeadersAttributes
|
||||
|
||||
Arch *string
|
||||
}
|
||||
|
||||
func (a *bazelCcApiLibraryHeadersAttributes) isEmpty() bool {
|
||||
return a.Export_includes.IsEmpty() &&
|
||||
a.Export_system_includes.IsEmpty() &&
|
||||
a.Deps.IsEmpty()
|
||||
}
|
||||
|
||||
type apiIncludes struct {
|
||||
name string // name of the Bazel target in the generated bp2build workspace
|
||||
attrs bazelCcApiLibraryHeadersAttributes
|
||||
}
|
||||
|
||||
func (includes *apiIncludes) isEmpty() bool {
|
||||
return includes.attrs.isEmpty()
|
||||
}
|
||||
|
||||
func (includes *apiIncludes) addDep(name string) {
|
||||
l := bazel.Label{Label: ":" + name}
|
||||
ll := bazel.MakeLabelList([]bazel.Label{l})
|
||||
lla := bazel.MakeLabelListAttribute(ll)
|
||||
includes.attrs.Deps.Append(lla)
|
||||
}
|
||||
|
||||
// cc_library creates both static and/or shared libraries for a device and/or
|
||||
// host. By default, a cc_library has a single variant that targets the device.
|
||||
// Specifying `host_supported: true` also creates a library that targets the
|
||||
|
@ -577,8 +230,6 @@ func LibraryFactory() android.Module {
|
|||
staticLibrarySdkMemberType,
|
||||
staticAndSharedLibrarySdkMemberType,
|
||||
}
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -587,8 +238,6 @@ func LibraryStaticFactory() android.Module {
|
|||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.BuildOnlyStatic()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -597,8 +246,6 @@ func LibrarySharedFactory() android.Module {
|
|||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.BuildOnlyShared()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -608,8 +255,6 @@ func LibraryHostStaticFactory() android.Module {
|
|||
module, library := NewLibrary(android.HostSupported)
|
||||
library.BuildOnlyStatic()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{staticLibrarySdkMemberType}
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -618,8 +263,6 @@ func LibraryHostSharedFactory() android.Module {
|
|||
module, library := NewLibrary(android.HostSupported)
|
||||
library.BuildOnlyShared()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{sharedLibrarySdkMemberType}
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@ -782,145 +425,6 @@ type libraryDecorator struct {
|
|||
apiListCoverageXmlPath android.ModuleOutPath
|
||||
}
|
||||
|
||||
type ccLibraryBazelHandler struct {
|
||||
module *Module
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*ccLibraryBazelHandler)(nil)
|
||||
|
||||
// generateStaticBazelBuildActions constructs the StaticLibraryInfo Soong
|
||||
// provider from a Bazel shared library's CcInfo provider.
|
||||
func (handler *ccLibraryBazelHandler) generateStaticBazelBuildActions(ctx android.ModuleContext, label string, ccInfo cquery.CcInfo) {
|
||||
rootStaticArchives := ccInfo.RootStaticArchives
|
||||
if len(rootStaticArchives) != 1 {
|
||||
ctx.ModuleErrorf("expected exactly one root archive file for '%s', but got %s", label, rootStaticArchives)
|
||||
return
|
||||
}
|
||||
var outputFilePath android.Path = android.PathForBazelOut(ctx, rootStaticArchives[0])
|
||||
if len(ccInfo.TidyFiles) > 0 {
|
||||
handler.module.tidyFiles = android.PathsForBazelOut(ctx, ccInfo.TidyFiles)
|
||||
outputFilePath = android.AttachValidationActions(ctx, outputFilePath, handler.module.tidyFiles)
|
||||
}
|
||||
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
|
||||
|
||||
objPaths := ccInfo.CcObjectFiles
|
||||
objFiles := make(android.Paths, len(objPaths))
|
||||
for i, objPath := range objPaths {
|
||||
objFiles[i] = android.PathForBazelOut(ctx, objPath)
|
||||
}
|
||||
objects := Objects{
|
||||
objFiles: objFiles,
|
||||
}
|
||||
|
||||
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
||||
StaticLibrary: outputFilePath,
|
||||
ReuseObjects: objects,
|
||||
Objects: objects,
|
||||
|
||||
// TODO(b/190524881): Include transitive static libraries in this provider to support
|
||||
// static libraries with deps.
|
||||
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).
|
||||
Direct(outputFilePath).
|
||||
Build(),
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// generateSharedBazelBuildActions constructs the SharedLibraryInfo Soong
|
||||
// provider from a Bazel shared library's CcInfo provider.
|
||||
func (handler *ccLibraryBazelHandler) generateSharedBazelBuildActions(ctx android.ModuleContext, label string, ccInfo cquery.CcInfo) {
|
||||
rootDynamicLibraries := ccInfo.RootDynamicLibraries
|
||||
|
||||
if len(rootDynamicLibraries) != 1 {
|
||||
ctx.ModuleErrorf("expected exactly one root dynamic library file for '%s', but got %s", label, rootDynamicLibraries)
|
||||
return
|
||||
}
|
||||
var outputFilePath android.Path = android.PathForBazelOut(ctx, rootDynamicLibraries[0])
|
||||
if len(ccInfo.TidyFiles) > 0 {
|
||||
handler.module.tidyFiles = android.PathsForBazelOut(ctx, ccInfo.TidyFiles)
|
||||
outputFilePath = android.AttachValidationActions(ctx, outputFilePath, handler.module.tidyFiles)
|
||||
}
|
||||
|
||||
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
|
||||
handler.module.linker.(*libraryDecorator).unstrippedOutputFile = android.PathForBazelOut(ctx, ccInfo.UnstrippedOutput)
|
||||
|
||||
var tocFile android.OptionalPath
|
||||
if len(ccInfo.TocFile) > 0 {
|
||||
tocFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, ccInfo.TocFile))
|
||||
}
|
||||
handler.module.linker.(*libraryDecorator).tocFile = tocFile
|
||||
|
||||
if len(ccInfo.AbiDiffFiles) > 0 {
|
||||
handler.module.linker.(*libraryDecorator).sAbiDiff = android.PathsForBazelOut(ctx, ccInfo.AbiDiffFiles)
|
||||
}
|
||||
|
||||
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
|
||||
TableOfContents: tocFile,
|
||||
SharedLibrary: outputFilePath,
|
||||
Target: ctx.Target(),
|
||||
// TODO(b/190524881): Include transitive static libraries in this provider to support
|
||||
// static libraries with deps. The provider key for this is TransitiveStaticLibrariesForOrdering.
|
||||
})
|
||||
}
|
||||
|
||||
func (handler *ccLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
if v := handler.module.library.stubsVersion(); v != "" {
|
||||
stubsLabel := label + "_stub_libs-" + v
|
||||
bazelCtx.QueueBazelRequest(stubsLabel, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
if v := handler.module.library.stubsVersion(); v != "" {
|
||||
// if we are a stubs variant, just use the Bazel stubs target
|
||||
label = label + "_stub_libs-" + v
|
||||
}
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if handler.module.static() {
|
||||
handler.generateStaticBazelBuildActions(ctx, label, ccInfo)
|
||||
} else if handler.module.Shared() {
|
||||
handler.generateSharedBazelBuildActions(ctx, label, ccInfo)
|
||||
} else {
|
||||
ctx.ModuleErrorf("Unhandled bazel case for %s (neither shared nor static!)", ctx.ModuleName())
|
||||
}
|
||||
|
||||
handler.module.linker.(*libraryDecorator).setFlagExporterInfoFromCcInfo(ctx, ccInfo)
|
||||
handler.module.maybeUnhideFromMake()
|
||||
|
||||
if i, ok := handler.module.linker.(snapshotLibraryInterface); ok {
|
||||
// Dependencies on this library will expect collectedSnapshotHeaders to
|
||||
// be set, otherwise validation will fail. For now, set this to an empty
|
||||
// list.
|
||||
// TODO(b/190533363): More closely mirror the collectHeadersForSnapshot
|
||||
// implementation.
|
||||
i.(*libraryDecorator).collectedSnapshotHeaders = android.Paths{}
|
||||
}
|
||||
|
||||
handler.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo)
|
||||
|
||||
cctx := moduleContextFromAndroidModuleContext(ctx, handler.module)
|
||||
addStubDependencyProviders(cctx)
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) setFlagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) {
|
||||
flagExporterInfo := flagExporterInfoFromCcInfo(ctx, ccInfo)
|
||||
// flag exporters consolidates properties like includes, flags, dependencies that should be
|
||||
// exported from this module to other modules
|
||||
ctx.SetProvider(FlagExporterInfoProvider, flagExporterInfo)
|
||||
// Store flag info to be passed along to androidmk
|
||||
// TODO(b/184387147): Androidmk should be done in Bazel, not Soong.
|
||||
library.flagExporterInfo = &flagExporterInfo
|
||||
}
|
||||
|
||||
func GlobHeadersForSnapshot(ctx android.ModuleContext, paths android.Paths) android.Paths {
|
||||
ret := android.Paths{}
|
||||
|
||||
|
@ -935,11 +439,6 @@ func GlobHeadersForSnapshot(ctx android.ModuleContext, paths android.Paths) andr
|
|||
continue
|
||||
}
|
||||
|
||||
// Filter out the generated headers from bazel.
|
||||
if strings.HasPrefix(dir, android.PathForBazelOut(ctx, "bazel-out").String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
// libeigen wrongly exports the root directory "external/eigen". But only two
|
||||
// subdirectories "Eigen" and "unsupported" contain exported header files. Even worse
|
||||
// some of them have no extension. So we need special treatment for libeigen in order
|
||||
|
@ -2621,7 +2120,7 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
|
|||
// normalizeVersions modifies `versions` in place, so that each raw version
|
||||
// string becomes its normalized canonical form.
|
||||
// Validates that the versions in `versions` are specified in least to greatest order.
|
||||
func normalizeVersions(ctx android.BazelConversionPathContext, versions []string) {
|
||||
func normalizeVersions(ctx android.BaseModuleContext, versions []string) {
|
||||
var previous android.ApiLevel
|
||||
for i, v := range versions {
|
||||
ver, err := android.ApiLevelFromUser(ctx, v)
|
||||
|
@ -2792,263 +2291,3 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu
|
|||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
func bp2buildParseAbiCheckerProps(ctx android.Bp2buildMutatorContext, module *Module) bazelCcHeaderAbiCheckerAttributes {
|
||||
lib, ok := module.linker.(*libraryDecorator)
|
||||
if !ok {
|
||||
return bazelCcHeaderAbiCheckerAttributes{}
|
||||
}
|
||||
|
||||
abiChecker := lib.getHeaderAbiCheckerProperties(ctx)
|
||||
|
||||
abiCheckerAttrs := bazelCcHeaderAbiCheckerAttributes{
|
||||
Abi_checker_enabled: abiChecker.Enabled,
|
||||
Abi_checker_exclude_symbol_versions: abiChecker.Exclude_symbol_versions,
|
||||
Abi_checker_exclude_symbol_tags: abiChecker.Exclude_symbol_tags,
|
||||
Abi_checker_check_all_apis: abiChecker.Check_all_apis,
|
||||
Abi_checker_diff_flags: abiChecker.Diff_flags,
|
||||
}
|
||||
if abiChecker.Symbol_file != nil {
|
||||
symbolFile := android.BazelLabelForModuleSrcSingle(ctx, *abiChecker.Symbol_file)
|
||||
abiCheckerAttrs.Abi_checker_symbol_file = &symbolFile
|
||||
}
|
||||
|
||||
return abiCheckerAttrs
|
||||
}
|
||||
|
||||
func sharedOrStaticLibraryBp2Build(ctx android.Bp2buildMutatorContext, module *Module, isStatic bool) {
|
||||
baseAttributes := bp2BuildParseBaseProps(ctx, module)
|
||||
compilerAttrs := baseAttributes.compilerAttributes
|
||||
linkerAttrs := baseAttributes.linkerAttributes
|
||||
|
||||
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, &compilerAttrs.includes)
|
||||
includeAttrs := includesAttributes{
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
Local_includes: compilerAttrs.localIncludes,
|
||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||
}
|
||||
|
||||
// Append shared/static{} stanza properties. These won't be specified on
|
||||
// cc_library_* itself, but may be specified in cc_defaults that this module
|
||||
// depends on.
|
||||
libSharedOrStaticAttrs := bp2BuildParseLibProps(ctx, module, isStatic)
|
||||
|
||||
compilerAttrs.srcs.Append(libSharedOrStaticAttrs.Srcs)
|
||||
compilerAttrs.cSrcs.Append(libSharedOrStaticAttrs.Srcs_c)
|
||||
compilerAttrs.asSrcs.Append(libSharedOrStaticAttrs.Srcs_as)
|
||||
compilerAttrs.copts.Append(libSharedOrStaticAttrs.Copts)
|
||||
|
||||
linkerAttrs.deps.Append(libSharedOrStaticAttrs.Deps)
|
||||
linkerAttrs.implementationDeps.Append(libSharedOrStaticAttrs.Implementation_deps)
|
||||
linkerAttrs.dynamicDeps.Append(libSharedOrStaticAttrs.Dynamic_deps)
|
||||
linkerAttrs.implementationDynamicDeps.Append(libSharedOrStaticAttrs.Implementation_dynamic_deps)
|
||||
linkerAttrs.systemDynamicDeps.Append(libSharedOrStaticAttrs.System_dynamic_deps)
|
||||
|
||||
asFlags := compilerAttrs.asFlags
|
||||
if compilerAttrs.asSrcs.IsEmpty() {
|
||||
// Skip asflags for BUILD file simplicity if there are no assembly sources.
|
||||
asFlags = bazel.MakeStringListAttribute(nil)
|
||||
}
|
||||
|
||||
features := baseAttributes.features.Clone().Append(libSharedOrStaticAttrs.Features)
|
||||
features.DeduplicateAxesFromBase()
|
||||
|
||||
commonAttrs := staticOrSharedAttributes{
|
||||
Srcs: compilerAttrs.srcs,
|
||||
Srcs_c: compilerAttrs.cSrcs,
|
||||
Srcs_as: compilerAttrs.asSrcs,
|
||||
Copts: compilerAttrs.copts,
|
||||
Hdrs: compilerAttrs.hdrs,
|
||||
|
||||
Deps: linkerAttrs.deps,
|
||||
Implementation_deps: linkerAttrs.implementationDeps,
|
||||
Dynamic_deps: linkerAttrs.dynamicDeps,
|
||||
Implementation_dynamic_deps: linkerAttrs.implementationDynamicDeps,
|
||||
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
|
||||
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
|
||||
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
|
||||
SdkAttributes: Bp2BuildParseSdkAttributes(module),
|
||||
Runtime_deps: linkerAttrs.runtimeDeps,
|
||||
Native_coverage: baseAttributes.Native_coverage,
|
||||
Additional_compiler_inputs: compilerAttrs.additionalCompilerInputs,
|
||||
}
|
||||
|
||||
module.convertTidyAttributes(ctx, &commonAttrs.tidyAttributes)
|
||||
|
||||
var attrs interface{}
|
||||
if isStatic {
|
||||
commonAttrs.Deps.Add(baseAttributes.protoDependency)
|
||||
var alwayslink *bool
|
||||
if _, ok := alwaysLinkLibraries[module.Name()]; ok && isStatic {
|
||||
alwayslink = proptools.BoolPtr(true)
|
||||
}
|
||||
attrs = &bazelCcLibraryStaticAttributes{
|
||||
staticOrSharedAttributes: commonAttrs,
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
|
||||
includesAttributes: includeAttrs,
|
||||
|
||||
Cppflags: compilerAttrs.cppFlags,
|
||||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Alwayslink: alwayslink,
|
||||
Features: *features,
|
||||
}
|
||||
|
||||
} else {
|
||||
commonAttrs.Dynamic_deps.Add(baseAttributes.protoDependency)
|
||||
|
||||
sharedLibAttrs := &bazelCcLibrarySharedAttributes{
|
||||
staticOrSharedAttributes: commonAttrs,
|
||||
|
||||
Cppflags: compilerAttrs.cppFlags,
|
||||
Conlyflags: compilerAttrs.conlyFlags,
|
||||
Asflags: asFlags,
|
||||
|
||||
Linkopts: linkerAttrs.linkopts,
|
||||
Use_version_lib: linkerAttrs.useVersionLib,
|
||||
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
|
||||
includesAttributes: includeAttrs,
|
||||
|
||||
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
||||
|
||||
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
||||
|
||||
Features: *features,
|
||||
|
||||
Stem: compilerAttrs.stem,
|
||||
Suffix: compilerAttrs.suffix,
|
||||
|
||||
bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, module),
|
||||
|
||||
Fdo_profile: compilerAttrs.fdoProfile,
|
||||
}
|
||||
if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
|
||||
sharedLibAttrs.Stubs_symbol_file = compilerAttrs.stubsSymbolFile
|
||||
}
|
||||
attrs = sharedLibAttrs
|
||||
}
|
||||
|
||||
var modType string
|
||||
if isStatic {
|
||||
modType = "cc_library_static"
|
||||
} else {
|
||||
modType = "cc_library_shared"
|
||||
createStubsBazelTargetIfNeeded(ctx, module, compilerAttrs, exportedIncludes, baseAttributes)
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: modType,
|
||||
Bzl_load_location: fmt.Sprintf("//build/bazel/rules/cc:%s.bzl", modType),
|
||||
}
|
||||
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
||||
Name: module.Name(),
|
||||
Tags: tags,
|
||||
// TODO: b/303307456 - Remove this when data is properly supported in cc rules.
|
||||
SkipData: proptools.BoolPtr(true),
|
||||
}, attrs)
|
||||
}
|
||||
|
||||
type includesAttributes struct {
|
||||
Export_includes bazel.StringListAttribute
|
||||
Export_absolute_includes bazel.StringListAttribute
|
||||
Export_system_includes bazel.StringListAttribute
|
||||
Local_includes bazel.StringListAttribute
|
||||
Absolute_includes bazel.StringListAttribute
|
||||
}
|
||||
|
||||
// TODO(b/199902614): Can this be factored to share with the other Attributes?
|
||||
type bazelCcLibraryStaticAttributes struct {
|
||||
staticOrSharedAttributes
|
||||
includesAttributes
|
||||
|
||||
Use_version_lib bazel.BoolAttribute
|
||||
Rtti bazel.BoolAttribute
|
||||
Stl *string
|
||||
Cpp_std *string
|
||||
C_std *string
|
||||
|
||||
Hdrs bazel.LabelListAttribute
|
||||
|
||||
Cppflags bazel.StringListAttribute
|
||||
Conlyflags bazel.StringListAttribute
|
||||
Asflags bazel.StringListAttribute
|
||||
|
||||
Alwayslink *bool
|
||||
Features bazel.StringListAttribute
|
||||
}
|
||||
|
||||
// TODO(b/199902614): Can this be factored to share with the other Attributes?
|
||||
type bazelCcLibrarySharedAttributes struct {
|
||||
staticOrSharedAttributes
|
||||
includesAttributes
|
||||
|
||||
Linkopts bazel.StringListAttribute
|
||||
Use_version_lib bazel.BoolAttribute
|
||||
|
||||
Rtti bazel.BoolAttribute
|
||||
Stl *string
|
||||
Cpp_std *string
|
||||
C_std *string
|
||||
|
||||
Hdrs bazel.LabelListAttribute
|
||||
|
||||
Strip stripAttributes
|
||||
Additional_linker_inputs bazel.LabelListAttribute
|
||||
|
||||
Cppflags bazel.StringListAttribute
|
||||
Conlyflags bazel.StringListAttribute
|
||||
Asflags bazel.StringListAttribute
|
||||
|
||||
Features bazel.StringListAttribute
|
||||
|
||||
Stubs_symbol_file *string
|
||||
|
||||
Inject_bssl_hash bazel.BoolAttribute
|
||||
|
||||
Stem bazel.StringAttribute
|
||||
Suffix bazel.StringAttribute
|
||||
|
||||
bazelCcHeaderAbiCheckerAttributes
|
||||
|
||||
Fdo_profile bazel.LabelAttribute
|
||||
}
|
||||
|
||||
type bazelCcStubSuiteAttributes struct {
|
||||
Symbol_file *string
|
||||
Versions bazel.StringListAttribute
|
||||
Export_includes bazel.StringListAttribute
|
||||
Source_library_label *string
|
||||
Soname *string
|
||||
Deps bazel.LabelListAttribute
|
||||
Api_surface *string
|
||||
|
||||
// Unless the library is in the NDK, module-libapi stubs should *not* include the public symbols
|
||||
// Soong uses a global variable to determine if the library is in the NDK
|
||||
// Since Bazel does not have global analysis, create an explicit property
|
||||
// This property is only relevant if `api_surface = module-libapi`
|
||||
// https://cs.android.com/android/_/android/platform/build/soong/+/main:cc/library.go;l=1214-1219;drc=7123cc5370a38983ee6325b5f5f6df19f4e4f10b;bpv=1;bpt=0
|
||||
Included_in_ndk *bool
|
||||
}
|
||||
|
||||
type bazelCcHeaderAbiCheckerAttributes struct {
|
||||
Abi_checker_enabled *bool
|
||||
Abi_checker_symbol_file *bazel.Label
|
||||
Abi_checker_exclude_symbol_versions []string
|
||||
Abi_checker_exclude_symbol_tags []string
|
||||
Abi_checker_check_all_apis *bool
|
||||
Abi_checker_diff_flags []string
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue