cc/cc.go: Support per-image-variation "required"

Support "core" and "recovery" variants for now. Might add more image
types if needed.

Bug: 191369319
Test: Presubmit
Test: Inspect out/soong/Android-*.mk
Change-Id: Iebab29ed5d6d8fe9c66b6d6e56e00246d10c36b3
diff --git a/cc/cc.go b/cc/cc.go
index 7aec7f2..1ee1137 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -354,6 +354,24 @@
 	// can depend on libraries that are not exported by the APEXes and use private symbols
 	// from the exported libraries.
 	Test_for []string `android:"arch_variant"`
+
+	Target struct {
+		Platform struct {
+			// List of modules required by the core variant.
+			Required []string `android:"arch_variant"`
+
+			// List of modules not required by the core variant.
+			Exclude_required []string `android:"arch_variant"`
+		} `android:"arch_variant"`
+
+		Recovery struct {
+			// List of modules required by the recovery variant.
+			Required []string `android:"arch_variant"`
+
+			// List of modules not required by the recovery variant.
+			Exclude_required []string `android:"arch_variant"`
+		} `android:"arch_variant"`
+	} `android:"arch_variant"`
 }
 
 type VendorProperties struct {
@@ -865,6 +883,18 @@
 	return c.Properties.HideFromMake
 }
 
+func (c *Module) RequiredModuleNames() []string {
+	required := android.CopyOf(c.ModuleBase.RequiredModuleNames())
+	if c.ImageVariation().Variation == android.CoreVariation {
+		required = append(required, c.Properties.Target.Platform.Required...)
+		required = removeListFromList(required, c.Properties.Target.Platform.Exclude_required)
+	} else if c.InRecovery() {
+		required = append(required, c.Properties.Target.Recovery.Required...)
+		required = removeListFromList(required, c.Properties.Target.Recovery.Exclude_required)
+	}
+	return android.FirstUniqueStrings(required)
+}
+
 func (c *Module) Toc() android.OptionalPath {
 	if c.linker != nil {
 		if library, ok := c.linker.(libraryInterface); ok {