Set __<libname>_API__ macro when building against stubs

When building against libFoo#ver, __LIBFOO_API__ macro is set to ver so
that headers from libFoo can be conditionally compiled (e.g., hide APIs
that are not available for the version, etc.)

Bug: 112672359
Test: m (cc_test added)
Change-Id: I863ef95b385cdd842eec1bf34e81f44b5e3b58b3
diff --git a/cc/cc_test.go b/cc/cc_test.go
index fba38a2..e4904f2 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -1738,13 +1738,16 @@
 	ctx := testCc(t, `
 		cc_library_shared {
 			name: "libFoo",
+			srcs: ["foo.c"],
 			stubs: {
 				symbol_file: "foo.map.txt",
 				versions: ["1", "2", "3"],
 			},
 		}
+
 		cc_library_shared {
 			name: "libBar",
+			srcs: ["bar.c"],
 			shared_libs: ["libFoo#1"],
 		}`)
 
@@ -1786,4 +1789,11 @@
 	if !strings.Contains(libFlags, libFoo1StubPath) {
 		t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
 	}
+
+	libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc")
+	cFlags := libBarCompileRule.Args["cFlags"]
+	libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
+	if !strings.Contains(cFlags, libFoo1VersioningMacro) {
+		t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
+	}
 }