Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64379951 authored by Jiyong Park's avatar Jiyong Park
Browse files

Remove -include <file> when compiling stubs.

Otherwise, the force included headers might cause conflicting types
error with the symbols in the generated stubs source code. e.g.

double acos(double); // in header
void acos() {} // in the generated source code

Bug: 120266448
Test: m (apex_test also updated, and passing)
Change-Id: I717df990959d1b24ec515f0f52a4e28b94e92f32
parent 1ee00b54
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -267,6 +267,7 @@ func TestApexWithStubs(t *testing.T) {
		cc_library {
			name: "mylib2",
			srcs: ["mylib.cpp"],
			cflags: ["-include mylib.h"],
			system_shared_libs: [],
			stl: "none",
			stubs: {
@@ -316,6 +317,10 @@ func TestApexWithStubs(t *testing.T) {
	ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_myapex/mylib3.so")
	// .. and not linking to the stubs variant of mylib3
	ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12_myapex/mylib3.so")

	// 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 ")
}

func TestApexWithExplicitStubsDependency(t *testing.T) {
+18 −0
Original line number Diff line number Diff line
@@ -351,6 +351,24 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d

	flags = library.baseCompiler.compilerFlags(ctx, flags, deps)
	if library.buildStubs() {
		// Remove -include <file> when compiling stubs. Otherwise, the force included
		// headers might cause conflicting types error with the symbols in the
		// generated stubs source code. e.g.
		// double acos(double); // in header
		// void acos() {} // in the generated source code
		removeInclude := func(flags []string) []string {
			ret := flags[:0]
			for _, f := range flags {
				if strings.HasPrefix(f, "-include ") {
					continue
				}
				ret = append(ret, f)
			}
			return ret
		}
		flags.GlobalFlags = removeInclude(flags.GlobalFlags)
		flags.CFlags = removeInclude(flags.CFlags)

		flags = addStubLibraryCompilerFlags(flags)
	}
	return flags