Merge "bp2build converter for cc libraries containing yacc"

This commit is contained in:
Spandan Das
2023-05-16 02:48:53 +00:00
committed by Gerrit Code Review
2 changed files with 123 additions and 0 deletions

View File

@@ -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