diff options
| author | 2023-05-16 02:48:53 +0000 | |
|---|---|---|
| committer | 2023-05-16 02:48:53 +0000 | |
| commit | 29c8ad3821cae095ea397ae75d2cb93e96094c8e (patch) | |
| tree | c286edd446339d2f998dd9f1d9befddfe0f9c7cb | |
| parent | be981e5e0755e6ef9e70e106d022d4edc2956cd4 (diff) | |
| parent | df4c2134ea59886cde76916b8da79863499482d1 (diff) | |
Merge "bp2build converter for cc libraries containing yacc"
| -rw-r--r-- | bp2build/cc_library_conversion_test.go | 56 | ||||
| -rw-r--r-- | cc/bp2build.go | 67 |
2 files changed, 123 insertions, 0 deletions
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 1b681efb0..37d6da260 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -4519,3 +4519,59 @@ func TestCcLibraryCppFlagsInProductVariables(t *testing.T) { }, ) } + +func TestCcLibraryYaccConversion(t *testing.T) { + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library is built from .y/.yy files", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: soongCcLibraryPreamble + `cc_library { + name: "a", + srcs: [ + "a.cpp", + "a.yy", + ], + shared_libs: ["sharedlib"], + static_libs: ["staticlib"], + yacc: { + flags: ["someYaccFlag"], + gen_location_hh: true, + gen_position_hh: true, + }, +} +cc_library_static { + name: "staticlib", + bazel_module: { bp2build_available: false }, +} +cc_library { + name: "sharedlib", + bazel_module: { bp2build_available: false }, +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("cc_yacc_static_library", "a_yacc", AttrNameToString{ + "src": `"a.yy"`, + "implementation_deps": `[":staticlib"]`, + "implementation_dynamic_deps": `[":sharedlib"]`, + "flags": `["someYaccFlag"]`, + "gen_location_hh": "True", + "gen_position_hh": "True", + "local_includes": `["."]`, + }), + MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ + "srcs": `["a.cpp"]`, + "implementation_deps": `[":staticlib"]`, + "implementation_dynamic_deps": `[":sharedlib"]`, + "implementation_whole_archive_deps": `[":a_yacc"]`, + "local_includes": `["."]`, + }), + MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{ + "srcs": `["a.cpp"]`, + "implementation_deps": `[":staticlib"]`, + "implementation_dynamic_deps": `[":sharedlib"]`, + "implementation_whole_archive_deps": `[":a_yacc"]`, + "local_includes": `["."]`, + }), + }, + }) +} diff --git a/cc/bp2build.go b/cc/bp2build.go index cf5f74d4d..fcc85071e 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -38,6 +38,7 @@ const ( protoSrcPartition = "proto" aidlSrcPartition = "aidl" syspropSrcPartition = "sysprop" + yaccSrcPartition = "yacc" stubsSuffix = "_stub_libs_current" ) @@ -154,6 +155,7 @@ func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.Lab // know the language of these sources until the genrule is executed. cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true}, syspropSrcPartition: bazel.LabelPartition{Extensions: []string{".sysprop"}}, + yaccSrcPartition: bazel.LabelPartition{Extensions: []string{".y", "yy"}}, } return bazel.PartitionLabelListAttribute(ctx, &srcs, labels) @@ -404,6 +406,12 @@ type compilerAttributes struct { // Sysprop sources syspropSrcs bazel.LabelListAttribute + // Yacc sources + yaccSrc *bazel.LabelAttribute + yaccFlags bazel.StringListAttribute + yaccGenLocationHeader bazel.BoolAttribute + yaccGenPositionHeader bazel.BoolAttribute + hdrs bazel.LabelListAttribute rtti bazel.BoolAttribute @@ -566,6 +574,12 @@ func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, i ca.asmSrcs = partitionedSrcs[asmSrcPartition] ca.lSrcs = partitionedSrcs[lSrcPartition] ca.llSrcs = partitionedSrcs[llSrcPartition] + if yacc := partitionedSrcs[yaccSrcPartition]; !yacc.IsEmpty() { + if len(yacc.Value.Includes) > 1 { + ctx.PropertyErrorf("srcs", "Found multiple yacc (.y/.yy) files in library") + } + ca.yaccSrc = bazel.MakeLabelAttribute(yacc.Value.Includes[0].Label) + } ca.syspropSrcs = partitionedSrcs[syspropSrcPartition] ca.absoluteIncludes.DeduplicateAxesFromBase() @@ -742,6 +756,11 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) if baseCompilerProps.Lex != nil { compilerAttrs.lexopts.SetSelectValue(axis, cfg, baseCompilerProps.Lex.Flags) } + if baseCompilerProps.Yacc != nil { + compilerAttrs.yaccFlags.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Flags) + compilerAttrs.yaccGenLocationHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_location_hh) + compilerAttrs.yaccGenPositionHeader.SetSelectValue(axis, cfg, baseCompilerProps.Yacc.Gen_position_hh) + } (&compilerAttrs).bp2buildForAxisAndConfig(ctx, axis, cfg, baseCompilerProps) } @@ -826,6 +845,12 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) } } + // Create a cc_yacc_static_library if srcs contains .y/.yy files + // This internal target will produce an .a file that will be statically linked to the parent library + if yaccDep := bp2buildCcYaccLibrary(ctx, compilerAttrs, linkerAttrs); yaccDep != nil { + (&linkerAttrs).implementationWholeArchiveDeps.Add(yaccDep) + } + convertedLSrcs := bp2BuildLex(ctx, module.Name(), compilerAttrs) (&compilerAttrs).srcs.Add(&convertedLSrcs.srcName) (&compilerAttrs).cSrcs.Add(&convertedLSrcs.cSrcName) @@ -864,6 +889,48 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) } } +type ccYaccLibraryAttributes struct { + Src bazel.LabelAttribute + Flags bazel.StringListAttribute + Gen_location_hh bazel.BoolAttribute + Gen_position_hh bazel.BoolAttribute + Local_includes bazel.StringListAttribute + Implementation_deps bazel.LabelListAttribute + Implementation_dynamic_deps bazel.LabelListAttribute +} + +func bp2buildCcYaccLibrary(ctx android.Bp2buildMutatorContext, ca compilerAttributes, la linkerAttributes) *bazel.LabelAttribute { + if ca.yaccSrc == nil { + return nil + } + yaccLibraryLabel := ctx.Module().Name() + "_yacc" + ctx.CreateBazelTargetModule( + bazel.BazelTargetModuleProperties{ + Rule_class: "cc_yacc_static_library", + Bzl_load_location: "//build/bazel/rules/cc:cc_yacc_library.bzl", + }, + android.CommonAttributes{ + Name: yaccLibraryLabel, + }, + &ccYaccLibraryAttributes{ + Src: *ca.yaccSrc, + Flags: ca.yaccFlags, + Gen_location_hh: ca.yaccGenLocationHeader, + Gen_position_hh: ca.yaccGenPositionHeader, + Local_includes: ca.localIncludes, + Implementation_deps: la.implementationDeps, + Implementation_dynamic_deps: la.implementationDynamicDeps, + }, + ) + + yaccLibrary := &bazel.LabelAttribute{ + Value: &bazel.Label{ + Label: ":" + yaccLibraryLabel, + }, + } + return yaccLibrary +} + // As a workaround for b/261657184, we are manually adding the default value // of system_dynamic_deps for the linux_musl os. // TODO: Solve this properly |