Hide static from cc_library_shared and vice versa
The static properties don't make sense for cc_library_shared
modules, and the shared properties don't make sense for
cc_library_static modules. Move them into separate property
structs so they can be added conditionally.
Test: m nothing
Test: DefaultsTest
Change-Id: I0b0cedf9eba07deb721fae138ffa7bedcfbfe71e
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 6275822..689aacd 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -15,8 +15,6 @@
package cc
import (
- "android/soong/android"
-
"fmt"
"io/ioutil"
"os"
@@ -25,6 +23,8 @@
"sort"
"strings"
"testing"
+
+ "android/soong/android"
)
var buildDir string
@@ -53,6 +53,7 @@
}
func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext {
+ t.Helper()
return testCcWithConfigForOs(t, bp, config, android.Android)
}
@@ -2321,3 +2322,67 @@
}
}
}
+
+func TestDefaults(t *testing.T) {
+ ctx := testCc(t, `
+ cc_defaults {
+ name: "defaults",
+ srcs: ["foo.c"],
+ static: {
+ srcs: ["bar.c"],
+ },
+ shared: {
+ srcs: ["baz.c"],
+ },
+ }
+
+ cc_library_static {
+ name: "libstatic",
+ defaults: ["defaults"],
+ }
+
+ cc_library_shared {
+ name: "libshared",
+ defaults: ["defaults"],
+ }
+
+ cc_library {
+ name: "libboth",
+ defaults: ["defaults"],
+ }
+
+ cc_binary {
+ name: "binary",
+ defaults: ["defaults"],
+ }`)
+
+ pathsToBase := func(paths android.Paths) []string {
+ var ret []string
+ for _, p := range paths {
+ ret = append(ret, p.Base())
+ }
+ return ret
+ }
+
+ shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_core_shared").Rule("ld")
+ if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libshared ld rule wanted %q, got %q", w, g)
+ }
+ bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_shared").Rule("ld")
+ if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libboth ld rule wanted %q, got %q", w, g)
+ }
+ binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a_core").Rule("ld")
+ if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("binary ld rule wanted %q, got %q", w, g)
+ }
+
+ static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_core_static").Rule("ar")
+ if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libstatic ar rule wanted %q, got %q", w, g)
+ }
+ bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_static").Rule("ar")
+ if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) {
+ t.Errorf("libboth ar rule wanted %q, got %q", w, g)
+ }
+}