Do not install LLNDK libs moved APEX on /system

Export LLNDK_MOVED_TO_APEX_LIBRARIES which is used by make
to filter out LLNDK libs that been migrated to an APEX.
It's used by the ld.config.txt generaton, and to filter out
the vndk_package dependencies.

Test: Build&flashed crosshatch image
Bug: 137320025
Change-Id: I1449dad79edf36a628fa1ac15c35f163dbd8ee2a
diff --git a/cc/makevars.go b/cc/makevars.go
index 78a32c8..8f4aa01 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -63,6 +63,13 @@
 	}
 }
 
+type notOnHostContext struct {
+}
+
+func (c *notOnHostContext) Host() bool {
+	return false
+}
+
 func makeVarsProvider(ctx android.MakeVarsContext) {
 	vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
 
@@ -102,13 +109,23 @@
 	// Therefore, by removing the library here, we cause it to only be installed if libc
 	// depends on it.
 	installedLlndkLibraries := []string{}
+
+	// Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to avoid installing libraries on /system if
+	// they been moved to an apex.
+	movedToApexLlndkLibraries := []string{}
 	for _, lib := range *llndkLibraries(ctx.Config()) {
 		if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
 			continue
 		}
 		installedLlndkLibraries = append(installedLlndkLibraries, lib)
+
+		// Skip bionic libs, they are handled in different manner
+		if android.DirectlyInAnyApex(&notOnHostContext{}, lib) && !isBionic(lib) {
+			movedToApexLlndkLibraries = append(movedToApexLlndkLibraries, lib)
+		}
 	}
 	ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
+	ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", strings.Join(movedToApexLlndkLibraries, " "))
 
 	ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(*vndkPrivateLibraries(ctx.Config()), " "))
 	ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(*vndkUsingCoreVariantLibraries(ctx.Config()), " "))