Merge "bp2build: refactor compiler/linker prop function." am: 02e40d0589
am: 39c14f4112
am: e865be2ee1
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1671525 Change-Id: I7021083f52dcfec26408a036028d079dab7e5bac
This commit is contained in:
commit
be66aca8e1
|
@ -59,13 +59,17 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
|
|||
ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
|
||||
}
|
||||
|
||||
// Convenience struct to hold all attributes parsed from compiler properties.
|
||||
type compilerAttributes struct {
|
||||
copts bazel.StringListAttribute
|
||||
srcs bazel.LabelListAttribute
|
||||
hdrs bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
|
||||
func bp2BuildParseCompilerProps(
|
||||
ctx android.TopDownMutatorContext,
|
||||
module *Module) (
|
||||
copts bazel.StringListAttribute,
|
||||
srcs bazel.LabelListAttribute,
|
||||
hdrs bazel.LabelListAttribute) {
|
||||
func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
|
||||
var hdrs, srcs bazel.LabelListAttribute
|
||||
var copts bazel.StringListAttribute
|
||||
|
||||
hdrsAndSrcs := func(baseCompilerProps *BaseCompilerProperties) (bazel.LabelList, bazel.LabelList) {
|
||||
srcsList := android.BazelLabelForModuleSrcExcludes(
|
||||
|
@ -100,13 +104,22 @@ func bp2BuildParseCompilerProps(
|
|||
}
|
||||
}
|
||||
|
||||
return copts, srcs, hdrs
|
||||
return compilerAttributes{
|
||||
hdrs: hdrs,
|
||||
srcs: srcs,
|
||||
copts: copts,
|
||||
}
|
||||
}
|
||||
|
||||
// Convenience struct to hold all attributes parsed from linker properties.
|
||||
type linkerAttributes struct {
|
||||
deps bazel.LabelListAttribute
|
||||
linkopts bazel.StringListAttribute
|
||||
}
|
||||
|
||||
// bp2BuildParseLinkerProps creates a label list attribute containing the header library deps of a module, including
|
||||
// configurable attribute values.
|
||||
func bp2BuildParseLinkerProps(
|
||||
ctx android.TopDownMutatorContext, module *Module) (bazel.LabelListAttribute, bazel.StringListAttribute) {
|
||||
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
|
||||
|
||||
var deps bazel.LabelListAttribute
|
||||
var linkopts bazel.StringListAttribute
|
||||
|
@ -142,7 +155,10 @@ func bp2BuildParseLinkerProps(
|
|||
}
|
||||
}
|
||||
|
||||
return deps, linkopts
|
||||
return linkerAttributes{
|
||||
deps: deps,
|
||||
linkopts: linkopts,
|
||||
}
|
||||
}
|
||||
|
||||
func bp2BuildListHeadersInDir(ctx android.TopDownMutatorContext, includeDir string) bazel.LabelList {
|
||||
|
|
|
@ -256,17 +256,17 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
|||
return
|
||||
}
|
||||
|
||||
copts, srcs, hdrs := bp2BuildParseCompilerProps(ctx, m)
|
||||
deps, linkopts := bp2BuildParseLinkerProps(ctx, m)
|
||||
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
|
||||
linkerAttrs := bp2BuildParseLinkerProps(ctx, m)
|
||||
exportedIncludes, exportedIncludesHeaders := bp2BuildParseExportedIncludes(ctx, m)
|
||||
hdrs.Append(exportedIncludesHeaders)
|
||||
compilerAttrs.hdrs.Append(exportedIncludesHeaders)
|
||||
|
||||
attrs := &bazelCcLibraryAttributes{
|
||||
Srcs: srcs,
|
||||
Hdrs: hdrs,
|
||||
Copts: copts,
|
||||
Linkopts: linkopts,
|
||||
Deps: deps,
|
||||
Srcs: compilerAttrs.srcs,
|
||||
Hdrs: compilerAttrs.hdrs,
|
||||
Copts: compilerAttrs.copts,
|
||||
Linkopts: linkerAttrs.linkopts,
|
||||
Deps: linkerAttrs.deps,
|
||||
Includes: exportedIncludes,
|
||||
}
|
||||
|
||||
|
@ -2154,12 +2154,13 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
|
|||
return
|
||||
}
|
||||
|
||||
copts, srcs, hdrs := bp2BuildParseCompilerProps(ctx, module)
|
||||
compilerAttrs := bp2BuildParseCompilerProps(ctx, module)
|
||||
|
||||
var includeDirs []string
|
||||
var localIncludeDirs []string
|
||||
for _, props := range module.compiler.compilerProps() {
|
||||
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
||||
// TODO: these should be arch and os specific.
|
||||
includeDirs = bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs)
|
||||
localIncludeDirs = bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Local_include_dirs)
|
||||
break
|
||||
|
@ -2174,15 +2175,16 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
|
|||
|
||||
// For Bazel, be more explicit about headers - list all header files in include dirs as srcs
|
||||
for _, includeDir := range includeDirs {
|
||||
srcs.Value.Append(bp2BuildListHeadersInDir(ctx, includeDir))
|
||||
compilerAttrs.srcs.Value.Append(bp2BuildListHeadersInDir(ctx, includeDir))
|
||||
}
|
||||
for _, localIncludeDir := range localIncludeDirs {
|
||||
srcs.Value.Append(bp2BuildListHeadersInDir(ctx, localIncludeDir))
|
||||
compilerAttrs.srcs.Value.Append(bp2BuildListHeadersInDir(ctx, localIncludeDir))
|
||||
}
|
||||
|
||||
var staticLibs []string
|
||||
var wholeStaticLibs []string
|
||||
for _, props := range module.linker.linkerProps() {
|
||||
// TODO: move this into bp2buildParseLinkerProps
|
||||
if baseLinkerProperties, ok := props.(*BaseLinkerProperties); ok {
|
||||
staticLibs = baseLinkerProperties.Static_libs
|
||||
wholeStaticLibs = baseLinkerProperties.Whole_static_libs
|
||||
|
@ -2204,18 +2206,18 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
|
|||
allIncludes.Value = append(allIncludes.Value, includeDirs...)
|
||||
allIncludes.Value = append(allIncludes.Value, localIncludeDirs...)
|
||||
|
||||
hdrs.Append(exportedIncludesHeaders)
|
||||
compilerAttrs.hdrs.Append(exportedIncludesHeaders)
|
||||
|
||||
headerLibsLabels, _ := bp2BuildParseLinkerProps(ctx, module)
|
||||
depsLabels.Append(headerLibsLabels.Value)
|
||||
linkerAttrs := bp2BuildParseLinkerProps(ctx, module)
|
||||
depsLabels.Append(linkerAttrs.deps.Value)
|
||||
|
||||
attrs := &bazelCcLibraryStaticAttributes{
|
||||
Copts: copts,
|
||||
Srcs: srcs,
|
||||
Copts: compilerAttrs.copts,
|
||||
Srcs: compilerAttrs.srcs,
|
||||
Deps: bazel.MakeLabelListAttribute(depsLabels),
|
||||
Linkstatic: true,
|
||||
Includes: allIncludes,
|
||||
Hdrs: hdrs,
|
||||
Hdrs: compilerAttrs.hdrs,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
|
|
|
@ -96,14 +96,14 @@ func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
|
|||
}
|
||||
|
||||
exportedIncludes, exportedIncludesHeaders := bp2BuildParseExportedIncludes(ctx, module)
|
||||
copts, _, _ := bp2BuildParseCompilerProps(ctx, module)
|
||||
headerLibs, _ := bp2BuildParseLinkerProps(ctx, module)
|
||||
compilerAttrs := bp2BuildParseCompilerProps(ctx, module)
|
||||
linkerAttrs := bp2BuildParseLinkerProps(ctx, module)
|
||||
|
||||
attrs := &bazelCcLibraryHeadersAttributes{
|
||||
Copts: copts,
|
||||
Copts: compilerAttrs.copts,
|
||||
Includes: exportedIncludes,
|
||||
Hdrs: exportedIncludesHeaders,
|
||||
Deps: headerLibs,
|
||||
Deps: linkerAttrs.deps,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
|
|
14
cc/object.go
14
cc/object.go
|
@ -157,7 +157,7 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
|
|||
}
|
||||
|
||||
// Set arch-specific configurable attributes
|
||||
copts, srcs, hdrs := bp2BuildParseCompilerProps(ctx, m)
|
||||
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
|
||||
var localIncludeDirs []string
|
||||
var asFlags []string
|
||||
for _, props := range m.compiler.compilerProps() {
|
||||
|
@ -196,17 +196,11 @@ func ObjectBp2Build(ctx android.TopDownMutatorContext) {
|
|||
}
|
||||
// TODO(b/183595872) warn/error if we're not handling product variables
|
||||
|
||||
for arch, p := range m.GetArchProperties(&BaseCompilerProperties{}) {
|
||||
if cProps, ok := p.(*BaseCompilerProperties); ok {
|
||||
srcs.SetValueForArch(arch.Name, android.BazelLabelForModuleSrcExcludes(ctx, cProps.Srcs, cProps.Exclude_srcs))
|
||||
}
|
||||
}
|
||||
|
||||
attrs := &bazelObjectAttributes{
|
||||
Srcs: srcs,
|
||||
Hdrs: hdrs,
|
||||
Srcs: compilerAttrs.srcs,
|
||||
Hdrs: compilerAttrs.hdrs,
|
||||
Deps: deps,
|
||||
Copts: copts,
|
||||
Copts: compilerAttrs.copts,
|
||||
Asflags: asFlags,
|
||||
Local_include_dirs: localIncludeDirs,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue