blob: 28109b5ea2cf1dfcd94d90f3fa0d8de89659b35a [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",
Jihoon Kangdc16c222024-08-06 00:15:25 +000055 "android_stubs_current",
56 "android_system_stubs_current",
57 "android_test_stubs_current",
58 "android_test_frameworks_core_stubs_current",
59 "android_module_lib_stubs_current",
60 "android_system_server_stubs_current",
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000061 "android_stubs_current.from-text",
62 "android_system_stubs_current.from-text",
63 "android_test_stubs_current.from-text",
64 "android_test_frameworks_core_stubs_current.from-text",
65 "android_module_lib_stubs_current.from-text",
66 "android_system_server_stubs_current.from-text",
67 "android_stubs_current.from-source",
68 "android_system_stubs_current.from-source",
69 "android_test_stubs_current.from-source",
70 "android_test_frameworks_core_stubs_current.from-source",
71 "android_module_lib_stubs_current.from-source",
72 "android_system_server_stubs_current.from-source",
73 "android_stubs_current_exportable.from-source",
74 "android_system_stubs_current_exportable.from-source",
75 "android_test_stubs_current_exportable.from-source",
76 "android_module_lib_stubs_current_exportable.from-source",
77 "android_system_server_stubs_current_exportable.from-source",
78 "stub-annotations",
79 }
80
Harshit Mahajan989825d2024-10-09 12:42:55 +000081 extraSdkLibraryModules := non_updatable_modules
Jihoon Kangcc4c8f92024-07-18 18:52:03 +000082
83 extraSystemModules := []string{
84 "core-public-stubs-system-modules",
85 "core-module-lib-stubs-system-modules",
86 "stable-core-platform-api-stubs-system-modules",
87 }
88
89 extraFilegroupModules := []string{
90 "non-updatable-current.txt",
91 "non-updatable-removed.txt",
92 "non-updatable-system-current.txt",
93 "non-updatable-system-removed.txt",
94 "non-updatable-test-current.txt",
95 "non-updatable-test-removed.txt",
96 "non-updatable-module-lib-current.txt",
97 "non-updatable-module-lib-removed.txt",
98 "non-updatable-system-server-current.txt",
99 "non-updatable-system-server-removed.txt",
100 "non-updatable-exportable-current.txt",
101 "non-updatable-exportable-removed.txt",
102 "non-updatable-exportable-system-current.txt",
103 "non-updatable-exportable-system-removed.txt",
104 "non-updatable-exportable-test-current.txt",
105 "non-updatable-exportable-test-removed.txt",
106 "non-updatable-exportable-module-lib-current.txt",
107 "non-updatable-exportable-module-lib-removed.txt",
108 "non-updatable-exportable-system-server-current.txt",
109 "non-updatable-exportable-system-server-removed.txt",
110 }
111
112 for _, extra := range extraLibraryModules {
113 bp += fmt.Sprintf(`
114 java_library {
115 name: "%s",
116 srcs: ["a.java"],
117 sdk_version: "none",
118 system_modules: "stable-core-platform-api-stubs-system-modules",
119 compile_dex: true,
120 }
121 `, extra)
122 }
123
124 for _, extra := range extraSdkLibraryModules {
125 bp += fmt.Sprintf(`
126 java_sdk_library {
127 name: "%s",
128 srcs: ["a.java"],
129 public: {
130 enabled: true,
131 },
132 system: {
133 enabled: true,
134 },
135 test: {
136 enabled: true,
137 },
138 module_lib: {
139 enabled: true,
140 },
141 api_packages: [
142 "foo",
143 ],
144 sdk_version: "core_current",
145 compile_dex: true,
146 annotations_enabled: true,
147 }
148 `, extra)
149 }
150
151 for _, extra := range extraFilegroupModules {
152 bp += fmt.Sprintf(`
153 filegroup {
154 name: "%[1]s",
155 }
156 `, extra)
157 }
158
159 for _, extra := range extraSystemModules {
160 bp += fmt.Sprintf(`
161 java_system_modules {
162 name: "%[1]s",
163 libs: ["%[1]s-lib"],
164 }
165 java_library {
166 name: "%[1]s-lib",
167 sdk_version: "none",
168 system_modules: "none",
169 }
170 `, extra)
171 }
172
173 bp += fmt.Sprintf(`
174 java_defaults {
175 name: "android.jar_defaults",
176 }
177 `)
178
179 return bp
180}
181
182func TestCombinedApisDefaults(t *testing.T) {
183
Harshit Mahajan989825d2024-10-09 12:42:55 +0000184 testNonUpdatableModules := append(non_updatable_modules, "framework-foo", "framework-bar")
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000185 result := android.GroupFixturePreparers(
186 prepareForTestWithCombinedApis,
Harshit Mahajan989825d2024-10-09 12:42:55 +0000187 java.FixtureWithLastReleaseApis(testNonUpdatableModules...),
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000188 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
189 variables.VendorVars = map[string]map[string]string{
190 "boolean_var": {
191 "for_testing": "true",
192 },
193 }
194 }),
195 ).RunTestWithBp(t, `
Jihoon Kangdc16c222024-08-06 00:15:25 +0000196 java_sdk_library {
197 name: "framework-foo",
198 srcs: ["a.java"],
199 public: {
200 enabled: true,
201 },
202 system: {
203 enabled: true,
204 },
205 test: {
206 enabled: true,
207 },
208 module_lib: {
209 enabled: true,
210 },
211 api_packages: [
212 "foo",
213 ],
214 sdk_version: "core_current",
215 annotations_enabled: true,
216 }
217 java_sdk_library {
218 name: "framework-bar",
219 srcs: ["a.java"],
220 public: {
221 enabled: true,
222 },
223 system: {
224 enabled: true,
225 },
226 test: {
227 enabled: true,
228 },
229 module_lib: {
230 enabled: true,
231 },
232 api_packages: [
233 "foo",
234 ],
235 sdk_version: "core_current",
236 annotations_enabled: true,
237 }
Liana Kazanova1ae36c82024-08-05 19:45:03 +0000238
Jihoon Kangdc16c222024-08-06 00:15:25 +0000239 combined_apis {
240 name: "foo",
241 bootclasspath: [
242 "framework-bar",
243 ] + select(boolean_var_for_testing(), {
244 true: [
245 "framework-foo",
Liana Kazanova1ae36c82024-08-05 19:45:03 +0000246 ],
Jihoon Kangdc16c222024-08-06 00:15:25 +0000247 default: [],
248 }),
249 }
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000250 `)
251
252 subModuleDependsOnSelectAppendedModule := java.CheckModuleHasDependency(t,
Cole Faust5aeb9fd2024-10-22 16:30:57 -0700253 result.TestContext, "foo-current.txt", "android_common", "framework-foo")
Jihoon Kangcc4c8f92024-07-18 18:52:03 +0000254 android.AssertBoolEquals(t, "Submodule expected to depend on the select-appended module",
255 true, subModuleDependsOnSelectAppendedModule)
256}