summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2021-12-02 14:50:47 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2021-12-02 14:50:47 +0000
commiteca59f3deecf7fc14a4c9cbee2b0e14b2e34cb66 (patch)
treeec91728d462e1093bf22896255394e1d9ae0c328
parenta71eabb7052e000b53c40a21e30651e1e364710e (diff)
parentd51cb5c130700cc4442ee53187e15181d5eabaa2 (diff)
Merge changes Ied267053,Ica29c649
* changes: Fix prebuilt header files to produce proper AndroidMk entries. Reduce code duplication for testing the two header modules.
-rw-r--r--cc/library_headers_test.go64
-rw-r--r--cc/prebuilt.go8
2 files changed, 35 insertions, 37 deletions
diff --git a/cc/library_headers_test.go b/cc/library_headers_test.go
index 9789ab04b..3e448ba26 100644
--- a/cc/library_headers_test.go
+++ b/cc/library_headers_test.go
@@ -16,7 +16,6 @@ package cc
import (
"fmt"
- "strings"
"testing"
"android/soong/android"
@@ -25,44 +24,37 @@ import (
)
func TestLibraryHeaders(t *testing.T) {
- ctx := testCc(t, `
- cc_library_headers {
- name: "headers",
- export_include_dirs: ["my_include"],
- }
- cc_library_static {
- name: "lib",
- srcs: ["foo.c"],
- header_libs: ["headers"],
- }
- `)
+ bp := `
+ %s {
+ name: "headers",
+ export_include_dirs: ["my_include"],
+ }
+ cc_library_static {
+ name: "lib",
+ srcs: ["foo.c"],
+ header_libs: ["headers"],
+ }
+ `
- // test if header search paths are correctly added
- cc := ctx.ModuleForTests("lib", "android_arm64_armv8-a_static").Rule("cc")
- cflags := cc.Args["cFlags"]
- if !strings.Contains(cflags, " -Imy_include ") {
- t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
- }
-}
+ for _, headerModule := range []string{"cc_library_headers", "cc_prebuilt_library_headers"} {
+ t.Run(headerModule, func(t *testing.T) {
+ ctx := testCc(t, fmt.Sprintf(bp, headerModule))
-func TestPrebuiltLibraryHeaders(t *testing.T) {
- ctx := testCc(t, `
- cc_prebuilt_library_headers {
- name: "headers",
- export_include_dirs: ["my_include"],
- }
- cc_library_static {
- name: "lib",
- srcs: ["foo.c"],
- header_libs: ["headers"],
- }
- `)
+ // test if header search paths are correctly added
+ cc := ctx.ModuleForTests("lib", "android_arm64_armv8-a_static").Rule("cc")
+ android.AssertStringDoesContain(t, "cFlags for lib module", cc.Args["cFlags"], " -Imy_include ")
+
+ // Test that there's a valid AndroidMk entry.
+ headers := ctx.ModuleForTests("headers", "android_arm64_armv8-a").Module()
+ e := android.AndroidMkEntriesForTest(t, ctx, headers)[0]
- // test if header search paths are correctly added
- cc := ctx.ModuleForTests("lib", "android_arm64_armv8-a_static").Rule("cc")
- cflags := cc.Args["cFlags"]
- if !strings.Contains(cflags, " -Imy_include ") {
- t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
+ // This duplicates the tests done in AndroidMkEntries.write. It would be
+ // better to test its output, but there are no test functions that capture that.
+ android.AssertBoolEquals(t, "AndroidMkEntries.Disabled", false, e.Disabled)
+ android.AssertBoolEquals(t, "AndroidMkEntries.OutputFile.Valid()", true, e.OutputFile.Valid())
+
+ android.AssertStringListContains(t, "LOCAL_EXPORT_CFLAGS for headers module", e.EntryMap["LOCAL_EXPORT_CFLAGS"], "-Imy_include")
+ })
}
}
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index a279054c3..c303fda99 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -197,7 +197,13 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
if p.header() {
ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{})
- return nil
+ // Need to return an output path so that the AndroidMk logic doesn't skip
+ // the prebuilt header. For compatibility, in case Android.mk files use a
+ // header lib in LOCAL_STATIC_LIBRARIES, create an empty ar file as
+ // placeholder, just like non-prebuilt header modules do in linkStatic().
+ ph := android.PathForModuleOut(ctx, ctx.ModuleName()+staticLibraryExtension)
+ transformObjToStaticLib(ctx, nil, nil, builderFlags{}, ph, nil, nil)
+ return ph
}
return nil