Merge "Support cc_prebuilt_binary building with Bazel"
This commit is contained in:
committed by
Gerrit Code Review
commit
49b59385da
@@ -190,7 +190,7 @@ var (
|
|||||||
"frameworks/native/opengl/tests/testPauseResume": Bp2BuildDefaultTrue,
|
"frameworks/native/opengl/tests/testPauseResume": Bp2BuildDefaultTrue,
|
||||||
"frameworks/native/opengl/tests/testViewport": Bp2BuildDefaultTrue,
|
"frameworks/native/opengl/tests/testViewport": Bp2BuildDefaultTrue,
|
||||||
"frameworks/native/services/batteryservice": Bp2BuildDefaultTrue,
|
"frameworks/native/services/batteryservice": Bp2BuildDefaultTrue,
|
||||||
"frameworks/proto_logging/stats/stats_log_api_gen": Bp2BuildDefaultTrueRecursively,
|
"frameworks/proto_logging/stats": Bp2BuildDefaultTrueRecursively,
|
||||||
|
|
||||||
"hardware/interfaces": Bp2BuildDefaultTrue,
|
"hardware/interfaces": Bp2BuildDefaultTrue,
|
||||||
"hardware/interfaces/common/aidl": Bp2BuildDefaultTrue,
|
"hardware/interfaces/common/aidl": Bp2BuildDefaultTrue,
|
||||||
@@ -318,8 +318,6 @@ var (
|
|||||||
"system/tools/sysprop": Bp2BuildDefaultTrue,
|
"system/tools/sysprop": Bp2BuildDefaultTrue,
|
||||||
"system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively,
|
"system/unwinding/libunwindstack": Bp2BuildDefaultTrueRecursively,
|
||||||
|
|
||||||
"frameworks/proto_logging/stats": Bp2BuildDefaultTrueRecursively,
|
|
||||||
|
|
||||||
"tools/apksig": Bp2BuildDefaultTrue,
|
"tools/apksig": Bp2BuildDefaultTrue,
|
||||||
"tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
|
"tools/platform-compat/java/android/compat": Bp2BuildDefaultTrueRecursively,
|
||||||
"tools/tradefederation/prebuilts/filegroups": Bp2BuildDefaultTrueRecursively,
|
"tools/tradefederation/prebuilts/filegroups": Bp2BuildDefaultTrueRecursively,
|
||||||
@@ -472,6 +470,9 @@ var (
|
|||||||
"libstagefright_bufferpool@2.0.1",
|
"libstagefright_bufferpool@2.0.1",
|
||||||
"libSurfaceFlingerProp",
|
"libSurfaceFlingerProp",
|
||||||
|
|
||||||
|
// prebuilts
|
||||||
|
"prebuilt_stats-log-api-gen",
|
||||||
|
|
||||||
// fastboot
|
// fastboot
|
||||||
"bootimg_headers",
|
"bootimg_headers",
|
||||||
"fastboot",
|
"fastboot",
|
||||||
|
125
bp2build/cc_prebuilt_binary_conversion_test.go
Normal file
125
bp2build/cc_prebuilt_binary_conversion_test.go
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
// Copyright 2022 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
package bp2build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/cc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runCcPrebuiltBinaryTestCase(t *testing.T, testCase Bp2buildTestCase) {
|
||||||
|
t.Helper()
|
||||||
|
description := fmt.Sprintf("cc_prebuilt_binary: %s", testCase.Description)
|
||||||
|
testCase.ModuleTypeUnderTest = "cc_prebuilt_binary"
|
||||||
|
testCase.ModuleTypeUnderTestFactory = cc.PrebuiltBinaryFactory
|
||||||
|
testCase.Description = description
|
||||||
|
t.Run(description, func(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
RunBp2BuildTestCaseSimple(t, testCase)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltBinary(t *testing.T) {
|
||||||
|
runCcPrebuiltBinaryTestCase(t,
|
||||||
|
Bp2buildTestCase{
|
||||||
|
Description: "simple",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"bin": "",
|
||||||
|
},
|
||||||
|
Blueprint: `
|
||||||
|
cc_prebuilt_binary {
|
||||||
|
name: "bintest",
|
||||||
|
srcs: ["bin"],
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
|
||||||
|
"src": `"bin"`,
|
||||||
|
})},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltBinaryWithStrip(t *testing.T) {
|
||||||
|
runCcPrebuiltBinaryTestCase(t,
|
||||||
|
Bp2buildTestCase{
|
||||||
|
Description: "with strip",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"bin": "",
|
||||||
|
},
|
||||||
|
Blueprint: `
|
||||||
|
cc_prebuilt_binary {
|
||||||
|
name: "bintest",
|
||||||
|
srcs: ["bin"],
|
||||||
|
strip: { all: true },
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}`, ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
|
||||||
|
"src": `"bin"`,
|
||||||
|
"strip": `{
|
||||||
|
"all": True,
|
||||||
|
}`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltBinaryWithArchVariance(t *testing.T) {
|
||||||
|
runCcPrebuiltBinaryTestCase(t,
|
||||||
|
Bp2buildTestCase{
|
||||||
|
Description: "with arch variance",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"bina": "",
|
||||||
|
"binb": "",
|
||||||
|
},
|
||||||
|
Blueprint: `
|
||||||
|
cc_prebuilt_binary {
|
||||||
|
name: "bintest",
|
||||||
|
arch: {
|
||||||
|
arm64: { srcs: ["bina"], },
|
||||||
|
arm: { srcs: ["binb"], },
|
||||||
|
},
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}`, ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("cc_prebuilt_binary", "bintest", AttrNameToString{
|
||||||
|
"src": `select({
|
||||||
|
"//build/bazel/platforms/arch:arm": "binb",
|
||||||
|
"//build/bazel/platforms/arch:arm64": "bina",
|
||||||
|
"//conditions:default": None,
|
||||||
|
})`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrebuiltBinaryMultipleSrcsFails(t *testing.T) {
|
||||||
|
runCcPrebuiltBinaryTestCase(t,
|
||||||
|
Bp2buildTestCase{
|
||||||
|
Description: "fails because multiple sources",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"bina": "",
|
||||||
|
"binb": "",
|
||||||
|
},
|
||||||
|
Blueprint: `
|
||||||
|
cc_prebuilt_binary {
|
||||||
|
name: "bintest",
|
||||||
|
srcs: ["bina", "binb"],
|
||||||
|
bazel_module: { bp2build_available: true },
|
||||||
|
}`,
|
||||||
|
ExpectedErr: fmt.Errorf("Expected at most one source file"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: nosrcs test
|
@@ -169,6 +169,14 @@ func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.BazelConve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bp2BuildPropParseHelper(ctx android.ArchVariantContext, module *Module, propsType interface{}, parseFunc func(axis bazel.ConfigurationAxis, config string, props interface{})) {
|
||||||
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, propsType) {
|
||||||
|
for config, props := range configToProps {
|
||||||
|
parseFunc(axis, config, props)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parses properties common to static and shared libraries. Also used for prebuilt libraries.
|
// Parses properties common to static and shared libraries. Also used for prebuilt libraries.
|
||||||
func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
|
func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
|
||||||
attrs := staticOrSharedAttributes{}
|
attrs := staticOrSharedAttributes{}
|
||||||
@@ -227,32 +235,30 @@ type prebuiltAttributes struct {
|
|||||||
Enabled bazel.BoolAttribute
|
Enabled bazel.BoolAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseSrc(ctx android.BazelConversionPathContext, srcLabelAttribute *bazel.LabelAttribute, axis bazel.ConfigurationAxis, config string, srcs []string) {
|
||||||
|
srcFileError := func() {
|
||||||
|
ctx.ModuleErrorf("parseSrc: Expected at most one source file for %s %s\n", axis, config)
|
||||||
|
}
|
||||||
|
if len(srcs) > 1 {
|
||||||
|
srcFileError()
|
||||||
|
return
|
||||||
|
} else if len(srcs) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if srcLabelAttribute.SelectValue(axis, config) != nil {
|
||||||
|
srcFileError()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
srcLabelAttribute.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, srcs[0]))
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package
|
// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package
|
||||||
func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) prebuiltAttributes {
|
func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) prebuiltAttributes {
|
||||||
manySourceFileError := func(axis bazel.ConfigurationAxis, config string) {
|
|
||||||
ctx.ModuleErrorf("Bp2BuildParsePrebuiltLibraryProps: Expected at most one source file for %s %s\n", axis, config)
|
|
||||||
}
|
|
||||||
var srcLabelAttribute bazel.LabelAttribute
|
var srcLabelAttribute bazel.LabelAttribute
|
||||||
|
|
||||||
parseSrcs := func(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, srcs []string) {
|
|
||||||
if len(srcs) > 1 {
|
|
||||||
manySourceFileError(axis, config)
|
|
||||||
return
|
|
||||||
} else if len(srcs) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if srcLabelAttribute.SelectValue(axis, config) != nil {
|
|
||||||
manySourceFileError(axis, config)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
src := android.BazelLabelForModuleSrcSingle(ctx, srcs[0])
|
|
||||||
srcLabelAttribute.SetSelectValue(axis, config, src)
|
|
||||||
}
|
|
||||||
|
|
||||||
bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
||||||
if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok {
|
if prebuiltLinkerProperties, ok := props.(*prebuiltLinkerProperties); ok {
|
||||||
parseSrcs(ctx, axis, config, prebuiltLinkerProperties.Srcs)
|
parseSrc(ctx, &srcLabelAttribute, axis, config, prebuiltLinkerProperties.Srcs)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -261,7 +267,7 @@ func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, m
|
|||||||
if props.Enabled != nil {
|
if props.Enabled != nil {
|
||||||
enabledLabelAttribute.SetSelectValue(axis, config, props.Enabled)
|
enabledLabelAttribute.SetSelectValue(axis, config, props.Enabled)
|
||||||
}
|
}
|
||||||
parseSrcs(ctx, axis, config, props.Srcs)
|
parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isStatic {
|
if isStatic {
|
||||||
@@ -284,11 +290,16 @@ func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func bp2BuildPropParseHelper(ctx android.ArchVariantContext, module *Module, propsType interface{}, parseFunc func(axis bazel.ConfigurationAxis, config string, props interface{})) {
|
func bp2BuildParsePrebuiltBinaryProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes {
|
||||||
for axis, configToProps := range module.GetArchVariantProperties(ctx, propsType) {
|
var srcLabelAttribute bazel.LabelAttribute
|
||||||
for config, props := range configToProps {
|
bp2BuildPropParseHelper(ctx, module, &prebuiltLinkerProperties{}, func(axis bazel.ConfigurationAxis, config string, props interface{}) {
|
||||||
parseFunc(axis, config, props)
|
if props, ok := props.(*prebuiltLinkerProperties); ok {
|
||||||
|
parseSrc(ctx, &srcLabelAttribute, axis, config, props.Srcs)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return prebuiltAttributes{
|
||||||
|
Src: srcLabelAttribute,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
cc/cc.go
4
cc/cc.go
@@ -3714,7 +3714,9 @@ func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|||||||
prebuilt := c.IsPrebuilt()
|
prebuilt := c.IsPrebuilt()
|
||||||
switch c.typ() {
|
switch c.typ() {
|
||||||
case binary:
|
case binary:
|
||||||
if !prebuilt {
|
if prebuilt {
|
||||||
|
prebuiltBinaryBp2Build(ctx, c)
|
||||||
|
} else {
|
||||||
binaryBp2build(ctx, c)
|
binaryBp2build(ctx, c)
|
||||||
}
|
}
|
||||||
case testBin:
|
case testBin:
|
||||||
|
@@ -289,6 +289,16 @@ type stripAttributes struct {
|
|||||||
None 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.TopDownMutatorContext, m *Module) {
|
func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||||
// For some cc_library modules, their static variants are ready to be
|
// For some cc_library modules, their static variants are ready to be
|
||||||
// converted, but not their shared variants. For these modules, delegate to
|
// converted, but not their shared variants. For these modules, delegate to
|
||||||
@@ -395,13 +405,7 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
|
|
||||||
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
||||||
|
|
||||||
Strip: stripAttributes{
|
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
||||||
Keep_symbols: linkerAttrs.stripKeepSymbols,
|
|
||||||
Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame,
|
|
||||||
Keep_symbols_list: linkerAttrs.stripKeepSymbolsList,
|
|
||||||
All: linkerAttrs.stripAll,
|
|
||||||
None: linkerAttrs.stripNone,
|
|
||||||
},
|
|
||||||
Features: baseAttributes.features,
|
Features: baseAttributes.features,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2839,13 +2843,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||||||
Absolute_includes: compilerAttrs.absoluteIncludes,
|
Absolute_includes: compilerAttrs.absoluteIncludes,
|
||||||
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
|
||||||
|
|
||||||
Strip: stripAttributes{
|
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
|
||||||
Keep_symbols: linkerAttrs.stripKeepSymbols,
|
|
||||||
Keep_symbols_and_debug_frame: linkerAttrs.stripKeepSymbolsAndDebugFrame,
|
|
||||||
Keep_symbols_list: linkerAttrs.stripKeepSymbolsList,
|
|
||||||
All: linkerAttrs.stripAll,
|
|
||||||
None: linkerAttrs.stripNone,
|
|
||||||
},
|
|
||||||
|
|
||||||
Features: baseAttributes.features,
|
Features: baseAttributes.features,
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ func RegisterPrebuiltBuildComponents(ctx android.RegistrationContext) {
|
|||||||
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
|
ctx.RegisterModuleType("cc_prebuilt_library_static", PrebuiltStaticLibraryFactory)
|
||||||
ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory)
|
ctx.RegisterModuleType("cc_prebuilt_test_library_shared", PrebuiltSharedTestLibraryFactory)
|
||||||
ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory)
|
ctx.RegisterModuleType("cc_prebuilt_object", prebuiltObjectFactory)
|
||||||
ctx.RegisterModuleType("cc_prebuilt_binary", prebuiltBinaryFactory)
|
ctx.RegisterModuleType("cc_prebuilt_binary", PrebuiltBinaryFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type prebuiltLinkerInterface interface {
|
type prebuiltLinkerInterface interface {
|
||||||
@@ -668,8 +668,8 @@ func (p *prebuiltBinaryLinker) binary() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cc_prebuilt_binary installs a precompiled executable in srcs property in the
|
// cc_prebuilt_binary installs a precompiled executable in srcs property in the
|
||||||
// device's directory.
|
// device's directory, for both the host and device
|
||||||
func prebuiltBinaryFactory() android.Module {
|
func PrebuiltBinaryFactory() android.Module {
|
||||||
module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported)
|
module, _ := NewPrebuiltBinary(android.HostAndDeviceSupported)
|
||||||
return module.Init()
|
return module.Init()
|
||||||
}
|
}
|
||||||
@@ -690,6 +690,30 @@ func NewPrebuiltBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecor
|
|||||||
return module, binary
|
return module, binary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bazelPrebuiltBinaryAttributes struct {
|
||||||
|
Src bazel.LabelAttribute
|
||||||
|
Strip stripAttributes
|
||||||
|
}
|
||||||
|
|
||||||
|
func prebuiltBinaryBp2Build(ctx android.TopDownMutatorContext, 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())
|
||||||
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
|
||||||
|
}
|
||||||
|
|
||||||
type Sanitized struct {
|
type Sanitized struct {
|
||||||
None struct {
|
None struct {
|
||||||
Srcs []string `android:"path,arch_variant"`
|
Srcs []string `android:"path,arch_variant"`
|
||||||
|
Reference in New Issue
Block a user