Loading android/bazel_handler.go +24 −2 Original line number Diff line number Diff line Loading @@ -92,10 +92,11 @@ type configKey struct { type ApexConfigKey struct { WithinApex bool ApexSdkVersion string ApiDomain 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 { Loading Loading @@ -737,6 +738,7 @@ def _config_node_transition_impl(settings, attr): "@//build/bazel/rules/apex:within_apex": attr.within_apex, "@//build/bazel/rules/apex:min_sdk_version": attr.apex_sdk_version, "@//build/bazel/rules/apex:apex_name": apex_name, "@//build/bazel/rules/apex:api_domain": attr.api_domain, } return outputs Loading @@ -749,6 +751,7 @@ _config_node_transition = transition( "@//build/bazel/rules/apex:within_apex", "@//build/bazel/rules/apex:min_sdk_version", "@//build/bazel/rules/apex:apex_name", "@//build/bazel/rules/apex:api_domain", ], ) Loading @@ -762,6 +765,7 @@ config_node = rule( "os" : attr.string(mandatory = True), "within_apex" : attr.bool(default = False), "apex_sdk_version" : attr.string(mandatory = True), "api_domain" : attr.string(mandatory = 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"), }, Loading Loading @@ -823,6 +827,7 @@ config_node(name = "%s", os = "%s", within_apex = %s, apex_sdk_version = "%s", api_domain = "%s", deps = [%s], testonly = True, # Unblocks testonly deps. ) Loading Loading @@ -856,6 +861,11 @@ config_node(name = "%s", osString := configTokens[1] withinApex := "False" apexSdkVerString := "" apiDomainString := "" if osString == "android" { // api domains are meaningful only for device variants apiDomainString = "system" } targetString := fmt.Sprintf("%s_%s", osString, archString) if len(configTokens) > 2 { targetString += "_" + configTokens[2] Loading @@ -867,9 +877,13 @@ config_node(name = "%s", targetString += "_" + configTokens[3] apexSdkVerString = configTokens[3] } if len(configTokens) > 4 { apiDomainString = configTokens[4] targetString += "_" + apiDomainString } allLabels = append(allLabels, fmt.Sprintf("\":%s\"", targetString)) 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) } Loading Loading @@ -974,11 +988,14 @@ def get_arch(target): within_apex = buildoptions.get("//build/bazel/rules/apex:within_apex") 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: config_key += "|within_apex" if apex_sdk_version != None and len(apex_sdk_version) > 0: config_key += "|" + apex_sdk_version if api_domain != None and len(api_domain) > 0: config_key += "|" + api_domain return config_key Loading Loading @@ -1385,6 +1402,10 @@ func getConfigString(key cqueryKey) string { keyString += "|" + key.configKey.apexKey.ApexSdkVersion } if len(key.configKey.apexKey.ApiDomain) > 0 { keyString += "|" + key.configKey.apexKey.ApiDomain } return keyString } Loading @@ -1403,6 +1424,7 @@ func GetConfigKeyApexVariant(ctx BaseModuleContext, apexKey *ApexConfigKey) conf configKey.apexKey = ApexConfigKey{ WithinApex: apexKey.WithinApex, ApexSdkVersion: apexKey.ApexSdkVersion, ApiDomain: apexKey.ApiDomain, } } Loading android/bazel_handler_test.go +2 −1 Original line number Diff line number Diff line Loading @@ -58,11 +58,12 @@ func TestRequestResultsAfterInvokeBazel(t *testing.T) { apexKey := ApexConfigKey{ WithinApex: true, ApexSdkVersion: "29", ApiDomain: "myapex", } cfg_foo := configKey{"arm64_armv8-a", Android, apexKey} cfg_bar := configKey{arch: "arm64_armv8-a", osType: Android} 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`, } bazelContext, _ := testBazelContext(t, map[bazelCommand]string{cqueryCmd: strings.Join(cmd_results, "\n")}) Loading cc/cc.go +25 −0 Original line number Diff line number Diff line Loading @@ -2003,6 +2003,7 @@ func GetApexConfigKey(ctx android.BaseModuleContext) *android.ApexConfigKey { apexKey := android.ApexConfigKey{ WithinApex: true, ApexSdkVersion: findApexSdkVersion(ctx, apexInfo).String(), ApiDomain: findApiDomain(apexInfo), } return &apexKey } Loading @@ -2010,6 +2011,30 @@ func GetApexConfigKey(ctx android.BaseModuleContext) *android.ApexConfigKey { 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) { bazelModuleLabel := c.getBazelModuleLabel(ctx) c.bazelHandler.ProcessBazelQueryResponse(ctx, bazelModuleLabel) Loading Loading
android/bazel_handler.go +24 −2 Original line number Diff line number Diff line Loading @@ -92,10 +92,11 @@ type configKey struct { type ApexConfigKey struct { WithinApex bool ApexSdkVersion string ApiDomain 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 { Loading Loading @@ -737,6 +738,7 @@ def _config_node_transition_impl(settings, attr): "@//build/bazel/rules/apex:within_apex": attr.within_apex, "@//build/bazel/rules/apex:min_sdk_version": attr.apex_sdk_version, "@//build/bazel/rules/apex:apex_name": apex_name, "@//build/bazel/rules/apex:api_domain": attr.api_domain, } return outputs Loading @@ -749,6 +751,7 @@ _config_node_transition = transition( "@//build/bazel/rules/apex:within_apex", "@//build/bazel/rules/apex:min_sdk_version", "@//build/bazel/rules/apex:apex_name", "@//build/bazel/rules/apex:api_domain", ], ) Loading @@ -762,6 +765,7 @@ config_node = rule( "os" : attr.string(mandatory = True), "within_apex" : attr.bool(default = False), "apex_sdk_version" : attr.string(mandatory = True), "api_domain" : attr.string(mandatory = 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"), }, Loading Loading @@ -823,6 +827,7 @@ config_node(name = "%s", os = "%s", within_apex = %s, apex_sdk_version = "%s", api_domain = "%s", deps = [%s], testonly = True, # Unblocks testonly deps. ) Loading Loading @@ -856,6 +861,11 @@ config_node(name = "%s", osString := configTokens[1] withinApex := "False" apexSdkVerString := "" apiDomainString := "" if osString == "android" { // api domains are meaningful only for device variants apiDomainString = "system" } targetString := fmt.Sprintf("%s_%s", osString, archString) if len(configTokens) > 2 { targetString += "_" + configTokens[2] Loading @@ -867,9 +877,13 @@ config_node(name = "%s", targetString += "_" + configTokens[3] apexSdkVerString = configTokens[3] } if len(configTokens) > 4 { apiDomainString = configTokens[4] targetString += "_" + apiDomainString } allLabels = append(allLabels, fmt.Sprintf("\":%s\"", targetString)) 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) } Loading Loading @@ -974,11 +988,14 @@ def get_arch(target): within_apex = buildoptions.get("//build/bazel/rules/apex:within_apex") 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: config_key += "|within_apex" if apex_sdk_version != None and len(apex_sdk_version) > 0: config_key += "|" + apex_sdk_version if api_domain != None and len(api_domain) > 0: config_key += "|" + api_domain return config_key Loading Loading @@ -1385,6 +1402,10 @@ func getConfigString(key cqueryKey) string { keyString += "|" + key.configKey.apexKey.ApexSdkVersion } if len(key.configKey.apexKey.ApiDomain) > 0 { keyString += "|" + key.configKey.apexKey.ApiDomain } return keyString } Loading @@ -1403,6 +1424,7 @@ func GetConfigKeyApexVariant(ctx BaseModuleContext, apexKey *ApexConfigKey) conf configKey.apexKey = ApexConfigKey{ WithinApex: apexKey.WithinApex, ApexSdkVersion: apexKey.ApexSdkVersion, ApiDomain: apexKey.ApiDomain, } } Loading
android/bazel_handler_test.go +2 −1 Original line number Diff line number Diff line Loading @@ -58,11 +58,12 @@ func TestRequestResultsAfterInvokeBazel(t *testing.T) { apexKey := ApexConfigKey{ WithinApex: true, ApexSdkVersion: "29", ApiDomain: "myapex", } cfg_foo := configKey{"arm64_armv8-a", Android, apexKey} cfg_bar := configKey{arch: "arm64_armv8-a", osType: Android} 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`, } bazelContext, _ := testBazelContext(t, map[bazelCommand]string{cqueryCmd: strings.Join(cmd_results, "\n")}) Loading
cc/cc.go +25 −0 Original line number Diff line number Diff line Loading @@ -2003,6 +2003,7 @@ func GetApexConfigKey(ctx android.BaseModuleContext) *android.ApexConfigKey { apexKey := android.ApexConfigKey{ WithinApex: true, ApexSdkVersion: findApexSdkVersion(ctx, apexInfo).String(), ApiDomain: findApiDomain(apexInfo), } return &apexKey } Loading @@ -2010,6 +2011,30 @@ func GetApexConfigKey(ctx android.BaseModuleContext) *android.ApexConfigKey { 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) { bazelModuleLabel := c.getBazelModuleLabel(ctx) c.bazelHandler.ProcessBazelQueryResponse(ctx, bazelModuleLabel) Loading