blob: b52f2b6a3d4585d82b458bf4ebad9e27a7ff239d [file] [log] [blame]
Liz Kammer3b0f36c2022-09-16 12:39:27 -04001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "android/soong/android"
19 "strings"
20 "testing"
21
22 "github.com/google/blueprint"
23)
24
25func TestThinLtoDeps(t *testing.T) {
26 bp := `
27 cc_library {
28 name: "lto_enabled",
29 srcs: ["src.c"],
30 static_libs: ["foo"],
31 shared_libs: ["bar"],
32 lto: {
33 thin: true,
34 }
35 }
36 cc_library {
37 name: "foo",
38 static_libs: ["baz"],
39 }
40 cc_library {
41 name: "bar",
42 static_libs: ["qux"],
43 }
44 cc_library {
45 name: "baz",
46 }
47 cc_library {
48 name: "qux",
49 }
50`
51
52 result := android.GroupFixturePreparers(
53 prepareForCcTest,
54 ).RunTestWithBp(t, bp)
55
56 libLto := result.ModuleForTests("lto_enabled", "android_arm64_armv8-a_shared").Module()
57 libFoo := result.ModuleForTests("foo", "android_arm64_armv8-a_static_lto-thin").Module()
58 libBaz := result.ModuleForTests("baz", "android_arm64_armv8-a_static_lto-thin").Module()
59
60 hasDep := func(m android.Module, wantDep android.Module) bool {
61 var found bool
62 result.VisitDirectDeps(m, func(dep blueprint.Module) {
63 if dep == wantDep {
64 found = true
65 }
66 })
67 return found
68 }
69
70 if !hasDep(libLto, libFoo) {
71 t.Errorf("'lto_enabled' missing dependency on thin lto variant of 'foo'")
72 }
73
74 if !hasDep(libFoo, libBaz) {
75 t.Errorf("'lto_enabled' missing dependency on thin lto variant of transitive dep 'baz'")
76 }
77
78 barVariants := result.ModuleVariantsForTests("bar")
79 for _, v := range barVariants {
80 if strings.Contains(v, "lto-thin") {
81 t.Errorf("Expected variants for 'bar' to not contain 'lto-thin', but found %q", v)
82 }
83 }
84 quxVariants := result.ModuleVariantsForTests("qux")
85 for _, v := range quxVariants {
86 if strings.Contains(v, "lto-thin") {
87 t.Errorf("Expected variants for 'qux' to not contain 'lto-thin', but found %q", v)
88 }
89 }
90}