blob: 99d982bdaab41d35ab1b521922e7a131a5bed760 [file] [log] [blame]
Bob Badourafd99fd2022-05-23 12:37:02 -07001package android
2
3import (
4 "testing"
5
6 "github.com/google/blueprint"
7)
8
9var genNoticeTests = []struct {
10 name string
11 fs MockFS
12 expectedErrors []string
13}{
14 {
Bob Badour4660a982022-09-12 16:06:03 -070015 name: "gen_notice must not accept licenses property",
16 fs: map[string][]byte{
17 "top/Android.bp": []byte(`
18 gen_notice {
19 name: "top_license",
20 licenses: ["other_license"],
21 }`),
22 },
23 expectedErrors: []string{
24 `not supported on "gen_notice" modules`,
25 },
26 },
27 {
Bob Badourafd99fd2022-05-23 12:37:02 -070028 name: "bad gen_notice",
29 fs: map[string][]byte{
30 "top/Android.bp": []byte(`
31 gen_notice {
32 name: "top_notice",
33 for: ["top_rule"],
34 }`),
35 "other/Android.bp": []byte(`
36 mock_genrule {
37 name: "other_rule",
38 dep: ["top_notice"],
39 }`),
40 },
41 expectedErrors: []string{
42 `module "top_notice": for: no "top_rule" module exists`,
43 },
44 },
45 {
46 name: "doubly bad gen_notice",
47 fs: map[string][]byte{
48 "top/Android.bp": []byte(`
49 gen_notice {
50 name: "top_notice",
51 for: ["top_rule", "other_rule"],
52 }`),
53 },
54 expectedErrors: []string{
55 `module "top_notice": for: modules "top_rule", "other_rule" do not exist`,
56 },
57 },
58 {
59 name: "good gen_notice",
60 fs: map[string][]byte{
61 "top/Android.bp": []byte(`
62 gen_notice {
63 name: "top_notice",
64 for: ["top_rule"],
65 }
66
67 mock_genrule {
68 name: "top_rule",
69 dep: ["top_notice"],
70 }`),
71 "other/Android.bp": []byte(`
72 mock_genrule {
73 name: "other_rule",
74 dep: ["top_notice"],
75 }`),
76 },
77 },
78 {
79 name: "multiple license kinds",
80 fs: map[string][]byte{
81 "top/Android.bp": []byte(`
82 gen_notice {
83 name: "top_notice",
84 for: ["top_rule"],
85 }
86
87 gen_notice {
88 name: "top_html_notice",
89 html: true,
90 for: ["top_rule"],
91 }
92
93 gen_notice {
94 name: "top_xml_notice",
95 xml: true,
96 for: ["top_notice"],
97 }
98
99 mock_genrule {
100 name: "top_rule",
101 dep: [
102 "top_notice",
103 "top_html_notice",
104 "top_xml_notice",
105 ],
106 }`),
107 "other/Android.bp": []byte(`
108 mock_genrule {
109 name: "other_rule",
110 dep: ["top_xml_notice"],
111 }`),
112 },
113 },
114}
115
116func TestGenNotice(t *testing.T) {
117 for _, test := range genNoticeTests {
118 t.Run(test.name, func(t *testing.T) {
119 GroupFixturePreparers(
120 PrepareForTestWithGenNotice,
121 FixtureRegisterWithContext(func(ctx RegistrationContext) {
122 ctx.RegisterModuleType("mock_genrule", newMockGenruleModule)
123 }),
124 test.fs.AddToFixture(),
125 ).
126 ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
127 RunTest(t)
128 })
129 }
130}
131
132type mockGenruleProperties struct {
133 Dep []string
134}
135
136type mockGenruleModule struct {
137 ModuleBase
138 DefaultableModuleBase
139
140 properties mockGenruleProperties
141}
142
143func newMockGenruleModule() Module {
144 m := &mockGenruleModule{}
145 m.AddProperties(&m.properties)
146 InitAndroidArchModule(m, HostAndDeviceSupported, MultilibCommon)
147 InitDefaultableModule(m)
148 return m
149}
150
151type genruleDepTag struct {
152 blueprint.BaseDependencyTag
153}
154
155func (j *mockGenruleModule) DepsMutator(ctx BottomUpMutatorContext) {
156 m, ok := ctx.Module().(Module)
157 if !ok {
158 return
159 }
160 ctx.AddDependency(m, genruleDepTag{}, j.properties.Dep...)
161}
162
163func (p *mockGenruleModule) GenerateAndroidBuildActions(ModuleContext) {
164}