cc mixed build support to allowlist M13 libraries

Propagate api_domain from top-level config_node(s) in mixed builds.
This ensures that cc_libraries are built in the correct config setting
in mixed builds

Test: m com.android.media.swcodec
Test: built and booted google variant of com.android.media.swcodec
Test: m ccodec_unit_test

Change-Id: I14e3c8e8358b5e90e71697584f9b0eceb018bfa9
This commit is contained in:
Spandan Das
2023-06-25 20:56:06 +00:00
parent 184893a851
commit 40b79f8def
3 changed files with 51 additions and 3 deletions

View File

@@ -92,10 +92,11 @@ type configKey struct {
type ApexConfigKey struct { type ApexConfigKey struct {
WithinApex bool WithinApex bool
ApexSdkVersion string ApexSdkVersion string
ApiDomain string
} }
func (c ApexConfigKey) String() string { func (c ApexConfigKey) String() string {
return fmt.Sprintf("%s_%s", withinApexToString(c.WithinApex), c.ApexSdkVersion) return fmt.Sprintf("%s_%s_%s", withinApexToString(c.WithinApex), c.ApexSdkVersion, c.ApiDomain)
} }
func withinApexToString(withinApex bool) string { func withinApexToString(withinApex bool) string {
@@ -737,6 +738,7 @@ def _config_node_transition_impl(settings, attr):
"@//build/bazel/rules/apex:within_apex": attr.within_apex, "@//build/bazel/rules/apex:within_apex": attr.within_apex,
"@//build/bazel/rules/apex:min_sdk_version": attr.apex_sdk_version, "@//build/bazel/rules/apex:min_sdk_version": attr.apex_sdk_version,
"@//build/bazel/rules/apex:apex_name": apex_name, "@//build/bazel/rules/apex:apex_name": apex_name,
"@//build/bazel/rules/apex:api_domain": attr.api_domain,
} }
return outputs return outputs
@@ -749,6 +751,7 @@ _config_node_transition = transition(
"@//build/bazel/rules/apex:within_apex", "@//build/bazel/rules/apex:within_apex",
"@//build/bazel/rules/apex:min_sdk_version", "@//build/bazel/rules/apex:min_sdk_version",
"@//build/bazel/rules/apex:apex_name", "@//build/bazel/rules/apex:apex_name",
"@//build/bazel/rules/apex:api_domain",
], ],
) )
@@ -762,6 +765,7 @@ config_node = rule(
"os" : attr.string(mandatory = True), "os" : attr.string(mandatory = True),
"within_apex" : attr.bool(default = False), "within_apex" : attr.bool(default = False),
"apex_sdk_version" : attr.string(mandatory = True), "apex_sdk_version" : attr.string(mandatory = True),
"api_domain" : attr.string(mandatory = True),
"deps" : attr.label_list(cfg = _config_node_transition, allow_files = True), "deps" : attr.label_list(cfg = _config_node_transition, allow_files = True),
"_allowlist_function_transition": attr.label(default = "@bazel_tools//tools/allowlists/function_transition_allowlist"), "_allowlist_function_transition": attr.label(default = "@bazel_tools//tools/allowlists/function_transition_allowlist"),
}, },
@@ -823,6 +827,7 @@ config_node(name = "%s",
os = "%s", os = "%s",
within_apex = %s, within_apex = %s,
apex_sdk_version = "%s", apex_sdk_version = "%s",
api_domain = "%s",
deps = [%s], deps = [%s],
testonly = True, # Unblocks testonly deps. testonly = True, # Unblocks testonly deps.
) )
@@ -856,6 +861,11 @@ config_node(name = "%s",
osString := configTokens[1] osString := configTokens[1]
withinApex := "False" withinApex := "False"
apexSdkVerString := "" apexSdkVerString := ""
apiDomainString := ""
if osString == "android" {
// api domains are meaningful only for device variants
apiDomainString = "system"
}
targetString := fmt.Sprintf("%s_%s", osString, archString) targetString := fmt.Sprintf("%s_%s", osString, archString)
if len(configTokens) > 2 { if len(configTokens) > 2 {
targetString += "_" + configTokens[2] targetString += "_" + configTokens[2]
@@ -867,9 +877,13 @@ config_node(name = "%s",
targetString += "_" + configTokens[3] targetString += "_" + configTokens[3]
apexSdkVerString = configTokens[3] apexSdkVerString = configTokens[3]
} }
if len(configTokens) > 4 {
apiDomainString = configTokens[4]
targetString += "_" + apiDomainString
}
allLabels = append(allLabels, fmt.Sprintf("\":%s\"", targetString)) allLabels = append(allLabels, fmt.Sprintf("\":%s\"", targetString))
labelsString := strings.Join(labels, ",\n ") labelsString := strings.Join(labels, ",\n ")
configNodesSection += fmt.Sprintf(configNodeFormatString, targetString, archString, osString, withinApex, apexSdkVerString, configNodesSection += fmt.Sprintf(configNodeFormatString, targetString, archString, osString, withinApex, apexSdkVerString, apiDomainString,
labelsString) labelsString)
} }
@@ -974,11 +988,14 @@ def get_arch(target):
within_apex = buildoptions.get("//build/bazel/rules/apex:within_apex") within_apex = buildoptions.get("//build/bazel/rules/apex:within_apex")
apex_sdk_version = buildoptions.get("//build/bazel/rules/apex:min_sdk_version") apex_sdk_version = buildoptions.get("//build/bazel/rules/apex:min_sdk_version")
api_domain = buildoptions.get("//build/bazel/rules/apex:api_domain")
if within_apex: if within_apex:
config_key += "|within_apex" config_key += "|within_apex"
if apex_sdk_version != None and len(apex_sdk_version) > 0: if apex_sdk_version != None and len(apex_sdk_version) > 0:
config_key += "|" + apex_sdk_version config_key += "|" + apex_sdk_version
if api_domain != None and len(api_domain) > 0:
config_key += "|" + api_domain
return config_key return config_key
@@ -1385,6 +1402,10 @@ func getConfigString(key cqueryKey) string {
keyString += "|" + key.configKey.apexKey.ApexSdkVersion keyString += "|" + key.configKey.apexKey.ApexSdkVersion
} }
if len(key.configKey.apexKey.ApiDomain) > 0 {
keyString += "|" + key.configKey.apexKey.ApiDomain
}
return keyString return keyString
} }
@@ -1403,6 +1424,7 @@ func GetConfigKeyApexVariant(ctx BaseModuleContext, apexKey *ApexConfigKey) conf
configKey.apexKey = ApexConfigKey{ configKey.apexKey = ApexConfigKey{
WithinApex: apexKey.WithinApex, WithinApex: apexKey.WithinApex,
ApexSdkVersion: apexKey.ApexSdkVersion, ApexSdkVersion: apexKey.ApexSdkVersion,
ApiDomain: apexKey.ApiDomain,
} }
} }

View File

@@ -58,11 +58,12 @@ func TestRequestResultsAfterInvokeBazel(t *testing.T) {
apexKey := ApexConfigKey{ apexKey := ApexConfigKey{
WithinApex: true, WithinApex: true,
ApexSdkVersion: "29", ApexSdkVersion: "29",
ApiDomain: "myapex",
} }
cfg_foo := configKey{"arm64_armv8-a", Android, apexKey} cfg_foo := configKey{"arm64_armv8-a", Android, apexKey}
cfg_bar := configKey{arch: "arm64_armv8-a", osType: Android} cfg_bar := configKey{arch: "arm64_armv8-a", osType: Android}
cmd_results := []string{ cmd_results := []string{
`@//foo:foo|arm64_armv8-a|android|within_apex|29>>out/foo/foo.txt`, `@//foo:foo|arm64_armv8-a|android|within_apex|29|myapex>>out/foo/foo.txt`,
`@//foo:bar|arm64_armv8-a|android>>out/foo/bar.txt`, `@//foo:bar|arm64_armv8-a|android>>out/foo/bar.txt`,
} }
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{cqueryCmd: strings.Join(cmd_results, "\n")}) bazelContext, _ := testBazelContext(t, map[bazelCommand]string{cqueryCmd: strings.Join(cmd_results, "\n")})

View File

@@ -1974,6 +1974,7 @@ func GetApexConfigKey(ctx android.BaseModuleContext) *android.ApexConfigKey {
apexKey := android.ApexConfigKey{ apexKey := android.ApexConfigKey{
WithinApex: true, WithinApex: true,
ApexSdkVersion: findApexSdkVersion(ctx, apexInfo).String(), ApexSdkVersion: findApexSdkVersion(ctx, apexInfo).String(),
ApiDomain: findApiDomain(apexInfo),
} }
return &apexKey return &apexKey
} }
@@ -1981,6 +1982,30 @@ func GetApexConfigKey(ctx android.BaseModuleContext) *android.ApexConfigKey {
return nil return nil
} }
// Returns the api domain of a module for an apexInfo group
// Input:
// ai.InApexModules: [com.android.foo, test_com.android.foo, com.google.android.foo]
// Return:
// com.android.foo
// If a module is included in multiple api domains (collated by min_sdk_version), it will return
// the first match. The other matches have the same build actions since they share a min_sdk_version, so returning
// the first match is fine.
func findApiDomain(ai android.ApexInfo) string {
// Remove any test apexes
matches, _ := android.FilterList(ai.InApexModules, ai.TestApexes)
// Remove any google apexes. Rely on naming convention.
pred := func(s string) bool { return !strings.HasPrefix(s, "com.google") }
matches = android.FilterListPred(matches, pred)
if len(matches) > 0 {
// Return the first match
return android.SortedUniqueStrings(matches)[0]
} else {
// No apex in the tree has a dependency on this module
return ""
}
}
func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) { func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
bazelModuleLabel := c.getBazelModuleLabel(ctx) bazelModuleLabel := c.getBazelModuleLabel(ctx)
c.bazelHandler.ProcessBazelQueryResponse(ctx, bazelModuleLabel) c.bazelHandler.ProcessBazelQueryResponse(ctx, bazelModuleLabel)