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:
@@ -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
|
||||
}
|
||||
|
@@ -16,8 +16,6 @@ package cc
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -48,52 +46,6 @@ func RegisterLibraryHeadersBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_prebuilt_library_headers", prebuiltLibraryHeaderFactory)
|
||||
}
|
||||
|
||||
type libraryHeaderBazelHandler struct {
|
||||
module *Module
|
||||
library *libraryDecorator
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*libraryHeaderBazelHandler)(nil)
|
||||
|
||||
func (handler *libraryHeaderBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
}
|
||||
|
||||
func (h *libraryHeaderBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
outputPaths := ccInfo.OutputFiles
|
||||
if len(outputPaths) != 1 {
|
||||
ctx.ModuleErrorf("expected exactly one output file for %q, but got %q", label, outputPaths)
|
||||
return
|
||||
}
|
||||
|
||||
var outputPath android.Path = android.PathForBazelOut(ctx, outputPaths[0])
|
||||
if len(ccInfo.TidyFiles) > 0 {
|
||||
h.module.tidyFiles = android.PathsForBazelOut(ctx, ccInfo.TidyFiles)
|
||||
outputPath = android.AttachValidationActions(ctx, outputPath, h.module.tidyFiles)
|
||||
}
|
||||
h.module.outputFile = android.OptionalPathForPath(outputPath)
|
||||
|
||||
// HeaderLibraryInfo is an empty struct to indicate to dependencies that this is a header library
|
||||
ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{})
|
||||
|
||||
h.library.setFlagExporterInfoFromCcInfo(ctx, ccInfo)
|
||||
|
||||
// Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise
|
||||
// validation will fail. For now, set this to an empty list.
|
||||
// TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation.
|
||||
h.library.collectedSnapshotHeaders = android.Paths{}
|
||||
|
||||
h.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo)
|
||||
}
|
||||
|
||||
// cc_library_headers contains a set of c/c++ headers which are imported by
|
||||
// other soong cc modules using the header_libs property. For best practices,
|
||||
// use export_include_dirs property or LOCAL_EXPORT_C_INCLUDE_DIRS for
|
||||
@@ -102,8 +54,6 @@ func LibraryHeaderFactory() android.Module {
|
||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.HeaderOnly()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{headersLibrarySdkMemberType}
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &libraryHeaderBazelHandler{module: module, library: library}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
@@ -111,50 +61,5 @@ func LibraryHeaderFactory() android.Module {
|
||||
func prebuiltLibraryHeaderFactory() android.Module {
|
||||
module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported, "")
|
||||
library.HeaderOnly()
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
type bazelCcLibraryHeadersAttributes struct {
|
||||
Hdrs bazel.LabelListAttribute
|
||||
Export_includes bazel.StringListAttribute
|
||||
Export_absolute_includes bazel.StringListAttribute
|
||||
Export_system_includes bazel.StringListAttribute
|
||||
Deps bazel.LabelListAttribute
|
||||
SdkAttributes
|
||||
}
|
||||
|
||||
func libraryHeadersBp2Build(ctx android.Bp2buildMutatorContext, module *Module) {
|
||||
baseAttributes := bp2BuildParseBaseProps(ctx, module)
|
||||
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, &baseAttributes.includes)
|
||||
linkerAttrs := baseAttributes.linkerAttributes
|
||||
(&linkerAttrs.deps).Append(linkerAttrs.dynamicDeps)
|
||||
(&linkerAttrs.deps).Append(linkerAttrs.wholeArchiveDeps)
|
||||
|
||||
attrs := &bazelCcLibraryHeadersAttributes{
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
Deps: linkerAttrs.deps,
|
||||
Hdrs: baseAttributes.hdrs,
|
||||
SdkAttributes: Bp2BuildParseSdkAttributes(module),
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_library_headers",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_library_headers.bzl",
|
||||
}
|
||||
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||
|
||||
name := module.Name()
|
||||
if module.IsPrebuilt() {
|
||||
name = android.RemoveOptionalPrebuiltPrefix(name)
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
||||
Name: name,
|
||||
Tags: tags,
|
||||
}, attrs)
|
||||
}
|
||||
|
@@ -251,16 +251,9 @@ func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMembe
|
||||
return &nativeLibInfoProperties{memberType: mt}
|
||||
}
|
||||
|
||||
func isBazelOutDirectory(p android.Path) bool {
|
||||
_, bazel := p.(android.BazelOutPath)
|
||||
return bazel
|
||||
}
|
||||
|
||||
func isGeneratedHeaderDirectory(p android.Path) bool {
|
||||
_, gen := p.(android.WritablePath)
|
||||
// TODO(b/183213331): Here we assume that bazel-based headers are not generated; we need
|
||||
// to support generated headers in mixed builds.
|
||||
return gen && !isBazelOutDirectory(p)
|
||||
return gen
|
||||
}
|
||||
|
||||
type includeDirsProperty struct {
|
||||
|
@@ -19,7 +19,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel/cquery"
|
||||
)
|
||||
|
||||
func TestLibraryReuse(t *testing.T) {
|
||||
@@ -246,137 +245,6 @@ func TestStubsVersions_ParseError(t *testing.T) {
|
||||
testCcError(t, `"libfoo" .*: versions: "X" could not be parsed as an integer and is not a recognized codename`, bp)
|
||||
}
|
||||
|
||||
func TestCcLibraryWithBazel(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_library {
|
||||
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",
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
Headers: []string{"foo.h"},
|
||||
RootDynamicLibraries: []string{"foo.so"},
|
||||
UnstrippedOutput: "foo_unstripped.so",
|
||||
},
|
||||
"//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
Headers: []string{"foo.h"},
|
||||
RootStaticArchives: []string{"foo.a"},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
|
||||
staticFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module()
|
||||
outputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
|
||||
expectedOutputFiles := []string{"outputbase/execroot/__main__/foo.a"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
|
||||
flagExporter := ctx.ModuleProvider(staticFoo, FlagExporterInfoProvider).(FlagExporterInfo)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders)
|
||||
android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps)
|
||||
|
||||
sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
outputFiles, err = sharedFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_library outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles = []string{"outputbase/execroot/__main__/foo.so"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
|
||||
android.AssertStringEquals(t, "unstripped shared library", "outputbase/execroot/__main__/foo_unstripped.so", sharedFoo.(*Module).linker.unstrippedOutputFilePath().String())
|
||||
flagExporter = ctx.ModuleProvider(sharedFoo, FlagExporterInfoProvider).(FlagExporterInfo)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders)
|
||||
android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps)
|
||||
}
|
||||
|
||||
func TestCcLibraryWithBazelValidations(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_library {
|
||||
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",
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
Headers: []string{"foo.h"},
|
||||
RootDynamicLibraries: []string{"foo.so"},
|
||||
UnstrippedOutput: "foo_unstripped.so",
|
||||
},
|
||||
"//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
Headers: []string{"foo.h"},
|
||||
RootStaticArchives: []string{"foo.a"},
|
||||
TidyFiles: []string{"foo.c.tidy"},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := android.GroupFixturePreparers(
|
||||
prepareForCcTest,
|
||||
android.FixtureMergeEnv(map[string]string{
|
||||
"ALLOW_LOCAL_TIDY_TRUE": "1",
|
||||
}),
|
||||
).RunTestWithConfig(t, config).TestContext
|
||||
|
||||
staticFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module()
|
||||
outputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
|
||||
expectedOutputFiles := []string{"out/soong/.intermediates/foo/android_arm_armv7-a-neon_static/validated/foo.a"}
|
||||
android.AssertPathsRelativeToTopEquals(t, "output files", expectedOutputFiles, outputFiles)
|
||||
|
||||
flagExporter := ctx.ModuleProvider(staticFoo, FlagExporterInfoProvider).(FlagExporterInfo)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders)
|
||||
android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps)
|
||||
|
||||
sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
outputFiles, err = sharedFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_library outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles = []string{"outputbase/execroot/__main__/foo.so"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
|
||||
android.AssertStringEquals(t, "unstripped shared library", "outputbase/execroot/__main__/foo_unstripped.so", sharedFoo.(*Module).linker.unstrippedOutputFilePath().String())
|
||||
flagExporter = ctx.ModuleProvider(sharedFoo, FlagExporterInfoProvider).(FlagExporterInfo)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported include dirs", []string{"outputbase/execroot/__main__/include"}, flagExporter.IncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported system include dirs", []string{"outputbase/execroot/__main__/system_include"}, flagExporter.SystemIncludeDirs)
|
||||
android.AssertPathsRelativeToTopEquals(t, "exported headers", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.GeneratedHeaders)
|
||||
android.AssertPathsRelativeToTopEquals(t, "deps", []string{"outputbase/execroot/__main__/foo.h"}, flagExporter.Deps)
|
||||
}
|
||||
|
||||
func TestLibraryVersionScript(t *testing.T) {
|
||||
t.Parallel()
|
||||
result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
|
||||
@@ -413,107 +281,6 @@ func TestLibraryDynamicList(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedWithBazelValidations(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_library_shared {
|
||||
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",
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
RootDynamicLibraries: []string{"foo.so"},
|
||||
TocFile: "foo.so.toc",
|
||||
TidyFiles: []string{"foo.c.tidy"},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := android.GroupFixturePreparers(
|
||||
prepareForCcTest,
|
||||
android.FixtureMergeEnv(map[string]string{
|
||||
"ALLOW_LOCAL_TIDY_TRUE": "1",
|
||||
}),
|
||||
).RunTestWithConfig(t, config).TestContext
|
||||
|
||||
sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
producer := sharedFoo.(android.OutputFileProducer)
|
||||
outputFiles, err := producer.OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{"out/soong/.intermediates/foo/android_arm_armv7-a-neon_shared/validated/foo.so"}
|
||||
android.AssertPathsRelativeToTopEquals(t, "output files", expectedOutputFiles, outputFiles)
|
||||
|
||||
tocFilePath := sharedFoo.(*Module).Toc()
|
||||
if !tocFilePath.Valid() {
|
||||
t.Errorf("Invalid tocFilePath: %s", tocFilePath)
|
||||
}
|
||||
tocFile := tocFilePath.Path()
|
||||
expectedToc := "outputbase/execroot/__main__/foo.so.toc"
|
||||
android.AssertStringEquals(t, "toc file", expectedToc, tocFile.String())
|
||||
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, sharedFoo)[0]
|
||||
expectedFlags := []string{"-Ioutputbase/execroot/__main__/include", "-isystem outputbase/execroot/__main__/system_include"}
|
||||
gotFlags := entries.EntryMap["LOCAL_EXPORT_CFLAGS"]
|
||||
android.AssertDeepEquals(t, "androidmk exported cflags", expectedFlags, gotFlags)
|
||||
android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "cc_library_shared", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0])
|
||||
}
|
||||
|
||||
func TestCcLibrarySharedWithBazel(t *testing.T) {
|
||||
t.Parallel()
|
||||
bp := `
|
||||
cc_library_shared {
|
||||
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",
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcObjectFiles: []string{"foo.o"},
|
||||
Includes: []string{"include"},
|
||||
SystemIncludes: []string{"system_include"},
|
||||
RootDynamicLibraries: []string{"foo.so"},
|
||||
TocFile: "foo.so.toc",
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
|
||||
sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").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())
|
||||
|
||||
tocFilePath := sharedFoo.(*Module).Toc()
|
||||
if !tocFilePath.Valid() {
|
||||
t.Errorf("Invalid tocFilePath: %s", tocFilePath)
|
||||
}
|
||||
tocFile := tocFilePath.Path()
|
||||
expectedToc := "outputbase/execroot/__main__/foo.so.toc"
|
||||
android.AssertStringEquals(t, "toc file", expectedToc, tocFile.String())
|
||||
|
||||
entries := android.AndroidMkEntriesForTest(t, ctx, sharedFoo)[0]
|
||||
expectedFlags := []string{"-Ioutputbase/execroot/__main__/include", "-isystem outputbase/execroot/__main__/system_include"}
|
||||
gotFlags := entries.EntryMap["LOCAL_EXPORT_CFLAGS"]
|
||||
android.AssertDeepEquals(t, "androidmk exported cflags", expectedFlags, gotFlags)
|
||||
android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "cc_library_shared", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0])
|
||||
}
|
||||
|
||||
func TestWholeStaticLibPrebuilts(t *testing.T) {
|
||||
t.Parallel()
|
||||
result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
|
||||
|
@@ -2,7 +2,6 @@ package cc
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel/cquery"
|
||||
"android/soong/fuzz"
|
||||
"android/soong/snapshot"
|
||||
|
||||
@@ -431,19 +430,3 @@ type FlagExporterInfo struct {
|
||||
}
|
||||
|
||||
var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
|
||||
|
||||
// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
|
||||
func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
|
||||
|
||||
includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
|
||||
systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
|
||||
headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
|
||||
|
||||
return FlagExporterInfo{
|
||||
IncludeDirs: android.FirstUniquePaths(includes),
|
||||
SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
|
||||
GeneratedHeaders: headers,
|
||||
// necessary to ensure generated headers are considered implicit deps of dependent actions
|
||||
Deps: headers,
|
||||
}
|
||||
}
|
||||
|
@@ -18,11 +18,8 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -81,7 +78,6 @@ type headerProperties struct {
|
||||
|
||||
type headerModule struct {
|
||||
android.ModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
properties headerProperties
|
||||
|
||||
@@ -148,30 +144,6 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
}
|
||||
}
|
||||
|
||||
type bazelNdkHeadersAttributes struct {
|
||||
Strip_import_prefix *string
|
||||
Import_prefix *string
|
||||
Hdrs bazel.LabelListAttribute
|
||||
Run_versioner *bool
|
||||
}
|
||||
|
||||
func (h *headerModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "ndk_headers",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:ndk_headers.bzl",
|
||||
}
|
||||
attrs := &bazelNdkHeadersAttributes{
|
||||
Strip_import_prefix: h.properties.From,
|
||||
Import_prefix: h.properties.To,
|
||||
Hdrs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, h.properties.Srcs, h.properties.Exclude_srcs)),
|
||||
}
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
android.CommonAttributes{Name: h.Name()},
|
||||
attrs,
|
||||
)
|
||||
}
|
||||
|
||||
// ndk_headers installs the sets of ndk headers defined in the srcs property
|
||||
// to the sysroot base + "usr/include" + to directory + directory component.
|
||||
// ndk_headers requires the license file to be specified. Example:
|
||||
@@ -186,7 +158,6 @@ func NdkHeadersFactory() android.Module {
|
||||
module := &headerModule{}
|
||||
module.AddProperties(&module.properties)
|
||||
android.InitAndroidModule(module)
|
||||
android.InitBazelModule(module)
|
||||
return module
|
||||
}
|
||||
|
||||
@@ -219,7 +190,6 @@ type versionedHeaderProperties struct {
|
||||
// Note that this is really only built to handle bionic/libc/include.
|
||||
type versionedHeaderModule struct {
|
||||
android.ModuleBase
|
||||
android.BazelModuleBase
|
||||
|
||||
properties versionedHeaderProperties
|
||||
|
||||
@@ -258,25 +228,6 @@ func (m *versionedHeaderModule) GenerateAndroidBuildActions(ctx android.ModuleCo
|
||||
processHeadersWithVersioner(ctx, fromSrcPath, toOutputPath, m.srcPaths, installPaths)
|
||||
}
|
||||
|
||||
func (h *versionedHeaderModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "ndk_headers",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:ndk_headers.bzl",
|
||||
}
|
||||
globPattern := headerGlobPattern(proptools.String(h.properties.From))
|
||||
attrs := &bazelNdkHeadersAttributes{
|
||||
Strip_import_prefix: h.properties.From,
|
||||
Import_prefix: h.properties.To,
|
||||
Run_versioner: proptools.BoolPtr(true),
|
||||
Hdrs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, []string{globPattern})),
|
||||
}
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
android.CommonAttributes{Name: h.Name()},
|
||||
attrs,
|
||||
)
|
||||
}
|
||||
|
||||
func processHeadersWithVersioner(ctx android.ModuleContext, srcDir, outDir android.Path,
|
||||
srcPaths android.Paths, installPaths []android.WritablePath) android.Path {
|
||||
// The versioner depends on a dependencies directory to simplify determining include paths
|
||||
@@ -326,7 +277,6 @@ func VersionedNdkHeadersFactory() android.Module {
|
||||
module.AddProperties(&module.properties)
|
||||
|
||||
android.InitAndroidModule(module)
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/cc/config"
|
||||
)
|
||||
|
||||
@@ -563,51 +562,5 @@ func newStubLibrary() *Module {
|
||||
func NdkLibraryFactory() android.Module {
|
||||
module := newStubLibrary()
|
||||
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
|
||||
android.InitBazelModule(module)
|
||||
return module
|
||||
}
|
||||
|
||||
type bazelCcApiContributionAttributes struct {
|
||||
Api bazel.LabelAttribute
|
||||
Api_surfaces bazel.StringListAttribute
|
||||
Hdrs bazel.LabelListAttribute
|
||||
Library_name string
|
||||
}
|
||||
|
||||
func ndkLibraryBp2build(ctx android.Bp2buildMutatorContext, c *Module) {
|
||||
ndk, _ := c.linker.(*stubDecorator)
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_stub_suite",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_stub_library.bzl",
|
||||
}
|
||||
sourceLibraryName := strings.TrimSuffix(c.Name(), ".ndk")
|
||||
fromApiLevel, err := android.ApiLevelFromUser(ctx, proptools.String(ndk.properties.First_version))
|
||||
if err != nil {
|
||||
ctx.PropertyErrorf("first_version", "error converting first_version %v", proptools.String(ndk.properties.First_version))
|
||||
}
|
||||
symbolFileLabel := android.BazelLabelForModuleSrcSingle(ctx, proptools.String(ndk.properties.Symbol_file))
|
||||
attrs := &bazelCcStubSuiteAttributes{
|
||||
// TODO - b/300504837 Add ndk headers
|
||||
Symbol_file: proptools.StringPtr(symbolFileLabel.Label),
|
||||
Soname: proptools.StringPtr(sourceLibraryName + ".so"),
|
||||
Api_surface: proptools.StringPtr(android.PublicApi.String()),
|
||||
Included_in_ndk: proptools.BoolPtr(true),
|
||||
}
|
||||
if sourceLibrary, exists := ctx.ModuleFromName(sourceLibraryName); exists {
|
||||
// the source library might not exist in minimal/unbuildable branches like kernel-build-tools.
|
||||
// check for its existence
|
||||
attrs.Source_library_label = proptools.StringPtr(c.GetBazelLabel(ctx, sourceLibrary))
|
||||
}
|
||||
if ctx.Config().RawPlatformSdkVersion() != nil {
|
||||
// This is a hack to populate `versions` only on branches that set a platform_sdk_version
|
||||
// This prevents errors on branches such as kernel-build-tools
|
||||
// This hack is acceptable since we are not required to support NDK Bazel builds on those branches
|
||||
attrs.Versions = bazel.MakeStringListAttribute(ndkLibraryVersions(ctx, fromApiLevel))
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
android.CommonAttributes{Name: c.Name() + "_stub_libs"},
|
||||
attrs,
|
||||
)
|
||||
}
|
||||
|
@@ -15,11 +15,9 @@
|
||||
package cc
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -66,7 +64,6 @@ func NdkPrebuiltSharedStlFactory() android.Module {
|
||||
module.Properties.Sdk_version = StringPtr("minimum")
|
||||
module.Properties.AlwaysSdk = true
|
||||
module.stl.Properties.Stl = StringPtr("none")
|
||||
module.bazelable = true
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
@@ -87,7 +84,6 @@ func NdkPrebuiltStaticStlFactory() android.Module {
|
||||
module.Properties.AlwaysSdk = true
|
||||
module.Properties.Sdk_version = StringPtr("current")
|
||||
module.stl.Properties.Stl = StringPtr("none")
|
||||
module.bazelable = true
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
@@ -135,81 +131,3 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
||||
|
||||
return lib
|
||||
}
|
||||
|
||||
var (
|
||||
archToAbiDirMap = map[string]string{
|
||||
"android_arm": "armeabi-v7a",
|
||||
"android_arm64": "arm64-v8a",
|
||||
"android_riscv64": "riscv64",
|
||||
"android_x86": "x86",
|
||||
"android_x86_64": "x86_64",
|
||||
}
|
||||
)
|
||||
|
||||
// stlSrcBp2build returns a bazel label for the checked-in .so/.a file
|
||||
// It contains a select statement for each ABI
|
||||
func stlSrcBp2build(ctx android.Bp2buildMutatorContext, c *Module) bazel.LabelAttribute {
|
||||
libName := strings.TrimPrefix(c.Name(), "ndk_")
|
||||
libExt := ".so" // TODO - b/201079053: Support windows
|
||||
if ctx.ModuleType() == "ndk_prebuilt_static_stl" {
|
||||
libExt = ".a"
|
||||
}
|
||||
src := bazel.LabelAttribute{}
|
||||
for arch, abiDir := range archToAbiDirMap {
|
||||
srcPath := filepath.Join(libDir, abiDir, libName+libExt)
|
||||
src.SetSelectValue(
|
||||
bazel.OsArchConfigurationAxis,
|
||||
arch,
|
||||
android.BazelLabelForModuleSrcSingle(ctx, srcPath),
|
||||
)
|
||||
}
|
||||
return src
|
||||
}
|
||||
|
||||
// stlIncludesBp2build returns the includes exported by the STL
|
||||
func stlIncludesBp2build(c *Module) bazel.StringListAttribute {
|
||||
linker, _ := c.linker.(*ndkPrebuiltStlLinker)
|
||||
includeDirs := append(
|
||||
[]string{},
|
||||
linker.libraryDecorator.flagExporter.Properties.Export_include_dirs...,
|
||||
)
|
||||
includeDirs = append(
|
||||
includeDirs,
|
||||
linker.libraryDecorator.flagExporter.Properties.Export_system_include_dirs...,
|
||||
)
|
||||
return bazel.MakeStringListAttribute(android.FirstUniqueStrings(includeDirs))
|
||||
}
|
||||
|
||||
func ndkPrebuiltStlBp2build(ctx android.Bp2buildMutatorContext, c *Module) {
|
||||
if ctx.ModuleType() == "ndk_prebuilt_static_stl" {
|
||||
ndkPrebuiltStaticStlBp2build(ctx, c)
|
||||
} else {
|
||||
ndkPrebuiltSharedStlBp2build(ctx, c)
|
||||
}
|
||||
}
|
||||
|
||||
func ndkPrebuiltStaticStlBp2build(ctx android.Bp2buildMutatorContext, c *Module) {
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_prebuilt_library_static",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_prebuilt_library_static.bzl",
|
||||
}
|
||||
attrs := &bazelPrebuiltLibraryStaticAttributes{
|
||||
Static_library: stlSrcBp2build(ctx, c),
|
||||
Export_system_includes: stlIncludesBp2build(c), // The exports are always as system
|
||||
}
|
||||
// TODO: min_sdk_version
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: c.Name()}, attrs)
|
||||
}
|
||||
|
||||
func ndkPrebuiltSharedStlBp2build(ctx android.Bp2buildMutatorContext, c *Module) {
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_prebuilt_library_shared",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_prebuilt_library_shared.bzl",
|
||||
}
|
||||
attrs := &bazelPrebuiltLibrarySharedAttributes{
|
||||
Shared_library: stlSrcBp2build(ctx, c),
|
||||
Export_system_includes: stlIncludesBp2build(c), // The exports are always as system
|
||||
}
|
||||
// TODO: min_sdk_version
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: c.Name()}, attrs)
|
||||
}
|
||||
|
129
cc/object.go
129
cc/object.go
@@ -19,8 +19,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -50,33 +48,6 @@ type objectLinker struct {
|
||||
ndkSysrootPath android.Path
|
||||
}
|
||||
|
||||
type objectBazelHandler struct {
|
||||
module *Module
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*objectBazelHandler)(nil)
|
||||
|
||||
func (handler *objectBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(label, cquery.GetOutputFiles, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
}
|
||||
|
||||
func (handler *objectBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
objPaths, err := bazelCtx.GetOutputFiles(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if len(objPaths) != 1 {
|
||||
ctx.ModuleErrorf("expected exactly one object file for '%s', but got %s", label, objPaths)
|
||||
return
|
||||
}
|
||||
|
||||
handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0]))
|
||||
}
|
||||
|
||||
type ObjectLinkerProperties struct {
|
||||
// list of static library modules that should only provide headers for this module.
|
||||
Static_libs []string `android:"arch_variant,variant_prepend"`
|
||||
@@ -125,115 +96,15 @@ func ObjectFactory() android.Module {
|
||||
baseLinker: NewBaseLinker(module.sanitize),
|
||||
}
|
||||
module.compiler = NewBaseCompiler()
|
||||
module.bazelHandler = &objectBazelHandler{module: module}
|
||||
|
||||
// Clang's address-significance tables are incompatible with ld -r.
|
||||
module.compiler.appendCflags([]string{"-fno-addrsig"})
|
||||
|
||||
module.sdkMemberTypes = []android.SdkMemberType{ccObjectSdkMemberType}
|
||||
|
||||
module.bazelable = true
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
// For bp2build conversion.
|
||||
type bazelObjectAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Srcs_as bazel.LabelListAttribute
|
||||
Hdrs bazel.LabelListAttribute
|
||||
Objs bazel.LabelListAttribute
|
||||
Deps bazel.LabelListAttribute
|
||||
System_dynamic_deps bazel.LabelListAttribute
|
||||
Copts bazel.StringListAttribute
|
||||
Asflags bazel.StringListAttribute
|
||||
Local_includes bazel.StringListAttribute
|
||||
Absolute_includes bazel.StringListAttribute
|
||||
Stl *string
|
||||
Linker_script bazel.LabelAttribute
|
||||
Crt *bool
|
||||
SdkAttributes
|
||||
}
|
||||
|
||||
// objectBp2Build is the bp2build converter from cc_object modules to the
|
||||
// Bazel equivalent target, plus any necessary include deps for the cc_object.
|
||||
func objectBp2Build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||
if m.compiler == nil {
|
||||
// a cc_object must have access to the compiler decorator for its props.
|
||||
ctx.ModuleErrorf("compiler must not be nil for a cc_object module")
|
||||
}
|
||||
|
||||
// Set arch-specific configurable attributes
|
||||
baseAttributes := bp2BuildParseBaseProps(ctx, m)
|
||||
compilerAttrs := baseAttributes.compilerAttributes
|
||||
var objs bazel.LabelListAttribute
|
||||
var deps bazel.LabelListAttribute
|
||||
systemDynamicDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
|
||||
|
||||
var linkerScript bazel.LabelAttribute
|
||||
|
||||
for axis, configToProps := range m.GetArchVariantProperties(ctx, &ObjectLinkerProperties{}) {
|
||||
for config, props := range configToProps {
|
||||
if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {
|
||||
if objectLinkerProps.Linker_script != nil {
|
||||
label := android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script)
|
||||
linkerScript.SetSelectValue(axis, config, label)
|
||||
}
|
||||
objs.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
|
||||
systemSharedLibs := objectLinkerProps.System_shared_libs
|
||||
if len(systemSharedLibs) > 0 {
|
||||
systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
|
||||
}
|
||||
systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
|
||||
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Static_libs))
|
||||
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Shared_libs))
|
||||
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Header_libs))
|
||||
// static_libs, shared_libs, and header_libs have variant_prepend tag
|
||||
deps.Prepend = true
|
||||
}
|
||||
}
|
||||
}
|
||||
objs.ResolveExcludes()
|
||||
|
||||
// Don't split cc_object srcs across languages. Doing so would add complexity,
|
||||
// and this isn't typically done for cc_object.
|
||||
srcs := compilerAttrs.srcs
|
||||
srcs.Append(compilerAttrs.cSrcs)
|
||||
|
||||
asFlags := compilerAttrs.asFlags
|
||||
if compilerAttrs.asSrcs.IsEmpty() {
|
||||
// Skip asflags for BUILD file simplicity if there are no assembly sources.
|
||||
asFlags = bazel.MakeStringListAttribute(nil)
|
||||
}
|
||||
|
||||
attrs := &bazelObjectAttributes{
|
||||
Srcs: srcs,
|
||||
Srcs_as: compilerAttrs.asSrcs,
|
||||
Objs: objs,
|
||||
Deps: deps,
|
||||
System_dynamic_deps: systemDynamicDeps,
|
||||
Copts: compilerAttrs.copts,
|
||||
Asflags: asFlags,
|
||||
Local_includes: compilerAttrs.localIncludes,
|
||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||
Stl: compilerAttrs.stl,
|
||||
Linker_script: linkerScript,
|
||||
Crt: m.linker.(*objectLinker).Properties.Crt,
|
||||
SdkAttributes: Bp2BuildParseSdkAttributes(m),
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_object",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_object.bzl",
|
||||
}
|
||||
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
||||
Name: m.Name(),
|
||||
Tags: tags,
|
||||
}, attrs)
|
||||
}
|
||||
|
||||
func (object *objectLinker) appendLdflags(flags []string) {
|
||||
panic(fmt.Errorf("appendLdflags on objectLinker not supported"))
|
||||
}
|
||||
|
@@ -85,30 +85,6 @@ func TestLinkerScript(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcObjectWithBazel(t *testing.T) {
|
||||
bp := `
|
||||
cc_object {
|
||||
name: "foo",
|
||||
srcs: ["baz.o"],
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "outputbase",
|
||||
LabelToOutputFiles: map[string][]string{
|
||||
"//foo/bar:bar": []string{"bazel_out.o"}}}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
|
||||
module := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon").Module()
|
||||
outputFiles, err := module.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
|
||||
expectedOutputFiles := []string{"outputbase/execroot/__main__/bazel_out.o"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
}
|
||||
|
||||
func TestCcObjectOutputFile(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
|
323
cc/prebuilt.go
323
cc/prebuilt.go
@@ -18,8 +18,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -57,13 +55,6 @@ type prebuiltLinkerProperties struct {
|
||||
// This is needed only if this library is linked by other modules in build time.
|
||||
// Only makes sense for the Windows target.
|
||||
Windows_import_lib *string `android:"path,arch_variant"`
|
||||
|
||||
// MixedBuildsDisabled is true if and only if building this prebuilt is explicitly disabled in mixed builds for either
|
||||
// its static or shared version on the current build variant. This is to prevent Bazel targets for build variants with
|
||||
// which either the static or shared version is incompatible from participating in mixed buiods. Please note that this
|
||||
// is an override and does not fully determine whether Bazel or Soong will be used. For the full determination, see
|
||||
// cc.ProcessBazelQueryResponse, cc.QueueBazelCall, and cc.MixedBuildsDisabled.
|
||||
MixedBuildsDisabled bool `blueprint:"mutated"`
|
||||
}
|
||||
|
||||
type prebuiltLinker struct {
|
||||
@@ -261,7 +252,6 @@ func (p *prebuiltLibraryLinker) nativeCoverage() bool {
|
||||
|
||||
func (p *prebuiltLibraryLinker) disablePrebuilt() {
|
||||
p.properties.Srcs = nil
|
||||
p.properties.MixedBuildsDisabled = true
|
||||
}
|
||||
|
||||
// Implements versionedInterface
|
||||
@@ -272,8 +262,6 @@ func (p *prebuiltLibraryLinker) implementationModuleName(name string) string {
|
||||
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported, srcsProperty string) (*Module, *libraryDecorator) {
|
||||
module, library := NewLibrary(hod)
|
||||
module.compiler = nil
|
||||
module.bazelable = true
|
||||
module.bazelHandler = &prebuiltLibraryBazelHandler{module: module, library: library}
|
||||
|
||||
prebuilt := &prebuiltLibraryLinker{
|
||||
libraryDecorator: library,
|
||||
@@ -348,82 +336,6 @@ func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libr
|
||||
return module, library
|
||||
}
|
||||
|
||||
type bazelPrebuiltLibraryStaticAttributes struct {
|
||||
Static_library bazel.LabelAttribute
|
||||
Export_includes bazel.StringListAttribute
|
||||
Export_system_includes bazel.StringListAttribute
|
||||
Alwayslink bazel.BoolAttribute
|
||||
}
|
||||
|
||||
// TODO(b/228623543): The below is not entirely true until the bug is fixed. For now, both targets are always generated
|
||||
// Implements bp2build for cc_prebuilt_library modules. This will generate:
|
||||
// - Only a cc_prebuilt_library_static if the shared.enabled property is set to false across all variants.
|
||||
// - Only a cc_prebuilt_library_shared if the static.enabled property is set to false across all variants
|
||||
// - Both a cc_prebuilt_library_static and cc_prebuilt_library_shared if the aforementioned properties are not false across
|
||||
// all variants
|
||||
//
|
||||
// In all cases, cc_prebuilt_library_static target names will be appended with "_bp2build_cc_library_static".
|
||||
func prebuiltLibraryBp2Build(ctx android.Bp2buildMutatorContext, module *Module) {
|
||||
prebuiltLibraryStaticBp2Build(ctx, module, true)
|
||||
prebuiltLibrarySharedBp2Build(ctx, module)
|
||||
}
|
||||
|
||||
func prebuiltLibraryStaticBp2Build(ctx android.Bp2buildMutatorContext, module *Module, fullBuild bool) {
|
||||
prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module, true)
|
||||
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, nil)
|
||||
|
||||
attrs := &bazelPrebuiltLibraryStaticAttributes{
|
||||
Static_library: prebuiltAttrs.Src,
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
// TODO: ¿Alwayslink?
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_prebuilt_library_static",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_prebuilt_library_static.bzl",
|
||||
}
|
||||
|
||||
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
||||
if fullBuild {
|
||||
name += "_bp2build_cc_library_static"
|
||||
}
|
||||
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name, Tags: tags}, attrs, prebuiltAttrs.Enabled)
|
||||
|
||||
_true := true
|
||||
alwayslinkAttrs := *attrs
|
||||
alwayslinkAttrs.Alwayslink.SetValue(&_true)
|
||||
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name + "_alwayslink", Tags: tags}, &alwayslinkAttrs, prebuiltAttrs.Enabled)
|
||||
}
|
||||
|
||||
type bazelPrebuiltLibrarySharedAttributes struct {
|
||||
Shared_library bazel.LabelAttribute
|
||||
Export_includes bazel.StringListAttribute
|
||||
Export_system_includes bazel.StringListAttribute
|
||||
}
|
||||
|
||||
func prebuiltLibrarySharedBp2Build(ctx android.Bp2buildMutatorContext, module *Module) {
|
||||
prebuiltAttrs := Bp2BuildParsePrebuiltLibraryProps(ctx, module, false)
|
||||
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, nil)
|
||||
|
||||
attrs := &bazelPrebuiltLibrarySharedAttributes{
|
||||
Shared_library: prebuiltAttrs.Src,
|
||||
Export_includes: exportedIncludes.Includes,
|
||||
Export_system_includes: exportedIncludes.SystemIncludes,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_prebuilt_library_shared",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_prebuilt_library_shared.bzl",
|
||||
}
|
||||
|
||||
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name, Tags: tags}, attrs, prebuiltAttrs.Enabled)
|
||||
}
|
||||
|
||||
type prebuiltObjectProperties struct {
|
||||
Srcs []string `android:"path,arch_variant"`
|
||||
}
|
||||
@@ -435,135 +347,6 @@ type prebuiltObjectLinker struct {
|
||||
properties prebuiltObjectProperties
|
||||
}
|
||||
|
||||
type prebuiltLibraryBazelHandler struct {
|
||||
module *Module
|
||||
library *libraryDecorator
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*prebuiltLibraryBazelHandler)(nil)
|
||||
|
||||
func (h *prebuiltLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
if h.module.linker.(*prebuiltLibraryLinker).properties.MixedBuildsDisabled {
|
||||
return
|
||||
}
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKey(ctx))
|
||||
}
|
||||
|
||||
func (h *prebuiltLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
if h.module.linker.(*prebuiltLibraryLinker).properties.MixedBuildsDisabled {
|
||||
return
|
||||
}
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKey(ctx))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if h.module.static() {
|
||||
if ok := h.processStaticBazelQueryResponse(ctx, label, ccInfo); !ok {
|
||||
return
|
||||
}
|
||||
} else if h.module.Shared() {
|
||||
if ok := h.processSharedBazelQueryResponse(ctx, label, ccInfo); !ok {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
h.module.maybeUnhideFromMake()
|
||||
|
||||
h.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo)
|
||||
}
|
||||
|
||||
func (h *prebuiltLibraryBazelHandler) processStaticBazelQueryResponse(ctx android.ModuleContext, label string, ccInfo cquery.CcInfo) bool {
|
||||
staticLibs := ccInfo.CcStaticLibraryFiles
|
||||
if len(staticLibs) > 1 {
|
||||
ctx.ModuleErrorf("expected 1 static library from bazel target %q, got %s", label, staticLibs)
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO(b/184543518): cc_prebuilt_library_static may have properties for re-exporting flags
|
||||
|
||||
// TODO(eakammer):Add stub-related flags if this library is a stub library.
|
||||
// h.library.exportVersioningMacroIfNeeded(ctx)
|
||||
|
||||
// Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise
|
||||
// validation will fail. For now, set this to an empty list.
|
||||
// TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation.
|
||||
h.library.collectedSnapshotHeaders = android.Paths{}
|
||||
|
||||
if len(staticLibs) == 0 {
|
||||
h.module.outputFile = android.OptionalPath{}
|
||||
return true
|
||||
}
|
||||
|
||||
var outputPath android.Path = android.PathForBazelOut(ctx, staticLibs[0])
|
||||
if len(ccInfo.TidyFiles) > 0 {
|
||||
h.module.tidyFiles = android.PathsForBazelOut(ctx, ccInfo.TidyFiles)
|
||||
outputPath = android.AttachValidationActions(ctx, outputPath, h.module.tidyFiles)
|
||||
}
|
||||
|
||||
h.module.outputFile = android.OptionalPathForPath(outputPath)
|
||||
|
||||
depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(outputPath).Build()
|
||||
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
|
||||
StaticLibrary: outputPath,
|
||||
TransitiveStaticLibrariesForOrdering: depSet,
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (h *prebuiltLibraryBazelHandler) processSharedBazelQueryResponse(ctx android.ModuleContext, label string, ccInfo cquery.CcInfo) bool {
|
||||
sharedLibs := ccInfo.CcSharedLibraryFiles
|
||||
if len(sharedLibs) > 1 {
|
||||
ctx.ModuleErrorf("expected 1 shared library from bazel target %s, got %q", label, sharedLibs)
|
||||
return false
|
||||
}
|
||||
|
||||
// TODO(b/184543518): cc_prebuilt_library_shared may have properties for re-exporting flags
|
||||
|
||||
// TODO(eakammer):Add stub-related flags if this library is a stub library.
|
||||
// h.library.exportVersioningMacroIfNeeded(ctx)
|
||||
|
||||
if len(sharedLibs) == 0 {
|
||||
h.module.outputFile = android.OptionalPath{}
|
||||
return true
|
||||
}
|
||||
|
||||
var outputPath android.Path = android.PathForBazelOut(ctx, sharedLibs[0])
|
||||
if len(ccInfo.TidyFiles) > 0 {
|
||||
h.module.tidyFiles = android.PathsForBazelOut(ctx, ccInfo.TidyFiles)
|
||||
outputPath = android.AttachValidationActions(ctx, outputPath, h.module.tidyFiles)
|
||||
}
|
||||
|
||||
h.module.outputFile = android.OptionalPathForPath(outputPath)
|
||||
|
||||
// FIXME(b/214600441): We don't yet strip prebuilt shared libraries
|
||||
h.library.unstrippedOutputFile = outputPath
|
||||
|
||||
var toc android.Path
|
||||
if len(ccInfo.TocFile) > 0 {
|
||||
toc = android.PathForBazelOut(ctx, ccInfo.TocFile)
|
||||
} else {
|
||||
toc = outputPath // Just reuse `out` so ninja still gets an input but won't matter
|
||||
}
|
||||
|
||||
info := SharedLibraryInfo{
|
||||
SharedLibrary: outputPath,
|
||||
TableOfContents: android.OptionalPathForPath(toc),
|
||||
Target: ctx.Target(),
|
||||
}
|
||||
ctx.SetProvider(SharedLibraryInfoProvider, info)
|
||||
|
||||
h.library.setFlagExporterInfoFromCcInfo(ctx, ccInfo)
|
||||
h.module.maybeUnhideFromMake()
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *prebuiltObjectLinker) prebuilt() *android.Prebuilt {
|
||||
return &p.Prebuilt
|
||||
}
|
||||
@@ -593,8 +376,6 @@ func (p *prebuiltObjectLinker) object() bool {
|
||||
|
||||
func NewPrebuiltObject(hod android.HostOrDeviceSupported) *Module {
|
||||
module := newObject(hod)
|
||||
module.bazelHandler = &prebuiltObjectBazelHandler{module: module}
|
||||
module.bazelable = true
|
||||
prebuilt := &prebuiltObjectLinker{
|
||||
objectLinker: objectLinker{
|
||||
baseLinker: NewBaseLinker(nil),
|
||||
@@ -606,54 +387,6 @@ func NewPrebuiltObject(hod android.HostOrDeviceSupported) *Module {
|
||||
return module
|
||||
}
|
||||
|
||||
type prebuiltObjectBazelHandler struct {
|
||||
module *Module
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*prebuiltObjectBazelHandler)(nil)
|
||||
|
||||
func (h *prebuiltObjectBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(label, cquery.GetOutputFiles, android.GetConfigKey(ctx))
|
||||
}
|
||||
|
||||
func (h *prebuiltObjectBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
outputs, err := bazelCtx.GetOutputFiles(label, android.GetConfigKey(ctx))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
if len(outputs) != 1 {
|
||||
ctx.ModuleErrorf("Expected a single output for `%s`, but got:\n%v", label, outputs)
|
||||
return
|
||||
}
|
||||
out := android.PathForBazelOut(ctx, outputs[0])
|
||||
h.module.outputFile = android.OptionalPathForPath(out)
|
||||
h.module.maybeUnhideFromMake()
|
||||
}
|
||||
|
||||
type bazelPrebuiltObjectAttributes struct {
|
||||
Src bazel.LabelAttribute
|
||||
}
|
||||
|
||||
func prebuiltObjectBp2Build(ctx android.Bp2buildMutatorContext, module *Module) {
|
||||
prebuiltAttrs := bp2BuildParsePrebuiltObjectProps(ctx, module)
|
||||
|
||||
attrs := &bazelPrebuiltObjectAttributes{
|
||||
Src: prebuiltAttrs.Src,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_prebuilt_object",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_prebuilt_object.bzl",
|
||||
}
|
||||
|
||||
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name, Tags: tags}, attrs)
|
||||
}
|
||||
|
||||
func PrebuiltObjectFactory() android.Module {
|
||||
module := NewPrebuiltObject(android.HostAndDeviceSupported)
|
||||
return module.Init()
|
||||
@@ -747,15 +480,9 @@ func PrebuiltBinaryFactory() android.Module {
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
type prebuiltBinaryBazelHandler struct {
|
||||
module *Module
|
||||
decorator *binaryDecorator
|
||||
}
|
||||
|
||||
func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
|
||||
module, binary := newBinary(hod, true)
|
||||
module, binary := newBinary(hod)
|
||||
module.compiler = nil
|
||||
module.bazelHandler = &prebuiltBinaryBazelHandler{module, binary}
|
||||
|
||||
prebuilt := &prebuiltBinaryLinker{
|
||||
binaryDecorator: binary,
|
||||
@@ -769,54 +496,6 @@ func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecor
|
||||
return module, binary
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*prebuiltBinaryBazelHandler)(nil)
|
||||
|
||||
func (h *prebuiltBinaryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(label, cquery.GetOutputFiles, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
}
|
||||
|
||||
func (h *prebuiltBinaryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
outputs, err := bazelCtx.GetOutputFiles(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
return
|
||||
}
|
||||
if len(outputs) != 1 {
|
||||
ctx.ModuleErrorf("Expected a single output for `%s`, but got:\n%v", label, outputs)
|
||||
return
|
||||
}
|
||||
out := android.PathForBazelOut(ctx, outputs[0])
|
||||
h.module.outputFile = android.OptionalPathForPath(out)
|
||||
h.module.maybeUnhideFromMake()
|
||||
}
|
||||
|
||||
type bazelPrebuiltBinaryAttributes struct {
|
||||
Src bazel.LabelAttribute
|
||||
Strip stripAttributes
|
||||
}
|
||||
|
||||
func prebuiltBinaryBp2Build(ctx android.Bp2buildMutatorContext, module *Module) {
|
||||
prebuiltAttrs := bp2BuildParsePrebuiltBinaryProps(ctx, module)
|
||||
|
||||
var la linkerAttributes
|
||||
la.convertStripProps(ctx, module)
|
||||
attrs := &bazelPrebuiltBinaryAttributes{
|
||||
Src: prebuiltAttrs.Src,
|
||||
Strip: stripAttrsFromLinkerAttrs(&la),
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_prebuilt_binary",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_prebuilt_binary.bzl",
|
||||
}
|
||||
|
||||
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name, Tags: tags}, attrs)
|
||||
}
|
||||
|
||||
type Sanitized struct {
|
||||
None struct {
|
||||
Srcs []string `android:"path,arch_variant"`
|
||||
|
@@ -19,8 +19,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
@@ -386,289 +384,6 @@ func TestPrebuiltLibrarySanitized(t *testing.T) {
|
||||
assertString(t, static2.OutputFile().Path().Base(), "libf.hwasan.a")
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryWithBazel(t *testing.T) {
|
||||
const bp = `
|
||||
cc_prebuilt_library {
|
||||
name: "foo",
|
||||
shared: {
|
||||
srcs: ["foo.so"],
|
||||
},
|
||||
static: {
|
||||
srcs: ["foo.a"],
|
||||
},
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
outBaseDir := "outputbase"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForPrebuiltTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcSharedLibraryFiles: []string{"foo.so"},
|
||||
},
|
||||
"//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
|
||||
CcStaticLibraryFiles: []string{"foo.a"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
sharedFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
pathPrefix := outBaseDir + "/execroot/__main__/"
|
||||
|
||||
sharedInfo := result.ModuleProvider(sharedFoo, SharedLibraryInfoProvider).(SharedLibraryInfo)
|
||||
android.AssertPathRelativeToTopEquals(t,
|
||||
"prebuilt library shared target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
|
||||
pathPrefix+"foo.so", sharedInfo.SharedLibrary)
|
||||
|
||||
outputFiles, err := sharedFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{pathPrefix + "foo.so"}
|
||||
android.AssertDeepEquals(t,
|
||||
"prebuilt library shared target output files did not match expected.",
|
||||
expectedOutputFiles, outputFiles.Strings())
|
||||
|
||||
staticFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module()
|
||||
staticInfo := result.ModuleProvider(staticFoo, StaticLibraryInfoProvider).(StaticLibraryInfo)
|
||||
android.AssertPathRelativeToTopEquals(t,
|
||||
"prebuilt library static target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
|
||||
pathPrefix+"foo.a", staticInfo.StaticLibrary)
|
||||
|
||||
staticOutputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object staticOutputFiles %s", err)
|
||||
}
|
||||
expectedStaticOutputFiles := []string{pathPrefix + "foo.a"}
|
||||
android.AssertDeepEquals(t,
|
||||
"prebuilt library static target output files did not match expected.",
|
||||
expectedStaticOutputFiles, staticOutputFiles.Strings())
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryWithBazelValidations(t *testing.T) {
|
||||
const bp = `
|
||||
cc_prebuilt_library {
|
||||
name: "foo",
|
||||
shared: {
|
||||
srcs: ["foo.so"],
|
||||
},
|
||||
static: {
|
||||
srcs: ["foo.a"],
|
||||
},
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
tidy: true,
|
||||
}`
|
||||
outBaseDir := "outputbase"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForPrebuiltTest,
|
||||
android.FixtureMergeEnv(map[string]string{
|
||||
"ALLOW_LOCAL_TIDY_TRUE": "1",
|
||||
}),
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcSharedLibraryFiles: []string{"foo.so"},
|
||||
TidyFiles: []string{"foo.c.tidy"},
|
||||
},
|
||||
"//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
|
||||
CcStaticLibraryFiles: []string{"foo.a"},
|
||||
TidyFiles: []string{"foo.c.tidy"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
sharedFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
|
||||
expectedOutputFile := "out/soong/.intermediates/foo/android_arm_armv7-a-neon_shared/validated/foo.so"
|
||||
sharedInfo := result.ModuleProvider(sharedFoo, SharedLibraryInfoProvider).(SharedLibraryInfo)
|
||||
android.AssertPathRelativeToTopEquals(t,
|
||||
"prebuilt library shared target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
|
||||
expectedOutputFile, sharedInfo.SharedLibrary)
|
||||
|
||||
outputFiles, err := sharedFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{expectedOutputFile}
|
||||
android.AssertPathsRelativeToTopEquals(t,
|
||||
"prebuilt library shared target output files did not match expected.",
|
||||
expectedOutputFiles, outputFiles)
|
||||
|
||||
staticFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module()
|
||||
staticInfo := result.ModuleProvider(staticFoo, StaticLibraryInfoProvider).(StaticLibraryInfo)
|
||||
expectedStaticOutputFile := "out/soong/.intermediates/foo/android_arm_armv7-a-neon_static/validated/foo.a"
|
||||
android.AssertPathRelativeToTopEquals(t,
|
||||
"prebuilt library static target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
|
||||
expectedStaticOutputFile, staticInfo.StaticLibrary)
|
||||
|
||||
staticOutputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object staticOutputFiles %s", err)
|
||||
}
|
||||
expectedStaticOutputFiles := []string{expectedStaticOutputFile}
|
||||
android.AssertPathsRelativeToTopEquals(t,
|
||||
"prebuilt library static target output files did not match expected.",
|
||||
expectedStaticOutputFiles, staticOutputFiles)
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryWithBazelStaticDisabled(t *testing.T) {
|
||||
const bp = `
|
||||
cc_prebuilt_library {
|
||||
name: "foo",
|
||||
shared: {
|
||||
srcs: ["foo.so"],
|
||||
},
|
||||
static: {
|
||||
enabled: false
|
||||
},
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
outBaseDir := "outputbase"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForPrebuiltTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcSharedLibraryFiles: []string{"foo.so"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
sharedFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
pathPrefix := outBaseDir + "/execroot/__main__/"
|
||||
|
||||
sharedInfo := result.ModuleProvider(sharedFoo, SharedLibraryInfoProvider).(SharedLibraryInfo)
|
||||
android.AssertPathRelativeToTopEquals(t,
|
||||
"prebuilt library shared target path did not exist or did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
|
||||
pathPrefix+"foo.so", sharedInfo.SharedLibrary)
|
||||
|
||||
outputFiles, err := sharedFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{pathPrefix + "foo.so"}
|
||||
android.AssertDeepEquals(t,
|
||||
"prebuilt library shared target output files did not match expected.",
|
||||
expectedOutputFiles, outputFiles.Strings())
|
||||
}
|
||||
|
||||
func TestPrebuiltLibraryStaticWithBazel(t *testing.T) {
|
||||
const bp = `
|
||||
cc_prebuilt_library_static {
|
||||
name: "foo",
|
||||
srcs: ["foo.so"],
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
outBaseDir := "outputbase"
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForPrebuiltTest,
|
||||
android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcStaticLibraryFiles: []string{"foo.so"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}),
|
||||
).RunTestWithBp(t, bp)
|
||||
staticFoo := result.ModuleForTests("foo", "android_arm_armv7-a-neon_static").Module()
|
||||
pathPrefix := outBaseDir + "/execroot/__main__/"
|
||||
|
||||
info := result.ModuleProvider(staticFoo, StaticLibraryInfoProvider).(StaticLibraryInfo)
|
||||
android.AssertPathRelativeToTopEquals(t,
|
||||
"prebuilt library static path did not match expected. If the base path is what does not match, it is likely that Soong built this module instead of Bazel.",
|
||||
pathPrefix+"foo.so", info.StaticLibrary)
|
||||
|
||||
outputFiles, err := staticFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{pathPrefix + "foo.so"}
|
||||
android.AssertDeepEquals(t, "prebuilt library static output files did not match expected.", expectedOutputFiles, outputFiles.Strings())
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedWithBazelWithoutToc(t *testing.T) {
|
||||
const bp = `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "foo",
|
||||
srcs: ["foo.so"],
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
outBaseDir := "outputbase"
|
||||
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcSharedLibraryFiles: []string{"foo.so"},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
pathPrefix := outBaseDir + "/execroot/__main__/"
|
||||
|
||||
info := ctx.ModuleProvider(sharedFoo, SharedLibraryInfoProvider).(SharedLibraryInfo)
|
||||
android.AssertPathRelativeToTopEquals(t, "prebuilt shared library",
|
||||
pathPrefix+"foo.so", info.SharedLibrary)
|
||||
android.AssertPathRelativeToTopEquals(t, "prebuilt's 'nullary' ToC",
|
||||
pathPrefix+"foo.so", info.TableOfContents.Path())
|
||||
|
||||
outputFiles, err := sharedFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{pathPrefix + "foo.so"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
}
|
||||
|
||||
func TestPrebuiltLibrarySharedWithBazelWithToc(t *testing.T) {
|
||||
const bp = `
|
||||
cc_prebuilt_library_shared {
|
||||
name: "foo",
|
||||
srcs: ["foo.so"],
|
||||
bazel_module: { label: "//foo/bar:bar" },
|
||||
}`
|
||||
outBaseDir := "outputbase"
|
||||
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||
"//foo/bar:bar": cquery.CcInfo{
|
||||
CcSharedLibraryFiles: []string{"foo.so"},
|
||||
TocFile: "toc",
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
sharedFoo := ctx.ModuleForTests("foo", "android_arm_armv7-a-neon_shared").Module()
|
||||
pathPrefix := outBaseDir + "/execroot/__main__/"
|
||||
|
||||
info := ctx.ModuleProvider(sharedFoo, SharedLibraryInfoProvider).(SharedLibraryInfo)
|
||||
android.AssertPathRelativeToTopEquals(t, "prebuilt shared library's ToC",
|
||||
pathPrefix+"toc", info.TableOfContents.Path())
|
||||
android.AssertPathRelativeToTopEquals(t, "prebuilt shared library",
|
||||
pathPrefix+"foo.so", info.SharedLibrary)
|
||||
|
||||
outputFiles, err := sharedFoo.(android.OutputFileProducer).OutputFiles("")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting cc_object outputfiles %s", err)
|
||||
}
|
||||
expectedOutputFiles := []string{pathPrefix + "foo.so"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
|
||||
}
|
||||
|
||||
func TestPrebuiltStubNoinstall(t *testing.T) {
|
||||
testFunc := func(t *testing.T, expectLibfooOnSystemLib bool, fs android.MockFS) {
|
||||
result := android.GroupFixturePreparers(
|
||||
@@ -794,27 +509,3 @@ cc_prebuilt_binary {
|
||||
}`
|
||||
testCcError(t, `Android.bp:4:6: module "bintest" variant "android_arm64_armv8-a": srcs: multiple prebuilt source files`, bp)
|
||||
}
|
||||
|
||||
func TestPrebuiltBinaryWithBazel(t *testing.T) {
|
||||
const bp = `
|
||||
cc_prebuilt_binary {
|
||||
name: "bintest",
|
||||
srcs: ["bin"],
|
||||
bazel_module: { label: "//bin/foo:foo" },
|
||||
}`
|
||||
const outBaseDir = "outputbase"
|
||||
const expectedOut = outBaseDir + "/execroot/__main__/bin"
|
||||
config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: outBaseDir,
|
||||
LabelToOutputFiles: map[string][]string{"//bin/foo:foo": []string{"bin"}},
|
||||
}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
bin := ctx.ModuleForTests("bintest", "android_arm64_armv8-a").Module().(*Module)
|
||||
out := bin.OutputFile()
|
||||
if !out.Valid() {
|
||||
t.Error("Invalid output file")
|
||||
return
|
||||
}
|
||||
android.AssertStringEquals(t, "output file", expectedOut, out.String())
|
||||
}
|
||||
|
107
cc/proto.go
107
cc/proto.go
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -163,109 +162,3 @@ func protoFlags(ctx ModuleContext, flags Flags, p *android.ProtoProperties) Flag
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
type protoAttributes struct {
|
||||
Deps bazel.LabelListAttribute
|
||||
|
||||
// A list of proto_library targets that that the proto_library in `deps` depends on
|
||||
// This list is overestimation.
|
||||
// Overestimation is necessary since Soong includes other protos via proto.include_dirs and not
|
||||
// a specific .proto file module explicitly.
|
||||
Transitive_deps bazel.LabelListAttribute
|
||||
|
||||
// A list of cc_library_* targets that the generated cpp code depends on
|
||||
Cc_deps bazel.LabelListAttribute
|
||||
|
||||
Min_sdk_version *string
|
||||
}
|
||||
|
||||
type bp2buildProtoDeps struct {
|
||||
wholeStaticLib *bazel.LabelAttribute
|
||||
implementationWholeStaticLib *bazel.LabelAttribute
|
||||
protoDep *bazel.LabelAttribute
|
||||
}
|
||||
|
||||
func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs bazel.LabelListAttribute, la linkerAttributes) bp2buildProtoDeps {
|
||||
var ret bp2buildProtoDeps
|
||||
|
||||
protoInfo, ok := android.Bp2buildProtoProperties(ctx, &m.ModuleBase, protoSrcs)
|
||||
if !ok || protoInfo.Proto_libs.IsEmpty() {
|
||||
return ret
|
||||
}
|
||||
|
||||
var depName string
|
||||
typ := proptools.StringDefault(protoInfo.Type, protoTypeDefault)
|
||||
var rule_class string
|
||||
suffix := "_cc_proto"
|
||||
switch typ {
|
||||
case "lite":
|
||||
suffix += "_lite"
|
||||
rule_class = "cc_lite_proto_library"
|
||||
depName = "libprotobuf-cpp-lite"
|
||||
case "full":
|
||||
rule_class = "cc_proto_library"
|
||||
depName = "libprotobuf-cpp-full"
|
||||
default:
|
||||
ctx.PropertyErrorf("proto.type", "cannot handle conversion at this time: %q", typ)
|
||||
}
|
||||
|
||||
dep := android.BazelLabelForModuleDepSingle(ctx, depName)
|
||||
ret.protoDep = &bazel.LabelAttribute{Value: &dep}
|
||||
|
||||
var protoAttrs protoAttributes
|
||||
protoAttrs.Deps.SetValue(protoInfo.Proto_libs)
|
||||
protoAttrs.Transitive_deps.SetValue(protoInfo.Transitive_proto_libs)
|
||||
|
||||
// Add the implementation deps of the top-level cc_library_static
|
||||
// This is necessary to compile the internal root of cc_proto_library.
|
||||
// Without this, clang might not be able to find .h files that the generated cpp files depends on
|
||||
protoAttrs.Cc_deps = *la.implementationDeps.Clone()
|
||||
protoAttrs.Cc_deps.Append(la.implementationDynamicDeps)
|
||||
protoAttrs.Cc_deps.Append(la.implementationWholeArchiveDeps)
|
||||
protoAttrs.Cc_deps.Append(la.wholeArchiveDeps)
|
||||
// Subtract myself to prevent possible circular dep
|
||||
protoAttrs.Cc_deps = bazel.SubtractBazelLabelListAttribute(
|
||||
protoAttrs.Cc_deps,
|
||||
bazel.MakeLabelListAttribute(
|
||||
bazel.MakeLabelList([]bazel.Label{
|
||||
bazel.Label{Label: ":" + m.Name() + suffix},
|
||||
}),
|
||||
),
|
||||
)
|
||||
// Subtract the protobuf libraries since cc_proto_library implicitly adds them
|
||||
protoAttrs.Cc_deps = bazel.SubtractBazelLabelListAttribute(
|
||||
protoAttrs.Cc_deps,
|
||||
bazel.MakeLabelListAttribute(
|
||||
bazel.MakeLabelList([]bazel.Label{
|
||||
bazel.Label{Label: "//external/protobuf:libprotobuf-cpp-full", OriginalModuleName: "libprotobuf-cpp-full"},
|
||||
bazel.Label{Label: "//external/protobuf:libprotobuf-cpp-lite", OriginalModuleName: "libprotobuf-cpp-lite"},
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
protoAttrs.Min_sdk_version = m.Properties.Min_sdk_version
|
||||
|
||||
name := m.Name() + suffix
|
||||
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: rule_class,
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_proto.bzl",
|
||||
},
|
||||
android.CommonAttributes{Name: name, Tags: tags},
|
||||
&protoAttrs)
|
||||
|
||||
var privateHdrs bool
|
||||
if lib, ok := m.linker.(*libraryDecorator); ok {
|
||||
privateHdrs = !proptools.Bool(lib.Properties.Proto.Export_proto_headers)
|
||||
}
|
||||
|
||||
labelAttr := &bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + name}}
|
||||
if privateHdrs {
|
||||
ret.implementationWholeStaticLib = labelAttr
|
||||
} else {
|
||||
ret.wholeStaticLib = labelAttr
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
33
cc/rs.go
33
cc/rs.go
@@ -20,7 +20,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
|
||||
@@ -134,35 +133,3 @@ func rsFlags(ctx ModuleContext, flags Flags, properties *BaseCompilerProperties)
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
type rscriptAttributes struct {
|
||||
// Renderscript source files
|
||||
Srcs bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
func bp2buildRScript(ctx android.Bp2buildMutatorContext, m *Module, ca compilerAttributes) (bazel.LabelAttribute, bazel.StringListAttribute, bazel.StringListAttribute) {
|
||||
var rscriptAttrs rscriptAttributes
|
||||
var rsAbsIncludes bazel.StringListAttribute
|
||||
var localIncludes bazel.StringListAttribute
|
||||
var rsModuleName string
|
||||
var convertedRsSrcsLabel bazel.LabelAttribute
|
||||
|
||||
if !ca.rscriptSrcs.IsEmpty() {
|
||||
rscriptAttrs.Srcs = ca.rscriptSrcs
|
||||
rsModuleName = m.Name() + "_renderscript"
|
||||
|
||||
localIncludes.Value = []string{"."}
|
||||
rsAbsIncludes.Value = []string{"frameworks/rs", "frameworks/rs/cpp"}
|
||||
convertedRsSrcsLabel = bazel.LabelAttribute{Value: &bazel.Label{Label: rsModuleName}}
|
||||
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "rscript_to_cpp",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:rscript_to_cpp.bzl",
|
||||
},
|
||||
android.CommonAttributes{Name: rsModuleName},
|
||||
&rscriptAttrs)
|
||||
}
|
||||
|
||||
return convertedRsSrcsLabel, rsAbsIncludes, localIncludes
|
||||
}
|
||||
|
@@ -1911,7 +1911,3 @@ func cfiMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||
func hwasanMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||
hwasanStaticLibs(ctx.Config()).exportToMake(ctx)
|
||||
}
|
||||
|
||||
func BazelCcSanitizerToolchainVars(config android.Config) string {
|
||||
return android.BazelToolchainVars(config, exportedVars)
|
||||
}
|
||||
|
@@ -134,8 +134,6 @@ func staticUnwinder(ctx android.BaseModuleContext) string {
|
||||
return "libunwind"
|
||||
}
|
||||
|
||||
// Should be kept up to date with
|
||||
// https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/cc/stl.bzl;l=46;drc=21771b671ae08565033768a6d3d151c54f887fa2
|
||||
func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
switch stl.Properties.SelectedStl {
|
||||
case "libstdc++":
|
||||
@@ -187,8 +185,6 @@ func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps {
|
||||
return deps
|
||||
}
|
||||
|
||||
// Should be kept up to date with
|
||||
// https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/cc/stl.bzl;l=94;drc=5bc8e39d2637927dc57dd0850210d43d348a1341
|
||||
func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
switch stl.Properties.SelectedStl {
|
||||
case "libc++", "libc++_static":
|
||||
|
@@ -59,7 +59,6 @@ func (stripper *Stripper) NeedsStrip(actx android.ModuleContext) bool {
|
||||
return !forceDisable && (forceEnable || defaultEnable)
|
||||
}
|
||||
|
||||
// Keep this consistent with //build/bazel/rules/stripped_shared_library.bzl.
|
||||
func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
|
||||
flags StripFlags, isStaticLib bool) {
|
||||
if actx.Darwin() {
|
||||
|
192
cc/test.go
192
cc/test.go
@@ -22,8 +22,6 @@ import (
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
"android/soong/tradefed"
|
||||
)
|
||||
|
||||
@@ -139,8 +137,7 @@ func init() {
|
||||
// specific functionality on a device. The executable binary gets an implicit
|
||||
// static_libs dependency on libgtests unless the gtest flag is set to false.
|
||||
func TestFactory() android.Module {
|
||||
module := NewTest(android.HostAndDeviceSupported, true)
|
||||
module.bazelHandler = &ccTestBazelHandler{module: module}
|
||||
module := NewTest(android.HostAndDeviceSupported)
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
@@ -164,7 +161,7 @@ func BenchmarkFactory() android.Module {
|
||||
|
||||
// cc_test_host compiles a test host binary.
|
||||
func TestHostFactory() android.Module {
|
||||
module := NewTest(android.HostSupported, true)
|
||||
module := NewTest(android.HostSupported)
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
@@ -488,9 +485,8 @@ func getTradefedConfigOptions(ctx android.EarlyModuleContext, properties *TestBi
|
||||
return configs
|
||||
}
|
||||
|
||||
func NewTest(hod android.HostOrDeviceSupported, bazelable bool) *Module {
|
||||
module, binary := newBinary(hod, bazelable)
|
||||
module.bazelable = bazelable
|
||||
func NewTest(hod android.HostOrDeviceSupported) *Module {
|
||||
module, binary := newBinary(hod)
|
||||
module.multilib = android.MultilibBoth
|
||||
module.testModule = true
|
||||
binary.baseInstaller = NewTestInstaller()
|
||||
@@ -552,7 +548,6 @@ func NewTestLibrary(hod android.HostOrDeviceSupported) *Module {
|
||||
}
|
||||
module.linker = test
|
||||
module.installer = test
|
||||
module.bazelable = true
|
||||
return module
|
||||
}
|
||||
|
||||
@@ -632,7 +627,7 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat
|
||||
}
|
||||
|
||||
func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
|
||||
module, binary := newBinary(hod, false)
|
||||
module, binary := newBinary(hod)
|
||||
module.multilib = android.MultilibBoth
|
||||
binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData)
|
||||
|
||||
@@ -643,180 +638,3 @@ func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
|
||||
module.installer = benchmark
|
||||
return module
|
||||
}
|
||||
|
||||
type ccTestBazelHandler struct {
|
||||
module *Module
|
||||
}
|
||||
|
||||
var _ BazelHandler = (*ccTestBazelHandler)(nil)
|
||||
|
||||
// The top level target named $label is a test_suite target,
|
||||
// not the internal cc_test executable target.
|
||||
//
|
||||
// This is to ensure `b test //$label` runs the test_suite target directly,
|
||||
// which depends on tradefed_test targets, instead of the internal cc_test
|
||||
// target, which doesn't have tradefed integrations.
|
||||
//
|
||||
// However, for cquery, we want the internal cc_test executable target, which
|
||||
// has the suffix "__tf_internal".
|
||||
func mixedBuildsTestLabel(label string) string {
|
||||
return label + "__tf_internal"
|
||||
}
|
||||
|
||||
func (handler *ccTestBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
bazelCtx.QueueBazelRequest(mixedBuildsTestLabel(label), cquery.GetCcUnstrippedInfo, android.GetConfigKey(ctx))
|
||||
}
|
||||
|
||||
func (handler *ccTestBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
info, err := bazelCtx.GetCcUnstrippedInfo(mixedBuildsTestLabel(label), android.GetConfigKey(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.(*testBinary).unstrippedOutputFile = android.PathForBazelOut(ctx, info.UnstrippedOutput)
|
||||
|
||||
handler.module.setAndroidMkVariablesFromCquery(info.CcAndroidMkInfo)
|
||||
}
|
||||
|
||||
// binaryAttributes contains Bazel attributes corresponding to a cc test
|
||||
type testBinaryAttributes struct {
|
||||
binaryAttributes
|
||||
|
||||
Gtest *bool
|
||||
|
||||
tidyAttributes
|
||||
tradefed.TestConfigAttributes
|
||||
|
||||
Runs_on bazel.StringListAttribute
|
||||
}
|
||||
|
||||
// testBinaryBp2build is the bp2build converter for cc_test modules. A cc_test's
|
||||
// dependency graph and compilation/linking steps are functionally similar to a
|
||||
// cc_binary, but has additional dependencies on test deps like gtest, and
|
||||
// produces additional runfiles like XML plans for Tradefed orchestration
|
||||
//
|
||||
// TODO(b/244432609): handle `isolated` property.
|
||||
// TODO(b/244432134): handle custom runpaths for tests that assume runfile layouts not
|
||||
// default to bazel. (see linkerInit function)
|
||||
func testBinaryBp2build(ctx android.Bp2buildMutatorContext, m *Module) {
|
||||
var testBinaryAttrs testBinaryAttributes
|
||||
testBinaryAttrs.binaryAttributes = binaryBp2buildAttrs(ctx, m)
|
||||
|
||||
var data bazel.LabelListAttribute
|
||||
var tags bazel.StringListAttribute
|
||||
|
||||
testBinaryProps := m.GetArchVariantProperties(ctx, &TestBinaryProperties{})
|
||||
for axis, configToProps := range testBinaryProps {
|
||||
for config, props := range configToProps {
|
||||
if p, ok := props.(*TestBinaryProperties); ok {
|
||||
// Combine data, data_bins and data_libs into a single 'data' attribute.
|
||||
var combinedData bazel.LabelList
|
||||
combinedData.Append(android.BazelLabelForModuleSrc(ctx, p.Data))
|
||||
combinedData.Append(android.BazelLabelForModuleDeps(ctx, p.Data_bins))
|
||||
combinedData.Append(android.BazelLabelForModuleDeps(ctx, p.Data_libs))
|
||||
data.SetSelectValue(axis, config, combinedData)
|
||||
tags.SetSelectValue(axis, config, p.Test_options.Tags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The logic comes from https://cs.android.com/android/platform/superproject/main/+/0df8153267f96da877febc5332240fa06ceb8533:build/soong/cc/sanitize.go;l=488
|
||||
var features bazel.StringListAttribute
|
||||
curFeatures := testBinaryAttrs.binaryAttributes.Features.SelectValue(bazel.OsArchConfigurationAxis, bazel.OsArchAndroidArm64)
|
||||
var newFeatures []string
|
||||
if !android.InList("memtag_heap", curFeatures) && !android.InList("-memtag_heap", curFeatures) {
|
||||
newFeatures = append(newFeatures, "memtag_heap")
|
||||
if !android.InList("diag_memtag_heap", curFeatures) && !android.InList("-diag_memtag_heap", curFeatures) {
|
||||
newFeatures = append(newFeatures, "diag_memtag_heap")
|
||||
}
|
||||
}
|
||||
|
||||
features.SetSelectValue(bazel.OsArchConfigurationAxis, bazel.OsArchAndroidArm64, newFeatures)
|
||||
testBinaryAttrs.binaryAttributes.Features.Append(features)
|
||||
testBinaryAttrs.binaryAttributes.Features.DeduplicateAxesFromBase()
|
||||
|
||||
m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes)
|
||||
|
||||
testBinary := m.linker.(*testBinary)
|
||||
gtest := testBinary.gtest()
|
||||
gtestIsolated := testBinary.isolated(ctx)
|
||||
// Use the underling bool pointer for Gtest in attrs
|
||||
// This ensures that if this property is not set in Android.bp file, it will not be set in BUILD file either
|
||||
// cc_test macro will default gtest to True
|
||||
testBinaryAttrs.Gtest = testBinary.LinkerProperties.Gtest
|
||||
|
||||
addImplicitGtestDeps(ctx, &testBinaryAttrs, gtest, gtestIsolated)
|
||||
|
||||
var unitTest *bool
|
||||
|
||||
for _, testProps := range m.GetProperties() {
|
||||
if p, ok := testProps.(*TestBinaryProperties); ok {
|
||||
useVendor := false // TODO Bug: 262914724
|
||||
testInstallBase := getTestInstallBase(useVendor)
|
||||
testConfigAttributes := tradefed.GetTestConfigAttributes(
|
||||
ctx,
|
||||
p.Test_config,
|
||||
p.Test_options.Extra_test_configs,
|
||||
p.Auto_gen_config,
|
||||
p.Test_options.Test_suite_tag,
|
||||
p.Test_config_template,
|
||||
getTradefedConfigOptions(ctx, p, gtestIsolated, true),
|
||||
&testInstallBase,
|
||||
)
|
||||
testBinaryAttrs.TestConfigAttributes = testConfigAttributes
|
||||
unitTest = p.Test_options.Unit_test
|
||||
}
|
||||
}
|
||||
|
||||
testBinaryAttrs.Runs_on = bazel.MakeStringListAttribute(android.RunsOn(
|
||||
m.ModuleBase.HostSupported(),
|
||||
m.ModuleBase.DeviceSupported(),
|
||||
gtest || (unitTest != nil && *unitTest)))
|
||||
|
||||
// TODO (b/262914724): convert to tradefed_cc_test and tradefed_cc_test_host
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "cc_test",
|
||||
Bzl_load_location: "//build/bazel/rules/cc:cc_test.bzl",
|
||||
},
|
||||
android.CommonAttributes{
|
||||
Name: m.Name(),
|
||||
Data: data,
|
||||
Tags: tags,
|
||||
},
|
||||
&testBinaryAttrs)
|
||||
}
|
||||
|
||||
// cc_test that builds using gtest needs some additional deps
|
||||
// addImplicitGtestDeps makes these deps explicit in the generated BUILD files
|
||||
func addImplicitGtestDeps(ctx android.Bp2buildMutatorContext, attrs *testBinaryAttributes, gtest, gtestIsolated bool) {
|
||||
addDepsAndDedupe := func(lla *bazel.LabelListAttribute, modules []string) {
|
||||
moduleLabels := android.BazelLabelForModuleDeps(ctx, modules)
|
||||
lla.Value.Append(moduleLabels)
|
||||
// Dedupe
|
||||
lla.Value = bazel.FirstUniqueBazelLabelList(lla.Value)
|
||||
}
|
||||
// this must be kept in sync with Soong's implementation in:
|
||||
// https://cs.android.com/android/_/android/platform/build/soong/+/460fb2d6d546b5ab493a7e5479998c4933a80f73:cc/test.go;l=300-313;drc=ec7314336a2b35ea30ce5438b83949c28e3ac429;bpv=1;bpt=0
|
||||
if gtest {
|
||||
// TODO - b/244433197: Handle canUseSdk
|
||||
if gtestIsolated {
|
||||
addDepsAndDedupe(&attrs.Deps, []string{"libgtest_isolated_main"})
|
||||
addDepsAndDedupe(&attrs.Dynamic_deps, []string{"liblog"})
|
||||
} else {
|
||||
addDepsAndDedupe(&attrs.Deps, []string{
|
||||
"libgtest_main",
|
||||
"libgtest",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -68,7 +68,6 @@ func (tidy *tidyFeature) props() []interface{} {
|
||||
// Then, that old style usage will be obsolete and an error.
|
||||
const NoWarningsAsErrorsInTidyFlags = true
|
||||
|
||||
// keep this up to date with https://cs.android.com/android/platform/superproject/+/master:build/bazel/rules/cc/clang_tidy.bzl
|
||||
func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
CheckBadTidyFlags(ctx, "tidy_flags", tidy.Properties.Tidy_flags)
|
||||
CheckBadTidyChecks(ctx, "tidy_checks", tidy.Properties.Tidy_checks)
|
||||
|
Reference in New Issue
Block a user