Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 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 sdk |
| 16 | |
| 17 | import ( |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 18 | "log" |
| 19 | "os" |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 20 | "runtime" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 21 | "testing" |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 22 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 23 | "android/soong/android" |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 24 | "android/soong/java" |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 25 | |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 29 | // Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE. |
| 30 | func TestMain(m *testing.M) { |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 31 | if runtime.GOOS != "linux" { |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 32 | // b/145598135 - Generating host snapshots for anything other than linux is not supported. |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 33 | log.Printf("Skipping as sdk snapshot generation is only supported on linux not %s", runtime.GOOS) |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 34 | os.Exit(0) |
| 35 | } |
| 36 | |
Paul Duffin | abbf63d | 2021-03-18 01:47:31 +0000 | [diff] [blame] | 37 | os.Exit(m.Run()) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 38 | } |
| 39 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 40 | // Ensure that prebuilt modules have the same effective visibility as the source |
| 41 | // modules. |
| 42 | func TestSnapshotVisibility(t *testing.T) { |
| 43 | packageBp := ` |
| 44 | package { |
| 45 | default_visibility: ["//other/foo"], |
| 46 | } |
| 47 | |
| 48 | sdk { |
| 49 | name: "mysdk", |
| 50 | visibility: [ |
| 51 | "//other/foo", |
| 52 | // This short form will be replaced with //package:__subpackages__ in the |
| 53 | // generated sdk_snapshot. |
| 54 | ":__subpackages__", |
| 55 | ], |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 56 | prebuilt_visibility: [ |
| 57 | "//prebuilts/mysdk", |
| 58 | ], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 59 | java_header_libs: [ |
| 60 | "myjavalib", |
| 61 | "mypublicjavalib", |
| 62 | "mydefaultedjavalib", |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 63 | "myprivatejavalib", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 64 | ], |
| 65 | } |
| 66 | |
| 67 | java_library { |
| 68 | name: "myjavalib", |
| 69 | // Uses package default visibility |
| 70 | srcs: ["Test.java"], |
| 71 | system_modules: "none", |
| 72 | sdk_version: "none", |
| 73 | } |
| 74 | |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 75 | java_defaults { |
| 76 | name: "java-defaults", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 77 | visibility: ["//other/bar"], |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 80 | java_library { |
| 81 | name: "mypublicjavalib", |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 82 | defaults: ["java-defaults"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 83 | visibility: ["//visibility:public"], |
| 84 | srcs: ["Test.java"], |
| 85 | system_modules: "none", |
| 86 | sdk_version: "none", |
| 87 | } |
| 88 | |
| 89 | java_defaults { |
| 90 | name: "myjavadefaults", |
| 91 | visibility: ["//other/bar"], |
| 92 | } |
| 93 | |
| 94 | java_library { |
| 95 | name: "mydefaultedjavalib", |
| 96 | defaults: ["myjavadefaults"], |
| 97 | srcs: ["Test.java"], |
| 98 | system_modules: "none", |
| 99 | sdk_version: "none", |
| 100 | } |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 101 | |
| 102 | java_library { |
| 103 | name: "myprivatejavalib", |
| 104 | srcs: ["Test.java"], |
| 105 | visibility: ["//visibility:private"], |
| 106 | system_modules: "none", |
| 107 | sdk_version: "none", |
| 108 | } |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 109 | ` |
| 110 | |
| 111 | result := testSdkWithFs(t, ``, |
| 112 | map[string][]byte{ |
| 113 | "package/Test.java": nil, |
| 114 | "package/Android.bp": []byte(packageBp), |
| 115 | }) |
| 116 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 117 | CheckSnapshot(t, result, "mysdk", "package", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 118 | checkAndroidBpContents(` |
| 119 | // This is auto-generated. DO NOT EDIT. |
| 120 | |
Spandan Das | a5e26d3 | 2024-03-06 14:04:36 +0000 | [diff] [blame] | 121 | apex_contributions_defaults { |
| 122 | name: "mysdk.contributions", |
| 123 | contents: [ |
| 124 | "prebuilt_myjavalib", |
| 125 | "prebuilt_mypublicjavalib", |
| 126 | "prebuilt_mydefaultedjavalib", |
| 127 | "prebuilt_myprivatejavalib", |
| 128 | ], |
| 129 | } |
| 130 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 131 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 132 | name: "myjavalib", |
| 133 | prefer: false, |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 134 | visibility: [ |
| 135 | "//other/foo", |
| 136 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 137 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 138 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 139 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 140 | jars: ["java/myjavalib.jar"], |
| 141 | } |
| 142 | |
| 143 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 144 | name: "mypublicjavalib", |
| 145 | prefer: false, |
| 146 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 147 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 148 | jars: ["java/mypublicjavalib.jar"], |
| 149 | } |
| 150 | |
| 151 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 152 | name: "mydefaultedjavalib", |
| 153 | prefer: false, |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 154 | visibility: [ |
| 155 | "//other/bar", |
| 156 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 157 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 158 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 159 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 160 | jars: ["java/mydefaultedjavalib.jar"], |
| 161 | } |
| 162 | |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 163 | java_import { |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 164 | name: "myprivatejavalib", |
| 165 | prefer: false, |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 166 | visibility: [ |
| 167 | "//package", |
| 168 | "//prebuilts/mysdk", |
| 169 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 170 | apex_available: ["//apex_available:platform"], |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 171 | jars: ["java/myprivatejavalib.jar"], |
| 172 | } |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 173 | `)) |
| 174 | } |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 175 | |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 176 | func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) { |
| 177 | testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, ` |
| 178 | sdk { |
| 179 | name: "mysdk", |
| 180 | prebuilt_visibility: [ |
| 181 | "//foo", |
| 182 | "//visibility:private", |
| 183 | ], |
| 184 | } |
| 185 | `) |
| 186 | } |
| 187 | |
| 188 | func TestPrebuiltVisibilityProperty_AddPrivate(t *testing.T) { |
| 189 | testSdkError(t, `prebuilt_visibility: "//visibility:private" does not widen the visibility`, ` |
| 190 | sdk { |
| 191 | name: "mysdk", |
| 192 | prebuilt_visibility: [ |
| 193 | "//visibility:private", |
| 194 | ], |
| 195 | java_header_libs: [ |
| 196 | "myjavalib", |
| 197 | ], |
| 198 | } |
| 199 | |
| 200 | java_library { |
| 201 | name: "myjavalib", |
| 202 | // Uses package default visibility |
| 203 | srcs: ["Test.java"], |
| 204 | system_modules: "none", |
| 205 | sdk_version: "none", |
| 206 | } |
| 207 | `) |
| 208 | } |
| 209 | |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 210 | func TestSdkInstall(t *testing.T) { |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 211 | sdk := ` |
| 212 | sdk { |
| 213 | name: "mysdk", |
| 214 | } |
| 215 | ` |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 216 | result := testSdkWithFs(t, sdk, nil) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 217 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 218 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 219 | checkAllOtherCopyRules(` |
| 220 | .intermediates/mysdk/common_os/mysdk-current.info -> mysdk-current.info |
| 221 | .intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip |
| 222 | `)) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 223 | } |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 224 | |
| 225 | type EmbeddedPropertiesStruct struct { |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 226 | S_Embedded_Common string `android:"arch_variant"` |
| 227 | S_Embedded_Different string `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | type testPropertiesStruct struct { |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 231 | name string |
| 232 | private string |
| 233 | Public_Ignore string `sdk:"ignore"` |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 234 | Public_Keep string `sdk:"keep"` |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 235 | S_Common string |
| 236 | S_Different string `android:"arch_variant"` |
| 237 | A_Common []string |
| 238 | A_Different []string `android:"arch_variant"` |
| 239 | F_Common *bool |
| 240 | F_Different *bool `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 241 | EmbeddedPropertiesStruct |
| 242 | } |
| 243 | |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 244 | func (p *testPropertiesStruct) optimizableProperties() interface{} { |
| 245 | return p |
| 246 | } |
| 247 | |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 248 | func (p *testPropertiesStruct) String() string { |
| 249 | return p.name |
| 250 | } |
| 251 | |
| 252 | var _ propertiesContainer = (*testPropertiesStruct)(nil) |
| 253 | |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 254 | func TestCommonValueOptimization(t *testing.T) { |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 255 | common := &testPropertiesStruct{name: "common"} |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 256 | structs := []propertiesContainer{ |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 257 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 258 | name: "struct-0", |
| 259 | private: "common", |
| 260 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 261 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 262 | S_Common: "common", |
| 263 | S_Different: "upper", |
| 264 | A_Common: []string{"first", "second"}, |
| 265 | A_Different: []string{"alpha", "beta"}, |
| 266 | F_Common: proptools.BoolPtr(false), |
| 267 | F_Different: proptools.BoolPtr(false), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 268 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 269 | S_Embedded_Common: "embedded_common", |
| 270 | S_Embedded_Different: "embedded_upper", |
| 271 | }, |
| 272 | }, |
| 273 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 274 | name: "struct-1", |
| 275 | private: "common", |
| 276 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 277 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 278 | S_Common: "common", |
| 279 | S_Different: "lower", |
| 280 | A_Common: []string{"first", "second"}, |
| 281 | A_Different: []string{"alpha", "delta"}, |
| 282 | F_Common: proptools.BoolPtr(false), |
| 283 | F_Different: proptools.BoolPtr(true), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 284 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 285 | S_Embedded_Common: "embedded_common", |
| 286 | S_Embedded_Different: "embedded_lower", |
| 287 | }, |
| 288 | }, |
| 289 | } |
| 290 | |
| 291 | extractor := newCommonValueExtractor(common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 292 | |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 293 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 294 | android.AssertDeepEquals(t, "unexpected error", nil, err) |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 295 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 296 | android.AssertDeepEquals(t, "common properties not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 297 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 298 | name: "common", |
| 299 | private: "", |
| 300 | Public_Ignore: "", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 301 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 302 | S_Common: "common", |
| 303 | S_Different: "", |
| 304 | A_Common: []string{"first", "second"}, |
| 305 | A_Different: []string(nil), |
| 306 | F_Common: proptools.BoolPtr(false), |
| 307 | F_Different: nil, |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 308 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 309 | S_Embedded_Common: "embedded_common", |
| 310 | S_Embedded_Different: "", |
| 311 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 312 | }, |
| 313 | common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 314 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 315 | android.AssertDeepEquals(t, "updated properties[0] not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 316 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 317 | name: "struct-0", |
| 318 | private: "common", |
| 319 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 320 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 321 | S_Common: "", |
| 322 | S_Different: "upper", |
| 323 | A_Common: nil, |
| 324 | A_Different: []string{"alpha", "beta"}, |
| 325 | F_Common: nil, |
| 326 | F_Different: proptools.BoolPtr(false), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 327 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 328 | S_Embedded_Common: "", |
| 329 | S_Embedded_Different: "embedded_upper", |
| 330 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 331 | }, |
| 332 | structs[0]) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 333 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 334 | android.AssertDeepEquals(t, "updated properties[1] not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 335 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 336 | name: "struct-1", |
| 337 | private: "common", |
| 338 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 339 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 340 | S_Common: "", |
| 341 | S_Different: "lower", |
| 342 | A_Common: nil, |
| 343 | A_Different: []string{"alpha", "delta"}, |
| 344 | F_Common: nil, |
| 345 | F_Different: proptools.BoolPtr(true), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 346 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 347 | S_Embedded_Common: "", |
| 348 | S_Embedded_Different: "embedded_lower", |
| 349 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 350 | }, |
| 351 | structs[1]) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 352 | } |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 353 | |
| 354 | func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) { |
| 355 | common := &testPropertiesStruct{name: "common"} |
| 356 | structs := []propertiesContainer{ |
| 357 | &testPropertiesStruct{ |
| 358 | name: "struct-0", |
| 359 | S_Common: "should-be-but-is-not-common0", |
| 360 | }, |
| 361 | &testPropertiesStruct{ |
| 362 | name: "struct-1", |
| 363 | S_Common: "should-be-but-is-not-common1", |
| 364 | }, |
| 365 | } |
| 366 | |
| 367 | extractor := newCommonValueExtractor(common) |
| 368 | |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 369 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 370 | android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties: |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 371 | "struct-0" has value "should-be-but-is-not-common0" |
| 372 | "struct-1" has value "should-be-but-is-not-common1"`, err) |
| 373 | } |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 374 | |
| 375 | // Ensure that sdk snapshot related environment variables work correctly. |
| 376 | func TestSnapshot_EnvConfiguration(t *testing.T) { |
| 377 | bp := ` |
| 378 | sdk { |
| 379 | name: "mysdk", |
| 380 | java_header_libs: ["myjavalib"], |
| 381 | } |
| 382 | |
| 383 | java_library { |
| 384 | name: "myjavalib", |
| 385 | srcs: ["Test.java"], |
| 386 | system_modules: "none", |
| 387 | sdk_version: "none", |
| 388 | compile_dex: true, |
| 389 | host_supported: true, |
| 390 | } |
| 391 | ` |
| 392 | preparer := android.GroupFixturePreparers( |
| 393 | prepareForSdkTestWithJava, |
| 394 | android.FixtureWithRootAndroidBp(bp), |
| 395 | ) |
| 396 | |
| 397 | checkZipFile := func(t *testing.T, result *android.TestResult, expected string) { |
| 398 | zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles") |
| 399 | android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String()) |
| 400 | } |
| 401 | |
| 402 | t.Run("no env variables", func(t *testing.T) { |
| 403 | result := preparer.RunTest(t) |
| 404 | |
| 405 | checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") |
| 406 | |
| 407 | CheckSnapshot(t, result, "mysdk", "", |
| 408 | checkAndroidBpContents(` |
| 409 | // This is auto-generated. DO NOT EDIT. |
| 410 | |
Spandan Das | a5e26d3 | 2024-03-06 14:04:36 +0000 | [diff] [blame] | 411 | apex_contributions_defaults { |
| 412 | name: "mysdk.contributions", |
| 413 | contents: ["prebuilt_myjavalib"], |
| 414 | } |
| 415 | |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 416 | java_import { |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 417 | name: "myjavalib", |
| 418 | prefer: false, |
| 419 | visibility: ["//visibility:public"], |
| 420 | apex_available: ["//apex_available:platform"], |
| 421 | jars: ["java/myjavalib.jar"], |
| 422 | } |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 423 | `), |
| 424 | ) |
| 425 | }) |
Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 426 | |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 427 | t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) { |
| 428 | result := android.GroupFixturePreparers( |
| 429 | prepareForSdkTestWithJava, |
| 430 | java.PrepareForTestWithJavaDefaultModules, |
| 431 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 432 | java.FixtureWithLastReleaseApis("mysdklibrary"), |
| 433 | android.FixtureWithRootAndroidBp(` |
| 434 | sdk { |
| 435 | name: "mysdk", |
| 436 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 437 | } |
| 438 | |
| 439 | bootclasspath_fragment { |
| 440 | name: "mybootclasspathfragment", |
| 441 | apex_available: ["myapex"], |
| 442 | contents: ["mysdklibrary"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 443 | hidden_api: { |
| 444 | split_packages: ["*"], |
| 445 | }, |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | java_sdk_library { |
| 449 | name: "mysdklibrary", |
| 450 | srcs: ["Test.java"], |
| 451 | compile_dex: true, |
Paul Duffin | 1938dba | 2022-07-26 23:53:00 +0000 | [diff] [blame] | 452 | sdk_version: "S", |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 453 | public: {enabled: true}, |
| 454 | permitted_packages: ["mysdklibrary"], |
| 455 | } |
| 456 | `), |
| 457 | android.FixtureMergeEnv(map[string]string{ |
| 458 | "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", |
| 459 | }), |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 460 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 461 | variables.BuildFlags = map[string]string{ |
| 462 | "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", |
| 463 | } |
| 464 | }), |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 465 | ).RunTest(t) |
| 466 | |
| 467 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame] | 468 | checkAndroidBpContents(` |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 469 | // This is auto-generated. DO NOT EDIT. |
| 470 | |
Spandan Das | a5e26d3 | 2024-03-06 14:04:36 +0000 | [diff] [blame] | 471 | apex_contributions_defaults { |
| 472 | name: "mysdk.contributions", |
| 473 | contents: ["prebuilt_mysdklibrary"], |
| 474 | } |
| 475 | |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 476 | prebuilt_bootclasspath_fragment { |
| 477 | name: "mybootclasspathfragment", |
| 478 | prefer: false, |
| 479 | visibility: ["//visibility:public"], |
| 480 | apex_available: ["myapex"], |
| 481 | contents: ["mysdklibrary"], |
| 482 | hidden_api: { |
| 483 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 484 | metadata: "hiddenapi/metadata.csv", |
| 485 | index: "hiddenapi/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 486 | stub_flags: "hiddenapi/stub-flags.csv", |
| 487 | all_flags: "hiddenapi/all-flags.csv", |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 488 | }, |
| 489 | } |
| 490 | |
| 491 | java_sdk_library_import { |
| 492 | name: "mysdklibrary", |
| 493 | prefer: false, |
| 494 | visibility: ["//visibility:public"], |
| 495 | apex_available: ["//apex_available:platform"], |
| 496 | shared_library: true, |
| 497 | compile_dex: true, |
| 498 | permitted_packages: ["mysdklibrary"], |
| 499 | public: { |
| 500 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 501 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 502 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 503 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 504 | sdk_version: "current", |
| 505 | }, |
| 506 | } |
| 507 | `), |
| 508 | |
| 509 | checkAllCopyRules(` |
| 510 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 511 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 512 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 513 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv |
| 514 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 515 | .intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 516 | .intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 517 | .intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 518 | `), |
| 519 | ) |
| 520 | }) |
| 521 | |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame^] | 522 | t.Run("test replacing exportable module", func(t *testing.T) { |
| 523 | result := android.GroupFixturePreparers( |
| 524 | prepareForSdkTestWithJava, |
| 525 | java.PrepareForTestWithJavaDefaultModules, |
| 526 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 527 | java.FixtureWithLastReleaseApis("mysdklibrary", "anothersdklibrary"), |
| 528 | android.FixtureWithRootAndroidBp(` |
| 529 | sdk { |
| 530 | name: "mysdk", |
| 531 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 532 | } |
| 533 | |
| 534 | bootclasspath_fragment { |
| 535 | name: "mybootclasspathfragment", |
| 536 | apex_available: ["myapex"], |
| 537 | contents: ["mysdklibrary"], |
| 538 | hidden_api: { |
| 539 | split_packages: ["*"], |
| 540 | }, |
| 541 | core_platform_api: { |
| 542 | stub_libs: [ |
| 543 | "anothersdklibrary.stubs.exportable", |
| 544 | ], |
| 545 | }, |
| 546 | api: { |
| 547 | stub_libs: [ |
| 548 | "anothersdklibrary", |
| 549 | ], |
| 550 | }, |
| 551 | } |
| 552 | |
| 553 | java_sdk_library { |
| 554 | name: "mysdklibrary", |
| 555 | srcs: ["Test.java"], |
| 556 | compile_dex: true, |
| 557 | min_sdk_version: "S", |
| 558 | public: {enabled: true}, |
| 559 | permitted_packages: ["mysdklibrary"], |
| 560 | } |
| 561 | |
| 562 | java_sdk_library { |
| 563 | name: "anothersdklibrary", |
| 564 | srcs: ["Test.java"], |
| 565 | compile_dex: true, |
| 566 | min_sdk_version: "S", |
| 567 | public: {enabled: true}, |
| 568 | system: {enabled: true}, |
| 569 | module_lib: {enabled: true}, |
| 570 | } |
| 571 | `), |
| 572 | android.FixtureMergeEnv(map[string]string{ |
| 573 | "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", |
| 574 | }), |
| 575 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 576 | variables.BuildFlags = map[string]string{ |
| 577 | "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", |
| 578 | } |
| 579 | variables.Platform_version_active_codenames = []string{"UpsideDownCake", "Tiramisu", "S-V2"} |
| 580 | }), |
| 581 | ).RunTest(t) |
| 582 | |
| 583 | CheckSnapshot(t, result, "mysdk", "", |
| 584 | checkAndroidBpContents(` |
| 585 | // This is auto-generated. DO NOT EDIT. |
| 586 | |
| 587 | prebuilt_bootclasspath_fragment { |
| 588 | name: "mybootclasspathfragment", |
| 589 | prefer: false, |
| 590 | visibility: ["//visibility:public"], |
| 591 | apex_available: ["myapex"], |
| 592 | contents: ["mysdklibrary"], |
| 593 | api: { |
| 594 | stub_libs: ["anothersdklibrary"], |
| 595 | }, |
| 596 | core_platform_api: { |
| 597 | stub_libs: ["anothersdklibrary.stubs"], |
| 598 | }, |
| 599 | hidden_api: { |
| 600 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 601 | metadata: "hiddenapi/metadata.csv", |
| 602 | index: "hiddenapi/index.csv", |
| 603 | stub_flags: "hiddenapi/stub-flags.csv", |
| 604 | all_flags: "hiddenapi/all-flags.csv", |
| 605 | }, |
| 606 | } |
| 607 | |
| 608 | java_sdk_library_import { |
| 609 | name: "mysdklibrary", |
| 610 | prefer: false, |
| 611 | visibility: ["//visibility:public"], |
| 612 | apex_available: ["//apex_available:platform"], |
| 613 | shared_library: true, |
| 614 | compile_dex: true, |
| 615 | permitted_packages: ["mysdklibrary"], |
| 616 | public: { |
| 617 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 618 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 619 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 620 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 621 | sdk_version: "current", |
| 622 | }, |
| 623 | } |
| 624 | |
| 625 | java_sdk_library_import { |
| 626 | name: "anothersdklibrary", |
| 627 | prefer: false, |
| 628 | visibility: ["//visibility:public"], |
| 629 | apex_available: ["//apex_available:platform"], |
| 630 | shared_library: true, |
| 631 | compile_dex: true, |
| 632 | public: { |
| 633 | jars: ["sdk_library/public/anothersdklibrary-stubs.jar"], |
| 634 | stub_srcs: ["sdk_library/public/anothersdklibrary_stub_sources"], |
| 635 | current_api: "sdk_library/public/anothersdklibrary.txt", |
| 636 | removed_api: "sdk_library/public/anothersdklibrary-removed.txt", |
| 637 | sdk_version: "current", |
| 638 | }, |
| 639 | system: { |
| 640 | jars: ["sdk_library/system/anothersdklibrary-stubs.jar"], |
| 641 | stub_srcs: ["sdk_library/system/anothersdklibrary_stub_sources"], |
| 642 | current_api: "sdk_library/system/anothersdklibrary.txt", |
| 643 | removed_api: "sdk_library/system/anothersdklibrary-removed.txt", |
| 644 | sdk_version: "system_current", |
| 645 | }, |
| 646 | module_lib: { |
| 647 | jars: ["sdk_library/module-lib/anothersdklibrary-stubs.jar"], |
| 648 | stub_srcs: ["sdk_library/module-lib/anothersdklibrary_stub_sources"], |
| 649 | current_api: "sdk_library/module-lib/anothersdklibrary.txt", |
| 650 | removed_api: "sdk_library/module-lib/anothersdklibrary-removed.txt", |
| 651 | sdk_version: "module_current", |
| 652 | }, |
| 653 | } |
| 654 | `), |
| 655 | ) |
| 656 | }) |
| 657 | |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 658 | } |