Loading bp2build/cc_library_static_conversion_test.go +72 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import ( "android/soong/android" "android/soong/cc" "android/soong/genrule" "fmt" "testing" ) Loading Loading @@ -1489,3 +1490,72 @@ func TestCcLibraryStaticStdInFlags(t *testing.T) { }, }) } func TestCcLibraryStaticStl(t *testing.T) { testCases := []struct { desc string prop string attr attrNameToString }{ { desc: "c++_shared deduped to libc++", prop: `stl: "c++_shared",`, attr: attrNameToString{ "stl": `"libc++"`, }, }, { desc: "libc++ to libc++", prop: `stl: "libc++",`, attr: attrNameToString{ "stl": `"libc++"`, }, }, { desc: "c++_static to libc++_static", prop: `stl: "c++_static",`, attr: attrNameToString{ "stl": `"libc++_static"`, }, }, { desc: "libc++_static to libc++_static", prop: `stl: "libc++_static",`, attr: attrNameToString{ "stl": `"libc++_static"`, }, }, { desc: "system to system", prop: `stl: "system",`, attr: attrNameToString{ "stl": `"system"`, }, }, { desc: "none to none", prop: `stl: "none",`, attr: attrNameToString{ "stl": `"none"`, }, }, { desc: "empty to empty", attr: attrNameToString{}, }, } for _, tc := range testCases { t.Run(tc.desc, func(*testing.T) { runCcLibraryStaticTestCase(t, bp2buildTestCase{ blueprint: fmt.Sprintf(`cc_library_static { name: "foo", include_build_directory: false, %s }`, tc.prop), expectedBazelTargets: []string{ makeBazelTarget("cc_library_static", "foo", tc.attr), }, }) }) } } cc/bp2build.go +2 −1 Original line number Diff line number Diff line Loading @@ -376,7 +376,8 @@ func (ca *compilerAttributes) convertStlProps(ctx android.ArchVariantContext, mo return } if ca.stl == nil { ca.stl = stlProps.Stl stl := deduplicateStlInput(*stlProps.Stl) ca.stl = &stl } else if ca.stl != stlProps.Stl { ctx.ModuleErrorf("Unsupported conversion: module with different stl for different variants: %s and %s", *ca.stl, stlProps.Stl) } Loading cc/stl.go +14 −12 Original line number Diff line number Diff line Loading @@ -25,6 +25,16 @@ func getNdkStlFamily(m LinkableInterface) string { return family } func deduplicateStlInput(stl string) string { switch stl { case "c++_shared": return "libc++" case "c++_static": return "libc++_static" } return stl } func getNdkStlFamilyAndLinkType(m LinkableInterface) (string, string) { stl := m.SelectedStl() switch stl { Loading Loading @@ -66,18 +76,18 @@ func (stl *stl) begin(ctx BaseModuleContext) { } else if ctx.header() { s = "none" } if s == "none" { return "" } s = deduplicateStlInput(s) if ctx.useSdk() && ctx.Device() { switch s { case "", "system": return "ndk_system" case "c++_shared", "c++_static": return "ndk_lib" + s case "libc++": return "ndk_libc++_shared" case "libc++_static": return "ndk_libc++_static" case "none": return "" default: ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", s) return "" Loading @@ -87,8 +97,6 @@ func (stl *stl) begin(ctx BaseModuleContext) { case "libc++", "libc++_static", "": // Only use static libc++ for Windows. return "libc++_static" case "none": return "" default: ctx.ModuleErrorf("stl: %q is not a supported STL for windows", s) return "" Loading @@ -97,12 +105,6 @@ func (stl *stl) begin(ctx BaseModuleContext) { switch s { case "libc++", "libc++_static": return s case "c++_shared": return "libc++" case "c++_static": return "libc++_static" case "none": return "" case "", "system": if ctx.static() { return "libc++_static" Loading Loading
bp2build/cc_library_static_conversion_test.go +72 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import ( "android/soong/android" "android/soong/cc" "android/soong/genrule" "fmt" "testing" ) Loading Loading @@ -1489,3 +1490,72 @@ func TestCcLibraryStaticStdInFlags(t *testing.T) { }, }) } func TestCcLibraryStaticStl(t *testing.T) { testCases := []struct { desc string prop string attr attrNameToString }{ { desc: "c++_shared deduped to libc++", prop: `stl: "c++_shared",`, attr: attrNameToString{ "stl": `"libc++"`, }, }, { desc: "libc++ to libc++", prop: `stl: "libc++",`, attr: attrNameToString{ "stl": `"libc++"`, }, }, { desc: "c++_static to libc++_static", prop: `stl: "c++_static",`, attr: attrNameToString{ "stl": `"libc++_static"`, }, }, { desc: "libc++_static to libc++_static", prop: `stl: "libc++_static",`, attr: attrNameToString{ "stl": `"libc++_static"`, }, }, { desc: "system to system", prop: `stl: "system",`, attr: attrNameToString{ "stl": `"system"`, }, }, { desc: "none to none", prop: `stl: "none",`, attr: attrNameToString{ "stl": `"none"`, }, }, { desc: "empty to empty", attr: attrNameToString{}, }, } for _, tc := range testCases { t.Run(tc.desc, func(*testing.T) { runCcLibraryStaticTestCase(t, bp2buildTestCase{ blueprint: fmt.Sprintf(`cc_library_static { name: "foo", include_build_directory: false, %s }`, tc.prop), expectedBazelTargets: []string{ makeBazelTarget("cc_library_static", "foo", tc.attr), }, }) }) } }
cc/bp2build.go +2 −1 Original line number Diff line number Diff line Loading @@ -376,7 +376,8 @@ func (ca *compilerAttributes) convertStlProps(ctx android.ArchVariantContext, mo return } if ca.stl == nil { ca.stl = stlProps.Stl stl := deduplicateStlInput(*stlProps.Stl) ca.stl = &stl } else if ca.stl != stlProps.Stl { ctx.ModuleErrorf("Unsupported conversion: module with different stl for different variants: %s and %s", *ca.stl, stlProps.Stl) } Loading
cc/stl.go +14 −12 Original line number Diff line number Diff line Loading @@ -25,6 +25,16 @@ func getNdkStlFamily(m LinkableInterface) string { return family } func deduplicateStlInput(stl string) string { switch stl { case "c++_shared": return "libc++" case "c++_static": return "libc++_static" } return stl } func getNdkStlFamilyAndLinkType(m LinkableInterface) (string, string) { stl := m.SelectedStl() switch stl { Loading Loading @@ -66,18 +76,18 @@ func (stl *stl) begin(ctx BaseModuleContext) { } else if ctx.header() { s = "none" } if s == "none" { return "" } s = deduplicateStlInput(s) if ctx.useSdk() && ctx.Device() { switch s { case "", "system": return "ndk_system" case "c++_shared", "c++_static": return "ndk_lib" + s case "libc++": return "ndk_libc++_shared" case "libc++_static": return "ndk_libc++_static" case "none": return "" default: ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", s) return "" Loading @@ -87,8 +97,6 @@ func (stl *stl) begin(ctx BaseModuleContext) { case "libc++", "libc++_static", "": // Only use static libc++ for Windows. return "libc++_static" case "none": return "" default: ctx.ModuleErrorf("stl: %q is not a supported STL for windows", s) return "" Loading @@ -97,12 +105,6 @@ func (stl *stl) begin(ctx BaseModuleContext) { switch s { case "libc++", "libc++_static": return s case "c++_shared": return "libc++" case "c++_static": return "libc++_static" case "none": return "" case "", "system": if ctx.static() { return "libc++_static" Loading