From 5d1598f746e513001443f44f9f4a70a54f73d039 Mon Sep 17 00:00:00 2001
From: Jiyong Park <jiyong@google.com>
Date: Mon, 25 Feb 2019 22:14:17 +0900
Subject: Fix: sysprop module can't be used with whole_static_libs

When a sysprop module is listed in whole_static_libs, it is renamed to
"lib" + <module> to actually refer to the generated C++ library for the
sysprop module.

Test: m (sysprop_test amended)
Change-Id: I05eddb24433d444376787be567830929ef078159
---
 cc/cc.go                | 14 ++++++++++----
 sysprop/sysprop_test.go | 18 +++++++++++++++++-
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/cc/cc.go b/cc/cc.go
index 7b19e98d..ddc47eae 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1225,12 +1225,18 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
 		return
 	}
 
-	actx.AddVariationDependencies([]blueprint.Variation{
-		{Mutator: "link", Variation: "static"},
-	}, wholeStaticDepTag, deps.WholeStaticLibs...)
-
 	syspropImplLibraries := syspropImplLibraries(actx.Config())
 
+	for _, lib := range deps.WholeStaticLibs {
+		depTag := wholeStaticDepTag
+		if impl, ok := syspropImplLibraries[lib]; ok {
+			lib = impl
+		}
+		actx.AddVariationDependencies([]blueprint.Variation{
+			{Mutator: "link", Variation: "static"},
+		}, depTag, lib)
+	}
+
 	for _, lib := range deps.StaticLibs {
 		depTag := staticDepTag
 		if inList(lib, deps.ReexportStaticLibHeaders) {
diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index 745e4241..79b0f4e8 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -73,6 +73,7 @@ func testContext(config android.Config, bp string,
 	})
 
 	ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
+	ctx.RegisterModuleType("cc_library_static", android.ModuleFactoryAdaptor(cc.LibraryFactory))
 	ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
 	ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
 	ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
@@ -251,6 +252,12 @@ func TestSyspropLibrary(t *testing.T) {
 			static_libs: ["sysprop-platform"],
 		}
 
+		cc_library_static {
+			name: "cc-client-platform-static",
+			srcs: ["d.cpp"],
+			whole_static_libs: ["sysprop-platform"],
+		}
+
 		cc_library {
 			name: "cc-client-product",
 			srcs: ["d.cpp"],
@@ -300,12 +307,21 @@ func TestSyspropLibrary(t *testing.T) {
 	platformClient := ctx.ModuleForTests("cc-client-platform", coreVariant)
 	platformFlags := platformClient.Rule("cc").Args["cFlags"]
 
-	// Platform should use platform's internal header
+	// platform should use platform's internal header
 	if !strings.Contains(platformFlags, platformInternalPath) {
 		t.Errorf("flags for platform must contain %#v, but was %#v.",
 			platformInternalPath, platformFlags)
 	}
 
+	platformStaticClient := ctx.ModuleForTests("cc-client-platform-static", coreVariant)
+	platformStaticFlags := platformStaticClient.Rule("cc").Args["cFlags"]
+
+	// platform-static should use platform's internal header
+	if !strings.Contains(platformStaticFlags, platformInternalPath) {
+		t.Errorf("flags for platform-static must contain %#v, but was %#v.",
+			platformInternalPath, platformStaticFlags)
+	}
+
 	productClient := ctx.ModuleForTests("cc-client-product", coreVariant)
 	productFlags := productClient.Rule("cc").Args["cFlags"]
 
-- 
cgit v1.2.3