Convert the following singletons to use ModuleProxy:

buildTargetSingleton
exportedJavaDeclarationsLibrarySingleton
javaFuzzPackager
kytheExtractAllSingleton
kytheExtractJavaSingleton
kytheExtractRustSingleton
lintSingleton
logtagsSingleton
makeVarsSingleton
ndkAbiDiffSingleton
ndkAbiDumpSingleton
phonySingleton
platformCompatConfigSingleton
sdkSingleton

Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: I625ac8a209ca93755b2ba232202cfb44ecefde0a
diff --git a/android/filegroup.go b/android/filegroup.go
index 47102b9..4fad52a 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -131,10 +131,11 @@
 	return append(Paths{}, fg.srcs...)
 }
 
-func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) {
+func (fg *fileGroup) MakeVars(_ MakeVarsModuleContext) []ModuleMakeVarsValue {
 	if makeVar := String(fg.properties.Export_to_make_var); makeVar != "" {
-		ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " "))
+		return []ModuleMakeVarsValue{{makeVar, strings.Join(fg.srcs.Strings(), " ")}}
 	}
+	return nil
 }
 
 // Defaults
diff --git a/android/logtags.go b/android/logtags.go
index abc37f9..88d36ec 100644
--- a/android/logtags.go
+++ b/android/logtags.go
@@ -42,8 +42,8 @@
 
 func (l *logtagsSingleton) GenerateBuildActions(ctx SingletonContext) {
 	var allLogtags Paths
-	ctx.VisitAllModules(func(module Module) {
-		if !module.ExportedToMake() {
+	ctx.VisitAllModuleProxies(func(module ModuleProxy) {
+		if !OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).ExportedToMake {
 			return
 		}
 		if logtagsInfo, ok := OtherModuleProvider(ctx, module, LogtagsProviderKey); ok {
diff --git a/android/makevars.go b/android/makevars.go
index 2931d0b..692b27e 100644
--- a/android/makevars.go
+++ b/android/makevars.go
@@ -84,6 +84,7 @@
 	Errorf(format string, args ...interface{})
 
 	VisitAllModules(visit func(Module))
+	VisitAllModuleProxies(visit func(proxy ModuleProxy))
 	VisitAllModulesIf(pred func(Module) bool, visit func(Module))
 
 	// Verify the make variable matches the Soong version, fail the build
@@ -108,7 +109,7 @@
 // MakeVarsModuleContext contains the set of functions available for modules
 // implementing the ModuleMakeVarsProvider interface.
 type MakeVarsModuleContext interface {
-	BaseMakeVarsContext
+	Config() Config
 }
 
 var _ PathContext = MakeVarsContext(nil)
@@ -150,14 +151,21 @@
 	return func(ctx MakeVarsContext) { singleton.MakeVars(ctx) }
 }
 
+type ModuleMakeVarsValue struct {
+	// Make variable name.
+	Name string
+	// Make variable value.
+	Value string
+}
+
 // ModuleMakeVarsProvider is a Module with an extra method to provide extra values to be exported to Make.
 type ModuleMakeVarsProvider interface {
-	Module
-
 	// MakeVars uses a MakeVarsModuleContext to provide extra values to be exported to Make.
-	MakeVars(ctx MakeVarsModuleContext)
+	MakeVars(ctx MakeVarsModuleContext) []ModuleMakeVarsValue
 }
 
+var ModuleMakeVarsInfoProvider = blueprint.NewProvider[[]ModuleMakeVarsValue]()
+
 // /////////////////////////////////////////////////////////////////////////////
 
 func makeVarsSingletonFunc() Singleton {
@@ -250,19 +258,24 @@
 	dists = append(dists, singletonDists.dists...)
 	singletonDists.lock.Unlock()
 
-	ctx.VisitAllModules(func(m Module) {
-		if provider, ok := m.(ModuleMakeVarsProvider); ok && m.Enabled(ctx) {
+	ctx.VisitAllModuleProxies(func(m ModuleProxy) {
+		commonInfo, _ := OtherModuleProvider(ctx, m, CommonModuleInfoKey)
+		if provider, ok := OtherModuleProvider(ctx, m, ModuleMakeVarsInfoProvider); ok &&
+			commonInfo.Enabled {
 			mctx := &makeVarsContext{
 				SingletonContext: ctx,
 			}
-
-			provider.MakeVars(mctx)
+			for _, val := range provider {
+				if val.Name != "" {
+					mctx.StrictRaw(val.Name, val.Value)
+				}
+			}
 
 			vars = append(vars, mctx.vars...)
 			phonies = append(phonies, mctx.phonies...)
 		}
 
-		if m.ExportedToMake() {
+		if commonInfo.ExportedToMake {
 			info := OtherModuleProviderOrDefault(ctx, m, InstallFilesProvider)
 			katiInstalls = append(katiInstalls, info.KatiInstalls...)
 			katiInitRcInstalls = append(katiInitRcInstalls, info.KatiInitRcInstalls...)
diff --git a/android/module.go b/android/module.go
index 996c64e..984f037 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1939,6 +1939,7 @@
 	TargetRequiredModuleNames                    []string
 	VintfFragmentModuleNames                     []string
 	Dists                                        []Dist
+	ExportedToMake                               bool
 }
 
 type ApiLevelOrPlatform struct {
@@ -2298,6 +2299,7 @@
 		TargetRequiredModuleNames:                    m.module.TargetRequiredModuleNames(),
 		VintfFragmentModuleNames:                     m.module.VintfFragmentModuleNames(ctx),
 		Dists:                                        m.Dists(),
+		ExportedToMake:                               m.ExportedToMake(),
 	}
 	if mm, ok := m.module.(interface {
 		MinSdkVersion(ctx EarlyModuleContext) ApiLevel
@@ -2368,6 +2370,10 @@
 			GeneratedDeps:        s.GeneratedDeps(),
 		})
 	}
+
+	if v, ok := m.module.(ModuleMakeVarsProvider); m.Enabled(ctx) && ok {
+		SetProvider(ctx, ModuleMakeVarsInfoProvider, v.MakeVars(ctx))
+	}
 }
 
 func SetJarJarPrefixHandler(handler func(ModuleContext)) {
@@ -2884,6 +2890,8 @@
 
 // OutputFileForModule returns the output file paths with the given tag.  On error, including if the
 // module produced zero or multiple paths, it reports errors to the ctx and returns nil.
+// TODO(b/397766191): Change the signature to take ModuleProxy
+// Please only access the module's internal data through providers.
 func OutputFileForModule(ctx PathContext, module Module, tag string) Path {
 	paths, err := outputFilesForModule(ctx, module, tag)
 	if err != nil {
@@ -2924,6 +2932,8 @@
 	EqualModules(m1, m2 Module) bool
 }
 
+// TODO(b/397766191): Change the signature to take ModuleProxy
+// Please only access the module's internal data through providers.
 func outputFilesForModule(ctx PathContext, module Module, tag string) (Paths, error) {
 	outputFilesFromProvider, err := outputFilesForModuleFromProvider(ctx, module, tag)
 	if outputFilesFromProvider != nil || err != OutputFilesProviderNotSet {
@@ -3069,7 +3079,7 @@
 
 	modulesInDir := make(map[string]Paths)
 
-	ctx.VisitAllModules(func(module Module) {
+	ctx.VisitAllModuleProxies(func(module ModuleProxy) {
 		info := OtherModuleProviderOrDefault(ctx, module, FinalModuleBuildTargetsProvider)
 
 		if info.CheckbuildTarget != nil {
diff --git a/android/paths.go b/android/paths.go
index 1c0321c..a944c48 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -229,6 +229,8 @@
 	}
 }
 
+// TODO(b/397766191): Change the signature to take ModuleProxy
+// Please only access the module's internal data through providers.
 func pathContextName(ctx PathContext, module blueprint.Module) string {
 	if x, ok := ctx.(interface{ ModuleName(blueprint.Module) string }); ok {
 		return x.ModuleName(module)
diff --git a/android/phony.go b/android/phony.go
index 7bdd9d3..99ff0aa 100644
--- a/android/phony.go
+++ b/android/phony.go
@@ -55,7 +55,7 @@
 
 func (p *phonySingleton) GenerateBuildActions(ctx SingletonContext) {
 	p.phonyMap = getSingletonPhonyMap(ctx.Config())
-	ctx.VisitAllModules(func(m Module) {
+	ctx.VisitAllModuleProxies(func(m ModuleProxy) {
 		if info, ok := OtherModuleProvider(ctx, m, ModulePhonyProvider); ok {
 			for k, v := range info.Phonies {
 				p.phonyMap[k] = append(p.phonyMap[k], v...)
diff --git a/android/prebuilt_build_tool.go b/android/prebuilt_build_tool.go
index 17b3230..7773bf8 100644
--- a/android/prebuilt_build_tool.go
+++ b/android/prebuilt_build_tool.go
@@ -84,13 +84,12 @@
 	t.toolPath = OptionalPathForPath(installedPath)
 }
 
-func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) {
-	if makeVar := String(t.properties.Export_to_make_var); makeVar != "" {
-		if t.Target().Os != ctx.Config().BuildOS {
-			return
-		}
-		ctx.StrictRaw(makeVar, t.toolPath.String())
+func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) []ModuleMakeVarsValue {
+	if makeVar := String(t.properties.Export_to_make_var); makeVar != "" &&
+		t.Target().Os == ctx.Config().BuildOS {
+		return []ModuleMakeVarsValue{{makeVar, t.toolPath.String()}}
 	}
+	return nil
 }
 
 func (t *prebuiltBuildTool) HostToolPath() OptionalPath {