bp2build: split full_cc_library into shared/static

Test: mixed_droid.sh in conjunction with rule changes
Test: bp2build.sh
Change-Id: If0577065fd39a0446eab16b62c15204d43207e19
This commit is contained in:
Chris Parsons
2021-12-03 17:27:16 -05:00
parent 85c0097d69
commit 77acf2e5c1
5 changed files with 561 additions and 434 deletions

View File

@@ -385,9 +385,12 @@ func (ll labelListSelectValues) addSelects(label labelSelectValues) {
}
}
func (ll labelListSelectValues) appendSelects(other labelListSelectValues) {
func (ll labelListSelectValues) appendSelects(other labelListSelectValues, forceSpecifyEmptyList bool) {
for k, v := range other {
l := ll[k]
if forceSpecifyEmptyList && l.IsNil() && !v.IsNil() {
l.Includes = []Label{}
}
(&l).Append(v)
ll[k] = l
}
@@ -443,17 +446,22 @@ func (cll configurableLabelLists) setValueForAxis(axis ConfigurationAxis, config
cll[axis][config] = list
}
func (cll configurableLabelLists) Append(other configurableLabelLists) {
func (cll configurableLabelLists) Append(other configurableLabelLists, forceSpecifyEmptyList bool) {
for axis, otherSelects := range other {
selects := cll[axis]
if selects == nil {
selects = make(labelListSelectValues, len(otherSelects))
}
selects.appendSelects(otherSelects)
selects.appendSelects(otherSelects, forceSpecifyEmptyList)
cll[axis] = selects
}
}
func (lla *LabelListAttribute) Clone() *LabelListAttribute {
result := &LabelListAttribute{ForceSpecifyEmptyList: lla.ForceSpecifyEmptyList}
return result.Append(*lla)
}
// MakeLabelListAttribute initializes a LabelListAttribute with the non-arch specific value.
func MakeLabelListAttribute(value LabelList) LabelListAttribute {
return LabelListAttribute{
@@ -507,16 +515,18 @@ func (lla *LabelListAttribute) SortedConfigurationAxes() []ConfigurationAxis {
}
// Append all values, including os and arch specific ones, from another
// LabelListAttribute to this LabelListAttribute.
func (lla *LabelListAttribute) Append(other LabelListAttribute) {
if lla.ForceSpecifyEmptyList && !other.Value.IsNil() {
// LabelListAttribute to this LabelListAttribute. Returns this LabelListAttribute.
func (lla *LabelListAttribute) Append(other LabelListAttribute) *LabelListAttribute {
forceSpecifyEmptyList := lla.ForceSpecifyEmptyList || other.ForceSpecifyEmptyList
if forceSpecifyEmptyList && lla.Value.IsNil() && !other.Value.IsNil() {
lla.Value.Includes = []Label{}
}
lla.Value.Append(other.Value)
if lla.ConfigurableValues == nil {
lla.ConfigurableValues = make(configurableLabelLists)
}
lla.ConfigurableValues.Append(other.ConfigurableValues)
lla.ConfigurableValues.Append(other.ConfigurableValues, forceSpecifyEmptyList)
return lla
}
// Add inserts the labels for each axis of LabelAttribute at the end of corresponding axis's
@@ -795,12 +805,18 @@ func (sla StringListAttribute) HasConfigurableValues() bool {
// Append appends all values, including os and arch specific ones, from another
// StringListAttribute to this StringListAttribute
func (sla *StringListAttribute) Append(other StringListAttribute) {
func (sla *StringListAttribute) Append(other StringListAttribute) *StringListAttribute {
sla.Value = append(sla.Value, other.Value...)
if sla.ConfigurableValues == nil {
sla.ConfigurableValues = make(configurableStringLists)
}
sla.ConfigurableValues.Append(other.ConfigurableValues)
return sla
}
func (sla *StringListAttribute) Clone() *StringListAttribute {
result := &StringListAttribute{}
return result.Append(*sla)
}
// SetSelectValue set a value for a bazel select for the given axis, config and value.

File diff suppressed because it is too large Load Diff

View File

@@ -1713,7 +1713,15 @@ func (c *Module) setSubnameProperty(actx android.ModuleContext) {
// Returns true if Bazel was successfully used for the analysis of this module.
func (c *Module) maybeGenerateBazelActions(actx android.ModuleContext) bool {
bazelModuleLabel := c.GetBazelLabel(actx, c)
var bazelModuleLabel string
if actx.ModuleType() == "cc_library" && c.static() {
// cc_library is a special case in bp2build; two targets are generated -- one for each
// of the shared and static variants. The shared variant keeps the module name, but the
// static variant uses a different suffixed name.
bazelModuleLabel = bazelLabelForStaticModule(actx, c)
} else {
bazelModuleLabel = c.GetBazelLabel(actx, c)
}
bazelActionsUsed := false
// Mixed builds mode is disabled for modules outside of device OS.
// TODO(b/200841190): Support non-device OS in mixed builds.

View File

@@ -313,35 +313,74 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
asFlags = bazel.MakeStringListAttribute(nil)
}
attrs := &bazelCcLibraryAttributes{
Srcs: srcs,
Srcs_c: compilerAttrs.cSrcs,
Srcs_as: compilerAttrs.asSrcs,
Hdrs: compilerAttrs.hdrs,
staticCommonAttrs := staticOrSharedAttributes{
Srcs: *srcs.Clone().Append(staticAttrs.Srcs),
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(staticAttrs.Srcs_c),
Srcs_as: *compilerAttrs.asSrcs.Clone().Append(staticAttrs.Srcs_as),
Copts: *compilerAttrs.copts.Clone().Append(staticAttrs.Copts),
Hdrs: *compilerAttrs.hdrs.Clone().Append(staticAttrs.Hdrs),
Deps: *linkerAttrs.deps.Clone().Append(staticAttrs.Deps),
Implementation_deps: *linkerAttrs.implementationDeps.Clone().Append(staticAttrs.Implementation_deps),
Dynamic_deps: *linkerAttrs.dynamicDeps.Clone().Append(staticAttrs.Dynamic_deps),
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(staticAttrs.Implementation_dynamic_deps),
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(staticAttrs.Whole_archive_deps),
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(staticAttrs.System_dynamic_deps),
}
sharedCommonAttrs := staticOrSharedAttributes{
Srcs: *srcs.Clone().Append(sharedAttrs.Srcs),
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(sharedAttrs.Srcs_c),
Srcs_as: *compilerAttrs.asSrcs.Clone().Append(sharedAttrs.Srcs_as),
Copts: *compilerAttrs.copts.Clone().Append(sharedAttrs.Copts),
Hdrs: *compilerAttrs.hdrs.Clone().Append(sharedAttrs.Hdrs),
Deps: *linkerAttrs.deps.Clone().Append(sharedAttrs.Deps),
Implementation_deps: *linkerAttrs.implementationDeps.Clone().Append(sharedAttrs.Implementation_deps),
Dynamic_deps: *linkerAttrs.dynamicDeps.Clone().Append(sharedAttrs.Dynamic_deps),
Implementation_dynamic_deps: *linkerAttrs.implementationDynamicDeps.Clone().Append(sharedAttrs.Implementation_dynamic_deps),
Whole_archive_deps: *linkerAttrs.wholeArchiveDeps.Clone().Append(sharedAttrs.Whole_archive_deps),
System_dynamic_deps: *linkerAttrs.systemDynamicDeps.Clone().Append(sharedAttrs.System_dynamic_deps),
}
staticTargetAttrs := &bazelCcLibraryStaticAttributes{
staticOrSharedAttributes: staticCommonAttrs,
Copts: compilerAttrs.copts,
Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
Implementation_deps: linkerAttrs.implementationDeps,
Deps: linkerAttrs.deps,
Implementation_dynamic_deps: linkerAttrs.implementationDynamicDeps,
Dynamic_deps: linkerAttrs.dynamicDeps,
Whole_archive_deps: linkerAttrs.wholeArchiveDeps,
Implementation_whole_archive_deps: linkerAttrs.implementationWholeArchiveDeps,
System_dynamic_deps: linkerAttrs.systemDynamicDeps,
Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Linkopts: linkerAttrs.linkopts,
Link_crt: linkerAttrs.linkCrt,
Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
Features: linkerAttrs.features,
}
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
staticOrSharedAttributes: sharedCommonAttrs,
Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
Export_includes: exportedIncludes.Includes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Linkopts: linkerAttrs.linkopts,
Link_crt: linkerAttrs.linkCrt,
Use_libcrt: linkerAttrs.useLibcrt,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
@@ -352,20 +391,20 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
All: linkerAttrs.stripAll,
None: linkerAttrs.stripNone,
},
Shared: sharedAttrs,
Static: staticAttrs,
Features: linkerAttrs.features,
}
props := bazel.BazelTargetModuleProperties{
Rule_class: "cc_library",
Bzl_load_location: "//build/bazel/rules:full_cc_library.bzl",
staticProps := bazel.BazelTargetModuleProperties{
Rule_class: "cc_library_static",
Bzl_load_location: "//build/bazel/rules:cc_library_static.bzl",
}
sharedProps := bazel.BazelTargetModuleProperties{
Rule_class: "cc_library_shared",
Bzl_load_location: "//build/bazel/rules:cc_library_shared.bzl",
}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
ctx.CreateBazelTargetModule(staticProps, android.CommonAttributes{Name: m.Name() + "_bp2build_cc_library_static"}, staticTargetAttrs)
ctx.CreateBazelTargetModule(sharedProps, android.CommonAttributes{Name: m.Name()}, sharedTargetAttrs)
}
// cc_library creates both static and/or shared libraries for a device and/or

View File

@@ -257,9 +257,14 @@ cc_library {
CcObjectFiles: []string{"foo.o"},
Includes: []string{"include"},
SystemIncludes: []string{"system_include"},
RootStaticArchives: []string{"foo.a"},
RootDynamicLibraries: []string{"foo.so"},
},
"//foo/bar:bar_bp2build_cc_library_static": cquery.CcInfo{
CcObjectFiles: []string{"foo.o"},
Includes: []string{"include"},
SystemIncludes: []string{"system_include"},
RootStaticArchives: []string{"foo.a"},
},
},
}
ctx := testCcWithConfig(t, config)