bp2build: allowlist //external/libcap/...
This builds cap_names.list.h, which uses an eponymous filegroup
"generate_cap_names_list.awk" in Soong, but uses the file target
directly in Bazel.
This also improve filegroup support for mixed builds, by issuing a
cquery call _without_ arch. Filegroups in Soong don't have configurable
properties, so don't generate Bazel filegroups into buildroot's
config_nodes (which was x86_64 by default).
The mixed_build_root now looks like this:
```
config_node(...)
config_node(...)
config_node(...)
config_node(...)
...
filegroup(name = "common",
srcs = ["@//bionic/linker:linker_sources_x86",
"@//bionic/libc:kernel_input_headers",
"@//system/timezone/apex:com.android.tzdata-androidManifest",
"@//external/libcap:generate_cap_names_list.awk",
"@//bionic/linker:linker_sources_arm64",
"@//bionic/linker:linker_sources",
"@//bionic/libc:libc_sources_shared_arm",
"@//bionic/linker:linker_sources_x86_64",
"@//bionic/libc:all_kernel_uapi_headers",
"@//build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal-file_contexts",
"@//system/core/libcutils:android_filesystem_config_header",
"@//bionic/libc:libc_sources_static",
"@//bionic/linker:linker_sources_arm",
"@//bionic/libc/tools:bionic-gensyscalls",
"@//bionic/tools:bionic-generate-version-script",
"@//bionic/libc:libc_sources_shared"],
)
mixed_build_root(name = "buildroot",
deps = [":x86",
":arm64",
":arm",
":common",
":x86_64"],
)
```
Test: CI
Fixes: 198595323
Fixes: 198235838
Change-Id: I6df9a14da556cf358d96e6a99b514f66a2638295
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 9c922dd..50b79fa 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -27,9 +27,9 @@
"sync"
"android/soong/bazel/cquery"
+ "android/soong/shared"
"android/soong/bazel"
- "android/soong/shared"
)
type cqueryRequest interface {
@@ -492,6 +492,12 @@
)
`
+ commonArchFilegroupString := `
+filegroup(name = "common",
+ srcs = [%s],
+)
+`
+
configNodesSection := ""
labelsByArch := map[string][]string{}
@@ -501,14 +507,22 @@
labelsByArch[archString] = append(labelsByArch[archString], labelString)
}
- configNodeLabels := []string{}
+ allLabels := []string{}
for archString, labels := range labelsByArch {
- configNodeLabels = append(configNodeLabels, fmt.Sprintf("\":%s\"", archString))
- labelsString := strings.Join(labels, ",\n ")
- configNodesSection += fmt.Sprintf(configNodeFormatString, archString, archString, labelsString)
+ if archString == "common" {
+ // arch-less labels (e.g. filegroups) don't need a config_node
+ allLabels = append(allLabels, "\":common\"")
+ labelsString := strings.Join(labels, ",\n ")
+ configNodesSection += fmt.Sprintf(commonArchFilegroupString, labelsString)
+ } else {
+ // Create a config_node, and add the config_node's label to allLabels
+ allLabels = append(allLabels, fmt.Sprintf("\":%s\"", archString))
+ labelsString := strings.Join(labels, ",\n ")
+ configNodesSection += fmt.Sprintf(configNodeFormatString, archString, archString, labelsString)
+ }
}
- return []byte(fmt.Sprintf(formatString, configNodesSection, strings.Join(configNodeLabels, ",\n ")))
+ return []byte(fmt.Sprintf(formatString, configNodesSection, strings.Join(allLabels, ",\n ")))
}
func indent(original string) string {
@@ -573,6 +587,12 @@
%s
def get_arch(target):
+ # TODO(b/199363072): filegroups and file targets aren't associated with any
+ # specific platform architecture in mixed builds. This is consistent with how
+ # Soong treats filegroups, but it may not be the case with manually-written
+ # filegroup BUILD targets.
+ if target.kind in ["filegroup", ""]:
+ return "common"
buildoptions = build_options(target)
platforms = build_options(target)["//command_line_option:platforms"]
if len(platforms) != 1:
@@ -671,11 +691,12 @@
if err != nil {
return err
}
+
buildrootLabel := "@soong_injection//mixed_builds:buildroot"
cqueryOutput, cqueryErr, err = context.issueBazelCommand(
context.paths,
bazel.CqueryBuildRootRunName,
- bazelCommand{"cquery", fmt.Sprintf("kind(rule, deps(%s))", buildrootLabel)},
+ bazelCommand{"cquery", fmt.Sprintf("deps(%s)", buildrootLabel)},
"--output=starlark",
"--starlark:file="+absolutePath(cqueryFileRelpath))
err = ioutil.WriteFile(filepath.Join(soongInjectionPath, "cquery.out"),