Add libbuildversion in converion instead of macro
Test: bp2build.sh Change-Id: I96fa6e4dda7d54224a20bcb35414d61c6f70cf7e
This commit is contained in:
@@ -45,6 +45,7 @@ func generateBazelTargetsForTest(targets []testBazelTarget, hod android.HostOrDe
|
||||
|
||||
type ccBinaryBp2buildTestCase struct {
|
||||
description string
|
||||
filesystem map[string]string
|
||||
blueprint string
|
||||
targets []testBazelTarget
|
||||
}
|
||||
@@ -79,6 +80,7 @@ func runCcBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) {
|
||||
ModuleTypeUnderTestFactory: cc.BinaryFactory,
|
||||
Description: description,
|
||||
Blueprint: binaryReplacer.Replace(testCase.blueprint),
|
||||
Filesystem: testCase.filesystem,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -94,6 +96,7 @@ func runCcHostBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) {
|
||||
ModuleTypeUnderTestFactory: cc.BinaryHostFactory,
|
||||
Description: description,
|
||||
Blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
|
||||
Filesystem: testCase.filesystem,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -101,6 +104,9 @@ func runCcHostBinaryTestCase(t *testing.T, testCase ccBinaryBp2buildTestCase) {
|
||||
func TestBasicCcBinary(t *testing.T) {
|
||||
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
|
||||
description: "basic -- properties -> attrs with little/no transformation",
|
||||
filesystem: map[string]string{
|
||||
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
||||
},
|
||||
blueprint: `
|
||||
{rule_name} {
|
||||
name: "foo",
|
||||
@@ -149,6 +155,7 @@ func TestBasicCcBinary(t *testing.T) {
|
||||
"sdk_version": `"current"`,
|
||||
"min_sdk_version": `"29"`,
|
||||
"use_version_lib": `True`,
|
||||
"whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@@ -27,7 +27,16 @@ const (
|
||||
soongCcLibraryPreamble = `
|
||||
cc_defaults {
|
||||
name: "linux_bionic_supported",
|
||||
}`
|
||||
}
|
||||
`
|
||||
|
||||
soongCcVersionLibBpPath = "build/soong/cc/libbuildversion/Android.bp"
|
||||
soongCcVersionLibBp = `
|
||||
cc_library_static {
|
||||
name: "libbuildversion",
|
||||
bazel_module: { bp2build_available: false },
|
||||
}
|
||||
`
|
||||
|
||||
soongCcProtoLibraries = `
|
||||
cc_library {
|
||||
@@ -62,6 +71,7 @@ func TestCcLibrarySimple(t *testing.T) {
|
||||
ModuleTypeUnderTest: "cc_library",
|
||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||
Filesystem: map[string]string{
|
||||
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
||||
"android.cpp": "",
|
||||
"bionic.cpp": "",
|
||||
"darwin.cpp": "",
|
||||
@@ -146,6 +156,7 @@ cc_library {
|
||||
"sdk_version": `"current"`,
|
||||
"min_sdk_version": `"29"`,
|
||||
"use_version_lib": `True`,
|
||||
"implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
||||
}),
|
||||
})
|
||||
}
|
||||
@@ -1337,6 +1348,7 @@ func makeCcLibraryTargets(name string, attrs AttrNameToString) []string {
|
||||
"strip": true,
|
||||
"inject_bssl_hash": true,
|
||||
"has_stubs": true,
|
||||
"use_version_lib": true,
|
||||
}
|
||||
|
||||
sharedAttrs := AttrNameToString{}
|
||||
|
@@ -454,6 +454,9 @@ func TestCcLibrarySharedProto(t *testing.T) {
|
||||
|
||||
func TestCcLibrarySharedUseVersionLib(t *testing.T) {
|
||||
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||
Filesystem: map[string]string{
|
||||
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
||||
},
|
||||
Blueprint: soongCcProtoPreamble + `cc_library_shared {
|
||||
name: "foo",
|
||||
use_version_lib: true,
|
||||
@@ -462,6 +465,7 @@ func TestCcLibrarySharedUseVersionLib(t *testing.T) {
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||
"use_version_lib": "True",
|
||||
"implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
@@ -1485,14 +1485,37 @@ func TestCcLibraryStaticProto(t *testing.T) {
|
||||
|
||||
func TestCcLibraryStaticUseVersionLib(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Filesystem: map[string]string{
|
||||
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
||||
},
|
||||
Blueprint: soongCcProtoPreamble + `cc_library_static {
|
||||
name: "foo",
|
||||
use_version_lib: true,
|
||||
static_libs: ["libbuildversion"],
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"use_version_lib": "True",
|
||||
"implementation_whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestCcLibraryStaticUseVersionLibHasDep(t *testing.T) {
|
||||
runCcLibraryStaticTestCase(t, Bp2buildTestCase{
|
||||
Filesystem: map[string]string{
|
||||
soongCcVersionLibBpPath: soongCcVersionLibBp,
|
||||
},
|
||||
Blueprint: soongCcProtoPreamble + `cc_library_static {
|
||||
name: "foo",
|
||||
use_version_lib: true,
|
||||
whole_static_libs: ["libbuildversion"],
|
||||
include_build_directory: false,
|
||||
}`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||
"whole_archive_deps": `["//build/soong/cc/libbuildversion:libbuildversion"]`,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
@@ -838,6 +838,7 @@ type linkerAttributes struct {
|
||||
|
||||
var (
|
||||
soongSystemSharedLibs = []string{"libc", "libm", "libdl"}
|
||||
versionLib = "libbuildversion"
|
||||
)
|
||||
|
||||
// resolveTargetApex re-adds the shared and static libs in target.apex.exclude_shared|static_libs props to non-apex variant
|
||||
@@ -877,10 +878,27 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion
|
||||
var axisFeatures []string
|
||||
|
||||
wholeStaticLibs := android.FirstUniqueStrings(props.Whole_static_libs)
|
||||
la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs))
|
||||
staticLibs := android.FirstUniqueStrings(android.RemoveListFromList(props.Static_libs, wholeStaticLibs))
|
||||
if axis == bazel.NoConfigAxis {
|
||||
la.useVersionLib.SetSelectValue(axis, config, props.Use_version_lib)
|
||||
if proptools.Bool(props.Use_version_lib) {
|
||||
versionLibAlreadyInDeps := android.InList(versionLib, wholeStaticLibs)
|
||||
// remove from static libs so there is no duplicate dependency
|
||||
_, staticLibs = android.RemoveFromList(versionLib, staticLibs)
|
||||
// only add the dep if it is not in progress
|
||||
if !versionLibAlreadyInDeps {
|
||||
if isBinary {
|
||||
wholeStaticLibs = append(wholeStaticLibs, versionLib)
|
||||
} else {
|
||||
la.implementationWholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, []string{versionLib}, props.Exclude_static_libs))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Excludes to parallel Soong:
|
||||
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
|
||||
staticLibs := android.FirstUniqueStrings(android.RemoveListFromList(props.Static_libs, wholeStaticLibs))
|
||||
la.wholeArchiveDeps.SetSelectValue(axis, config, bazelLabelForWholeDepsExcludes(ctx, wholeStaticLibs, props.Exclude_static_libs))
|
||||
|
||||
staticDeps := maybePartitionExportedAndImplementationsDepsExcludes(
|
||||
ctx,
|
||||
@@ -1006,10 +1024,6 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion
|
||||
la.linkopts.SetSelectValue(axis, config, parseCommandLineFlags(linkerFlags, false, filterOutClangUnknownCflags))
|
||||
la.useLibcrt.SetSelectValue(axis, config, props.libCrt())
|
||||
|
||||
if axis == bazel.NoConfigAxis {
|
||||
la.useVersionLib.SetSelectValue(axis, config, props.Use_version_lib)
|
||||
}
|
||||
|
||||
// it's very unlikely for nocrt to be arch variant, so bp2build doesn't support it.
|
||||
if props.crt() != nil {
|
||||
if axis == bazel.NoConfigAxis {
|
||||
|
@@ -367,7 +367,6 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
Stl: compilerAttrs.stl,
|
||||
Cpp_std: compilerAttrs.cppStd,
|
||||
C_std: compilerAttrs.cStd,
|
||||
Use_version_lib: linkerAttrs.useVersionLib,
|
||||
|
||||
Features: baseAttributes.features,
|
||||
}
|
||||
@@ -2632,7 +2631,6 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
||||
staticOrSharedAttributes: commonAttrs,
|
||||
|
||||
Use_libcrt: linkerAttrs.useLibcrt,
|
||||
Use_version_lib: linkerAttrs.useVersionLib,
|
||||
|
||||
Rtti: compilerAttrs.rtti,
|
||||
Stl: compilerAttrs.stl,
|
||||
|
Reference in New Issue
Block a user