Loading bp2build/cc_library_conversion_test.go +40 −2 Original line number Diff line number Diff line Loading @@ -1692,7 +1692,7 @@ cc_library { } func TestCcLibraryCppStdWithGnuExtensions_ConvertstoCopt(t *testing.T) { func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { type testCase struct { cpp_std string gnu_extensions string Loading Loading @@ -1751,7 +1751,7 @@ func TestCcLibraryCppStdWithGnuExtensions_ConvertstoCopt(t *testing.T) { } bazelCppStdAttr := "" if tc.bazel_cpp_std != "" { bazelCppStdAttr = fmt.Sprintf("\n copts = [\"-std=%s\"],", tc.bazel_cpp_std) bazelCppStdAttr = fmt.Sprintf("\n cpp_std = \"%s\",", tc.bazel_cpp_std) } runCcLibraryTestCase(t, bp2buildTestCase{ Loading @@ -1770,6 +1770,44 @@ cc_library { `, cppStdAttr, gnuExtensionsAttr), expectedBazelTargets: []string{fmt.Sprintf(`cc_library( name = "a",%s )`, bazelCppStdAttr)}, }) runCcLibraryStaticTestCase(t, bp2buildTestCase{ description: fmt.Sprintf( "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), moduleTypeUnderTest: "cc_library_static", moduleTypeUnderTestFactory: cc.LibraryStaticFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, blueprint: soongCcLibraryPreamble + fmt.Sprintf(` cc_library_static { name: "a", %s // cpp_std: *string %s // gnu_extensions: *bool include_build_directory: false, } `, cppStdAttr, gnuExtensionsAttr), expectedBazelTargets: []string{fmt.Sprintf(`cc_library_static( name = "a",%s )`, bazelCppStdAttr)}, }) runCcLibrarySharedTestCase(t, bp2buildTestCase{ description: fmt.Sprintf( "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), moduleTypeUnderTest: "cc_library_shared", moduleTypeUnderTestFactory: cc.LibrarySharedFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, blueprint: soongCcLibraryPreamble + fmt.Sprintf(` cc_library_shared { name: "a", %s // cpp_std: *string %s // gnu_extensions: *bool include_build_directory: false, } `, cppStdAttr, gnuExtensionsAttr), expectedBazelTargets: []string{fmt.Sprintf(`cc_library_shared( name = "a",%s )`, bazelCppStdAttr)}, }) } Loading cc/bp2build.go +12 −5 Original line number Diff line number Diff line Loading @@ -226,7 +226,10 @@ type compilerAttributes struct { srcs bazel.LabelListAttribute rtti bazel.BoolAttribute // Not affected by arch variants stl *string cppStd *string localIncludes bazel.StringListAttribute absoluteIncludes bazel.StringListAttribute Loading @@ -242,6 +245,8 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul var rtti bazel.BoolAttribute var localIncludes bazel.StringListAttribute var absoluteIncludes bazel.StringListAttribute var stl *string = nil var cppStd *string = nil parseCommandLineFlags := func(soongFlags []string) []string { var result []string Loading Loading @@ -283,7 +288,6 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul srcs.SetSelectValue(axis, config, srcsList) } var archVariantCopts []string if axis == bazel.NoConfigAxis { // If cpp_std is not specified, don't generate it in the // BUILD file. For readability purposes, cpp_std and gnu_extensions are Loading @@ -295,11 +299,14 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul // These transformations are shared with compiler.go. cppStdVal := parseCppStd(baseCompilerProps.Cpp_std) _, cppStdVal = maybeReplaceGnuToC(baseCompilerProps.Gnu_extensions, "", cppStdVal) archVariantCopts = append(archVariantCopts, "-std="+cppStdVal) cppStd = &cppStdVal } else if baseCompilerProps.Gnu_extensions != nil && !*baseCompilerProps.Gnu_extensions { archVariantCopts = append(archVariantCopts, "-std=c++17") cppStdVal := "c++17" cppStd = &cppStdVal } } var archVariantCopts []string archVariantCopts = append(archVariantCopts, parseCommandLineFlags(baseCompilerProps.Cflags)...) archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags) Loading Loading @@ -345,7 +352,6 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs) var stl *string = nil stlPropsByArch := module.GetArchVariantProperties(ctx, &StlProperties{}) for _, configToProps := range stlPropsByArch { for _, props := range configToProps { Loading Loading @@ -373,6 +379,7 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul cppFlags: cppFlags, rtti: rtti, stl: stl, cppStd: cppStd, localIncludes: localIncludes, absoluteIncludes: absoluteIncludes, } Loading cc/library.go +8 −1 Original line number Diff line number Diff line Loading @@ -248,7 +248,9 @@ type bazelCcLibraryAttributes struct { Linkopts bazel.StringListAttribute Use_libcrt bazel.BoolAttribute Rtti bazel.BoolAttribute Stl *string Cpp_std *string // This is shared only. Version_script bazel.LabelAttribute Loading Loading @@ -328,6 +330,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { Use_libcrt: linkerAttrs.useLibcrt, Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd, Version_script: linkerAttrs.versionScript, Loading Loading @@ -2403,6 +2406,7 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, Use_libcrt: linkerAttrs.useLibcrt, Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd, Export_includes: exportedIncludes.Includes, Export_system_includes: exportedIncludes.SystemIncludes, Local_includes: compilerAttrs.localIncludes, Loading @@ -2427,6 +2431,7 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, Use_libcrt: linkerAttrs.useLibcrt, Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd, Export_includes: exportedIncludes.Includes, Export_system_includes: exportedIncludes.SystemIncludes, Loading Loading @@ -2462,6 +2467,7 @@ type bazelCcLibraryStaticAttributes struct { Use_libcrt bazel.BoolAttribute Rtti bazel.BoolAttribute Stl *string Cpp_std *string Export_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute Loading Loading @@ -2489,6 +2495,7 @@ type bazelCcLibrarySharedAttributes struct { Use_libcrt bazel.BoolAttribute Rtti bazel.BoolAttribute Stl *string Cpp_std *string Export_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute Loading Loading
bp2build/cc_library_conversion_test.go +40 −2 Original line number Diff line number Diff line Loading @@ -1692,7 +1692,7 @@ cc_library { } func TestCcLibraryCppStdWithGnuExtensions_ConvertstoCopt(t *testing.T) { func TestCcLibraryCppStdWithGnuExtensions_ConvertsToFeatureAttr(t *testing.T) { type testCase struct { cpp_std string gnu_extensions string Loading Loading @@ -1751,7 +1751,7 @@ func TestCcLibraryCppStdWithGnuExtensions_ConvertstoCopt(t *testing.T) { } bazelCppStdAttr := "" if tc.bazel_cpp_std != "" { bazelCppStdAttr = fmt.Sprintf("\n copts = [\"-std=%s\"],", tc.bazel_cpp_std) bazelCppStdAttr = fmt.Sprintf("\n cpp_std = \"%s\",", tc.bazel_cpp_std) } runCcLibraryTestCase(t, bp2buildTestCase{ Loading @@ -1770,6 +1770,44 @@ cc_library { `, cppStdAttr, gnuExtensionsAttr), expectedBazelTargets: []string{fmt.Sprintf(`cc_library( name = "a",%s )`, bazelCppStdAttr)}, }) runCcLibraryStaticTestCase(t, bp2buildTestCase{ description: fmt.Sprintf( "cc_library_static with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), moduleTypeUnderTest: "cc_library_static", moduleTypeUnderTestFactory: cc.LibraryStaticFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build, blueprint: soongCcLibraryPreamble + fmt.Sprintf(` cc_library_static { name: "a", %s // cpp_std: *string %s // gnu_extensions: *bool include_build_directory: false, } `, cppStdAttr, gnuExtensionsAttr), expectedBazelTargets: []string{fmt.Sprintf(`cc_library_static( name = "a",%s )`, bazelCppStdAttr)}, }) runCcLibrarySharedTestCase(t, bp2buildTestCase{ description: fmt.Sprintf( "cc_library_shared with cpp_std: %s and gnu_extensions: %s", tc.cpp_std, tc.gnu_extensions), moduleTypeUnderTest: "cc_library_shared", moduleTypeUnderTestFactory: cc.LibrarySharedFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibrarySharedBp2Build, blueprint: soongCcLibraryPreamble + fmt.Sprintf(` cc_library_shared { name: "a", %s // cpp_std: *string %s // gnu_extensions: *bool include_build_directory: false, } `, cppStdAttr, gnuExtensionsAttr), expectedBazelTargets: []string{fmt.Sprintf(`cc_library_shared( name = "a",%s )`, bazelCppStdAttr)}, }) } Loading
cc/bp2build.go +12 −5 Original line number Diff line number Diff line Loading @@ -226,7 +226,10 @@ type compilerAttributes struct { srcs bazel.LabelListAttribute rtti bazel.BoolAttribute // Not affected by arch variants stl *string cppStd *string localIncludes bazel.StringListAttribute absoluteIncludes bazel.StringListAttribute Loading @@ -242,6 +245,8 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul var rtti bazel.BoolAttribute var localIncludes bazel.StringListAttribute var absoluteIncludes bazel.StringListAttribute var stl *string = nil var cppStd *string = nil parseCommandLineFlags := func(soongFlags []string) []string { var result []string Loading Loading @@ -283,7 +288,6 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul srcs.SetSelectValue(axis, config, srcsList) } var archVariantCopts []string if axis == bazel.NoConfigAxis { // If cpp_std is not specified, don't generate it in the // BUILD file. For readability purposes, cpp_std and gnu_extensions are Loading @@ -295,11 +299,14 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul // These transformations are shared with compiler.go. cppStdVal := parseCppStd(baseCompilerProps.Cpp_std) _, cppStdVal = maybeReplaceGnuToC(baseCompilerProps.Gnu_extensions, "", cppStdVal) archVariantCopts = append(archVariantCopts, "-std="+cppStdVal) cppStd = &cppStdVal } else if baseCompilerProps.Gnu_extensions != nil && !*baseCompilerProps.Gnu_extensions { archVariantCopts = append(archVariantCopts, "-std=c++17") cppStdVal := "c++17" cppStd = &cppStdVal } } var archVariantCopts []string archVariantCopts = append(archVariantCopts, parseCommandLineFlags(baseCompilerProps.Cflags)...) archVariantAsflags := parseCommandLineFlags(baseCompilerProps.Asflags) Loading Loading @@ -345,7 +352,6 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul srcs, cSrcs, asSrcs := groupSrcsByExtension(ctx, srcs) var stl *string = nil stlPropsByArch := module.GetArchVariantProperties(ctx, &StlProperties{}) for _, configToProps := range stlPropsByArch { for _, props := range configToProps { Loading Loading @@ -373,6 +379,7 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul cppFlags: cppFlags, rtti: rtti, stl: stl, cppStd: cppStd, localIncludes: localIncludes, absoluteIncludes: absoluteIncludes, } Loading
cc/library.go +8 −1 Original line number Diff line number Diff line Loading @@ -248,7 +248,9 @@ type bazelCcLibraryAttributes struct { Linkopts bazel.StringListAttribute Use_libcrt bazel.BoolAttribute Rtti bazel.BoolAttribute Stl *string Cpp_std *string // This is shared only. Version_script bazel.LabelAttribute Loading Loading @@ -328,6 +330,7 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) { Use_libcrt: linkerAttrs.useLibcrt, Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd, Version_script: linkerAttrs.versionScript, Loading Loading @@ -2403,6 +2406,7 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, Use_libcrt: linkerAttrs.useLibcrt, Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd, Export_includes: exportedIncludes.Includes, Export_system_includes: exportedIncludes.SystemIncludes, Local_includes: compilerAttrs.localIncludes, Loading @@ -2427,6 +2431,7 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext, Use_libcrt: linkerAttrs.useLibcrt, Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd, Export_includes: exportedIncludes.Includes, Export_system_includes: exportedIncludes.SystemIncludes, Loading Loading @@ -2462,6 +2467,7 @@ type bazelCcLibraryStaticAttributes struct { Use_libcrt bazel.BoolAttribute Rtti bazel.BoolAttribute Stl *string Cpp_std *string Export_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute Loading Loading @@ -2489,6 +2495,7 @@ type bazelCcLibrarySharedAttributes struct { Use_libcrt bazel.BoolAttribute Rtti bazel.BoolAttribute Stl *string Cpp_std *string Export_includes bazel.StringListAttribute Export_system_includes bazel.StringListAttribute Loading