When a stub is built for APEX, it is generated with --apex

Now, symbols that are only to be visible to across APEXes can be tagged
as # vndk. Then when generating the stubs library, the tagged symbol
is included. The symbol is NOT included in other cases; build NDK stubs,
etc.

Bug: 120638081
Test: m (apex_test updated.)
Change-Id: Idb2b552badddfc26af113cc8d4b984788f478813
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 88c57bc..acc895f 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -321,6 +321,9 @@
 	// Ensure that stubs libs are built without -include flags
 	mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"]
 	ensureNotContains(t, mylib2Cflags, "-include ")
+
+	// Ensure that genstub is invoked with --apex
+	ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3_myapex").Rule("genStubSrc").Args["flags"])
 }
 
 func TestApexWithExplicitStubsDependency(t *testing.T) {
diff --git a/cc/library.go b/cc/library.go
index 524b886..86cd5da 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -395,7 +395,7 @@
 
 func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
 	if library.buildStubs() {
-		objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "")
+		objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "--apex")
 		library.versionScriptPath = versionScript
 		return objs
 	}
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 53fe314..1b09f88 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -31,9 +31,9 @@
 	genStubSrc = pctx.AndroidStaticRule("genStubSrc",
 		blueprint.RuleParams{
 			Command: "$toolPath --arch $arch --api $apiLevel --api-map " +
-				"$apiMap $vndk $in $out",
+				"$apiMap $flags $in $out",
 			CommandDeps: []string{"$toolPath"},
-		}, "arch", "apiLevel", "apiMap", "vndk")
+		}, "arch", "apiLevel", "apiMap", "flags")
 
 	ndkLibrarySuffix = ".ndk"
 
@@ -271,7 +271,7 @@
 	return addStubLibraryCompilerFlags(flags)
 }
 
-func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, vndk string) (Objects, android.ModuleGenPath) {
+func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, genstubFlags string) (Objects, android.ModuleGenPath) {
 	arch := ctx.Arch().ArchType.String()
 
 	stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
@@ -288,7 +288,7 @@
 			"arch":     arch,
 			"apiLevel": apiLevel,
 			"apiMap":   apiLevelsJson.String(),
-			"vndk":     vndk,
+			"flags":    genstubFlags,
 		},
 	})