Просмотр исходного кода

Broaden the granularity of config_setting from apex_name to api_domain am: 9cad90f966

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2577054

Change-Id: I47194c91febd64c91350ac203cc942a1ebed68b2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Spandan Das 1 год назад
Родитель
Сommit
8adfbc21e3
3 измененных файлов с 41 добавлено и 14 удалено
  1. 2 0
      bazel/properties.go
  2. 3 2
      bp2build/cc_library_conversion_test.go
  3. 36 12
      cc/bp2build.go

+ 2 - 0
bazel/properties.go

@@ -1434,4 +1434,6 @@ type StringMapAttribute map[string]string
 type ConfigSettingAttributes struct {
 	// Each key in Flag_values is a label to a custom string_setting
 	Flag_values StringMapAttribute
+	// Each element in Constraint_values is a label to a constraint_value
+	Constraint_values LabelListAttribute
 }

+ 3 - 2
bp2build/cc_library_conversion_test.go

@@ -4473,11 +4473,12 @@ cc_library {
 		ExpectedBazelTargets: []string{
 			MakeBazelTargetNoRestrictions(
 				"config_setting",
-				"android-in_myapex",
+				"myapex",
 				AttrNameToString{
 					"flag_values": `{
-        "//build/bazel/rules/apex:apex_name": "myapex",
+        "//build/bazel/rules/apex:api_domain": "myapex",
     }`,
+					"constraint_values": `["//build/bazel/platforms/os:android"]`,
 				},
 			),
 		},

+ 36 - 12
cc/bp2build.go

@@ -1194,16 +1194,30 @@ func availableToSameApexes(a, b []string) bool {
 }
 
 var (
-	apexConfigSettingKey  = android.NewOnceKey("apexConfigSetting")
-	apexConfigSettingLock sync.Mutex
+	apiDomainConfigSettingKey  = android.NewOnceKey("apiDomainConfigSettingKey")
+	apiDomainConfigSettingLock sync.Mutex
 )
 
-func getApexConfigSettingMap(config android.Config) *map[string]bool {
-	return config.Once(apexConfigSettingKey, func() interface{} {
+func getApiDomainConfigSettingMap(config android.Config) *map[string]bool {
+	return config.Once(apiDomainConfigSettingKey, func() interface{} {
 		return &map[string]bool{}
 	}).(*map[string]bool)
 }
 
+var (
+	testApexNameToApiDomain = map[string]string{
+		"test_broken_com.android.art": "com.android.art",
+	}
+)
+
+func getApiDomain(apexName string) string {
+	if apiDomain, exists := testApexNameToApiDomain[apexName]; exists {
+		return apiDomain
+	}
+	// Remove `test_` prefix
+	return strings.TrimPrefix(apexName, "test_")
+}
+
 // Create a config setting for this apex in build/bazel/rules/apex
 // The use case for this is stub/impl selection in cc libraries
 // Long term, these config_setting(s) should be colocated with the respective apex definitions.
@@ -1215,23 +1229,32 @@ func createInApexConfigSetting(ctx android.TopDownMutatorContext, apexName strin
 		// These correspond to android-non_apex and android-in_apex
 		return
 	}
-	apexConfigSettingLock.Lock()
-	defer apexConfigSettingLock.Unlock()
+	apiDomainConfigSettingLock.Lock()
+	defer apiDomainConfigSettingLock.Unlock()
 
 	// Return if a config_setting has already been created
-	acsm := getApexConfigSettingMap(ctx.Config())
-	if _, exists := (*acsm)[apexName]; exists {
+	apiDomain := getApiDomain(apexName)
+	acsm := getApiDomainConfigSettingMap(ctx.Config())
+	if _, exists := (*acsm)[apiDomain]; exists {
 		return
 	}
-	(*acsm)[apexName] = true
+	(*acsm)[apiDomain] = true
 
 	csa := bazel.ConfigSettingAttributes{
 		Flag_values: bazel.StringMapAttribute{
-			"//build/bazel/rules/apex:apex_name": apexName,
+			"//build/bazel/rules/apex:api_domain": apiDomain,
 		},
+		// Constraint this to android
+		Constraint_values: bazel.MakeLabelListAttribute(
+			bazel.MakeLabelList(
+				[]bazel.Label{
+					bazel.Label{Label: "//build/bazel/platforms/os:android"},
+				},
+			),
+		),
 	}
 	ca := android.CommonAttributes{
-		Name: "android-in_" + apexName,
+		Name: apiDomain,
 	}
 	ctx.CreateBazelConfigSetting(
 		csa,
@@ -1247,7 +1270,8 @@ func inApexConfigSetting(apexAvailable string) string {
 	if apexAvailable == android.AvailableToAnyApex {
 		return bazel.AndroidAndInApex
 	}
-	return "//build/bazel/rules/apex:android-in_" + apexAvailable
+	apiDomain := getApiDomain(apexAvailable)
+	return "//build/bazel/rules/apex:" + apiDomain
 }
 
 func setStubsForDynamicDeps(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis,