Merge "bp2build: refactor compiler/linker prop function." am: 02e40d0589
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1671525 Change-Id: Ied11887b04e072936f34269751cf8c0a4bb38053
This commit is contained in:
commit
39c14f4112
|
@ -59,13 +59,17 @@ func depsBp2BuildMutator(ctx android.BottomUpMutatorContext) {
|
||||||
ctx.AddDependency(module, nil, android.SortedUniqueStrings(allDeps)...)
|
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.
|
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
|
||||||
func bp2BuildParseCompilerProps(
|
func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Module) compilerAttributes {
|
||||||
ctx android.TopDownMutatorContext,
|
var hdrs, srcs bazel.LabelListAttribute
|
||||||
module *Module) (
|
var copts bazel.StringListAttribute
|
||||||
copts bazel.StringListAttribute,
|
|
||||||
srcs bazel.LabelListAttribute,
|
|
||||||
hdrs bazel.LabelListAttribute) {
|
|
||||||
|
|
||||||
hdrsAndSrcs := func(baseCompilerProps *BaseCompilerProperties) (bazel.LabelList, bazel.LabelList) {
|
hdrsAndSrcs := func(baseCompilerProps *BaseCompilerProperties) (bazel.LabelList, bazel.LabelList) {
|
||||||
srcsList := android.BazelLabelForModuleSrcExcludes(
|
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
|
// bp2BuildParseLinkerProps creates a label list attribute containing the header library deps of a module, including
|
||||||
// configurable attribute values.
|
// configurable attribute values.
|
||||||
func bp2BuildParseLinkerProps(
|
func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
|
||||||
ctx android.TopDownMutatorContext, module *Module) (bazel.LabelListAttribute, bazel.StringListAttribute) {
|
|
||||||
|
|
||||||
var deps bazel.LabelListAttribute
|
var deps bazel.LabelListAttribute
|
||||||
var linkopts bazel.StringListAttribute
|
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 {
|
func bp2BuildListHeadersInDir(ctx android.TopDownMutatorContext, includeDir string) bazel.LabelList {
|
||||||
|
|
|
@ -256,17 +256,17 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
copts, srcs, hdrs := bp2BuildParseCompilerProps(ctx, m)
|
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
|
||||||
deps, linkopts := bp2BuildParseLinkerProps(ctx, m)
|
linkerAttrs := bp2BuildParseLinkerProps(ctx, m)
|
||||||
exportedIncludes, exportedIncludesHeaders := bp2BuildParseExportedIncludes(ctx, m)
|
exportedIncludes, exportedIncludesHeaders := bp2BuildParseExportedIncludes(ctx, m)
|
||||||
hdrs.Append(exportedIncludesHeaders)
|
compilerAttrs.hdrs.Append(exportedIncludesHeaders)
|
||||||
|
|
||||||
attrs := &bazelCcLibraryAttributes{
|
attrs := &bazelCcLibraryAttributes{
|
||||||
Srcs: srcs,
|
Srcs: compilerAttrs.srcs,
|
||||||
Hdrs: hdrs,
|
Hdrs: compilerAttrs.hdrs,
|
||||||
Copts: copts,
|
Copts: compilerAttrs.copts,
|
||||||
Linkopts: linkopts,
|
Linkopts: linkerAttrs.linkopts,
|
||||||
Deps: deps,
|
Deps: linkerAttrs.deps,
|
||||||
Includes: exportedIncludes,
|
Includes: exportedIncludes,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2154,12 +2154,13 @@ func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
copts, srcs, hdrs := bp2BuildParseCompilerProps(ctx, module)
|
compilerAttrs := bp2BuildParseCompilerProps(ctx, module)
|
||||||
|
|
||||||
var includeDirs []string
|
var includeDirs []string
|
||||||
var localIncludeDirs []string
|
var localIncludeDirs []string
|
||||||
for _, props := range module.compiler.compilerProps() {
|
for _, props := range module.compiler.compilerProps() {
|
||||||
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
||||||
|
// TODO: these should be arch and os specific.
|
||||||
includeDirs = bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs)
|
includeDirs = bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Include_dirs)
|
||||||
localIncludeDirs = bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Local_include_dirs)
|
localIncludeDirs = bp2BuildMakePathsRelativeToModule(ctx, baseCompilerProps.Local_include_dirs)
|
||||||
break
|
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 Bazel, be more explicit about headers - list all header files in include dirs as srcs
|
||||||
for _, includeDir := range includeDirs {
|
for _, includeDir := range includeDirs {
|
||||||
srcs.Value.Append(bp2BuildListHeadersInDir(ctx, includeDir))
|
compilerAttrs.srcs.Value.Append(bp2BuildListHeadersInDir(ctx, includeDir))
|
||||||
}
|
}
|
||||||
for _, localIncludeDir := range localIncludeDirs {
|
for _, localIncludeDir := range localIncludeDirs {
|
||||||
srcs.Value.Append(bp2BuildListHeadersInDir(ctx, localIncludeDir))
|
compilerAttrs.srcs.Value.Append(bp2BuildListHeadersInDir(ctx, localIncludeDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
var staticLibs []string
|
var staticLibs []string
|
||||||
var wholeStaticLibs []string
|
var wholeStaticLibs []string
|
||||||
for _, props := range module.linker.linkerProps() {
|
for _, props := range module.linker.linkerProps() {
|
||||||
|
// TODO: move this into bp2buildParseLinkerProps
|
||||||
if baseLinkerProperties, ok := props.(*BaseLinkerProperties); ok {
|
if baseLinkerProperties, ok := props.(*BaseLinkerProperties); ok {
|
||||||
staticLibs = baseLinkerProperties.Static_libs
|
staticLibs = baseLinkerProperties.Static_libs
|
||||||
wholeStaticLibs = baseLinkerProperties.Whole_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, includeDirs...)
|
||||||
allIncludes.Value = append(allIncludes.Value, localIncludeDirs...)
|
allIncludes.Value = append(allIncludes.Value, localIncludeDirs...)
|
||||||
|
|
||||||
hdrs.Append(exportedIncludesHeaders)
|
compilerAttrs.hdrs.Append(exportedIncludesHeaders)
|
||||||
|
|
||||||
headerLibsLabels, _ := bp2BuildParseLinkerProps(ctx, module)
|
linkerAttrs := bp2BuildParseLinkerProps(ctx, module)
|
||||||
depsLabels.Append(headerLibsLabels.Value)
|
depsLabels.Append(linkerAttrs.deps.Value)
|
||||||
|
|
||||||
attrs := &bazelCcLibraryStaticAttributes{
|
attrs := &bazelCcLibraryStaticAttributes{
|
||||||
Copts: copts,
|
Copts: compilerAttrs.copts,
|
||||||
Srcs: srcs,
|
Srcs: compilerAttrs.srcs,
|
||||||
Deps: bazel.MakeLabelListAttribute(depsLabels),
|
Deps: bazel.MakeLabelListAttribute(depsLabels),
|
||||||
Linkstatic: true,
|
Linkstatic: true,
|
||||||
Includes: allIncludes,
|
Includes: allIncludes,
|
||||||
Hdrs: hdrs,
|
Hdrs: compilerAttrs.hdrs,
|
||||||
}
|
}
|
||||||
|
|
||||||
props := bazel.BazelTargetModuleProperties{
|
props := bazel.BazelTargetModuleProperties{
|
||||||
|
|
|
@ -96,14 +96,14 @@ func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exportedIncludes, exportedIncludesHeaders := bp2BuildParseExportedIncludes(ctx, module)
|
exportedIncludes, exportedIncludesHeaders := bp2BuildParseExportedIncludes(ctx, module)
|
||||||
copts, _, _ := bp2BuildParseCompilerProps(ctx, module)
|
compilerAttrs := bp2BuildParseCompilerProps(ctx, module)
|
||||||
headerLibs, _ := bp2BuildParseLinkerProps(ctx, module)
|
linkerAttrs := bp2BuildParseLinkerProps(ctx, module)
|
||||||
|
|
||||||
attrs := &bazelCcLibraryHeadersAttributes{
|
attrs := &bazelCcLibraryHeadersAttributes{
|
||||||
Copts: copts,
|
Copts: compilerAttrs.copts,
|
||||||
Includes: exportedIncludes,
|
Includes: exportedIncludes,
|
||||||
Hdrs: exportedIncludesHeaders,
|
Hdrs: exportedIncludesHeaders,
|
||||||
Deps: headerLibs,
|
Deps: linkerAttrs.deps,
|
||||||
}
|
}
|
||||||
|
|
||||||
props := bazel.BazelTargetModuleProperties{
|
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
|
// Set arch-specific configurable attributes
|
||||||
copts, srcs, hdrs := bp2BuildParseCompilerProps(ctx, m)
|
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
|
||||||
var localIncludeDirs []string
|
var localIncludeDirs []string
|
||||||
var asFlags []string
|
var asFlags []string
|
||||||
for _, props := range m.compiler.compilerProps() {
|
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
|
// 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{
|
attrs := &bazelObjectAttributes{
|
||||||
Srcs: srcs,
|
Srcs: compilerAttrs.srcs,
|
||||||
Hdrs: hdrs,
|
Hdrs: compilerAttrs.hdrs,
|
||||||
Deps: deps,
|
Deps: deps,
|
||||||
Copts: copts,
|
Copts: compilerAttrs.copts,
|
||||||
Asflags: asFlags,
|
Asflags: asFlags,
|
||||||
Local_include_dirs: localIncludeDirs,
|
Local_include_dirs: localIncludeDirs,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue