Support mechanism to select a specific version of module sdk prebuilt

This CL is scoped to cc_* module types. With trunk stable, we will have
multiple prebuilts of the cc modules in
prebuilts/module_sdk/art/<v>/host-exports/, and this CL introduces a
mechanism to use apex_contributions to select a specific versioned
prebuilt when building.

If a soong module is selected using apex_contributions, all rdeps will
get that soong module, which includes
- rdep soong modules which might be depending on it via Android.bp
- Soong's rule builder HostToolPath API

Implementation details: Create a new source_module_name property to
identify the root module. rdeps referring to the root module will get
redirected if necessary. This property also
becomes the stem, if `stem` is not set explicitly.

Bug: 322175508

Test: Added a unit test

Change-Id: Ic8725602c81999621fcb33ce2a57fe4b9751baa8
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index e721c53..8f4b7df 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -17,6 +17,8 @@
 import (
 	"path/filepath"
 
+	"github.com/google/blueprint/proptools"
+
 	"android/soong/android"
 )
 
@@ -36,9 +38,15 @@
 type prebuiltLinkerInterface interface {
 	Name(string) string
 	prebuilt() *android.Prebuilt
+	sourceModuleName() string
 }
 
 type prebuiltLinkerProperties struct {
+	// Name of the source soong module that gets shadowed by this prebuilt
+	// If unspecified, follows the naming convention that the source module of
+	// the prebuilt is Name() without "prebuilt_" prefix
+	Source_module_name *string
+
 	// a prebuilt library or binary. Can reference a genrule module that generates an executable file.
 	Srcs []string `android:"path,arch_variant"`
 
@@ -337,7 +345,11 @@
 }
 
 type prebuiltObjectProperties struct {
-	Srcs []string `android:"path,arch_variant"`
+	// Name of the source soong module that gets shadowed by this prebuilt
+	// If unspecified, follows the naming convention that the source module of
+	// the prebuilt is Name() without "prebuilt_" prefix
+	Source_module_name *string
+	Srcs               []string `android:"path,arch_variant"`
 }
 
 type prebuiltObjectLinker struct {
@@ -351,6 +363,10 @@
 	return &p.Prebuilt
 }
 
+func (p *prebuiltObjectLinker) sourceModuleName() string {
+	return proptools.String(p.properties.Source_module_name)
+}
+
 var _ prebuiltLinkerInterface = (*prebuiltObjectLinker)(nil)
 
 func (p *prebuiltObjectLinker) link(ctx ModuleContext,
@@ -520,3 +536,7 @@
 	}
 	return sanitized.None.Srcs
 }
+
+func (p *prebuiltLinker) sourceModuleName() string {
+	return proptools.String(p.properties.Source_module_name)
+}