Add test for LTO edge case

This test confirms the behavior when LTO is disabled generally but
then enabled for a specific target.

Bug: 261733821
Test: Unit test
Change-Id: I415cd0146f2b83d85654239550d129f87e9001bc
This commit is contained in:
Trevor Radcliffe 2023-02-07 19:46:51 +00:00
parent bae5f4c472
commit 07cf4ed90d

View file

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