blob: 70f2162348ad03ce1e540608af964cbf0152f7fd [file] [log] [blame]
Zi Wang0d6a5302023-02-16 14:54:01 -08001// 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
15package api
16
17import (
18 "testing"
19
20 "android/soong/android"
21 "android/soong/bp2build"
Jihoon Kang1453baa2023-05-27 05:32:30 +000022 "android/soong/java"
Zi Wang0d6a5302023-02-16 14:54:01 -080023)
24
25func 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
32func runCombinedApisTestCase(t *testing.T, tc bp2build.Bp2buildTestCase) {
33 t.Helper()
Jihoon Kang1453baa2023-05-27 05:32:30 +000034 runCombinedApisTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {
35 ctx.RegisterModuleType("java_defaults", java.DefaultsFactory)
Chris Parsons3b7e34b2023-09-27 22:34:57 +000036 ctx.RegisterModuleType("java_sdk_library", java.SdkLibraryFactory)
37 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Jihoon Kang1453baa2023-05-27 05:32:30 +000038 })
Zi Wang0d6a5302023-02-16 14:54:01 -080039}
40
41func 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 Parsons3b7e34b2023-09-27 22:34:57 +000049
50java_sdk_library {
51 name: "bcp",
52 srcs: ["a.java", "b.java"],
53 shared_library: false,
54}
55java_sdk_library {
56 name: "ssc",
57 srcs: ["a.java", "b.java"],
58 shared_library: false,
59}
60filegroup {
61 name: "non-updatable-current.txt",
62 srcs: ["current.txt"],
63}
64filegroup {
65 name: "non-updatable-system-current.txt",
66 srcs: ["system-current.txt"],
67}
68filegroup {
69 name: "non-updatable-module-lib-current.txt",
70 srcs: ["system-removed.txt"],
71}
72filegroup {
73 name: "non-updatable-system-server-current.txt",
74 srcs: ["system-lint-baseline.txt"],
75}
Zi Wang0d6a5302023-02-16 14:54:01 -080076`,
Jihoon Kang1453baa2023-05-27 05:32:30 +000077 Filesystem: map[string]string{
78 "a/Android.bp": `
79 java_defaults {
80 name: "android.jar_defaults",
81 }
82 `,
Chris Parsons3b7e34b2023-09-27 22:34:57 +000083 "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 Kang1453baa2023-05-27 05:32:30 +000089 },
Chris Parsons3b7e34b2023-09-27 22:34:57 +000090 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 Wang0d6a5302023-02-16 14:54:01 -080092 ExpectedBazelTargets: []string{
93 bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-current.txt", bp2build.AttrNameToString{
94 "scope": `"public"`,
Chris Parsons3b7e34b2023-09-27 22:34:57 +000095 "base": `":non-updatable-current.txt"`,
96 "deps": `[":bcp"]`,
Zi Wang0d6a5302023-02-16 14:54:01 -080097 }),
98 bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-current.txt", bp2build.AttrNameToString{
99 "scope": `"system"`,
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000100 "base": `":non-updatable-system-current.txt"`,
101 "deps": `[":bcp"]`,
Zi Wang0d6a5302023-02-16 14:54:01 -0800102 }),
103 bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-module-lib-current.txt", bp2build.AttrNameToString{
104 "scope": `"module-lib"`,
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000105 "base": `":non-updatable-module-lib-current.txt"`,
106 "deps": `[":bcp"]`,
Zi Wang0d6a5302023-02-16 14:54:01 -0800107 }),
108 bp2build.MakeBazelTargetNoRestrictions("merged_txts", "foo-system-server-current.txt", bp2build.AttrNameToString{
109 "scope": `"system-server"`,
Chris Parsons3b7e34b2023-09-27 22:34:57 +0000110 "base": `":non-updatable-system-server-current.txt"`,
111 "deps": `[":ssc"]`,
Zi Wang0d6a5302023-02-16 14:54:01 -0800112 }),
113 },
114 })
115}