Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 1 | // Copyright (C) 2023 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 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | "android/soong/bp2build" |
Jihoon Kang | 1453baa | 2023-05-27 05:32:30 +0000 | [diff] [blame] | 22 | "android/soong/java" |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func runCombinedApisTestCaseWithRegistrationCtxFunc(t *testing.T, tc bp2build.Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) { |
| 26 | t.Helper() |
| 27 | (&tc).ModuleTypeUnderTest = "combined_apis" |
| 28 | (&tc).ModuleTypeUnderTestFactory = combinedApisModuleFactory |
| 29 | bp2build.RunBp2BuildTestCase(t, registrationCtxFunc, tc) |
| 30 | } |
| 31 | |
| 32 | func runCombinedApisTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) { |
| 33 | t.Helper() |
Jihoon Kang | 1453baa | 2023-05-27 05:32:30 +0000 | [diff] [blame] | 34 | runCombinedApisTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) { |
| 35 | ctx.RegisterModuleType("java_defaults", java.DefaultsFactory) |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 36 | ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory) |
| 37 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Jihoon Kang | 1453baa | 2023-05-27 05:32:30 +0000 | [diff] [blame] | 38 | }) |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | func TestCombinedApisGeneral(t *testing.T) { |
| 42 | runCombinedApisTestCase(t, bp2build.Bp2buildTestCase{ |
| 43 | Description: "combined_apis, general case", |
| 44 | Blueprint: `combined_apis { |
| 45 | name: "foo", |
| 46 | bootclasspath: ["bcp"], |
| 47 | system_server_classpath: ["ssc"], |
| 48 | } |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 49 | |
| 50 | java_sdk_library { |
| 51 | name: "bcp", |
| 52 | srcs: ["a.java", "b.java"], |
| 53 | shared_library: false, |
| 54 | } |
| 55 | java_sdk_library { |
| 56 | name: "ssc", |
| 57 | srcs: ["a.java", "b.java"], |
| 58 | shared_library: false, |
| 59 | } |
| 60 | filegroup { |
| 61 | name: "non-updatable-current.txt", |
| 62 | srcs: ["current.txt"], |
| 63 | } |
| 64 | filegroup { |
| 65 | name: "non-updatable-system-current.txt", |
| 66 | srcs: ["system-current.txt"], |
| 67 | } |
| 68 | filegroup { |
| 69 | name: "non-updatable-module-lib-current.txt", |
| 70 | srcs: ["system-removed.txt"], |
| 71 | } |
| 72 | filegroup { |
| 73 | name: "non-updatable-system-server-current.txt", |
| 74 | srcs: ["system-lint-baseline.txt"], |
| 75 | } |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 76 | `, |
Jihoon Kang | 1453baa | 2023-05-27 05:32:30 +0000 | [diff] [blame] | 77 | Filesystem: map[string]string{ |
| 78 | "a/Android.bp": ` |
| 79 | java_defaults { |
| 80 | name: "android.jar_defaults", |
| 81 | } |
| 82 | `, |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 83 | "api/current.txt": "", |
| 84 | "api/removed.txt": "", |
| 85 | "api/system-current.txt": "", |
| 86 | "api/system-removed.txt": "", |
| 87 | "api/test-current.txt": "", |
| 88 | "api/test-removed.txt": "", |
Jihoon Kang | 1453baa | 2023-05-27 05:32:30 +0000 | [diff] [blame] | 89 | }, |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 90 | StubbedBuildDefinitions: []string{"bcp", "ssc", "non-updatable-current.txt", "non-updatable-system-current.txt", "non-updatable-module-lib-current.txt", "non-updatable-system-server-current.txt"}, |
| 91 | ExpectedHandcraftedModules: []string{"foo-current.txt", "foo-system-current.txt", "foo-module-lib-current.txt", "foo-system-server-current.txt"}, |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 92 | ExpectedBazelTargets: []string{ |
| 93 | bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-current.txt", bp2build.AttrNameToString{ |
| 94 | "scope": `"public"`, |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 95 | "base": `":non-updatable-current.txt"`, |
| 96 | "deps": `[":bcp"]`, |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 97 | }), |
| 98 | bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-current.txt", bp2build.AttrNameToString{ |
| 99 | "scope": `"system"`, |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 100 | "base": `":non-updatable-system-current.txt"`, |
| 101 | "deps": `[":bcp"]`, |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 102 | }), |
| 103 | bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-module-lib-current.txt", bp2build.AttrNameToString{ |
| 104 | "scope": `"module-lib"`, |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 105 | "base": `":non-updatable-module-lib-current.txt"`, |
| 106 | "deps": `[":bcp"]`, |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 107 | }), |
| 108 | bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-server-current.txt", bp2build.AttrNameToString{ |
| 109 | "scope": `"system-server"`, |
Chris Parsons | 3b7e34b | 2023-09-27 22:34:57 +0000 | [diff] [blame^] | 110 | "base": `":non-updatable-system-server-current.txt"`, |
| 111 | "deps": `[":ssc"]`, |
Zi Wang | 0d6a530 | 2023-02-16 14:54:01 -0800 | [diff] [blame] | 112 | }), |
| 113 | }, |
| 114 | }) |
| 115 | } |