blob: 1c84a7bbac41e1a7c428522e84a8c49dd1a1682e [file] [log] [blame]
Jiakai Zhanga8d86602021-09-26 09:02:17 +00001// Copyright (C) 2021 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 sdk
16
17import (
18 "testing"
19
20 "android/soong/android"
21 "android/soong/dexpreopt"
22 "android/soong/java"
23)
24
Paul Duffinf861df72022-07-01 15:56:06 +000025func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRelease string, expectedSdkSnapshot string) {
Jiakai Zhanga8d86602021-09-26 09:02:17 +000026 result := android.GroupFixturePreparers(
27 prepareForSdkTestWithJava,
28 java.PrepareForTestWithJavaDefaultModules,
29 java.PrepareForTestWithJavaSdkLibraryFiles,
30 java.FixtureWithLastReleaseApis("mysdklibrary"),
31 dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"),
Paul Duffinf861df72022-07-01 15:56:06 +000032 android.FixtureModifyEnv(func(env map[string]string) {
33 env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = targetBuildRelease
34 }),
Jiakai Zhanga8d86602021-09-26 09:02:17 +000035 prepareForSdkTestWithApex,
36
37 android.FixtureWithRootAndroidBp(`
38 sdk {
39 name: "mysdk",
40 systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
41 java_sdk_libs: [
42 // This is not strictly needed as it should be automatically added to the sdk_snapshot as
43 // a java_sdk_libs module because it is used in the mysystemserverclasspathfragment's
44 // contents property. However, it is specified here to ensure that duplicates are
45 // correctly deduped.
46 "mysdklibrary",
47 ],
48 }
49
50 apex {
51 name: "myapex",
52 key: "myapex.key",
53 min_sdk_version: "2",
54 systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
55 }
56
57 systemserverclasspath_fragment {
58 name: "mysystemserverclasspathfragment",
59 apex_available: ["myapex"],
60 contents: [
61 "mylib",
62 "mysdklibrary",
63 ],
64 }
65
66 java_library {
67 name: "mylib",
68 apex_available: ["myapex"],
69 srcs: ["Test.java"],
70 system_modules: "none",
71 sdk_version: "none",
72 min_sdk_version: "2",
73 compile_dex: true,
74 permitted_packages: ["mylib"],
75 }
76
77 java_sdk_library {
78 name: "mysdklibrary",
79 apex_available: ["myapex"],
80 srcs: ["Test.java"],
81 shared_library: false,
82 public: {enabled: true},
83 min_sdk_version: "2",
84 }
85 `),
86 ).RunTest(t)
87
88 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinf861df72022-07-01 15:56:06 +000089 checkAndroidBpContents(expectedSdkSnapshot),
90 )
91}
92
93func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
94 t.Run("target-s", func(t *testing.T) {
95 testSnapshotWithSystemServerClasspathFragment(t, "S", `
96// This is auto-generated. DO NOT EDIT.
97
98java_sdk_library_import {
99 name: "mysdklibrary",
100 prefer: false,
101 visibility: ["//visibility:public"],
102 apex_available: ["myapex"],
103 shared_library: false,
104 public: {
105 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
106 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
107 current_api: "sdk_library/public/mysdklibrary.txt",
108 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
109 sdk_version: "current",
110 },
111}
112`)
113 })
114
115 t.Run("target-t", func(t *testing.T) {
116 testSnapshotWithSystemServerClasspathFragment(t, "Tiramisu", `
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000117// This is auto-generated. DO NOT EDIT.
118
119java_sdk_library_import {
120 name: "mysdklibrary",
121 prefer: false,
122 visibility: ["//visibility:public"],
123 apex_available: ["myapex"],
124 shared_library: false,
125 public: {
126 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
127 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
128 current_api: "sdk_library/public/mysdklibrary.txt",
129 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
130 sdk_version: "current",
131 },
132}
133
134java_import {
135 name: "mylib",
136 prefer: false,
137 visibility: ["//visibility:public"],
138 apex_available: ["myapex"],
139 jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
140 permitted_packages: ["mylib"],
141}
142
143prebuilt_systemserverclasspath_fragment {
144 name: "mysystemserverclasspathfragment",
145 prefer: false,
146 visibility: ["//visibility:public"],
147 apex_available: ["myapex"],
148 contents: [
149 "mylib",
150 "mysdklibrary",
151 ],
152}
Paul Duffinf861df72022-07-01 15:56:06 +0000153`)
154 })
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000155}