Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package api |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java" |
| 20 | "fmt" |
| 21 | "testing" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | ) |
| 25 | |
| 26 | var 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 | |
| 46 | func 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 Kang | d6e978e | 2024-02-29 23:09:10 +0000 | [diff] [blame^] | 55 | "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 Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 61 | "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 | |
| 81 | extraSdkLibraryModules := []string{ |
| 82 | "framework-virtualization", |
| 83 | "framework-location", |
| 84 | } |
| 85 | |
| 86 | extraSystemModules := []string{ |
| 87 | "core-public-stubs-system-modules", |
| 88 | "core-module-lib-stubs-system-modules", |
| 89 | "stable-core-platform-api-stubs-system-modules", |
| 90 | } |
| 91 | |
| 92 | extraFilegroupModules := []string{ |
| 93 | "non-updatable-current.txt", |
| 94 | "non-updatable-removed.txt", |
| 95 | "non-updatable-system-current.txt", |
| 96 | "non-updatable-system-removed.txt", |
| 97 | "non-updatable-test-current.txt", |
| 98 | "non-updatable-test-removed.txt", |
| 99 | "non-updatable-module-lib-current.txt", |
| 100 | "non-updatable-module-lib-removed.txt", |
| 101 | "non-updatable-system-server-current.txt", |
| 102 | "non-updatable-system-server-removed.txt", |
| 103 | "non-updatable-exportable-current.txt", |
| 104 | "non-updatable-exportable-removed.txt", |
| 105 | "non-updatable-exportable-system-current.txt", |
| 106 | "non-updatable-exportable-system-removed.txt", |
| 107 | "non-updatable-exportable-test-current.txt", |
| 108 | "non-updatable-exportable-test-removed.txt", |
| 109 | "non-updatable-exportable-module-lib-current.txt", |
| 110 | "non-updatable-exportable-module-lib-removed.txt", |
| 111 | "non-updatable-exportable-system-server-current.txt", |
| 112 | "non-updatable-exportable-system-server-removed.txt", |
| 113 | } |
| 114 | |
| 115 | for _, extra := range extraLibraryModules { |
| 116 | bp += fmt.Sprintf(` |
| 117 | java_library { |
| 118 | name: "%s", |
| 119 | srcs: ["a.java"], |
| 120 | sdk_version: "none", |
| 121 | system_modules: "stable-core-platform-api-stubs-system-modules", |
| 122 | compile_dex: true, |
| 123 | } |
| 124 | `, extra) |
| 125 | } |
| 126 | |
| 127 | for _, extra := range extraSdkLibraryModules { |
| 128 | bp += fmt.Sprintf(` |
| 129 | java_sdk_library { |
| 130 | name: "%s", |
| 131 | srcs: ["a.java"], |
| 132 | public: { |
| 133 | enabled: true, |
| 134 | }, |
| 135 | system: { |
| 136 | enabled: true, |
| 137 | }, |
| 138 | test: { |
| 139 | enabled: true, |
| 140 | }, |
| 141 | module_lib: { |
| 142 | enabled: true, |
| 143 | }, |
| 144 | api_packages: [ |
| 145 | "foo", |
| 146 | ], |
| 147 | sdk_version: "core_current", |
| 148 | compile_dex: true, |
| 149 | annotations_enabled: true, |
| 150 | } |
| 151 | `, extra) |
| 152 | } |
| 153 | |
| 154 | for _, extra := range extraFilegroupModules { |
| 155 | bp += fmt.Sprintf(` |
| 156 | filegroup { |
| 157 | name: "%[1]s", |
| 158 | } |
| 159 | `, extra) |
| 160 | } |
| 161 | |
| 162 | for _, extra := range extraSystemModules { |
| 163 | bp += fmt.Sprintf(` |
| 164 | java_system_modules { |
| 165 | name: "%[1]s", |
| 166 | libs: ["%[1]s-lib"], |
| 167 | } |
| 168 | java_library { |
| 169 | name: "%[1]s-lib", |
| 170 | sdk_version: "none", |
| 171 | system_modules: "none", |
| 172 | } |
| 173 | `, extra) |
| 174 | } |
| 175 | |
| 176 | bp += fmt.Sprintf(` |
| 177 | java_defaults { |
| 178 | name: "android.jar_defaults", |
| 179 | } |
| 180 | `) |
| 181 | |
| 182 | return bp |
| 183 | } |
| 184 | |
| 185 | func TestCombinedApisDefaults(t *testing.T) { |
| 186 | |
| 187 | result := android.GroupFixturePreparers( |
| 188 | prepareForTestWithCombinedApis, |
| 189 | java.FixtureWithLastReleaseApis( |
| 190 | "framework-location", "framework-virtualization", "framework-foo", "framework-bar"), |
| 191 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 192 | variables.VendorVars = map[string]map[string]string{ |
| 193 | "boolean_var": { |
| 194 | "for_testing": "true", |
| 195 | }, |
| 196 | } |
| 197 | }), |
| 198 | ).RunTestWithBp(t, ` |
Jihoon Kang | d6e978e | 2024-02-29 23:09:10 +0000 | [diff] [blame^] | 199 | java_sdk_library { |
| 200 | name: "framework-foo", |
| 201 | srcs: ["a.java"], |
| 202 | public: { |
| 203 | enabled: true, |
| 204 | }, |
| 205 | system: { |
| 206 | enabled: true, |
| 207 | }, |
| 208 | test: { |
| 209 | enabled: true, |
| 210 | }, |
| 211 | module_lib: { |
| 212 | enabled: true, |
| 213 | }, |
| 214 | api_packages: [ |
| 215 | "foo", |
| 216 | ], |
| 217 | sdk_version: "core_current", |
| 218 | annotations_enabled: true, |
| 219 | } |
| 220 | java_sdk_library { |
| 221 | name: "framework-bar", |
| 222 | srcs: ["a.java"], |
| 223 | public: { |
| 224 | enabled: true, |
| 225 | }, |
| 226 | system: { |
| 227 | enabled: true, |
| 228 | }, |
| 229 | test: { |
| 230 | enabled: true, |
| 231 | }, |
| 232 | module_lib: { |
| 233 | enabled: true, |
| 234 | }, |
| 235 | api_packages: [ |
| 236 | "foo", |
| 237 | ], |
| 238 | sdk_version: "core_current", |
| 239 | annotations_enabled: true, |
| 240 | } |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 241 | |
Jihoon Kang | d6e978e | 2024-02-29 23:09:10 +0000 | [diff] [blame^] | 242 | combined_apis { |
| 243 | name: "foo", |
| 244 | bootclasspath: [ |
| 245 | "framework-bar", |
| 246 | ] + select(boolean_var_for_testing(), { |
| 247 | true: [ |
| 248 | "framework-foo", |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 249 | ], |
Jihoon Kang | d6e978e | 2024-02-29 23:09:10 +0000 | [diff] [blame^] | 250 | default: [], |
| 251 | }), |
| 252 | } |
Jihoon Kang | cc4c8f9 | 2024-07-18 18:52:03 +0000 | [diff] [blame] | 253 | `) |
| 254 | |
| 255 | subModuleDependsOnSelectAppendedModule := java.CheckModuleHasDependency(t, |
| 256 | result.TestContext, "foo-current.txt", "", "framework-foo") |
| 257 | android.AssertBoolEquals(t, "Submodule expected to depend on the select-appended module", |
| 258 | true, subModuleDependsOnSelectAppendedModule) |
| 259 | } |