blob: 47d167093b39570ab4996df33ab45cd238aa2e28 [file] [log] [blame]
Jihoon Kangcc4c8f92024-07-18 18:52:03 +00001// Copyright (C) 2024 The Android Open Source Project
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 api
16
17import (
18 "android/soong/android"
19 "android/soong/java"
20 "fmt"
21 "testing"
22
23 "github.com/google/blueprint/proptools"
24)
25
26var prepareForTestWithCombinedApis = android.GroupFixturePreparers(
27 android.FixtureRegisterWithContext(registerBuildComponents),
28 java.PrepareForTestWithJavaBuildComponents,
29 android.FixtureAddTextFile("a/Android.bp", gatherRequiredDepsForTest()),
30 java.PrepareForTestWithJavaSdkLibraryFiles,
31 android.FixtureMergeMockFs(android.MockFS{
32 "a/api/current.txt": nil,
33 "a/api/removed.txt": nil,
34 "a/api/system-current.txt": nil,
35 "a/api/system-removed.txt": nil,
36 "a/api/test-current.txt": nil,
37 "a/api/test-removed.txt": nil,
38 "a/api/module-lib-current.txt": nil,
39 "a/api/module-lib-removed.txt": nil,
40 }),
41 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
42 variables.Allow_missing_dependencies = proptools.BoolPtr(true)
43 }),
44)
45
46func gatherRequiredDepsForTest() string {
47 var bp string
48
49 extraLibraryModules := []string{
50 "stable.core.platform.api.stubs",
51 "core-lambda-stubs",
52 "core.current.stubs",
53 "ext",
54 "framework",
55 "android_stubs_current.from-text",
56 "android_system_stubs_current.from-text",
57 "android_test_stubs_current.from-text",
58 "android_test_frameworks_core_stubs_current.from-text",
59 "android_module_lib_stubs_current.from-text",
60 "android_system_server_stubs_current.from-text",
61 "android_stubs_current.from-source",
62 "android_system_stubs_current.from-source",
63 "android_test_stubs_current.from-source",
64 "android_test_frameworks_core_stubs_current.from-source",
65 "android_module_lib_stubs_current.from-source",
66 "android_system_server_stubs_current.from-source",
67 "android_stubs_current_exportable.from-source",
68 "android_system_stubs_current_exportable.from-source",
69 "android_test_stubs_current_exportable.from-source",
70 "android_module_lib_stubs_current_exportable.from-source",
71 "android_system_server_stubs_current_exportable.from-source",
72 "stub-annotations",
73 }
74
75 extraSdkLibraryModules := []string{
76 "framework-virtualization",
77 "framework-location",
78 }
79
80 extraSystemModules := []string{
81 "core-public-stubs-system-modules",
82 "core-module-lib-stubs-system-modules",
83 "stable-core-platform-api-stubs-system-modules",
84 }
85
86 extraFilegroupModules := []string{
87 "non-updatable-current.txt",
88 "non-updatable-removed.txt",
89 "non-updatable-system-current.txt",
90 "non-updatable-system-removed.txt",
91 "non-updatable-test-current.txt",
92 "non-updatable-test-removed.txt",
93 "non-updatable-module-lib-current.txt",
94 "non-updatable-module-lib-removed.txt",
95 "non-updatable-system-server-current.txt",
96 "non-updatable-system-server-removed.txt",
97 "non-updatable-exportable-current.txt",
98 "non-updatable-exportable-removed.txt",
99 "non-updatable-exportable-system-current.txt",
100 "non-updatable-exportable-system-removed.txt",
101 "non-updatable-exportable-test-current.txt",
102 "non-updatable-exportable-test-removed.txt",
103 "non-updatable-exportable-module-lib-current.txt",
104 "non-updatable-exportable-module-lib-removed.txt",
105 "non-updatable-exportable-system-server-current.txt",
106 "non-updatable-exportable-system-server-removed.txt",
107 }
108
109 for _, extra := range extraLibraryModules {
110 bp += fmt.Sprintf(`
111 java_library {
112 name: "%s",
113 srcs: ["a.java"],
114 sdk_version: "none",
115 system_modules: "stable-core-platform-api-stubs-system-modules",
116 compile_dex: true,
117 }
118 `, extra)
119 }
120
121 for _, extra := range extraSdkLibraryModules {
122 bp += fmt.Sprintf(`
123 java_sdk_library {
124 name: "%s",
125 srcs: ["a.java"],
126 public: {
127 enabled: true,
128 },
129 system: {
130 enabled: true,
131 },
132 test: {
133 enabled: true,
134 },
135 module_lib: {
136 enabled: true,
137 },
138 api_packages: [
139 "foo",
140 ],
141 sdk_version: "core_current",
142 compile_dex: true,
143 annotations_enabled: true,
144 }
145 `, extra)
146 }
147
148 for _, extra := range extraFilegroupModules {
149 bp += fmt.Sprintf(`
150 filegroup {
151 name: "%[1]s",
152 }
153 `, extra)
154 }
155
156 for _, extra := range extraSystemModules {
157 bp += fmt.Sprintf(`
158 java_system_modules {
159 name: "%[1]s",
160 libs: ["%[1]s-lib"],
161 }
162 java_library {
163 name: "%[1]s-lib",
164 sdk_version: "none",
165 system_modules: "none",
166 }
167 `, extra)
168 }
169
170 bp += fmt.Sprintf(`
171 java_defaults {
172 name: "android.jar_defaults",
173 }
174 `)
175
176 return bp
177}
178
179func TestCombinedApisDefaults(t *testing.T) {
180
181 result := android.GroupFixturePreparers(
182 prepareForTestWithCombinedApis,
183 java.FixtureWithLastReleaseApis(
184 "framework-location", "framework-virtualization", "framework-foo", "framework-bar"),
185 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
186 variables.VendorVars = map[string]map[string]string{
187 "boolean_var": {
188 "for_testing": "true",
189 },
190 }
191 }),
192 ).RunTestWithBp(t, `
Liana Kazanova1ae36c82024-08-05 19:45:03 +0000193 java_sdk_library {
194 name: "framework-foo",
195 srcs: ["a.java"],
196 public: {
197 enabled: true,
198 },
199 system: {
200 enabled: true,
201 },
202 test: {
203 enabled: true,
204 },
205 module_lib: {
206 enabled: true,
207 },
208 api_packages: [
209 "foo",
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000210 ],
Liana Kazanova1ae36c82024-08-05 19:45:03 +0000211 sdk_version: "core_current",
212 annotations_enabled: true,
213 }
214
215 java_sdk_library {
216 name: "framework-bar",
217 srcs: ["a.java"],
218 public: {
219 enabled: true,
220 },
221 system: {
222 enabled: true,
223 },
224 test: {
225 enabled: true,
226 },
227 module_lib: {
228 enabled: true,
229 },
230 api_packages: [
231 "foo",
232 ],
233 sdk_version: "core_current",
234 annotations_enabled: true,
235 }
236
237 combined_apis {
238 name: "foo",
239 bootclasspath: [
240 "framework-bar",
241 ] + select(boolean_var_for_testing(), {
242 true: [
243 "framework-foo",
244 ],
245 default: [],
246 }),
247 }
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000248 `)
249
250 subModuleDependsOnSelectAppendedModule := java.CheckModuleHasDependency(t,
251 result.TestContext, "foo-current.txt", "", "framework-foo")
252 android.AssertBoolEquals(t, "Submodule expected to depend on the select-appended module",
253 true, subModuleDependsOnSelectAppendedModule)
254}