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

Commit 41d05397 authored by Trevor Radcliffe's avatar Trevor Radcliffe Committed by Gerrit Code Review
Browse files

Merge "Add test for LTO edge case"

parents aa97f1dc 07cf4ed9
Loading
Loading
Loading
Loading
+34 −1
Original line number Diff line number Diff line
@@ -15,10 +15,11 @@
package cc

import (
	"android/soong/android"
	"strings"
	"testing"

	"android/soong/android"

	"github.com/google/blueprint"
)

@@ -177,3 +178,35 @@ func TestThinLtoOnlyOnStaticDep(t *testing.T) {
		t.Errorf("'baz' expected to have flags %q, but got %q", w, libFooCFlags)
	}
}

func TestLtoDisabledButEnabledForArch(t *testing.T) {
	t.Parallel()
	bp := `
	cc_library {
		name: "libfoo",
		srcs: ["foo.c"],
		host_supported:true,
		lto: {
			never: true,
		},
		target: {
			android: {
				lto: {
					never: false,
					thin: true,
				},
			},
		},
	}`
	result := android.GroupFixturePreparers(
		prepareForCcTest,
	).RunTestWithBp(t, bp)

	libFooWithLto := result.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("ld")
	libFooWithoutLto := result.ModuleForTests("libfoo", "linux_glibc_x86_64_shared").Rule("ld")

	android.AssertStringDoesContain(t, "missing flag for LTO in variant that expects it",
		libFooWithLto.Args["ldFlags"], "-flto=thin")
	android.AssertStringDoesNotContain(t, "got flag for LTO in variant that doesn't expect it",
		libFooWithoutLto.Args["ldFlags"], "-flto=thin")
}