bp2build: Improve handling of generated_sources
Test: build/bazel/ci/bp2build.sh Change-Id: Id5f8b6ae9bbf1e90d72854daafb8b1f86f7241ea
This commit is contained in:
parent
97b8531492
commit
222bdcff5c
2 changed files with 55 additions and 30 deletions
|
@ -1000,55 +1000,66 @@ func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) {
|
|||
"dep/Android.bp": `
|
||||
genrule {
|
||||
name: "generated_src_other_pkg",
|
||||
out: ["generated_src_other_pkg.cpp"],
|
||||
cmd: "nothing to see here",
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "generated_hdr_other_pkg",
|
||||
out: ["generated_hdr_other_pkg.cpp"],
|
||||
cmd: "nothing to see here",
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "generated_hdr_other_pkg_x86",
|
||||
out: ["generated_hdr_other_pkg_x86.cpp"],
|
||||
cmd: "nothing to see here",
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "generated_hdr_other_pkg_android",
|
||||
cmd: "nothing to see here",
|
||||
}`,
|
||||
},
|
||||
blueprint: soongCcLibraryStaticPreamble + `
|
||||
genrule {
|
||||
name: "generated_src",
|
||||
out: ["generated_src.cpp"],
|
||||
cmd: "nothing to see here",
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "generated_src_x86",
|
||||
out: ["generated_src_x86.cpp"],
|
||||
name: "generated_src_not_x86",
|
||||
cmd: "nothing to see here",
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "generated_src_android",
|
||||
cmd: "nothing to see here",
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "generated_hdr",
|
||||
out: ["generated_hdr.h"],
|
||||
cmd: "nothing to see here",
|
||||
}
|
||||
|
||||
cc_library_static {
|
||||
name: "foo_static3",
|
||||
srcs: ["common.cpp", "not-for-*.cpp"],
|
||||
exclude_srcs: ["not-for-everything.cpp"],
|
||||
generated_sources: ["generated_src", "generated_src_other_pkg"],
|
||||
generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
|
||||
arch: {
|
||||
x86: {
|
||||
srcs: ["for-x86.cpp"],
|
||||
exclude_srcs: ["not-for-x86.cpp"],
|
||||
generated_sources: ["generated_src_x86"],
|
||||
generated_headers: ["generated_hdr_other_pkg_x86"],
|
||||
},
|
||||
},
|
||||
name: "foo_static3",
|
||||
srcs: ["common.cpp", "not-for-*.cpp"],
|
||||
exclude_srcs: ["not-for-everything.cpp"],
|
||||
generated_sources: ["generated_src", "generated_src_other_pkg", "generated_src_not_x86"],
|
||||
generated_headers: ["generated_hdr", "generated_hdr_other_pkg"],
|
||||
arch: {
|
||||
x86: {
|
||||
srcs: ["for-x86.cpp"],
|
||||
exclude_srcs: ["not-for-x86.cpp"],
|
||||
generated_headers: ["generated_hdr_other_pkg_x86"],
|
||||
exclude_generated_sources: ["generated_src_not_x86"],
|
||||
},
|
||||
},
|
||||
target: {
|
||||
android: {
|
||||
generated_sources: ["generated_src_android"],
|
||||
generated_headers: ["generated_hdr_other_pkg_android"],
|
||||
},
|
||||
},
|
||||
|
||||
include_build_directory: false,
|
||||
}
|
||||
`,
|
||||
|
@ -1063,10 +1074,18 @@ cc_library_static {
|
|||
] + select({
|
||||
"//build/bazel/platforms/arch:x86": [
|
||||
"//dep:generated_hdr_other_pkg_x86",
|
||||
":generated_src_x86",
|
||||
"for-x86.cpp",
|
||||
],
|
||||
"//conditions:default": ["not-for-x86.cpp"],
|
||||
"//conditions:default": [
|
||||
":generated_src_not_x86",
|
||||
"not-for-x86.cpp",
|
||||
],
|
||||
}) + select({
|
||||
"//build/bazel/platforms/os:android": [
|
||||
"//dep:generated_hdr_other_pkg_android",
|
||||
":generated_src_android",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)`},
|
||||
})
|
||||
|
|
|
@ -255,15 +255,22 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
|
|||
}
|
||||
|
||||
// Parse srcs from an arch or OS's props value.
|
||||
parseSrcs := func(baseCompilerProps *BaseCompilerProperties) bazel.LabelList {
|
||||
parseSrcs := func(props *BaseCompilerProperties) (bazel.LabelList, bool) {
|
||||
anySrcs := false
|
||||
// Add srcs-like dependencies such as generated files.
|
||||
// First create a LabelList containing these dependencies, then merge the values with srcs.
|
||||
generatedHdrsAndSrcs := baseCompilerProps.Generated_headers
|
||||
generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, baseCompilerProps.Generated_sources...)
|
||||
generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDeps(ctx, generatedHdrsAndSrcs)
|
||||
generatedHdrsAndSrcs := props.Generated_headers
|
||||
generatedHdrsAndSrcs = append(generatedHdrsAndSrcs, props.Generated_sources...)
|
||||
generatedHdrsAndSrcsLabelList := android.BazelLabelForModuleDepsExcludes(ctx, generatedHdrsAndSrcs, props.Exclude_generated_sources)
|
||||
if len(generatedHdrsAndSrcs) > 0 || len(props.Exclude_generated_sources) > 0 {
|
||||
anySrcs = true
|
||||
}
|
||||
|
||||
allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, baseCompilerProps.Srcs, baseCompilerProps.Exclude_srcs)
|
||||
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList)
|
||||
allSrcsLabelList := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs)
|
||||
if len(props.Srcs) > 0 || len(props.Exclude_srcs) > 0 {
|
||||
anySrcs = true
|
||||
}
|
||||
return bazel.AppendBazelLabelLists(allSrcsLabelList, generatedHdrsAndSrcsLabelList), anySrcs
|
||||
}
|
||||
|
||||
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
|
||||
|
@ -272,8 +279,7 @@ func bp2BuildParseCompilerProps(ctx android.TopDownMutatorContext, module *Modul
|
|||
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
||||
// If there's arch specific srcs or exclude_srcs, generate a select entry for it.
|
||||
// TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
|
||||
if len(baseCompilerProps.Srcs) > 0 || len(baseCompilerProps.Exclude_srcs) > 0 {
|
||||
srcsList := parseSrcs(baseCompilerProps)
|
||||
if srcsList, ok := parseSrcs(baseCompilerProps); ok {
|
||||
srcs.SetSelectValue(axis, config, srcsList)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue