APEX can depend on non-APEX module and vice versa

Previously, an APEX module (also called apexBundle inside of Soong) had
only one "apex" variant which has the same name as the module. This
prevented an APEX from depending on another module which is outside of
the APEX (ex: another APEX). Similarily, a module outside of an APEX
(ex: a shared lib or a test) couldn't depend on an APEX.

This CL fixes the issue by creating the "" variant as the alias of the
"<apex_name>" variant, and also by setting the "" variant as the default
dependency variant.

Bug: 321626681
Test: m
Change-Id: Ie3e57a96530c25e966cfd551676d819c442bb0d5
diff --git a/apex/apex.go b/apex/apex.go
index d437efe..c030a36 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1306,30 +1306,26 @@
 	}
 
 	// apexBundle itself is mutated so that it and its dependencies have the same apex variant.
-	if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
-		apexBundleName := ai.ApexVariationName()
+	// Note that a default variation "" is also created as an alias, and the default dependency
+	// variation is set to the default variation. This is to allow an apex to depend on another
+	// module which is outside of the apex. This is because the dependent module is not mutated
+	// for this apex variant.
+	createApexVariation := func(apexBundleName string) {
+		defaultVariation := ""
+		mctx.SetDefaultDependencyVariation(&defaultVariation)
 		mctx.CreateVariations(apexBundleName)
-		if strings.HasPrefix(apexBundleName, "com.android.art") {
-			// Create an alias from the platform variant. This is done to make
-			// test_for dependencies work for modules that are split by the APEX
-			// mutator, since test_for dependencies always go to the platform variant.
-			// This doesn't happen for normal APEXes that are disjunct, so only do
-			// this for the overlapping ART APEXes.
-			// TODO(b/183882457): Remove this if the test_for functionality is
-			// refactored to depend on the proper APEX variants instead of platform.
-			mctx.CreateAliasVariation("", apexBundleName)
-		}
+		mctx.CreateAliasVariation(defaultVariation, apexBundleName)
+	}
+
+	if ai, ok := mctx.Module().(ApexInfoMutator); ok && apexModuleTypeRequiresVariant(ai) {
+		createApexVariation(ai.ApexVariationName())
 	} else if o, ok := mctx.Module().(*OverrideApex); ok {
 		apexBundleName := o.GetOverriddenModuleName()
 		if apexBundleName == "" {
 			mctx.ModuleErrorf("base property is not set")
 			return
 		}
-		mctx.CreateVariations(apexBundleName)
-		if strings.HasPrefix(apexBundleName, "com.android.art") {
-			// TODO(b/183882457): See note for CreateAliasVariation above.
-			mctx.CreateAliasVariation("", apexBundleName)
-		}
+		createApexVariation(apexBundleName)
 	}
 }